Search in sources :

Example 6 with PushTaskTO

use of org.apache.syncope.common.lib.to.PushTaskTO in project syncope by apache.

the class PushTaskITCase method issueSYNCOPE648.

@Test
public void issueSYNCOPE648() {
    // 1. Create Push Task
    PushTaskTO task = new PushTaskTO();
    task.setName("Test create Push");
    task.setActive(true);
    task.setResource(RESOURCE_NAME_LDAP);
    task.setSourceRealm(SyncopeConstants.ROOT_REALM);
    task.getFilters().put(AnyTypeKind.USER.name(), SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("_NO_ONE_").query());
    task.getFilters().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("citizen").query());
    task.setMatchingRule(MatchingRule.IGNORE);
    task.setUnmatchingRule(UnmatchingRule.IGNORE);
    Response response = taskService.create(TaskType.PUSH, task);
    PushTaskTO actual = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
    assertNotNull(actual);
    // 2. Create notification
    NotificationTO notification = new NotificationTO();
    notification.setTraceLevel(TraceLevel.FAILURES);
    notification.getEvents().add("[PushTask]:[group]:[resource-ldap]:[matchingrule_ignore]:[SUCCESS]");
    notification.getEvents().add("[PushTask]:[group]:[resource-ldap]:[unmatchingrule_ignore]:[SUCCESS]");
    notification.getStaticRecipients().add("issueyncope648@syncope.apache.org");
    notification.setSelfAsRecipient(false);
    notification.setRecipientAttrName("email");
    notification.setSender("syncope648@syncope.apache.org");
    String subject = "Test notification";
    notification.setSubject(subject);
    notification.setTemplate("optin");
    notification.setActive(true);
    Response responseNotification = notificationService.create(notification);
    notification = getObject(responseNotification.getLocation(), NotificationService.class, NotificationTO.class);
    assertNotNull(notification);
    execProvisioningTask(taskService, TaskType.PUSH, actual.getKey(), 50, false);
    NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
    assertNotNull(taskTO);
}
Also used : Response(javax.ws.rs.core.Response) NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) NotificationService(org.apache.syncope.common.rest.api.service.NotificationService) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 7 with PushTaskTO

use of org.apache.syncope.common.lib.to.PushTaskTO in project syncope by apache.

the class PushTaskITCase method read.

@Test
public void read() {
    PushTaskTO pushTaskTO = taskService.<PushTaskTO>read(TaskType.PUSH, "0bc11a19-6454-45c2-a4e3-ceef84e5d79b", true);
    assertEquals(UnmatchingRule.ASSIGN, pushTaskTO.getUnmatchingRule());
    assertEquals(MatchingRule.UPDATE, pushTaskTO.getMatchingRule());
}
Also used : PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Test(org.junit.jupiter.api.Test)

Example 8 with PushTaskTO

use of org.apache.syncope.common.lib.to.PushTaskTO in project syncope by apache.

the class TaskDataBinderImpl method fill.

