Skip to content
Snippets Groups Projects
Commit bfa342e4 authored by srosse's avatar srosse
Browse files

OO-3286: extends reach of the curriculum search to identifier of

curriculum elements
parent 4f5b5b57
No related branches found
No related tags found
No related merge requests found
......@@ -131,23 +131,6 @@ public class PersistenceHelper {
return true;
}
public static boolean appendGroupBy(StringBuilder sb, String dbRef, SortKey... orderBy) {
boolean appended = false;
if(orderBy != null && orderBy.length > 0 && orderBy[0] != null) {
sb.append(" order by ");
for(SortKey sort:orderBy) {
sb.append(dbRef).append(".").append(sort.getKey());
if(sort.isAsc()) {
sb.append(" asc ");
} else {
sb.append(" desc ");
}
appended = true;
}
}
return appended;
}
public static final void appendFuzzyLike(Appendable sb, String var, String key, String dbVendor) {
try {
if(dbVendor.equals("mysql")) {
......
......@@ -177,6 +177,18 @@ public class QueryBuilder implements Appendable {
return this;
}
public QueryBuilder likeFuzzy(String var, String key, String dbVendor) {
if(dbVendor.equals("mysql")) {
append(" ").append(var).append(" like :").append(key);
} else {
append(" lower(").append(var).append(") like :").append(key);
}
if(dbVendor.equals("oracle")) {
append(" escape '\\'");
}
return this;
}
public QueryBuilder appendAsc(boolean asc) {
if(asc) {
sb.append(" asc");
......
......@@ -105,15 +105,14 @@ public class CurriculumDAO {
}
public List<Curriculum> search(CurriculumSearchParameters params) {
StringBuilder sb = new StringBuilder(256);
QueryBuilder sb = new QueryBuilder(256);
sb.append("select cur from curriculum cur")
.append(" ").append(params.getOrganisations().isEmpty() ? "left" : "inner").append(" join fetch cur.organisation organis")
.append(" inner join fetch cur.group baseGroup");
boolean where = false;
if(!params.getOrganisations().isEmpty()) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append(" organis.key in (:organisationKeys)");
sb.and()
.append(" organis.key in (:organisationKeys)");
}
Long key = null;
......@@ -123,11 +122,15 @@ public class CurriculumDAO {
ref = params.getSearchString();
fuzzyRef = PersistenceHelper.makeFuzzyQueryString(ref);
where = PersistenceHelper.appendAnd(sb, where);
sb.append(" (cur.externalId=:ref or ");
PersistenceHelper.appendFuzzyLike(sb, "cur.displayName", "fuzzyRef", dbInstance.getDbVendor());
sb.append(" or ");
PersistenceHelper.appendFuzzyLike(sb, "cur.identifier", "fuzzyRef", dbInstance.getDbVendor());
sb.and()
.append(" (cur.externalId=:ref or ")
.likeFuzzy("cur.displayName", "fuzzyRef", dbInstance.getDbVendor())
.append(" or ")
.likeFuzzy("cur.identifier", "fuzzyRef", dbInstance.getDbVendor())
.append(" or exists (select curEl.key from curriculumelement as curEl where")
.append(" curEl.curriculum.key=cur.key and")
.likeFuzzy("curEl.identifier", "fuzzyRef", dbInstance.getDbVendor())
.append(")");
if(StringHelper.isLong(ref)) {
key = Long.valueOf(ref);
sb.append(" or cur.key=:curriculumKey");
......@@ -136,8 +139,8 @@ public class CurriculumDAO {
}
if(params.getManagerIdentity() != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append("exists (select membership.key from bgroupmember as membership")
sb.and()
.append("exists (select membership.key from bgroupmember as membership")
.append(" where membership.identity.key=:managerKey")
.append(" and (membership.group.key=baseGroup.key or organis.group.key=baseGroup.key)")
.append(" and role in ('").append(CurriculumRoles.curriculummanager).append("')")
......@@ -167,7 +170,7 @@ public class CurriculumDAO {
}
public List<CurriculumInfos> searchWithInfos(CurriculumSearchParameters params) {
StringBuilder sb = new StringBuilder(256);
QueryBuilder sb = new QueryBuilder(512);
sb.append("select cur,")
.append(" (select count(curElement.key) from curriculumelement curElement")
.append(" where curElement.curriculum.key=cur.key")
......@@ -176,10 +179,8 @@ public class CurriculumDAO {
.append(" inner join fetch cur.group baseGroup")
.append(" ").append(params.getOrganisations().isEmpty() ? "left" : "inner").append(" join fetch cur.organisation organis");
boolean where = false;
if(!params.getOrganisations().isEmpty()) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append(" organis.key in (:organisationKeys)");
sb.and().append(" organis.key in (:organisationKeys)");
}
Long key = null;
......@@ -189,11 +190,15 @@ public class CurriculumDAO {
ref = params.getSearchString();
fuzzyRef = PersistenceHelper.makeFuzzyQueryString(ref);
where = PersistenceHelper.appendAnd(sb, where);
sb.append(" (cur.externalId=:ref or ");
PersistenceHelper.appendFuzzyLike(sb, "cur.displayName", "fuzzyRef", dbInstance.getDbVendor());
sb.append(" or ");
PersistenceHelper.appendFuzzyLike(sb, "cur.identifier", "fuzzyRef", dbInstance.getDbVendor());
sb.and()
.append(" (cur.externalId=:ref or ")
.likeFuzzy("cur.displayName", "fuzzyRef", dbInstance.getDbVendor())
.append(" or ")
.likeFuzzy("cur.identifier", "fuzzyRef", dbInstance.getDbVendor())
.append(" or exists (select curEl.key from curriculumelement as curEl where")
.append(" curEl.curriculum.key=cur.key and")
.likeFuzzy("curEl.identifier", "fuzzyRef", dbInstance.getDbVendor())
.append(")");
if(StringHelper.isLong(ref)) {
key = Long.valueOf(ref);
sb.append(" or cur.key=:curriculumKey");
......@@ -202,8 +207,8 @@ public class CurriculumDAO {
}
if(params.getManagerIdentity() != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append("exists (select membership.key from bgroupmember as membership")
sb.and()
.append("exists (select membership.key from bgroupmember as membership")
.append(" where membership.identity.key=:managerKey")
.append(" and (membership.group.key=baseGroup.key or membership.group.key=organis.group.key)")
.append(" and role in ('").append(CurriculumRoles.curriculummanager).append("','").append(OrganisationRoles.administrator).append("','").append(OrganisationRoles.principal).append("')")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment