use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.
the class TaskDetails method details.
public void details() {
if (input.parameterNumber() == 0) {
try {
final Map<String, String> details = new LinkedHashMap<>();
final List<TaskTO> notificationTaskTOs = taskSyncopeOperations.list(TaskType.NOTIFICATION.name());
final List<TaskTO> propagationTaskTOs = taskSyncopeOperations.list(TaskType.PROPAGATION.name());
final List<TaskTO> pushTaskTOs = taskSyncopeOperations.list(TaskType.PUSH.name());
final List<TaskTO> scheduledTaskTOs = taskSyncopeOperations.list(TaskType.SCHEDULED.name());
final List<TaskTO> pullTaskTOs = taskSyncopeOperations.list(TaskType.PULL.name());
final List<JobTO> jobTOs = taskSyncopeOperations.listJobs();
final int notificationTaskSize = notificationTaskTOs.size();
final int propagationTaskSize = propagationTaskTOs.size();
final int pushTaskSize = pushTaskTOs.size();
final int scheduledTaskSize = scheduledTaskTOs.size();
final int pullTaskSize = pullTaskTOs.size();
final int jobsSize = jobTOs.size();
long notificationNotExecuted = notificationTaskTOs.stream().filter(notificationTaskTO -> !((NotificationTaskTO) notificationTaskTO).isExecuted()).count();
long propagationNotExecuted = propagationTaskTOs.stream().filter(propagationTaskTO -> ((PropagationTaskTO) propagationTaskTO).getExecutions().isEmpty()).count();
long pushNotExecuted = pushTaskTOs.stream().filter(pushTaskTO -> ((PushTaskTO) pushTaskTO).getExecutions().isEmpty()).count();
long scheduledNotExecuted = scheduledTaskTOs.stream().filter(scheduledTaskTO -> ((SchedTaskTO) scheduledTaskTO).getExecutions().isEmpty()).count();
int pullNotExecuted = 0;
int pullFull = 0;
for (final TaskTO pullTaskTO : pullTaskTOs) {
if (((PullTaskTO) pullTaskTO).getExecutions().isEmpty()) {
pullNotExecuted++;
}
if (((PullTaskTO) pullTaskTO).getPullMode() == PullMode.FULL_RECONCILIATION) {
pullFull++;
}
}
details.put("total number", String.valueOf(notificationTaskSize + propagationTaskSize + pushTaskSize + scheduledTaskSize + pullTaskSize));
details.put("notification tasks", String.valueOf(notificationTaskSize));
details.put("notification tasks not executed", String.valueOf(notificationNotExecuted));
details.put("propagation tasks", String.valueOf(propagationTaskSize));
details.put("propagation tasks not executed", String.valueOf(propagationNotExecuted));
details.put("push tasks", String.valueOf(pushTaskSize));
details.put("push tasks not executed", String.valueOf(pushNotExecuted));
details.put("scheduled tasks", String.valueOf(scheduledTaskSize));
details.put("scheduled tasks not executed", String.valueOf(scheduledNotExecuted));
details.put("pull tasks", String.valueOf(pullTaskSize));
details.put("pull tasks not executed", String.valueOf(pullNotExecuted));
details.put("pull tasks with full reconciliation", String.valueOf(pullFull));
details.put("jobs", String.valueOf(jobsSize));
taskResultManager.printDetails(details);
} catch (final SyncopeClientException ex) {
LOG.error("Error reading details about task", ex);
taskResultManager.genericError(ex.getMessage());
} catch (final IllegalArgumentException ex) {
LOG.error("Error reading details about task", ex);
taskResultManager.typeNotValidError("task", input.firstParameter(), CommandUtils.fromEnumToArray(TaskType.class));
}
} else {
taskResultManager.commandOptionError(DETAILS_HELP_MESSAGE);
}
}
use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.
the class TaskDataBinderImpl method getTaskTO.
@Override
public <T extends TaskTO> T getTaskTO(final Task task, final TaskUtils taskUtils, final boolean details) {
T taskTO = taskUtils.newTaskTO();
BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES);
TaskExec latestExec = taskExecDAO.findLatestStarted(task);
if (latestExec == null) {
taskTO.setLatestExecStatus(StringUtils.EMPTY);
} else {
taskTO.setLatestExecStatus(latestExec.getStatus());
taskTO.setStart(latestExec.getStart());
taskTO.setEnd(latestExec.getEnd());
}
if (details) {
task.getExecs().stream().filter(execution -> execution != null).forEachOrdered(execution -> taskTO.getExecutions().add(getExecTO(execution)));
}
switch(taskUtils.getType()) {
case PROPAGATION:
PropagationTask propagationTask = (PropagationTask) task;
PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
propagationTaskTO.setAnyTypeKind(propagationTask.getAnyTypeKind());
propagationTaskTO.setEntityKey(propagationTask.getEntityKey());
propagationTaskTO.setResource(propagationTask.getResource().getKey());
propagationTaskTO.setAttributes(propagationTask.getSerializedAttributes());
break;
case SCHEDULED:
SchedTask schedTask = (SchedTask) task;
SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
setExecTime(schedTaskTO, task);
if (schedTask.getJobDelegate() != null) {
schedTaskTO.setJobDelegate(schedTask.getJobDelegate().getKey());
}
break;
case PULL:
PullTask pullTask = (PullTask) task;
PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
setExecTime(pullTaskTO, task);
pullTaskTO.setDestinationRealm(pullTask.getDestinatioRealm().getFullPath());
pullTaskTO.setResource(pullTask.getResource().getKey());
pullTaskTO.setMatchingRule(pullTask.getMatchingRule() == null ? MatchingRule.UPDATE : pullTask.getMatchingRule());
pullTaskTO.setUnmatchingRule(pullTask.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTask.getUnmatchingRule());
if (pullTask.getReconFilterBuilder() != null) {
pullTaskTO.setReconFilterBuilder(pullTask.getReconFilterBuilder().getKey());
}
pullTaskTO.getActions().addAll(pullTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
pullTask.getTemplates().forEach(template -> {
pullTaskTO.getTemplates().put(template.getAnyType().getKey(), template.get());
});
pullTaskTO.setRemediation(pullTask.isRemediation());
break;
case PUSH:
PushTask pushTask = (PushTask) task;
PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
setExecTime(pushTaskTO, task);
pushTaskTO.setSourceRealm(pushTask.getSourceRealm().getFullPath());
pushTaskTO.setResource(pushTask.getResource().getKey());
pushTaskTO.setMatchingRule(pushTask.getMatchingRule() == null ? MatchingRule.LINK : pushTask.getMatchingRule());
pushTaskTO.setUnmatchingRule(pushTask.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTask.getUnmatchingRule());
pushTaskTO.getActions().addAll(pushTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
pushTask.getFilters().forEach(filter -> {
pushTaskTO.getFilters().put(filter.getAnyType().getKey(), filter.getFIQLCond());
});
break;
case NOTIFICATION:
NotificationTask notificationTask = (NotificationTask) task;
NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
notificationTaskTO.setNotification(notificationTask.getNotification().getKey());
notificationTaskTO.setAnyTypeKind(notificationTask.getAnyTypeKind());
notificationTaskTO.setEntityKey(notificationTask.getEntityKey());
if (notificationTask.isExecuted() && StringUtils.isBlank(taskTO.getLatestExecStatus())) {
taskTO.setLatestExecStatus("[EXECUTED]");
}
break;
default:
}
return taskTO;
}
use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.
the class NotificationTaskDirectoryPanel method getActions.
@Override
public ActionsPanel<NotificationTaskTO> getActions(final IModel<NotificationTaskTO> model) {
final ActionsPanel<NotificationTaskTO> panel = super.getActions(model);
final NotificationTaskTO taskTO = model.getObject();
panel.add(new ActionLink<NotificationTaskTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
viewTask(taskTO, target);
}
}, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
panel.add(new ActionLink<NotificationTaskTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
viewMailBody(MailTemplateFormat.TEXT, taskTO.getTextBody(), target);
}
}, ActionLink.ActionType.TEXT, StandardEntitlement.TASK_READ);
panel.add(new ActionLink<NotificationTaskTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
viewMailBody(MailTemplateFormat.HTML, taskTO.getHtmlBody(), target);
}
}, ActionLink.ActionType.HTML, StandardEntitlement.TASK_READ);
panel.add(new ActionLink<NotificationTaskTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
try {
restClient.startExecution(taskTO.getKey(), null);
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
LOG.error("While running {}", taskTO.getKey(), e);
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
}, ActionLink.ActionType.EXECUTE, StandardEntitlement.TASK_EXECUTE);
panel.add(new ActionLink<NotificationTaskTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
try {
restClient.delete(TaskType.NOTIFICATION, taskTO.getKey());
updateResultTable(target);
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
LOG.error("While deleting {}", taskTO.getKey(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
}, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
return panel;
}
use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.
the class NotificationTaskITCase method notifyByMailWithRetry.
@Test
public void notifyByMailWithRetry() throws Exception {
// 1. Set higher number of retries
AttrTO origMaxRetries = configurationService.get("notification.maxRetries");
configurationService.set(attrTO(origMaxRetries.getSchema(), "10"));
// 2. Stop mail server to force errors while sending out e-mails
stopGreenMail();
try {
// 3. create notification and user
String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, subject);
NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
int preExecs = taskTO.getExecutions().size();
// 4. verify notification could not be delivered
execTask(taskService, TaskType.NOTIFICATION, taskTO.getKey(), NotificationJob.Status.NOT_SENT.name(), 5, false);
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
assertNotNull(taskTO);
assertFalse(taskTO.isExecuted());
assertTrue(preExecs <= taskTO.getExecutions().size());
for (ExecTO exec : taskTO.getExecutions()) {
assertEquals(NotificationJob.Status.NOT_SENT.name(), exec.getStatus());
}
} finally {
// start mail server again
startGreenMail();
// reset number of retries
configurationService.set(origMaxRetries);
}
}
use of org.apache.syncope.common.lib.to.NotificationTaskTO in project syncope by apache.
the class NotificationTaskITCase method issueSYNCOPE192.
@Test
public void issueSYNCOPE192() throws Exception {
String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, true, TraceLevel.NONE, sender, subject);
NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getExecutions().isEmpty());
taskService.execute(new ExecuteQuery.Builder().key(taskTO.getKey()).build());
try {
Thread.sleep(5);
} catch (InterruptedException e) {
}
assertTrue(verifyMail(sender, subject, created.getRight()));
// verify that last exec status was updated
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(), true);
assertNotNull(taskTO);
assertTrue(taskTO.isExecuted());
assertTrue(taskTO.getExecutions().isEmpty());
assertTrue(StringUtils.isNotBlank(taskTO.getLatestExecStatus()));
}
Aggregations