Search in sources :

Example 11 with OperationOptions

use of org.identityconnectors.framework.common.objects.OperationOptions in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method count.

@Override
public int count(ObjectClassComplexTypeDefinition objectClassDefinition, final ObjectQuery query, PagedSearchCapabilityType pagedSearchCapabilityType, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, UnsupportedOperationException {
    // Result type for this operation
    final OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".count");
    result.addParam("objectClass", objectClassDefinition);
    result.addContext("connector", connectorType);
    if (objectClassDefinition == null) {
        result.recordFatalError("Object class not defined");
        throw new IllegalArgumentException("objectClass not defined");
    }
    ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(objectClassDefinition, getSchemaNamespace(), connectorType, legacySchema);
    if (icfObjectClass == null) {
        IllegalArgumentException ex = new IllegalArgumentException("Unable to determine object class from QName " + objectClassDefinition + " while attempting to search objects by " + ObjectTypeUtil.toShortString(connectorType));
        result.recordFatalError("Unable to determine object class", ex);
        throw ex;
    }
    final boolean useConnectorPaging = pagedSearchCapabilityType != null;
    if (!useConnectorPaging) {
        throw new UnsupportedOperationException("ConnectorInstanceIcfImpl.count operation is supported only in combination with connector-implemented paging");
    }
    OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
    optionsBuilder.setAttributesToGet(Name.NAME);
    optionsBuilder.setPagedResultsOffset(1);
    optionsBuilder.setPageSize(1);
    if (pagedSearchCapabilityType.getDefaultSortField() != null) {
        String orderByIcfName = connIdNameMapper.convertAttributeNameToIcf(pagedSearchCapabilityType.getDefaultSortField(), objectClassDefinition, "(default sorting field)");
        boolean isAscending = pagedSearchCapabilityType.getDefaultSortDirection() != OrderDirectionType.DESCENDING;
        optionsBuilder.setSortKeys(new SortKey(orderByIcfName, isAscending));
    }
    OperationOptions options = optionsBuilder.build();
    // Connector operation cannot create result for itself, so we need to
    // create result for it
    OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".search");
    icfResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    int retval;
    try {
        Filter filter = convertFilterToIcf(query, objectClassDefinition);
        final Holder<Integer> fetched = new Holder<>(0);
        ResultsHandler icfHandler = new ResultsHandler() {

            @Override
            public boolean handle(ConnectorObject connectorObject) {
                // actually, this should execute at most once
                fetched.setValue(fetched.getValue() + 1);
                return false;
            }
        };
        InternalMonitor.recordConnectorOperation("search");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
        SearchResult searchResult = connIdConnectorFacade.search(icfObjectClass, filter, icfHandler, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
        if (searchResult == null || searchResult.getRemainingPagedResults() == -1) {
            throw new UnsupportedOperationException("Connector does not seem to support paged searches or does not provide object count information");
        } else {
            retval = fetched.getValue() + searchResult.getRemainingPagedResults();
        }
        icfResult.recordSuccess();
    } catch (IntermediateException inex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, inex);
        SchemaException ex = (SchemaException) inex.getCause();
        icfResult.recordFatalError(ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (UnsupportedOperationException uoe) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, uoe);
        icfResult.recordFatalError(uoe);
        result.recordFatalError(uoe);
        throw uoe;
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, ex);
        Throwable midpointEx = processIcfException(ex, this, icfResult);
        result.computeStatus();
        // exception
        if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            throw (SchemaException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    if (result.isUnknown()) {
        result.recordSuccess();
    }
    return retval;
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) SortKey(org.identityconnectors.framework.common.objects.SortKey) GuardedString(org.identityconnectors.common.security.GuardedString) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SystemException(com.evolveum.midpoint.util.exception.SystemException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) Holder(com.evolveum.midpoint.util.Holder) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) SearchResult(org.identityconnectors.framework.common.objects.SearchResult) SyncResultsHandler(org.identityconnectors.framework.common.objects.SyncResultsHandler) ResultsHandler(org.identityconnectors.framework.common.objects.ResultsHandler) Filter(org.identityconnectors.framework.common.objects.filter.Filter)

