Skip to content

Commit

Permalink
MID-1994 - tenant reference of assignments is now editable from GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Suta committed Jul 23, 2014
1 parent 03a339f commit 3cbb2d0
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 8 deletions.
Expand Up @@ -17,11 +17,16 @@
package com.evolveum.midpoint.web.component.assignment;

import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

Expand All @@ -36,24 +41,29 @@
*/
public class AssignmentEditorDto extends SelectableBean implements Comparable<AssignmentEditorDto> {

private static final String DOT_CLASS = AssignmentEditorDto.class.getName() + ".";
private static final String OPERATION_LOAD_ORG_TENANT = DOT_CLASS + "loadTenantOrg";

public static final String F_TYPE = "type";
public static final String F_NAME = "name";
public static final String F_DESCRIPTION = "description";
public static final String F_ACTIVATION = "activation";
public static final String F_RELATION = "relation";
public static final String F_TENANT_REF = "tenantRef";

private String name;
private AssignmentEditorDtoType type;
private UserDtoStatus status;
private AssignmentType oldAssignment;
private ObjectViewDto<OrgType> tenantRef;

private boolean showEmpty = false;
private boolean minimized = true;

private AssignmentType newAssignment;
private List<ACAttributeDto> attributes;

public AssignmentEditorDto(ObjectType targetObject, AssignmentEditorDtoType type, UserDtoStatus status, AssignmentType assignment) {
public AssignmentEditorDto(ObjectType targetObject, AssignmentEditorDtoType type, UserDtoStatus status, AssignmentType assignment, PageBase pageBase) {
Validate.notNull(status, "User dto status must not be null.");
Validate.notNull(type, "Type must not be null.");
Validate.notNull(assignment, "Assignment must not be null.");
Expand All @@ -76,6 +86,28 @@ public AssignmentEditorDto(ObjectType targetObject, AssignmentEditorDtoType type
// }

this.name = getNameForTargetObject(targetObject);
this.tenantRef = loadTenantReference(targetObject, assignment, pageBase);
}

private ObjectViewDto loadTenantReference(ObjectType object, AssignmentType assignment, PageBase page){
ObjectViewDto dto;

if(object instanceof RoleType){
if(assignment.getTenantRef() != null){
ObjectReferenceType ref = assignment.getTenantRef();

OperationResult result = new OperationResult(OPERATION_LOAD_ORG_TENANT);
PrismObject<OrgType> org = WebModelUtils.loadObject(OrgType.class, ref.getOid(), result, page);

dto = new ObjectViewDto(ref.getOid(), WebMiscUtil.getName(org.asObjectable()));
dto.setType(OrgType.class);
return dto;
}
}

dto = new ObjectViewDto();
dto.setType(OrgType.class);
return dto;
}

private String getNameForTargetObject(ObjectType object) {
Expand Down Expand Up @@ -181,6 +213,12 @@ public PrismContainerValue getNewValue() throws SchemaException {
newAssignment.setActivation(null);
}

if(tenantRef != null){
ObjectReferenceType ref = new ObjectReferenceType();
ref.setOid(this.tenantRef.getOid());
newAssignment.setTenantRef(ref);
}

ConstructionType construction = newAssignment.getConstruction();
if (construction == null) {
return newAssignment.asPrismContainerValue();
Expand Down Expand Up @@ -245,4 +283,12 @@ private int getIndexOfType(AssignmentEditorDtoType type) {

return 0;
}

public ObjectViewDto<OrgType> getTenantRef() {
return tenantRef;
}

public void setTenantRef(ObjectViewDto<OrgType> tenantRef) {
this.tenantRef = tenantRef;
}
}
Expand Up @@ -53,6 +53,13 @@
</div>
</div>

<div wicket:id="tenantRefContainer" class="row">
<div class="col-xs-4">
<span><wicket:message key="AssignmentEditorPanel.tenantRef" /></span>
</div>
<div wicket:id="tenantRefChooser"/>
</div>

<div class="row" wicket:id="activationBlock">
<div class="col-xs-12">
<h4>
Expand Down
Expand Up @@ -19,6 +19,9 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -34,6 +37,9 @@
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.configuration.component.ChooseTypeDialog;
import com.evolveum.midpoint.web.page.admin.configuration.component.ChooseTypePanel;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand Down Expand Up @@ -98,10 +104,11 @@ public class AssignmentEditorPanel extends SimplePanel<AssignmentEditorDto> {
private static final String ID_TARGET = "target";
private static final String ID_TARGET_CONTAINER = "targetContainer";
private static final String ID_CONSTRUCTION_CONTAINER = "constructionContainer";
private static final String ID_CONTAINER_TENANT_REF = "tenantRefContainer";
private static final String ID_TENANT_CHOOSER = "tenantRefChooser";

private IModel<List<ACAttributeDto>> attributesModel;


public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model) {
super(id, model);

Expand Down Expand Up @@ -250,6 +257,39 @@ private void initBodyLayout(WebMarkupContainer body) {
relation.setEnabled(false);
body.add(relation);

//TODO - add VisibleEnableBehaviour so we can only edit tenantRef in RoleAssignments
WebMarkupContainer tenantRefContainer = new WebMarkupContainer(ID_CONTAINER_TENANT_REF);
ChooseTypePanel tenantRef = new ChooseTypePanel(ID_TENANT_CHOOSER,
new PropertyModel<ObjectViewDto>(getModel(), AssignmentEditorDto.F_TENANT_REF)){

@Override
protected ObjectQuery getChooseQuery(){
ObjectQuery query = new ObjectQuery();

ObjectFilter filter = EqualFilter.createEqual(OrgType.F_TENANT, OrgType.class,
getPageBase().getPrismContext(), null, true);
query.setFilter(filter);

return query;
}
};
tenantRefContainer.add(tenantRef);
tenantRefContainer.add(new VisibleEnableBehaviour(){

@Override
public boolean isVisible() {
AssignmentEditorDto dto = getModel().getObject();
if(dto != null){
if(AssignmentEditorDtoType.ROLE.equals(dto.getType())){
return true;
}
}

return false;
}
});
body.add(tenantRefContainer);

WebMarkupContainer activationBlock = new WebMarkupContainer(ID_ACTIVATION_BLOCK);
activationBlock.add(new VisibleEnableBehaviour() {

Expand Down
Expand Up @@ -24,5 +24,6 @@ AssignmentEditorPanel.enabledFromTo={0}, from {1,date,medium} to {2,date,medium}
AssignmentEditorPanel.enabledFrom={0}, from {1,date,medium}
AssignmentEditorPanel.enabledTo={0}, to {1,date,medium}
AssignmentEditorPanel.relation=Relation
AssignmentEditorPanel.tenantRef=Tenant


Expand Up @@ -133,7 +133,7 @@ public List<AssignmentEditorDto> loadFromAssignmentTypeList(List<AssignmentType>
}
}

list.add(new AssignmentEditorDto(targetObject, type, UserDtoStatus.MODIFY, assignment));
list.add(new AssignmentEditorDto(targetObject, type, UserDtoStatus.MODIFY, assignment, getPageBase()));
}

Collections.sort(list);
Expand Down Expand Up @@ -383,7 +383,7 @@ private void addSelectedAssignablePerformed(AjaxRequestTarget target, List<Objec
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(targetRef);

AssignmentEditorDto dto = new AssignmentEditorDto(object, aType, UserDtoStatus.ADD, assignment);
AssignmentEditorDto dto = new AssignmentEditorDto(object, aType, UserDtoStatus.ADD, assignment, getPageBase());
dto.setMinimized(false);
dto.setShowEmpty(true);

Expand Down Expand Up @@ -414,7 +414,7 @@ private void addSelectedResourceAssignPerformed(ResourceType resource) {

List<AssignmentEditorDto> assignments = assignmentModel.getObject();
AssignmentEditorDto dto = new AssignmentEditorDto(resource, AssignmentEditorDtoType.ACCOUNT_CONSTRUCTION,
UserDtoStatus.ADD, assignment);
UserDtoStatus.ADD, assignment, getPageBase());
assignments.add(dto);

dto.setMinimized(false);
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.evolveum.midpoint.web.page.admin.configuration.component;

import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.SimplePanel;
Expand Down Expand Up @@ -94,11 +95,20 @@ private void initDialog(){
protected void chooseOperationPerformed(AjaxRequestTarget target, ObjectType object){
choosePerformed(target, object);
}

@Override
protected ObjectQuery getDataProviderQuery(){
return getChooseQuery();
}
};

add(dialog);
}

protected ObjectQuery getChooseQuery(){
return null;
}

private void choosePerformed(AjaxRequestTarget target, ObjectType object){
ModalWindow window = (ModalWindow) get(MODAL_ID_SHOW_CHOOSE_OPTIONS);
window.close(target);
Expand Down
Expand Up @@ -743,7 +743,7 @@ private List<AssignmentEditorDto> loadAssignments() {
}
}

list.add(new AssignmentEditorDto(targetObject, type, UserDtoStatus.MODIFY, assignment));
list.add(new AssignmentEditorDto(targetObject, type, UserDtoStatus.MODIFY, assignment, this));
}

Collections.sort(list);
Expand Down Expand Up @@ -1598,7 +1598,7 @@ private void addSelectedResourceAssignPerformed(ResourceType resource) {

List<AssignmentEditorDto> assignments = assignmentsModel.getObject();
AssignmentEditorDto dto = new AssignmentEditorDto(resource, AssignmentEditorDtoType.ACCOUNT_CONSTRUCTION,
UserDtoStatus.ADD, assignment);
UserDtoStatus.ADD, assignment, this);
assignments.add(dto);

dto.setMinimized(false);
Expand Down Expand Up @@ -1632,7 +1632,7 @@ private void addSelectedAssignablePerformed(AjaxRequestTarget target, List<Objec
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(targetRef);

AssignmentEditorDto dto = new AssignmentEditorDto(object, aType, UserDtoStatus.ADD, assignment);
AssignmentEditorDto dto = new AssignmentEditorDto(object, aType, UserDtoStatus.ADD, assignment, this);
dto.setMinimized(false);
dto.setShowEmpty(true);

Expand Down

0 comments on commit 3cbb2d0

Please sign in to comment.