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.dao.som.DocumentTypeDAO;
20 import org.splat.kernel.InvalidPropertyException;
21 import org.splat.kernel.MissedPropertyException;
22 import org.splat.kernel.MultiplyDefinedException;
23 import org.splat.service.technical.ProjectSettingsService;
24 import org.springframework.transaction.annotation.Transactional;
27 * Document type service implementation.
29 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
31 public class DocumentTypeServiceImpl implements DocumentTypeService {
34 * Injected document type DAO.
36 private DocumentTypeDAO _documentTypeDAO;
39 * Get all document types from the database.
41 * @return the list of all document types
43 @Transactional(readOnly = true)
44 public List<DocumentType> selectAllTypes() {
45 List<DocumentType> types = getDocumentTypeDAO().getAll();
46 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
47 Hibernate.initialize(i.next()); // Supposed fetching document types
53 * Find all result document types.
55 * @return the list of found types
57 @Transactional(readOnly = true)
58 public List<DocumentType> selectResultTypes() {
59 return getDocumentTypeDAO().getFilteredList(
60 Restrictions.isNotNull("result"), Order.asc("result"));
64 * Get document type by the given type name.
68 * @return the found document type
70 @Transactional(readOnly = true)
71 public DocumentType selectType(String name) {
72 return getDocumentTypeDAO().findByCriteria(
73 Restrictions.eq("name", name));
77 * Get document type by the given id.
81 * @return the found document type
83 @Transactional(readOnly = true)
84 public DocumentType selectType(long index) {
85 return getDocumentTypeDAO().get(index);
89 * Create a new document type.
92 * properties of the new document type
93 * @return the created document type
94 * @throws MissedPropertyException
95 * if a mandatory property is missed
96 * @throws InvalidPropertyException
97 * if some property doesn't exist
98 * @throws MultiplyDefinedException
99 * if some property is defined several times
102 public DocumentType createType(DocumentType.Properties tprop)
103 throws MissedPropertyException, InvalidPropertyException,
104 MultiplyDefinedException {
105 // TODO: Check for duplicate definition
106 DocumentType type = new DocumentType(tprop);
107 getDocumentTypeDAO().create(type);
112 * Get document types applicable for the given study step.
115 * the step (study activity)
116 * @return the list of found document types
118 @Transactional(readOnly = true)
119 public List<DocumentType> selectTypesOf(ProjectSettingsService.Step step) {
120 Integer number = step.getNumber();
121 String sampleStr = new StringBuffer("%-").append(number).append("-%")
123 List<DocumentType> types = getDocumentTypeDAO().getFilteredList(
124 Restrictions.like("step", sampleStr));
125 for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
126 Hibernate.initialize(i.next()); // For fetching document types
132 * Get the documentTypeDAO.
134 * @return the documentTypeDAO
136 public DocumentTypeDAO getDocumentTypeDAO() {
137 return _documentTypeDAO;
141 * Set the documentTypeDAO.
143 * @param documentTypeDAO
144 * the documentTypeDAO to set
146 public void setDocumentTypeDAO(DocumentTypeDAO documentTypeDAO) {
147 _documentTypeDAO = documentTypeDAO;