Search in sources :

Example 6 with NotificationTaskTO

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);
    }
}
Also used : NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) CommandUtils(org.apache.syncope.client.cli.util.CommandUtils) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Logger(org.slf4j.Logger) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) PullMode(org.apache.syncope.common.lib.types.PullMode) LoggerFactory(org.slf4j.LoggerFactory) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Input(org.apache.syncope.client.cli.Input) Map(java.util.Map) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JobTO(org.apache.syncope.common.lib.to.JobTO) TaskType(org.apache.syncope.common.lib.types.TaskType) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) TaskTO(org.apache.syncope.common.lib.to.TaskTO) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) JobTO(org.apache.syncope.common.lib.to.JobTO) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with NotificationTaskTO

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;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) Entity(org.apache.syncope.core.persistence.api.entity.Entity) StringUtils(org.apache.commons.lang3.StringUtils) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) Scheduler(org.quartz.Scheduler) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) ProvisioningTaskTO(org.apache.syncope.common.lib.to.ProvisioningTaskTO) TaskExecDAO(org.apache.syncope.core.persistence.api.dao.TaskExecDAO) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) ExecTO(org.apache.syncope.common.lib.to.ExecTO) Task(org.apache.syncope.core.persistence.api.entity.task.Task) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Collectors(java.util.stream.Collectors) UnmatchingRule(org.apache.syncope.common.lib.types.UnmatchingRule) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ImplementationEngine(org.apache.syncope.common.lib.types.ImplementationEngine) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) TaskUtilsFactory(org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory) ProvisioningTask(org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask) TriggerKey(org.quartz.TriggerKey) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskDataBinder(org.apache.syncope.core.provisioning.api.data.TaskDataBinder) BeanUtils(org.apache.syncope.core.spring.BeanUtils) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) TemplateUtils(org.apache.syncope.core.provisioning.java.utils.TemplateUtils) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Logger(org.slf4j.Logger) PushTaskAnyFilter(org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter) TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) Component(org.springframework.stereotype.Component) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JobType(org.apache.syncope.common.lib.types.JobType) MatchingRule(org.apache.syncope.common.lib.types.MatchingRule) TaskType(org.apache.syncope.common.lib.types.TaskType) Entity(org.apache.syncope.core.persistence.api.entity.Entity) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Example 8 with NotificationTaskTO

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;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Example 9 with NotificationTaskTO

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);
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 10 with NotificationTaskTO

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()));
}
Also used : ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Aggregations

NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)13 Test (org.junit.jupiter.api.Test)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 PushTaskTO (org.apache.syncope.common.lib.to.PushTaskTO)3 Response (javax.ws.rs.core.Response)2 ExecTO (org.apache.syncope.common.lib.to.ExecTO)2 NotificationTO (org.apache.syncope.common.lib.to.NotificationTO)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)2 SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)2 TaskTO (org.apache.syncope.common.lib.to.TaskTO)2 TaskType (org.apache.syncope.common.lib.types.TaskType)2 TaskQuery (org.apache.syncope.common.rest.api.beans.TaskQuery)2 NotificationService (org.apache.syncope.common.rest.api.service.NotificationService)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1