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
KaterynaHonchar committed Apr 16, 2020
2 parents 87cf8b6 + b0c86bf commit aefe294
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 505 deletions.
Expand Up @@ -6,17 +6,15 @@
*/
package com.evolveum.midpoint.gui.impl.component;

import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.path.ItemPathDto;
import com.evolveum.midpoint.gui.api.component.path.ItemPathPanel;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType;

import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;

public class VariableBindingDefinitionTypePanel extends BasePanel<VariableBindingDefinitionType> {

private static final String ID_PATH_LABEL = "pathLabel";
Expand All @@ -43,6 +41,11 @@ protected void onUpdate(ItemPathDto itemPathDto) {
newPathtype = new ItemPathType(newPath);
}

VariableBindingDefinitionType var = VariableBindingDefinitionTypePanel.this.getModelObject();
if (var == null) {
var = new VariableBindingDefinitionType();
VariableBindingDefinitionTypePanel.this.getModel().setObject(var);
}
VariableBindingDefinitionTypePanel.this.getModelObject().setPath(newPathtype);
}
};
Expand Down
Expand Up @@ -51,8 +51,9 @@ public PrismContainerValueWrapper<ConstructionType> createContainerValueWrapper(
PrismObject resource = constructionType.getResourceRef().asReferenceValue().getObject();
if (resource != null) {
constructionValueWrapper.setResource(resource);
return constructionValueWrapper;
}
return constructionValueWrapper;

}

ObjectReferenceType resourceRef = constructionType.getResourceRef();
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
Expand Up @@ -36,7 +36,9 @@ public void setResource(PrismObject<ResourceType> resource) {

public RefinedResourceSchema getResourceSchema() throws SchemaException {
if (resourceSchema == null) {
resourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
if (resource != null) {
resourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
}
}

return resourceSchema;
Expand Down

0 comments on commit aefe294

Please sign in to comment.