]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1273ad5b26556b782ad85498485db3352e2dffa6
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.account.storage;
25
26 import java.util.List;
27 import java.util.UUID;
28 import org.collectionspace.services.account.AccountsCommon;
29 import org.collectionspace.services.account.AccountsCommonList;
30 import org.collectionspace.services.account.AccountsCommonList.AccountListItem;
31 import org.collectionspace.services.common.document.AbstractDocumentHandler;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
34
35 /**
36  *
37  * @author 
38  */
39 public class AccountDocumentHandler
40         extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
41
42     private AccountsCommon account;
43     private AccountsCommonList accountList;
44
45     @Override
46     public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
47         String id = UUID.randomUUID().toString();
48         AccountsCommon account = wrapDoc.getWrappedObject();
49         account.setCsid(id);
50     }
51
52     @Override
53     public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
54         getServiceContext().setOutput(getCommonPart());
55     }
56
57     @Override
58     public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
59         setCommonPart(extractCommonPart(wrapDoc));
60         getServiceContext().setOutput(getCommonPart());
61     }
62
63     @Override
64     public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
65         AccountsCommonList accList = extractCommonPartList(wrapDoc);
66         setCommonPartList(accList);
67         getServiceContext().setOutput(getCommonPartList());
68     }
69
70     @Override
71     public AccountsCommon extractCommonPart(
72             DocumentWrapper<AccountsCommon> wrapDoc)
73             throws Exception {
74         return wrapDoc.getWrappedObject();
75     }
76
77     @Override
78     public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
79             throws Exception {
80         throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
81     }
82
83     @Override
84     public AccountsCommonList extractCommonPartList(
85             DocumentWrapper<List> wrapDoc)
86             throws Exception {
87
88         AccountsCommonList accList = new AccountsCommonList();
89         List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
90
91         for (Object obj : wrapDoc.getWrappedObject()) {
92             AccountsCommon account = (AccountsCommon) obj;
93             AccountListItem accListItem = new AccountListItem();
94             accListItem.setScreenName(account.getScreenName());
95             accListItem.setEmail(account.getEmail());
96             accListItem.setFirstName(account.getFirstName());
97             accListItem.setLastName(account.getLastName());
98             String id = account.getCsid();
99             accListItem.setUri(getServiceContextPath() + id);
100             accListItem.setCsid(id);
101             list.add(accListItem);
102         }
103         return accList;
104     }
105
106     @Override
107     public AccountsCommon getCommonPart() {
108         return account;
109     }
110
111     @Override
112     public void setCommonPart(AccountsCommon account) {
113         this.account = account;
114     }
115
116     @Override
117     public AccountsCommonList getCommonPartList() {
118         return accountList;
119     }
120
121     @Override
122     public void setCommonPartList(AccountsCommonList accountList) {
123         this.accountList = accountList;
124     }
125
126     @Override
127     public String getQProperty(
128             String prop) {
129         return null;
130     }
131 }