* @return true if updating succeeded
*/
protected boolean update(final KnowledgeElement knowledgeElement) {
- try {
+// try {
getKnowledgeElementDAO().update(knowledgeElement);
- getIndexService().update(knowledgeElement);
+// getIndexService().update(knowledgeElement);
return true;
- } catch (Exception error) {
- LOG.error("Unable to re-index the knowledge '"
- + knowledgeElement.getIndex() + "', reason:", error);
- return false;
- }
+// } catch (Exception error) {
+// LOG.error("Unable to re-index the knowledge '"
+// + knowledgeElement.getIndex() + "', reason:", error);
+// return false;
+// }
}
/**
throws MissedPropertyException, InvalidPropertyException,
MultiplyDefinedException {
KnowledgeElement kelm = null;
- try {
+// try {
long aScenarioId = aScenarioDTO.getIndex();
if (LOG.isDebugEnabled()) {
LOG.debug("Add a knowledge element to the scenario #"
// all study actors durng reindexing.
getStudyService().loadWorkflow(aScenario.getOwnerStudy());
- // Update the lucene index of knowledge elements.
- getIndexService().add(kelm);
+// // Update the lucene index of knowledge elements.
+// getIndexService().add(kelm);
if (LOG.isDebugEnabled()) {
LOG.debug("A knowledge element #" + kelm.getIndex()
+ " is added to the scenario #" + aScenario.getIndex());
}
- } catch (IOException error) {
- LOG.error("Unable to index the knowedge element '"
- + kelm.getIndex() + "', reason:", error);
- kelm = null;
- }
+// } catch (IOException error) {
+// LOG.error("Unable to index the knowedge element '"
+// + kelm.getIndex() + "', reason:", error);
+// kelm = null;
+// }
return kelm;
}
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.Study;
import org.splat.service.dto.ImportedStudyDTO;
+import org.splat.service.dto.KnowledgeSearchFilterDTO;
import org.splat.service.dto.Proxy;
import org.splat.service.dto.StudySearchFilterDTO;
*/
void reindexStudies(String[] ridlist);
+ /**
+ * Find knowledge elements with given properties.
+ *
+ * @param filter
+ * search filter parameters
+ * @return the list of found knowledge elements as proxiy results of lucene search
+ */
+ List<Proxy> selectKnowledgeElementsWhere(
+ final KnowledgeSearchFilterDTO filter);
+
/**
* Find knowledge elements with given properties.
*
/**
* Find studies with given properties.
*
- * @param allCriteria
- * if true then search for all criteria (AND), otherwise search for any criteria
- * @param allContexts
- * if true then search for all simulation contexts (AND), otherwise search for any simulation contexts
- * @param sprop
+ * @param filter
* search filter parameters
* @return the list of found studies as proxy results
*/
import java.util.List;
import org.apache.log4j.Logger;
+import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanFilter;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.Visibility;
+import org.splat.dal.dao.som.KnowledgeElementDAO;
import org.splat.dal.dao.som.StudyDAO;
import org.splat.service.dto.ImportedStudyDTO;
+import org.splat.service.dto.KnowledgeSearchFilterDTO;
import org.splat.service.dto.Proxy;
+import org.splat.service.dto.SearchFilterDTO;
import org.splat.service.dto.StudyDTO;
import org.splat.service.dto.StudySearchFilterDTO;
import org.splat.service.technical.IndexService;
* Injected study DAO.
*/
private StudyDAO _studyDAO;
+ /**
+ * Injected knowledge element DAO.
+ */
+ private KnowledgeElementDAO _knowledgeElementDAO;
/**
* Get a list of studies which are currently not presented in the lucene index.
}
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.service.dto.KnowledgeSearchFilterDTO)
+ */
+ public List<Proxy> selectKnowledgeElementsWhere(
+ final KnowledgeSearchFilterDTO filter) {
+ List<Proxy> result = new ArrayList<Proxy>();
+
+ // Search matching all criteria
+ DetachedCriteria query = DetachedCriteria.forClass(
+ KnowledgeElement.class, "kelm");
+ query.createAlias("kelm.owner", "scen", Criteria.INNER_JOIN)
+ .createCriteria("scen.owner", "study", Criteria.INNER_JOIN)
+ .add(visibleStudyFilter(filter));
+
+ // Creation of the query
+ Junction topJunction = initQuery(filter);
+
+ addByWordsCriteria(topJunction, filter);
+
+ List<SimulationContext> context = filter.getSimContexts();
+ if (context != null && (!context.isEmpty())) {
+ // Get only studies which have given contexts
+ query.createAlias("study.contex", "ctx", Criteria.INNER_JOIN);
+ Junction critctx;
+ if (filter.isMatchAllContexts()) { // AND
+ critctx = Restrictions.conjunction();
+ } else { // OR
+ critctx = Restrictions.disjunction();
+ }
+ for (SimulationContext seltext : context) {
+ // (simctxType = seltext.getType() AND simctxValue = seltext.getValue())
+ critctx.add(Restrictions.and(Restrictions.eq("ctx.value",
+ seltext.getValue()), Restrictions.eq("ctx.type",
+ seltext.getType())));
+
+ }
+ topJunction.add(critctx);
+ }
+
+ query.add(topJunction);
+ // Group by study
+ query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
+ // Creation of the sort criteria
+ query.addOrder(Order.asc("title"));
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Searching knowledge elements: \"" + query.toString());
+ }
+
+ // Search
+ List<KnowledgeElement> found = getKnowledgeElementDAO()
+ .getFilteredList(query);
+
+ // Construction of the result list
+ for (KnowledgeElement kelm : found) {
+ result.add(new StudyDTO(kelm.getIndex(), kelm.getReference(), kelm
+ .getProgressState(), kelm.getTitle(), kelm.getAuthor()
+ .getDisplayName()));
+ }
+ return result;
+ }
+
+ /**
+ * Add search criteria for filtering by title contents.
+ *
+ * @param topJunction
+ * the search condition to be appended
+ * @param filter
+ * the criteria
+ */
+ private void addByWordsCriteria(final Junction topJunction,
+ final SearchFilterDTO filter) {
+ String title = filter.getWords(); // Title
+ if (title != null && (!title.isEmpty())) {
+ // Look for given words in titles
+ Junction critext;
+ if (filter.isMatchAllCriteria()) { // AND
+ critext = Restrictions.conjunction();
+ } else { // OR
+ critext = Restrictions.disjunction();
+ }
+
+ String[] word = title.split(" ");
+ for (int j = 0; j < word.length; j++) {
+ critext.add(Restrictions.like("title", "%" + word[j] + "%"));
+ }
+ topJunction.add(critext);
+ }
+ }
+
/**
* {@inheritDoc}
*
* @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.dal.bo.som.KnowledgeElement.Properties[])
*/
+ @Deprecated
public List<Proxy> selectKnowledgeElementsWhere(
final KnowledgeElement.Properties... kprop) {
List<Proxy> result = new ArrayList<Proxy>();
}
if (LOG.isInfoEnabled()) {
LOG.info("Searching knowledges by Lucene query \""
- + fulquery.toString() + "\".");
+ + fulquery.toString());
}
// Creation of the knowledge filter
BooleanFilter filter = new BooleanFilter();
/**
* {@inheritDoc}
*
- * @see org.splat.service.SearchService#selectStudiesWhere(org.splat.dal.bo.som.Study.Properties[])
+ * @see org.splat.service.SearchService#selectStudiesWhere(org.splat.service.dto.StudySearchFilterDTO)
*/
public List<Proxy> selectStudiesWhere(final StudySearchFilterDTO filter) {
List<Proxy> result = new ArrayList<Proxy>();
DetachedCriteria query = DetachedCriteria
- .forClass(Study.class, "study");
+ .forClass(Study.class, "study").add(visibleStudyFilter(filter));
// Creation of the query
Junction topJunction = initQuery(filter);
- String title = filter.getWords(); // Title
- if (title != null && (!title.isEmpty())) {
- // Look for given words in study titles
- Junction critext;
- if (filter.isMatchAllCriteria()) { // AND
- critext = Restrictions.conjunction();
- } else { // OR
- critext = Restrictions.disjunction();
- }
-
- String[] word = title.split(" ");
- for (int j = 0; j < word.length; j++) {
- critext.add(Restrictions.like("title", "%" + word[j] + "%"));
- }
- topJunction.add(critext);
- }
+ addByWordsCriteria(topJunction, filter);
List<SimulationContext> context = filter.getSimContexts();
if (context != null && (!context.isEmpty())) {
query.addOrder(Order.asc("title"));
if (LOG.isInfoEnabled()) {
- LOG.info("Searching studies: \"" + query.toString() + "\".");
+ LOG.info("Searching studies: \"" + query.toString());
}
// Search
addDatesCriteria(topJunction, filter);
+ // Filter by study author
long authorId = Long.valueOf(filter.getAuthor());
- if (authorId > 0) { // Author
+ if (authorId > 0) {
topJunction.add(Restrictions.eq("manager.rid", authorId));
}
+ return topJunction;
+ }
+
+ /**
+ * Initialize query with base criteria.
+ *
+ * @param filter
+ * the criteria
+ * @return top junction of the search filter
+ */
+ private Junction initQuery(final KnowledgeSearchFilterDTO filter) {
+ Junction topJunction;
+ if (filter.isMatchAllCriteria()) { // AND
+ topJunction = Restrictions.conjunction();
+ } else { // OR
+ topJunction = Restrictions.disjunction();
+ }
+
+ // Filter by knowledge type
+ long ktypeId = Long.valueOf(filter.getKtype());
+ if (ktypeId > 0) {
+ topJunction.add(Restrictions.eq("kelm.type.rid", ktypeId));
+ }
+
+ String refid = filter.getReference(); // Reference
+ if (refid != null && !refid.isEmpty()) {
+ long id = Long.valueOf(refid.replaceAll("^KE(0)*", ""));
+ if (id > 0) {
+ topJunction.add(Restrictions.eq("kelm.rid", id));
+ }
+ }
+
+ addCreationDateCriteria(topJunction, filter, "date");
+
+ // Filter by knowledge author
+ long authorId = Long.valueOf(filter.getAuthor());
+ if (authorId > 0) {
+ topJunction.add(Restrictions.eq("kelm.author.rid", authorId));
+ }
+
+ return topJunction;
+ }
+
+ /**
+ * Filter for visible studies.
+ *
+ * @param filter
+ * search criteria
+ * @return search condition for studies to get only visible studies
+ */
+ private Junction visibleStudyFilter(final SearchFilterDTO filter) {
+ Junction topJunction;
+ if (filter.isMatchAllCriteria()) { // AND
+ topJunction = Restrictions.conjunction();
+ } else { // OR
+ topJunction = Restrictions.disjunction();
+ }
+
+ // Filter by connected user
long actorId = filter.getConnectedUserId(); // Contributor, Reviewer or Approver
if (actorId > 0) {
// User is loggen in - show public studies and studies where he is participating
Visibility.PUBLIC)));
} else {
// User is not logged in - show only public studies
- topJunction.add(Restrictions.eq("visibility", Visibility.PUBLIC));
+ topJunction.add(Restrictions.eq("study.visibility",
+ Visibility.PUBLIC));
}
return topJunction;
}
private void addDatesCriteria(final Junction topJunction,
final StudySearchFilterDTO filter) {
// Filter by creation date
- if (filter.getCreatedAfter() != null) {
- topJunction.add(Restrictions
- .gt("credate", filter.getCreatedAfter()));
- }
- if (filter.getCreatedBefore() != null) {
- topJunction.add(Restrictions.lt("credate", filter
- .getCreatedBefore()));
- }
+ addCreationDateCriteria(topJunction, filter, "credate");
// Filter by modification date
if (filter.getUpdatedAfter() != null) {
topJunction.add(Restrictions
}
+ /**
+ * Add search criteria by dates to the junction filter condition.
+ *
+ * @param topJunction
+ * the junction filter condition
+ * @param filter
+ * search criteria
+ */
+ private void addCreationDateCriteria(final Junction topJunction,
+ final SearchFilterDTO filter, final String propName) {
+ // Filter by creation date
+ if (filter.getCreatedAfter() != null) {
+ topJunction.add(Restrictions
+ .gt(propName, filter.getCreatedAfter()));
+ }
+ if (filter.getCreatedBefore() != null) {
+ topJunction.add(Restrictions.lt(propName, filter
+ .getCreatedBefore()));
+ }
+ }
+
/**
* {@inheritDoc}
*
}
if (LOG.isInfoEnabled()) {
LOG.info("Searching studies by Lucene query \""
- + fulquery.toString() + "\".");
+ + fulquery.toString());
}
// Creation of the studies filter
BooleanFilter filter = new BooleanFilter();
*/
private IndexService getIndex() throws IOException {
IndexService lucin = getIndexService();
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()))) {
+ IndexWriter.unlock(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()));
+ }
if (!lucin.exists()) {
lucin.create(); // Happens when re-indexing all studies
}
public void setStudyDAO(final StudyDAO studyDAO) {
_studyDAO = studyDAO;
}
+
+ /**
+ * Get the knowledgeElementDAO.
+ *
+ * @return the knowledgeElementDAO
+ */
+ public KnowledgeElementDAO getKnowledgeElementDAO() {
+ return _knowledgeElementDAO;
+ }
+
+ /**
+ * Set the knowledgeElementDAO.
+ *
+ * @param knowledgeElementDAO
+ * the knowledgeElementDAO to set
+ */
+ public void setKnowledgeElementDAO(
+ final KnowledgeElementDAO knowledgeElementDAO) {
+ _knowledgeElementDAO = knowledgeElementDAO;
+ }
}
/**
* Step service implementation.
- *
+ *
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class StepServiceImpl implements StepService {
* Injected user DAO.
*/
private UserDAO _userDAO;
-
-
+
+
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties)
*/
@Override
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
*/
@Override
/**
* Update lucene index of knowledge elements of a scenario or a study which the given step is related to.
- *
+ *
* @param aStep
* the step (activity)
*/
} else {
scenarii = aStep.getOwnerStudy().getScenarii();
}
- try {
+// try {
for (int i = 0; i < scenarii.length; i++) {
Scenario scene = scenarii[i];
List<KnowledgeElement> knelm = scene.getAllKnowledgeElements();
for (Iterator<KnowledgeElement> j = knelm.iterator(); j
.hasNext();) {
KnowledgeElement kelm = j.next();
- getIndexService().update(kelm);
+// getIndexService().update(kelm);
}
updateScenarioIndex(scene);
}
- } catch (Exception error) {
- LOG.error("Unable to re-index Knowledge Elements, reason:", error);
- }
+// } catch (Exception error) {
+// LOG.error("Unable to re-index Knowledge Elements, reason:", error);
+// }
}
/**
* Update lucene index for knowledge elements of the scenario.
- *
+ *
* @param scene
* the scenario
* @throws IOException
* if can't update lucene index
*/
- private void updateScenarioIndex(final Scenario scene) throws IOException {
+ private void updateScenarioIndex(final Scenario scene) /*throws IOException*/ {
if (scene.getUcase() == null) {
for (Iterator<KnowledgeElement> i = scene.getKnowledgeElements()
.iterator(); i.hasNext();) {
break;
}
}
- getIndexService().update(scene.getUcase());
+// getIndexService().update(scene.getUcase());
}
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
*/
@Override
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
*/
@Override
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
*/
@Override
/**
* Create a new version of a document in the given study step.
- *
+ *
* @param aStep
* the study step
* @param base
/**
* Create a new version of a document in the given study step.
- *
+ *
* @param aStep
* the study step
* @param base
/**
* Create a new version of a document in the given study step.
- *
+ *
* @param aStep
* the study step
* @param base
/**
* Get document types which are applicable for the given study step (activity).
- *
+ *
* @param aStep
* the study step
* @return the list of document types
/**
* Add a document publication to the given step.
- *
+ *
* @param aStep
* the target study step
* @param newdoc
/**
* Remove a document publication from the given step.
- *
+ *
* @param aStep
* the study step
* @param oldoc
}
}
return res;
-
-
}
-
+
/**
* {@inheritDoc}
*
comment.setId(resultKey);
}
- /**
+ /**
* {@inheritDoc}
* @see org.splat.service.StepService#getStepComments(org.splat.som.Step)
*/
}
return commentDTOs;
}
-
- /**
+
+ /**
* {@inheritDoc}
* @see org.splat.service.StepService#removeStepComment(long)
*/
/**
* Get the documentService.
- *
+ *
* @return the documentService
*/
public DocumentService getDocumentService() {
/**
* Set the documentService.
- *
+ *
* @param documentService
* the documentService to set
*/
/**
* Get the simulationContextService.
- *
+ *
* @return the simulationContextService
*/
public SimulationContextService getSimulationContextService() {
/**
* Set the simulationContextService.
- *
+ *
* @param simulationContextService
* the simulationContextService to set
*/
/**
* Get the documentDAO.
- *
+ *
* @return the documentDAO
*/
public DocumentDAO getDocumentDAO() {
/**
* Set the documentDAO.
- *
+ *
* @param documentDAO
* the documentDAO to set
*/
/**
* Get the simulationContextDAO.
- *
+ *
* @return the simulationContextDAO
*/
public SimulationContextDAO getSimulationContextDAO() {
/**
* Set the simulationContextDAO.
- *
+ *
* @param simulationContextDAO
* the simulationContextDAO to set
*/
/**
* Get the projectElementDAO.
- *
+ *
* @return the projectElementDAO
*/
public ProjectElementDAO getProjectElementDAO() {
/**
* Set the projectElementDAO.
- *
+ *
* @param projectElementDAO
* the projectElementDAO to set
*/
/**
* Get the indexService.
- *
+ *
* @return the indexService
*/
public IndexService getIndexService() {
/**
* Set the indexService.
- *
+ *
* @param indexService
* the indexService to set
*/
/**
* Get the fileDAO.
- *
+ *
* @return the fileDAO
*/
public FileDAO getFileDAO() {
/**
* Set the fileDAO.
- *
+ *
* @param fileDAO
* the fileDAO to set
*/
/**
* Get the documentTypeService.
- *
+ *
* @return the documentTypeService
*/
public DocumentTypeService getDocumentTypeService() {
/**
* Set the documentTypeService.
- *
+ *
* @param documentTypeService
* the documentTypeService to set
*/
/**
* Get the versionsRelationDAO.
- *
+ *
* @return the versionsRelationDAO
*/
public VersionsRelationDAO getVersionsRelationDAO() {
/**
* Set the versionsRelationDAO.
- *
+ *
* @param versionsRelationDAO
* the versionsRelationDAO to set
*/
/**
* Get project settings.
- *
+ *
* @return Project settings service
*/
private ProjectSettingsService getProjectSettings() {
return _projectSettings;
}
-
+
/**
* Set project settings service.
- *
+ *
* @param projectSettingsService
* project settings service
*/
final ProjectSettingsService projectSettingsService) {
_projectSettings = projectSettingsService;
}
-
+
/**
* Get the stepCommentAttributeDAO.
* @return the stepCommentAttributeDAO
public void setUserDAO(final UserDAO userDAO) {
_userDAO = userDAO;
}
-
+
/**
* Get the publicationDAO.
*
import java.util.Scanner;
import java.util.Set;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.store.FSDirectory;
import org.hibernate.criterion.Restrictions;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.splat.dal.bo.som.DescriptionAttribute;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.IDBuilder;
-import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.Publication;
-import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.Study;
-import org.splat.dal.bo.som.Study.Properties;
import org.splat.dal.bo.som.ValidationCycle;
-import org.splat.dal.bo.som.ValidationCycle.Actor;
import org.splat.dal.bo.som.ValidationCycleRelation;
import org.splat.dal.bo.som.ValidationStep;
import org.splat.dal.bo.som.Visibility;
+import org.splat.dal.bo.som.Study.Properties;
+import org.splat.dal.bo.som.ValidationCycle.Actor;
import org.splat.dal.dao.som.DescriptionAttributeDAO;
import org.splat.dal.dao.som.DocumentDAO;
import org.splat.dal.dao.som.IDBuilderDAO;
* Injected user service.
*/
private UserService _userService;
-
+
/**
* Injected publication DAO.
*/
*
* @see org.splat.service.StudyService#selectStudy(long)
*/
- @Override
@Transactional
public Study selectStudy(final long index) {
Study result = getStudyDAO().get(index);
*
* @see org.splat.service.StudyService#createStudy(org.splat.dal.bo.som.Study.Properties)
*/
- @Override
@Transactional
public Study createStudy(final Study.Properties sprop)
throws MissedPropertyException, InvalidPropertyException,
buildReference(study);
getStudyDAO().create(study);
- try {
- IndexService lucin = getIndex();
- lucin.add(study);
- } catch (IOException error) {
- LOG.error("Unable to index the study '" + study.getIndex()
- + "', reason:", error);
- // Continue and try to index later
- }
+// try {
+// IndexService lucin = getIndex();
+// lucin.add(study);
+// } catch (IOException error) {
+// LOG.error("Unable to index the study '" + study.getIndex()
+// + "', reason:", error);
+// // Continue and try to index later
+// }
return study;
}
*
* @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext.Properties)
*/
- @Override
@Transactional
public SimulationContext addProjectContext(final Study aStudy,
final SimulationContext.Properties cprop)
*
* @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
*/
- @Override
@Transactional
public SimulationContext addProjectContext(final Study aStudy,
final SimulationContext context) {
*
* @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User)
*/
- @Override
public boolean addContributor(final Study aStudy, final User user) {
List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
for (Iterator<User> i = contributor.iterator(); i.hasNext();) {
* @see #isPublic()
* @see Publication#approve(Date)
*/
- @Override
public boolean moveToReference(final Study aStudy) {
if (aStudy.getProgressState() != ProgressState.APPROVED) {
return false;
*
* @see org.splat.service.StudyService#update(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Study.Properties)
*/
- @Override
public boolean update(final Study aStudy, final Properties sprop)
throws InvalidPropertyException {
if (sprop.getTitle() != null) {
*
* @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[])
*/
- @Override
public boolean removeContributor(final Study aStudy, final User... users) {
List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
Boolean done = false;
*
* @see org.splat.service.StudyService#removeProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
*/
- @Override
public boolean removeProjectContext(final Study aStudy,
final SimulationContext context) {
boolean done = getStepService().removeSimulationContext(
* @see org.splat.service.StudyService#setValidationCycle(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.DocumentType,
* org.splat.dal.bo.som.ValidationCycle.Properties)
*/
- @Override
@Transactional
public void setValidationCycle(final Study aStudyDTO, final DocumentType type,
final ValidationCycle.Properties vprop) {
* a study to demote
* @return true if the demotion succeeded.
*/
- @Override
public boolean demote(final Study aStudy) {
if (aStudy.getProgressState() == ProgressState.inCHECK) {
aStudy.setProgressState(ProgressState.inDRAFT);
*
* @see org.splat.service.StudyService#generateLocalIndex(org.splat.dal.bo.som.Study)
*/
- @Override
@Transactional
public int generateLocalIndex(final Study aStudy) {
aStudy.setLastLocalIndex(aStudy.getLastLocalIndex() + 1);
* a study to promote
* @return true if the demotion succeeded.
*/
- @Override
@Transactional
public boolean promote(final Study aStudy) {
if (aStudy.getProgressState() == ProgressState.inWORK) {
* @return true if the move succeeded.
* @see #isPublic()
*/
- @Override
@Transactional
public boolean moveToPublic(final Study aStudy) {
boolean isOk = false;
* a study to move
* @return true if the move succeeded.
*/
- @Override
@Transactional
public boolean moveToPrivate(final Study aStudy) {
boolean isOk = false;
try {
getStudyDAO().merge(aStudy); // Update of relational base
setShortCuts(aStudy); // RKV: initialize transient actors set
- getIndex().update(aStudy); // Update of Lucene index
+ //RKV: getIndex().update(aStudy); // Update of Lucene index
isOk = true;
} catch (Exception e) {
LOG.error("STD-000001", e, aStudy.getIndex(), e.getMessage());
* @return true if reindexing succeeded
*/
private boolean updateKnowledgeElementsIndex(final Study aStudy) {
- boolean isOk = false;
- try {
- IndexService lucin = getIndex();
-
- for (Iterator<Scenario> i = aStudy.getScenariiList().iterator(); i
- .hasNext();) {
- Scenario scene = i.next();
- for (Iterator<KnowledgeElement> j = scene
- .getAllKnowledgeElements().iterator(); j.hasNext();) {
- KnowledgeElement kelm = j.next();
- lucin.update(kelm);
- }
- }
- isOk = true;
- } catch (Exception error) {
- LOG.error("Unable to re-index Knowledge Elements, reason:",
- error);
- }
- return isOk;
+// boolean isOk = false;
+// try {
+// IndexService lucin = getIndex();
+//
+// for (Iterator<Scenario> i = aStudy.getScenariiList().iterator(); i
+// .hasNext();) {
+// Scenario scene = i.next();
+// for (Iterator<KnowledgeElement> j = scene
+// .getAllKnowledgeElements().iterator(); j.hasNext();) {
+// KnowledgeElement kelm = j.next();
+// lucin.update(kelm);
+// }
+// }
+// isOk = true;
+// } catch (Exception error) {
+// LOG.error("Unable to re-index Knowledge Elements, reason:",
+// error);
+// }
+// return isOk;
+ return true;
}
/**
*/
private IndexService getIndex() throws IOException {
IndexService lucin = getIndexService();
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()))) {
+ IndexWriter.unlock(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()));
+ }
if (!lucin.exists()) {
lucin.create(); // Happens when re-indexing all studies
}
* the study
* @return the unmodifiable not null transient list of contributors of this study
*/
- @Override
public List<User> getContributors(final Study aStudy) {
if (aStudy.getContributor() == null) {
setShortCuts(aStudy);
* the document type being subject of validation
* @return the validation cycle of the document, or null if not defined.
*/
- @Override
public ValidationCycle getValidationCycleOf(final Study aStudy,
final DocumentType type) {
if (aStudy.getValidationCycles() == null || aStudy.getValidationCycles().isEmpty()) {
* @return true if the given user is actor of this study.
* @see #getActors()
*/
- @Override
public boolean hasActor(final Study aStudy, final User user) {
if (user == null) {
return false;
* @return true if the given user is actor of this study.
* @see #getContributors()
*/
- @Override
public boolean isStaffedBy(final Study aStudy, final User user) {
if (user == null) {
return false;
* @param aStudy
* the study
*/
- @Override
public void loadWorkflow(final Study aStudy) {
setShortCuts(aStudy);
}
getStudyDAO().merge(aStudy);
}
-
/**
* {@inheritDoc}
* @see org.splat.service.StudyService#getDescription(java.lang.Long)
}
study.setAttribute(new DescriptionAttribute(study, descriptionText));
}
-
- /**
+
+ /**
* {@inheritDoc}
* @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long)
*/
public void setUserService(final UserService userService) {
_userService = userService;
}
-
+
/**
* Get the publicationDAO.
* @return the publicationDAO
final DescriptionAttributeDAO descriptionAttributeDAO) {
_descriptionAttributeDAO = descriptionAttributeDAO;
}
+
}
import org.splat.som.Step;
/**
- * Implementation of the service for work with Lucen index.
+ * Implementation of the service for work with Lucen index.
*/
public class IndexServiceImpl implements IndexService {
/**
* The logger for this service.
*/
- private static final Logger LOG = Logger
- .getLogger(IndexServiceImpl.class);
+ private static final Logger LOG = Logger.getLogger(IndexServiceImpl.class);
- private final static String PROP_INDEX = "index";
- private final static String PROP_REF = "ref";
- private final static String PROP_STATE = "state";
+ private final static String PROP_INDEX = "index";
+ private final static String PROP_REF = "ref";
+ private final static String PROP_STATE = "state";
private final static String PROP_AUTHOR = "author";
- private final static String PROP_TITLE = "title";
-
+ private final static String PROP_TITLE = "title";
+
private transient Directory _index;
private transient org.apache.lucene.document.Document _body;
private ProjectElementService _projectElementService;
protected static StandardAnalyzer analyzer = new StandardAnalyzer(
Version.LUCENE_29);
+
private class Entry extends IndexWriter {
private transient final org.apache.lucene.document.Document _entry;
setContextAt(getProjectElementService().getSteps(study));
}
- private Entry(final KnowledgeElement kelm) throws CorruptIndexException,
- LockObtainFailedException, IOException {
+ private Entry(final KnowledgeElement kelm)
+ throws CorruptIndexException, LockObtainFailedException,
+ IOException {
super(_index, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED);
// Addition of mandatory fields
}
private void add() throws CorruptIndexException, IOException {
- addDocument(_entry);
- // Save the new entry
- optimize(); // Should be called before committing the index
- close(); // Commits the index
+ try {
+ addDocument(_entry);
+ // Save the new entry
+ optimize(); // Should be called before committing the index
+ close(); // Commits the index
+ } finally {
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()))) {
+ IndexWriter.unlock(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()));
+ }
+ }
}
private void update() throws CorruptIndexException, IOException {
- String value = _entry.getField(PROP_REF).stringValue(); // Only field with unique value
- Term term = new Term(PROP_REF).createTerm(value);
- updateDocument(term, _entry);
- // Save the updated entry
- optimize(); // Should be called before committing the index
- close(); // Commits the index
+ try {
+ String value = _entry.getField(PROP_REF).stringValue(); // Only field with unique value
+ Term term = new Term(PROP_REF).createTerm(value);
+ updateDocument(term, _entry);
+ // Save the updated entry
+ optimize(); // Should be called before committing the index
+ close(); // Commits the index
+ } finally {
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()))) {
+ IndexWriter.unlock(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()));
+ }
+ }
}
private void setContextAt(final Step[] step) {
public void configure() throws IOException {
File indir = getRepositoryService().getRepositoryIndexDirectory();
+ if (_index != null) {
+ try {
+ _index.close();
+ } finally {
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()))) {
+ IndexWriter.unlock(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()));
+ }
+ }
+ }
_index = FSDirectory.open(indir);
_body = new org.apache.lucene.document.Document();
_body.add(new Field(PROP_INDEX, "", Field.Store.YES,
Field.Index.NOT_ANALYZED));
_body.add(new Field("type", "", Field.Store.YES,
Field.Index.NOT_ANALYZED));
- _body
- .add(new Field(PROP_REF, "", Field.Store.YES,
- Field.Index.NOT_ANALYZED));
- _body
- .add(new Field("area", "", Field.Store.NO,
- Field.Index.NOT_ANALYZED));
+ _body.add(new Field(PROP_REF, "", Field.Store.YES,
+ Field.Index.NOT_ANALYZED));
+ _body.add(new Field("area", "", Field.Store.NO,
+ Field.Index.NOT_ANALYZED));
_body.add(new Field(PROP_STATE, "", Field.Store.YES,
Field.Index.NOT_ANALYZED));
_body.add(new Field(PROP_AUTHOR, "", Field.Store.YES,
Field.Index.NOT_ANALYZED));
_body.add(new Field(PROP_TITLE, "", Field.Store.YES,
Field.Index.NOT_ANALYZED));
- _body
- .add(new Field("contents", "", Field.Store.NO,
- Field.Index.ANALYZED));
+ _body.add(new Field("contents", "", Field.Store.NO,
+ Field.Index.ANALYZED));
if (!this.exists()) {
this.create(); // Happens when re-indexing all studies
}
}
public void create() throws IOException {
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()))) {
+ IndexWriter.unlock(FSDirectory.open(getRepositoryService()
+ .getRepositoryIndexDirectory()));
+ }
Directory index = FSDirectory.open(getRepositoryService()
.getRepositoryIndexDirectory());
- IndexWriter writer = new IndexWriter(index, analyzer, true,
- IndexWriter.MaxFieldLength.UNLIMITED);
- writer.close(); // ==== Creates an empty index
+ if (IndexWriter.isLocked(index)) {
+ IndexWriter.unlock(index);
+ }
+ IndexWriter writer = null;
+ try {
+ writer = new IndexWriter(index, analyzer, true,
+ IndexWriter.MaxFieldLength.UNLIMITED);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.optimize();
+ writer.close(); // ==== Creates an empty index
+ } finally {
+ if (IndexWriter.isLocked(index)) {
+ IndexWriter.unlock(index);
+ }
+ }
+ }
+ }
}
// ==============================================================================================================================
<property name="repositoryService" ref="repositoryService" />
<property name="studyService" ref="studyService" />
<property name="studyDAO" ref="studyDAO" />
+ <property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
</bean>
<bean id="stepService" class="org.splat.service.StepServiceImpl">
<property name="documentTypeService" ref="documentTypeService" />
<property name="userService" ref="userService" />
<property name="descriptionAttributeDAO" ref="descriptionAttributeDAO" />
+ <property name="repositoryService" ref="repositoryService" />
</bean>
<bean id="userRights" abstract="true" scope="session">
"/spring/technicalServiceContext.xml"
})
@TransactionConfiguration(defaultRollback = true, transactionManager = "txManager")
-@Test(sequential=true, groups = {"service", "functional", "business"})
+@Test(singleThreaded=true, groups = {"service", "functional", "business"})
public class BaseTest extends TestListingAndOrder {
// ========================================= static methods
* @author <a href="mailto:vera.polyanskikh@opencascade.com">Vera POLYANSKIKH (VPH)</a>
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
-@Test(sequential=true, groups = {"service", "functional", "business"})
+@Test(singleThreaded=true, groups = {"service", "functional", "business"})
public class TestListingAndOrder extends AbstractTransactionalTestNGSpringContextTests {
compareObjects(aKelmFound, aKelm);
- // Call DAO's create method for a knowledge element with non-zero id.
+ // Call DAO's update method for a bad knowledge element with zero id.
KnowledgeElement aBadKelm = new KnowledgeElement(
(new KnowledgeElement.Properties())
.setTitle("Test knowledge element")
package test.splat.service;
import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.ContributorRelation;
import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.Visibility;
import org.splat.dal.dao.kernel.UserDAO;
import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.KnowledgeElementDAO;
+import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
+import org.splat.dal.dao.som.ScenarioDAO;
import org.splat.dal.dao.som.StudyDAO;
import org.splat.dal.dao.som.ValidationCycleDAO;
import org.splat.exception.BusinessException;
import org.splat.service.SimulationContextService;
import org.splat.service.StepService;
import org.splat.service.StudyService;
+import org.splat.service.dto.KnowledgeSearchFilterDTO;
import org.splat.service.dto.Proxy;
import org.splat.service.dto.StudySearchFilterDTO;
import org.splat.service.technical.ProjectSettingsService;
@Qualifier("studyDAO")
private transient StudyDAO _studyDAO;
+ /**
+ * The ScenarioDAO. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("scenarioDAO")
+ private transient ScenarioDAO _scenarioDAO;
+
+ /**
+ * The KnowledgeElementDAO. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("knowledgeElementDAO")
+ private transient KnowledgeElementDAO _knowledgeElementDAO;
+
+ /**
+ * The KnowledgeElementTypeDAO. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("knowledgeElementTypeDAO")
+ private transient KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
+
/**
* The PublicationService. Later injected by Spring.
*/
*/
@Test
public void testSelectStudiesWhere() throws BusinessException {
- LOG.debug(">>>>> BEGIN testGenerateLocalIndex()");
+ LOG.debug(">>>>> BEGIN testSelectStudiesWhere()");
startNestedTransaction();
HibernateTemplate ht = getHibernateTemplate();
+ Calendar calend = java.util.Calendar.getInstance();
+ calend.roll(Calendar.DATE, false);
+ Date beforeCreation = calend.getTime();
Database.getInstance().reset();
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
_userDAO.create(thirdUser);
+ // ============== STUDY 0: Private : goodUser
// Create private study
Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
aStudy.setTitle("0.This is private study");
SimulationContext ctx = _studyService.addProjectContext(aStudy, cprop);
ht.flush();
+ // ============== STUDY 1: Public : goodUser : otherUser is contributor
// Create public study with predefined title
aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
aStudy.setVisibility(Visibility.PUBLIC);
aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
Long titleStudyId = _studyDAO.create(aStudy);
- // Add simulation context to the study 2
- SimulationContext.Properties cprop1 = new SimulationContext.Properties();
+ // Add simulation context to the study 1
cprop.setType(_simulationContextService.selectType("product"))
.setValue("Test Simulation Context: Product1");
- SimulationContext ctx1 = _studyService.addProjectContext(aStudy, cprop);
+ _studyService.addProjectContext(aStudy, cprop);
ht.flush();
+ // ============== STUDY 2: Public : otherUser
// Create public study with predefined reference
aStudy = TestEntitiesGenerator.getTestStudy(otherUser);
aStudy.setVisibility(Visibility.PUBLIC);
aStudy.setReference("TEST_REF");
Long refStudyId = _studyDAO.create(aStudy);
+ // ============== STUDY 3: Private : thirdUser : otherUser is contributor
// 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");
ValidationCycleRelation link = cycle.getContext();
aStudy.addRelation(link);
ht.flush();
+ calend = java.util.Calendar.getInstance();
+ calend.roll(Calendar.DATE, true);
+ Date afterCreation = calend.getTime();
+ // ============== START OF TEST CALLS
// Search by study author
StudySearchFilterDTO filter = new StudySearchFilterDTO();
filter.setAuthor(String.valueOf(goodUser.getIndex()));
Assert.assertNotNull(res);
Assert.assertEquals(res.size(), 3);
Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // goodUser is author
- Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
+ Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
// Search by study title contents
filter = new StudySearchFilterDTO();
Assert.assertEquals(res.size(), 1);
Assert.assertEquals(res.get(0).getIndex(), privateStudyId);
// Check simualtion contexts of the found study
- aStudy = _studyService.selectStudy(res.get(0).getIndex());
- Iterator<SimulationContext> ctxIter = aStudy.SimulationContextIterator();
+ for (Proxy proxy: res) {
+ aStudy = _studyService.selectStudy(proxy.getIndex());
+ Iterator<SimulationContext> ctxIter = aStudy
+ .SimulationContextIterator();
contexts.clear();
while (ctxIter.hasNext()) {
contexts.add(ctxIter.next());
}
Assert.assertEquals(contexts.size(), 1);
Assert.assertEquals(contexts.get(0), ctx);
+ }
+ // Search for dates
+ filter = new StudySearchFilterDTO();
+ filter.setCreatedAfter(beforeCreation);
+ filter.setCreatedBefore(afterCreation);
+ res = _searchService.selectStudiesWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 2);
+ Assert.assertEquals(res.get(0).getIndex(), refStudyId);
+ Assert.assertEquals(res.get(1).getIndex(), titleStudyId);
+
+ // Search for dates with no result
+ filter = new StudySearchFilterDTO();
+ filter.setCreatedAfter(afterCreation);
+ res = _searchService.selectStudiesWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 0);
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testSelectStudiesWhere()");
+ }
+
+ /**
+ * Test of searching a study.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create studies and try to find them according next document index.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>
+ * <ol>
+ * <li>Search study by state</li>
+ * <li>Search study by reference</li>
+ * <li>Search study by author</li>
+ * <li>Search study by actor</li>
+ * <li>Search study by title</li>
+ * <li>Search study by simulation contexts</li>
+ * <li>Search study by all criteria</li>
+ * <li>Search study by any criteria</li>
+ * </ol>
+ * </i> <B>Test data : </B><BR>
+ * <i>no input parameters</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>A study must be found according to the given criteria<BR>
+ * </li>
+ * </ul>
+ * </i>
+ *
+ * @throws BusinessException
+ * if can't create test user or study
+ */
+ @Test
+ public void testSelectKnowledgeElementsWhere() throws BusinessException {
+ LOG.debug(">>>>> BEGIN testSelectKnowledgeElementsWhere()");
+ startNestedTransaction();
+
+ HibernateTemplate ht = getHibernateTemplate();
+
+ Calendar calend = java.util.Calendar.getInstance();
+ calend.roll(Calendar.DATE, false);
+ Date beforeCreation = calend.getTime();
+
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ // Load workflow customization
+ try {
+ _projectSettings.configure(ClassLoader.getSystemResource(
+ "test/som.xml").getPath());
+ } catch (Exception e) {
+ Assert.fail("Can't load som.xml: ", e);
+ }
+
+ User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
+ _userDAO.create(goodUser);
+ User otherUser = TestEntitiesGenerator.getTestUser("otherUser");
+ _userDAO.create(otherUser);
+ User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
+ _userDAO.create(thirdUser);
+ KnowledgeElementType ktype1 = new KnowledgeElementType("testKType1");
+ KnowledgeElementType ktype2 = new KnowledgeElementType("testKType2");
+ _knowledgeElementTypeDAO.create(ktype1);
+ _knowledgeElementTypeDAO.create(ktype2);
+
+ // ============== STUDY 0: Private : goodUser
+ // Create private study
+ Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
+ aStudy.setTitle("0.This is private study");
+ Long privateStudyId = _studyDAO.create(aStudy);
+
+ // Add simulation context to the study 0
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ cprop.setType(_simulationContextService.selectType("product"))
+ .setValue("Test Simulation Context: Product");
+ SimulationContext ctx = _studyService.addProjectContext(aStudy, cprop);
+ ht.flush();
+
+ // Add a scenario to the study 0
+ Scenario scen = TestEntitiesGenerator.getTestScenario(aStudy);
+ _scenarioDAO.create(scen);
+ ht.flush();
+
+ // Add knowledge elements to the scenario
+ KnowledgeElement kelm01 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype1, "TestKelm01 title");
+ KnowledgeElement kelm02 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype2, "TestKelm02 title");
+ _knowledgeElementDAO.create(kelm01);
+ _knowledgeElementDAO.create(kelm02);
+ ht.flush();
+
+ // ============== STUDY 1: Public : goodUser : otherUser is contributor
+ // Create public study with predefined title
+ aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
+ aStudy.setVisibility(Visibility.PUBLIC);
+ aStudy.setTitle("2.This is a public study");
+ aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
+ Long titleStudyId = _studyDAO.create(aStudy);
+
+ // Add a scenario to the study 1
+ scen = TestEntitiesGenerator.getTestScenario(aStudy);
+ _scenarioDAO.create(scen);
+ ht.flush();
+
+ // Add knowledge elements to the scenario
+ KnowledgeElement kelm11 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype1, "TestKelm11 title");
+ KnowledgeElement kelm12 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype2, "TestKelm12 title");
+ _knowledgeElementDAO.create(kelm11);
+ _knowledgeElementDAO.create(kelm12);
+
+ // Add simulation context to the study 1
+ cprop.setType(_simulationContextService.selectType("product"))
+ .setValue("Test Simulation Context: Product1");
+ _studyService.addProjectContext(aStudy, cprop);
+ ht.flush();
+
+ // ============== STUDY 2: Public : otherUser
+ // Create public study with predefined reference
+ aStudy = TestEntitiesGenerator.getTestStudy(otherUser);
+ aStudy.setVisibility(Visibility.PUBLIC);
+ aStudy.setTitle("1.This is another public study");
+ aStudy.setReference("TEST_REF");
+ Long refStudyId = _studyDAO.create(aStudy);
+ // Add a scenario to the study 2
+ scen = TestEntitiesGenerator.getTestScenario(aStudy);
+ _scenarioDAO.create(scen);
+ ht.flush();
+
+ // Add knowledge elements to the scenario
+ KnowledgeElement kelm21 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype1, "TestKelm21 title");
+ KnowledgeElement kelm22 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype2, "TestKelm22 title");
+ _knowledgeElementDAO.create(kelm21);
+ _knowledgeElementDAO.create(kelm22);
+ ht.flush();
+
+ // ============== STUDY 3: Private : thirdUser : otherUser is contributor
+ // 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");
+ Long reviewStudyId = _studyDAO.create(aStudy);
+
+ // Create validation cycle for the last study
+ ValidationCycle.Properties vprop = new ValidationCycle.Properties();
+ DocumentType type = _documentTypeService.selectType("specification");
+ vprop.setDocumentType(type);
+ vprop.setActor(ValidationStep.REVIEW, otherUser);
+ ValidationCycle cycle = new ValidationCycle(aStudy, vprop);
+ _validationCycleDAO.create(cycle);
+ ValidationCycleRelation link = cycle.getContext();
+ aStudy.addRelation(link);
+ ht.flush();
+ // Add a scenario to the study 3
+ scen = TestEntitiesGenerator.getTestScenario(aStudy);
+ _scenarioDAO.create(scen);
+ ht.flush();
+
+ // Add knowledge elements to the scenario
+ KnowledgeElement kelm31 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype1, "TestKelm31 title");
+ KnowledgeElement kelm32 = TestEntitiesGenerator
+ .getTestKnowledgeElement(scen, ktype2, "TestKelm32 title");
+ _knowledgeElementDAO.create(kelm31);
+ _knowledgeElementDAO.create(kelm32);
+ ht.flush();
+ calend = java.util.Calendar.getInstance();
+ calend.roll(Calendar.DATE, true);
+ Date afterCreation = calend.getTime();
+
+ // ============== START OF TEST CALLS
+ // Search by author goodUser as not logged in user
+ KnowledgeSearchFilterDTO filter = new KnowledgeSearchFilterDTO();
+ filter.setAuthor(String.valueOf(goodUser.getIndex()));
+ List<Proxy> res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 2);
+ Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
+ Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
+
+ // Search for other logged in study contributor (what is visible for otherUser by default)
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setConnectedUserId(otherUser.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(), kelm31.getTitle());
+ Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle());
+
+ // Search for logged in study contributor
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setConnectedUserId(goodUser.getIndex());
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 6);
+ Assert.assertEquals(res.get(0).getTitle(), kelm01.getTitle());
+ Assert.assertEquals(res.get(1).getTitle(), kelm02.getTitle());
+ Assert.assertEquals(res.get(2).getTitle(), kelm11.getTitle());
+ Assert.assertEquals(res.get(3).getTitle(), kelm12.getTitle());
+ Assert.assertEquals(res.get(4).getTitle(), kelm21.getTitle());
+ Assert.assertEquals(res.get(5).getTitle(), kelm22.getTitle());
+
+ // Search by title contents
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setWords("TestKelm22");
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 1);
+ Assert.assertEquals(res.get(0).getTitle(), kelm22.getTitle());
+
+ // Search by reference
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setReference(kelm22.getReference());
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 1);
+ Assert.assertEquals(res.get(0).getTitle(), kelm22.getTitle());
+
+ // Search by simulation context
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setConnectedUserId(goodUser.getIndex());
+ List<SimulationContext> contexts = new ArrayList<SimulationContext>();
+ contexts.add(ctx);
+ filter.setSimContexts(contexts);
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 2);
+ Assert.assertEquals(res.get(0).getTitle(), kelm01.getTitle());
+ Assert.assertEquals(res.get(1).getTitle(), kelm02.getTitle());
+ // Check simualtion contexts of the found study
+ for (Proxy proxy : res) {
+ KnowledgeElement kelm = _knowledgeElementDAO.get(proxy.getIndex());
+ aStudy = _studyService.selectStudy(kelm.getOwnerScenario()
+ .getOwnerStudy().getIndex());
+ Iterator<SimulationContext> ctxIter = aStudy
+ .SimulationContextIterator();
+ contexts.clear();
+ while (ctxIter.hasNext()) {
+ contexts.add(ctxIter.next());
+ }
+ Assert.assertEquals(contexts.size(), 1);
+ Assert.assertEquals(contexts.get(0), ctx);
+ }
+
+ // Search for dates
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setCreatedAfter(beforeCreation);
+ filter.setCreatedBefore(afterCreation);
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 4);
+ 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());
+
+ // Search for dates with no result
+ filter = new KnowledgeSearchFilterDTO();
+ filter.setCreatedAfter(afterCreation);
+ res = _searchService.selectKnowledgeElementsWhere(filter);
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.size(), 0);
+
rollbackNestedTransaction();
- LOG.debug(">>>>> END testGenerateLocalIndex()");
+ LOG.debug(">>>>> END testSelectKnowledgeElementsWhere()");
}
}
* @version $Revision$
*****************************************************************************/
-package test.splat.util;
+package test.splat.util;
import java.util.ArrayList;
import java.util.Date;
import org.splat.dal.bo.kernel.User;
+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.Scenario;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.Study;
import org.splat.exception.BusinessException;
* Utility class for creating test entities.
*/
public class TestEntitiesGenerator {
-
+
/**
* Create a transient user.
- *
- * @param userName the userName
+ *
+ * @param userName
+ * the userName
* @return a transient StepCommentDTO
- * @throws BusinessException if something's wrong
+ * @throws BusinessException
+ * if something's wrong
*/
- public static User getTestUser(final String userName) throws BusinessException {
+ public static User getTestUser(final String userName)
+ throws BusinessException {
User.Properties uprop = new User.Properties();
- uprop.setUsername(userName)
- .setName("TST_Username")
- .setFirstName("TST_FirstName")
- .setDisplayName("TST_test.user")
- .setMailAddress("noreply@salome-platform.org")
- .addRole("TST-User");
+ uprop.setUsername(userName).setName("TST_Username").setFirstName(
+ "TST_FirstName").setDisplayName("TST_test.user")
+ .setMailAddress("noreply@salome-platform.org").addRole(
+ "TST-User");
uprop.disableCheck();
User user = new User(uprop);
return user;
/**
* Create a transient study.
- *
- * @param user the user that will be placed in 'manager' and 'actor' properties
+ *
+ * @param user
+ * the user that will be placed in 'manager' and 'actor' properties
* @return the test study
- * @throws BusinessException if something's wrong
+ * @throws BusinessException
+ * if something's wrong
*/
- public static Study getTestStudy(final User user) throws BusinessException{
+ public static Study getTestStudy(final User user) throws BusinessException {
Study.Properties studyProps = new Study.Properties();
- studyProps.setActor(user)
- .setManager(user)
+ studyProps.setActor(user).setManager(user)
.setTitle("a test study")
- //.setDescription("description")
- .setDate(new Date())
- .setReference("test reference")
+ // .setDescription("description")
+ .setDate(new Date()).setReference("test reference")
.setSimulationContexts(new ArrayList<SimulationContext>())
.setState(ProgressState.inWORK);
Study study = new Study(studyProps);
return study;
}
+
+ /**
+ * Create a transient test scenario.
+ *
+ * @param study
+ * the owner study
+ * @return the created scenario
+ * @throws BusinessException
+ * if creation is failed
+ */
+ public static Scenario getTestScenario(final Study study)
+ throws BusinessException {
+ Scenario.Properties sprops = new Scenario.Properties().setTitle(
+ "TST_Scenario").setManager(study.getAuthor()).setOwnerStudy(
+ study);
+ Scenario aScenario = new Scenario(sprops);
+ study.getScenariiList().add(aScenario);
+ return aScenario;
+ }
+
+ /**
+ * Create a transient knowledge element.
+ *
+ * @param scen
+ * the owner scenario
+ * @param ktype
+ * the knowledge type
+ * @param title
+ * the knowledge title
+ * @return the created knowledge element
+ * @throws BusinessException
+ * if creation is failed
+ */
+ public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
+ final KnowledgeElementType ktype, final String title)
+ throws BusinessException {
+
+ KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
+ Date aDate = new Date();
+
+ kprops
+ .setTitle(title)
+ .setAuthor(scen.getAuthor())
+ .setOwnerScenario(scen)
+ .setType(ktype)
+ .setDate(aDate)
+ .setValue(
+ "This is the test knowledge element.\nIt is created by the unit test.");
+
+ return new KnowledgeElement(kprops);
+ }
}
import java.util.List;
import java.util.Map;
-import org.splat.dal.bo.kernel.User;
-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.SimulationContextType;
-import org.splat.dal.bo.som.Visibility;
import org.splat.kernel.InvalidPropertyException;
import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.SearchService;
*/
@Override
protected String doSearch() throws InvalidPropertyException {
-
initializationScreenContext(Constants.OPEN);
- KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
-
- // Search matching all criteria
- sprop.setType(getKnowledgeElementTypeService().selectType(
- Integer.valueOf(getFilter().getKtype())));
- if (getFilter().getWords().length() > 0) {
- sprop.setTitle(getFilter().getWords());
- }
- if (getFilter().getReference().length() > 0) {
- sprop.setReference(getFilter().getReference());
- }
- if (getFilter().getSimContexts().size() > 0) {
- sprop.setSimulationContexts(getFilter().getSimContexts());
- }
- int index = Integer.valueOf(getFilter().getAuthor());
- if (index > 0) {
- User him = getUserService().selectUser(index);
- sprop.setAuthor(him);
+ if (getConnectedUser() != null) {
+ getFilter().setConnectedUserId(getConnectedUser().getIndex());
}
- // Set of the visibility
- KnowledgeElement.Properties other = sprop.copy();
-
- other.setVisibility(Visibility.PUBLIC);
- sprop.setVisibility(Visibility.PRIVATE);
- sprop.setActor(getConnectedUser());
-
- _result = getSearchService().selectKnowledgeElementsWhere(sprop, other);
+ _result = getSearchService().selectKnowledgeElementsWhere(getFilter());
getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
return "refresh";
}
// Getters
// ==============================================================================================================================
+ /**
+ * Get available knowledge types.
+ *
+ * @return map of knowledge type ids and translations.
+ */
public Map<Long, String> getKnowledgeTypes() {
return _knowledgeTypes;
}