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

OO-4567: search by owner in question pool

parent fc27cf58
No related branches found
No related tags found
No related merge requests found
...@@ -300,6 +300,19 @@ public class QItemQueriesDAO { ...@@ -300,6 +300,19 @@ public class QItemQueriesDAO {
sb.and(); sb.and();
PersistenceHelper.appendFuzzyLike(sb, "item.topic", "topic", dbInstance.getDbVendor()); PersistenceHelper.appendFuzzyLike(sb, "item.topic", "topic", dbInstance.getDbVendor());
} }
if(StringHelper.containsNonWhitespace(params.getOwner())) {
sb.and()
.append(" exists (select mship.key from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as mship ")
.append(" inner join mship.identity as oIdent")
.append(" inner join oIdent.user as oUser")
.append(" where mship.securityGroup.key=item.ownerGroup.key and (");
PersistenceHelper.appendFuzzyLike(sb, "oUser.firstName", "owner", dbInstance.getDbVendor());
sb.append(" or ");
PersistenceHelper.appendFuzzyLike(sb, "oUser.lastName", "owner", dbInstance.getDbVendor());
sb.append(" or ");
PersistenceHelper.appendFuzzyLike(sb, "oIdent.name", "owner", dbInstance.getDbVendor());
sb.append(" ))");
}
if(StringHelper.containsNonWhitespace(params.getKeywords())) { if(StringHelper.containsNonWhitespace(params.getKeywords())) {
sb.and(); sb.and();
PersistenceHelper.appendFuzzyLike(sb, "item.keywords", "keywords", dbInstance.getDbVendor()); PersistenceHelper.appendFuzzyLike(sb, "item.keywords", "keywords", dbInstance.getDbVendor());
...@@ -427,6 +440,10 @@ public class QItemQueriesDAO { ...@@ -427,6 +440,10 @@ public class QItemQueriesDAO {
String fuzzySearch = PersistenceHelper.makeFuzzyQueryString(params.getTopic()); String fuzzySearch = PersistenceHelper.makeFuzzyQueryString(params.getTopic());
query.setParameter("topic", fuzzySearch); query.setParameter("topic", fuzzySearch);
} }
if(StringHelper.containsNonWhitespace(params.getOwner())) {
String fuzzySearch = PersistenceHelper.makeFuzzyQueryString(params.getOwner());
query.setParameter("owner", fuzzySearch);
}
if(StringHelper.containsNonWhitespace(params.getKeywords())) { if(StringHelper.containsNonWhitespace(params.getKeywords())) {
String fuzzySearch = PersistenceHelper.makeFuzzyQueryString(params.getKeywords()); String fuzzySearch = PersistenceHelper.makeFuzzyQueryString(params.getKeywords());
query.setParameter("keywords", fuzzySearch); query.setParameter("keywords", fuzzySearch);
......
...@@ -48,6 +48,7 @@ public class SearchQuestionItemParams implements Cloneable { ...@@ -48,6 +48,7 @@ public class SearchQuestionItemParams implements Cloneable {
private Identity author; private Identity author;
private String title; private String title;
private String topic; private String topic;
private String owner;
private String keywords; private String keywords;
private String coverage; private String coverage;
private String informations; private String informations;
...@@ -146,6 +147,14 @@ public class SearchQuestionItemParams implements Cloneable { ...@@ -146,6 +147,14 @@ public class SearchQuestionItemParams implements Cloneable {
this.topic = topic; this.topic = topic;
} }
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getKeywords() { public String getKeywords() {
return keywords; return keywords;
} }
...@@ -345,6 +354,9 @@ public class SearchQuestionItemParams implements Cloneable { ...@@ -345,6 +354,9 @@ public class SearchQuestionItemParams implements Cloneable {
if(StringHelper.containsNonWhitespace(searchString)) { if(StringHelper.containsNonWhitespace(searchString)) {
clone.searchString = searchString; clone.searchString = searchString;
} }
if(StringHelper.containsNonWhitespace(owner)) {
clone.owner = owner;
}
if(favoritOnly) { if(favoritOnly) {
clone.favoritOnly = favoritOnly; clone.favoritOnly = favoritOnly;
} }
......
...@@ -200,6 +200,7 @@ my.share=Meine Shares ...@@ -200,6 +200,7 @@ my.share=Meine Shares
new.item=Frage erstellen new.item=Frage erstellen
next=N\u00E4chste next=N\u00E4chste
numberOfRatings=Anzahl Bewertungen numberOfRatings=Anzahl Bewertungen
owner=Autor
pool.add.to.source=Fragen zum Pool "{0}" hinzuf\u00FCgen pool.add.to.source=Fragen zum Pool "{0}" hinzuf\u00FCgen
pool.key=ID pool.key=ID
pool.name=Name pool.name=Name
......
...@@ -200,6 +200,7 @@ my.share=My shares ...@@ -200,6 +200,7 @@ my.share=My shares
new.item=Create question new.item=Create question
next=Next next=Next
numberOfRatings=Number of ratings numberOfRatings=Number of ratings
owner=Author
pool.add.to.source=Add questions to pool "{0}" pool.add.to.source=Add questions to pool "{0}"
pool.key=ID pool.key=ID
pool.name=Name pool.name=Name
......
...@@ -334,6 +334,7 @@ public class ExtendedSearchController extends FormBasicController implements Ext ...@@ -334,6 +334,7 @@ public class ExtendedSearchController extends FormBasicController implements Ext
attributes.add(new SearchAttribute("classification.taxonomy.level", new TaxonomicFieldQueryParameter())); attributes.add(new SearchAttribute("classification.taxonomy.level", new TaxonomicFieldQueryParameter()));
attributes.add(new SearchAttribute("classification.taxonomic.path.incl", new TaxonomicPathQueryParameter())); attributes.add(new SearchAttribute("classification.taxonomic.path.incl", new TaxonomicPathQueryParameter()));
} }
attributes.add(new SearchAttribute("owner", new StringQueryParameter(AbstractOlatDocument.AUTHOR_FIELD_NAME)));
//educational //educational
if (qPoolSecurityCallback.canUseEducationalContext()) { if (qPoolSecurityCallback.canUseEducationalContext()) {
attributes.add(new SearchAttribute("educational.context", new ContextQueryParameter())); attributes.add(new SearchAttribute("educational.context", new ContextQueryParameter()));
...@@ -400,6 +401,8 @@ public class ExtendedSearchController extends FormBasicController implements Ext ...@@ -400,6 +401,8 @@ public class ExtendedSearchController extends FormBasicController implements Ext
searchParams.setTopic(val); searchParams.setTopic(val);
} else if(QItemDocument.KEYWORDS_FIELD.equals(docAttribute)) { } else if(QItemDocument.KEYWORDS_FIELD.equals(docAttribute)) {
searchParams.setKeywords(val); searchParams.setKeywords(val);
} else if(AbstractOlatDocument.AUTHOR_FIELD_NAME.equals(docAttribute)) {
searchParams.setOwner(val);
} else if(QItemDocument.COVERAGE_FIELD.equals(docAttribute)) { } else if(QItemDocument.COVERAGE_FIELD.equals(docAttribute)) {
searchParams.setCoverage(val); searchParams.setCoverage(val);
} else if(QItemDocument.ADD_INFOS_FIELD.equals(docAttribute)) { } else if(QItemDocument.ADD_INFOS_FIELD.equals(docAttribute)) {
...@@ -461,7 +464,7 @@ public class ExtendedSearchController extends FormBasicController implements Ext ...@@ -461,7 +464,7 @@ public class ExtendedSearchController extends FormBasicController implements Ext
private final LicenseSelectionConfig config; private final LicenseSelectionConfig config;
public LicenseQueryParameter() { public LicenseQueryParameter() {
super(QItemDocument.LICENSE_TYPE_FIELD_NAME); super(AbstractOlatDocument.LICENSE_TYPE_FIELD_NAME);
config = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler); config = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler);
} }
......
...@@ -327,6 +327,41 @@ public class QItemQueriesDAOTest extends OlatTestCase { ...@@ -327,6 +327,41 @@ public class QItemQueriesDAOTest extends OlatTestCase {
} }
} }
@Test
public void getItemsByOwner() {
//create an author with 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("QOwner-and-only-2-");
QuestionItem item = questionDao.createAndPersist(id, "NGC 7837", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH);
params.setOwner("Owner-and-only");
SortKey sortAsc = new SortKey(QuestionItemView.OrderBy.title.name(), true);
List<QuestionItemView> views = qItemQueriesDao.getItems(params, 0, -1, sortAsc);
Assert.assertNotNull(views);
Assert.assertFalse(views.isEmpty());
boolean match = views.stream().anyMatch(view -> item.getKey().equals(view.getKey()));
Assert.assertTrue(match);
}
@Test
public void getItemsByOwner_negativeTest() {
//create an author with 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("QOwn-29-");
QuestionItem item = questionDao.createAndPersist(id, "NGC 7838", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(item);
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH);
params.setOwner(UUID.randomUUID().toString());
SortKey sortAsc = new SortKey(QuestionItemView.OrderBy.title.name(), true);
List<QuestionItemView> views = qItemQueriesDao.getItems(params, 0, -1, sortAsc);
Assert.assertNotNull(views);
Assert.assertTrue(views.isEmpty());
}
@Test @Test
public void getItemsOfPool() { public void getItemsOfPool() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("Poolman-"); Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("Poolman-");
......
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