Salome HOME
afd6f5e39bc627b423ce8994e200950e8a679987
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / dto / DocumentDTO.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   14.11.2012
6  * @author         $Author$
7  * @version        $Revision$
8  * @copyright      OPEN CASCADE 2012-2015
9  *****************************************************************************/
10
11 package org.splat.service.dto;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 /**
17  * Document DTO. This is a container of document files.
18  */
19 public class DocumentDTO {
20         /**
21          * Document persistent id.
22          */
23         private Long _id;
24         /**
25          * Document title.
26          */
27         private String _title;
28         /**
29          * List of document files.
30          */
31         private final List<FileDTO> _files = new ArrayList<FileDTO>(); // RKV: NOPMD: Access to the collection via getter
32
33         /**
34          * Constructor with initialization.
35          * 
36          * @param index
37          *            the document persistent id
38          * @param title
39          *            the document title
40          */
41         public DocumentDTO(final long index, final String title) {
42                 _id = index;
43                 _title = title;
44         }
45         
46         /**
47          * Default constructor.
48          */
49         public DocumentDTO() {
50                 // The empty constructor
51         }
52
53         /**
54          * Get the files.
55          * 
56          * @return the files
57          */
58         public List<FileDTO> getFiles() {
59                 return _files;
60         }
61
62         /**
63          * Get the id.
64          * 
65          * @return the id
66          */
67         public Long getId() {
68                 return _id;
69         }
70
71         /**
72          * Set the id.
73          * 
74          * @param id
75          *            the id to set
76          */
77         public void setId(final Long id) {
78                 _id = id;
79         }
80
81         /**
82          * Get the title.
83          * 
84          * @return the title
85          */
86         public String getTitle() {
87                 return _title;
88         }
89
90         /**
91          * Set the title.
92          * 
93          * @param title
94          *            the title to set
95          */
96         public void setTitle(final String title) {
97                 _title = title;
98         }
99
100         /**
101          * Add a new file DTO.
102          * 
103          * @param id
104          *            file persistent id
105          * @param relativePath
106          *            relative file path
107          * @param state
108          *            file state
109          * @param processing
110          *            processing instruction: file-download or file-import
111          * @param isResult
112          *            true if the file is result
113          * @return the added file DTO
114          */
115         public FileDTO addFile(final long id, final String relativePath, final char state,
116                         final String processing, final boolean isResult) {
117                 FileDTO fileDTO = new FileDTO(id, relativePath, state, processing, isResult);
118                 _files.add(fileDTO);
119                 return fileDTO;
120         }
121         
122         /**
123          * Add a new file DTO.
124          * @param file the file to be added.
125          **/
126         public void addFile(final FileDTO file) {
127                 _files.add(file);
128         }
129
130         /**
131          * {@inheritDoc}
132          * 
133          * @see java.lang.Object#toString()
134          */
135         @Override
136         public String toString() {
137                 StringBuffer buf = new StringBuffer();
138                 String indent = "    ";
139                 buf.append(indent).append("Document: ").append(getTitle()).append('\n')
140                                 .append(indent).append("Document ID: ").append(getId()).append(
141                                                 '\n');
142                 for (FileDTO file : getFiles()) {
143                         buf.append(file);
144                 }
145                 return buf.toString();
146         }
147 }