use of com.evolveum.icf.dummy.resource.DummyDelta in project midpoint by Evolveum.
the class DummyConnector method sync.
/**
* {@inheritDoc}
*/
public void sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, final OperationOptions options) {
log.info("sync::begin");
validate(objectClass);
Collection<String> attributesToGet = getAttrsToGet(options);
try {
int syncToken = (Integer) token.getValue();
List<DummyDelta> deltas = resource.getDeltasSince(syncToken);
for (DummyDelta delta : deltas) {
Class<? extends DummyObject> deltaObjectClass = delta.getObjectClass();
if (objectClass.is(ObjectClass.ALL_NAME)) {
// take all changes
} else if (objectClass.is(ObjectClass.ACCOUNT_NAME)) {
if (deltaObjectClass != DummyAccount.class) {
log.ok("Skipping delta {0} because of objectclass mismatch", delta);
continue;
}
} else if (objectClass.is(ObjectClass.GROUP_NAME)) {
if (deltaObjectClass != DummyGroup.class) {
log.ok("Skipping delta {0} because of objectclass mismatch", delta);
continue;
}
}
SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder();
if (deltaObjectClass == DummyAccount.class) {
deltaBuilder.setObjectClass(ObjectClass.ACCOUNT);
} else if (deltaObjectClass == DummyGroup.class) {
deltaBuilder.setObjectClass(ObjectClass.GROUP);
} else if (deltaObjectClass == DummyPrivilege.class) {
deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_PRIVILEGE_NAME));
} else if (deltaObjectClass == DummyOrg.class) {
deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_ORG_NAME));
} else {
throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
}
SyncDeltaType deltaType;
if (delta.getType() == DummyDeltaType.ADD || delta.getType() == DummyDeltaType.MODIFY) {
if (resource.getSyncStyle() == DummySyncStyle.DUMB) {
deltaType = SyncDeltaType.CREATE_OR_UPDATE;
} else {
if (delta.getType() == DummyDeltaType.ADD) {
deltaType = SyncDeltaType.CREATE;
} else {
deltaType = SyncDeltaType.UPDATE;
}
}
if (deltaObjectClass == DummyAccount.class) {
DummyAccount account = resource.getAccountById(delta.getObjectId());
if (account == null) {
throw new IllegalStateException("We have delta for account '" + delta.getObjectId() + "' but such account does not exist");
}
ConnectorObject cobject = convertToConnectorObject(account, attributesToGet);
deltaBuilder.setObject(cobject);
} else if (deltaObjectClass == DummyGroup.class) {
DummyGroup group = resource.getGroupById(delta.getObjectId());
if (group == null) {
throw new IllegalStateException("We have delta for group '" + delta.getObjectId() + "' but such group does not exist");
}
ConnectorObject cobject = convertToConnectorObject(group, attributesToGet);
deltaBuilder.setObject(cobject);
} else if (deltaObjectClass == DummyPrivilege.class) {
DummyPrivilege privilege = resource.getPrivilegeById(delta.getObjectId());
if (privilege == null) {
throw new IllegalStateException("We have privilege for group '" + delta.getObjectId() + "' but such privilege does not exist");
}
ConnectorObject cobject = convertToConnectorObject(privilege, attributesToGet);
deltaBuilder.setObject(cobject);
} else {
throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
}
} else if (delta.getType() == DummyDeltaType.DELETE) {
deltaType = SyncDeltaType.DELETE;
} else {
throw new IllegalStateException("Unknown delta type " + delta.getType());
}
deltaBuilder.setDeltaType(deltaType);
deltaBuilder.setToken(new SyncToken(delta.getSyncToken()));
Uid uid;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
uid = new Uid(delta.getObjectName());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
if (nameHintChecksEnabled()) {
uid = new Uid(delta.getObjectId(), new Name(delta.getObjectName()));
} else {
uid = new Uid(delta.getObjectId());
}
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
deltaBuilder.setUid(uid);
SyncDelta syncDelta = deltaBuilder.build();
log.info("sync::handle {0}", syncDelta);
handler.handle(syncDelta);
}
} catch (ConnectException e) {
log.info("sync::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("sync::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("sync::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("sync::exception " + e);
throw new AlreadyExistsException(e);
}
log.info("sync::end");
}
Aggregations