Search in sources :

Example 1 with AnyTypeCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond in project syncope by apache.

the class SearchCondConverterTest method type.

@Test
public void type() {
    String fiql = new AnyObjectFiqlSearchConditionBuilder("PRINTER").query();
    assertEquals(SpecialAttr.TYPE + "==PRINTER", fiql);
    AnyTypeCond acond = new AnyTypeCond();
    acond.setAnyTypeKey("PRINTER");
    SearchCond simpleCond = SearchCond.getLeafCond(acond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) AnyObjectFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 2 with AnyTypeCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond 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 3 with AnyTypeCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond in project syncope by apache.

the class AnySearchTest method issueSYNCOPE980.

@Test
public void issueSYNCOPE980() {
    AnyType service = entityFactory.newEntity(AnyType.class);
    service.setKey("SERVICE");
    service.setKind(AnyTypeKind.ANY_OBJECT);
    service = anyTypeDAO.save(service);
    Group citizen = groupDAO.findByName("citizen");
    assertNotNull(citizen);
    AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
    anyObject.setName("one");
    anyObject.setType(service);
    anyObject.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM));
    AMembership membership = entityFactory.newEntity(AMembership.class);
    membership.setRightEnd(citizen);
    membership.setLeftEnd(anyObject);
    anyObject.add(membership);
    anyObjectDAO.save(anyObject);
    anyObject = anyObjectDAO.find("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
    membership = entityFactory.newEntity(AMembership.class);
    membership.setRightEnd(citizen);
    membership.setLeftEnd(anyObject);
    anyObject.add(membership);
    anyObjectDAO.save(anyObject);
    anyObjectDAO.flush();
    MembershipCond groupCond = new MembershipCond();
    groupCond.setGroup("citizen");
    SearchCond searchCondition = SearchCond.getLeafCond(groupCond);
    List<AnyObject> matching = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertEquals(2, matching.size());
    AnyTypeCond anyTypeCond = new AnyTypeCond();
    anyTypeCond.setAnyTypeKey(service.getKey());
    searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(groupCond), SearchCond.getLeafCond(anyTypeCond));
    matching = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertEquals(1, matching.size());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 4 with AnyTypeCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond in project syncope by apache.

the class AnySearchTest method searchByRelationshipType.

@Test
public void searchByRelationshipType() {
    // 1. first search for printers involved in "neighborhood" relationship
    RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
    relationshipTypeCond.setRelationshipTypeKey("neighborhood");
    AnyTypeCond tcond = new AnyTypeCond();
    tcond.setAnyTypeKey("PRINTER");
    SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(relationshipTypeCond), SearchCond.getLeafCond(tcond));
    assertTrue(searchCondition.isValid());
    List<AnyObject> anyObjects = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertNotNull(anyObjects);
    assertEquals(2, anyObjects.size());
    assertTrue(anyObjects.stream().anyMatch(any -> "fc6dbc3a-6c07-4965-8781-921e7401a4a5".equals(any.getKey())));
    assertTrue(anyObjects.stream().anyMatch(any -> "8559d14d-58c2-46eb-a2d4-a7d35161e8f8".equals(any.getKey())));
    // 2. search for users involved in "neighborhood" relationship
    searchCondition = SearchCond.getLeafCond(relationshipTypeCond);
    List<User> users = searchDAO.search(searchCondition, AnyTypeKind.USER);
    assertNotNull(users);
    assertEquals(1, users.size());
    assertTrue(users.stream().anyMatch(any -> "c9b2dec2-00a7-4855-97c0-d854842b4b24".equals(any.getKey())));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) PrivilegeCond(org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) ResourceCond(org.apache.syncope.core.persistence.api.dao.search.ResourceCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) 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) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MemberCond(org.apache.syncope.core.persistence.api.dao.search.MemberCond) Test(org.junit.jupiter.api.Test) List(java.util.List) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) 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) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) User(org.apache.syncope.core.persistence.api.entity.user.User) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) 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 5 with AnyTypeCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond in project syncope by apache.

the class ReconciliationReportlet method doExtract.

@Override
protected void doExtract(final ReportletConf conf, final ContentHandler handler, final AtomicReference<String> status) throws SAXException {
    if (conf instanceof ReconciliationReportletConf) {
        this.conf = ReconciliationReportletConf.class.cast(conf);
    } else {
        throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
    }
    AttributesImpl atts = new AttributesImpl();
    if (StringUtils.isBlank(this.conf.getUserMatchingCond())) {
        int total = userDAO.count();
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " users in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " users: page " + page + " of " + pages);
            doExtract(handler, userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
        }
    } else {
        SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
        int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.USER);
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " users in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " users: page " + page + " of " + pages);
            doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER));
        }
    }
    handler.endElement("", "", getAnyElementName(AnyTypeKind.USER) + "s");
    atts.clear();
    if (StringUtils.isBlank(this.conf.getGroupMatchingCond())) {
        int total = groupDAO.count();
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " groups in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " groups: page " + page + " of " + pages);
            doExtract(handler, groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
        }
    } else {
        SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
        int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.GROUP);
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " groups in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " groups: page " + page + " of " + pages);
            doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.GROUP));
        }
    }
    handler.endElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s");
    for (AnyType anyType : anyTypeDAO.findAll()) {
        if (!anyType.equals(anyTypeDAO.findUser()) && !anyType.equals(anyTypeDAO.findGroup())) {
            AnyTypeCond anyTypeCond = new AnyTypeCond();
            anyTypeCond.setAnyTypeKey(anyType.getKey());
            SearchCond cond = StringUtils.isBlank(this.conf.getAnyObjectMatchingCond()) ? SearchCond.getLeafCond(anyTypeCond) : SearchCond.getAndCond(SearchCond.getLeafCond(anyTypeCond), SearchCondConverter.convert(this.conf.getAnyObjectMatchingCond()));
            int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.ANY_OBJECT);
            int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
            status.set("Processing " + total + " any objects " + anyType.getKey() + " in " + pages + " pages");
            atts.clear();
            atts.addAttribute("", "", "type", ReportXMLConst.XSD_STRING, anyType.getKey());
            atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
            handler.startElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s", atts);
            for (int page = 1; page <= pages; page++) {
                status.set("Processing " + total + " any objects " + anyType.getKey() + ": page " + page + " of " + pages);
                doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.ANY_OBJECT));
            }
            handler.endElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s");
        }
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) ReconciliationReportletConf(org.apache.syncope.common.lib.report.ReconciliationReportletConf) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Aggregations

AnyTypeCond (org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond)6 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)6 Test (org.junit.jupiter.api.Test)4 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)3 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)3 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)3 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)3 AssignableCond (org.apache.syncope.core.persistence.api.dao.search.AssignableCond)2 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)2 MemberCond (org.apache.syncope.core.persistence.api.dao.search.MemberCond)2 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)2 PrivilegeCond (org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond)2 RelationshipCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipCond)2 RelationshipTypeCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond)2 ResourceCond (org.apache.syncope.core.persistence.api.dao.search.ResourceCond)2 RoleCond (org.apache.syncope.core.persistence.api.dao.search.RoleCond)2 AMembership (org.apache.syncope.core.persistence.api.entity.anyobject.AMembership)2 Group (org.apache.syncope.core.persistence.api.entity.group.Group)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1