Skip to content

Commit

Permalink
added possibility to override resource schema and set secondary ident…
Browse files Browse the repository at this point in the history
…ifier - imporved consistency mechanism..
  • Loading branch information
katkav committed Oct 4, 2014
1 parent dbb0f1e commit 05abb27
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
Expand Up @@ -48,6 +48,7 @@ public class RefinedAttributeDefinition extends ResourceAttributeDefinition impl
private String description;
private boolean tolerant = true;
private boolean isExclusiveStrong = false;
protected boolean secondaryIdentifier = false;
private List<String> intolerantValuePattern;
private List<String> tolerantValuePattern;
private ResourceAttributeDefinition attributeDefinition;
Expand Down Expand Up @@ -75,6 +76,14 @@ public void setTolerant(boolean tolerant) {
this.tolerant = tolerant;
}

public boolean isSecondaryIdentifier() {
return secondaryIdentifier;
}

public void setSecondaryIdentifier(boolean secondaryIdentifier) {
this.secondaryIdentifier = secondaryIdentifier;
}

@Override
public boolean canAdd() {
return canAdd(DEFAULT_LAYER);
Expand Down Expand Up @@ -328,6 +337,7 @@ static RefinedAttributeDefinition parse(ResourceAttributeDefinition schemaAttrDe
schemaLimitations.getAccess().setModify(schemaAttrDef.canModify());
schemaLimitations.getAccess().setRead(schemaAttrDef.canRead());


if (schemaHandlingAttrDefType != null) {

if (schemaHandlingAttrDefType.getDescription() != null) {
Expand All @@ -340,6 +350,12 @@ static RefinedAttributeDefinition parse(ResourceAttributeDefinition schemaAttrDe
rAttrDef.tolerant = schemaHandlingAttrDefType.isTolerant();
}

if (schemaHandlingAttrDefType.isSecondaryIdentifier() == null){
rAttrDef.secondaryIdentifier = false;
} else {
rAttrDef.secondaryIdentifier = schemaHandlingAttrDefType.isSecondaryIdentifier();
}

rAttrDef.tolerantValuePattern = schemaHandlingAttrDefType.getTolerantValuePattern();
rAttrDef.intolerantValuePattern = schemaHandlingAttrDefType.getIntolerantValuePattern();

Expand All @@ -365,6 +381,8 @@ static RefinedAttributeDefinition parse(ResourceAttributeDefinition schemaAttrDe
limitations.getAccess().setAdd(previousLimitations.getAccess().isAdd());
limitations.getAccess().setRead(previousLimitations.getAccess().isRead());
limitations.getAccess().setModify(previousLimitations.getAccess().isModify());
limitations.setSecondaryIdentifier(previousLimitations.isSecondaryIdentifier());
limitations.setUnique(previousLimitations.isUnique());
}
previousLimitations = limitations;
if (schemaHandlingAttrDefType != null) {
Expand Down Expand Up @@ -408,6 +426,7 @@ private static void applyLimitationsType(PropertyLimitations limitations, Proper
limitations.getAccess().setModify(accessType.isModify());
}
}

}

private static PropertyLimitationsType getLimitationsType(List<PropertyLimitationsType> limitationsTypes, LayerType layer) throws SchemaException {
Expand Down
Expand Up @@ -576,7 +576,7 @@ private void processIdentifiers(RefinedAttributeDefinition rAttrDef, ObjectClass
if (objectClassDef.isIdentifier(attrName)) {
((Collection)getIdentifiers()).add(rAttrDef);
}
if (objectClassDef.isSecondaryIdentifier(attrName)) {
if (objectClassDef.isSecondaryIdentifier(attrName) || rAttrDef.isSecondaryIdentifier()) {
((Collection)getSecondaryIdentifiers()).add(rAttrDef);
}
}
Expand Down
10 changes: 10 additions & 0 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd
Expand Up @@ -3567,6 +3567,16 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="secondaryIdentifier" type="xsd:boolean" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Indicated if the attribute should be considered as secondary identifier. If set to true,
this attribue is stored in repository and user for example by synchronization (correlation
rule), consistency mechanism, etc.
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="tolerantValuePattern" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Expand Down
Expand Up @@ -389,16 +389,6 @@ private <F extends FocusType> void processProjections(LensContext<F> context,
}
LOGGER.trace("User {} satisfies correlation rules.", context.getFocusContext().getObjectNew());

// result.computeStatus();
// // if the result is fatal error, it may mean that the
// // already exists expection occures before..but in this
// // scenario it means, the exception was handled and we
// // can mute the result to give better understanding of
// // the situation which happend
// if (result.isError()){
// result.muteError();
// }
//
// Re-do this same iteration again (do not increase iteration count).
// It will recompute the values and therefore enforce the user deltas and enable reconciliation
skipUniquenessCheck = true; // to avoid endless loop
Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.evolveum.midpoint.prism.query.AndFilter;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrFilter;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription;
Expand Down Expand Up @@ -124,21 +125,29 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except
private ObjectQuery createQueryByIcfName(ShadowType shadow) throws SchemaException {
// TODO: error handling TODO TODO TODO set matching rule instead of null in equlas filter
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow);
PrismProperty nameProperty = null;
if (secondaryIdentifiers.size() != 1){
nameProperty = shadow.getAttributes().asPrismContainerValue()
.findProperty(new QName(SchemaConstants.NS_ICF_SCHEMA, "name"));
} else {
nameProperty = secondaryIdentifiers.iterator().next();

List<EqualFilter> secondaryIdentifierFilters = new ArrayList<EqualFilter>();

for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers){
EqualFilter equal = EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, secondaryIdentifier.getElementName()), secondaryIdentifier);
secondaryIdentifierFilters.add(equal);
}
OrFilter orSecondary = OrFilter.createOr((List)secondaryIdentifierFilters);
// PrismProperty nameProperty = null;
// if (secondaryIdentifiers.size() != 1){
// nameProperty = shadow.getAttributes().asPrismContainerValue()
// .findProperty(new QName(SchemaConstants.NS_ICF_SCHEMA, "name"));
// } else {
// nameProperty = secondaryIdentifiers.iterator().next();
// }

EqualFilter nameFilter = EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, nameProperty.getDefinition().getName()),nameProperty);
// EqualFilter nameFilter = EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, nameProperty.getDefinition().getName()),nameProperty);
RefFilter resourceRefFilter = RefFilter.createReferenceEqual(ShadowType.F_RESOURCE_REF, ShadowType.class,
prismContext, shadow.getResourceRef().getOid());
EqualFilter objectClassFilter = EqualFilter.createEqual(ShadowType.F_OBJECT_CLASS, ShadowType.class, prismContext,
null, shadow.getObjectClass());

ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.createAnd(nameFilter, resourceRefFilter,
ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.createAnd(orSecondary, resourceRefFilter,
objectClassFilter));

return query;
Expand Down
Expand Up @@ -197,7 +197,10 @@ public static String getResourceOidFromFilter(List<? extends ObjectFilter> condi
return values.get(0).getOid();
}
if (NaryLogicalFilter.class.isAssignableFrom(f.getClass())){
return getResourceOidFromFilter(((NaryLogicalFilter) f).getConditions());
String resourceOid = getResourceOidFromFilter(((NaryLogicalFilter) f).getConditions());
if (resourceOid != null){
return resourceOid;
}
}
}

Expand All @@ -221,7 +224,10 @@ public static <T> T getValueFromFilter(List<? extends ObjectFilter> conditions,
return (T) ((PrismPropertyValue)values.get(0)).getValue();
}
if (NaryLogicalFilter.class.isAssignableFrom(f.getClass())){
return getValueFromFilter(((NaryLogicalFilter) f).getConditions(), propertyName);
T value = getValueFromFilter(((NaryLogicalFilter) f).getConditions(), propertyName);
if (value != null){
return value;
}
}
}

Expand Down

0 comments on commit 05abb27

Please sign in to comment.