Search in sources :

Example 56 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class RunReportPopupPanel method createLookupTableRows.

private <O extends ObjectType> List<LookupTableRowType> createLookupTableRows(JasperReportParameterDto param, String input) {
    ItemPath label = null;
    ItemPath key = null;
    List<LookupTableRowType> rows = new ArrayList<>();
    JasperReportParameterPropertiesDto properties = param.getProperties();
    if (properties == null) {
        return null;
    }
    String pLabel = properties.getLabel();
    if (pLabel != null) {
        label = new ItemPath(pLabel);
    }
    String pKey = properties.getKey();
    if (pKey != null) {
        key = new ItemPath(pKey);
    }
    String pTargetType = properties.getTargetType();
    Class<O> targetType = null;
    if (pTargetType != null) {
        try {
            targetType = (Class<O>) Class.forName(pTargetType);
        } catch (ClassNotFoundException e) {
            error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
        //e.printStackTrace();
        }
    }
    if (label != null && targetType != null && input != null) {
        OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
        Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
        Collection<PrismObject<O>> objects;
        ObjectQuery query = QueryBuilder.queryFor(targetType, getPrismContext()).item(new QName(SchemaConstants.NS_C, pLabel)).startsWith(input).matching(new QName(SchemaConstants.NS_MATCHING_RULE, "origIgnoreCase")).maxSize(AUTO_COMPLETE_BOX_SIZE).build();
        try {
            objects = getPageBase().getModelService().searchObjects(targetType, query, SelectorOptions.createCollection(GetOperationOptions.createNoFetch()), task, result);
            for (PrismObject<O> o : objects) {
                Object realKeyValue = null;
                PrismProperty labelItem = o.findProperty(label);
                //TODO: e.g. support not only for property, but also ref, container..
                if (labelItem == null || labelItem.isEmpty()) {
                    continue;
                }
                PrismProperty keyItem = o.findProperty(key);
                if ("oid".equals(pKey)) {
                    realKeyValue = o.getOid();
                }
                if (realKeyValue == null && (keyItem == null || keyItem.isEmpty())) {
                    continue;
                }
                //TODO: support for single/multivalue value 
                if (!labelItem.isSingleValue()) {
                    continue;
                }
                Object realLabelValue = labelItem.getRealValue();
                realKeyValue = (realKeyValue == null) ? keyItem.getRealValue() : realKeyValue;
                // TODO: take definition into account
                QName typeName = labelItem.getDefinition().getTypeName();
                LookupTableRowType row = new LookupTableRowType();
                if (realKeyValue != null) {
                    row.setKey(convertObjectToPolyStringType(realKeyValue).getOrig());
                } else {
                    throw new SchemaException("Cannot create lookup table with null key for label: " + realLabelValue);
                }
                row.setLabel(convertObjectToPolyStringType(realLabelValue));
                rows.add(row);
            }
            return rows;
        } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
            error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
        //e.printStackTrace();
        }
    }
    return rows;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) JasperReportParameterPropertiesDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterPropertiesDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 57 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class AbstractManualConnectorInstance method addObject.

// TODO: operations to check ticket state
@Override
public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObject(PrismObject<? extends ShadowType> object, Collection<Operation> additionalOperations, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(OPERATION_ADD);
    String ticketIdentifier = null;
    try {
        ticketIdentifier = createTicketAdd(object, additionalOperations, result);
    } catch (CommunicationException | GenericFrameworkException | SchemaException | ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    result.recordInProgress();
    result.setAsynchronousOperationReference(ticketIdentifier);
    AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> ret = new AsynchronousOperationReturnValue<>();
    ret.setOperationResult(result);
    return ret;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 58 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class AbstractManualConnectorInstance method modifyObject.

@Override
public AsynchronousOperationReturnValue<Collection<PropertyModificationOperation>> modifyObject(ObjectClassComplexTypeDefinition objectClass, Collection<? extends ResourceAttribute<?>> identifiers, Collection<Operation> changes, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, SecurityViolationException, ObjectAlreadyExistsException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(OPERATION_MODIFY);
    String ticketIdentifier = null;
    try {
        ticketIdentifier = createTicketModify(objectClass, identifiers, changes, result);
    } catch (ObjectNotFoundException | CommunicationException | GenericFrameworkException | SchemaException | ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    result.recordInProgress();
    result.setAsynchronousOperationReference(ticketIdentifier);
    AsynchronousOperationReturnValue<Collection<PropertyModificationOperation>> ret = new AsynchronousOperationReturnValue<>();
    ret.setOperationResult(result);
    return ret;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 59 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class TestOpenDjNegative method test520ListResourceObjects.

/**
	 * This is using the shadow to go to the resource. But it cannot as OpenDJ is down. 
	 * Therefore the expected result is CommunicationException. It must not be ObjectNotFound as 
	 * we do NOT know that the shadow does not exist. 
	 */
@Test
public void test520ListResourceObjects() throws Exception {
    final String TEST_NAME = "test520ListResourceObjects";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestOpenDjNegative.class.getName() + "." + TEST_NAME);
    try {
        // WHEN
        List<PrismObject<? extends ShadowType>> objectList = provisioningService.listResourceObjects(RESOURCE_OPENDJ_OID, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS, null, null, result);
        AssertJUnit.fail("listResourceObjects succeeded unexpectedly");
    } catch (CommunicationException e) {
        // This is expected
        display("Expected exception", e);
    }
    result.computeStatus();
    TestUtil.assertFailure(result);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 60 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class TestOpenDjNegative method test590Synchronize.

@Test
public void test590Synchronize() throws Exception {
    final String TEST_NAME = "test590Synhronize";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestOpenDjNegative.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_OPENDJ_OID, new QName(RESOURCE_NS, SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME));
    try {
        provisioningService.synchronize(coords, task, result);
        AssertJUnit.fail("addObject succeeded unexpectedly");
    } catch (CommunicationException e) {
        // This is expected
        display("Expected exception", e);
    }
    result.computeStatus();
    TestUtil.assertFailure(result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) Test(org.testng.annotations.Test)

Aggregations

CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)108 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)87 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)87 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)86 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)82 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)69 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)67 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)39 SystemException (com.evolveum.midpoint.util.exception.SystemException)38 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)36 Task (com.evolveum.midpoint.task.api.Task)30 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)24 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 QName (javax.xml.namespace.QName)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)14 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)13