use of org.apache.syncope.core.persistence.api.entity.task.PushTask 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.core.persistence.api.entity.task.PushTask in project syncope by apache.
the class JobManagerImpl method register.
@Override
public Map<String, Object> register(final SchedTask task, final Date startAt, final long interruptMaxRetries) throws SchedulerException {
TaskJob job = createSpringBean(TaskJob.class);
job.setTaskKey(task.getKey());
Implementation jobDelegate = task.getJobDelegate() == null ? task instanceof PullTask ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PullJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : task instanceof PushTask ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PushJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : null : task.getJobDelegate();
if (jobDelegate == null) {
throw new IllegalArgumentException("Task " + task + " does not provide any " + SchedTaskJobDelegate.class.getSimpleName());
}
Map<String, Object> jobMap = new HashMap<>();
jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
jobMap.put(TaskJob.DELEGATE_IMPLEMENTATION, jobDelegate.getKey());
registerJob(JobNamer.getJobKey(task).getName(), job, task.getCronExpression(), startAt, jobMap);
return jobMap;
}
use of org.apache.syncope.core.persistence.api.entity.task.PushTask 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()));
}
use of org.apache.syncope.core.persistence.api.entity.task.PushTask in project syncope by apache.
the class TaskTest method addPushTaskExecution.
@Test
public void addPushTaskExecution() {
PushTask task = taskDAO.find("af558be4-9d2f-4359-bf85-a554e6e90be1");
assertNotNull(task);
int executionNumber = task.getExecs().size();
TaskExec execution = entityFactory.newEntity(TaskExec.class);
execution.setStatus("Text-free status");
execution.setTask(task);
execution.setStart(new Date());
execution.setMessage("A message");
task.add(execution);
taskDAO.save(task);
taskDAO.flush();
task = taskDAO.find("af558be4-9d2f-4359-bf85-a554e6e90be1");
assertNotNull(task);
assertEquals(executionNumber + 1, task.getExecs().size());
}
Aggregations