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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.account.storage;
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;
40 public class AccountDocumentHandler
41 extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
43 private AccountsCommon account;
44 private AccountsCommonList accountList;
47 public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
48 String id = UUID.randomUUID().toString();
49 AccountsCommon account = wrapDoc.getWrappedObject();
51 account.setStatus(Status.ACTIVE);
55 public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
59 public void completeUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
60 AccountsCommon upAcc = wrapDoc.getWrappedObject();
61 getServiceContext().setOutput(account);
66 public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
67 setCommonPart(extractCommonPart(wrapDoc));
68 sanitize(getCommonPart());
69 getServiceContext().setOutput(account);
73 public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
74 AccountsCommonList accList = extractCommonPartList(wrapDoc);
75 setCommonPartList(accList);
76 getServiceContext().setOutput(getCommonPartList());
80 public AccountsCommon extractCommonPart(
81 DocumentWrapper<AccountsCommon> wrapDoc)
83 return wrapDoc.getWrappedObject();
87 public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
89 throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
93 public AccountsCommonList extractCommonPartList(
94 DocumentWrapper<List> wrapDoc)
97 AccountsCommonList accList = new AccountsCommonList();
98 List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
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);
117 public AccountsCommon getCommonPart() {
122 public void setCommonPart(AccountsCommon account) {
123 this.account = account;
127 public AccountsCommonList getCommonPartList() {
132 public void setCommonPartList(AccountsCommonList accountList) {
133 this.accountList = accountList;
137 public String getQProperty(
143 * sanitize removes data not needed to be sent to the consumer
146 private void sanitize(AccountsCommon account) {
147 account.setTenantid("");
148 account.setPassword(null);