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.DocumentTypeDAO;
21 import org.splat.kernel.InvalidPropertyException;
22 import org.splat.kernel.MissedPropertyException;
23 import org.splat.kernel.MultiplyDefinedException;
24 import org.splat.service.technical.ProjectSettingsService;
25 import org.springframework.transaction.annotation.Transactional;
28 * Document type service implementation.
30 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
32 public class DocumentTypeServiceImpl implements DocumentTypeService {
35 * Injected document type DAO.
37 private DocumentTypeDAO _documentTypeDAO;
40 * Get all document types from the database.
42 * @return the list of all document types
44 // @Transactional(readOnly = true)
46 public List<DocumentType> selectAllTypes() {
47 List<DocumentType> types = getDocumentTypeDAO().getAll();
48 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
49 Hibernate.initialize(i.next()); // Supposed fetching document types
55 * Find all result document types.
57 * @return the list of found types
59 @Transactional(readOnly = true)
60 public List<DocumentType> selectResultTypes() {
61 return getDocumentTypeDAO().getFilteredList(
62 Restrictions.isNotNull("result"), Order.asc("result"));
66 * Get document type by the given type name.
70 * @return the found document type
72 @Transactional(readOnly = true)
73 public DocumentType selectType(final String name) {
74 return getDocumentTypeDAO().findByCriteria(
75 Restrictions.eq("name", name));
79 * Get document type by the given id.
83 * @return the found document type
85 @Transactional(readOnly = true)
86 public DocumentType selectType(final long index) {
87 return getDocumentTypeDAO().get(index);
91 * Create a new document type.
94 * properties of the new document type
95 * @return the created document type
96 * @throws MissedPropertyException
97 * if a mandatory property is missed
98 * @throws InvalidPropertyException
99 * if some property doesn't exist
100 * @throws MultiplyDefinedException
101 * if some property is defined several times
104 public DocumentType createType(final DocumentType.Properties tprop)
105 throws MissedPropertyException, InvalidPropertyException,
106 MultiplyDefinedException {
107 DocumentType type = getDocumentTypeDAO().findByCriteria(
108 Restrictions.eq("name", tprop.getName()));
110 type = new DocumentType(tprop);
111 getDocumentTypeDAO().create(type);
113 type.setProperties(tprop); // Update properties of persistent type
119 * Get document types applicable for the given study step.
122 * the step (study activity)
123 * @return the list of found document types
125 @Transactional(readOnly = true)
126 public List<DocumentType> selectTypesOf(
127 final ProjectSettingsService.Step step) {
128 Integer number = step.getNumber();
129 String sampleStr = new StringBuffer("%-").append(number).append("-%")
131 List<DocumentType> types = getDocumentTypeDAO().getFilteredList(
132 Restrictions.like("step", sampleStr));
133 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
134 Hibernate.initialize(i.next()); // For fetching document types
140 * Approve the document type.
143 * the document type to approve
144 * @return true if approval succeeded
147 public boolean approve(final DocumentType aType) {
148 boolean res = (aType.getState() == ProgressState.inCHECK);
150 aType.setState(ProgressState.APPROVED); // The type name is supposed being localized
151 getDocumentTypeDAO().update(aType);
157 * Get the documentTypeDAO.
159 * @return the documentTypeDAO
161 public DocumentTypeDAO getDocumentTypeDAO() {
162 return _documentTypeDAO;
166 * Set the documentTypeDAO.
168 * @param documentTypeDAO
169 * the documentTypeDAO to set
171 public void setDocumentTypeDAO(final DocumentTypeDAO documentTypeDAO) {
172 _documentTypeDAO = documentTypeDAO;