use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class DefaultAnyObjectPullResultHandler method doCreate.
@Override
protected AnyTO doCreate(final AnyTO anyTO, final SyncDelta delta) {
AnyObjectTO anyObjectTO = AnyObjectTO.class.cast(anyTO);
Map.Entry<String, List<PropagationStatus>> created = anyObjectProvisioningManager.create(anyObjectTO, Collections.singleton(profile.getTask().getResource().getKey()), true);
return getAnyTO(created.getKey());
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class PropagationTaskITCase method propagationJEXLTransformer.
@Test
public void propagationJEXLTransformer() {
// 0. Set propagation JEXL MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
Optional<ItemTO> mappingItem = provision.getMapping().getItems().stream().filter(item -> "location".equals(item.getIntAttrName())).findFirst();
assertTrue(mappingItem.isPresent());
assertTrue(mappingItem.get().getTransformers().isEmpty());
String suffix = getUUIDString();
mappingItem.get().setPropagationJEXLTransformer("value + '" + suffix + "'");
try {
resourceService.update(resource);
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("propagationJEXLTransformer");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.endsWith(suffix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that JEXL MappingItemTransformer was applied during propagation
// (location ends with given suffix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).endsWith(suffix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).endsWith(suffix));
} finally {
resourceService.update(originalResource);
}
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class PullTaskITCase method reconcileFromScriptedSQL.
@Test
public void reconcileFromScriptedSQL() throws IOException {
// 0. reset sync token and set MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
ItemTO mappingItem = provision.getMapping().getItems().stream().filter(object -> "location".equals(object.getIntAttrName())).findFirst().get();
assertNotNull(mappingItem);
final String prefix = "PREFIX_";
ImplementationTO transformer = new ImplementationTO();
transformer.setKey("PrefixItemTransformer");
transformer.setEngine(ImplementationEngine.GROOVY);
transformer.setType(ImplementationType.ITEM_TRANSFORMER);
transformer.setBody(IOUtils.toString(getClass().getResourceAsStream("/PrefixItemTransformer.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(transformer);
transformer = implementationService.read(transformer.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(transformer);
mappingItem.getTransformers().clear();
mappingItem.getTransformers().add(transformer.getKey());
try {
resourceService.update(resource);
resourceService.removeSyncToken(resource.getKey(), provision.getAnyType());
// insert a deleted record in the external resource (SYNCOPE-923), which will be returned
// as sync event prior to the CREATE_OR_UPDATE events generated by the actions below (before pull)
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
jdbcTemplate.update("INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)", UUID.randomUUID().toString(), "Mysterious Printer", "Nowhere", true, new Date());
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("pull");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.startsWith(prefix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that PrefixMappingItemTransformer was applied during propagation
// (location starts with given prefix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).startsWith(prefix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).startsWith(prefix));
// 3. unlink any existing printer and delete from Syncope (printer is now only on external resource)
PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
for (AnyObjectTO printer : matchingPrinters.getResult()) {
anyObjectService.deassociate(new DeassociationPatch.Builder().key(printer.getKey()).action(ResourceDeassociationAction.UNLINK).resource(RESOURCE_NAME_DBSCRIPTED).build());
anyObjectService.delete(printer.getKey());
}
// ensure that the pull task does not have the DELETE capability (SYNCOPE-923)
PullTaskTO pullTask = taskService.read(TaskType.PULL, "30cfd653-257b-495f-8665-281281dbcb3d", false);
assertNotNull(pullTask);
assertFalse(pullTask.isPerformDelete());
// 4. pull
execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
// 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix,
// hence PrefixItemTransformer was applied during pull)
matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
// 6. verify that synctoken was updated
assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()).get().getSyncToken());
} finally {
resourceService.update(originalResource);
}
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class SearchITCase method searchByType.
@Test
public void searchByType() {
PagedResult<AnyObjectTO> matching = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").query()).build());
assertNotNull(matching);
assertFalse(matching.getResult().isEmpty());
for (AnyObjectTO printer : matching.getResult()) {
assertNotNull(printer);
}
matching = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("UNEXISTING").query()).build());
assertNotNull(matching);
assertTrue(matching.getResult().isEmpty());
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class ResourceITCase method syncToken.
@Test
public void syncToken() {
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
resource.setKey(resource.getKey() + getUUIDString());
AnyObjectTO anyObject = AnyObjectITCase.getSampleTO("syncToken");
anyObject.getResources().clear();
anyObject.getResources().add(resource.getKey());
try {
// create a new resource
resource = createResource(resource);
assertNull(resource.getProvision("PRINTER").get().getSyncToken());
// create some object on the new resource
anyObject = createAnyObject(anyObject).getEntity();
// update sync token
resourceService.setLatestSyncToken(resource.getKey(), "PRINTER");
resource = resourceService.read(resource.getKey());
assertNotNull(resource.getProvision("PRINTER").get().getSyncToken());
// remove sync token
resourceService.removeSyncToken(resource.getKey(), "PRINTER");
resource = resourceService.read(resource.getKey());
assertNull(resource.getProvision("PRINTER").get().getSyncToken());
} finally {
if (anyObject.getKey() != null) {
anyObjectService.delete(anyObject.getKey());
}
resourceService.delete(resource.getKey());
}
}
Aggregations