Search in sources :

Example 1 with DynRealmMembership

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);
}
Also used : DynRealmMembership(org.apache.syncope.core.persistence.api.entity.DynRealmMembership) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Example 2 with DynRealmMembership

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);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DynRealmMembership(org.apache.syncope.core.persistence.api.entity.DynRealmMembership) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond)

Example 3 with DynRealmMembership

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()));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) DynRealmCond(org.apache.syncope.core.persistence.api.dao.search.DynRealmCond) DynRealmMembership(org.apache.syncope.core.persistence.api.entity.DynRealmMembership) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

DynRealmMembership (org.apache.syncope.core.persistence.api.entity.DynRealmMembership)3 DynRealm (org.apache.syncope.core.persistence.api.entity.DynRealm)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 DynRealmCond (org.apache.syncope.core.persistence.api.dao.search.DynRealmCond)1 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)1 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)1 Test (org.junit.jupiter.api.Test)1