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;
}
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;
}
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");
}
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());
}
}
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());
}
Aggregations