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.common.document.AbstractDocumentHandler;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
39 public class AccountDocumentHandler
40 extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
42 private AccountsCommon account;
43 private AccountsCommonList accountList;
46 public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
47 String id = UUID.randomUUID().toString();
48 AccountsCommon account = wrapDoc.getWrappedObject();
53 public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
54 getServiceContext().setOutput(getCommonPart());
58 public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
59 setCommonPart(extractCommonPart(wrapDoc));
60 getServiceContext().setOutput(getCommonPart());
64 public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
65 AccountsCommonList accList = extractCommonPartList(wrapDoc);
66 setCommonPartList(accList);
67 getServiceContext().setOutput(getCommonPartList());
71 public AccountsCommon extractCommonPart(
72 DocumentWrapper<AccountsCommon> wrapDoc)
74 return wrapDoc.getWrappedObject();
78 public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
80 throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
84 public AccountsCommonList extractCommonPartList(
85 DocumentWrapper<List> wrapDoc)
88 AccountsCommonList accList = new AccountsCommonList();
89 List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
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);
107 public AccountsCommon getCommonPart() {
112 public void setCommonPart(AccountsCommon account) {
113 this.account = account;
117 public AccountsCommonList getCommonPartList() {
122 public void setCommonPartList(AccountsCommonList accountList) {
123 this.accountList = accountList;
127 public String getQProperty(