Skip to content

Commit

Permalink
MID-4487 Role inducement - construction values are copied
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 6, 2018
1 parent 34805d9 commit 5b7e843
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 53 deletions.
Expand Up @@ -127,35 +127,20 @@ protected QName getRelation() {
initContainersPanel(form, pageBase);
}

protected void initContainersPanel(Form form, PageAdminObjectDetails<F> pageBase){
ContainerWrapperListFromObjectWrapperModel<Containerable, F> containerModel =
new ContainerWrapperListFromObjectWrapperModel<Containerable, F>(pageBase.getObjectModel(), collectContainersToShow());
protected void initContainersPanel(Form form, PageAdminObjectDetails<F> pageBase) {
ItemPath assignmentPath = getModelObject().getPath();
if (containerModel != null && containerModel.getObject() != null){
containerModel.getObject().forEach(container -> {
if (container.getName().equals(AssignmentType.F_CONSTRUCTION)) {
container.setAddContainerButtonVisible(true);
container.setShowEmpty(true, false);

ContainerWrapper associationWrapper = container.findContainerWrapper(container.getPath().append(ConstructionType.F_ASSOCIATION));
if (associationWrapper != null) {
associationWrapper.setRemoveContainerButtonVisible(true);
}
}
});
}

PrismPanel<Containerable> containers = new PrismPanel<Containerable>(ID_SPECIFIC_CONTAINERS, containerModel,
null, form,
itemWrapper -> getSpecificContainersItemsVisibility(itemWrapper, assignmentPath), pageBase) ;
add(containers);
PrismContainerPanel<PolicyRuleType> constraintsContainerPanel = new PrismContainerPanel(ID_SPECIFIC_CONTAINERS,
getSpecificContainerModel(), false, form,
itemWrapper -> getSpecificContainersItemsVisibility(itemWrapper, assignmentPath), pageBase);
constraintsContainerPanel.setOutputMarkupId(true);
add(constraintsContainerPanel);
}

protected ItemPath getAssignmentPath() {
return getModelObject().getContainerValue().getValue().asPrismContainerValue().getPath();
}

protected abstract List<ItemPath> collectContainersToShow();
protected abstract IModel<ContainerWrapper> getSpecificContainerModel();

protected boolean getSpecificContainersItemsVisibility(ItemWrapper itemWrapper, ItemPath parentAssignmentPath) {
if (ContainerWrapper.class.isAssignableFrom(itemWrapper.getClass())){
Expand Down
Expand Up @@ -18,12 +18,16 @@
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper;
import com.evolveum.midpoint.web.component.prism.ContainerWrapper;
import com.evolveum.midpoint.web.model.ContainerWrapperListFromObjectWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.web.component.form.Form;
import org.apache.wicket.model.Model;

/**
* TODO: is this class abstract or not?
Expand All @@ -38,16 +42,30 @@ public AbstractRoleAssignmentDetailsPanel(String id, Form<?> form, IModel<Contai


@Override
protected List<ItemPath> collectContainersToShow() {
List<ItemPath> pathsToShow = new ArrayList<>();
protected IModel<ContainerWrapper> getSpecificContainerModel() {
if (ConstructionType.COMPLEX_TYPE.equals(AssignmentsUtil.getTargetType(getModelObject().getContainerValue().getValue()))) {
pathsToShow.add(getAssignmentPath().append(AssignmentType.F_CONSTRUCTION));
ContainerWrapper<ConstructionType> constructionWrapper = getModelObject().findContainerWrapper(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION));
constructionWrapper.setAddContainerButtonVisible(true);
constructionWrapper.setShowEmpty(true, false);
if (constructionWrapper != null && constructionWrapper.getValues() != null) {
constructionWrapper.getValues().forEach(vw -> vw.setShowEmpty(true, false));
}
ContainerWrapper associationWrapper = constructionWrapper.findContainerWrapper(constructionWrapper.getPath().append(ConstructionType.F_ASSOCIATION));
if (associationWrapper != null) {
associationWrapper.setRemoveContainerButtonVisible(true);
}
return Model.of(constructionWrapper);
}

if (PersonaConstructionType.COMPLEX_TYPE.equals(AssignmentsUtil.getTargetType(getModelObject().getContainerValue().getValue()))) {
pathsToShow.add(getAssignmentPath().append(AssignmentType.F_PERSONA_CONSTRUCTION));
ContainerWrapper<PolicyRuleType> personasWrapper = getModelObject().findContainerWrapper(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_PERSONA_CONSTRUCTION));
if (personasWrapper != null && personasWrapper.getValues() != null) {
personasWrapper.getValues().forEach(vw -> vw.setShowEmpty(true, false));
}

return Model.of();
}
return pathsToShow;
return null;
}

}
Expand Up @@ -26,6 +26,7 @@

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.web.component.form.Form;
import org.apache.wicket.model.Model;

/**
* Created by honchar.
Expand All @@ -37,27 +38,6 @@ public PolicyRuleDetailsPanel(String id, Form<?> form, IModel<ContainerValueWrap
super(id, form, model);
}

protected void initContainersPanel(Form form, PageAdminObjectDetails<F> pageBase){
ContainerWrapperFromObjectWrapperModel<PolicyRuleType, F> policyRuleModel =
new ContainerWrapperFromObjectWrapperModel<PolicyRuleType, F>(pageBase.getObjectModel(),
getModelObject().getPath().append(AssignmentType.F_POLICY_RULE));

ContainerWrapper<PolicyRuleType> policyRules = policyRuleModel.getObject();
if (policyRules.getValues() != null){
policyRules.getValues().forEach(policyRuleContainerValueWrapper -> {
policyRuleContainerValueWrapper.setShowEmpty(true, false);
});
}
policyRules.setShowEmpty(true, false);
setRemoveContainerButtonVisibility(policyRules);
setAddContainerButtonVisibility(policyRules);

PrismContainerPanel<PolicyRuleType> constraintsContainerPanel = new PrismContainerPanel(ID_SPECIFIC_CONTAINERS, policyRuleModel,
false, form, null, pageBase);
constraintsContainerPanel.setOutputMarkupId(true);
add(constraintsContainerPanel);
}

private void setRemoveContainerButtonVisibility(ContainerWrapper<PolicyRuleType> policyRulesContainer){
ContainerWrapper constraintsContainer = policyRulesContainer.findContainerWrapper(new ItemPath(policyRulesContainer.getPath(), PolicyRuleType.F_POLICY_CONSTRAINTS));
if (constraintsContainer != null){
Expand All @@ -79,11 +59,15 @@ private void setAddContainerButtonVisibility(ContainerWrapper<PolicyRuleType> po
}

@Override
protected List<ItemPath> collectContainersToShow() {
List<ItemPath> containersToShow = new ArrayList<>();
containersToShow.add(getAssignmentPath().append(AssignmentType.F_POLICY_RULE));

return containersToShow;
protected IModel<ContainerWrapper> getSpecificContainerModel() {
ContainerWrapper<PolicyRuleType> policyRuleWrapper = getModelObject().findContainerWrapper(new ItemPath(FocusType.F_ASSIGNMENT, AssignmentType.F_POLICY_RULE));
if (policyRuleWrapper != null && policyRuleWrapper.getValues() != null) {
policyRuleWrapper.getValues().forEach(vw -> vw.setShowEmpty(true, false));
}
setRemoveContainerButtonVisibility(policyRuleWrapper);
setAddContainerButtonVisibility(policyRuleWrapper);

return Model.of(policyRuleWrapper);
}

}

0 comments on commit 5b7e843

Please sign in to comment.