Skip to content

Commit

Permalink
query engine, org structure fix, tests updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 11, 2014
1 parent e6e6adc commit db28741
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 72 deletions.
Expand Up @@ -346,25 +346,25 @@ protected void assertMonkeyIslandOrgSanity() throws ObjectNotFoundException, Sch

List<PrismObject<OrgType>> governorSubOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, null, 1, task, result);
if (verbose) display("governor suborgs", governorSubOrgs);
assertEquals("Unexpected number of governor suborgs", 3, governorSubOrgs.size());
assertEquals("Unexpected number of governor suborgs", 4, governorSubOrgs.size());

List<PrismObject<OrgType>> functionalOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, null, null, task, result);
if (verbose) display("functional orgs (null)", functionalOrgs);
assertEquals("Unexpected number of functional orgs (null)", NUM_FUNCTIONAL_ORGS, functionalOrgs.size());

functionalOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, null, -1, task, result);
functionalOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, null, null, task, result);
if (verbose) display("functional orgs (-1)", functionalOrgs);
assertEquals("Unexpected number of functional orgs (-1)", NUM_FUNCTIONAL_ORGS, functionalOrgs.size());

List<PrismObject<OrgType>> prootSubOrgs = searchOrg(ORG_PROJECT_ROOT_OID, null, 1, task, result);
if (verbose) display("project root suborgs", prootSubOrgs);
assertEquals("Unexpected number of governor suborgs", 2, prootSubOrgs.size());
assertEquals("Unexpected number of governor suborgs", 3, prootSubOrgs.size());

List<PrismObject<OrgType>> projectOrgs = searchOrg(ORG_PROJECT_ROOT_OID, null, null, task, result);
if (verbose) display("project orgs (null)", projectOrgs);
assertEquals("Unexpected number of functional orgs (null)", NUM_PROJECT_ORGS, projectOrgs.size());

projectOrgs = searchOrg(ORG_PROJECT_ROOT_OID, null, -1, task, result);
projectOrgs = searchOrg(ORG_PROJECT_ROOT_OID, null, null, task, result);
if (verbose) display("project orgs (-1)", projectOrgs);
assertEquals("Unexpected number of functional orgs (-1)", NUM_PROJECT_ORGS, projectOrgs.size());

