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 // TODO: Check for duplicate definition
108 DocumentType type = new DocumentType(tprop);
109 getDocumentTypeDAO().create(type);
114 * Get document types applicable for the given study step.
117 * the step (study activity)
118 * @return the list of found document types
120 @Transactional(readOnly = true)
121 public List<DocumentType> selectTypesOf(final ProjectSettingsService.Step step) {
122 Integer number = step.getNumber();
123 String sampleStr = new StringBuffer("%-").append(number).append("-%")
125 List<DocumentType> types = getDocumentTypeDAO().getFilteredList(
126 Restrictions.like("step", sampleStr));
127 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
128 Hibernate.initialize(i.next()); // For fetching document types
134 * Approve the document type.
135 * @param aType the document type to approve
136 * @return true if approval succeeded
139 public boolean approve(final DocumentType aType) {
140 boolean res = (aType.getState() == ProgressState.inCHECK);
142 aType.setState(ProgressState.APPROVED); // The type name is supposed being localized
143 getDocumentTypeDAO().update(aType);
149 * Get the documentTypeDAO.
151 * @return the documentTypeDAO
153 public DocumentTypeDAO getDocumentTypeDAO() {
154 return _documentTypeDAO;
158 * Set the documentTypeDAO.
160 * @param documentTypeDAO
161 * the documentTypeDAO to set
163 public void setDocumentTypeDAO(final DocumentTypeDAO documentTypeDAO) {
164 _documentTypeDAO = documentTypeDAO;