use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class AbstractModificationConverter method convert.
public void convert() throws SchemaException {
PropertyDelta<QName> auxiliaryObjectClassDelta = determineAuxilaryObjectClassDelta(changes);
ResourceObjectDefinition structuralObjectClassDefinition = resourceSchema.findDefinitionForObjectClass(objectDefinition.getTypeName());
if (structuralObjectClassDefinition == null) {
throw new SchemaException("No definition of structural object class " + objectDefinition.getTypeName() + " in " + connectorDescription);
}
Map<QName, ResourceObjectDefinition> auxiliaryObjectClassMap = new HashMap<>();
if (auxiliaryObjectClassDelta != null) {
// Auxiliary object class change means modification of __AUXILIARY_OBJECT_CLASS__ attribute
collect(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME, auxiliaryObjectClassDelta, null, (pvals, midPointAttributeName) -> covertAuxiliaryObjectClassValuesToConnId(pvals, midPointAttributeName, auxiliaryObjectClassMap));
}
for (Operation operation : changes) {
if (operation instanceof PropertyModificationOperation) {
PropertyModificationOperation change = (PropertyModificationOperation) operation;
PropertyDelta<?> delta = change.getPropertyDelta();
if (delta.getParentPath().equivalent(ShadowType.F_ATTRIBUTES)) {
if (delta.getDefinition() == null || !(delta.getDefinition() instanceof ResourceAttributeDefinition)) {
ResourceAttributeDefinition def = objectDefinition.findAttributeDefinition(delta.getElementName());
if (def == null) {
String message = "No definition for attribute " + delta.getElementName() + " used in modification delta";
throw new SchemaException(message);
}
try {
delta.applyDefinition(def);
} catch (SchemaException e) {
throw e;
}
}
PlusMinusZero isInModifiedAuxilaryClass = null;
ResourceAttributeDefinition<?> structAttrDef = structuralObjectClassDefinition.findAttributeDefinition(delta.getElementName());
// aux object class, we cannot add/remove it with the object class unless it is normally requested
if (structAttrDef == null) {
if (auxiliaryObjectClassDelta != null && auxiliaryObjectClassDelta.isDelete()) {
// is removed, the attributes must be removed as well.
for (PrismPropertyValue<QName> auxPval : auxiliaryObjectClassDelta.getValuesToDelete()) {
ResourceObjectDefinition auxDef = auxiliaryObjectClassMap.get(auxPval.getValue());
ResourceAttributeDefinition<?> attrDef = auxDef.findAttributeDefinition(delta.getElementName());
if (attrDef != null) {
// means: is in removed auxiliary class
isInModifiedAuxilaryClass = PlusMinusZero.MINUS;
break;
}
}
}
if (auxiliaryObjectClassDelta != null && auxiliaryObjectClassDelta.isAdd()) {
// is added, the attributes must be added as well.
for (PrismPropertyValue<QName> auxPval : auxiliaryObjectClassDelta.getValuesToAdd()) {
ResourceObjectDefinition auxOcDef = auxiliaryObjectClassMap.get(auxPval.getValue());
ResourceAttributeDefinition<?> auxAttrDef = auxOcDef.findAttributeDefinition(delta.getElementName());
if (auxAttrDef != null) {
// means: is in added auxiliary class
isInModifiedAuxilaryClass = PlusMinusZero.PLUS;
break;
}
}
}
}
// Change in (ordinary) attributes. Transform to the ConnId attributes.
String connIdAttrName = connIdNameMapper.convertAttributeNameToConnId(delta, objectDefinition);
collect(connIdAttrName, delta, isInModifiedAuxilaryClass);
} else if (delta.getParentPath().equivalent(ShadowType.F_ACTIVATION)) {
convertFromActivation(delta);
} else if (delta.getParentPath().equivalent(SchemaConstants.PATH_PASSWORD)) {
convertFromPassword((PropertyDelta<ProtectedStringType>) delta);
} else if (delta.getPath().equivalent(ShadowType.F_AUXILIARY_OBJECT_CLASS)) {
// already processed
} else {
throw new SchemaException("Change of unknown attribute " + delta.getPath());
}
} else {
throw new IllegalArgumentException("Unknown operation type " + operation.getClass().getName() + ": " + operation);
}
}
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class AbstractModificationConverter method covertAuxiliaryObjectClassValuesToConnId.
private <T> List<Object> covertAuxiliaryObjectClassValuesToConnId(Collection<PrismPropertyValue<QName>> pvals, QName midPointAttributeName, Map<QName, ResourceObjectDefinition> auxiliaryObjectClassMap) throws SchemaException {
List<Object> connIdVals = new ArrayList<>(pvals.size());
for (PrismPropertyValue<QName> pval : pvals) {
QName auxQName = pval.getValue();
ResourceObjectDefinition auxDef = resourceSchema.findDefinitionForObjectClass(auxQName);
if (auxDef == null) {
throw new SchemaException("Auxiliary object class " + auxQName + " not found in the schema");
}
auxiliaryObjectClassMap.put(auxQName, auxDef);
ObjectClass icfOc = connIdNameMapper.objectClassToConnId(pval.getValue(), connectorType, false);
connIdVals.add(icfOc.getObjectClassValue());
}
return connIdVals;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class SyncDeltaConverter method getActualObjectDefinition.
@Nullable
private ResourceObjectDefinition getActualObjectDefinition(SyncDelta connIdDelta) throws SchemaException {
if (requestedObjectDefinition != null) {
return requestedObjectDefinition;
}
ObjectClass deltaConnIdObjectClass = connIdDelta.getObjectClass();
QName deltaObjectClassName = nameMapper.objectClassToQname(deltaConnIdObjectClass, connectorInstance.isLegacySchema());
ResourceObjectDefinition deltaObjectClass;
if (deltaConnIdObjectClass != null) {
deltaObjectClass = (ResourceObjectClassDefinition) connectorInstance.getRawResourceSchema().findComplexTypeDefinitionByType(deltaObjectClassName);
} else {
deltaObjectClass = null;
}
if (deltaObjectClass == null) {
if (connIdDelta.getDeltaType() == SyncDeltaType.DELETE) {
// tolerate this. E.g. LDAP changelogs do not have objectclass in delete deltas.
} else {
throw new SchemaException("Got delta with object class " + deltaObjectClassName + " (" + deltaConnIdObjectClass + ") that has no definition in resource schema");
}
}
return deltaObjectClass;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class SyncDeltaConverter method createChange.
@NotNull
UcfLiveSyncChange createChange(int localSequenceNumber, SyncDelta connIdDelta, OperationResult result) {
// The following should not throw any exception. And if it does, we are lost anyway, because
// we need this information to create even "errored" change object.
// For non-nullability of these variables see the code of SyncDelta.
@NotNull SyncDeltaType icfDeltaType = connIdDelta.getDeltaType();
@NotNull Uid uid = connIdDelta.getUid();
@NotNull String uidValue = uid.getUidValue();
@NotNull UcfSyncToken token = toUcf(connIdDelta.getToken());
Collection<ResourceAttribute<?>> identifiers = new ArrayList<>();
ResourceObjectDefinition actualObjectDefinition = null;
ObjectDelta<ShadowType> objectDelta = null;
PrismObject<ShadowType> resourceObject = null;
LOGGER.trace("START creating delta of type {}", icfDeltaType);
UcfErrorState errorState;
try {
actualObjectDefinition = getActualObjectDefinition(connIdDelta);
assert actualObjectDefinition != null || icfDeltaType == SyncDeltaType.DELETE;
if (icfDeltaType == SyncDeltaType.DELETE) {
identifiers.addAll(ConnIdUtil.convertToIdentifiers(uid, actualObjectDefinition, connectorInstance.getRawResourceSchema()));
objectDelta = prismContext.deltaFactory().object().create(ShadowType.class, ChangeType.DELETE);
} else if (icfDeltaType == SyncDeltaType.CREATE || icfDeltaType == SyncDeltaType.CREATE_OR_UPDATE || icfDeltaType == SyncDeltaType.UPDATE) {
PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(actualObjectDefinition);
LOGGER.trace("Object definition: {}", objectDefinition);
// We can consider using "fetch result" error reporting method here, and go along with a partial object.
resourceObject = connIdConvertor.convertToUcfObject(connIdDelta.getObject(), objectDefinition, false, connectorInstance.isCaseIgnoreAttributeNames(), connectorInstance.isLegacySchema(), UcfFetchErrorReportingMethod.EXCEPTION, result).getResourceObject();
LOGGER.trace("Got (current) resource object: {}", resourceObject.debugDumpLazily());
identifiers.addAll(emptyIfNull(ShadowUtil.getAllIdentifiers(resourceObject)));
if (icfDeltaType == SyncDeltaType.CREATE) {
objectDelta = prismContext.deltaFactory().object().create(ShadowType.class, ChangeType.ADD);
objectDelta.setObjectToAdd(resourceObject);
}
} else {
throw new GenericFrameworkException("Unexpected sync delta type " + icfDeltaType);
}
if (identifiers.isEmpty()) {
throw new SchemaException("No identifiers in sync delta " + connIdDelta);
}
errorState = UcfErrorState.success();
} catch (Exception e) {
result.recordFatalError(e);
errorState = UcfErrorState.error(e);
}
UcfLiveSyncChange change = new UcfLiveSyncChange(localSequenceNumber, uidValue, identifiers, actualObjectDefinition, objectDelta, resourceObject, token, errorState);
LOGGER.trace("END creating change of type {}:\n{}", icfDeltaType, change.debugDumpLazily());
return change;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class RefinedResourceSchemaAsserter method objectClass.
public ResourceObjectDefinitionAsserter<RefinedResourceSchemaAsserter<RA>> objectClass(String ocName) {
ResourceObjectDefinition objectClassDefinition = getSchema().findDefinitionForObjectClass(new QName(MidPointConstants.NS_RI, ocName));
ResourceObjectDefinitionAsserter<RefinedResourceSchemaAsserter<RA>> asserter = new ResourceObjectDefinitionAsserter<>(objectClassDefinition, this, desc());
copySetupTo(asserter);
return asserter;
}
Aggregations