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.ArrayList;
27 import java.util.List;
28 import java.util.UUID;
29 import org.collectionspace.services.account.AccountsCommon;
30 import org.collectionspace.services.account.AccountsCommon.Tenant;
31 import org.collectionspace.services.account.AccountsCommonList;
32 import org.collectionspace.services.account.AccountsCommonList.AccountListItem;
33 import org.collectionspace.services.account.Status;
34 import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;
35 import org.collectionspace.services.common.document.DocumentFilter;
36 import org.collectionspace.services.common.document.DocumentWrapper;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
44 public class AccountDocumentHandler
45 extends AbstractDocumentHandlerImpl<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
47 private final Logger logger = LoggerFactory.getLogger(AccountDocumentHandler.class);
48 private AccountsCommon account;
49 private AccountsCommonList accountList;
52 public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
53 String id = UUID.randomUUID().toString();
54 AccountsCommon account = wrapDoc.getWrappedObject();
57 account.setStatus(Status.ACTIVE);
61 public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
65 public void completeUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
66 AccountsCommon upAcc = wrapDoc.getWrappedObject();
67 getServiceContext().setOutput(account);
72 public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
73 setCommonPart(extractCommonPart(wrapDoc));
74 sanitize(getCommonPart());
75 getServiceContext().setOutput(account);
79 public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
80 AccountsCommonList accList = extractCommonPartList(wrapDoc);
81 setCommonPartList(accList);
82 getServiceContext().setOutput(getCommonPartList());
86 public AccountsCommon extractCommonPart(
87 DocumentWrapper<AccountsCommon> wrapDoc)
89 return wrapDoc.getWrappedObject();
93 public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
95 throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
99 public AccountsCommonList extractCommonPartList(
100 DocumentWrapper<List> wrapDoc)
103 AccountsCommonList accList = new AccountsCommonList();
104 List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
106 for (Object obj : wrapDoc.getWrappedObject()) {
107 AccountsCommon account = (AccountsCommon) obj;
108 AccountListItem accListItem = new AccountListItem();
109 accListItem.setScreenName(account.getScreenName());
110 accListItem.setEmail(account.getEmail());
111 accListItem.setStatus(account.getStatus());
112 String id = account.getCsid();
113 accListItem.setUri(getServiceContextPath() + id);
114 accListItem.setCsid(id);
115 list.add(accListItem);
121 public AccountsCommon getCommonPart() {
126 public void setCommonPart(AccountsCommon account) {
127 this.account = account;
131 public AccountsCommonList getCommonPartList() {
136 public void setCommonPartList(AccountsCommonList accountList) {
137 this.accountList = accountList;
141 public String getQProperty(
147 public DocumentFilter createDocumentFilter() {
148 return new AccountJpaFilter();
152 * sanitize removes data not needed to be sent to the consumer
155 private void sanitize(AccountsCommon account) {
156 account.setPassword(null);
157 //FIXME once auth mode is mandatory, assume tenant could be retrieved
158 //from security context, remove tenant info being passed to the consumer
159 //account.setTenant(new ArrayList<Tenant>(0));