protected void fill()

in core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/TaskDataBinderImpl.java [134:292]


    protected void fill(final ProvisioningTask<?> provisioningTask, final ProvisioningTaskTO provisioningTaskTO) {
        if (provisioningTask instanceof final PushTask pushTask
                && provisioningTaskTO instanceof final PushTaskTO pushTaskTO) {

            Implementation jobDelegate = pushTaskTO.getJobDelegate() == null
                    ? implementationDAO.findByType(IdRepoImplementationType.TASKJOB_DELEGATE).stream().
                            filter(impl -> PushJobDelegate.class.getSimpleName().equals(impl.getKey())).
                            findFirst().orElse(null)
                    : implementationDAO.findById(pushTaskTO.getJobDelegate()).orElse(null);
            if (jobDelegate == null) {
                jobDelegate = entityFactory.newEntity(Implementation.class);
                jobDelegate.setKey(PushJobDelegate.class.getSimpleName());
                jobDelegate.setEngine(ImplementationEngine.JAVA);
                jobDelegate.setType(IdRepoImplementationType.TASKJOB_DELEGATE);
                jobDelegate.setBody(PushJobDelegate.class.getName());
                jobDelegate = implementationDAO.save(jobDelegate);
            }
            pushTask.setJobDelegate(jobDelegate);

            pushTask.setSourceRealm(realmSearchDAO.findByFullPath(pushTaskTO.getSourceRealm()).
                    orElseThrow(() -> new NotFoundException("Realm " + 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) -> anyTypeDAO.findById(type).ifPresentOrElse(
                    anyType -> pushTask.getFilters().put(anyType.getKey(), fiql),
                    () -> LOG.debug("Invalid AnyType {} specified, ignoring...", type)));
            // remove all filters not contained in the TO
            pushTask.getFilters().entrySet().
                    removeIf(filter -> !pushTaskTO.getFilters().containsKey(filter.getKey()));
        } else if (provisioningTask instanceof final InboundTask<?> inboundTask
                && provisioningTaskTO instanceof final InboundTaskTO inboundTaskTO) {

            inboundTask.setDestinationRealm(realmSearchDAO.findByFullPath(inboundTaskTO.getDestinationRealm()).
                    orElseThrow(() -> new NotFoundException("Realm " + inboundTaskTO.getDestinationRealm())));

            inboundTask.setMatchingRule(inboundTaskTO.getMatchingRule() == null
                    ? MatchingRule.UPDATE : inboundTaskTO.getMatchingRule());
            inboundTask.setUnmatchingRule(inboundTaskTO.getUnmatchingRule() == null
                    ? UnmatchingRule.PROVISION : inboundTaskTO.getUnmatchingRule());

            inboundTask.setRemediation(inboundTaskTO.isRemediation());

            if (provisioningTask instanceof final LiveSyncTask liveSyncTask
                    && provisioningTaskTO instanceof final LiveSyncTaskTO liveSyncTaskTO) {

                Implementation jobDelegate = liveSyncTaskTO.getJobDelegate() == null
                        ? implementationDAO.findByType(IdRepoImplementationType.TASKJOB_DELEGATE).stream().
                                filter(impl -> LiveSyncJobDelegate.class.getSimpleName().equals(impl.getKey())).
                                findFirst().orElse(null)
                        : implementationDAO.findById(liveSyncTaskTO.getJobDelegate()).orElse(null);
                if (jobDelegate == null) {
                    jobDelegate = entityFactory.newEntity(Implementation.class);
                    jobDelegate.setKey(LiveSyncJobDelegate.class.getSimpleName());
                    jobDelegate.setEngine(ImplementationEngine.JAVA);
                    jobDelegate.setType(IdRepoImplementationType.TASKJOB_DELEGATE);
                    jobDelegate.setBody(LiveSyncJobDelegate.class.getName());
                    jobDelegate = implementationDAO.save(jobDelegate);
                }
                liveSyncTask.setJobDelegate(jobDelegate);

                liveSyncTask.setDelaySecondsAcrossInvocations(liveSyncTaskTO.getDelaySecondsAcrossInvocations());

                if (liveSyncTaskTO.getLiveSyncDeltaMapper() == null) {
                    liveSyncTask.setLiveSyncDeltaMapper(null);
                } else {
                    implementationDAO.findById(liveSyncTaskTO.getLiveSyncDeltaMapper()).ifPresentOrElse(
                            liveSyncTask::setLiveSyncDeltaMapper,
                            () -> LOG.debug("Invalid Implementation {}, ignoring...",
                                    liveSyncTaskTO.getLiveSyncDeltaMapper()));
                }

                // validate JEXL expressions from templates and proceed if fine
                TemplateUtils.check(liveSyncTaskTO.getTemplates(), ClientExceptionType.InvalidLiveSyncTask);
                liveSyncTaskTO.getTemplates().forEach((type, template) -> anyTypeDAO.findById(type).ifPresentOrElse(
                        anyType -> {
                            AnyTemplateLiveSyncTask anyTemplate = liveSyncTask.getTemplate(anyType.getKey()).
                                    orElse(null);
                            if (anyTemplate == null) {
                                anyTemplate = entityFactory.newEntity(AnyTemplateLiveSyncTask.class);
                                anyTemplate.setAnyType(anyType);
                                anyTemplate.setLiveSyncTask(liveSyncTask);

                                liveSyncTask.add(anyTemplate);
                            }
                            anyTemplate.set(template);
                        },
                        () -> LOG.debug("Invalid AnyType {} specified, ignoring...", type)));
                // remove all templates not contained in the TO
                liveSyncTask.getTemplates().removeIf(
                        anyTemplate -> !liveSyncTaskTO.getTemplates().containsKey(anyTemplate.getAnyType().getKey()));
            } else if (provisioningTask instanceof final PullTask pullTask
                    && provisioningTaskTO instanceof final PullTaskTO pullTaskTO) {

                Implementation jobDelegate = pullTaskTO.getJobDelegate() == null
                        ? implementationDAO.findByType(IdRepoImplementationType.TASKJOB_DELEGATE).stream().
                                filter(impl -> PullJobDelegate.class.getSimpleName().equals(impl.getKey())).
                                findFirst().orElse(null)
                        : implementationDAO.findById(pullTaskTO.getJobDelegate()).orElse(null);
                if (jobDelegate == null) {
                    jobDelegate = entityFactory.newEntity(Implementation.class);
                    jobDelegate.setKey(PullJobDelegate.class.getSimpleName());
                    jobDelegate.setEngine(ImplementationEngine.JAVA);
                    jobDelegate.setType(IdRepoImplementationType.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 {
                    implementationDAO.findById(pullTaskTO.getReconFilterBuilder()).ifPresentOrElse(
                            pullTask::setReconFilterBuilder,
                            () -> LOG.debug("Invalid Implementation {}, ignoring...",
                                    pullTaskTO.getReconFilterBuilder()));
                }

                // validate JEXL expressions from templates and proceed if fine
                TemplateUtils.check(pullTaskTO.getTemplates(), ClientExceptionType.InvalidPullTask);
                pullTaskTO.getTemplates().forEach((type, template) -> anyTypeDAO.findById(type).ifPresentOrElse(
                        anyType -> {
                            AnyTemplatePullTask anyTemplate = pullTask.getTemplate(anyType.getKey()).orElse(null);
                            if (anyTemplate == null) {
                                anyTemplate = entityFactory.newEntity(AnyTemplatePullTask.class);
                                anyTemplate.setAnyType(anyType);
                                anyTemplate.setPullTask(pullTask);

                                pullTask.add(anyTemplate);
                            }
                            anyTemplate.set(template);
                        },
                        () -> LOG.debug("Invalid AnyType {} specified, ignoring...", type)));
                // remove all templates not contained in the TO
                pullTask.getTemplates().
                        removeIf(anyTemplate -> !pullTaskTO.getTemplates().
                        containsKey(anyTemplate.getAnyType().getKey()));
            }
        }

        // 3. fill the remaining fields
        provisioningTask.setPerformCreate(provisioningTaskTO.isPerformCreate());
        provisioningTask.setPerformUpdate(provisioningTaskTO.isPerformUpdate());
        provisioningTask.setPerformDelete(provisioningTaskTO.isPerformDelete());
        provisioningTask.setSyncStatus(provisioningTaskTO.isSyncStatus());

        provisioningTaskTO.getActions().forEach(action -> implementationDAO.findById(action).ifPresentOrElse(
                provisioningTask::add,
                () -> LOG.debug("Invalid Implementation {}, ignoring...", action)));
        // remove all implementations not contained in the TO
        provisioningTask.getActions().removeIf(impl -> !provisioningTaskTO.getActions().contains(impl.getKey()));

        provisioningTask.setConcurrentSettings(provisioningTaskTO.getConcurrentSettings());
    }