use of org.identityconnectors.framework.common.exceptions.ConnectionFailedException in project midpoint by Evolveum.
the class DummyConnector method create.
/******************
* SPI Operations
*
* Implement the following operations using the contract and
* description found in the Javadoc for these methods.
******************/
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/
public Uid create(final ObjectClass objectClass, final Set<Attribute> createAttributes, final OperationOptions options) {
log.info("create::begin attributes {0}", createAttributes);
validate(objectClass);
DummyObject newObject;
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
// Convert attributes to account
DummyAccount newAccount = convertToAccount(createAttributes);
log.ok("Adding dummy account:\n{0}", newAccount.debugDump());
resource.addAccount(newAccount);
newObject = newAccount;
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
DummyGroup newGroup = convertToGroup(createAttributes);
log.ok("Adding dummy group:\n{0}", newGroup.debugDump());
resource.addGroup(newGroup);
newObject = newGroup;
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
DummyPrivilege newPriv = convertToPriv(createAttributes);
log.ok("Adding dummy privilege:\n{0}", newPriv.debugDump());
resource.addPrivilege(newPriv);
newObject = newPriv;
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
DummyOrg newOrg = convertToOrg(createAttributes);
log.ok("Adding dummy org:\n{0}", newOrg.debugDump());
resource.addOrg(newOrg);
newObject = newOrg;
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ObjectAlreadyExistsException e) {
// The framework should deal with it ... somehow
throw new AlreadyExistsException(e.getMessage(), e);
} catch (ConnectException e) {
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
throw new InvalidAttributeValueException(e);
} catch (ConflictException e) {
throw new AlreadyExistsException(e);
}
String id;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
id = newObject.getName();
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
id = newObject.getId();
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
Uid uid = new Uid(id);
log.info("create::end");
return uid;
}
Aggregations