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));
}
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());
}
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());
}
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())));
}
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");
}
}
}
Aggregations