Example 12 with OperationOptions

use of org.identityconnectors.framework.common.objects.OperationOptions in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method fetchChanges.

@Override
public List<Change> fetchChanges(ObjectClassComplexTypeDefinition objectClass, PrismProperty<?> lastToken, AttributesToReturn attrsToReturn, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".fetchChanges");
    result.addContext("objectClass", objectClass);
    result.addParam("lastToken", lastToken);
    // create sync token from the property last token
    SyncToken syncToken = null;
    try {
        syncToken = getSyncToken(lastToken);
        LOGGER.trace("Sync token created from the property last token: {}", syncToken == null ? null : syncToken.getValue());
    } catch (SchemaException ex) {
        result.recordFatalError(ex.getMessage(), ex);
        throw new SchemaException(ex.getMessage(), ex);
    }
    final List<SyncDelta> syncDeltas = new ArrayList<SyncDelta>();
    // get icf object class
    ObjectClass icfObjectClass;
    if (objectClass == null) {
        icfObjectClass = ObjectClass.ALL;
    } else {
        icfObjectClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
    }
    OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
    if (objectClass != null) {
        convertToIcfAttrsToGet(objectClass, attrsToReturn, optionsBuilder);
    }
    OperationOptions options = optionsBuilder.build();
    SyncResultsHandler syncHandler = new SyncResultsHandler() {

        @Override
        public boolean handle(SyncDelta delta) {
            LOGGER.trace("Detected sync delta: {}", delta);
            return syncDeltas.add(delta);
        }
    };
    OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".sync");
    connIdResult.addContext("connector", connIdConnectorFacade.getClass());
    connIdResult.addArbitraryObjectAsParam("connIdObjectClass", icfObjectClass);
    connIdResult.addArbitraryObjectAsParam("syncToken", syncToken);
    connIdResult.addArbitraryObjectAsParam("syncHandler", syncHandler);
    SyncToken lastReceivedToken;
    try {
        InternalMonitor.recordConnectorOperation("sync");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
        lastReceivedToken = connIdConnectorFacade.sync(icfObjectClass, syncToken, syncHandler, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
        connIdResult.recordSuccess();
        connIdResult.addReturn(OperationResult.RETURN_COUNT, syncDeltas.size());
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass, ex);
        Throwable midpointEx = processIcfException(ex, this, connIdResult);
        result.computeStatus();
        // exception
        if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            throw (SchemaException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    // convert changes from icf to midpoint Change
    List<Change> changeList;
    try {
        changeList = getChangesFromSyncDeltas(icfObjectClass, syncDeltas, resourceSchema, result);
    } catch (SchemaException ex) {
        result.recordFatalError(ex.getMessage(), ex);
        throw new SchemaException(ex.getMessage(), ex);
    }
    if (lastReceivedToken != null) {
        Change lastChange = new Change((ObjectDelta) null, getToken(lastReceivedToken));
        LOGGER.trace("Adding last change: {}", lastChange);
        changeList.add(lastChange);
    }
    result.recordSuccess();
    result.addReturn(OperationResult.RETURN_COUNT, changeList == null ? 0 : changeList.size());
    return changeList;
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) Change(com.evolveum.midpoint.provisioning.ucf.api.Change) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) SystemException(com.evolveum.midpoint.util.exception.SystemException) SyncResultsHandler(org.identityconnectors.framework.common.objects.SyncResultsHandler)

Example 13 with OperationOptions

use of org.identityconnectors.framework.common.objects.OperationOptions in project syncope by apache.

the class ConnectorFacadeProxy method filteredReconciliation.

