Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Mar 12, 2020
2 parents 22f663f + 281baa7 commit 99882da
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 493 deletions.
Expand Up @@ -14,6 +14,7 @@
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.web.component.data.column.ImagePanel;
import com.evolveum.midpoint.web.component.util.EnableBehaviour;
Expand All @@ -31,7 +32,7 @@
/**
* Created by honchar
*/
public class LinkedReferencePanel<O extends ObjectType> extends BasePanel<ObjectReferenceType> {
public class LinkedReferencePanel<O extends ObjectType, R extends Referencable> extends BasePanel<R> {
private static final long serialVersionUID = 1L;

private static final String ID_ICON = "icon";
Expand All @@ -43,7 +44,7 @@ public class LinkedReferencePanel<O extends ObjectType> extends BasePanel<Object

IModel<ObjectType> referencedObjectModel = null;

public LinkedReferencePanel(String id, IModel<ObjectReferenceType> objectReferenceModel){
public LinkedReferencePanel(String id, IModel<R> objectReferenceModel){
super(id, objectReferenceModel);
}

Expand All @@ -65,10 +66,11 @@ protected ObjectType load() {
&& getModelObject().asReferenceValue().getObject().asObjectable() instanceof ObjectType ){
return (ObjectType)getModelObject().asReferenceValue().getObject().asObjectable();
}
if (StringUtils.isNotEmpty(getModelObject().getOid()) && getModelObject().getType() != null) {
if (StringUtils.isNotEmpty(getModelObject().getOid()) && getModelObject().getType() != null &&
getModelObject() instanceof ObjectReferenceType) {
PageBase pageBase = LinkedReferencePanel.this.getPageBase();
OperationResult result = new OperationResult(OPERATION_LOAD_REFERENCED_OBJECT);
PrismObject<ObjectType> referencedObject = WebModelServiceUtils.loadObject(getModelObject(), pageBase,
PrismObject<ObjectType> referencedObject = WebModelServiceUtils.loadObject((ObjectReferenceType) getModelObject(), pageBase,
pageBase.createSimpleTask(OPERATION_LOAD_REFERENCED_OBJECT), result);
return referencedObject != null ? referencedObject.asObjectable() : null;
}
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import java.util.ArrayList;
Expand Down Expand Up @@ -98,6 +99,10 @@ public class PageCaseWorkItem extends PageAdminCaseWorkItems {
private WorkItemId workItemId;
private PageParameters pageParameters;

public PageCaseWorkItem() {
this(null);
}

public PageCaseWorkItem(CaseWorkItemType workItem) {
this(workItem, null);
}
Expand All @@ -108,7 +113,12 @@ public PageCaseWorkItem(CaseWorkItemType workItem, PageParameters parameters) {
caseWorkItemModel = new LoadableModel<CaseWorkItemType>(false) {
@Override
protected CaseWorkItemType load() {
return workItem;
if (workItem != null) {
return workItem;
} else {
getSession().error("Workitem model cannot be null");
throw redirectBackViaRestartResponseException();
}
}
};

Expand Down
Expand Up @@ -8,11 +8,7 @@

import static com.evolveum.midpoint.model.api.util.DashboardUtils.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -41,27 +37,10 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuditSearchType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetDataFieldTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetPresentationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetSourceTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetVariationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.IconType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.IntegerStatType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectCollectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

/**
Expand Down Expand Up @@ -99,77 +78,77 @@ public DashboardWidget createWidgetData(DashboardWidgetType widget, Task task, O
return data;
}

private DisplayType combinateDisplay(DisplayType display, DisplayType variationDisplay) {
DisplayType combinatedDisplay = new DisplayType();
private DisplayType combineDisplay(DisplayType display, DisplayType variationDisplay) {
DisplayType combinedDisplay = new DisplayType();
if (variationDisplay == null) {
return display;
}
if(display == null) {
if (display == null) {
return variationDisplay;
}
if(StringUtils.isBlank(variationDisplay.getColor())) {
combinatedDisplay.setColor(display.getColor());
if (StringUtils.isBlank(variationDisplay.getColor())) {
combinedDisplay.setColor(display.getColor());
} else {
combinatedDisplay.setColor(variationDisplay.getColor());
combinedDisplay.setColor(variationDisplay.getColor());
}
if(StringUtils.isBlank(variationDisplay.getCssClass())) {
combinatedDisplay.setCssClass(display.getCssClass());
if (StringUtils.isBlank(variationDisplay.getCssClass())) {
combinedDisplay.setCssClass(display.getCssClass());
} else {
combinatedDisplay.setCssClass(variationDisplay.getCssClass());
combinedDisplay.setCssClass(variationDisplay.getCssClass());
}
if(StringUtils.isBlank(variationDisplay.getCssStyle())) {
combinatedDisplay.setCssStyle(display.getCssStyle());
if (StringUtils.isBlank(variationDisplay.getCssStyle())) {
combinedDisplay.setCssStyle(display.getCssStyle());
} else {
combinatedDisplay.setCssStyle(variationDisplay.getCssStyle());
combinedDisplay.setCssStyle(variationDisplay.getCssStyle());
}
if(variationDisplay.getHelp() == null) {
combinatedDisplay.setHelp(display.getHelp());
if (variationDisplay.getHelp() == null) {
combinedDisplay.setHelp(display.getHelp());
} else {
combinatedDisplay.setHelp(variationDisplay.getHelp());
combinedDisplay.setHelp(variationDisplay.getHelp());
}
if(variationDisplay.getLabel() == null) {
combinatedDisplay.setLabel(display.getLabel());
if (variationDisplay.getLabel() == null) {
combinedDisplay.setLabel(display.getLabel());
} else {
combinatedDisplay.setLabel(variationDisplay.getLabel());
combinedDisplay.setLabel(variationDisplay.getLabel());
}
if(variationDisplay.getSingularLabel() == null) {
combinatedDisplay.setSingularLabel(display.getSingularLabel());
if (variationDisplay.getSingularLabel() == null) {
combinedDisplay.setSingularLabel(display.getSingularLabel());
} else {
combinatedDisplay.setSingularLabel(variationDisplay.getSingularLabel());
combinedDisplay.setSingularLabel(variationDisplay.getSingularLabel());
}
if(variationDisplay.getPluralLabel() == null) {
combinatedDisplay.setPluralLabel(display.getPluralLabel());
if (variationDisplay.getPluralLabel() == null) {
combinedDisplay.setPluralLabel(display.getPluralLabel());
} else {
combinatedDisplay.setPluralLabel(variationDisplay.getPluralLabel());
combinedDisplay.setPluralLabel(variationDisplay.getPluralLabel());
}
if(variationDisplay.getTooltip() == null) {
combinatedDisplay.setTooltip(display.getTooltip());
if (variationDisplay.getTooltip() == null) {
combinedDisplay.setTooltip(display.getTooltip());
} else {
combinatedDisplay.setTooltip(variationDisplay.getTooltip());
combinedDisplay.setTooltip(variationDisplay.getTooltip());
}
if(variationDisplay.getIcon() == null) {
combinatedDisplay.setIcon(display.getIcon());
} else if(display.getIcon() != null){
if (variationDisplay.getIcon() == null) {
combinedDisplay.setIcon(display.getIcon());
} else if (display.getIcon() != null) {
IconType icon = new IconType();
if(StringUtils.isBlank(variationDisplay.getIcon().getCssClass())) {
if (StringUtils.isBlank(variationDisplay.getIcon().getCssClass())) {
icon.setCssClass(display.getIcon().getCssClass());
} else {
icon.setCssClass(variationDisplay.getIcon().getCssClass());
}
if(StringUtils.isBlank(variationDisplay.getIcon().getColor())) {
if (StringUtils.isBlank(variationDisplay.getIcon().getColor())) {
icon.setColor(display.getIcon().getColor());
} else {
icon.setColor(variationDisplay.getIcon().getColor());
}
if(StringUtils.isBlank(variationDisplay.getIcon().getImageUrl())) {
if (StringUtils.isBlank(variationDisplay.getIcon().getImageUrl())) {
icon.setImageUrl(display.getIcon().getImageUrl());
} else {
icon.setImageUrl(variationDisplay.getIcon().getImageUrl());
}
combinatedDisplay.setIcon(icon);
combinedDisplay.setIcon(icon);
}

return combinatedDisplay;
return combinedDisplay;
}

public DashboardWidgetSourceTypeType getSourceType(DashboardWidgetType widget) {
Expand Down Expand Up @@ -227,7 +206,7 @@ private String generateNumberMessageForAuditSearch(DashboardWidgetType widget, D
return null;
}

Map<String, Object> parameters = new HashMap<String, Object>();
Map<String, Object> parameters = new HashMap<>();
String query = getQueryForCount(createQuery(collection,
parameters, false, clock));
LOGGER.debug("Parameters for select: " + parameters);
Expand All @@ -237,7 +216,7 @@ private String generateNumberMessageForAuditSearch(DashboardWidgetType widget, D
if(auditSearch.getDomainQuery() == null) {
LOGGER.error("DomainQuery of auditSearch is not defined");
} else {
parameters = new HashMap<String, Object>();
parameters = new HashMap<>();
query = getQueryForCount(createQuery(collection,
parameters, true, clock));
LOGGER.debug("Parameters for select: " + parameters);
Expand All @@ -251,7 +230,7 @@ private String generateNumberMessageForAuditSearch(DashboardWidgetType widget, D

private String getQueryForCount(String query) {
int index = query.toLowerCase().indexOf("from");
query = "select count (*) " + query.substring(index);
query = "select count(*) " + query.substring(index);
query = query.split("order")[0];
LOGGER.debug("Query for select: " + query);
return query;
Expand All @@ -273,7 +252,7 @@ private String generateNumberMessageForCollection(DashboardWidgetType widget, Da

Collection<EvaluatedPolicyRule> evalPolicyRules = modelInteractionService.evaluateCollectionPolicyRules(
valueCollection.asPrismObject(), compiledCollection, null, task, task.getResult());
Collection<String> policySituations = new ArrayList<String>();
Collection<String> policySituations = new ArrayList<>();
for(EvaluatedPolicyRule evalPolicyRule : evalPolicyRules) {
if(!evalPolicyRule.getAllTriggers().isEmpty()) {
policySituations.add(evalPolicyRule.getPolicySituation());
Expand Down Expand Up @@ -317,7 +296,7 @@ private static IntegerStatType generateIntegerStat(Integer value, Integer domain
}

private String generateNumberMessage(DashboardWidgetType widget, ExpressionVariables variables, DashboardWidget data) {
Map<DashboardWidgetDataFieldTypeType, String> numberMessagesParts = new HashMap<DashboardWidgetDataFieldTypeType, String>();
Map<DashboardWidgetDataFieldTypeType, String> numberMessagesParts = new HashMap<>();
widget.getPresentation().getDataField().forEach(dataField -> {
switch(dataField.getFieldType()) {

Expand Down Expand Up @@ -375,7 +354,7 @@ private void evaluateVariation(DashboardWidgetType widget, ExpressionVariables v

if(usingVariation != null && usingVariation.getRealValue() != null
&& usingVariation.getRealValue().equals(Boolean.TRUE)) {
data.setDisplay(combinateDisplay(widget.getDisplay(), variation.getDisplay()));
data.setDisplay(combineDisplay(widget.getDisplay(), variation.getDisplay()));
} else {
data.setDisplay(widget.getDisplay());
}
Expand Down Expand Up @@ -416,8 +395,7 @@ public ObjectCollectionType getObjectCollectionType(DashboardWidgetType widget,
return null;
}
ObjectReferenceType ref = widget.getData().getCollection().getCollectionRef();
ObjectCollectionType collection = objectResolver.resolve(ref, ObjectCollectionType.class, null, "resolving collection from "+widget, task, result);
return collection;
return objectResolver.resolve(ref, ObjectCollectionType.class, null, "resolving collection from "+widget, task, result);
}

private ObjectType getObjectFromObjectRef(DashboardWidgetType widget, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Expand Down

0 comments on commit 99882da

Please sign in to comment.