]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
bdc735a85db346021d0d8af5fe1d6efc3463f5d4
[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.account.Status;
32 import org.collectionspace.services.common.document.AbstractDocumentHandler;
33 import org.collectionspace.services.common.document.DocumentWrapper;
34 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
35
36 /**
37  *
38  * @author 
39  */
40 public class AccountDocumentHandler
41         extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
42
43     private AccountsCommon account;
44     private AccountsCommonList accountList;
45
46     @Override
47     public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
48         String id = UUID.randomUUID().toString();
49         AccountsCommon account = wrapDoc.getWrappedObject();
50         account.setCsid(id);
51         account.setStatus(Status.ACTIVE);
52     }
53
54     @Override
55     public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
56     }
57
58     @Override
59     public void completeUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
60         AccountsCommon upAcc = wrapDoc.getWrappedObject();
61         getServiceContext().setOutput(account);
62         sanitize(upAcc);
63     }
64
65     @Override
66     public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
67         setCommonPart(extractCommonPart(wrapDoc));
68         sanitize(getCommonPart());
69         getServiceContext().setOutput(account);
70     }
71
72     @Override
73     public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
74         AccountsCommonList accList = extractCommonPartList(wrapDoc);
75         setCommonPartList(accList);
76         getServiceContext().setOutput(getCommonPartList());
77     }
78
79     @Override
80     public AccountsCommon extractCommonPart(
81             DocumentWrapper<AccountsCommon> wrapDoc)
82             throws Exception {
83         return wrapDoc.getWrappedObject();
84     }
85
86     @Override
87     public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
88             throws Exception {
89         throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
90     }
91
92     @Override
93     public AccountsCommonList extractCommonPartList(
94             DocumentWrapper<List> wrapDoc)
95             throws Exception {
96
97         AccountsCommonList accList = new AccountsCommonList();
98         List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
99
100         for (Object obj : wrapDoc.getWrappedObject()) {
101             AccountsCommon account = (AccountsCommon) obj;
102             AccountListItem accListItem = new AccountListItem();
103             accListItem.setScreenName(account.getScreenName());
104             accListItem.setEmail(account.getEmail());
105             accListItem.setFirstName(account.getFirstName());
106             accListItem.setLastName(account.getLastName());
107             accListItem.setStatus(account.getStatus());
108             String id = account.getCsid();
109             accListItem.setUri(getServiceContextPath() + id);
110             accListItem.setCsid(id);
111             list.add(accListItem);
112         }
113         return accList;
114     }
115
116     @Override
117     public AccountsCommon getCommonPart() {
118         return account;
119     }
120
121     @Override
122     public void setCommonPart(AccountsCommon account) {
123         this.account = account;
124     }
125
126     @Override
127     public AccountsCommonList getCommonPartList() {
128         return accountList;
129     }
130
131     @Override
132     public void setCommonPartList(AccountsCommonList accountList) {
133         this.accountList = accountList;
134     }
135
136     @Override
137     public String getQProperty(
138             String prop) {
139         return null;
140     }
141
142     /**
143      * sanitize removes data not needed to be sent to the consumer
144      * @param account
145      */
146     private void sanitize(AccountsCommon account) {
147         account.setTenantid("");
148         account.setPassword(null);
149     }
150 }