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.BadRequestException;
34 import org.collectionspace.services.common.document.DocumentFilter;
35 import org.collectionspace.services.common.document.DocumentWrapper;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
43 public class AccountDocumentHandler
44 extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
46 private final Logger logger = LoggerFactory.getLogger(AccountDocumentHandler.class);
47 private AccountsCommon account;
48 private AccountsCommonList accountList;
51 public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
52 String id = UUID.randomUUID().toString();
53 AccountsCommon account = wrapDoc.getWrappedObject();
55 account.setStatus(Status.ACTIVE);
59 public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
63 public void completeUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
64 AccountsCommon upAcc = wrapDoc.getWrappedObject();
65 getServiceContext().setOutput(account);
70 public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
71 setCommonPart(extractCommonPart(wrapDoc));
72 sanitize(getCommonPart());
73 getServiceContext().setOutput(account);
77 public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
78 AccountsCommonList accList = extractCommonPartList(wrapDoc);
79 setCommonPartList(accList);
80 getServiceContext().setOutput(getCommonPartList());
84 public AccountsCommon extractCommonPart(
85 DocumentWrapper<AccountsCommon> wrapDoc)
87 return wrapDoc.getWrappedObject();
91 public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
93 throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
97 public AccountsCommonList extractCommonPartList(
98 DocumentWrapper<List> wrapDoc)
101 AccountsCommonList accList = new AccountsCommonList();
102 List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
104 for (Object obj : wrapDoc.getWrappedObject()) {
105 AccountsCommon account = (AccountsCommon) obj;
106 AccountListItem accListItem = new AccountListItem();
107 accListItem.setScreenName(account.getScreenName());
108 accListItem.setEmail(account.getEmail());
109 accListItem.setStatus(account.getStatus());
110 String id = account.getCsid();
111 accListItem.setUri(getServiceContextPath() + id);
112 accListItem.setCsid(id);
113 list.add(accListItem);
119 public AccountsCommon getCommonPart() {
124 public void setCommonPart(AccountsCommon account) {
125 this.account = account;
129 public AccountsCommonList getCommonPartList() {
134 public void setCommonPartList(AccountsCommonList accountList) {
135 this.accountList = accountList;
139 public String getQProperty(
145 public DocumentFilter createDocumentFilter() {
146 return new AccountJpaFilter();
150 * sanitize removes data not needed to be sent to the consumer
153 private void sanitize(AccountsCommon account) {
154 account.setPassword(null);