use of org.apache.syncope.common.lib.to.TypeExtensionTO in project syncope by apache.
the class MembershipITCase method onGroupDelete.
@Test
public void onGroupDelete() {
// pre: create group with type extension
TypeExtensionTO typeExtension = new TypeExtensionTO();
typeExtension.setAnyType(AnyTypeKind.USER.name());
typeExtension.getAuxClasses().add("csv");
typeExtension.getAuxClasses().add("other");
GroupTO groupTO = GroupITCase.getBasicSampleTO("typeExt");
groupTO.getTypeExtensions().add(typeExtension);
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
// pre: create user with membership to such group
UserTO user = UserITCase.getUniqueSampleTO("typeExt@apache.org");
MembershipTO membership = new MembershipTO.Builder().group(groupTO.getKey()).build();
membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("1454").build());
user.getMemberships().add(membership);
user = createUser(user).getEntity();
// verify that 'aLong' is correctly populated for user's membership
assertEquals(1, user.getMemberships().size());
membership = user.getMembership(groupTO.getKey()).get();
assertNotNull(membership);
assertEquals(1, membership.getPlainAttr("aLong").get().getValues().size());
assertEquals("1454", membership.getPlainAttr("aLong").get().getValues().get(0));
// verify that derived attrbutes from 'csv' and 'other' are also populated for user's membership
assertFalse(membership.getDerAttr("csvuserid").get().getValues().isEmpty());
assertFalse(membership.getDerAttr("noschema").get().getValues().isEmpty());
// now remove the group -> all related memberships should have been removed as well
groupService.delete(groupTO.getKey());
// re-read user and verify that no memberships are available any more
user = userService.read(user.getKey());
assertTrue(user.getMemberships().isEmpty());
}
use of org.apache.syncope.common.lib.to.TypeExtensionTO in project syncope by apache.
the class GroupDataBinderImpl method getTypeExtensionTO.
@Override
public TypeExtensionTO getTypeExtensionTO(final TypeExtension typeExt) {
TypeExtensionTO typeExtTO = new TypeExtensionTO();
typeExtTO.setAnyType(typeExt.getAnyType().getKey());
typeExtTO.getAuxClasses().addAll(typeExt.getAuxClasses().stream().map(Entity::getKey).collect(Collectors.toList()));
return typeExtTO;
}
use of org.apache.syncope.common.lib.to.TypeExtensionTO in project syncope by apache.
the class GroupDataBinderImpl method update.
@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
// Re-merge any pending change from workflow tasks
Group group = groupDAO.save(toBeUpdated);
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
// fetch connObjectKeys before update
Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
// realm
setRealm(group, groupPatch);
// name
if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
group.setName(groupPatch.getName().getValue());
}
// owner
if (groupPatch.getUserOwner() != null) {
group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
}
if (groupPatch.getGroupOwner() != null) {
group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
}
// attributes and resources
propByRes.merge(fill(group, groupPatch, anyUtils, scce));
// check if some connObjectKey was changed by the update above
Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
propByRes.add(ResourceOperation.UPDATE, entry.getKey());
});
group = groupDAO.save(group);
// dynamic membership
if (groupPatch.getUDynMembershipCond() == null) {
if (group.getUDynMembership() != null) {
group.getUDynMembership().setGroup(null);
group.setUDynMembership(null);
groupDAO.clearUDynMembers(group);
}
} else {
setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
}
for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
ADynGroupMembership memb = itor.next();
memb.setGroup(null);
itor.remove();
}
groupDAO.clearADynMembers(group);
for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
AnyType anyType = anyTypeDAO.find(entry.getKey());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
} else {
setDynMembership(group, anyType, entry.getValue());
}
}
// type extensions
for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
if (typeExt == null) {
typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
}
// add all classes contained in the TO
for (String name : typeExtTO.getAuxClasses()) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
}
// remove all classes not contained in the TO
typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
// only consider non-empty type extensions
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
}
// remove all type extensions not contained in the TO
group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
return propByRes;
}
use of org.apache.syncope.common.lib.to.TypeExtensionTO in project syncope by apache.
the class GroupITCase method typeExtensions.
@Test
public void typeExtensions() {
TypeExtensionTO typeExtension = new TypeExtensionTO();
typeExtension.setAnyType(AnyTypeKind.USER.name());
typeExtension.getAuxClasses().add("csv");
GroupTO groupTO = getBasicSampleTO("typeExtensions");
groupTO.getTypeExtensions().add(typeExtension);
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
assertEquals(1, groupTO.getTypeExtensions().size());
assertEquals(1, groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().size());
assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("csv"));
typeExtension = new TypeExtensionTO();
typeExtension.setAnyType(AnyTypeKind.USER.name());
typeExtension.getAuxClasses().add("csv");
typeExtension.getAuxClasses().add("other");
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.getTypeExtensions().add(typeExtension);
groupTO = updateGroup(groupPatch).getEntity();
assertNotNull(groupTO);
assertEquals(1, groupTO.getTypeExtensions().size());
assertEquals(2, groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().size());
assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("csv"));
assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("other"));
}
use of org.apache.syncope.common.lib.to.TypeExtensionTO in project syncope by apache.
the class TypeExtensionDirectoryPanel method getActions.
@Override
public ActionsPanel<TypeExtensionTO> getActions(final IModel<TypeExtensionTO> model) {
final ActionsPanel<TypeExtensionTO> panel = super.getActions(model);
final TypeExtensionTO typeExtension = model.getObject();
panel.add(new ActionLink<TypeExtensionTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final TypeExtensionTO ignore) {
send(TypeExtensionDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(typeExtension, target));
}
}, ActionLink.ActionType.EDIT, StringUtils.EMPTY);
panel.add(new ActionLink<TypeExtensionTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final TypeExtensionTO ignore) {
Optional<TypeExtensionTO> typeExt = groupTO.getTypeExtension(typeExtension.getAnyType());
if (typeExt.isPresent()) {
groupTO.getTypeExtensions().remove(typeExt.get());
target.add(container);
}
}
}, ActionLink.ActionType.DELETE, StringUtils.EMPTY, true);
return panel;
}
Aggregations