Search in sources :

Example 1 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class AnyOperations method diff.

/**
 * Calculate modifications needed by first in order to be equal to second.
 *
 * @param updated updated AnyObjectTO
 * @param original original AnyObjectTO
 * @param incremental perform incremental diff (without removing existing info)
 * @return AnyObjectPatch containing differences
 */
public static AnyObjectPatch diff(final AnyObjectTO updated, final AnyObjectTO original, final boolean incremental) {
    AnyObjectPatch result = new AnyObjectPatch();
    diff(updated, original, result, incremental);
    // 1. name
    result.setName(replacePatchItem(updated.getName(), original.getName(), new StringReplacePatchItem()));
    // 2. relationships
    Map<Pair<String, String>, RelationshipTO> updatedRels = EntityTOUtils.buildRelationshipMap(updated.getRelationships());
    Map<Pair<String, String>, RelationshipTO> originalRels = EntityTOUtils.buildRelationshipMap(original.getRelationships());
    updatedRels.entrySet().stream().filter(entry -> (!originalRels.containsKey(entry.getKey()))).forEachOrdered(entry -> {
        result.getRelationships().add(new RelationshipPatch.Builder().operation(PatchOperation.ADD_REPLACE).relationshipTO(entry.getValue()).build());
    });
    if (!incremental) {
        originalRels.keySet().stream().filter(relationship -> !updatedRels.containsKey(relationship)).forEach(key -> {
            result.getRelationships().add(new RelationshipPatch.Builder().operation(PatchOperation.DELETE).relationshipTO(originalRels.get(key)).build());
        });
    }
    // 3. memberships
    Map<String, MembershipTO> updatedMembs = EntityTOUtils.buildMembershipMap(updated.getMemberships());
    Map<String, MembershipTO> originalMembs = EntityTOUtils.buildMembershipMap(original.getMemberships());
    updatedMembs.entrySet().stream().filter(entry -> (!originalMembs.containsKey(entry.getKey()))).forEachOrdered(entry -> {
        result.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(entry.getValue().getGroupKey()).build());
    });
    if (!incremental) {
        originalMembs.keySet().stream().filter(membership -> !updatedMembs.containsKey(membership)).forEach(key -> {
            result.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(originalMembs.get(key).getGroupKey()).build());
        });
    }
    return result;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) LoggerFactory(org.slf4j.LoggerFactory) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch) StringUtils(org.apache.commons.lang3.StringUtils) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AbstractReplacePatchItem(org.apache.syncope.common.lib.patch.AbstractReplacePatchItem) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Optional(java.util.Optional) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class AnyObjectWizardBuilder method onApplyInternal.

@Override
protected Serializable onApplyInternal(final AnyWrapper<AnyObjectTO> modelObject) {
    final AnyObjectTO inner = modelObject.getInnerObject();
    ProvisioningResult<AnyObjectTO> actual;
    if (inner.getKey() == null) {
        actual = anyObjectRestClient.create(inner);
    } else {
        AnyObjectPatch patch = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
        // update just if it is changed
        if (patch.isEmpty()) {
            actual = new ProvisioningResult<>();
            actual.setEntity(inner);
        } else {
            actual = anyObjectRestClient.update(getOriginalItem().getInnerObject().getETagValue(), patch);
        }
    }
    return actual;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 3 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class DefaultAnyObjectWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<AnyObjectPatch> doUpdate(final AnyObject anyObject, final AnyObjectPatch anyObjectPatch) {
    AnyObjectTO original = dataBinder.getAnyObjectTO(anyObject, true);
    PropagationByResource propByRes = dataBinder.update(anyObject, anyObjectPatch);
    Set<AttrTO> virAttrs = anyObjectPatch.getVirAttrs();
    AnyObjectTO updated = dataBinder.getAnyObjectTO(anyObjectDAO.save(anyObject), true);
    AnyObjectPatch effectivePatch = AnyOperations.diff(updated, original, false);
    effectivePatch.getVirAttrs().clear();
    effectivePatch.getVirAttrs().addAll(virAttrs);
    return new WorkflowResult<>(effectivePatch, propByRes, "update");
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 4 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class SearchITCase method issueSYNCOPE980.

@Test
public void issueSYNCOPE980() {
    AnyTypeTO service = new AnyTypeTO();
    service.setKey("SERVICE");
    service.setKind(AnyTypeKind.ANY_OBJECT);
    Response response = anyTypeService.create(service);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    String serviceKey = null;
    try {
        AnyObjectTO anyObjectTO = new AnyObjectTO();
        anyObjectTO.setName("one");
        anyObjectTO.setRealm(SyncopeConstants.ROOT_REALM);
        anyObjectTO.setType(service.getKey());
        anyObjectTO.getMemberships().add(new MembershipTO.Builder().group("29f96485-729e-4d31-88a1-6fc60e4677f3").build());
        serviceKey = createAnyObject(anyObjectTO).getEntity().getKey();
        AnyObjectPatch anyObjectPatch = new AnyObjectPatch();
        anyObjectPatch.setKey("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
        anyObjectPatch.getMemberships().add(new MembershipPatch.Builder().group("29f96485-729e-4d31-88a1-6fc60e4677f3").build());
        updateAnyObject(anyObjectPatch);
        PagedResult<AnyObjectTO> matching = anyObjectService.search(new AnyQuery.Builder().fiql(SyncopeClient.getAnyObjectSearchConditionBuilder(service.getKey()).inGroups("29f96485-729e-4d31-88a1-6fc60e4677f3").query()).build());
        assertEquals(1, matching.getSize());
        assertEquals(serviceKey, matching.getResult().get(0).getKey());
    } finally {
        if (serviceKey != null) {
            anyObjectService.delete(serviceKey);
        }
        anyTypeService.delete(service.getKey());
    }
}
Also used : Response(javax.ws.rs.core.Response) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) Test(org.junit.jupiter.api.Test)

Example 5 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class GroupITCase method aStaticMembershipCount.

@Test
public void aStaticMembershipCount() {
    // Create a new printer as a static member of a new group
    GroupTO group = getBasicSampleTO("aStaticMembership");
    group = createGroup(group).getEntity();
    AnyObjectTO printer = new AnyObjectTO();
    printer.setRealm(SyncopeConstants.ROOT_REALM);
    printer.setName("Printer_" + getUUIDString());
    printer.setType("PRINTER");
    MembershipTO membership = new MembershipTO();
    membership.setGroupKey(group.getKey());
    printer.getMemberships().add(membership);
    printer = createAnyObject(printer).getEntity();
    group = groupService.read(group.getKey());
    assertEquals(0, group.getDynamicAnyObjectMembershipCount());
    assertEquals(1, group.getStaticAnyObjectMembershipCount());
    anyObjectService.delete(printer.getKey());
    groupService.delete(group.getKey());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) 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