Skip to content

Commit

Permalink
model changes for assignments and policy rules tab. still not finished
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 1, 2017
1 parent ebc43a4 commit 68476c1
Show file tree
Hide file tree
Showing 37 changed files with 577 additions and 1,059 deletions.
Expand Up @@ -60,6 +60,9 @@ private void initLayout() {
}

private String createImageModel() {
if (getModelObject() == null){
return "";
}
if (ObjectType.class.isAssignableFrom(getModelObject().getClass())) {
return WebComponentUtil.createDefaultIcon((ObjectType) getModelObject());
}
Expand All @@ -74,6 +77,9 @@ private IModel<String> getAdditionalNameLabelStyleClass() {

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));
}
Expand Down
Expand Up @@ -20,6 +20,7 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.web.component.prism.*;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
Expand All @@ -37,12 +38,6 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.form.Form;
import com.evolveum.midpoint.web.component.prism.ContainerValuePanel;
import com.evolveum.midpoint.web.component.prism.ContainerWrapper;
import com.evolveum.midpoint.web.component.prism.ItemWrapper;
import com.evolveum.midpoint.web.component.prism.PrismContainerPanel;
import com.evolveum.midpoint.web.component.prism.PrismPanel;
import com.evolveum.midpoint.web.component.prism.PropertyOrReferenceWrapper;
import com.evolveum.midpoint.web.model.ContainerValueWrapperFromObjectWrapperModel;
import com.evolveum.midpoint.web.model.ContainerWrapperFromObjectWrapperModel;
import com.evolveum.midpoint.web.model.ContainerWrapperListFromObjectWrapperModel;
Expand All @@ -56,17 +51,15 @@
/**
* Created by honchar
*/
public abstract class AbstractAssignmentDetailsPanel<F extends FocusType> extends BasePanel<AssignmentDto>{
public abstract class AbstractAssignmentDetailsPanel<F extends FocusType> extends BasePanel<ContainerValueWrapper<AssignmentType>>{
private static final long serialVersionUID = 1L;

private final static String ID_DISPLAY_NAME = "displayName";
private final static String ID_ACTIVATION_PANEL = "activationPanel";
private final static String ID_CONTAINERS = "otherContainers";

public AbstractAssignmentDetailsPanel(String id, Form<?> form, IModel<AssignmentDto> assignmentModel){
public AbstractAssignmentDetailsPanel(String id, Form<?> form, IModel<ContainerValueWrapper<AssignmentType>> assignmentModel){
super(id, assignmentModel);


}

@Override
Expand All @@ -83,19 +76,18 @@ protected <C extends Containerable> void initLayout(){

@Override
public C getObject() {
AssignmentDto assignemtn = getModelObject();
if (assignemtn.isAssignableObject()) {
AssignmentType assignment = getModelObject().getContainerValue().getValue();
if (AssignmentsUtil.isAssignableObject(assignment)) {
Task task = getPageBase().createSimpleTask("Load target");
com.evolveum.midpoint.schema.result.OperationResult result = task.getResult();
return (C) WebModelServiceUtils.loadObject(getModelObject().getAssignment().getTargetRef(), getPageBase(), task, result).asObjectable();
return (C) WebModelServiceUtils.loadObject(assignment.getTargetRef(), getPageBase(), task, result).asObjectable();
}
AssignmentType assignmentType = assignemtn.getAssignment();
if (assignmentType.getConstruction() != null) {
return (C) assignmentType.getConstruction();
} else if (assignmentType.getPersonaConstruction() != null) {
return (C) assignmentType.getPersonaConstruction();
} else if (assignmentType.getPolicyRule() !=null) {
return (C) assignmentType.getPolicyRule();
if (assignment.getConstruction() != null) {
return (C) assignment.getConstruction();
} else if (assignment.getPersonaConstruction() != null) {
return (C) assignment.getPersonaConstruction();
} else if (assignment.getPolicyRule() !=null) {
return (C) assignment.getPolicyRule();
}

return null;
Expand All @@ -112,12 +104,12 @@ public C getObject() {
PageAdminObjectDetails<F> pageBase = (PageAdminObjectDetails<F>)getPageBase();

ItemPath assignmentPath = getAssignmentPath();
ContainerValueWrapperFromObjectWrapperModel<AssignmentType, F> assignmentModel =
new ContainerValueWrapperFromObjectWrapperModel<AssignmentType, F>(pageBase.getObjectModel(), assignmentPath);
// ContainerValueWrapperFromObjectWrapperModel<AssignmentType, F> assignmentModel =
// new ContainerValueWrapperFromObjectWrapperModel<AssignmentType, F>(pageBase.getObjectModel(), assignmentPath);

Form form = new Form<>("form");

ContainerValuePanel<AssignmentType> assignmentPanel = new ContainerValuePanel("basic", assignmentModel, true, form, itemWrapper -> getAssignmentBasicTabVisibity(itemWrapper, assignmentPath), pageBase);
ContainerValuePanel<AssignmentType> assignmentPanel = new ContainerValuePanel("basic", getModel(), true, form, itemWrapper -> getAssignmentBasicTabVisibity(itemWrapper, assignmentPath), pageBase);
add(assignmentPanel);


Expand All @@ -133,13 +125,13 @@ public C getObject() {
}

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

protected abstract List<ItemPath> collectContainersToShow();

private boolean getAssignmentBasicTabVisibity(ItemWrapper itemWrapper, ItemPath parentAssignmentPath) {
AssignmentType assignment = getModelObject().getAssignment();
AssignmentType assignment = getModelObject().getContainerValue().getValue();
ObjectReferenceType targetRef = assignment.getTargetRef();
List<ItemPath> pathsToHide = new ArrayList<>();
QName targetType = null;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.prism.path.ItemPath;
Expand Down Expand Up @@ -32,19 +33,19 @@ public class AbstractRoleAssignmentDetailsPanel<F extends FocusType> extends Abs
hiddenItems.add(AssignmentType.F_POLICY_RULE);
};

public AbstractRoleAssignmentDetailsPanel(String id, Form<?> form, IModel<AssignmentDto> assignmentModel) {
public AbstractRoleAssignmentDetailsPanel(String id, Form<?> form, IModel<ContainerValueWrapper<AssignmentType>> assignmentModel) {
super(id, form, assignmentModel);
}


@Override
protected List<ItemPath> collectContainersToShow() {
List<ItemPath> pathsToShow = new ArrayList<>();
if (ConstructionType.COMPLEX_TYPE.equals(getModelObject().getTargetType())) {
if (ConstructionType.COMPLEX_TYPE.equals(AssignmentsUtil.getTargetType(getModelObject().getContainerValue().getValue()))) {
pathsToShow.add(getAssignmentPath().append(AssignmentType.F_CONSTRUCTION));
}

if (PersonaConstructionType.COMPLEX_TYPE.equals(getModelObject().getTargetType())) {
if (PersonaConstructionType.COMPLEX_TYPE.equals(AssignmentsUtil.getTargetType(getModelObject().getContainerValue().getValue()))) {
pathsToShow.add(getAssignmentPath().append(AssignmentType.F_PERSONA_CONSTRUCTION));
}
return pathsToShow;
Expand Down
Expand Up @@ -21,7 +21,14 @@
import java.util.Map;

import javax.xml.namespace.QName;

import javax.xml.validation.Schema;

import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper;
import com.evolveum.midpoint.web.component.prism.ContainerWrapper;
import com.evolveum.midpoint.web.component.prism.ContainerWrapperFactory;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
Expand Down Expand Up @@ -56,10 +63,6 @@
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.session.UserProfileStorage.TableId;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

/**
* Created by honchar.
Expand All @@ -72,8 +75,9 @@ public class AbstractRoleAssignmentPanel extends AssignmentPanel {
private static final String ID_SHOW_ALL_ASSIGNMENTS_BUTTON = "showAllAssignmentsButton";


public AbstractRoleAssignmentPanel(String id, IModel<List<AssignmentDto>> assignmentsModel){
super(id, assignmentsModel);
public AbstractRoleAssignmentPanel(String id, IModel<List<ContainerValueWrapper<AssignmentType>>> assignmentsModel,
ContainerWrapper assignmentContainerWrapper){
super(id, assignmentsModel, assignmentContainerWrapper);
}

protected void initCustomLayout(WebMarkupContainer assignmentsContainer){
Expand Down Expand Up @@ -149,106 +153,33 @@ protected <T extends ObjectType> void addSelectedAssignmentsPerformed(AjaxReques
return;
}
for (T object : assignmentsList){
AssignmentType assignment = ObjectTypeUtil.createAssignmentTo(object.asPrismObject(), relation);
AssignmentDto dto = new AssignmentDto(assignment, UserDtoStatus.ADD);
getModelObject().add(0, dto);
try {
AssignmentType assignment = ObjectTypeUtil.createAssignmentTo(object.asPrismObject(), relation);
assignment.asPrismContainerValue().applyDefinition(assignmentContainerWrapper.getItem().getDefinition(), false);
ContainerValueWrapper<AssignmentType> newAssignmentContainerWrapper = assignmentContainerWrapper.createItem(false);
newAssignmentContainerWrapper.setStatus(ValueStatus.ADDED);
newAssignmentContainerWrapper.getContainerValue().getValue().setupContainerValue(assignment.asPrismContainerValue());
getModelObject().add(0, newAssignmentContainerWrapper);
} catch (SchemaException ex){

}
}

refreshTable(target);

}

protected List<IColumn<AssignmentDto, String>> initColumns() {
List<IColumn<AssignmentDto, String>> columns = new ArrayList<>();

columns.add(new PropertyColumn<AssignmentDto, String>(createStringResource("ObjectReferenceType.relation"), AssignmentDto.F_RELATION_TYPE));

//commented since these columns are not used
// columns.add(new DirectlyEditablePropertyColumn<AssignmentEditorDto>(createStringResource("AssignmentDataTablePanel.descriptionColumnName"), AssignmentEditorDto.F_DESCRIPTION){
// private static final long serialVersionUID = 1L;
//
// @Override
// public void populateItem(Item<ICellPopulator<AssignmentEditorDto>> cellItem, String componentId,
// final IModel<AssignmentEditorDto> rowModel) {
// super.populateItem(cellItem, componentId, rowModel);
// cellItem.add(AssignmentsUtil.getEnableBehavior(rowModel));
// }
// });
// columns.add(new AbstractColumn<AssignmentEditorDto, String>(createStringResource("AssignmentDataTablePanel.organizationColumnName")){
// private static final long serialVersionUID = 1L;
//
// @Override
// public void populateItem(Item<ICellPopulator<AssignmentEditorDto>> cellItem, String componentId, final IModel<AssignmentEditorDto> rowModel) {
// ObjectQuery orgQuery = QueryBuilder.queryFor(OrgType.class, getPageBase().getPrismContext())
// .item(OrgType.F_TENANT).eq(false)
// .or().item(OrgType.F_TENANT).isNull()
// .build();
// ChooseTypePanel orgPanel = getChooseOrgPanel(componentId, rowModel, orgQuery);
// orgPanel.add(visibleIfRoleBehavior(rowModel));
// cellItem.add(orgPanel);
// cellItem.add(AssignmentsUtil.getEnableBehavior(rowModel));
// }
//
// });
// columns.add(new AbstractColumn<AssignmentEditorDto, String>(createStringResource("AssignmentDataTablePanel.tenantColumnName")){
// private static final long serialVersionUID = 1L;
//
// @Override
// public void populateItem(Item<ICellPopulator<AssignmentEditorDto>> cellItem, String componentId, final IModel<AssignmentEditorDto> rowModel) {
// ObjectQuery tenantQuery = QueryBuilder.queryFor(OrgType.class, getPageBase().getPrismContext())
// .item(OrgType.F_TENANT).eq(true)
// .build();
// ChooseTypePanel tenantPanel = getChooseOrgPanel(componentId, rowModel, tenantQuery);
// tenantPanel.add(visibleIfRoleBehavior(rowModel));
// cellItem.add(tenantPanel);
// cellItem.add(AssignmentsUtil.getEnableBehavior(rowModel));
// }
//
// });
// columns.add(new LinkColumn<AssignmentEditorDto>(createStringResource("AssignmentDataTablePanel.activationColumnName")) {
// private static final long serialVersionUID = 1L;
//
// @Override
// public void populateItem(Item<ICellPopulator<AssignmentEditorDto>> cellItem, String componentId,
// final IModel<AssignmentEditorDto> rowModel) {
// super.populateItem(cellItem, componentId, rowModel);
// cellItem.setEnabled(false);
//// cellItem.add(AssignmentsUtil.getEnableBehavior(rowModel));
// }
//
// @Override
// protected IModel createLinkModel(IModel<AssignmentEditorDto> rowModel) {
// IModel<String> activationLabelModel = AssignmentsUtil.createActivationTitleModel(rowModel,"", AssignmentDataTablePanel.this);
// return StringUtils.isEmpty(activationLabelModel.getObject()) ?
// createStringResource("AssignmentEditorPanel.undefined") : activationLabelModel;
// }
//
// @Override
// public void onClick(AjaxRequestTarget target, IModel<AssignmentEditorDto> rowModel) {
// AssignmentActivationPopupablePanel popupPanel = new AssignmentActivationPopupablePanel(pageBase.getMainPopupBodyId(), rowModel){
// private static final long serialVersionUID = 1L;
//
// @Override
// protected void reloadDateComponent(AjaxRequestTarget target) {
// target.add(getAssignmentsContainer());
// }
// };
// pageBase.showMainPopup(popupPanel, target);
// }
// });
// columns.add(new AbstractColumn<AssignmentDto, String>(createStringResource("AssignmentDataTablePanel.activationColumnName")) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public void populateItem(Item<ICellPopulator<AssignmentDto>> cellItem, String componentId,
// final IModel<AssignmentDto> rowModel) {
// IModel<String> activationLabelModel = AssignmentsUtil.createActivationTitleModelExperimental(rowModel,"", AbstractRoleAssignmentPanel.this);
// cellItem.add(new Label(componentId, StringUtils.isEmpty(activationLabelModel.getObject()) ?
// createStringResource("AssignmentEditorPanel.undefined") : activationLabelModel));
// }
// });
protected List<IColumn<ContainerValueWrapper<AssignmentType>, String>> initColumns() {
List<IColumn<ContainerValueWrapper<AssignmentType>, String>> columns = new ArrayList<>();

columns.add(new AbstractColumn<ContainerValueWrapper<AssignmentType>, String>(createStringResource("ObjectReferenceType.relation")) {
@Override
public void populateItem(Item<ICellPopulator<ContainerValueWrapper<AssignmentType>>> item, String componentId, IModel<ContainerValueWrapper<AssignmentType>> assignmentModel) {
String relation = assignmentModel.getObject().getContainerValue().getValue().getTargetRef() != null ?
assignmentModel.getObject().getContainerValue().getValue().getTargetRef().getRelation().getLocalPart() : "";
item.add(new Label(componentId, relation));
}
});

return columns;
}
Expand Down Expand Up @@ -309,7 +240,7 @@ private QName getRelation() {
}

@Override
protected AbstractAssignmentDetailsPanel createDetailsPanel(String idAssignmentDetails, Form<?> form, IModel<AssignmentDto> model) {
protected AbstractAssignmentDetailsPanel createDetailsPanel(String idAssignmentDetails, Form<?> form, IModel<ContainerValueWrapper<AssignmentType>> model) {
return new AbstractRoleAssignmentDetailsPanel(ID_ASSIGNMENT_DETAILS, form, model);
}

Expand Down
Expand Up @@ -49,28 +49,6 @@ public AssignmentDto(AssignmentType assignment, UserDtoStatus status) {
this.status = status;
}

/**
*
* @return true if this is an assignment of a RoleType, OrgType, ServiceType or Resource
* @return false if this is an assignment of a User(delegation, deputy) or PolicyRules
*/
public boolean isAssignableObject(){
if (assignment.getPersonaConstruction() != null) {
return false;
}

if (assignment.getPolicyRule() != null) {
return false;
}

//TODO: uncomment when GDPR is in
// if (assignment.getTargetRef() != null && assignment.getTargetRef().getRelation().equals(SchemaConstants.ORG_CONSENT)) {
// return false;
// }

return true;
}

public Collection<? extends ItemDelta> computeAssignmentDelta() {
Collection<? extends ItemDelta> deltas = oldAssignment.asPrismContainerValue().diff(assignment.asPrismContainerValue());
return deltas;
Expand All @@ -96,25 +74,6 @@ public QName getRelation() {

}

public QName getTargetType() {
if (assignment.getTarget() != null) {
// object assignment
return assignment.getTarget().asPrismObject().getComplexTypeDefinition().getTypeName();
} else if (assignment.getTargetRef() != null) {
return assignment.getTargetRef().getType();
}
if (assignment.getPolicyRule() != null){
return PolicyRuleType.COMPLEX_TYPE;
}

if (assignment.getPersonaConstruction() != null) {
return PersonaConstructionType.COMPLEX_TYPE;
}
// account assignment through account construction
return ConstructionType.COMPLEX_TYPE;

}

public RelationTypes getRelationType() {
return RelationTypes.getRelationType(getRelation());
}
Expand Down

0 comments on commit 68476c1

Please sign in to comment.