private void fill(final ProvisioningTask task, final ProvisioningTaskTO taskTO) {
    if (task instanceof PushTask && taskTO instanceof PushTaskTO) {
        PushTask pushTask = (PushTask) task;
        PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
        Implementation jobDelegate = pushTaskTO.getJobDelegate() == null ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PushJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : implementationDAO.find(pushTaskTO.getJobDelegate());
        if (jobDelegate == null) {
            jobDelegate = entityFactory.newEntity(Implementation.class);
            jobDelegate.setKey(PushJobDelegate.class.getSimpleName());
            jobDelegate.setEngine(ImplementationEngine.JAVA);
            jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
            jobDelegate.setBody(PushJobDelegate.class.getName());
            jobDelegate = implementationDAO.save(jobDelegate);
        }
        pushTask.setJobDelegate(jobDelegate);
        pushTask.setSourceRealm(realmDAO.findByFullPath(pushTaskTO.getSourceRealm()));
        pushTask.setMatchingRule(pushTaskTO.getMatchingRule() == null ? MatchingRule.LINK : pushTaskTO.getMatchingRule());
        pushTask.setUnmatchingRule(pushTaskTO.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTaskTO.getUnmatchingRule());
        pushTaskTO.getFilters().forEach((type, fiql) -> {
            AnyType anyType = anyTypeDAO.find(type);
            if (anyType == null) {
                LOG.debug("Invalid AnyType {} specified, ignoring...", type);
            } else {
                PushTaskAnyFilter filter = pushTask.getFilter(anyType).orElse(null);
                if (filter == null) {
                    filter = entityFactory.newEntity(PushTaskAnyFilter.class);
                    filter.setAnyType(anyType);
                    filter.setPushTask(pushTask);
                    pushTask.add(filter);
                }
                filter.setFIQLCond(fiql);
            }
        });
        // remove all filters not contained in the TO
        pushTask.getFilters().removeIf(anyFilter -> !pushTaskTO.getFilters().containsKey(anyFilter.getAnyType().getKey()));
    } else if (task instanceof PullTask && taskTO instanceof PullTaskTO) {
        PullTask pullTask = (PullTask) task;
        PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
        Implementation jobDelegate = pullTaskTO.getJobDelegate() == null ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PullJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : implementationDAO.find(pullTaskTO.getJobDelegate());
        if (jobDelegate == null) {
            jobDelegate = entityFactory.newEntity(Implementation.class);
            jobDelegate.setKey(PullJobDelegate.class.getSimpleName());
            jobDelegate.setEngine(ImplementationEngine.JAVA);
            jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
            jobDelegate.setBody(PullJobDelegate.class.getName());
            jobDelegate = implementationDAO.save(jobDelegate);
        }
        pullTask.setJobDelegate(jobDelegate);
        pullTask.setPullMode(pullTaskTO.getPullMode());
        if (pullTaskTO.getReconFilterBuilder() == null) {
            pullTask.setReconFilterBuilder(null);
        } else {
            Implementation reconFilterBuilder = implementationDAO.find(pullTaskTO.getReconFilterBuilder());
            if (reconFilterBuilder == null) {
                LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", pullTaskTO.getReconFilterBuilder());
            } else {
                pullTask.setReconFilterBuilder(reconFilterBuilder);
            }
        }
        pullTask.setDestinationRealm(realmDAO.findByFullPath(pullTaskTO.getDestinationRealm()));
        pullTask.setMatchingRule(pullTaskTO.getMatchingRule() == null ? MatchingRule.UPDATE : pullTaskTO.getMatchingRule());
        pullTask.setUnmatchingRule(pullTaskTO.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTaskTO.getUnmatchingRule());
        // validate JEXL expressions from templates and proceed if fine
        templateUtils.check(pullTaskTO.getTemplates(), ClientExceptionType.InvalidPullTask);
        pullTaskTO.getTemplates().forEach((type, template) -> {
            AnyType anyType = anyTypeDAO.find(type);
            if (anyType == null) {
                LOG.debug("Invalid AnyType {} specified, ignoring...", type);
            } else {
                AnyTemplatePullTask anyTemplate = pullTask.getTemplate(anyType).orElse(null);
                if (anyTemplate == null) {
                    anyTemplate = entityFactory.newEntity(AnyTemplatePullTask.class);
                    anyTemplate.setAnyType(anyType);
                    anyTemplate.setPullTask(pullTask);
                    pullTask.add(anyTemplate);
                }
                anyTemplate.set(template);
            }
        });
        // remove all templates not contained in the TO
        pullTask.getTemplates().removeIf(anyTemplate -> !pullTaskTO.getTemplates().containsKey(anyTemplate.getAnyType().getKey()));
        pullTask.setRemediation(pullTaskTO.isRemediation());
    }
    // 3. fill the remaining fields
    task.setPerformCreate(taskTO.isPerformCreate());
    task.setPerformUpdate(taskTO.isPerformUpdate());
    task.setPerformDelete(taskTO.isPerformDelete());
    task.setSyncStatus(taskTO.isSyncStatus());
    taskTO.getActions().forEach(action -> {
        Implementation implementation = implementationDAO.find(action);
        if (implementation == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", action);
        } else {
            task.add(implementation);
        }
    });
    // remove all implementations not contained in the TO
    task.getActions().removeIf(implementation -> !taskTO.getActions().contains(implementation.getKey()));
}
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) PushTaskAnyFilter(org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Aggregations

PushTaskTO (org.apache.syncope.common.lib.to.PushTaskTO)8 Test (org.junit.jupiter.api.Test)5 Response (javax.ws.rs.core.Response)4 ExecTO (org.apache.syncope.common.lib.to.ExecTO)4 NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)3 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)3 SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)3 TaskTO (org.apache.syncope.common.lib.to.TaskTO)3 TaskType (org.apache.syncope.common.lib.types.TaskType)3 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 ProvisioningTaskTO (org.apache.syncope.common.lib.to.ProvisioningTaskTO)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2 ImplementationEngine (org.apache.syncope.common.lib.types.ImplementationEngine)2 ImplementationType (org.apache.syncope.common.lib.types.ImplementationType)2 JobType (org.apache.syncope.common.lib.types.JobType)2 MatchingRule (org.apache.syncope.common.lib.types.MatchingRule)2 UnmatchingRule (org.apache.syncope.common.lib.types.UnmatchingRule)2