use of org.apache.syncope.common.lib.to.PushTaskTO in project syncope by apache.
the class PushTaskITCase method createPushTask.
@Test
public void createPushTask() {
PushTaskTO task = new PushTaskTO();
task.setName("Test create Push");
task.setResource(RESOURCE_NAME_WS2);
task.setSourceRealm(SyncopeConstants.ROOT_REALM);
task.getFilters().put(AnyTypeKind.USER.name(), SyncopeClient.getUserSearchConditionBuilder().hasNotResources(RESOURCE_NAME_TESTDB2).query());
task.getFilters().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().isNotNull("cool").query());
task.setMatchingRule(MatchingRule.LINK);
final Response response = taskService.create(TaskType.PUSH, task);
final PushTaskTO actual = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
assertNotNull(actual);
task = taskService.read(TaskType.PUSH, actual.getKey(), true);
assertNotNull(task);
assertEquals(task.getKey(), actual.getKey());
assertEquals(task.getJobDelegate(), actual.getJobDelegate());
assertEquals(task.getFilters().get(AnyTypeKind.USER.name()), actual.getFilters().get(AnyTypeKind.USER.name()));
assertEquals(task.getFilters().get(AnyTypeKind.GROUP.name()), actual.getFilters().get(AnyTypeKind.GROUP.name()));
assertEquals(UnmatchingRule.ASSIGN, actual.getUnmatchingRule());
assertEquals(MatchingRule.LINK, actual.getMatchingRule());
}
use of org.apache.syncope.common.lib.to.PushTaskTO in project syncope by apache.
the class PushTaskITCase method orgUnit.
@Test
public void orgUnit() {
assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=odd,o=isp"));
assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=even,o=isp"));
assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=two,ou=even,o=isp"));
// 1. create task for pulling org units
PushTaskTO task = new PushTaskTO();
task.setName("For orgUnit");
task.setActive(true);
task.setResource(RESOURCE_NAME_LDAP_ORGUNIT);
task.setSourceRealm(SyncopeConstants.ROOT_REALM);
task.setPerformCreate(true);
task.setPerformDelete(true);
task.setPerformUpdate(true);
Response response = taskService.create(TaskType.PUSH, task);
PushTaskTO pushTask = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
assertNotNull(pushTask);
ExecTO exec = execProvisioningTask(taskService, TaskType.PUSH, pushTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
// 2. check
assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=odd,o=isp"));
assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=even,o=isp"));
assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=two,ou=even,o=isp"));
}
use of org.apache.syncope.common.lib.to.PushTaskTO 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.PushTaskTO 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.PushTaskTO in project syncope by apache.
the class PushTaskITCase method issueSYNCOPE598.
@Test
public void issueSYNCOPE598() {
// create a new group schema
PlainSchemaTO schemaTO = new PlainSchemaTO();
schemaTO.setKey("LDAPGroupName" + getUUIDString());
schemaTO.setType(AttrSchemaType.String);
schemaTO.setMandatoryCondition("true");
schemaTO = createSchema(SchemaType.PLAIN, schemaTO);
assertNotNull(schemaTO);
AnyTypeClassTO typeClass = new AnyTypeClassTO();
typeClass.setKey("SYNCOPE-598" + getUUIDString());
typeClass.getPlainSchemas().add(schemaTO.getKey());
anyTypeClassService.create(typeClass);
// create a new sample group
GroupTO groupTO = new GroupTO();
groupTO.setName("all" + getUUIDString());
groupTO.setRealm("/even");
groupTO.getAuxClasses().add(typeClass.getKey());
groupTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "all"));
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
String resourceName = "resource-ldap-grouponly";
ResourceTO newResourceTO = null;
try {
// Create resource ad-hoc
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceName);
resourceTO.setConnector("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.GROUP.name());
provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
provisionTO.getAuxClasses().add(typeClass.getKey());
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setExtAttrName("cn");
item.setIntAttrName(schemaTO.getKey());
item.setConnObjectKey(true);
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
mapping.setConnObjectLink("'cn=' + " + schemaTO.getKey() + " + ',ou=groups,o=isp'");
Response response = resourceService.create(resourceTO);
newResourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(newResourceTO);
assertFalse(newResourceTO.getProvision(AnyTypeKind.USER.name()).isPresent());
assertNotNull(newResourceTO.getProvision(AnyTypeKind.GROUP.name()).get().getMapping());
// create push task ad-hoc
PushTaskTO task = new PushTaskTO();
task.setName("issueSYNCOPE598");
task.setActive(true);
task.setResource(resourceName);
task.setSourceRealm(SyncopeConstants.ROOT_REALM);
task.setPerformCreate(true);
task.setPerformDelete(true);
task.setPerformUpdate(true);
task.setUnmatchingRule(UnmatchingRule.ASSIGN);
task.setMatchingRule(MatchingRule.UPDATE);
task.getFilters().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupTO.getName()).query());
response = taskService.create(TaskType.PUSH, task);
PushTaskTO push = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
assertNotNull(push);
// execute the new task
ExecTO exec = execProvisioningTask(taskService, TaskType.PUSH, push.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
} finally {
groupService.delete(groupTO.getKey());
if (newResourceTO != null) {
resourceService.delete(resourceName);
}
}
}
Aggregations