@Transactional
@Override
public void filteredReconciliation(final ObjectClass objectClass, final ReconFilterBuilder filterBuilder, final SyncResultsHandler handler, final OperationOptions options) {
    Filter filter = null;
    OperationOptions actualOptions = options;
    if (filterBuilder != null) {
        filter = filterBuilder.build();
        actualOptions = filterBuilder.build(actualOptions);
    }
    search(objectClass, filter, object -> handler.handle(new SyncDeltaBuilder().setObject(object).setUid(object.getUid()).setDeltaType(SyncDeltaType.CREATE_OR_UPDATE).setToken(new SyncToken("")).build()), actualOptions);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) SyncDeltaBuilder(org.identityconnectors.framework.common.objects.SyncDeltaBuilder) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) Filter(org.identityconnectors.framework.common.objects.filter.Filter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with OperationOptions

use of org.identityconnectors.framework.common.objects.OperationOptions in project CzechIdMng by bcvsolutions.

the class ConnIdIcConnectorService method updateObject.

@Override
public IcUidAttribute updateObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, IcUidAttribute uid, List<IcAttribute> replaceAttributes) {
    Assert.notNull(connectorInstance, "Connector instance is required.");
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    Assert.notNull(replaceAttributes, "Replace attributes are required.");
    Assert.notNull(uid, "Uid is required.");
    LOG.debug("Update object - ConnId (Uid= {} {} {})", uid, connectorInstance.getConnectorKey().toString(), replaceAttributes.toString());
    ConnectorFacade conn = facadeFactory.getConnectorFacade(connectorInstance, connectorConfiguration);
    Set<Attribute> connIdAttributes = new HashSet<>(replaceAttributes.size());
    for (IcAttribute icAttribute : replaceAttributes) {
        connIdAttributes.add(ConnIdIcConvertUtil.convertIcAttribute(icAttribute));
    }
    ObjectClass objectClassConnId = ConnIdIcConvertUtil.convertIcObjectClass(objectClass);
    if (objectClassConnId == null) {
        objectClassConnId = ObjectClass.ACCOUNT;
    }
    Uid updatedUid = conn.update(objectClassConnId, ConnIdIcConvertUtil.convertIcUid(uid), connIdAttributes, new OperationOptions(connectorConfiguration.getSystemOperationOptions()));
    LOG.debug("Updated object - ConnId ({} {}) Uid= {})", connectorInstance.getConnectorKey().toString(), replaceAttributes.toString(), updatedUid);
    return ConnIdIcConvertUtil.convertConnIdUid(updatedUid);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Uid(org.identityconnectors.framework.common.objects.Uid) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) Attribute(org.identityconnectors.framework.common.objects.Attribute) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) HashSet(java.util.HashSet)

Example 15 with OperationOptions

use of org.identityconnectors.framework.common.objects.OperationOptions in project CzechIdMng by bcvsolutions.

the class ConnIdIcConnectorService method deleteObject.

@Override
public void deleteObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, IcUidAttribute uid) {
    Assert.notNull(connectorInstance, "Connector instance is required.");
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    Assert.notNull(uid, "Uid is required.");
    LOG.debug("Delete object - ConnId (Uid= {} {})", uid, connectorInstance.getConnectorKey().toString());
    ConnectorFacade conn = facadeFactory.getConnectorFacade(connectorInstance, connectorConfiguration);
    ObjectClass objectClassConnId = ConnIdIcConvertUtil.convertIcObjectClass(objectClass);
    if (objectClassConnId == null) {
        objectClassConnId = ObjectClass.ACCOUNT;
    }
    conn.delete(objectClassConnId, ConnIdIcConvertUtil.convertIcUid(uid), new OperationOptions(connectorConfiguration.getSystemOperationOptions()));
    LOG.debug("Deleted object - ConnId ({}) Uid= {}", connectorInstance.getConnectorKey().toString(), uid);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade)

Aggregations

OperationOptions (org.identityconnectors.framework.common.objects.OperationOptions)17 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)15 ConnectorFacade (org.identityconnectors.framework.api.ConnectorFacade)9 IcConnectorFacade (eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade)8 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)7 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)7 Uid (org.identityconnectors.framework.common.objects.Uid)7 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)6 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 OperationOptionsBuilder (org.identityconnectors.framework.common.objects.OperationOptionsBuilder)6 SystemException (com.evolveum.midpoint.util.exception.SystemException)5 Attribute (org.identityconnectors.framework.common.objects.Attribute)5 GuardedString (org.identityconnectors.common.security.GuardedString)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 QualifiedUid (org.identityconnectors.framework.common.objects.QualifiedUid)3 Filter (org.identityconnectors.framework.common.objects.filter.Filter)3