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
semancik committed Jul 16, 2014
2 parents d9262d9 + 6166d4e commit fe16a5a
Show file tree
Hide file tree
Showing 93 changed files with 1,762 additions and 828 deletions.
Expand Up @@ -517,7 +517,7 @@ private ItemPath joinPath(ItemPath path, ItemPath deltaPath) {
ItemPathSegment firstDeltaSegment = deltaPath != null ? deltaPath.first() : null;
if (path != null) {
for (ItemPathSegment seg : path.getSegments()) {
if (seg.equals(firstDeltaSegment)) {
if (seg.equivalent(firstDeltaSegment)) {
break;
}
newPath.add(seg);
Expand Down
Expand Up @@ -235,7 +235,7 @@ public List<ContainerWrapper> getContainers() {
public ContainerWrapper findContainerWrapper(ItemPath path) {
for (ContainerWrapper wrapper : getContainers()) {
if (path != null) {
if (path.equals(wrapper.getPath())) {
if (path.equivalent(wrapper.getPath())) {
return wrapper;
}
} else {
Expand Down Expand Up @@ -505,7 +505,7 @@ public ObjectDelta getObjectDelta() throws SchemaException {

//TODO: need to check if the resource has defined capabilities
//todo this is bad hack because now we have not tri-state checkbox
if (SchemaConstants.PATH_ACTIVATION.equals(path)) {
if (SchemaConstants.PATH_ACTIVATION.equivalent(path)) {

if (object.asObjectable() instanceof ShadowType
&& (((ShadowType) object.asObjectable()).getActivation() == null
Expand All @@ -522,7 +522,7 @@ public ObjectDelta getObjectDelta() throws SchemaException {
switch (valueWrapper.getStatus()) {
case ADDED:
if (newValCloned != null) {
if (SchemaConstants.PATH_PASSWORD.equals(path)) {
if (SchemaConstants.PATH_PASSWORD.equivalent(path)) {
// password change will always look like add,
// therefore we push replace
pDelta.setValuesToReplace(Arrays.asList(newValCloned));
Expand Down
Expand Up @@ -228,7 +228,7 @@ private boolean hasPendingModification(IModel<PropertyWrapper> model) {
for (ItemDeltaType itemDelta : delta.getItemDelta()) {
ItemDelta iDelta = DeltaConvertor.createItemDelta(itemDelta, (Class<? extends Objectable>)
prismObject.getCompileTimeClass(), prismObject.getPrismContext());
if (iDelta.getPath().equals(path)) {
if (iDelta.getPath().equivalent(path)) {
return true;
}
}
Expand Down
Expand Up @@ -316,7 +316,7 @@ private DateValidator getActivationRangeValidator(Form form, ItemPath path) {
List<DateValidator> validators = form.getBehaviors(DateValidator.class);
if (validators != null) {
for (DateValidator val : validators) {
if (path.equals(val.getIdentifier())) {
if (path.equivalent(val.getIdentifier())) {
validator = val;
break;
}
Expand Down
Expand Up @@ -62,7 +62,7 @@ public PropertyWrapper(ContainerWrapper container, PrismProperty property, boole

ItemPath passwordPath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_PASSWORD);
if (passwordPath.equals(container.getPath())
if (passwordPath.equivalent(container.getPath())
&& PasswordType.F_VALUE.equals(property.getElementName())) {
displayName = "prismPropertyPanel.name.credentials.password";
}
Expand Down Expand Up @@ -179,7 +179,7 @@ private boolean isUser() {
}

private boolean isThisPropertyActivationEnabled() {
if (!new ItemPath(UserType.F_ACTIVATION).equals(container.getPath())) {
if (!new ItemPath(UserType.F_ACTIVATION).equivalent(container.getPath())) {
return false;
}

Expand Down
Expand Up @@ -1216,7 +1216,7 @@ private ItemPath joinPath(ItemPath path, ItemPath deltaPath) {
ItemPathSegment firstDeltaSegment = deltaPath != null ? deltaPath.first() : null;
if (path != null) {
for (ItemPathSegment seg : path.getSegments()) {
if (seg.equals(firstDeltaSegment)) {
if (seg.equivalent(firstDeltaSegment)) {
break;
}
newPath.add(seg);
Expand Down
12 changes: 1 addition & 11 deletions infra/common/src/test/resources/refinery/resource-complex.xml
Expand Up @@ -26,16 +26,6 @@
xmlns:enc="http://www.w3.org/2001/04/xmlenc#">
<name>Localhost OpenDJ Complex</name>
<connectorRef oid="14e63399-8869-4787-9369-93f9d1311671" type="ConnectorType">
<and xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000003"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:my="http://myself.me/schemas/whatever">
<c:type uri="http://midpoint.evolveum.com/xml/ns/public/common/common-3#ConnectorType" />
<c:equal>
<c:value>
<c:connectorType>org.identityconnectors.ldap.LdapConnector</c:connectorType>
</c:value>
</c:equal>
</and>
</connectorRef>
<connectorConfiguration>
<icfcldap:configurationProperties xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
Expand Down Expand Up @@ -411,7 +401,7 @@
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000003"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:my="http://myself.me/schemas/whatever">
<path>.</path>
<path>name</path>
<c:expression>
<c:script>
<c:code>
Expand Down
Expand Up @@ -39,9 +39,8 @@
<q:and>
<q:type uri="http://midpoint.evolveum.com/xml/ns/public/common/common-3#ConnectorType" />
<q:equal>
<q:value>
<connectorType>org.identityconnectors.ldap.LdapConnector</connectorType>
</q:value>
<q:path>connectorType</q:path>
<q:value>org.identityconnectors.ldap.LdapConnector</q:value>
</q:equal>
</q:and>
</filter>
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import org.apache.commons.lang.StringUtils;

/**
* Abstract item definition in the schema.
Expand Down Expand Up @@ -271,7 +272,17 @@ public void adoptElementDefinitionFrom(ItemDefinition otherDef) {
* @return created item instance
*/
abstract public Item instantiate(QName name);


// add namespace from the definition if it's safe to do so
protected QName addNamespaceIfApplicable(QName name) {
if (StringUtils.isEmpty(name.getNamespaceURI())) {
if (QNameUtil.match(name, this.name)) {
return this.name;
}
}
return name;
}

<T extends ItemDefinition> T findItemDefinition(ItemPath path, Class<T> clazz) {
if (path.isEmpty()) {
if (clazz.isAssignableFrom(this.getClass())) {
Expand Down
Expand Up @@ -74,7 +74,7 @@ public boolean equals(Object obj) {
if (residualPath == null) {
if (other.residualPath != null)
return false;
} else if (!residualPath.equals(other.residualPath))
} else if (!residualPath.equivalent(other.residualPath)) // TODO: ok?
return false;
return true;
}
Expand Down
Expand Up @@ -567,24 +567,25 @@ public <I extends Item<?>> void removeItem(ItemPath path, Class<I> itemType) {
}

// Expects that the "self" path segment is NOT included in the basePath
void addItemPathsToList(ItemPath basePath, Collection<ItemPath> list) {
boolean addIds = true;
if (getDefinition() != null) {
if (getDefinition().isSingleValue()) {
addIds = false;
}
}
for (PrismContainerValue<V> pval: getValues()) {
ItemPath subpath = null;
ItemPathSegment segment = null;
if (addIds) {
subpath = basePath.subPath(new IdItemPathSegment(pval.getId())).subPath(new NameItemPathSegment(getElementName()));
} else {
subpath = basePath.subPath(new NameItemPathSegment(getElementName()));
}
pval.addItemPathsToList(subpath, list);
}
}
// is this method used anywhere?
// void addItemPathsToList(ItemPath basePath, Collection<ItemPath> list) {
// boolean addIds = true;
// if (getDefinition() != null) {
// if (getDefinition().isSingleValue()) {
// addIds = false;
// }
// }
// for (PrismContainerValue<V> pval: getValues()) {
// ItemPath subpath = null;
// ItemPathSegment segment = null;
// if (addIds) {
// subpath = basePath.subPath(new IdItemPathSegment(pval.getId())).subPath(new NameItemPathSegment(getElementName()));
// } else {
// subpath = basePath.subPath(new NameItemPathSegment(getElementName()));
// }
// pval.addItemPathsToList(subpath, list);
// }
// }

@Override
public ContainerDelta<V> createDelta() {
Expand Down Expand Up @@ -705,7 +706,7 @@ public boolean equals(Object obj) {
}

/**
* this method ignores some part of the object during comparison (e.g. source demarkation in values)
* This method ignores some part of the object during comparison (e.g. source demarcation in values)
* These methods compare the "meaningful" parts of the objects.
*/
public boolean equivalent(Object obj) {
Expand Down
Expand Up @@ -326,6 +326,7 @@ public PrismContainer<V> instantiate() {
*/
@Override
public PrismContainer<V> instantiate(QName elementName) {
elementName = addNamespaceIfApplicable(elementName);
return new PrismContainer<V>(elementName, this, prismContext);
}

Expand Down
Expand Up @@ -38,6 +38,7 @@
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;

Expand Down Expand Up @@ -486,17 +487,18 @@ public void replace(Item<?> oldItem, Item<?> newItem) throws SchemaException {

// Expects that the "self" path segment is already included in the basePath
// todo treat unqualified names
void addItemPathsToList(ItemPath basePath, Collection<ItemPath> list) {
if (items != null) {
for (Item<?> item: items) {
if (item instanceof PrismProperty) {
list.add(basePath.subPath(item.getElementName()));
} else if (item instanceof PrismContainer) {
((PrismContainer<?>)item).addItemPathsToList(basePath, list);
}
}
}
}
// is this method used anywhere?
// void addItemPathsToList(ItemPath basePath, Collection<ItemPath> list) {
// if (items != null) {
// for (Item<?> item: items) {
// if (item instanceof PrismProperty) {
// list.add(basePath.subPath(item.getElementName()));
// } else if (item instanceof PrismContainer) {
// ((PrismContainer<?>)item).addItemPathsToList(basePath, list);
// }
// }
// }
// }

public void clear() {
if (items != null) {
Expand Down Expand Up @@ -716,30 +718,18 @@ private Item<?> findItemByQName(QName subName) throws SchemaException {
if (items == null) {
return null;
}
if (StringUtils.isNotEmpty(subName.getNamespaceURI())) {
// traditional search by fully qualified name
for (Item<?> item : items) {
if (subName.equals(item.getElementName())) {
return item;
}
}
return null;
} else {
// approximate search using local part
String localNameToFind = subName.getLocalPart();
Item<?> matching = null;
for (Item<?> item : items) {
if (localNameToFind.equals(item.getElementName().getLocalPart())) {
if (matching != null) {
String containerName = getParent() != null ? DebugUtil.formatElementName(getParent().getElementName()) : "";
throw new SchemaException("Using ambiguous unqualified item name " + localNameToFind + " in container " + containerName);
} else {
matching = item;
}
Item<?> matching = null;
for (Item<?> item : items) {
if (QNameUtil.match(subName, item.getElementName())) {
if (matching != null) {
String containerName = getParent() != null ? DebugUtil.formatElementName(getParent().getElementName()) : "";
throw new SchemaException("More than one items matching " + subName + " in container " + containerName);
} else {
matching = item;
}
}
return matching;
}
return matching;
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -294,7 +294,7 @@ public boolean equals(Object obj) {
}

/**
* this method ignores some part of the object during comparison (e.g. source demarkation in values)
* this method ignores some part of the object during comparison (e.g. source demarcation in values)
* These methods compare the "meaningful" parts of the objects.
*/
public boolean equivalent(Object obj) {
Expand Down
Expand Up @@ -18,9 +18,6 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;

/**
* MidPoint Object Definition.
*
Expand Down Expand Up @@ -54,6 +51,7 @@ public PrismObject<T> instantiate() {

@Override
public PrismObject<T> instantiate(QName name) {
name = addNamespaceIfApplicable(name);
PrismObject<T> midPointObject = new PrismObject<T>(name, this, prismContext);
return midPointObject;
}
Expand Down
Expand Up @@ -117,6 +117,7 @@ public PrismProperty<T> instantiate() {

@Override
public PrismProperty<T> instantiate(QName name) {
name = addNamespaceIfApplicable(name);
return new PrismProperty<T>(name, this, prismContext);
}

Expand Down
Expand Up @@ -44,6 +44,7 @@
import org.w3c.dom.Element;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

/**
* @author lazyman
Expand Down Expand Up @@ -111,8 +112,9 @@ public T getValue() {
// Do the most stupid thing possible. Assume string value. And there will be no definition.
value = (T) ((Element)rawElement).getTextContent();
} else if (rawElement instanceof PrimitiveXNode){
try{
value = (T) ((PrimitiveXNode) rawElement).getParsedValue(DOMUtil.XSD_STRING);
try {
QName type = rawElement.getTypeQName() != null ? rawElement.getTypeQName() : DOMUtil.XSD_STRING;
value = (T) ((PrimitiveXNode) rawElement).getParsedValueWithoutRecording(type);
} catch (SchemaException ex){
throw new IllegalStateException("Cannot fetch value from raw element. " + ex.getMessage(), ex);
}
Expand Down Expand Up @@ -421,9 +423,6 @@ public boolean equalsComplex(PrismPropertyValue<?> other, boolean ignoreMetadata
}

private boolean equalsRawElements(PrismPropertyValue<T> other) {
if (this.rawElement instanceof Element && other.rawElement instanceof Element) {
return DOMUtil.compareElement((Element)this.rawElement, (Element)other.rawElement, false);
}
return this.rawElement.equals(other.rawElement);
}

Expand Down
Expand Up @@ -106,6 +106,7 @@ public PrismReference instantiate() {

@Override
public PrismReference instantiate(QName name) {
name = addNamespaceIfApplicable(name);
return new PrismReference(name, this, prismContext);
}

Expand Down

0 comments on commit fe16a5a

Please sign in to comment.