]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
df5dd994ee378d93cc34bb183a5e9b117dd2bd95
[tmp/jakarta-migration.git] /
1 /**\r
2  *  This document is a part of the source code and related artifacts\r
3  *  for CollectionSpace, an open source collections management system\r
4  *  for museums and related institutions:\r
5 \r
6  *  http://www.collectionspace.org\r
7  *  http://wiki.collectionspace.org\r
8 \r
9  *  Copyright 2009 Regents of the University of California\r
10 \r
11  *  Licensed under the Educational Community License (ECL), Version 2.0.\r
12  *  You may not use this file except in compliance with this License.\r
13 \r
14  *  You may obtain a copy of the ECL 2.0 License at\r
15 \r
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
17 \r
18  *  Unless required by applicable law or agreed to in writing, software\r
19  *  distributed under the License is distributed on an "AS IS" BASIS,\r
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
21  *  See the License for the specific language governing permissions and\r
22  *  limitations under the License.\r
23  */\r
24 package org.collectionspace.services.note.nuxeo;\r
25 \r
26 import java.util.Iterator;\r
27 import java.util.List;\r
28 \r
29 import org.collectionspace.services.note.NoteJAXBSchema;\r
30 import org.collectionspace.services.common.document.DocumentHandler.Action;\r
31 import org.collectionspace.services.common.document.DocumentWrapper;\r
32 import org.collectionspace.services.note.NotesCommon;\r
33 import org.collectionspace.services.note.NotesCommonList;\r
34 import org.collectionspace.services.note.NotesCommonList.NoteListItem;\r
35 \r
36 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;\r
37 import org.collectionspace.services.nuxeo.client.java.RemoteSubItemDocumentModelHandlerImpl;\r
38 import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
39 import org.nuxeo.ecm.core.api.DocumentModel;\r
40 import org.nuxeo.ecm.core.api.DocumentModelList;\r
41 import org.slf4j.Logger;\r
42 import org.slf4j.LoggerFactory;\r
43 \r
44 /**\r
45  * The Class NoteDocumentModelHandler.\r
46  */\r
47 public class NoteDocumentModelHandler\r
48         extends RemoteSubItemDocumentModelHandlerImpl<NotesCommon, NotesCommonList> {\r
49 \r
50     /** The logger. */\r
51     private final Logger logger = LoggerFactory.getLogger(NoteDocumentModelHandler.class);\r
52     \r
53     /** The note. */\r
54     private NotesCommon note;\r
55     \r
56     /** The note list. */\r
57     private NotesCommonList noteList;\r
58 \r
59     /** The owner. */\r
60     private String owner;\r
61     \r
62     private final String commonSchemaName = "notes_common";\r
63     \r
64         public boolean schemaHasSubItem(String schema) {\r
65                 return commonSchemaName.equals(schema);\r
66         }\r
67 \r
68 \r
69     /**\r
70      * Gets the owner.\r
71      *\r
72      * @return the owner\r
73      */\r
74     public String getOwner() {\r
75         return owner;\r
76     }\r
77 \r
78     /**\r
79      * Sets the owner.\r
80      *\r
81      * @param owner the new owner\r
82      */\r
83     public void setInAuthority(String owner) {\r
84         this.owner = owner;\r
85     }\r
86 \r
87     /* (non-Javadoc)\r
88      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPart()\r
89      */\r
90     @Override\r
91     public NotesCommon getCommonPart() {\r
92         return note;\r
93     }\r
94 \r
95     /* (non-Javadoc)\r
96      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPart(java.lang.Object)\r
97      */\r
98     @Override\r
99     public void setCommonPart(NotesCommon note) {\r
100         this.note = note;\r
101     }\r
102 \r
103     /* (non-Javadoc)\r
104      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPartList()\r
105      */\r
106     @Override\r
107     public NotesCommonList getCommonPartList() {\r
108         return noteList;\r
109     }\r
110 \r
111     /* (non-Javadoc)\r
112      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)\r
113      */\r
114     @Override\r
115     public void setCommonPartList(NotesCommonList noteList) {\r
116         this.noteList = noteList;\r
117     }\r
118 \r
119     /* (non-Javadoc)\r
120      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)\r
121      */\r
122     @Override\r
123     public NotesCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)\r
124             throws Exception {\r
125         throw new UnsupportedOperationException();\r
126     }\r
127 \r
128     /* (non-Javadoc)\r
129      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)\r
130      */\r
131     @Override\r
132     public void fillCommonPart(NotesCommon noteObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {\r
133         throw new UnsupportedOperationException();\r
134     }\r
135 \r
136     /* (non-Javadoc)\r
137      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)\r
138      */\r
139     @Override\r
140     public NotesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {\r
141         NotesCommonList coList = extractPagingInfo(new NotesCommonList(), wrapDoc);\r
142         List<NotesCommonList.NoteListItem> list = coList.getNoteListItem();\r
143         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();\r
144         while(iter.hasNext()){\r
145             DocumentModel docModel = iter.next();\r
146             NoteListItem clistItem = new NoteListItem();\r
147             clistItem.setContent((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),\r
148                     NoteJAXBSchema.CONTENT));\r
149             String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
150             clistItem.setUri(getServiceContextPath() + id);\r
151             clistItem.setCsid(id);\r
152             list.add(clistItem);\r
153         }\r
154 \r
155         return coList;\r
156     }\r
157 \r
158     /* (non-Javadoc)\r
159      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)\r
160      */\r
161     @Override\r
162     public String getQProperty(String prop) {\r
163         return NoteConstants.NUXEO_SCHEMA_NAME + ":" + prop;\r
164     }\r
165 }\r
166 \r