Search in sources :

Example 11 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AbstractAnySearchDAO method check.

protected String check(final RelationshipCond cond) {
    String rightAnyObjectKey;
    if (SyncopeConstants.UUID_PATTERN.matcher(cond.getAnyObject()).matches()) {
        rightAnyObjectKey = cond.getAnyObject();
    } else {
        AnyObject anyObject = anyObjectDAO.findByName(cond.getAnyObject());
        rightAnyObjectKey = anyObject == null ? null : anyObject.getKey();
    }
    if (rightAnyObjectKey == null) {
        LOG.error("Could not find any object for '" + cond.getAnyObject() + "'");
        throw new IllegalArgumentException();
    }
    return rightAnyObjectKey;
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)

Example 12 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class JPAAnyObjectDAO method doSave.

private Pair<AnyObject, Pair<Set<String>, Set<String>>> doSave(final AnyObject anyObject) {
    AnyObject merged = super.save(anyObject);
    publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
    Pair<Set<String>, Set<String>> dynGroupMembs = groupDAO().refreshDynMemberships(merged);
    dynRealmDAO().refreshDynMemberships(merged);
    return Pair.of(merged, dynGroupMembs);
}
Also used : JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) HashSet(java.util.HashSet) Set(java.util.Set)

Example 13 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class GroupTest method findDynGroups.

/**
 * Static copy of {@link org.apache.syncope.core.persistence.jpa.dao.JPAAnyObjectDAO} method with same signature:
 * required for avoiding creating of a new transaction - good for general use case but bad for the way how
 * this test class is architected.
 */
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final AnyObject anyObject) {
    Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.ADYNMEMB_TABLE + " WHERE any_id=?");
    query.setParameter(1, anyObject.getKey());
    List<Group> result = new ArrayList<>();
    query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
        Group group = groupDAO.find(actualKey.toString());
        if (group == null) {
        } else if (!result.contains(group)) {
            result.add(group);
        }
    });
    return result;
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) UDynGroupMembership(org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GPlainAttrValue(org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) JPAADynGroupMembership(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Collection(java.util.Collection) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) User(org.apache.syncope.core.persistence.api.entity.user.User) GPlainAttr(org.apache.syncope.core.persistence.api.entity.group.GPlainAttr) JPAUDynGroupMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPAUDynGroupMembership) JPAGroupDAO(org.apache.syncope.core.persistence.jpa.dao.JPAGroupDAO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) PlainAttrValueDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) List(java.util.List) Query(javax.persistence.Query) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) APlainAttr(org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttr) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)

Example 14 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AnySearchTest method searchByType.

@Test
public void searchByType() {
    AnyTypeCond tcond = new AnyTypeCond();
    tcond.setAnyTypeKey("PRINTER");
    SearchCond searchCondition = SearchCond.getLeafCond(tcond);
    assertTrue(searchCondition.isValid());
    List<AnyObject> printers = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertNotNull(printers);
    assertEquals(3, printers.size());
    tcond.setAnyTypeKey("UNEXISTING");
    printers = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertNotNull(printers);
    assertTrue(printers.isEmpty());
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 15 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AnySearchTest method anyObjectMatch.

@Test
public void anyObjectMatch() {
    AnyObject anyObject = anyObjectDAO.find("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
    assertNotNull(anyObject);
    RelationshipCond relationshipCond = new RelationshipCond();
    relationshipCond.setAnyObject("Canon MF 8030cn");
    assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipCond)));
    RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
    relationshipTypeCond.setRelationshipTypeKey("neighborhood");
    assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipTypeCond)));
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)29 Group (org.apache.syncope.core.persistence.api.entity.group.Group)18 User (org.apache.syncope.core.persistence.api.entity.user.User)15 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)11 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Transactional (org.springframework.transaction.annotation.Transactional)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)7 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)7 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)7 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)7 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)7 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)7 Collections (java.util.Collections)6 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)6