Skip to content

Commit

Permalink
MID-4112: adapting object template GUI to keep conflict resolution in…
Browse files Browse the repository at this point in the history
…fo untouched
  • Loading branch information
mederly committed Aug 18, 2017
1 parent 571efa7 commit 64bac9a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 65 deletions.
Expand Up @@ -256,11 +256,21 @@ public String load() {
if(config != null){
ObjectReferenceType ref = config.getTemplateRef();

if(ref != null){
sb.append(WebComponentUtil.getOrigStringFromPoly(ref.getTargetName())).append(": ");
if (ref != null) {
sb.append(WebComponentUtil.getOrigStringFromPoly(ref.getTargetName()));
}

if(config.getType() != null){
if (config.getConflictResolution() != null) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append(getString("ObjectPolicyConfigurationEditor.conflictResolution"));
}

if(config.getType() != null) {
if (sb.length() > 0) {
sb.append(": ");
}
sb.append(config.getType().getLocalPart());
}

Expand Down
Expand Up @@ -341,6 +341,7 @@ private void saveObjectPolicies(SystemConfigurationType systemConfig) {
}

newObjectPolicyConfig.getPropertyConstraint().addAll(constraintList);
newObjectPolicyConfig.setConflictResolution(o.getConflictResolution());

confList.add(newObjectPolicyConfig);
}
Expand Down
Expand Up @@ -32,6 +32,15 @@

<div class="form-group" wicket:id="objectTemplate" />

<div class="form-group" wicket:id="conflictResolutionContainer">
<label class="col-md-4 control-label">
<wicket:message key="ObjectPolicyDialog.conflictResolution" />
</label>
<div class="col-md-8">
<wicket:message key="ObjectPolicyDialog.present" />
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">
<wicket:message key="ObjectPolicyDialog.propertyConstraint" />
Expand Down
Expand Up @@ -93,6 +93,7 @@ public class ObjectPolicyPanel extends BasePanel<ObjectPolicyDialogDto> implemen
private static final String ID_BUTTON_GROUP = "buttonGroup";
private static final String ID_BUTTON_REMOVE = "remove";
private static final String ID_BUTTON_ADD = "add";
private static final String ID_CONFLICT_RESOLUTION_CONTAINER = "conflictResolutionContainer";

private static final String ID_LABEL_SIZE = "col-md-4";
private static final String ID_INPUT_SIZE = "col-md-8";
Expand All @@ -114,7 +115,7 @@ protected ObjectPolicyDialogDto load() {
}
};

initLayout();
initLayout(config);

setOutputMarkupId(true);
// setTitle(createStringResource("ObjectPolicyDialog.label"));
Expand Down Expand Up @@ -154,7 +155,7 @@ public StringResourceModel createStringResource(String resourceKey, Object... ob
// target.add(getContent());
// }

public void initLayout() {
public void initLayout(ObjectPolicyConfigurationTypeDto config) {
Form form = new Form(ID_FORM);
form.setOutputMarkupId(true);
add(form);
Expand All @@ -164,8 +165,8 @@ public void initLayout() {
new QNameChoiceRenderer(), createStringResource("ObjectPolicyDialog.type"), ID_LABEL_SIZE,
ID_INPUT_SIZE, false);
form.add(type);
type.getInput().setNullValid(false);
type.getInput().setRequired(true);
type.getInput().setNullValid(config.getConflictResolution() != null);
type.getInput().setRequired(config.getConflictResolution() == null); // traditional template entries still require object type

TextField<String> fieldSubtype = new TextField<>(ID_SUBTYPE, new PropertyModel<String>(model, ObjectPolicyDialogDto.F_SUBTYPE));
form.add(fieldSubtype);
Expand All @@ -176,8 +177,12 @@ public void initLayout() {
createObjectTemplateList(), new ChoiceableChoiceRenderer<ObjectTemplateConfigTypeReferenceDto>(),
createStringResource("ObjectPolicyDialog.template"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
form.add(template);
template.getInput().setNullValid(false);
template.getInput().setRequired(true);
template.getInput().setNullValid(config.getConflictResolution() != null);
template.getInput().setRequired(config.getConflictResolution() == null);

WebMarkupContainer conflictResolutionContainer = new WebMarkupContainer(ID_CONFLICT_RESOLUTION_CONTAINER);
conflictResolutionContainer.setVisible(config.getConflictResolution() != null);
form.add(conflictResolutionContainer);

ListView repeater = new ListView<PropertyConstraintTypeDto>(ID_REPEATER,
new PropertyModel<List<PropertyConstraintTypeDto>>(model, ObjectPolicyDialogDto.F_PROPERTY_LIST)) {
Expand Down
Expand Up @@ -16,6 +16,7 @@

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

import com.evolveum.midpoint.xml.ns._public.common.common_3.ConflictResolutionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyConstraintType;
Expand All @@ -24,6 +25,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* @author shpood
Expand All @@ -40,6 +42,7 @@ public class ObjectPolicyConfigurationTypeDto implements Serializable{
private QName type;
private String subtype;
private List<PropertyConstraintTypeDto> constraints;
private ConflictResolutionType conflictResolution;

public ObjectPolicyConfigurationTypeDto(){}

Expand All @@ -60,6 +63,7 @@ public ObjectPolicyConfigurationTypeDto(ObjectPolicyConfigurationType policyConf
} else {
constraints.add(new PropertyConstraintTypeDto(null));
}
conflictResolution = policyConfig.getConflictResolution();
}

public ObjectReferenceType getTemplateRef() {
Expand Down Expand Up @@ -93,69 +97,44 @@ public List<PropertyConstraintTypeDto> getConstraints() {
public void setConstraints(List<PropertyConstraintTypeDto> constraints) {
this.constraints = constraints;
}

public boolean isEmpty(){
return type == null && subtype == null && constraints == null && templateRef == null;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
result = prime * result + ((subtype == null) ? 0 : subtype.hashCode());
result = prime * result + ((templateRef == null) ? 0 : templateRef.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
public ConflictResolutionType getConflictResolution() {
return conflictResolution;
}

public void setConflictResolution(ConflictResolutionType conflictResolution) {
this.conflictResolution = conflictResolution;
}

public boolean isEmpty(){
return type == null && subtype == null && constraints == null && templateRef == null && conflictResolution == null;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object o) {
if (this == o)
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (!(o instanceof ObjectPolicyConfigurationTypeDto))
return false;
}
ObjectPolicyConfigurationTypeDto other = (ObjectPolicyConfigurationTypeDto) obj;
if (constraints == null) {
if (other.constraints != null) {
return false;
}
} else if (!constraints.equals(other.constraints)) {
return false;
}
if (subtype == null) {
if (other.subtype != null) {
return false;
}
} else if (!subtype.equals(other.subtype)) {
return false;
}
if (templateRef == null) {
if (other.templateRef != null) {
return false;
}
} else if (!templateRef.equals(other.templateRef)) {
return false;
}
if (type == null) {
if (other.type != null) {
return false;
}
} else if (!type.equals(other.type)) {
return false;
}
return true;
ObjectPolicyConfigurationTypeDto that = (ObjectPolicyConfigurationTypeDto) o;
return Objects.equals(templateRef, that.templateRef) &&
Objects.equals(type, that.type) &&
Objects.equals(subtype, that.subtype) &&
Objects.equals(constraints, that.constraints) &&
Objects.equals(conflictResolution, that.conflictResolution);
}

@Override
public int hashCode() {
return Objects.hash(templateRef, type, subtype, constraints, conflictResolution);
}

@Override
public String toString() {
return "ObjectPolicyConfigurationTypeDto(templateRef=" + templateRef + ", type=" + type
+ ", subtype=" + subtype + ", constraints=" + constraints + ")";
+ ", subtype=" + subtype + ", constraints=" + constraints
+ (conflictResolution != null ? ",conflictResolution" : "")
+ ")";
}


Expand Down
Expand Up @@ -79,16 +79,16 @@ public ObjectPolicyConfigurationTypeDto preparePolicyConfig(){
newConfig.setConstraints(propertyConstraintsList);
newConfig.setType(type);
newConfig.setSubtype(subtype);
newConfig.setConflictResolution(config.getConflictResolution());

ObjectReferenceType ref = new ObjectReferenceType();
if(templateRef != null){
if (templateRef != null) {
ObjectReferenceType ref = new ObjectReferenceType();
ref.setOid(templateRef.getOid());
ref.setType(ObjectTemplateType.COMPLEX_TYPE);
ref.setTargetName(new PolyStringType(templateRef.getName()));
newConfig.setTemplateRef(ref);
}

newConfig.setTemplateRef(ref);

return newConfig;
}

Expand Down
Expand Up @@ -610,6 +610,8 @@ ObjectPolicyDialog.button.save=Save
ObjectPolicyDialog.label=Edit Object Policy
ObjectPolicyDialog.label.oidBound.help=Oid bound - The property value will be bound to OID. This property will be set to the value of OID and it cannot be changed.
ObjectPolicyDialog.propertyConstraint=Property constraint
ObjectPolicyDialog.conflictResolution=Conflict resolution
ObjectPolicyDialog.present=(present)
ObjectPolicyDialog.property.placeholder=Insert property path
ObjectPolicyDialog.subtype=Object subtype
ObjectPolicyDialog.template=Object template
Expand Down Expand Up @@ -3735,3 +3737,4 @@ ApprovalProcessesPreviewPanel.processRelatedTo=Approval process related to {0}
ApprovalProcessesPreviewPanel.process=Approval process
ApprovalProcessExecutionInformationPanel.stage=Stage {0}/{1}
PageImportResource.title=Import resource definition
ObjectPolicyConfigurationEditor.conflictResolution=(conflict resolution)

0 comments on commit 64bac9a

Please sign in to comment.