import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
+import org.hibernate.Criteria;
import org.hibernate.Hibernate;
+import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.hibernate.proxy.HibernateProxy;
import org.jfree.chart.ChartFactory;
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;
import org.splat.dal.dao.som.PublicationDAO;
import org.splat.dal.dao.som.ScenarioDAO;
import org.splat.dal.dao.som.StudyDAO;
+import org.splat.dal.dao.som.UsedByRelationDAO;
import org.splat.dal.dao.som.ValidationCycleDAO;
import org.splat.exception.IncompatibleDataException;
import org.splat.exception.InvalidParameterException;
import org.splat.service.dto.StudyFacadeDTO;
import org.splat.service.technical.IndexService;
import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.ProjectSettingsService.Step;
import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.splat.service.technical.RepositoryService;
+import org.splat.service.technical.ProjectSettingsService.Step;
import org.splat.som.Revision;
import org.springframework.transaction.annotation.Transactional;
*/
private StudyDAO _studyDAO;
+ /**
+ * Injected usedBy relations DAO.
+ */
+ private UsedByRelationDAO _usedByRelationDAO;
+
/**
* Injected scenario DAO.
*/
*
* @see org.splat.service.StudyService#selectStudy(long)
*/
- @Override
@Transactional
public Study selectStudy(final long index) {
Study result = getStudyDAO().get(index);
return result;
}
- /**
+ /**
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#removeStudy(long)
*/
@Transactional
- public void removeStudy(final long index) {
+ public void removeStudy(final Long index) {
Study study = getStudyDAO().get(index);
+ Set<org.splat.dal.bo.som.Document> docums = new HashSet<org.splat.dal.bo.som.Document>();
if (study != null) {
+ // Select all documents published in the study and study's scenarios.
+ DetachedCriteria query = DetachedCriteria.forClass(
+ Publication.class, "pub");
+ query
+ .createCriteria("pub.owner", "projelem",
+ Criteria.INNER_JOIN)
+ .createAlias("projelem.owner", "study", Criteria.LEFT_JOIN)
+ .add(
+ Restrictions
+ .or(Restrictions.eq("projelem.rid", index),
+ Restrictions.eq("study.rid", index)))
+ .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Find study documents: " + query.toString());
+ }
+ for (Publication pub : getPublicationDAO().getFilteredList(query)) {
+ docums.add(pub.value());
+ // Find also all previous versions of the document
+ for (org.splat.dal.bo.som.Document prev = pub.value()
+ .getPreviousVersion(); prev != null; prev = prev
+ .getPreviousVersion()) {
+ docums.add(prev);
+ }
+ }
+
+ // Delete the study with its relations, scenarios and publications
getStudyDAO().delete(study);
+
+ // Remove all relations of study documents
+ for (org.splat.dal.bo.som.Document doc : docums) {
+ LOG.debug("Found doc: " + doc.getTitle() + " [" + doc.getReference() + "]" + " [" + doc.getRid() + "]");
+ doc.getAllRelations().clear();
+ }
+ getDocumentDAO().flush();
+
+ // Remove all documents of the study
+ for (org.splat.dal.bo.som.Document doc : docums) {
+ LOG.debug("Remove doc: " + doc.getTitle() + " [" + doc.getReference() + "]" + " [" + doc.getRid() + "]");
+ getDocumentDAO().delete(doc);
+ }
}
}
-
+
/**
* Get study by its reference.
*
*
* @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) {
}
return false;
}
-*/
+ */
/**
* {@inheritDoc}
*
* @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) {
- Map<String, ValidationCycle> validactor = aStudyDTO.getValidationCycles();
+ public void setValidationCycle(final Study aStudyDTO,
+ final DocumentType type, final ValidationCycle.Properties vprop) {
+ Map<String, ValidationCycle> validactor = aStudyDTO
+ .getValidationCycles();
if (validactor == null) {
setShortCuts(aStudyDTO); // Initializes validactor and actor
}
Study aStudy = selectStudy(aStudyDTO.getIndex());
-
+
String cname = type.getName();
ValidationCycle cycle = validactor.get(cname);
* 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;
}
return isOk;
}
-
+
/**
* Moves this study from the Public to the Private area of the repository.
*
* 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
- //RKV: 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());
break;
}
}
- SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); //RKV: NOPMD: TODO: Use locale here?
+ SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); // RKV: NOPMD: TODO: Use locale here?
String year = tostring.format(study.getDate());
year = year.substring(4 - (i - n), 4); // 4-(i-n) must be equal to either 0 or 2
for (int j = 0; j < year.length(); j++) {
* @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()
+ if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
.getRepositoryIndexDirectory()))) {
IndexWriter.unlock(FSDirectory.open(getRepositoryService()
.getRepositoryIndexDirectory()));
* 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()) {
+ if (aStudy.getValidationCycles() == null
+ || aStudy.getValidationCycles().isEmpty()) {
setShortCuts(aStudy);
}
ValidationCycle result = aStudy.getValidationCycles().get(
* @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);
}
aStudy.getActor().add(((ActorRelation) link).getTo());
}
}
-
+
/**
*
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#markStudyAsReference(org.splat.dal.bo.som.Study)
*/
@Override
@Transactional
- public void markStudyAsReference (final Study aStudy) {
-
+ public void markStudyAsReference(final Study aStudy) {
+
aStudy.setMarkreference(1);
aStudy.setProgressState(ProgressState.TEMPLATE);
getStudyDAO().merge(aStudy);
}
-
+
/**
*
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#removeStudyAsReference(org.splat.dal.bo.som.Study)
*/
@Override
@Transactional
public void removeStudyAsReference(final Study aStudy) {
-
+
aStudy.setMarkreference(0);
aStudy.setProgressState(ProgressState.APPROVED);
getStudyDAO().merge(aStudy);
}
-
-
- /**
+
+ /**
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#getDescription(java.lang.Long)
*/
@Override
@Transactional(readOnly = true)
- public String getDescription(final Long studyId) throws InvalidParameterException {
- if(studyId == null) {
+ public String getDescription(final Long studyId)
+ throws InvalidParameterException {
+ if (studyId == null) {
throw new InvalidParameterException("studyId", "null");
}
Study study = _studyDAO.get(studyId);
- if(study == null) {
+ if (study == null) {
throw new InvalidParameterException("studyId", studyId.toString());
}
return study.getDescription();
}
-
-
- /**
+
+ /**
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#setDescription(java.lang.Long, java.lang.String)
*/
@Override
@Transactional
- public void setDescription(final Long studyId, final String descriptionText)
+ public void setDescription(final Long studyId, final String descriptionText)
throws InvalidParameterException {
- if(studyId == null) {
+ if (studyId == null) {
throw new InvalidParameterException("studyId", "null");
}
Study study = _studyDAO.get(studyId);
- if(study == null) {
+ if (study == null) {
throw new InvalidParameterException("studyId", studyId.toString());
}
study.setAttribute(new DescriptionAttribute(study, descriptionText));
}
-
- /**
+
+ /**
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long)
*/
@Override
@Transactional
- public boolean removeDescription(final Long studyId) throws InvalidParameterException {
- if(studyId == null) {
- throw new InvalidParameterException("studyId", String.valueOf(studyId));
+ public boolean removeDescription(final Long studyId)
+ throws InvalidParameterException {
+ if (studyId == null) {
+ throw new InvalidParameterException("studyId", String
+ .valueOf(studyId));
}
Study study = _studyDAO.get(studyId);
- if(study == null) {
- throw new InvalidParameterException("studyId", String.valueOf(studyId));
+ if (study == null) {
+ throw new InvalidParameterException("studyId", String
+ .valueOf(studyId));
}
- return study.removeAttribute(study.getAttribute(DescriptionAttribute.class));
+ return study.removeAttribute(study
+ .getAttribute(DescriptionAttribute.class));
}
-
/**
*
* {@inheritDoc}
+ *
* @see org.splat.service.StudyService#compare(java.util.List)
*/
@Override
- public String compare (final List<DocToCompareDTO> docsList, final String userName) throws IncompatibleDataException{
-
+ public String compare(final List<DocToCompareDTO> docsList,
+ final String userName) throws IncompatibleDataException {
+
String axis1Name = "";
String axis2Name = "";
String chartTitle = "";
String resultPath = "";
-
+
XYSeriesCollection dataset = new XYSeriesCollection();
-
+
Iterator<DocToCompareDTO> docListIter = docsList.iterator();
-
+
for (; docListIter.hasNext();) {
-
+
DocToCompareDTO docDTO = docListIter.next();
String pathToFile = docDTO.getPathToFile();
File compDocFile = new File(pathToFile);
-
- resultPath = pathToFile.substring(0, pathToFile.indexOf("vault")) + "downloads" + File.separator + userName + File.separator + "ComparisonResult.pdf";
-
+
+ resultPath = pathToFile.substring(0, pathToFile.indexOf("vault"))
+ + "downloads" + File.separator + userName + File.separator
+ + "ComparisonResult.pdf";
+
XYSeries series = new XYSeries("Study: " + docDTO.getStudyTitle() + " Scenario: " + docDTO.getScenarioTitle() + " Document: " + docDTO.getDocumentTitle());
-
- //read the file and get points information.
+
+ // read the file and get points information.
try {
Scanner input = new Scanner(compDocFile);
-
+
//get the title of the chart.
if (input.hasNext()) {
chartTitle = input.nextLine();
}
- //get the name of the axis.
+ // get the name of the axis.
if (input.hasNext()) {
String[] tokens = input.nextLine().split(",");
-
- if (tokens.length < 2)
- throw new IncompatibleDataException(MessageKeyEnum.IDT_000001.toString());
-
+
+ if (tokens.length < 2) {
+ throw new IncompatibleDataException(
+ MessageKeyEnum.IDT_000001.toString());
+ }
+
if ("".equals(axis1Name)) {
axis1Name = tokens[0];
} else if (!axis1Name.equals(tokens[0])) {
LOG.debug("Axis must be the same for all documents");
- throw new IncompatibleDataException(MessageKeyEnum.IDT_000001.toString());
+ throw new IncompatibleDataException(
+ MessageKeyEnum.IDT_000001.toString());
}
-
+
if ("".equals(axis2Name)) {
axis2Name = tokens[1];
} else if (!axis2Name.equals(tokens[1])) {
LOG.debug("Axis must be the same for all documents");
- throw new IncompatibleDataException(MessageKeyEnum.IDT_000001.toString());
+ throw new IncompatibleDataException(
+ MessageKeyEnum.IDT_000001.toString());
}
}
-
- //Get the XY points series.
- while(input.hasNext()) {
-
+
+ // Get the XY points series.
+ while (input.hasNext()) {
+
String currentString = input.nextLine();
-
- if ("".equals(currentString)) {
- continue;
- }
- else {
+
+ if (!("".equals(currentString))) {
String[] tokens = currentString.split(" ");
- series.add(Double.valueOf(tokens[0]), Double.valueOf(tokens[1]));
- }
-
- } //while
-
+ series.add(Double.valueOf(tokens[0]), Double
+ .valueOf(tokens[1]));
+ }
+
+ } // while
+
dataset.addSeries(series);
-
+
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "ERROR";
}
- } //for
-
+ } // for
+
JFreeChart chart = ChartFactory.createXYLineChart(
chartTitle, // Title
axis1Name, // x-axis Label
true, // Use tooltips
false // Configure chart to generate URLs?
);
-
- //export to PDF - file.
+
+ // export to PDF - file.
int x = 500;
int y = 300;
Rectangle pagesize = new Rectangle(x, y);
Document document = new Document(pagesize, 50, 50, 50, 50);
- PdfWriter writer;
+ PdfWriter writer;
try {
File resFile = new File(resultPath);
- File resFolder = new File(resultPath.substring(0, resultPath.lastIndexOf(File.separator)));
+ File resFolder = new File(resultPath.substring(0, resultPath
+ .lastIndexOf(File.separator)));
resFolder.mkdirs();
- writer = PdfWriter.getInstance(document, new FileOutputStream(resFile));
-
- document.open();
- PdfContentByte cb = writer.getDirectContent();
- PdfTemplate tp = cb.createTemplate(x, y);
- Graphics2D g2 = tp.createGraphics(x, y, new DefaultFontMapper());
- chart.draw(g2, new java.awt.Rectangle(x,y));
- g2.dispose();
- cb.addTemplate(tp, 0, 0);
- document.close();
-
+ writer = PdfWriter.getInstance(document, new FileOutputStream(
+ resFile));
+
+ document.open();
+ PdfContentByte cb = writer.getDirectContent();
+ PdfTemplate tp = cb.createTemplate(x, y);
+ Graphics2D g2 = tp.createGraphics(x, y, new DefaultFontMapper());
+ chart.draw(g2, new java.awt.Rectangle(x, y));
+ g2.dispose();
+ cb.addTemplate(tp, 0, 0);
+ document.close();
+
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
return resultPath;
}
-
+
/**
* Get project settings.
*
public void setUserService(final UserService userService) {
_userService = userService;
}
-
+
/**
* {@inheritDoc}
*
/**
* Get the publicationDAO.
+ *
* @return the publicationDAO
*/
public PublicationDAO getPublicationDAO() {
/**
* Set the publicationDAO.
- * @param publicationDAO the publicationDAO to set
+ *
+ * @param publicationDAO
+ * the publicationDAO to set
*/
public void setPublicationDAO(final PublicationDAO publicationDAO) {
_publicationDAO = publicationDAO;
/**
* Get the repositoryService.
+ *
* @return the repositoryService
*/
public RepositoryService getRepositoryService() {
/**
* Set the repositoryService.
- * @param repositoryService the repositoryService to set
+ *
+ * @param repositoryService
+ * the repositoryService to set
*/
public void setRepositoryService(final RepositoryService repositoryService) {
_repositoryService = repositoryService;
/**
* Get the documentDAO.
+ *
* @return the documentDAO
*/
public DocumentDAO getDocumentDAO() {
/**
* Set the documentDAO.
- * @param documentDAO the documentDAO to set
+ *
+ * @param documentDAO
+ * the documentDAO to set
*/
public void setDocumentDAO(final DocumentDAO documentDAO) {
_documentDAO = documentDAO;
/**
* Get the descriptionAttributeDAO.
+ *
* @return the descriptionAttributeDAO
*/
public DescriptionAttributeDAO getDescriptionAttributeDAO() {
/**
* Set the descriptionAttributeDAO.
- * @param descriptionAttributeDAO the descriptionAttributeDAO to set
+ *
+ * @param descriptionAttributeDAO
+ * the descriptionAttributeDAO to set
*/
public void setDescriptionAttributeDAO(
final DescriptionAttributeDAO descriptionAttributeDAO) {
_descriptionAttributeDAO = descriptionAttributeDAO;
}
+
+ /**
+ * Get the usedByRelationDAO.
+ *
+ * @return the usedByRelationDAO
+ */
+ public UsedByRelationDAO getUsedByRelationDAO() {
+ return _usedByRelationDAO;
+ }
+
+ /**
+ * Set the usedByRelationDAO.
+ *
+ * @param usedByRelationDAO
+ * the usedByRelationDAO to set
+ */
+ public void setUsedByRelationDAO(final UsedByRelationDAO usedByRelationDAO) {
+ _usedByRelationDAO = usedByRelationDAO;
+ }
+
}