Skip to content

Commit

Permalink
fix for profiling logger delta and choices for logging package
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed May 29, 2019
1 parent d17e416 commit 430f298
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 44 deletions.
Expand Up @@ -97,7 +97,7 @@ public C convertToObject(String value, Locale arg1) throws ConversionException {
}

for (LookupTableRowType row : lookupTable.getRow()) {
if (value.equals(WebComponentUtil.getLocalizedPolyStringValue(row.getLabel() != null ? row.getLabel().toPolyString() : null, (PageBase) getPage()))) {
if (value.equals(WebComponentUtil.getLocalizedPolyStringValue(row.getLabel() != null ? row.getLabel().toPolyString() : null))) {
return (C) row.getKey();
}
}
Expand All @@ -115,7 +115,7 @@ public String convertToString(C key, Locale arg1) {
if (lookupTable != null) {
for (LookupTableRowType row : lookupTable.getRow()) {
if (key.equals(row.getKey())) {
return (String) WebComponentUtil.getLocalizedPolyStringValue(row.getLabel() != null ? row.getLabel().toPolyString() : null, (PageBase) getPage());
return (String) WebComponentUtil.getLocalizedPolyStringValue(row.getLabel() != null ? row.getLabel().toPolyString() : null);
}
}
}
Expand Down
Expand Up @@ -131,17 +131,19 @@ protected List<String> prepareAutoCompleteList(String input, LookupTableType loo

if (input == null || input.isEmpty()) {
for (LookupTableRowType row : rows) {
values.add(WebComponentUtil.getOrigStringFromPoly(row.getLabel()));
values.add(WebComponentUtil.getLocalizedPolyStringValue(row.getLabel() != null ? row.getLabel().toPolyString() : null));
}
} else {
for (LookupTableRowType row : rows) {
if (WebComponentUtil.getOrigStringFromPoly(row.getLabel()) != null
&& WebComponentUtil.getOrigStringFromPoly(row.getLabel()).toLowerCase().contains(input.toLowerCase())) {
values.add(WebComponentUtil.getOrigStringFromPoly(row.getLabel()));
if (row.getLabel() == null) {
continue;
}
if (WebComponentUtil.getLocalizedPolyStringValue(row.getLabel().toPolyString()) != null
&& WebComponentUtil.getLocalizedPolyStringValue(row.getLabel().toPolyString()).toLowerCase().contains(input.toLowerCase())) {
values.add(WebComponentUtil.getLocalizedPolyStringValue(row.getLabel().toPolyString()));
}
}
}

return values;
}

Expand Down
Expand Up @@ -3867,8 +3867,16 @@ public static void saveTask(PrismObject<TaskType> oldTask, OperationResult resul
}
result.recomputeStatus();
}

public static String getLocalizedPolyStringValue(PolyString polyString, PageBase pageBase){

public static String getLocalizedOrOriginPolyStringValue(PolyString polyString){
String value = getLocalizedPolyStringValue(polyString);
if(value == null) {
return getOrigStringFromPoly(polyString);
}
return value;
}

public static String getLocalizedPolyStringValue(PolyString polyString){
if (polyString == null){
return null;
}
Expand All @@ -3893,13 +3901,17 @@ public static String getLocalizedPolyStringValue(PolyString polyString, PageBase
String translationValue = "";
if (argument.getTranslation() != null){
String argumentKey = argument.getTranslation().getKey();
String valueByKey = StringUtils.isNotEmpty(argumentKey) ? pageBase.createStringResource(argumentKey).getString() : null;
String valueByKey = StringUtils.isNotEmpty(argumentKey) ? new StringResourceModel(argumentKey).getString() : null;
translationValue = StringUtils.isNotEmpty(valueByKey) ? valueByKey : argument.getTranslation().getFallback();
}
argumentValue = StringUtils.isNotEmpty(translationValue) ? translationValue : argument.getValue();
argumentValues.add(argumentValue);
});
return pageBase.createStringResource(polyString.getTranslation().getKey(), argumentValues.toArray()).getString();
return new StringResourceModel(polyString.getTranslation().getKey())
.setDefaultValue(polyString.getTranslation().getKey())
.setModel(new Model<String>())
.setParameters(argumentValues.toArray())
.getString();
}
return null;
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.gui.impl.prism.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.ProfilingClassLoggerContainerValueWrapperImpl;
import com.evolveum.midpoint.gui.impl.prism.ProfilingClassLoggerContainerWrapperImpl;
import com.evolveum.midpoint.gui.impl.prism.ProfilingClassLoggerPanel;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContainer;
Expand All @@ -45,7 +46,7 @@
*
*/
@Component
public class ProfilingClassLoggerWrapperFactoryImpl<C extends Containerable> extends PrismContainerWrapperFactoryImpl<C>{
public class ProfilingClassLoggerWrapperFactoryImpl extends PrismContainerWrapperFactoryImpl<ClassLoggerConfigurationType>{

private static final long serialVersionUID = 1L;

Expand All @@ -63,7 +64,7 @@ public boolean match(ItemDefinition<?> def) {
}

@Override
protected boolean canCreateValueWrapper(PrismContainerValue<C> value) {
protected boolean canCreateValueWrapper(PrismContainerValue<ClassLoggerConfigurationType> value) {
if(value == null || value.getRealValue() == null) {
return false;
}
Expand All @@ -75,30 +76,30 @@ protected boolean canCreateValueWrapper(PrismContainerValue<C> value) {
}

@Override
protected PrismContainerWrapper<C> createWrapper(PrismContainerValueWrapper<?> parent, PrismContainer<C> childContainer,
ItemStatus status) {
PrismContainer<C> clone = childContainer.clone();
protected PrismContainerWrapper<ClassLoggerConfigurationType> createWrapper(PrismContainerValueWrapper<?> parent,
PrismContainer<ClassLoggerConfigurationType> childContainer, ItemStatus status) {
PrismContainer<ClassLoggerConfigurationType> clone = childContainer.clone();
// clone.setElementName(PROFILING_LOGGER_PATH);
registry.registerWrapperPanel(PROFILING_LOGGER_PATH, PrismContainerPanel.class);
return new ProfilingClassLoggerContainerWrapperImpl<C>((PrismContainerValueWrapper<C>) parent, clone, status);
registry.registerWrapperPanel(PROFILING_LOGGER_PATH, ProfilingClassLoggerPanel.class);
return new ProfilingClassLoggerContainerWrapperImpl<ClassLoggerConfigurationType>((PrismContainerValueWrapper<ClassLoggerConfigurationType>) parent, clone, status);
}

@Override
protected <ID extends ItemDefinition<PrismContainer<C>>> List<PrismContainerValueWrapper<C>> createValuesWrapper(
PrismContainerWrapper<C> itemWrapper, PrismContainer<C> item, WrapperContext context)
protected <ID extends ItemDefinition<PrismContainer<ClassLoggerConfigurationType>>> List<PrismContainerValueWrapper<ClassLoggerConfigurationType>> createValuesWrapper(
PrismContainerWrapper<ClassLoggerConfigurationType> itemWrapper, PrismContainer<ClassLoggerConfigurationType> item, WrapperContext context)
throws SchemaException {
List<PrismContainerValueWrapper<C>> pvWrappers = new ArrayList<>();
List<PrismContainerValueWrapper<ClassLoggerConfigurationType>> pvWrappers = new ArrayList<>();

for (PrismContainerValue<C> pcv : (List<PrismContainerValue<C>>)item.getValues()) {
for (PrismContainerValue<ClassLoggerConfigurationType> pcv : (List<PrismContainerValue<ClassLoggerConfigurationType>>)item.getValues()) {
if(canCreateValueWrapper(pcv)) {
PrismContainerValueWrapper<C> valueWrapper = createValueWrapper(itemWrapper, pcv, ValueStatus.NOT_CHANGED, context);
PrismContainerValueWrapper<ClassLoggerConfigurationType> valueWrapper = createValueWrapper(itemWrapper, pcv, ValueStatus.NOT_CHANGED, context);
pvWrappers.add(valueWrapper);
}
}

if (pvWrappers.isEmpty()) {
PrismContainerValue<C> prismValue = createNewValue(item);
PrismContainerValueWrapper<C> valueWrapper = createValueWrapper(itemWrapper, prismValue, ValueStatus.ADDED, context);
PrismContainerValue<ClassLoggerConfigurationType> prismValue = createNewValue(item);
PrismContainerValueWrapper<ClassLoggerConfigurationType> valueWrapper = createValueWrapper(itemWrapper, prismValue, ValueStatus.ADDED, context);
((ClassLoggerConfigurationType)valueWrapper.getRealValue()).setPackage(LOGGER_PROFILING);
pvWrappers.add(valueWrapper);
}
Expand All @@ -107,13 +108,13 @@ protected <ID extends ItemDefinition<PrismContainer<C>>> List<PrismContainerValu
}

@Override
public PrismContainerValueWrapper<C> createContainerValueWrapper(PrismContainerWrapper<C> objectWrapper,
PrismContainerValue<C> objectValue, ValueStatus status) {
public PrismContainerValueWrapper<ClassLoggerConfigurationType> createContainerValueWrapper(PrismContainerWrapper<ClassLoggerConfigurationType> objectWrapper,
PrismContainerValue<ClassLoggerConfigurationType> objectValue, ValueStatus status) {

ClassLoggerConfigurationType logger = (ClassLoggerConfigurationType) objectValue.getRealValue();
logger.setPackage(LOGGER_PROFILING);

return new ProfilingClassLoggerContainerValueWrapperImpl<C>(objectWrapper, objectValue, status);
return new ProfilingClassLoggerContainerValueWrapperImpl(objectWrapper, objectValue, status);
}

}
Expand Up @@ -30,6 +30,8 @@
import com.evolveum.midpoint.gui.api.registry.GuiComponentRegistry;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.page.admin.configuration.component.ProfilingLevel;
import com.evolveum.midpoint.gui.impl.prism.ProfilingClassLoggerContainerValueWrapperImpl;
import com.evolveum.midpoint.gui.impl.prism.ProfilingClassLoggerContainerWrapperImpl;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType;
Expand All @@ -42,7 +44,7 @@
*
*/
@Component
public class LoggingLevelPanelFactory implements GuiComponentFactory<PrismPropertyPanelContext<LoggingLevelType>>, Serializable {
public class ProfilingLoggerLevelPanelFactory implements GuiComponentFactory<PrismPropertyPanelContext<LoggingLevelType>>, Serializable {

private static final long serialVersionUID = 1L;

Expand All @@ -60,16 +62,7 @@ public void register() {

@Override
public <IW extends ItemWrapper> boolean match(IW wrapper) {
if(!wrapper.getPath().removeIds().equivalent(
ItemPath.create(
SystemConfigurationType.F_LOGGING,
LoggingConfigurationType.F_CLASS_LOGGER,
ClassLoggerConfigurationType.F_LEVEL))) {
return false;
}
ClassLoggerConfigurationType logger = (ClassLoggerConfigurationType)wrapper.getParent().getRealValue();
return logger != null && logger.getPackage() != null
&& logger.getPackage().equals(ProfilingClassLoggerWrapperFactoryImpl.LOGGER_PROFILING);
return wrapper.getParent() instanceof ProfilingClassLoggerContainerValueWrapperImpl && wrapper.getName().equals(ClassLoggerConfigurationType.F_LEVEL);
}

@Override
Expand Down
Expand Up @@ -16,29 +16,42 @@
package com.evolveum.midpoint.gui.impl.prism;

import com.evolveum.midpoint.gui.api.prism.PrismContainerWrapper;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.data.column.ColumnUtils;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType;

/**
* @author skublik
*
*/
public class ProfilingClassLoggerContainerValueWrapperImpl<C extends Containerable> extends PrismContainerValueWrapperImpl<C> {
public class ProfilingClassLoggerContainerValueWrapperImpl extends PrismContainerValueWrapperImpl<ClassLoggerConfigurationType> {

private static final long serialVersionUID = 1L;

private static final transient Trace LOGGER = TraceManager.getTrace(PrismReferenceValueWrapperImpl.class);

public ProfilingClassLoggerContainerValueWrapperImpl(PrismContainerWrapper<C> parent, PrismContainerValue<C> pcv, ValueStatus status) {
public ProfilingClassLoggerContainerValueWrapperImpl(PrismContainerWrapper<ClassLoggerConfigurationType> parent, PrismContainerValue<ClassLoggerConfigurationType> pcv, ValueStatus status) {
super(parent, pcv, status);
}

@Override
public String getDisplayName() {
return ColumnUtils.createStringResource("LoggingConfigPanel.profiling.entryExit").getString();
}

@Override
public PrismContainerValue<ClassLoggerConfigurationType> getValueToAdd() throws SchemaException {
PrismProperty<Object> level = getNewValue().findProperty(ClassLoggerConfigurationType.F_LEVEL);
if(level != null && !level.isEmpty() && level.getRealValue() != null) {
return super.getValueToAdd();
}
return null;
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.gui.impl.prism;

import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.PrismContainerWrapper;
import com.evolveum.midpoint.web.component.prism.ItemVisibility;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType;

/**
* @author skublik
*
*/
public class ProfilingClassLoggerPanel extends PrismContainerPanel<ClassLoggerConfigurationType> {

public ProfilingClassLoggerPanel(String id, IModel<PrismContainerWrapper<ClassLoggerConfigurationType>> model, ItemVisibilityHandler visibilitytHandler) {
super(id, model, itemWrapper -> checkVisibility(itemWrapper, visibilitytHandler));
}

private static ItemVisibility checkVisibility(ItemWrapper itemWrapper, ItemVisibilityHandler visibilitytHandler) {

if(itemWrapper.getName().equals(ClassLoggerConfigurationType.F_PACKAGE)) {
return ItemVisibility.HIDDEN;
}
return visibilitytHandler != null ? visibilitytHandler.isVisible(itemWrapper) : ItemVisibility.AUTO;
}
}
Expand Up @@ -315,7 +315,7 @@ public void onClick(AjaxRequestTarget target) {
}

private String getLocalizedPolyStringValue(){
return WebComponentUtil.getLocalizedPolyStringValue(getModelObject(), getPageBase());
return WebComponentUtil.getLocalizedPolyStringValue(getModelObject());
}

private String getKeyValue(){
Expand Down
Expand Up @@ -101,9 +101,11 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
* @author semancik
* @author skublik
*/
public class FocusProjectionsTabPanel<F extends FocusType> extends AbstractObjectTabPanel<F> {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -409,7 +411,7 @@ private void addSelectedAccountPerformed(AjaxRequestTarget target, List<Resource
shadow.setObjectClass(objectClass);
shadow.setIntent(accountDefinition.getObjectClassDefinition().getIntent());
shadow.setKind(accountDefinition.getObjectClassDefinition().getKind());

shadow.setName(new PolyStringType("New projection"));
getPrismContext().adopt(shadow);

Task task = getPageBase().createSimpleTask(OPERATION_ADD_ACCOUNT);
Expand Down
Expand Up @@ -192,6 +192,8 @@ CapabilitiesType.auxiliaryObjectClasses=Auxiliary Object Classes
CapabilitiesType.pagedSearch=Paged Search
CapabilitiesType.script=Script
CapabilitiesType.runAs=Run As
ClassLoggerConfigurationType.level=Level
ClassLoggerConfigurationType.package=Package
CleanupPoliciesType.auditRecords=Audit records
CleanupPoliciesType.closedTasks=Closed tasks
CleanupPoliciesType.closedCertificationCampaigns=Closed certification campaigns
Expand Down

0 comments on commit 430f298

Please sign in to comment.