import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.ReaderRelation;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.Study;
_userDAO.create(otherUser);
User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
_userDAO.create(thirdUser);
+ User reader = TestEntitiesGenerator.getTestUser("readerUser");
+ _userDAO.create(reader);
- // ============== STUDY 0: Private : goodUser
+ // ============== STUDY 0: Private : goodUser : readerUser is reader : otherUser is contributor
// Create private study
Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
aStudy.setTitle("0.This is private study");
+ aStudy.addRelation(new ReaderRelation(aStudy, reader));
+ aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
Long privateStudyId = _studyDAO.create(aStudy);
// Add simulation context to the study 0
aStudy.setReference("TEST_REF");
Long refStudyId = _studyDAO.create(aStudy);
- // ============== STUDY 3: Private : inDraft : thirdUser : otherUser is contributor
+ // ============== STUDY 3: Private : inDraft : thirdUser : otherUser is reviewer
// Create private study of third user with otherUser as a reviewer
aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
aStudy.setTitle("3.This is a private study of third user");
Assert.assertEquals(res.size(), 1);
Assert.assertEquals(res.get(0).getIndex(), titleStudyId);
- // Search for other logged in study contributor
+ // Search for logged in study contributor otherUser
filter = new StudySearchFilterDTO();
filter.setConnectedUserId(otherUser.getIndex());
res = _searchService.selectStudiesWhere(filter);
Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 4);
+ Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // OtherUser is contributor in this study
+ Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
+ Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
+ Assert.assertEquals(res.get(3).getIndex(), reviewStudyId); // OtherUser is reviewer in this study
+
+ // Search for logged in study reader readerUser
+ filter = new StudySearchFilterDTO();
+ filter.setConnectedUserId(reader.getIndex());
+ res = _searchService.selectStudiesWhere(filter);
+ Assert.assertNotNull(res);
Assert.assertEquals(res.size(), 3);
- Assert.assertEquals(res.get(0).getIndex(), refStudyId); // Public study
- Assert.assertEquals(res.get(1).getIndex(), titleStudyId); // Public study
- Assert.assertEquals(res.get(2).getIndex(), reviewStudyId); // OtherUser is reviewer in this study
+ Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // readerUser is reader in this study
+ Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
+ Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
- // Search for logged in study contributor
+ // Search for logged in study contributor goodUser
filter = new StudySearchFilterDTO();
filter.setConnectedUserId(goodUser.getIndex());
res = _searchService.selectStudiesWhere(filter);
Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
- // Search for logged in study contributor
- // filtered by state
+ // Search for logged in study contributor otherUser filtered by Draft state
filter = new StudySearchFilterDTO();
filter.setConnectedUserId(otherUser.getIndex());
filter.setState(ProgressState.inDRAFT);
_userDAO.create(otherUser);
User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
_userDAO.create(thirdUser);
+ User reader = TestEntitiesGenerator.getTestUser("readerUser");
+ _userDAO.create(reader);
KnowledgeElementType ktype1 = new KnowledgeElementType("testKType1");
KnowledgeElementType ktype2 = new KnowledgeElementType("testKType2");
ktype2.setState(ProgressState.inWORK);
_knowledgeElementDAO.create(kelm22);
ht.flush();
- // ============== STUDY 3: Private : thirdUser : otherUser is contributor
+ // ============== STUDY 3: Private : thirdUser : otherUser is reviewer
// Create private study of third user with otherUser as a reviewer
aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
aStudy.setTitle("3.This is a private study of third user");
_knowledgeElementDAO.create(kelm31);
_knowledgeElementDAO.create(kelm32);
ht.flush();
+
+ // ============== STUDY 4: Private : thirdUser : otherUser is contributor : readerUser is reader
+ // Create private study of third user with otherUser as a reviewer
+ aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
+ aStudy.setTitle("4.This is a private study of third user");
+ aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
+ aStudy.addRelation(new ReaderRelation(aStudy, reader));
+ _studyDAO.create(aStudy);
+
+ ht.flush();
+ // Add a scenario to the study 4
+ scen = TestEntitiesGenerator.getTestScenario(aStudy);
+ _scenarioDAO.create(scen);
+ ht.flush();
+
+ // Add knowledge elements to the scenario
+ KnowledgeElement kelm41 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype1, "TestKelm41 title");
+ KnowledgeElement kelm42 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype2, "TestKelm42 title");
+ _knowledgeElementDAO.create(kelm41);
+ _knowledgeElementDAO.create(kelm42);
+ ht.flush();
+
calend = java.util.Calendar.getInstance();
calend.roll(Calendar.DATE, true);
Date afterCreation = calend.getTime();
filter.setConnectedUserId(otherUser.getIndex());
res = _searchService.selectKnowledgeElementsWhere(filter);
Assert.assertNotNull(res);
- Assert.assertEquals(res.size(), 6);
+ Assert.assertEquals(res.size(), 8);
Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle());
Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle());
+ Assert.assertEquals(res.get(6).getTitle(), kelm41.getTitle());
+ Assert.assertEquals(res.get(7).getTitle(), kelm42.getTitle());
- // Search for logged in study contributor
+ // Search for logged in goodUser
filter = new KnowledgeSearchFilterDTO();
filter.setConnectedUserId(goodUser.getIndex());
res = _searchService.selectKnowledgeElementsWhere(filter);
Assert.assertEquals(res.get(4).getTitle(), kelm21.getTitle());
Assert.assertEquals(res.get(5).getTitle(), kelm22.getTitle());
+ // Search for logged in study contributor otherUser
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setConnectedUserId(otherUser.getIndex());
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 8);
+ Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
+ Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
+ Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
+ Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
+ Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle());
+ Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle());
+ Assert.assertEquals(res.get(6).getTitle(), kelm41.getTitle());
+ Assert.assertEquals(res.get(7).getTitle(), kelm42.getTitle());
+
+ // Search for logged in study reader readerUser
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setConnectedUserId(reader.getIndex());
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 6);
+ Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
+ Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
+ Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
+ Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
+ Assert.assertEquals(res.get(4).getTitle(), kelm41.getTitle());
+ Assert.assertEquals(res.get(5).getTitle(), kelm42.getTitle());
+
// Search by title contents
filter = new KnowledgeSearchFilterDTO();
filter.setWords("TestKelm22");