Search in sources :

Example 1 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch 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 GroupTO
 * @param original original GroupTO
 * @param incremental perform incremental diff (without removing existing info)
 * @return GroupPatch containing differences
 */
public static GroupPatch diff(final GroupTO updated, final GroupTO original, final boolean incremental) {
    GroupPatch result = new GroupPatch();
    diff(updated, original, result, incremental);
    // 1. name
    result.setName(replacePatchItem(updated.getName(), original.getName(), new StringReplacePatchItem()));
    // 2. ownership
    result.setUserOwner(replacePatchItem(updated.getUserOwner(), original.getUserOwner(), new StringReplacePatchItem()));
    result.setGroupOwner(replacePatchItem(updated.getGroupOwner(), original.getGroupOwner(), new StringReplacePatchItem()));
    // 3. dynamic membership
    result.setUDynMembershipCond(updated.getUDynMembershipCond());
    result.getADynMembershipConds().putAll(updated.getADynMembershipConds());
    // 4. type extensions
    result.getTypeExtensions().addAll(updated.getTypeExtensions());
    return result;
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch)

Example 2 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class DefaultGroupWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<GroupPatch> doUpdate(final Group group, final GroupPatch groupPatch) {
    GroupTO original = dataBinder.getGroupTO(group, true);
    PropagationByResource propByRes = dataBinder.update(group, groupPatch);
    Set<AttrTO> virAttrs = groupPatch.getVirAttrs();
    GroupTO updated = dataBinder.getGroupTO(groupDAO.save(group), true);
    GroupPatch effectivePatch = AnyOperations.diff(updated, original, false);
    effectivePatch.getVirAttrs().clear();
    effectivePatch.getVirAttrs().addAll(virAttrs);
    return new WorkflowResult<>(effectivePatch, propByRes, "update");
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 3 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class CamelGroupProvisioningManager method link.

@Override
public String link(final GroupPatch groupPatch) {
    PollingConsumer pollingConsumer = getConsumer("direct:linkGroupPort");
    sendMessage("direct:linkGroup", groupPatch);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(GroupPatch.class).getKey();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch)

Example 4 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class GroupITCase method patch.

@Test
public void patch() {
    GroupTO original = getBasicSampleTO("patch");
    original.setUDynMembershipCond("(($groups==3;$resources!=ws-target-resource-1);aLong==1)");
    original.getADynMembershipConds().put("PRINTER", "(($groups==7;cool==ss);$resources==ws-target-resource-2);$type==PRINTER");
    GroupTO updated = createGroup(original).getEntity();
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("icon").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("show").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("rderived_sx").value("sx").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("rderived_dx").value("dx").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("title").value("mr").build());
    original = groupService.read(updated.getKey());
    GroupPatch patch = AnyOperations.diff(updated, original, true);
    GroupTO group = updateGroup(patch).getEntity();
    Map<String, AttrTO> attrs = EntityTOUtils.buildAttrMap(group.getPlainAttrs());
    assertFalse(attrs.containsKey("icon"));
    assertFalse(attrs.containsKey("show"));
    assertEquals(Collections.singletonList("sx"), attrs.get("rderived_sx").getValues());
    assertEquals(Collections.singletonList("dx"), attrs.get("rderived_dx").getValues());
    assertEquals(Collections.singletonList("mr"), attrs.get("title").getValues());
}
Also used : AttrTO(org.apache.syncope.common.lib.to.AttrTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 5 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class GroupITCase method issueSYNCOPE717.

@Test
public void issueSYNCOPE717() {
    String doubleSchemaName = "double" + getUUIDString();
    // 1. create double schema without conversion pattern
    PlainSchemaTO schema = new PlainSchemaTO();
    schema.setKey(doubleSchemaName);
    schema.setType(AttrSchemaType.Double);
    schema = createSchema(SchemaType.PLAIN, schema);
    assertNotNull(schema);
    assertNull(schema.getConversionPattern());
    AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
    assertNotNull(minimalGroup);
    minimalGroup.getPlainSchemas().add(doubleSchemaName);
    anyTypeClassService.update(minimalGroup);
    // 2. create group, provide valid input value
    GroupTO groupTO = GroupITCase.getBasicSampleTO("syncope717");
    groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 3. update schema, set conversion pattern
    schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
    schema.setConversionPattern("0.000");
    schemaService.update(SchemaType.PLAIN, schema);
    // 4. re-read group, verify that pattern was applied
    groupTO = groupService.read(groupTO.getKey());
    assertNotNull(groupTO);
    assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 5. modify group with new double value
    GroupPatch patch = new GroupPatch();
    patch.setKey(groupTO.getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
    groupTO = updateGroup(patch).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 6. update schema, unset conversion pattern
    schema.setConversionPattern(null);
    schemaService.update(SchemaType.PLAIN, schema);
    // 7. modify group with new double value, verify that no pattern is applied
    patch = new GroupPatch();
    patch.setKey(groupTO.getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
    groupTO = updateGroup(patch).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)33 GroupTO (org.apache.syncope.common.lib.to.GroupTO)23 Test (org.junit.jupiter.api.Test)15 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 List (java.util.List)5 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)5 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)5 GroupService (org.apache.syncope.common.rest.api.service.GroupService)5 ForbiddenException (javax.ws.rs.ForbiddenException)4 Response (javax.ws.rs.core.Response)4 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 StringPatchItem (org.apache.syncope.common.lib.patch.StringPatchItem)4 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)4 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 AccessControlException (java.security.AccessControlException)3 Collections (java.util.Collections)3 Map (java.util.Map)3 NamingException (javax.naming.NamingException)3