Skip to content

Commit

Permalink
Merge branch 'support-4.0' of https://github.com/Evolveum/midpoint in…
Browse files Browse the repository at this point in the history
…to support-4.0
  • Loading branch information
KaterynaHonchar committed Jun 5, 2020
2 parents 654a2b4 + 9581091 commit 808391c
Show file tree
Hide file tree
Showing 30 changed files with 527 additions and 275 deletions.
2 changes: 1 addition & 1 deletion build-system/pom.xml
Expand Up @@ -391,7 +391,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.6</version>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Expand Up @@ -11,10 +11,13 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.assignment.AssignmentPanel;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -149,33 +152,43 @@ protected String createImageModel() {

private IModel<String> createHeaderModel() {
// TODO: align with DisplayNameModel
if (getModelObject() == null){
return Model.of("");
}
if (ObjectType.class.isAssignableFrom(getModelObject().getClass())) {
return Model.of(WebComponentUtil.getEffectiveName((ObjectType) getModelObject(), AbstractRoleType.F_DISPLAY_NAME));
}
if (isObjectPolicyConfigurationType()) {
QName typeValue = WebComponentUtil.getValue(getModel().getObject().asPrismContainerValue(), ObjectPolicyConfigurationType.F_TYPE, QName.class);
ObjectReferenceType objectTemplate = ((ObjectPolicyConfigurationType)getModel().getObject()).getObjectTemplateRef();
if(objectTemplate == null || objectTemplate.getTargetName() == null){
return Model.of("");
return new ReadOnlyModel<String>(() -> {
if (getModelObject() == null) {
return "";
}
String objectTemplateNameValue = objectTemplate.getTargetName().toString();
StringBuilder sb = new StringBuilder();
if(typeValue != null) {
sb.append(typeValue.getLocalPart()).append(" - ");
if (ObjectType.class.isAssignableFrom(getModelObject().getClass())) {
return WebComponentUtil.getEffectiveName((ObjectType) getModelObject(), AbstractRoleType.F_DISPLAY_NAME);
}
sb.append(objectTemplateNameValue);
return Model.of(sb.toString());
}
PrismProperty<PolyString> name = getModelObject().asPrismContainerValue().findProperty(ObjectType.F_NAME);
if (name == null || name.isEmpty()) {
return Model.of("");
}
return Model.of(WebComponentUtil.getTranslatedPolyString(name.getRealValue()));
if (isObjectPolicyConfigurationType()) {
QName typeValue = WebComponentUtil.getValue(getModel().getObject().asPrismContainerValue(), ObjectPolicyConfigurationType.F_TYPE, QName.class);
ObjectReferenceType objectTemplate = ((ObjectPolicyConfigurationType) getModel().getObject()).getObjectTemplateRef();
if (objectTemplate == null || objectTemplate.getTargetName() == null) {
return "";
}
String objectTemplateNameValue = objectTemplate.getTargetName().toString();
StringBuilder sb = new StringBuilder();
if (typeValue != null) {
sb.append(typeValue.getLocalPart()).append(" - ");
}
sb.append(objectTemplateNameValue);
return sb.toString();
}
PrismProperty<?> name = getModelObject().asPrismContainerValue().findProperty(ObjectType.F_NAME);
if (name == null || name.isEmpty()) {
return "";
}

if (QNameUtil.match(DOMUtil.XSD_STRING, name.getDefinition().getTypeName())) {
return (String) name.getRealValue();
} else if (QNameUtil.match(PolyStringType.COMPLEX_TYPE, name.getDefinition().getTypeName())) {
return WebComponentUtil.getTranslatedPolyString((PolyString) name.getRealValue());
}

return name.getRealValue().toString();
});
}


private IModel<String> createIdentifierModel() {
if (getModelObject() == null){
return Model.of("");
Expand Down
Expand Up @@ -7,10 +7,12 @@

package com.evolveum.midpoint.gui.api.component.result;

import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.Visitable;
import com.evolveum.midpoint.prism.Visitor;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
Expand All @@ -20,13 +22,11 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.Validate;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;

Expand Down Expand Up @@ -59,7 +59,7 @@ public class OpResult implements Serializable, Visitable {
private List<OpResult> subresults;
private OpResult parent;
private int count;
private String xml;
private IModel<String> xml;
private LocalizableMessage userFriendlyMessage;

// we assume there is at most one background task created (TODO revisit this assumption)
Expand Down Expand Up @@ -165,17 +165,28 @@ public static OpResult getOpResult(PageBase page, OperationResult result) {
opResult.caseOid = caseOid;
}

if (opResult.parent == null) {
opResult.xml = createXmlModel(result, page);
}
return opResult;
}

private static IModel<String> createXmlModel(OperationResult result, PageBase page) {
try {
OperationResultType resultType = result.createOperationResultType();
ObjectFactory of = new ObjectFactory();
opResult.xml = page.getPrismContext().xmlSerializer().serialize(of.createOperationResult(resultType));
} catch (SchemaException | RuntimeException ex) {
return new ReadOnlyModel<String>(() -> {
try {
OperationResultType resultType = result.createOperationResultType();
return page.getPrismContext().xmlSerializer().serializeAnyData(resultType, SchemaConstants.C_RESULT);
} catch (SchemaException e) {
throw new TunnelException(e);
}
});
} catch (RuntimeException ex) {
String m = "Can't create xml: " + ex;
// error(m);
opResult.xml = "<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>";
return Model.of("<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>");
// throw ex;
}
return opResult;
}

// This method should be called along with getOpResult for root operationResult. However, it might take some time,
Expand Down Expand Up @@ -301,8 +312,12 @@ public int getCount() {
return count;
}

public boolean isParent() {
return parent == null;
}

public String getXml() {
return xml;
return xml.getObject();
}

public String getBackgroundTaskOid() {
Expand Down
Expand Up @@ -7,16 +7,9 @@

package com.evolveum.midpoint.gui.api.component.result;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -48,6 +41,14 @@
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
* @author katkav
*/
Expand Down Expand Up @@ -263,6 +264,7 @@ public File getObject() {
}

});
downloadXml.add(new VisibleBehaviour(() -> getModelObject().isParent()));
downloadXml.setDeleteAfterDownload(true);
box.add(downloadXml);
}
Expand Down
Expand Up @@ -1251,7 +1251,7 @@ public static <C extends Containerable> String getDisplayName(PrismContainerValu
}
} else if (prismContainerValue.canRepresent(AssignmentType.class)) {
AssignmentType assignmentType = (AssignmentType) prismContainerValue.asContainerable();
if (assignmentType.getTargetRef() != null) {
if (isNotEmpty(assignmentType.getTargetRef())) {
ObjectReferenceType assignmentTargetRef = assignmentType.getTargetRef();
displayName = getName(assignmentTargetRef) + " - " + normalizeRelation(assignmentTargetRef.getRelation()).getLocalPart();
} else {
Expand Down Expand Up @@ -1353,6 +1353,17 @@ public static <C extends Containerable> String getDisplayName(PrismContainerValu
return escaped;
}

private static boolean isNotEmpty(ObjectReferenceType ref) {
if (ref == null) {
return false;
}
if (ref.getObject() != null) {
return true;
}

return ref.getOid() != null;
}

public static QName normalizeRelation(QName relation) {
return getRelationRegistry().normalizeRelation(relation);
}
Expand Down Expand Up @@ -3956,6 +3967,14 @@ public static void dropPowerOfAttorneyIfRequested(OperationResult result, PrismO
}
}

public static <T> T runUnderPowerOfAttorneyIfNeeded(CheckedProducer<T> producer, PrismObject<UserType> powerDonor,
PageBase pageBase, Task task, OperationResult result) throws CommonException {
if (powerDonor != null) {
return pageBase.getModelInteractionService().runUnderPowerOfAttorneyChecked(producer, powerDonor, task, result);
} else {
return producer.get();
}
}

@NotNull
public static List<SceneDto> computeChangesCategorizationList(ChangesByState changesByState, ObjectReferenceType objectRef,
Expand Down
Expand Up @@ -53,11 +53,15 @@ public PrismContainerValueWrapper<ConstructionType> createContainerValueWrapper(
PrismObject resource = constructionType.getResourceRef().asReferenceValue().getObject();
if (resource != null) {
constructionValueWrapper.setResource(resource);
return constructionValueWrapper;
}
return constructionValueWrapper;

}

ObjectReferenceType resourceRef = constructionType.getResourceRef();
if (resourceRef.getOid() == null) {
return constructionValueWrapper;
}

PrismObject<ResourceType> resource = null;
try {
Expand Down
Expand Up @@ -7,6 +7,8 @@

package com.evolveum.midpoint.gui.impl.factory;

import com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel;
import com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel;
Expand All @@ -28,6 +30,8 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
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.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
Expand All @@ -46,7 +50,7 @@
@Component
public class ResourceAttributeRefPanelFactory extends AbstractGuiComponentFactory<ItemPathType> implements Serializable {

private static final String DOT_CLASS = ResourceAttributeRefPanelFactory.class.getName() + ".";
private static final transient Trace LOGGER = TraceManager.getTrace(ResourceAttributeRefPanelFactory.class);

@PostConstruct
public void register() {
Expand All @@ -72,10 +76,22 @@ public Collection<ItemName> loadChoices() {

@Override
public <IW extends ItemWrapper> boolean match(IW wrapper) {
ItemPath assignmetnPath = ItemPath.create(AssignmentHolderType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE, ResourceAttributeDefinitionType.F_REF);
ItemPath inducementPath = ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE, ResourceAttributeDefinitionType.F_REF);
ItemPath wrapperPath = wrapper.getPath().removeIds();
return isAssignmentAttributeOrAssociation(wrapperPath) || isInducementAttributeOrAssociation(wrapperPath);
}

private boolean isAssignmentAttributeOrAssociation(ItemPath wrapperPath) {
ItemPath assignmentAttributePath = ItemPath.create(AssignmentHolderType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE, ResourceAttributeDefinitionType.F_REF);
ItemPath assignmetnAssociationPath = ItemPath.create(AssignmentHolderType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ASSOCIATION, ResourceAttributeDefinitionType.F_REF);

return assignmentAttributePath.equivalent(wrapperPath) || assignmetnAssociationPath.equivalent(wrapperPath);
}

private boolean isInducementAttributeOrAssociation(ItemPath wrapperPath) {
ItemPath inducementAttributePath = ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE, ResourceAttributeDefinitionType.F_REF);
ItemPath inducementAssociationPath = ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ASSOCIATION, ResourceAttributeDefinitionType.F_REF);

return assignmetnPath.equivalent(wrapper.getPath().removeIds()) || inducementPath.equivalent(wrapper.getPath().removeIds());
return inducementAttributePath.equivalent(wrapperPath) || inducementAssociationPath.equivalent(wrapperPath);
}

private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
Expand All @@ -84,48 +100,56 @@ private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ct
PrismPropertyWrapper wrapper = ctx.unwrapWrapperModel();
//attribute/ref
if (wrapper == null) {
return new ArrayList<>();
return Collections.emptyList();
}

//attribute value
if (wrapper.getParent() == null) {
return new ArrayList<>();
return Collections.emptyList();
}

//attribute
ItemWrapper attributeWrapper = wrapper.getParent().getParent();
if (attributeWrapper == null) {
return new ArrayList<>();
return Collections.emptyList();
}

PrismContainerValueWrapper itemWrapper = attributeWrapper.getParent();

if (itemWrapper == null) {
return new ArrayList<>();
return Collections.emptyList();
}

if (!(itemWrapper instanceof ConstructionValueWrapper)) {
return new ArrayList<>();
return Collections.emptyList();
}

ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;


try {
RefinedResourceSchema schema = constructionWrapper.getResourceSchema();
ObjectClassComplexTypeDefinition ocd = schema.findObjectClassDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
Collection<? extends ResourceAttributeDefinition> attrDefs = ocd.getAttributeDefinitions();
if (schema == null) {
return new ArrayList<>();
}
RefinedObjectClassDefinition rOcd = schema.getRefinedDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
if (rOcd == null) {
return Collections.emptyList();
}

if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
Collection<RefinedAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
return associationDefs.stream().map(association -> association.getName()).collect(Collectors.toList());
}

List<ItemName> attributes = attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
return attributes;
Collection<? extends ResourceAttributeDefinition> attrDefs = rOcd.getAttributeDefinitions();
return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());

} catch (SchemaException e) {
e.printStackTrace();
LOGGER.warn("Cannot get resource attribute definitions");
}


return new ArrayList<>();

return Collections.emptyList();

}

Expand Down

0 comments on commit 808391c

Please sign in to comment.