Skip to content

Commit

Permalink
Merge branch 'feature/prism-api'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Dec 11, 2018
2 parents f8e988a + 05488db commit a5c39e4
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 44 deletions.
Expand Up @@ -99,7 +99,7 @@ public GenericHandlerDto(TaskDto taskDto, @NotNull List<Item> items, PageBase pa
clonedDefinition.setCanAdd(false);
clonedDefinition.setCanModify(false);
clonedDefinition.setDisplayOrder(displayOrder);
prismContext.hacks().addToDefinition(ctd, clonedDefinition);
ctd.toMutable().add(clonedDefinition);
}
displayOrder++;
}
Expand Down
Expand Up @@ -40,9 +40,6 @@
*/
public interface Hacks {

@Nullable
Serializable guessFormattedValue(Serializable value) throws SchemaException;

void serializeFaultMessage(Detail detail, Object faultInfo, QName faultMessageElementName, Trace logger);

<T> void setPrimitiveXNodeValue(PrimitiveXNode<T> node, T value, QName typeName);
Expand All @@ -56,8 +53,4 @@ public interface Hacks {
Element serializeSingleElementMapToElement(MapXNode filterClauseXNode) throws SchemaException;

void setXNodeType(XNode node, QName explicitTypeName, boolean explicitTypeDeclaration);

void addToDefinition(ComplexTypeDefinition ctd, ItemDefinition other);

void replaceDefinition(ComplexTypeDefinition ctd, ItemName name, ItemDefinition other);
}
Expand Up @@ -56,4 +56,6 @@ public interface MutableComplexTypeDefinition extends ComplexTypeDefinition, Mut
void setListMarker(boolean value);

void setCompileTimeClass(Class<?> compileTimeClass);

void replaceDefinition(QName itemName, ItemDefinition newDefinition);
}
Expand Up @@ -490,4 +490,9 @@ public void setCompileTimeClass(Class<?> compileTimeClass) {
public void setDocumentation(String value) {
inner.setDocumentation(value);
}

@Override
public void replaceDefinition(QName itemName, ItemDefinition newDefinition) {
inner.replaceDefinition(itemName, newDefinition);
}
}
Expand Up @@ -27,6 +27,8 @@
*/
public interface PrimitiveXNode<T> extends XNode {

String getGuessedFormattedValue() throws SchemaException;

/**
* Returns the value represented as string - in the best format that we can.
* There is no guarantee that the returned value will be precise.
Expand Down
Expand Up @@ -392,4 +392,18 @@ public void shortDump(StringBuilder sb) {
}
}

public boolean isParsed() {
return parsed != null;
}

// avoid if possible
public String guessFormattedValue() throws SchemaException {
if (parsed != null) {
return parsed.getRealValue().toString(); // todo reconsider this
} else if (xnode instanceof PrimitiveXNode) {
return ((PrimitiveXNode) xnode).getGuessedFormattedValue();
} else {
return null;
}
}
}
Expand Up @@ -376,23 +376,24 @@ protected void copyDefinitionData(ComplexTypeDefinitionImpl clone) {
clone.itemDefinitions.addAll(this.itemDefinitions);
}

public void replaceDefinition(QName propertyName, ItemDefinition newDefinition) {
@Override
public void replaceDefinition(QName itemName, ItemDefinition newDefinition) {
for (int i=0; i<itemDefinitions.size(); i++) {
ItemDefinition itemDef = itemDefinitions.get(i);
if (itemDef.getName().equals(propertyName)) {
if (itemDef.getName().equals(itemName)) {
if (!itemDef.getClass().isAssignableFrom(newDefinition.getClass())) {
throw new IllegalArgumentException("The provided definition of class "+newDefinition.getClass().getName()+" does not match existing definition of class "+itemDef.getClass().getName());
}
if (!itemDef.getName().equals(newDefinition.getName())) {
newDefinition = newDefinition.clone();
((ItemDefinitionImpl) newDefinition).setName(propertyName);
((ItemDefinitionImpl) newDefinition).setName(itemName);
}
// Make sure this is set, not add. set will keep correct ordering
itemDefinitions.set(i, newDefinition);
return;
}
}
throw new IllegalArgumentException("The definition with name "+propertyName+" was not found in complex type "+getTypeName());
throw new IllegalArgumentException("The definition with name "+ itemName +" was not found in complex type "+getTypeName());
}

@Override
Expand Down
Expand Up @@ -45,24 +45,6 @@ public class HacksImpl implements Hacks {
this.prismContext = prismContext;
}

/**
* Obscure method. TODO specify the functionality and decide what to do with this.
*/
@Override
@Nullable
public Serializable guessFormattedValue(Serializable value) throws SchemaException {
if (value instanceof RawType) {
XNode xnode = ((RawType) value).getXnode();
if (xnode instanceof PrimitiveXNodeImpl) {
return ((PrimitiveXNodeImpl) xnode).getGuessedFormattedValue();
} else {
return null;
}
} else {
return value;
}
}

/**
* TODO rewrite this method using Prism API
*/
Expand Down Expand Up @@ -117,14 +99,4 @@ public void setXNodeType(XNode node, QName explicitTypeName, boolean explicitTyp
((XNodeImpl) node).setTypeQName(explicitTypeName);
((XNodeImpl) node).setExplicitTypeDeclaration(explicitTypeDeclaration);
}

@Override
public void addToDefinition(ComplexTypeDefinition ctd, ItemDefinition other) {
((ComplexTypeDefinitionImpl) ctd).add(other);
}

@Override
public void replaceDefinition(ComplexTypeDefinition ctd, ItemName name, ItemDefinition other) {
((ComplexTypeDefinitionImpl) ctd).replaceDefinition(name, other);
}
}
Expand Up @@ -197,6 +197,7 @@ public String getFormattedValue() {
*
* @return properly formatted value
*/
@Override
public String getGuessedFormattedValue() throws SchemaException {
if (isParsed()) {
return getFormattedValue();
Expand Down
Expand Up @@ -62,20 +62,28 @@ private static EntryType createEntryElement(String key, String value) {
return entryType;
}

public static Map<String, Serializable> fromParamsType(ParamsType paramsType, PrismContext prismContext) throws SchemaException{
public static Map<String, Serializable> fromParamsType(ParamsType paramsType, PrismContext prismContext) throws SchemaException {
if (paramsType != null) {
Map<String, Serializable> params = new HashMap<>();
for (EntryType entry : paramsType.getEntry()) {
Serializable realValue;
if (entry.getEntryValue() != null) {
Serializable value = (Serializable) entry.getEntryValue().getValue();
realValue = prismContext.hacks().guessFormattedValue(value);
if (value instanceof RawType) {
RawType raw = (RawType) value;
if (raw.isParsed()) {
realValue = raw.getAlreadyParsedValue().getRealValue();
} else {
realValue = raw.guessFormattedValue();
}
} else {
realValue = value;
}
} else {
realValue = null;
}
params.put(entry.getKey(), realValue);
}

return params;
}
return null;
Expand Down
Expand Up @@ -335,7 +335,7 @@ public <O extends ObjectType> PrismObjectDefinition<O> getEditObjectDefinition(P
}
RefinedObjectClassDefinition refinedObjectClassDefinition = getEditObjectClassDefinition(shadow, resource, phase, task, result);
if (refinedObjectClassDefinition != null) {
prismContext.hacks().replaceDefinition(objectDefinition.getComplexTypeDefinition(), ShadowType.F_ATTRIBUTES,
objectDefinition.getComplexTypeDefinition().toMutable().replaceDefinition(ShadowType.F_ATTRIBUTES,
refinedObjectClassDefinition.toResourceAttributeContainerDefinition());
}
}
Expand Down

0 comments on commit a5c39e4

Please sign in to comment.