Search in sources :

Example 26 with AnyObjectTO

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());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) List(java.util.List) Map(java.util.Map)

Example 27 with AnyObjectTO

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);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) TaskTO(org.apache.syncope.common.lib.to.TaskTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SerializationUtils(org.apache.commons.lang3.SerializationUtils) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) Test(org.junit.jupiter.api.Test) List(java.util.List) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) BulkAction(org.apache.syncope.common.lib.to.BulkAction) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 28 with AnyObjectTO

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);
    }
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Date(java.util.Date) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) Test(org.junit.jupiter.api.Test)

Example 29 with AnyObjectTO

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());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) Test(org.junit.jupiter.api.Test)

Example 30 with AnyObjectTO

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());
    }
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) Test(org.junit.jupiter.api.Test)

Aggregations

AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)45 Test (org.junit.jupiter.api.Test)19 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 UserTO (org.apache.syncope.common.lib.to.UserTO)14 AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)13 AttrTO (org.apache.syncope.common.lib.to.AttrTO)10 List (java.util.List)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)8 Map (java.util.Map)7 Pair (org.apache.commons.lang3.tuple.Pair)6 AnyTO (org.apache.syncope.common.lib.to.AnyTO)6 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)6 Optional (java.util.Optional)5 Set (java.util.Set)5 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)5 AnyQuery (org.apache.syncope.common.rest.api.beans.AnyQuery)5 User (org.apache.syncope.core.persistence.api.entity.user.User)5 ArrayList (java.util.ArrayList)4 Response (javax.ws.rs.core.Response)4