Expand Down
Expand Up @@ -724,7 +724,7 @@ public void test007searchOrgStructOrgDepth() throws Exception {

List<PrismObject<ObjectType>> sOrgClosure = repositoryService.searchObjects(ObjectType.class, objectQuery, null, parentResult);

AssertJUnit.assertEquals(4, sOrgClosure.size());
AssertJUnit.assertEquals(5, sOrgClosure.size());

for (PrismObject<ObjectType> u : sOrgClosure) {
LOGGER.info("USER000 ======> {}", ObjectTypeUtil.toShortString(u.asObjectable()));
Expand Down Expand Up @@ -848,7 +848,7 @@ public void test011OrgFilter() throws Exception {

List<PrismObject<ObjectType>> orgClosure = repositoryService.searchObjects(ObjectType.class, query, null, opResult);

AssertJUnit.assertEquals(4, orgClosure.size());
AssertJUnit.assertEquals(5, orgClosure.size());

for (PrismObject<ObjectType> u : orgClosure) {
LOGGER.info("CHILD ======> {}", ObjectTypeUtil.toShortString(u.asObjectable()));
Expand Down
Expand Up @@ -9,7 +9,7 @@
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.UserType;
import org.apache.commons.lang.ObjectUtils;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
Expand All @@ -35,16 +35,15 @@ public RQuery interpret(ObjectQuery query, Class<? extends ObjectType> type,
boolean countingObjects, Session session) throws QueryException {

//todo search some query library for query filter match

//todo implement as query library search, this is just a proof of concept [lazyman]
// if (query != null && query.getFilter() != null && query.getFilter() instanceof OrgFilter) {
// // http://stackoverflow.com/questions/10515391/oracle-equivalent-of-postgres-distinct-on
// // select distinct col1, first_value(col2) over (partition by col1 order by col2 asc) from tmp
// RQuery q = createOrgQuery((OrgFilter) query.getFilter(), type, countingObjects, session);
// if (q != null) {
// return q;
// }
// }
if (query != null && query.getFilter() != null && query.getFilter() instanceof OrgFilter) {
// http://stackoverflow.com/questions/10515391/oracle-equivalent-of-postgres-distinct-on
// select distinct col1, first_value(col2) over (partition by col1 order by col2 asc) from tmp
RQuery q = createOrgQuery((OrgFilter) query.getFilter(), type, countingObjects, session);
if (q != null) {
return q;
}
}

QueryInterpreter interpreter = new QueryInterpreter(repoConfiguration);
Criteria criteria = interpreter.interpret(query, type, options, prismContext, countingObjects, session);
Expand Down Expand Up @@ -72,11 +71,16 @@ private RQueryImpl createOrgQuery(OrgFilter filter, Class<? extends ObjectType>
}
sb.append("from ").append(ClassMapper.getHQLType(type)).append(" as o left join o.descendants as d ");
sb.append("where d.ancestorOid = :aOid ");
if (filter.getMaxDepth() != null) {
if (filter.getMaxDepth() == 1) {
sb.append("and d.depth = :maxDepth ");
if (filter.getMinDepth() != null || filter.getMaxDepth() != null) {
if (ObjectUtils.equals(filter.getMinDepth(), filter.getMaxDepth())) {
sb.append("and d.depth = :depth");
} else {
sb.append("and d.depth <=:maxDepth and d.depth>:minDepth ");
if (filter.getMinDepth() != null) {
sb.append("and d.depth > :minDepth ");
}
if (filter.getMaxDepth() != null) {
sb.append("and d.depth <= :maxDepth ");
}
}
}

Expand All @@ -88,64 +92,23 @@ private RQueryImpl createOrgQuery(OrgFilter filter, Class<? extends ObjectType>

Query query = session.createQuery(sb.toString());
query.setString("aOid", filter.getOrgRef().getOid());
if (filter.getMaxDepth() != null) {
if (filter.getMaxDepth() != 1) {
int minDepth = filter.getMinDepth() == null ? 1 : filter.getMinDepth();
query.setInteger("minDepth", minDepth);
if (filter.getMinDepth() != null || filter.getMaxDepth() != null) {
if (ObjectUtils.equals(filter.getMinDepth(), filter.getMaxDepth())) {
query.setInteger("depth", filter.getMinDepth());
} else {
if (filter.getMinDepth() != null) {
query.setInteger("minDepth", filter.getMinDepth());
}
if (filter.getMaxDepth() != null) {
query.setInteger("maxDepth", filter.getMaxDepth());
}
}
query.setInteger("maxDepth", filter.getMaxDepth());
}

if (!countingObjects) {
query.setResultTransformer(GetObjectResult.RESULT_TRANSFORMER);
}

// Query query = session.createQuery(
// "select o.fullObject,o.stringsCount,o.longsCount,o.datesCount,o.referencesCount,o.polysCount from "
// + ClassMapper.getHQLType(UserType.class) + " as o left join o.descendants as d "
// + "where d.ancestorOid=:aOid and d.depth <=:maxDepth and d.depth>:minDepth "
// + "group by o.fullObject,o.stringsCount,o.longsCount,o.datesCount,o.referencesCount,o.polysCount, o.name.orig "
// + "order by o.name.orig asc");





// SELECT o.fullobject,
// o.stringscount,
// o.longscount,
// o.datescount,
// o.referencescount,
// o.polyscount,
// o.name_orig
// FROM m_object o INNER JOIN m_org_closure c ON o.oid = c.descendant_oid
// WHERE ( c.ancestor_oid = '' AND c.depthvalue <=1 AND c.depthvalue >0)
// GROUP BY o.name_orig, o.fullobject,o.stringscount, o.longscount,
// o.datescount,
// o.referencescount,
// o.polyscount ORDER BY o.name_orig ASC
// Query query = null;
//
// session.createQuery(
// "select o.fullobject,o.stringscount,o.longscount,o.datescount,o.referencescount,o.polyscount from "
// + ClassMapper.getHQLType(type) + " as o left join o.descendants as d "
// + "where d.ancestorOid=:aOid and d.depth <=:maxDepth and d.depth>:midDepth "
// + "group by o.fullobject,o.stringscount,o.longscount,o.datescount,o.referencescount,o.polyscount "
// + "order by o.name.orig asc");

// SELECT o.fullobject,
// o.stringscount,
// o.longscount,
// o.datescount,
// o.referencescount,
// o.polyscount,
// o.name_orig
// FROM m_object o INNER JOIN m_org_closure c ON o.oid = c.descendant_oid
// WHERE ( c.ancestor_oid = '' AND c.depthvalue <=1 AND c.depthvalue >0)
// GROUP BY o.name_orig, o.fullobject,o.stringscount, o.longscount,
// o.datescount,
// o.referencescount,
// o.polyscount ORDER BY o.name_orig ASC

return new RQueryImpl(query);
}
}

0 comments on commit db28741

Please sign in to comment.