use of org.apache.syncope.core.persistence.api.entity.DynRealmMembership in project syncope by apache.
the class DynRealmDataBinderImpl method update.
@Override
public DynRealm update(final DynRealm toBeUpdated, final DynRealmTO dynRealmTO) {
toBeUpdated.setKey(dynRealmTO.getKey());
DynRealm dynRealm = dynRealmDAO.save(toBeUpdated);
for (Iterator<? extends DynRealmMembership> itor = dynRealm.getDynMemberships().iterator(); itor.hasNext(); ) {
DynRealmMembership memb = itor.next();
memb.setDynRealm(null);
itor.remove();
}
dynRealmDAO.clearDynMembers(dynRealm);
dynRealmTO.getDynMembershipConds().forEach((type, fiql) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), type);
} else {
setDynMembership(dynRealm, anyType, fiql);
}
});
return dynRealmDAO.save(dynRealm);
}
use of org.apache.syncope.core.persistence.api.entity.DynRealmMembership in project syncope by apache.
the class DynRealmDataBinderImpl method setDynMembership.
private void setDynMembership(final DynRealm dynRealm, final AnyType anyType, final String dynMembershipFIQL) {
SearchCond dynMembershipCond = SearchCondConverter.convert(dynMembershipFIQL);
if (!dynMembershipCond.isValid()) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression);
sce.getElements().add(dynMembershipFIQL);
throw sce;
}
DynRealmMembership dynMembership;
if (dynRealm.getDynMembership(anyType).isPresent()) {
dynMembership = dynRealm.getDynMembership(anyType).get();
} else {
dynMembership = entityFactory.newEntity(DynRealmMembership.class);
dynMembership.setDynRealm(dynRealm);
dynMembership.setAnyType(anyType);
dynRealm.add(dynMembership);
}
dynMembership.setFIQLCond(dynMembershipFIQL);
}
use of org.apache.syncope.core.persistence.api.entity.DynRealmMembership in project syncope by apache.
the class DynRealmTest method misc.
@Test
public void misc() {
DynRealm dynRealm = entityFactory.newEntity(DynRealm.class);
dynRealm.setKey("/name");
DynRealmMembership memb = entityFactory.newEntity(DynRealmMembership.class);
memb.setDynRealm(dynRealm);
memb.setAnyType(anyTypeDAO.findUser());
memb.setFIQLCond("cool==true");
dynRealm.add(memb);
memb.setDynRealm(dynRealm);
// invalid key (starts with /)
try {
dynRealmDAO.save(dynRealm);
fail("This should not happen");
} catch (Exception e) {
assertNotNull(e);
}
dynRealm.setKey("name");
DynRealm actual = dynRealmDAO.save(dynRealm);
assertNotNull(actual);
dynRealmDAO.flush();
DynRealmCond dynRealmCond = new DynRealmCond();
dynRealmCond.setDynRealm(actual.getKey());
List<User> matching = searchDAO.search(SearchCond.getLeafCond(dynRealmCond), AnyTypeKind.USER);
assertNotNull(matching);
assertFalse(matching.isEmpty());
User user = matching.get(0);
assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(dynRealmCond)));
assertTrue(userDAO.findDynRealms(user.getKey()).contains(actual.getKey()));
}
Aggregations