Skip to content

Commit

Permalink
fix for MID-2189 - issue 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Suta committed Jan 30, 2015
1 parent 5de254c commit 3b74867
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Expand Up @@ -51,7 +51,6 @@

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
Expand Down Expand Up @@ -411,18 +410,14 @@ private List<QName> loadObjectReferences(boolean restrictObjectClass){
for(ObjectClassComplexTypeDefinition def: schema.getObjectClassDefinitions()){
if(restrictObjectClass){
if(objectType != null && def.getTypeName().equals(objectType.getObjectClass())){
Iterator it = def.getAttributeDefinitions().iterator();

while(it.hasNext()){
ResourceAttributeDefinition attributeDefinition = (ResourceAttributeDefinition)it.next();
for(ResourceAttributeDefinition attributeDefinition : def.getAttributeDefinitions()) {
references.add(attributeDefinition.getName());
}
}
} else {
Iterator it = def.getAttributeDefinitions().iterator();

while(it.hasNext()){
ResourceAttributeDefinition attributeDefinition = (ResourceAttributeDefinition)it.next();
for(ResourceAttributeDefinition attributeDefinition : def.getAttributeDefinitions()) {
references.add(attributeDefinition.getName());
}
}
Expand Down
Expand Up @@ -53,7 +53,6 @@

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
Expand Down Expand Up @@ -377,10 +376,8 @@ private List<QName> loadObjectReferences(){

for(ObjectClassComplexTypeDefinition def: schema.getObjectClassDefinitions()){
if(objectType != null && def.getTypeName().equals(objectType.getObjectClass())){
Iterator it = def.getAttributeDefinitions().iterator();

while(it.hasNext()){
ResourceAttributeDefinition attributeDefinition = (ResourceAttributeDefinition)it.next();
for (ResourceAttributeDefinition attributeDefinition : def.getAttributeDefinitions()) {
references.add(attributeDefinition.getName());
}
}
Expand Down
Expand Up @@ -573,6 +573,12 @@ private List<ObjectReferenceType> createPasswordPolicyList(){
}

private void cancelPerformed(AjaxRequestTarget target){
if(inputModel != null && model.getObject() != null){
model.getObject().cancelChanges();
}

updateComponents(target);
target.add(getPageBase().getFeedbackPanel());
close(target);
}

Expand All @@ -595,7 +601,8 @@ private void savePerformed(AjaxRequestTarget target){
close(target);
}

public void updateComponents(AjaxRequestTarget target){
//Override this if update of component(s) holding this modal window is needed
}
/**
* Override this if update of component(s) holding this modal window is needed
* */
public void updateComponents(AjaxRequestTarget target){}
}
Expand Up @@ -53,6 +53,7 @@ public class MappingTypeDto implements Serializable {
private static MappingStrengthType DEFAULT_MAPPING_STRENGTH = MappingStrengthType.NORMAL;

private MappingType mappingObject;
private MappingType oldMappingObject;
private String expression;
private String condition;
private String target;
Expand Down Expand Up @@ -80,6 +81,8 @@ public MappingTypeDto(MappingType mapping, PrismContext prismContext){
mappingObject = mapping;
}

oldMappingObject = mappingObject.clone();

for(MappingSourceDeclarationType mappingSource: mappingObject.getSource()){
if(mappingSource.getPath() != null && mappingSource.getPath().getItemPath() != null){
source.add(mappingSource.getPath().getItemPath().toString());
Expand Down Expand Up @@ -141,6 +144,18 @@ private JAXBElement<?> deserializeExpression(PrismContext prismContext, String x
return prismContext.parseAnyValueAsJAXBElement(xmlCode, PrismContext.LANG_XML);
}

public void cancelChanges(){
mappingObject.setName(oldMappingObject.getName());
mappingObject.setDescription(oldMappingObject.getDescription());
mappingObject.setAuthoritative(oldMappingObject.isAuthoritative());
mappingObject.setExclusive(oldMappingObject.isExclusive());
mappingObject.setStrength(oldMappingObject.getStrength());
mappingObject.getChannel().clear();
mappingObject.getChannel().addAll(oldMappingObject.getChannel());
mappingObject.getExceptChannel().clear();
mappingObject.getExceptChannel().addAll(oldMappingObject.getExceptChannel());
}

public MappingType prepareDtoToSave(PrismContext prismContext) throws SchemaException{

if(mappingObject == null){
Expand Down Expand Up @@ -301,7 +316,7 @@ public void setConditionPolicyRef(ObjectReferenceType conditionPolicyRef) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof MappingTypeDto)) return false;

MappingTypeDto that = (MappingTypeDto) o;

Expand All @@ -317,6 +332,8 @@ public boolean equals(Object o) {
if (expressionType != that.expressionType) return false;
if (mappingObject != null ? !mappingObject.equals(that.mappingObject) : that.mappingObject != null)
return false;
if (oldMappingObject != null ? !oldMappingObject.equals(that.oldMappingObject) : that.oldMappingObject != null)
return false;
if (source != null ? !source.equals(that.source) : that.source != null) return false;
if (target != null ? !target.equals(that.target) : that.target != null) return false;

Expand All @@ -326,6 +343,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = mappingObject != null ? mappingObject.hashCode() : 0;
result = 31 * result + (oldMappingObject != null ? oldMappingObject.hashCode() : 0);
result = 31 * result + (expression != null ? expression.hashCode() : 0);
result = 31 * result + (condition != null ? condition.hashCode() : 0);
result = 31 * result + (target != null ? target.hashCode() : 0);
Expand All @@ -339,9 +357,6 @@ public int hashCode() {
return result;
}

/**
* TODO - find a better place for this method, it probably shouldn't be here
* */
public static String createMappingLabel(MappingType mapping, Trace LOGGER, PrismContext context,
String placeholder, String nameNotSpecified ){
if(mapping == null){
Expand All @@ -363,4 +378,4 @@ public static String createMappingLabel(MappingType mapping, Trace LOGGER, Prism

return sb.toString();
}
}
}

0 comments on commit 3b74867

Please sign in to comment.