Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jul 18, 2014
2 parents 06e55ee + d6364b2 commit 39877bf
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 64 deletions.
Expand Up @@ -171,7 +171,7 @@ private List<PropertyWrapper> createProperties(PageBase pageBase) {
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

definition = pageBase.getModelInteractionService()
.getEditObjectClassDefinition(object.getObject(), resource).toResourceAttributeContainerDefinition();
.getEditObjectClassDefinition(object.getObject(), resource, AuthorizationPhaseType.REQUEST).toResourceAttributeContainerDefinition();

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined account def:\n{}", definition.debugDump());
Expand Down
Expand Up @@ -31,7 +31,7 @@ public static <O extends ObjectType> ObjectWrapper createObjectWrapper(String di
if (isShadow(object)) {
PrismReference resourceRef = object.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();
objectClassDefinitionForEditing = pageBase.getModelInteractionService().getEditObjectClassDefinition((PrismObject<ShadowType>) object, resource);
objectClassDefinitionForEditing = pageBase.getModelInteractionService().getEditObjectClassDefinition((PrismObject<ShadowType>) object, resource, AuthorizationPhaseType.REQUEST);
}

ObjectWrapper wrapper = new ObjectWrapper(displayName, description, object, objectDefinitionForEditing, objectClassDefinitionForEditing, status, delayContainerCreation, pageBase);
Expand Down
Expand Up @@ -117,7 +117,9 @@ private ObjectViewDto loadObject() {
try {
MidPointApplication application = PageDebugView.this.getMidpointApplication();

Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
GetOperationOptions rootOptions = GetOperationOptions.createRaw();
rootOptions.setResolveNames(true);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(rootOptions);
// FIXME: ObjectType.class will not work well here. We need more specific type.
//todo on page debug list create page params, put there oid and class for object type and send that to this page....read it here
Class type = ObjectType.class;
Expand Down
Expand Up @@ -176,8 +176,11 @@ public boolean handle(PrismObject object, OperationResult parentResult) {
};

ModelService service = page.getModelService();
service.searchObjectsIterative(type, query, handler, SelectorOptions.createCollection(new ItemPath(),
GetOperationOptions.createRaw()), page.createSimpleTask(OPERATION_SEARCH_OBJECT), result);
GetOperationOptions options = GetOperationOptions.createRaw();
// TODO enable when necessary
//options.setResolveNames(true);
service.searchObjectsIterative(type, query, handler, SelectorOptions.createCollection(options),
page.createSimpleTask(OPERATION_SEARCH_OBJECT), result);
}

private PageBase getPage() {
Expand Down
Expand Up @@ -29,7 +29,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -42,7 +44,8 @@ public abstract class PrismValue implements Visitable, PathVisitable, Serializab
private Objectable originObject;
private Itemable parent;
protected Element domElement = null;

private transient Map<String,Object> userData = new HashMap<>();;

PrismValue() {
super();
}
Expand Down Expand Up @@ -75,8 +78,20 @@ public OriginType getOriginType() {
public Objectable getOriginObject() {
return originObject;
}

public Itemable getParent() {

public Map<String, Object> getUserData() {
return userData;
}

public Object getUserData(String key) {
return userData.get(key);
}

public void setUserData(String key, Object value) {
userData.put(key, value);
}

public Itemable getParent() {
return parent;
}

Expand Down
Expand Up @@ -27,10 +27,13 @@
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.sun.org.apache.xml.internal.utils.XMLChar;
import org.apache.commons.lang.StringUtils;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import javax.xml.namespace.QName;
import java.util.Map.Entry;
Expand Down Expand Up @@ -139,10 +142,12 @@ private void serializeSubnode(XNode xsubnode, Element parentElement, QName eleme
}
if (xsubnode instanceof RootXNode) {
Element element = createElement(elementName, parentElement);
appendCommentIfPresent(element, xsubnode);
parentElement.appendChild(element);
serializeSubnode(((RootXNode) xsubnode).getSubnode(), element, ((RootXNode) xsubnode).getRootElementName());
} else if (xsubnode instanceof MapXNode) {
Element element = createElement(elementName, parentElement);
appendCommentIfPresent(element, xsubnode);
if (xsubnode.isExplicitTypeDeclaration() && xsubnode.getTypeQName() != null){
DOMUtil.setXsiType(element, xsubnode.getTypeQName());
}
Expand Down Expand Up @@ -199,6 +204,7 @@ private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Eleme
Element element;
try {
element = createElement(elementOrAttributeName, parentElement);
appendCommentIfPresent(element, xprim);
} catch (DOMException e) {
throw new DOMException(e.code, e.getMessage() + "; creating element "+elementOrAttributeName+" in element "+DOMUtil.getQName(parentElement));
}
Expand Down Expand Up @@ -240,6 +246,7 @@ private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Eleme
} catch (DOMException e) {
throw new DOMException(e.code, e.getMessage() + "; creating element "+elementOrAttributeName+" in element "+DOMUtil.getQName(parentElement));
}
appendCommentIfPresent(element, xprim);
parentElement.appendChild(element);
}

Expand Down Expand Up @@ -271,6 +278,13 @@ private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Eleme
}
}

private void appendCommentIfPresent(Element element, XNode xnode) {
String text = xnode.getComment();
if (StringUtils.isNotEmpty(text)) {
DOMUtil.createComment(element, text);
}
}

private void serializeSchema(SchemaXNode xschema, Element parentElement) {
Element schemaElement = xschema.getSchemaElement();
if (schemaElement == null){
Expand Down
Expand Up @@ -67,6 +67,9 @@ public class XNodeSerializer {

private PrismBeanConverter beanConverter;
private boolean serializeCompositeObjects = false;

// TODO think out where to put this key
public static final String USER_DATA_KEY_COMMENT = XNodeSerializer.class.getName()+".comment";

public XNodeSerializer(PrismBeanConverter beanConverter) {
super();
Expand Down Expand Up @@ -183,24 +186,7 @@ public <V extends PrismValue> XNode serializeItemValue(V itemValue, ItemDefiniti
return serializePropertyRawValue((PrismPropertyValue<?>) itemValue);
}
if (beanConverter.getPrismContext() == null) {
// hope we don't need this code any more
throw new IllegalStateException("No prismContext in beanConverter!");
// // HACK. Ugly hack. We need to make sure that the bean converter has a prism context.
// // If it does not then it cannot serialize any values and the subsequent calls may fail.
// // The bean converter usually has a context. The context may be missing if it was initialized
// // inside one of the JAXB getters/setters.
// // We need to get rid of JAXB entirelly to get rid of hacks like this
// PrismContext context = null;
// if (definition != null) {
// context = definition.getPrismContext();
// }
// if (context == null && itemValue.getParent() != null) {
// context = itemValue.getParent().getPrismContext();
// }
// if (context == null) {
// throw new SystemException("Cannot determine prism context when serializing "+itemValue);
// }
// beanConverter.setPrismContext(context);
}
if (itemValue instanceof PrismReferenceValue) {
xnode = serializeReferenceValue((PrismReferenceValue)itemValue, (PrismReferenceDefinition) definition);
Expand All @@ -214,6 +200,10 @@ public <V extends PrismValue> XNode serializeItemValue(V itemValue, ItemDefiniti
if (definition.isDynamic()) {
xnode.setExplicitTypeDeclaration(true);
}
Object commentValue = itemValue.getUserData(USER_DATA_KEY_COMMENT);
if (commentValue != null) {
xnode.setComment(commentValue.toString());
}
// System.out.println("item value serialization: \n" + xnode.debugDump());
return xnode;
}
Expand Down
Expand Up @@ -66,6 +66,9 @@ public abstract class XNode implements DebugDumpable, Visitable, Cloneable, Seri
private QName typeQName;
private Integer maxOccurs;

// a comment that could be stored into formats that support these (e.g. XML or YAML)
private String comment;

public XNode getParent() {
return parent;
}
Expand Down Expand Up @@ -98,7 +101,15 @@ public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}

public QName getTypeQName() {
public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public QName getTypeQName() {
return typeQName;
}

Expand Down
Expand Up @@ -28,7 +28,7 @@
* @author semancik
*
*/
public class GetOperationOptions implements Serializable {
public class GetOperationOptions implements Serializable, Cloneable {

/**
* Specifies whether to return specific items. It is used for optimizations.
Expand Down Expand Up @@ -59,8 +59,17 @@ public class GetOperationOptions implements Serializable {
* Resolve the object reference. This only makes sense with a (path-based) selector.
*/
Boolean resolve;

/**

/**
* Resolve the object reference names. (Currently applicable only as a top-level option.)
*
* Names of referenced objects are provided as PrismValue userData entries.
*
* EXPERIMENTAL.
*/
Boolean resolveNames;

/**
* No not fetch any information from external sources, e.g. do not fetch account data from resource,
* do not fetch resource schema, etc.
* Such operation returns only the data stored in midPoint repository.
Expand All @@ -79,8 +88,7 @@ public class GetOperationOptions implements Serializable {
* from the gui, for example
*/
Boolean doNotDiscovery;



public RetrieveOption getRetrieve() {
return retrieve;
}
Expand Down Expand Up @@ -163,31 +171,56 @@ public static Collection<SelectorOptions<GetOperationOptions>> createRetrieveAtt
return optionsCollection;
}

public Boolean getRaw() {
return raw;
public Boolean getResolveNames() {
return resolveNames;
}

public void setRaw(Boolean raw) {
this.raw = raw;
public void setResolveNames(Boolean resolveNames) {
this.resolveNames = resolveNames;
}

public static boolean isRaw(GetOperationOptions options) {
public static boolean isResolveNames(GetOperationOptions options) {
if (options == null) {
return false;
}
if (options.raw == null) {
if (options.resolveNames == null) {
return false;
}
return options.raw;
return options.resolveNames;
}

public static GetOperationOptions createRaw() {
public static GetOperationOptions createResolveNames() {
GetOperationOptions opts = new GetOperationOptions();
opts.setRaw(true);
opts.setResolveNames(true);
return opts;
}

public Boolean getDoNotDiscovery() {

public Boolean getRaw() {
return raw;
}

public void setRaw(Boolean raw) {
this.raw = raw;
}

public static boolean isRaw(GetOperationOptions options) {
if (options == null) {
return false;
}
if (options.raw == null) {
return false;
}
return options.raw;
}

public static GetOperationOptions createRaw() {
GetOperationOptions opts = new GetOperationOptions();
opts.setRaw(true);
return opts;
}


public Boolean getDoNotDiscovery() {
return doNotDiscovery;
}

Expand Down Expand Up @@ -258,6 +291,17 @@ public boolean equals(Object obj) {
return true;
}

public GetOperationOptions clone() {
GetOperationOptions clone = new GetOperationOptions();
clone.noFetch = this.noFetch;
clone.doNotDiscovery = this.doNotDiscovery;
clone.raw = this.raw;
clone.resolve = this.resolve;
clone.resolveNames = this.resolveNames;
clone.retrieve = this.retrieve;
return clone;
}

@Override
public String toString() {
return "GetOperationOptions(resolve=" + resolve + ", noFetch=" + noFetch
Expand Down
20 changes: 20 additions & 0 deletions infra/util/src/main/java/com/evolveum/midpoint/util/DOMUtil.java
Expand Up @@ -49,6 +49,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
Expand Down Expand Up @@ -1260,5 +1261,24 @@ private static String makeSafelyPrintable(String text, int maxSize) {
return sb.toString();
}

public static void createComment(Element element, String text) {
if (text != null) {
Comment commentNode = element.getOwnerDocument().createComment(replaceInvalidXmlChars(text));
element.appendChild(commentNode);
}
}

private static String replaceInvalidXmlChars(String text) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (!XMLChar.isValid(c)) {
sb.append('.');
} else {
sb.append(c);
}
}
return sb.toString();
}

}
Expand Up @@ -102,7 +102,7 @@ <F extends ObjectType> ModelContext<F> previewChanges(
*/
<O extends ObjectType> PrismObjectDefinition<O> getEditObjectDefinition(PrismObject<O> object, AuthorizationPhaseType phase) throws SchemaException;

RefinedObjectClassDefinition getEditObjectClassDefinition(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource) throws SchemaException;
RefinedObjectClassDefinition getEditObjectClassDefinition(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, AuthorizationPhaseType phase) throws SchemaException;

/**
* <p>
Expand Down

0 comments on commit 39877bf

Please sign in to comment.