use of org.apache.syncope.core.persistence.api.entity.task.PropagationTask in project syncope by apache.
the class TaskTest method delete.
@Test
public void delete() {
PropagationTask task = taskDAO.find("1e697572-b896-484c-ae7f-0c8f63fcbc6c");
assertNotNull(task);
ExternalResource resource = task.getResource();
assertNotNull(resource);
taskDAO.delete(task);
task = taskDAO.find("1e697572-b896-484c-ae7f-0c8f63fcbc6c");
assertNull(task);
resource = resourceDAO.find(resource.getKey());
assertNotNull(resource);
assertFalse(taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList()).contains(task));
}
use of org.apache.syncope.core.persistence.api.entity.task.PropagationTask in project syncope by apache.
the class TaskTest method deleteTaskExecution.
@Test
public void deleteTaskExecution() {
TaskExec execution = taskExecDAO.find("e58ca1c7-178a-4012-8a71-8aa14eaf0655");
int executionNumber = execution.getTask().getExecs().size();
taskExecDAO.delete("e58ca1c7-178a-4012-8a71-8aa14eaf0655");
taskExecDAO.flush();
assertNull(taskExecDAO.find("e58ca1c7-178a-4012-8a71-8aa14eaf0655"));
PropagationTask task = taskDAO.find("1e697572-b896-484c-ae7f-0c8f63fcbc6c");
assertEquals(task.getExecs().size(), executionNumber - 1);
}
use of org.apache.syncope.core.persistence.api.entity.task.PropagationTask in project syncope by apache.
the class AbstractPropagationTaskExecutor method getRemoteObject.
/**
* Get remote object for given task.
*
* @param connector connector facade proxy.
* @param task current propagation task.
* @param provision provision
* @param latest 'FALSE' to retrieve object using old connObjectKey if not null.
* @return remote connector object.
*/
protected ConnectorObject getRemoteObject(final PropagationTask task, final Connector connector, final Provision provision, final boolean latest) {
String connObjectKey = latest || task.getOldConnObjectKey() == null ? task.getConnObjectKey() : task.getOldConnObjectKey();
Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
ConnectorObject obj = null;
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
if (connObjectKeyItem.isPresent()) {
try {
obj = connector.getObject(new ObjectClass(task.getObjectClassName()), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey), MappingUtils.buildOperationOptions(new IteratorChain<>(MappingUtils.getPropagationItems(provision.getMapping().getItems()).iterator(), linkingMappingItems.iterator())));
for (MappingItem item : linkingMappingItems) {
Attribute attr = obj.getAttributeByName(item.getExtAttrName());
if (attr == null) {
virAttrCache.expire(task.getAnyType(), task.getEntityKey(), item.getIntAttrName());
} else {
VirAttrCacheValue cacheValue = new VirAttrCacheValue();
cacheValue.setValues(attr.getValue());
virAttrCache.put(task.getAnyType(), task.getEntityKey(), item.getIntAttrName(), cacheValue);
}
}
} catch (TimeoutException toe) {
LOG.debug("Request timeout", toe);
throw toe;
} catch (RuntimeException ignore) {
LOG.debug("While resolving {}", connObjectKey, ignore);
}
}
return obj;
}
use of org.apache.syncope.core.persistence.api.entity.task.PropagationTask in project syncope by apache.
the class ResourceTest method delete.
@Test
public void delete() {
ExternalResource resource = resourceDAO.find("resource-testdb");
assertNotNull(resource);
// -------------------------------------
// Get originally associated connector
// -------------------------------------
ConnInstance connector = resource.getConnector();
assertNotNull(connector);
// -------------------------------------
// -------------------------------------
// Get originally associated users
// -------------------------------------
List<User> users = userDAO.findByResource(resource);
assertNotNull(users);
Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
// -------------------------------------
// Get tasks
List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
assertFalse(propagationTasks.isEmpty());
// delete resource
resourceDAO.delete(resource.getKey());
// close the transaction
resourceDAO.flush();
// resource must be removed
ExternalResource actual = resourceDAO.find("resource-testdb");
assertNull(actual);
// resource must be not referenced any more from users
userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
assertNotNull(actualUser);
return actualUser;
}).forEachOrdered((actualUser) -> {
userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
});
// resource must be not referenced any more from the connector
ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
assertNotNull(actualConnector);
actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
// there must be no tasks
propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
use of org.apache.syncope.core.persistence.api.entity.task.PropagationTask in project syncope by apache.
the class TaskTest method save.
@Test
public void save() {
ExternalResource resource = resourceDAO.find("ws-target-resource-1");
assertNotNull(resource);
User user = userDAO.findByUsername("verdi");
assertNotNull(user);
PropagationTask task = entityFactory.newEntity(PropagationTask.class);
task.setResource(resource);
task.setAnyTypeKind(AnyTypeKind.USER);
task.setAnyType(AnyTypeKind.USER.name());
task.setOperation(ResourceOperation.CREATE);
task.setConnObjectKey("one@two.com");
Set<Attribute> attributes = new HashSet<>();
attributes.add(AttributeBuilder.build("testAttribute", "testValue1", "testValue2"));
attributes.add(AttributeBuilder.buildPassword("password".toCharArray()));
task.setAttributes(attributes);
task = taskDAO.save(task);
assertNotNull(task);
PropagationTask actual = taskDAO.find(task.getKey());
assertEquals(task, actual);
taskDAO.flush();
resource = resourceDAO.find("ws-target-resource-1");
assertTrue(taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList()).contains(task));
}
Aggregations