1 /*****************************************************************************
5 * Creation date 06.10.2012
8 *****************************************************************************/
10 package org.splat.service;
12 import java.util.Iterator;
13 import java.util.List;
15 import org.hibernate.Hibernate;
16 import org.hibernate.criterion.Order;
17 import org.hibernate.criterion.Restrictions;
18 import org.splat.dal.bo.som.DocumentType;
19 import org.splat.dal.bo.som.ProgressState;
20 import org.splat.dal.dao.som.Database;
21 import org.splat.dal.dao.som.DocumentTypeDAO;
22 import org.splat.kernel.InvalidPropertyException;
23 import org.splat.kernel.MissedPropertyException;
24 import org.splat.kernel.MultiplyDefinedException;
25 import org.splat.service.technical.ProjectSettingsService;
26 import org.springframework.transaction.annotation.Transactional;
29 * Document type service implementation.
31 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
33 public class DocumentTypeServiceImpl implements DocumentTypeService {
36 * Injected document type DAO.
38 private DocumentTypeDAO _documentTypeDAO;
41 * Get all document types from the database.
43 * @return the list of all document types
45 // @Transactional(readOnly = true)
47 public List<DocumentType> selectAllTypes() {
48 List<DocumentType> types = getDocumentTypeDAO().getAll();
49 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
50 Hibernate.initialize(i.next()); // Supposed fetching document types
56 * Find all result document types.
58 * @return the list of found types
60 @Transactional(readOnly = true)
61 public List<DocumentType> selectResultTypes() {
62 return getDocumentTypeDAO().getFilteredList(
63 Restrictions.isNotNull("result"), Order.asc("result"));
67 * Get document type by the given type name.
71 * @return the found document type
73 @Transactional(readOnly = true)
74 public DocumentType selectType(String name) {
75 return getDocumentTypeDAO().findByCriteria(
76 Restrictions.eq("name", name));
80 * Get document type by the given id.
84 * @return the found document type
86 @Transactional(readOnly = true)
87 public DocumentType selectType(long index) {
88 return getDocumentTypeDAO().get(index);
92 * Create a new document type.
95 * properties of the new document type
96 * @return the created document type
97 * @throws MissedPropertyException
98 * if a mandatory property is missed
99 * @throws InvalidPropertyException
100 * if some property doesn't exist
101 * @throws MultiplyDefinedException
102 * if some property is defined several times
105 public DocumentType createType(DocumentType.Properties tprop)
106 throws MissedPropertyException, InvalidPropertyException,
107 MultiplyDefinedException {
108 // TODO: Check for duplicate definition
109 DocumentType type = new DocumentType(tprop);
110 getDocumentTypeDAO().create(type);
115 * Get document types applicable for the given study step.
118 * the step (study activity)
119 * @return the list of found document types
121 @Transactional(readOnly = true)
122 public List<DocumentType> selectTypesOf(ProjectSettingsService.Step step) {
123 Integer number = step.getNumber();
124 String sampleStr = new StringBuffer("%-").append(number).append("-%")
126 List<DocumentType> types = getDocumentTypeDAO().getFilteredList(
127 Restrictions.like("step", sampleStr));
128 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
129 Hibernate.initialize(i.next()); // For fetching document types
135 * Approve the document type.
136 * @param aType the document type to approve
137 * @return true if approval succeeded
140 public boolean approve (DocumentType aType) {
141 if (aType.getState() != ProgressState.inCHECK) return false;
142 aType.setState(ProgressState.APPROVED); // The type name is supposed being localized
143 getDocumentTypeDAO().update(aType);
148 * Get the documentTypeDAO.
150 * @return the documentTypeDAO
152 public DocumentTypeDAO getDocumentTypeDAO() {
153 return _documentTypeDAO;
157 * Set the documentTypeDAO.
159 * @param documentTypeDAO
160 * the documentTypeDAO to set
162 public void setDocumentTypeDAO(DocumentTypeDAO documentTypeDAO) {
163 _documentTypeDAO = documentTypeDAO;