Search in sources :

Example 1 with DummyObject

use of com.evolveum.icf.dummy.resource.DummyObject in project midpoint by Evolveum.

the class DummyConnector method createConnectorObjectBuilderCommon.

private ConnectorObjectBuilder createConnectorObjectBuilderCommon(DummyObject dummyObject, DummyObjectClass objectClass, Collection<String> attributesToGet, boolean supportActivation) {
    ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
    if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
        builder.setUid(dummyObject.getName());
    } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
        builder.setUid(dummyObject.getId());
    } else {
        throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
    }
    builder.addAttribute(Name.NAME, dummyObject.getName());
    for (String name : dummyObject.getAttributeNames()) {
        DummyAttributeDefinition attrDef = dummyObject.getAttributeDefinition(name);
        if (attrDef == null) {
            throw new IllegalArgumentException("Unknown account attribute '" + name + "'");
        }
        if (!attrDef.isReturnedByDefault()) {
            if (attributesToGet != null && !attributesToGet.contains(name)) {
                continue;
            }
        }
        // Return all attributes that are returned by default. We will filter them out later.
        Set<Object> values = dummyObject.getAttributeValues(name, Object.class);
        if (configuration.isVaryLetterCase()) {
            name = varyLetterCase(name);
        }
        if (values != null && !values.isEmpty()) {
            builder.addAttribute(name, values);
        }
    }
    if (supportActivation) {
        if (attributesToGet == null || attributesToGet.contains(OperationalAttributes.ENABLE_NAME)) {
            builder.addAttribute(OperationalAttributes.ENABLE_NAME, dummyObject.isEnabled());
        }
        if (dummyObject.getValidFrom() != null && (attributesToGet == null || attributesToGet.contains(OperationalAttributes.ENABLE_DATE_NAME))) {
            builder.addAttribute(OperationalAttributes.ENABLE_DATE_NAME, convertToLong(dummyObject.getValidFrom()));
        }
        if (dummyObject.getValidTo() != null && (attributesToGet == null || attributesToGet.contains(OperationalAttributes.DISABLE_DATE_NAME))) {
            builder.addAttribute(OperationalAttributes.DISABLE_DATE_NAME, convertToLong(dummyObject.getValidTo()));
        }
    }
    if (configuration.isAddConnectorStateAttributes()) {
        builder.addAttribute(DummyResource.ATTRIBUTE_CONNECTOR_TO_STRING, this.toString());
        builder.addAttribute(DummyResource.ATTRIBUTE_CONNECTOR_STATIC_VAL, staticVal);
        builder.addAttribute(DummyResource.ATTRIBUTE_CONNECTOR_CONFIGURATION_TO_STRING, configuration.toString());
    }
    if (!dummyObject.getAuxiliaryObjectClassNames().isEmpty()) {
        builder.addAttribute(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME, dummyObject.getAuxiliaryObjectClassNames());
    }
    return builder;
}
Also used : DummyObject(com.evolveum.icf.dummy.resource.DummyObject) GuardedString(org.identityconnectors.common.security.GuardedString) DummyAttributeDefinition(com.evolveum.icf.dummy.resource.DummyAttributeDefinition)

Example 2 with DummyObject

use of com.evolveum.icf.dummy.resource.DummyObject 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;
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) DummyObject(com.evolveum.icf.dummy.resource.DummyObject) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException)

Aggregations

DummyObject (com.evolveum.icf.dummy.resource.DummyObject)2 GuardedString (org.identityconnectors.common.security.GuardedString)2 ConflictException (com.evolveum.icf.dummy.resource.ConflictException)1 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1 DummyAttributeDefinition (com.evolveum.icf.dummy.resource.DummyAttributeDefinition)1 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)1 DummyOrg (com.evolveum.icf.dummy.resource.DummyOrg)1 DummyPrivilege (com.evolveum.icf.dummy.resource.DummyPrivilege)1 ObjectAlreadyExistsException (com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException)1 SchemaViolationException (com.evolveum.icf.dummy.resource.SchemaViolationException)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 AlreadyExistsException (org.identityconnectors.framework.common.exceptions.AlreadyExistsException)1 ConnectionFailedException (org.identityconnectors.framework.common.exceptions.ConnectionFailedException)1 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)1 ConnectorIOException (org.identityconnectors.framework.common.exceptions.ConnectorIOException)1 InvalidAttributeValueException (org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException)1