Search in sources :

Example 6 with DummyOrg

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

the class DummyConnector method executeQuery.

/**
     * {@inheritDoc}
     */
public void executeQuery(ObjectClass objectClass, Filter query, ResultsHandler handler, OperationOptions options) {
    log.info("executeQuery({0},{1},{2},{3})", objectClass, query, handler, options);
    validate(objectClass);
    validate(query);
    notNull(handler, "Results handled object can't be null.");
    Collection<String> attributesToGet = getAttrsToGet(options);
    log.ok("attributesToGet={0}", attributesToGet);
    if (configuration.getRequiredBaseContextOrgName() != null && shouldRequireBaseContext(objectClass, query, options)) {
        if (options == null || options.getContainer() == null) {
            throw new ConnectorException("No container option while base context is required");
        }
        QualifiedUid container = options.getContainer();
        if (!configuration.getRequiredBaseContextOrgName().equals(container.getUid().getUidValue())) {
            throw new ConnectorException("Base context of '" + configuration.getRequiredBaseContextOrgName() + "' is required, but got '" + container.getUid().getUidValue() + "'");
        }
    }
    try {
        if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
            Collection<DummyAccount> accounts = resource.listAccounts();
            for (DummyAccount account : accounts) {
                ConnectorObject co = convertToConnectorObject(account, attributesToGet);
                if (matches(query, co)) {
                    co = filterOutAttributesToGet(co, account, attributesToGet, options.getReturnDefaultAttributes());
                    handler.handle(co);
                }
            }
        } else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
            Collection<DummyGroup> groups = resource.listGroups();
            for (DummyGroup group : groups) {
                ConnectorObject co = convertToConnectorObject(group, attributesToGet);
                if (matches(query, co)) {
                    if (attributesToGetHasAttribute(attributesToGet, DummyGroup.ATTR_MEMBERS_NAME)) {
                        resource.recordGroupMembersReadCount();
                    }
                    co = filterOutAttributesToGet(co, group, attributesToGet, options.getReturnDefaultAttributes());
                    handler.handle(co);
                }
            }
        } else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
            Collection<DummyPrivilege> privs = resource.listPrivileges();
            for (DummyPrivilege priv : privs) {
                ConnectorObject co = convertToConnectorObject(priv, attributesToGet);
                if (matches(query, co)) {
                    co = filterOutAttributesToGet(co, priv, attributesToGet, options.getReturnDefaultAttributes());
                    handler.handle(co);
                }
            }
        } else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
            Collection<DummyOrg> orgs = resource.listOrgs();
            for (DummyOrg org : orgs) {
                ConnectorObject co = convertToConnectorObject(org, attributesToGet);
                if (matches(query, co)) {
                    co = filterOutAttributesToGet(co, org, attributesToGet, options.getReturnDefaultAttributes());
                    handler.handle(co);
                }
            }
        } else {
            throw new ConnectorException("Unknown object class " + objectClass);
        }
    } catch (ConnectException e) {
        log.info("executeQuery::exception " + e);
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.info("executeQuery::exception " + e);
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (SchemaViolationException e) {
        log.info("executeQuery::exception " + e);
        throw new InvalidAttributeValueException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.info("executeQuery::exception " + e);
        throw new AlreadyExistsException(e);
    }
    log.info("executeQuery::end");
}
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) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) Collection(java.util.Collection) 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) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException)

Example 7 with DummyOrg

use of com.evolveum.icf.dummy.resource.DummyOrg 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

DummyOrg (com.evolveum.icf.dummy.resource.DummyOrg)7 SchemaViolationException (com.evolveum.icf.dummy.resource.SchemaViolationException)6 GuardedString (org.identityconnectors.common.security.GuardedString)6 ConflictException (com.evolveum.icf.dummy.resource.ConflictException)5 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)5 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)5 DummyPrivilege (com.evolveum.icf.dummy.resource.DummyPrivilege)5 ObjectAlreadyExistsException (com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException)5 FileNotFoundException (java.io.FileNotFoundException)5 ConnectException (java.net.ConnectException)5 AlreadyExistsException (org.identityconnectors.framework.common.exceptions.AlreadyExistsException)5 ConnectionFailedException (org.identityconnectors.framework.common.exceptions.ConnectionFailedException)5 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)5 ConnectorIOException (org.identityconnectors.framework.common.exceptions.ConnectorIOException)5 InvalidAttributeValueException (org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException)5 DummyObject (com.evolveum.icf.dummy.resource.DummyObject)4 ArrayList (java.util.ArrayList)3 UnknownUidException (org.identityconnectors.framework.common.exceptions.UnknownUidException)3 ObjectDoesNotExistException (com.evolveum.icf.dummy.resource.ObjectDoesNotExistException)1 Collection (java.util.Collection)1