Search in sources :

Example 81 with SystemException

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

the class SimpleSmsTransport method send.

@Override
public void send(Message message, String transportName, Event event, Task task, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(DOT_CLASS + "send");
    result.addCollectionOfSerializablesAsParam("message recipient(s)", message.getTo());
    result.addParam("message subject", message.getSubject());
    SystemConfigurationType systemConfiguration = NotificationFunctionsImpl.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
    if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null) {
        String msg = "No notifications are configured. SMS notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    // after "sms:"
    String smsConfigName = transportName.length() > NAME.length() ? transportName.substring(NAME.length() + 1) : null;
    SmsConfigurationType found = null;
    for (SmsConfigurationType smsConfigurationType : systemConfiguration.getNotificationConfiguration().getSms()) {
        if ((smsConfigName == null && smsConfigurationType.getName() == null) || (smsConfigName != null && smsConfigName.equals(smsConfigurationType.getName()))) {
            found = smsConfigurationType;
            break;
        }
    }
    if (found == null) {
        String msg = "SMS configuration '" + smsConfigName + "' not found. SMS notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    SmsConfigurationType smsConfigurationType = found;
    String file = smsConfigurationType.getRedirectToFile();
    if (file != null) {
        writeToFile(message, file, null, result);
        return;
    }
    if (smsConfigurationType.getGateway().isEmpty()) {
        String msg = "SMS gateway(s) are not defined, notification to " + message.getTo() + " will not be sent.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    String from = smsConfigurationType.getDefaultFrom() != null ? smsConfigurationType.getDefaultFrom() : "";
    if (message.getTo().isEmpty()) {
        String msg = "There is no recipient to send the notification to.";
        LOGGER.warn(msg);
        result.recordWarning(msg);
        return;
    }
    String to = message.getTo().get(0);
    if (message.getTo().size() > 1) {
        String msg = "Currently it is possible to send the SMS to one recipient only. Among " + message.getTo() + " the chosen one is " + to + " (the first one).";
        LOGGER.warn(msg);
    }
    for (SmsGatewayConfigurationType smsGatewayConfigurationType : smsConfigurationType.getGateway()) {
        OperationResult resultForGateway = result.createSubresult(DOT_CLASS + "send.forGateway");
        resultForGateway.addContext("gateway name", smsGatewayConfigurationType.getName());
        try {
            String url = evaluateExpressionChecked(smsGatewayConfigurationType.getUrl(), getDefaultVariables(from, to, message), "sms gateway url", task, result);
            LOGGER.debug("Sending SMS to URL " + url);
            if (smsGatewayConfigurationType.getRedirectToFile() != null) {
                writeToFile(message, smsGatewayConfigurationType.getRedirectToFile(), url, resultForGateway);
                result.computeStatus();
                return;
            } else {
                SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
                ClientHttpRequest request = requestFactory.createRequest(new URI(url), HttpMethod.GET);
                ClientHttpResponse response = request.execute();
                LOGGER.debug("Result: " + response.getStatusCode() + "/" + response.getStatusText());
                if (response.getStatusCode().series() != HttpStatus.Series.SUCCESSFUL) {
                    throw new SystemException("SMS gateway communication failed: " + response.getStatusCode() + ": " + response.getStatusText());
                }
                LOGGER.info("Message sent successfully to " + message.getTo() + " via gateway " + smsGatewayConfigurationType.getName() + ".");
                resultForGateway.recordSuccess();
                result.recordSuccess();
                return;
            }
        } catch (Throwable t) {
            String msg = "Couldn't send SMS to " + message.getTo() + " via " + smsGatewayConfigurationType.getName() + ", trying another gateway, if there is any";
            LoggingUtils.logException(LOGGER, msg, t);
            resultForGateway.recordFatalError(msg, t);
        }
    }
    LOGGER.warn("No more SMS gateways to try, notification to " + message.getTo() + " will not be sent.");
    result.recordWarning("Notification to " + message.getTo() + " could not be sent.");
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Example 82 with SystemException

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

the class TestOpenDj method test702ConfiguredCapabilityNoCreate.

@Test
public void test702ConfiguredCapabilityNoCreate() throws Exception {
    final String TEST_NAME = "test702ConfiguredCapabilityNoCreate";
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    addResourceFromFile(new File(TEST_DIR, "/resource-opendj-no-create.xml"), IntegrationTestTools.CONNECTOR_LDAP_TYPE, true, result);
    try {
        PrismObject<ShadowType> shadow = parseObjectType(ACCOUNT_WILL_FILE, ShadowType.class).asPrismObject();
        provisioningService.addObject(shadow, null, null, task, result);
        AssertJUnit.fail("Expected unsupported operation exception, but haven't got one.");
    } catch (SystemException ex) {
        LOGGER.info("exception: {}", ex.getMessage(), ex);
    // this is expected..				
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 83 with SystemException

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

the class TestOpenDj method test704ConfiguredCapabilityNoUpdate.

@Test
public void test704ConfiguredCapabilityNoUpdate() throws Exception {
    final String TEST_NAME = "test704ConfiguredCapabilityNoUpdate";
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    addResourceFromFile(new File(TEST_DIR, "/resource-opendj-no-update.xml"), IntegrationTestTools.CONNECTOR_LDAP_TYPE, true, result);
    try {
        PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(new ItemPath(ShadowType.F_ATTRIBUTES, new QName(resourceType.getNamespace(), "sn")), prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class), "doesnotmatter");
        Collection modifications = MiscUtil.createCollection(delta);
        provisioningService.modifyObject(ShadowType.class, ACCOUNT_WILL_OID, modifications, null, null, task, result);
        AssertJUnit.fail("Expected unsupported operation exception, but haven't got one.");
    } catch (SystemException ex) {
    // this is expected..				
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 84 with SystemException

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

the class SequenceTest method test020_ReachingLimit.

@Test
public void test020_ReachingLimit() throws Exception {
    OperationResult result = new OperationResult("test020_ReachingLimit");
    final File file = new File(TEST_DIR + "sequence-bound.xml");
    PrismObject<SequenceType> sequence = prismContext.parseObject(file);
    String oid = repositoryService.addObject(sequence, null, result);
    assertEquals(0L, repositoryService.advanceSequence(oid, result));
    assertEquals(1L, repositoryService.advanceSequence(oid, result));
    assertEquals(2L, repositoryService.advanceSequence(oid, result));
    assertEquals(3L, repositoryService.advanceSequence(oid, result));
    assertEquals(4L, repositoryService.advanceSequence(oid, result));
    assertEquals(5L, repositoryService.advanceSequence(oid, result));
    assertEquals(6L, repositoryService.advanceSequence(oid, result));
    assertEquals(7L, repositoryService.advanceSequence(oid, result));
    assertEquals(8L, repositoryService.advanceSequence(oid, result));
    assertEquals(9L, repositoryService.advanceSequence(oid, result));
    try {
        long value = repositoryService.advanceSequence(oid, result);
        fail("Expected an exception, got value of " + value);
    } catch (SystemException e) {
    // ok
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType) File(java.io.File) Test(org.testng.annotations.Test)

Example 85 with SystemException

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

the class SearchIterativeTest method test110DeleteAll.

@Test
public void test110DeleteAll() throws Exception {
    OperationResult result = new OperationResult("test110DeleteAll");
    final List<PrismObject<UserType>> objects = new ArrayList<>();
    ResultHandler handler = new ResultHandler() {

        @Override
        public boolean handle(PrismObject object, OperationResult parentResult) {
            objects.add(object);
            try {
                repositoryService.deleteObject(UserType.class, object.getOid(), parentResult);
            } catch (ObjectNotFoundException e) {
                throw new SystemException(e);
            }
            return true;
        }
    };
    repositoryService.searchObjectsIterative(UserType.class, null, handler, null, true, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertObjects(objects, COUNT);
    int count = repositoryService.countObjects(UserType.class, null, result);
    assertEquals("Wrong # of objects after operation", 0, count);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) Test(org.testng.annotations.Test)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12