1 /*****************************************************************************
5 * Creation date 07.10.2012
8 *****************************************************************************/
10 package org.splat.service;
12 import java.util.Iterator;
13 import java.util.List;
15 import org.splat.dal.bo.som.ProjectElement;
16 import org.splat.dal.bo.som.Publication;
17 import org.splat.dal.dao.som.ProjectElementDAO;
18 import org.splat.service.technical.ProjectSettingsService;
19 import org.splat.som.Step;
20 import org.springframework.transaction.annotation.Transactional;
23 * Project element service implementation.
28 public class ProjectElementServiceImpl implements ProjectElementService {
31 * Injected project settings service.
33 private ProjectSettingsService _projectSettings;
35 * Injected project element DAO.
37 private ProjectElementDAO _projectElementDAO;
42 * @see org.splat.service.ProjectElementService#getFirstStep(org.splat.dal.bo.som.ProjectElement)
44 public Step getFirstStep(final ProjectElement elem) {
45 return getSteps(elem)[0];
48 public Step getLastStep(final ProjectElement elem) {
49 Step[] mystep = getSteps(elem); // For getting the folders length, if null
50 return mystep[mystep.length - 1];
56 * @see org.splat.service.ProjectElementService#getSteps(org.splat.dal.bo.som.ProjectElement)
58 public Step[] getSteps(final ProjectElement elem) {
59 if (elem.getFolders() == null) {
60 List<ProjectSettingsService.Step> steps = getProjectSettings()
61 .getStepsOf(elem.getClass());
62 Iterator<ProjectSettingsService.Step> nstep = steps.iterator();
64 elem.setFolders(new Step[steps.size()]);
65 for (int i = 0; i < elem.getFolders().length; i++) {
66 elem.getFolders()[i] = new Step(nstep.next(), elem);
69 return elem.getFolders(); // No protection against this object corruption as it would not corrupt the database
73 * Refreshes the internal data potentially out-of-date. This function needs to be called when Publication objects are added to this
74 * Project Element before being saved. The reason is, as saving a persistent object changes its hashcode, hashed data need to be rebuilt
75 * after saving for making functions based on this hashcode such as remove(), working.
76 * @param elem the project element to refresh
79 public void refresh(final ProjectElement elem) {
80 // -------------------------
81 Publication[] curdoc = elem.getDocums().toArray(
82 new Publication[elem.getDocums().size()]);
84 elem.setFolders(null); // Just in case
85 elem.getDocums().clear();
86 for (int i = 0; i < curdoc.length; i++) {
87 elem.getDocums().add(curdoc[i]);
89 // No need to rebuild the list of SimulationContext as it does not use hashcodes
90 getProjectElementDAO().update(elem);
94 * Get project settings.
96 * @return Project settings service
98 private ProjectSettingsService getProjectSettings() {
99 return _projectSettings;
103 * Set project settings service.
105 * @param projectSettingsService
106 * project settings service
108 public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
109 _projectSettings = projectSettingsService;
113 * Get the projectElementDAO.
114 * @return the projectElementDAO
116 public ProjectElementDAO getProjectElementDAO() {
117 return _projectElementDAO;
121 * Set the projectElementDAO.
122 * @param projectElementDAO the projectElementDAO to set
124 public void setProjectElementDAO(final ProjectElementDAO projectElementDAO) {
125 _projectElementDAO = projectElementDAO;