use of org.identityconnectors.framework.common.objects.ObjectClass in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method count.
@Override
public int count(ObjectClassComplexTypeDefinition objectClassDefinition, final ObjectQuery query, PagedSearchCapabilityType pagedSearchCapabilityType, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, UnsupportedOperationException {
// Result type for this operation
final OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".count");
result.addParam("objectClass", objectClassDefinition);
result.addContext("connector", connectorType);
if (objectClassDefinition == null) {
result.recordFatalError("Object class not defined");
throw new IllegalArgumentException("objectClass not defined");
}
ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(objectClassDefinition, getSchemaNamespace(), connectorType, legacySchema);
if (icfObjectClass == null) {
IllegalArgumentException ex = new IllegalArgumentException("Unable to determine object class from QName " + objectClassDefinition + " while attempting to search objects by " + ObjectTypeUtil.toShortString(connectorType));
result.recordFatalError("Unable to determine object class", ex);
throw ex;
}
final boolean useConnectorPaging = pagedSearchCapabilityType != null;
if (!useConnectorPaging) {
throw new UnsupportedOperationException("ConnectorInstanceIcfImpl.count operation is supported only in combination with connector-implemented paging");
}
OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
optionsBuilder.setAttributesToGet(Name.NAME);
optionsBuilder.setPagedResultsOffset(1);
optionsBuilder.setPageSize(1);
if (pagedSearchCapabilityType.getDefaultSortField() != null) {
String orderByIcfName = connIdNameMapper.convertAttributeNameToIcf(pagedSearchCapabilityType.getDefaultSortField(), objectClassDefinition, "(default sorting field)");
boolean isAscending = pagedSearchCapabilityType.getDefaultSortDirection() != OrderDirectionType.DESCENDING;
optionsBuilder.setSortKeys(new SortKey(orderByIcfName, isAscending));
}
OperationOptions options = optionsBuilder.build();
// Connector operation cannot create result for itself, so we need to
// create result for it
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".search");
icfResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
int retval;
try {
Filter filter = convertFilterToIcf(query, objectClassDefinition);
final Holder<Integer> fetched = new Holder<>(0);
ResultsHandler icfHandler = new ResultsHandler() {
@Override
public boolean handle(ConnectorObject connectorObject) {
// actually, this should execute at most once
fetched.setValue(fetched.getValue() + 1);
return false;
}
};
InternalMonitor.recordConnectorOperation("search");
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
SearchResult searchResult = connIdConnectorFacade.search(icfObjectClass, filter, icfHandler, options);
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
if (searchResult == null || searchResult.getRemainingPagedResults() == -1) {
throw new UnsupportedOperationException("Connector does not seem to support paged searches or does not provide object count information");
} else {
retval = fetched.getValue() + searchResult.getRemainingPagedResults();
}
icfResult.recordSuccess();
} catch (IntermediateException inex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, inex);
SchemaException ex = (SchemaException) inex.getCause();
icfResult.recordFatalError(ex);
result.recordFatalError(ex);
throw ex;
} catch (UnsupportedOperationException uoe) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, uoe);
icfResult.recordFatalError(uoe);
result.recordFatalError(uoe);
throw uoe;
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, ex);
Throwable midpointEx = processIcfException(ex, this, icfResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) midpointEx;
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
if (result.isUnknown()) {
result.recordSuccess();
}
return retval;
}
use of org.identityconnectors.framework.common.objects.ObjectClass in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method parseResourceSchema.
private void parseResourceSchema(org.identityconnectors.framework.common.objects.Schema icfSchema, List<QName> generateObjectClasses) {
AttributeInfo passwordAttributeInfo = null;
AttributeInfo enableAttributeInfo = null;
AttributeInfo enableDateAttributeInfo = null;
AttributeInfo disableDateAttributeInfo = null;
AttributeInfo lockoutAttributeInfo = null;
AttributeInfo auxiliaryObjectClasseAttributeInfo = null;
// New instance of midPoint schema object
setResourceSchema(new ResourceSchemaImpl(getSchemaNamespace(), prismContext));
if (legacySchema == null) {
legacySchema = detectLegacySchema(icfSchema);
}
LOGGER.trace("Converting resource schema (legacy mode: {})", legacySchema);
Set<ObjectClassInfo> objectClassInfoSet = icfSchema.getObjectClassInfo();
// Let's convert every objectclass in the ICF schema ...
for (ObjectClassInfo objectClassInfo : objectClassInfoSet) {
// "Flat" ICF object class names needs to be mapped to QNames
QName objectClassXsdName = connIdNameMapper.objectClassToQname(new ObjectClass(objectClassInfo.getType()), getSchemaNamespace(), legacySchema);
if (!shouldBeGenerated(generateObjectClasses, objectClassXsdName)) {
LOGGER.trace("Skipping object class {} ({})", objectClassInfo.getType(), objectClassXsdName);
continue;
}
LOGGER.trace("Convering object class {} ({})", objectClassInfo.getType(), objectClassXsdName);
// ResourceObjectDefinition is a midPpoint way how to represent an
// object class.
// The important thing here is the last "type" parameter
// (objectClassXsdName). The rest is more-or-less cosmetics.
ObjectClassComplexTypeDefinition ocDef = ((ResourceSchemaImpl) resourceSchema).createObjectClassDefinition(objectClassXsdName);
// objectclass. So mark it appropriately.
if (ObjectClass.ACCOUNT_NAME.equals(objectClassInfo.getType())) {
((ObjectClassComplexTypeDefinitionImpl) ocDef).setKind(ShadowKindType.ACCOUNT);
((ObjectClassComplexTypeDefinitionImpl) ocDef).setDefaultInAKind(true);
}
ResourceAttributeDefinition<String> uidDefinition = null;
ResourceAttributeDefinition<String> nameDefinition = null;
boolean hasUidDefinition = false;
int displayOrder = ConnectorFactoryConnIdImpl.ATTR_DISPLAY_ORDER_START;
// Let's iterate over all attributes in this object class ...
Set<AttributeInfo> attributeInfoSet = objectClassInfo.getAttributeInfo();
for (AttributeInfo attributeInfo : attributeInfoSet) {
String icfName = attributeInfo.getName();
if (OperationalAttributes.PASSWORD_NAME.equals(icfName)) {
// This attribute will not go into the schema
// instead a "password" capability is used
passwordAttributeInfo = attributeInfo;
// Skip this attribute, capability is sufficient
continue;
}
if (OperationalAttributes.ENABLE_NAME.equals(icfName)) {
enableAttributeInfo = attributeInfo;
// Skip this attribute, capability is sufficient
continue;
}
if (OperationalAttributes.ENABLE_DATE_NAME.equals(icfName)) {
enableDateAttributeInfo = attributeInfo;
// Skip this attribute, capability is sufficient
continue;
}
if (OperationalAttributes.DISABLE_DATE_NAME.equals(icfName)) {
disableDateAttributeInfo = attributeInfo;
// Skip this attribute, capability is sufficient
continue;
}
if (OperationalAttributes.LOCK_OUT_NAME.equals(icfName)) {
lockoutAttributeInfo = attributeInfo;
// Skip this attribute, capability is sufficient
continue;
}
if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equals(icfName)) {
auxiliaryObjectClasseAttributeInfo = attributeInfo;
// Skip this attribute, capability is sufficient
continue;
}
String processedAttributeName = icfName;
if ((Name.NAME.equals(icfName) || Uid.NAME.equals(icfName)) && attributeInfo.getNativeName() != null) {
processedAttributeName = attributeInfo.getNativeName();
}
QName attrXsdName = connIdNameMapper.convertAttributeNameToQName(processedAttributeName, ocDef);
QName attrXsdType = ConnIdUtil.icfTypeToXsdType(attributeInfo.getType(), false);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Attr conversion ICF: {}({}) -> XSD: {}({})", icfName, attributeInfo.getType().getSimpleName(), PrettyPrinter.prettyPrint(attrXsdName), PrettyPrinter.prettyPrint(attrXsdType));
}
// Create ResourceObjectAttributeDefinition, which is midPoint
// way how to express attribute schema.
ResourceAttributeDefinitionImpl attrDef = new ResourceAttributeDefinitionImpl(attrXsdName, attrXsdType, prismContext);
attrDef.setMatchingRuleQName(icfAttributeInfoToMatchingRule(attributeInfo));
if (Name.NAME.equals(icfName)) {
nameDefinition = attrDef;
if (uidDefinition != null && attrXsdName.equals(uidDefinition.getName())) {
attrDef.setDisplayOrder(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_ORDER);
uidDefinition = attrDef;
hasUidDefinition = true;
} else {
if (attributeInfo.getNativeName() == null) {
// Set a better display name for __NAME__. The "name" is s very
// overloaded term, so let's try to make things
// a bit clearer
attrDef.setDisplayName(ConnectorFactoryConnIdImpl.ICFS_NAME_DISPLAY_NAME);
}
attrDef.setDisplayOrder(ConnectorFactoryConnIdImpl.ICFS_NAME_DISPLAY_ORDER);
}
} else if (Uid.NAME.equals(icfName)) {
// UID can be the same as other attribute
ResourceAttributeDefinition existingDefinition = ocDef.findAttributeDefinition(attrXsdName);
if (existingDefinition != null) {
hasUidDefinition = true;
((ResourceAttributeDefinitionImpl) existingDefinition).setDisplayOrder(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_ORDER);
uidDefinition = existingDefinition;
continue;
} else {
uidDefinition = attrDef;
if (attributeInfo.getNativeName() == null) {
attrDef.setDisplayName(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_NAME);
}
attrDef.setDisplayOrder(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_ORDER);
}
} else {
// Check conflict with UID definition
if (uidDefinition != null && attrXsdName.equals(uidDefinition.getName())) {
attrDef.setDisplayOrder(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_ORDER);
uidDefinition = attrDef;
hasUidDefinition = true;
} else {
attrDef.setDisplayOrder(displayOrder);
displayOrder += ConnectorFactoryConnIdImpl.ATTR_DISPLAY_ORDER_INCREMENT;
}
}
attrDef.setNativeAttributeName(attributeInfo.getNativeName());
attrDef.setFrameworkAttributeName(icfName);
// Now we are going to process flags such as optional and
// multi-valued
Set<Flags> flagsSet = attributeInfo.getFlags();
// System.out.println(flagsSet);
attrDef.setMinOccurs(0);
attrDef.setMaxOccurs(1);
boolean canCreate = true;
boolean canUpdate = true;
boolean canRead = true;
for (Flags flags : flagsSet) {
if (flags == Flags.REQUIRED) {
attrDef.setMinOccurs(1);
}
if (flags == Flags.MULTIVALUED) {
attrDef.setMaxOccurs(-1);
}
if (flags == Flags.NOT_CREATABLE) {
canCreate = false;
}
if (flags == Flags.NOT_READABLE) {
canRead = false;
}
if (flags == Flags.NOT_UPDATEABLE) {
canUpdate = false;
}
if (flags == Flags.NOT_RETURNED_BY_DEFAULT) {
attrDef.setReturnedByDefault(false);
}
}
attrDef.setCanAdd(canCreate);
attrDef.setCanModify(canUpdate);
attrDef.setCanRead(canRead);
if (!Uid.NAME.equals(icfName)) {
((ObjectClassComplexTypeDefinitionImpl) ocDef).add(attrDef);
}
}
if (uidDefinition == null) {
// Every object has UID in ICF, therefore add a default definition if no other was specified
uidDefinition = new ResourceAttributeDefinitionImpl<>(SchemaConstants.ICFS_UID, DOMUtil.XSD_STRING, prismContext);
// DO NOT make it mandatory. It must not be present on create hence it cannot be mandatory.
((ResourceAttributeDefinitionImpl) uidDefinition).setMinOccurs(0);
((ResourceAttributeDefinitionImpl) uidDefinition).setMaxOccurs(1);
// Make it read-only
((ResourceAttributeDefinitionImpl) uidDefinition).setReadOnly();
// Set a default display name
((ResourceAttributeDefinitionImpl) uidDefinition).setDisplayName(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_NAME);
((ResourceAttributeDefinitionImpl) uidDefinition).setDisplayOrder(ConnectorFactoryConnIdImpl.ICFS_UID_DISPLAY_ORDER);
// Uid is a primary identifier of every object (this is the ICF way)
}
if (!hasUidDefinition) {
((ObjectClassComplexTypeDefinitionImpl) ocDef).add(uidDefinition);
}
((ObjectClassComplexTypeDefinitionImpl) ocDef).addPrimaryIdentifier(uidDefinition);
if (uidDefinition != nameDefinition) {
((ObjectClassComplexTypeDefinitionImpl) ocDef).addSecondaryIdentifier(nameDefinition);
}
// Add schema annotations
((ObjectClassComplexTypeDefinitionImpl) ocDef).setNativeObjectClass(objectClassInfo.getType());
((ObjectClassComplexTypeDefinitionImpl) ocDef).setDisplayNameAttribute(nameDefinition.getName());
((ObjectClassComplexTypeDefinitionImpl) ocDef).setNamingAttribute(nameDefinition.getName());
((ObjectClassComplexTypeDefinitionImpl) ocDef).setAuxiliary(objectClassInfo.isAuxiliary());
}
// This is the default for all resources.
// (Currently there is no way how to obtain it from the connector.)
// It can be disabled manually.
AddRemoveAttributeValuesCapabilityType addRemove = new AddRemoveAttributeValuesCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createAddRemoveAttributeValues(addRemove));
ActivationCapabilityType capAct = null;
if (enableAttributeInfo != null) {
if (capAct == null) {
capAct = new ActivationCapabilityType();
}
ActivationStatusCapabilityType capActStatus = new ActivationStatusCapabilityType();
capAct.setStatus(capActStatus);
if (!enableAttributeInfo.isReturnedByDefault()) {
capActStatus.setReturnedByDefault(false);
}
}
if (enableDateAttributeInfo != null) {
if (capAct == null) {
capAct = new ActivationCapabilityType();
}
ActivationValidityCapabilityType capValidFrom = new ActivationValidityCapabilityType();
capAct.setValidFrom(capValidFrom);
if (!enableDateAttributeInfo.isReturnedByDefault()) {
capValidFrom.setReturnedByDefault(false);
}
}
if (disableDateAttributeInfo != null) {
if (capAct == null) {
capAct = new ActivationCapabilityType();
}
ActivationValidityCapabilityType capValidTo = new ActivationValidityCapabilityType();
capAct.setValidTo(capValidTo);
if (!disableDateAttributeInfo.isReturnedByDefault()) {
capValidTo.setReturnedByDefault(false);
}
}
if (lockoutAttributeInfo != null) {
if (capAct == null) {
capAct = new ActivationCapabilityType();
}
ActivationLockoutStatusCapabilityType capActStatus = new ActivationLockoutStatusCapabilityType();
capAct.setLockoutStatus(capActStatus);
if (!lockoutAttributeInfo.isReturnedByDefault()) {
capActStatus.setReturnedByDefault(false);
}
}
if (capAct != null) {
capabilities.add(CAPABILITY_OBJECT_FACTORY.createActivation(capAct));
}
if (passwordAttributeInfo != null) {
CredentialsCapabilityType capCred = new CredentialsCapabilityType();
PasswordCapabilityType capPass = new PasswordCapabilityType();
if (!passwordAttributeInfo.isReturnedByDefault()) {
capPass.setReturnedByDefault(false);
}
if (passwordAttributeInfo.isReadable()) {
capPass.setReadable(true);
}
capCred.setPassword(capPass);
capabilities.add(CAPABILITY_OBJECT_FACTORY.createCredentials(capCred));
}
if (auxiliaryObjectClasseAttributeInfo != null) {
AuxiliaryObjectClassesCapabilityType capAux = new AuxiliaryObjectClassesCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createAuxiliaryObjectClasses(capAux));
}
boolean canPageSize = false;
boolean canPageOffset = false;
boolean canSort = false;
for (OperationOptionInfo searchOption : icfSchema.getSupportedOptionsByOperation(SearchApiOp.class)) {
switch(searchOption.getName()) {
case OperationOptions.OP_PAGE_SIZE:
canPageSize = true;
break;
case OperationOptions.OP_PAGED_RESULTS_OFFSET:
canPageOffset = true;
break;
case OperationOptions.OP_SORT_KEYS:
canSort = true;
break;
case OperationOptions.OP_RETURN_DEFAULT_ATTRIBUTES:
supportsReturnDefaultAttributes = true;
break;
}
}
if (canPageSize || canPageOffset || canSort) {
PagedSearchCapabilityType capPage = new PagedSearchCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createPagedSearch(capPage));
}
}
use of org.identityconnectors.framework.common.objects.ObjectClass in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method fetchChanges.
@Override
public List<Change> fetchChanges(ObjectClassComplexTypeDefinition objectClass, PrismProperty<?> lastToken, AttributesToReturn attrsToReturn, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".fetchChanges");
result.addContext("objectClass", objectClass);
result.addParam("lastToken", lastToken);
// create sync token from the property last token
SyncToken syncToken = null;
try {
syncToken = getSyncToken(lastToken);
LOGGER.trace("Sync token created from the property last token: {}", syncToken == null ? null : syncToken.getValue());
} catch (SchemaException ex) {
result.recordFatalError(ex.getMessage(), ex);
throw new SchemaException(ex.getMessage(), ex);
}
final List<SyncDelta> syncDeltas = new ArrayList<SyncDelta>();
// get icf object class
ObjectClass icfObjectClass;
if (objectClass == null) {
icfObjectClass = ObjectClass.ALL;
} else {
icfObjectClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
}
OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
if (objectClass != null) {
convertToIcfAttrsToGet(objectClass, attrsToReturn, optionsBuilder);
}
OperationOptions options = optionsBuilder.build();
SyncResultsHandler syncHandler = new SyncResultsHandler() {
@Override
public boolean handle(SyncDelta delta) {
LOGGER.trace("Detected sync delta: {}", delta);
return syncDeltas.add(delta);
}
};
OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".sync");
connIdResult.addContext("connector", connIdConnectorFacade.getClass());
connIdResult.addArbitraryObjectAsParam("connIdObjectClass", icfObjectClass);
connIdResult.addArbitraryObjectAsParam("syncToken", syncToken);
connIdResult.addArbitraryObjectAsParam("syncHandler", syncHandler);
SyncToken lastReceivedToken;
try {
InternalMonitor.recordConnectorOperation("sync");
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
lastReceivedToken = connIdConnectorFacade.sync(icfObjectClass, syncToken, syncHandler, options);
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
connIdResult.recordSuccess();
connIdResult.addReturn(OperationResult.RETURN_COUNT, syncDeltas.size());
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass, ex);
Throwable midpointEx = processIcfException(ex, this, connIdResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) midpointEx;
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
// convert changes from icf to midpoint Change
List<Change> changeList;
try {
changeList = getChangesFromSyncDeltas(icfObjectClass, syncDeltas, resourceSchema, result);
} catch (SchemaException ex) {
result.recordFatalError(ex.getMessage(), ex);
throw new SchemaException(ex.getMessage(), ex);
}
if (lastReceivedToken != null) {
Change lastChange = new Change((ObjectDelta) null, getToken(lastReceivedToken));
LOGGER.trace("Adding last change: {}", lastChange);
changeList.add(lastChange);
}
result.recordSuccess();
result.addReturn(OperationResult.RETURN_COUNT, changeList == null ? 0 : changeList.size());
return changeList;
}
use of org.identityconnectors.framework.common.objects.ObjectClass in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method deleteObject.
@Override
public AsynchronousOperationResult deleteObject(ObjectClassComplexTypeDefinition objectClass, Collection<Operation> additionalOperations, Collection<? extends ResourceAttribute<?>> identifiers, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException {
Validate.notNull(objectClass, "No objectclass");
OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".deleteObject");
result.addCollectionOfSerializablesAsParam("identifiers", identifiers);
ObjectClass objClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
Uid uid;
try {
uid = getUid(objectClass, identifiers);
} catch (SchemaException e) {
result.recordFatalError(e);
throw e;
}
checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".delete");
icfResult.addArbitraryObjectAsParam("uid", uid);
icfResult.addArbitraryObjectAsParam("objectClass", objClass);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
try {
InternalMonitor.recordConnectorOperation("delete");
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_DELETE, objectClass, uid);
connIdConnectorFacade.delete(objClass, uid, new OperationOptionsBuilder().build());
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, null, uid);
icfResult.recordSuccess();
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, ex, uid);
String desc = this.getHumanReadableName() + " while deleting object identified by ICF UID '" + uid.getUidValue() + "'";
Throwable midpointEx = processIcfException(ex, desc, icfResult);
result.computeStatus("Removing attribute values failed");
// exception
if (midpointEx instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) midpointEx;
} else if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
// Schema exception during delete? It must be a missing UID
throw new IllegalArgumentException(midpointEx.getMessage(), midpointEx);
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
result.computeStatus();
return AsynchronousOperationResult.wrap(result);
}
use of org.identityconnectors.framework.common.objects.ObjectClass in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method getChangesFromSyncDeltas.
private List<Change> getChangesFromSyncDeltas(ObjectClass connIdObjClass, Collection<SyncDelta> connIdDeltas, PrismSchema schema, OperationResult parentResult) throws SchemaException, GenericFrameworkException {
List<Change> changeList = new ArrayList<Change>();
QName objectClass = connIdNameMapper.objectClassToQname(connIdObjClass, getSchemaNamespace(), legacySchema);
ObjectClassComplexTypeDefinition objClassDefinition = null;
if (objectClass != null) {
objClassDefinition = (ObjectClassComplexTypeDefinition) schema.findComplexTypeDefinition(objectClass);
}
Validate.notNull(connIdDeltas, "Sync result must not be null.");
for (SyncDelta icfDelta : connIdDeltas) {
ObjectClass deltaIcfObjClass = connIdObjClass;
QName deltaObjectClass = objectClass;
ObjectClassComplexTypeDefinition deltaObjClassDefinition = objClassDefinition;
if (objectClass == null) {
deltaIcfObjClass = icfDelta.getObjectClass();
deltaObjectClass = connIdNameMapper.objectClassToQname(deltaIcfObjClass, getSchemaNamespace(), legacySchema);
if (deltaIcfObjClass != null) {
deltaObjClassDefinition = (ObjectClassComplexTypeDefinition) schema.findComplexTypeDefinition(deltaObjectClass);
}
}
if (deltaObjClassDefinition == null) {
if (icfDelta.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 " + deltaObjectClass + " (" + deltaIcfObjClass + ") that has no definition in resource schema");
}
}
SyncDeltaType icfDeltaType = icfDelta.getDeltaType();
if (SyncDeltaType.DELETE.equals(icfDeltaType)) {
LOGGER.trace("START creating delta of type DELETE");
ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.DELETE, prismContext);
Collection<ResourceAttribute<?>> identifiers = ConnIdUtil.convertToIdentifiers(icfDelta.getUid(), deltaObjClassDefinition, resourceSchema);
Change change = new Change(identifiers, objectDelta, getToken(icfDelta.getToken()));
change.setObjectClassDefinition(deltaObjClassDefinition);
changeList.add(change);
LOGGER.trace("END creating delta of type DELETE");
} else if (SyncDeltaType.CREATE.equals(icfDeltaType)) {
PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(deltaObjClassDefinition);
LOGGER.trace("Object definition: {}", objectDefinition);
LOGGER.trace("START creating delta of type CREATE");
PrismObject<ShadowType> currentShadow = connIdConvertor.convertToResourceObject(icfDelta.getObject(), objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got current shadow: {}", currentShadow.debugDump());
}
Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getAllIdentifiers(currentShadow);
ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.ADD, prismContext);
objectDelta.setObjectToAdd(currentShadow);
Change change = new Change(identifiers, objectDelta, getToken(icfDelta.getToken()));
change.setObjectClassDefinition(deltaObjClassDefinition);
changeList.add(change);
LOGGER.trace("END creating delta of type CREATE");
} else if (SyncDeltaType.CREATE_OR_UPDATE.equals(icfDeltaType) || SyncDeltaType.UPDATE.equals(icfDeltaType)) {
PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(deltaObjClassDefinition);
LOGGER.trace("Object definition: {}", objectDefinition);
LOGGER.trace("START creating delta of type {}", icfDeltaType);
PrismObject<ShadowType> currentShadow = connIdConvertor.convertToResourceObject(icfDelta.getObject(), objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got current shadow: {}", currentShadow.debugDump());
}
Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getAllIdentifiers(currentShadow);
Change change = new Change(identifiers, currentShadow, getToken(icfDelta.getToken()));
change.setObjectClassDefinition(deltaObjClassDefinition);
changeList.add(change);
LOGGER.trace("END creating delta of type {}:\n{}", icfDeltaType, change.debugDump());
} else {
throw new GenericFrameworkException("Unexpected sync delta type " + icfDeltaType);
}
}
return changeList;
}
Aggregations