Skip to content

Commit

Permalink
Fix for MID-2048
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Suta committed Oct 24, 2014
1 parent 9e51b64 commit d09ec4c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
Expand Up @@ -49,8 +49,10 @@ public class AssignmentEditorDto extends SelectableBean implements Comparable<As
public static final String F_ACTIVATION = "activation";
public static final String F_RELATION = "relation";
public static final String F_TENANT_REF = "tenantRef";
public static final String F_ALT_NAME = "altName";

private String name;
private String altName;
private AssignmentEditorDtoType type;
private UserDtoStatus status;
private AssignmentType oldAssignment;
Expand Down Expand Up @@ -87,6 +89,7 @@ public AssignmentEditorDto(ObjectType targetObject, AssignmentEditorDtoType type
this.tenantRef = loadTenantReference(targetObject, assignment, pageBase);

this.name = getNameForTargetObject(targetObject);
this.altName = getAlternativeName(assignment);
}

private ObjectViewDto loadTenantReference(ObjectType object, AssignmentType assignment, PageBase page){
Expand Down Expand Up @@ -158,6 +161,18 @@ private String getNameForTargetObject(ObjectType object) {
return builder.toString();
}

private String getAlternativeName(AssignmentType assignment){
if(assignment == null){
return null;
}

if(assignment.getFocusMappings() != null){
return "(focus mapping)";
}

return null;
}

public List<ACAttributeDto> getAttributes() {
if (attributes == null) {
attributes = new ArrayList<>();
Expand Down Expand Up @@ -314,4 +329,50 @@ public ObjectViewDto<OrgType> getTenantRef() {
public void setTenantRef(ObjectViewDto<OrgType> tenantRef) {
this.tenantRef = tenantRef;
}

public String getAltName() {
return altName;
}

public void setAltName(String altName) {
this.altName = altName;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AssignmentEditorDto)) return false;

AssignmentEditorDto that = (AssignmentEditorDto) o;

if (minimized != that.minimized) return false;
if (showEmpty != that.showEmpty) return false;
if (altName != null ? !altName.equals(that.altName) : that.altName != null) return false;
if (attributes != null ? !attributes.equals(that.attributes) : that.attributes != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (newAssignment != null ? !newAssignment.equals(that.newAssignment) : that.newAssignment != null)
return false;
if (oldAssignment != null ? !oldAssignment.equals(that.oldAssignment) : that.oldAssignment != null)
return false;
if (status != that.status) return false;
if (tenantRef != null ? !tenantRef.equals(that.tenantRef) : that.tenantRef != null) return false;
if (type != that.type) return false;

return true;
}

@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (altName != null ? altName.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (oldAssignment != null ? oldAssignment.hashCode() : 0);
result = 31 * result + (tenantRef != null ? tenantRef.hashCode() : 0);
result = 31 * result + (showEmpty ? 1 : 0);
result = 31 * result + (minimized ? 1 : 0);
result = 31 * result + (newAssignment != null ? newAssignment.hashCode() : 0);
result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
return result;
}
}
Expand Up @@ -160,7 +160,7 @@ public void onClick(AjaxRequestTarget target) {
};
headerRow.add(name);

Label nameLabel = new Label(ID_NAME_LABEL, new PropertyModel<String>(getModel(), AssignmentEditorDto.F_NAME));
Label nameLabel = new Label(ID_NAME_LABEL, createAssignmentNameLabelModel());
name.add(nameLabel);

Label activation = new Label(ID_ACTIVATION, createActivationModel());
Expand All @@ -184,6 +184,28 @@ public boolean isVisible() {
initBodyLayout(body);
}

private IModel<String> createAssignmentNameLabelModel(){
return new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
if(getModel() != null && getModel().getObject() != null){
AssignmentEditorDto dto = getModelObject();

if(dto.getName() != null){
return dto.getName();
}

if(dto.getAltName() != null){
return getString("AssignmentEditorPanel.name.focus");
}
}

return getString("AssignmentEditorPanel.name.noTarget");
}
};
}

private IModel<String> createHeaderClassModel(final IModel<AssignmentEditorDto> model) {
return new AbstractReadOnlyModel<String>() {

Expand Down Expand Up @@ -464,10 +486,15 @@ private List<ACAttributeDto> loadAttributes() {
}

OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
List<ACAttributeDto> attributes = new ArrayList<ACAttributeDto>();
List<ACAttributeDto> attributes = new ArrayList<>();
try {
ConstructionType construction = WebMiscUtil.getContainerValue(dto.getOldValue(),
AssignmentType.F_CONSTRUCTION, ConstructionType.class);

if(construction == null){
return attributes;
}

PrismObject<ResourceType> resource = construction.getResource() != null
? construction.getResource().asPrismObject() : null;
if (resource == null) {
Expand Down
Expand Up @@ -25,5 +25,7 @@ AssignmentEditorPanel.enabledFrom={0}, from {1,date,medium}
AssignmentEditorPanel.enabledTo={0}, to {1,date,medium}
AssignmentEditorPanel.relation=Relation
AssignmentEditorPanel.tenantRef=Tenant
AssignmentEditorPanel.name.focus=(focus mapping)
AssignmentEditorPanel.name.noTarget=(no target)


0 comments on commit d09ec4c

Please sign in to comment.