use of com.evolveum.icf.dummy.resource.ObjectDoesNotExistException in project midpoint by Evolveum.
the class DummyConnector method delete.
/**
* {@inheritDoc}
*/
public void delete(final ObjectClass objectClass, final Uid uid, final OperationOptions options) {
log.info("delete::begin");
validate(objectClass);
validate(uid);
String id = uid.getUidValue();
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
resource.deleteAccountByName(id);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
resource.deleteAccountById(id);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
resource.deleteGroupByName(id);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
resource.deleteGroupById(id);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
resource.deletePrivilegeByName(id);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
resource.deletePrivilegeById(id);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
resource.deleteOrgByName(id);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
resource.deleteOrgById(id);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ObjectDoesNotExistException e) {
// The framework should deal with it ... somehow
throw new UnknownUidException(e.getMessage(), e);
} catch (ConnectException e) {
log.info("delete::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("delete::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("delete::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("delete::exception " + e);
throw new AlreadyExistsException(e);
}
log.info("delete::end");
}
use of com.evolveum.icf.dummy.resource.ObjectDoesNotExistException in project midpoint by Evolveum.
the class DummyConnector method update.
/**
* {@inheritDoc}
*/
public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> replaceAttributes, OperationOptions options) {
log.info("update::begin");
validate(objectClass);
validate(uid);
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
final DummyAccount account;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
account = resource.getAccountByUsername(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
account = resource.getAccountById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (account == null) {
throw new UnknownUidException("Account with UID " + uid + " does not exist on resource");
}
// we do this before setting attribute values, in case when description itself would be changed
resource.changeDescriptionIfNeeded(account);
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameAccount(account.getId(), account.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
} catch (SchemaViolationException e) {
throw new org.identityconnectors.framework.common.exceptions.ConnectorException("Schema exception: " + e.getMessage(), e);
}
// We need to change the returned uid here (only if the mode is not set to UUID)
if (!(configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID))) {
uid = new Uid(newName);
}
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
changePassword(account, attr);
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
account.setEnabled(getBoolean(attr));
} else if (attr.is(OperationalAttributes.ENABLE_DATE_NAME)) {
account.setValidFrom(getDate(attr));
} else if (attr.is(OperationalAttributes.DISABLE_DATE_NAME)) {
account.setValidTo(getDate(attr));
} else if (attr.is(OperationalAttributes.LOCK_OUT_NAME)) {
account.setLockout(getBooleanNotNull(attr));
} else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
account.replaceAuxiliaryObjectClassNames(attr.getValue());
} else {
String name = attr.getName();
try {
account.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
final DummyGroup group;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
group = resource.getGroupByName(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
group = resource.getGroupById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (group == null) {
throw new UnknownUidException("Group with UID " + uid + " does not exist on resource");
}
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameGroup(group.getId(), group.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here
uid = new Uid(newName);
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new IllegalArgumentException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
group.setEnabled(getBooleanNotNull(attr));
} else {
String name = attr.getName();
List<Object> values = attr.getValue();
if (attr.is(DummyGroup.ATTR_MEMBERS_NAME) && values != null && configuration.getUpCaseName()) {
List<Object> newValues = new ArrayList<Object>(values.size());
for (Object val : values) {
newValues.add(StringUtils.upperCase((String) val));
}
values = newValues;
}
try {
group.replaceAttributeValues(name, values);
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
final DummyPrivilege priv;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
priv = resource.getPrivilegeByName(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
priv = resource.getPrivilegeById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (priv == null) {
throw new UnknownUidException("Privilege with UID " + uid + " does not exist on resource");
}
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renamePrivilege(priv.getId(), priv.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here
uid = new Uid(newName);
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new IllegalArgumentException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to change enable on privilege");
} else {
String name = attr.getName();
try {
priv.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
final DummyOrg org;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
org = resource.getOrgByName(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
org = resource.getOrgById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (org == null) {
throw new UnknownUidException("Org with UID " + uid + " does not exist on resource");
}
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameOrg(org.getId(), org.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here
uid = new Uid(newName);
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new IllegalArgumentException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to change enable on org");
} else {
String name = attr.getName();
try {
org.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
log.info("update::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("update::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("update::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("update::exception " + e);
throw new AlreadyExistsException(e);
}
log.info("update::end");
return uid;
}
use of com.evolveum.icf.dummy.resource.ObjectDoesNotExistException in project midpoint by Evolveum.
the class DummyConnectorLegacyUpdate method update.
/**
* {@inheritDoc}
*/
@Override
public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> replaceAttributes, OperationOptions options) {
LOG.info("update::begin");
validate(objectClass);
validate(uid);
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
final DummyAccount account;
if (configuration.isUidBoundToName()) {
account = resource.getAccountByUsername(uid.getUidValue(), false);
} else if (configuration.isUidSeparateFromName()) {
account = resource.getAccountById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (account == null) {
throw new UnknownUidException("Account with UID " + uid + " does not exist on resource");
}
applyModifyMetadata(account, options);
// we do this before setting attribute values, in case when description itself would be changed
resource.changeDescriptionIfNeeded(account);
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameAccount(account.getId(), account.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
} catch (SchemaViolationException e) {
throw new org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException("Schema exception: " + e.getMessage(), e);
}
// We need to change the returned uid here (only if the mode is not set to NAME)
if (configuration.isUidBoundToName()) {
uid = new Uid(newName);
}
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
changePassword(account, attr);
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
account.setEnabled(getBoolean(attr));
} else if (attr.is(OperationalAttributes.ENABLE_DATE_NAME)) {
account.setValidFrom(getDate(attr));
} else if (attr.is(OperationalAttributes.DISABLE_DATE_NAME)) {
account.setValidTo(getDate(attr));
} else if (attr.is(OperationalAttributes.LOCK_OUT_NAME)) {
account.setLockout(getBooleanMandatory(attr));
} else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
account.replaceAuxiliaryObjectClassNames(attr.getValue());
} else {
String name = attr.getName();
try {
account.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
final DummyGroup group;
if (configuration.isUidBoundToName()) {
group = resource.getGroupByName(uid.getUidValue(), false);
} else if (configuration.isUidSeparateFromName()) {
group = resource.getGroupById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (group == null) {
throw new UnknownUidException("Group with UID " + uid + " does not exist on resource");
}
applyModifyMetadata(group, options);
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameGroup(group.getId(), group.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here (only if the mode is not set to NAME)
if (configuration.isUidBoundToName()) {
uid = new Uid(newName);
}
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new InvalidAttributeValueException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
group.setEnabled(getBooleanMandatory(attr));
} else {
String name = attr.getName();
List<Object> values = attr.getValue();
if (attr.is(DummyGroup.ATTR_MEMBERS_NAME) && values != null && configuration.getUpCaseName()) {
List<Object> newValues = new ArrayList<>(values.size());
for (Object val : values) {
newValues.add(StringUtils.upperCase((String) val));
}
values = newValues;
}
try {
group.replaceAttributeValues(name, values);
} catch (SchemaViolationException e) {
throw new InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
final DummyPrivilege priv;
if (configuration.isUidBoundToName()) {
priv = resource.getPrivilegeByName(uid.getUidValue(), false);
} else if (configuration.isUidSeparateFromName()) {
priv = resource.getPrivilegeById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (priv == null) {
throw new UnknownUidException("Privilege with UID " + uid + " does not exist on resource");
}
applyModifyMetadata(priv, options);
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renamePrivilege(priv.getId(), priv.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here (only if the mode is not set to NAME)
if (configuration.isUidBoundToName()) {
uid = new Uid(newName);
}
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new InvalidAttributeValueException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("Attempt to change enable on privilege");
} else {
String name = attr.getName();
try {
priv.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
final DummyOrg org;
if (configuration.isUidBoundToName()) {
org = resource.getOrgByName(uid.getUidValue(), false);
} else if (configuration.isUidSeparateFromName()) {
org = resource.getOrgById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (org == null) {
throw new UnknownUidException("Org with UID " + uid + " does not exist on resource");
}
applyModifyMetadata(org, options);
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameOrg(org.getId(), org.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here (only if the mode is not set to NAME)
if (configuration.isUidBoundToName()) {
uid = new Uid(newName);
}
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new InvalidAttributeValueException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("Attempt to change enable on org");
} else {
String name = attr.getName();
try {
org.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
LOG.info("update::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
LOG.info("update::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
LOG.info("update::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
LOG.info("update::exception " + e);
throw new AlreadyExistsException(e);
} catch (InterruptedException e) {
LOG.info("update::exception " + e);
throw new OperationTimeoutException(e);
}
LOG.info("update::end");
return uid;
}
Aggregations