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.");
}
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..
}
}
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..
}
}
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
}
}
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);
}
Aggregations