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.Date;
28 import java.util.List;
29 import java.util.UUID;
31 import org.apache.commons.lang.StringUtils;
32 import org.collectionspace.services.account.Tenant;
33 import org.collectionspace.services.account.TenantsList;
34 import org.collectionspace.services.account.TenantListItem;
36 import org.collectionspace.services.client.TenantClient;
37 import org.collectionspace.services.common.storage.jpa.JpaDocumentHandler;
38 import org.collectionspace.services.common.context.ServiceContext;
39 import org.collectionspace.services.common.document.DocumentFilter;
40 import org.collectionspace.services.common.document.DocumentWrapper;
41 import org.collectionspace.services.common.document.JaxbUtils;
42 import org.collectionspace.services.common.security.SecurityUtils;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
51 public class TenantDocumentHandler
52 extends JpaDocumentHandler<Tenant, TenantsList, Tenant, List> {
54 private final Logger logger = LoggerFactory.getLogger(AccountDocumentHandler.class);
55 private Tenant tenant;
56 private TenantsList tenantList;
59 public void handleCreate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
63 public void handleUpdate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
67 public void completeUpdate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
68 Tenant upAcc = wrapDoc.getWrappedObject();
69 getServiceContext().setOutput(upAcc);
73 public void handleGet(DocumentWrapper<Tenant> wrapDoc) throws Exception {
74 setCommonPart(extractCommonPart(wrapDoc));
75 getServiceContext().setOutput(tenant);
79 public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
80 TenantsList tenList = extractCommonPartList(wrapDoc);
81 setCommonPartList(tenList);
82 getServiceContext().setOutput(getCommonPartList());
86 public Tenant extractCommonPart(
87 DocumentWrapper<Tenant> wrapDoc)
89 return wrapDoc.getWrappedObject();
93 public void fillCommonPart(Tenant obj, DocumentWrapper<Tenant> wrapDoc)
95 throw new UnsupportedOperationException("operation not relevant for TenantDocumentHandler");
99 public TenantsList extractCommonPartList(
100 DocumentWrapper<List> wrapDoc)
103 TenantsList tenList = this.extractPagingInfo(new TenantsList(), wrapDoc);
104 // TenantsList accList = new TenantsList();
105 List<TenantListItem> list = tenList.getTenantListItem();
107 for (Object obj : wrapDoc.getWrappedObject()) {
108 Tenant tenant = (Tenant) obj;
109 TenantListItem tenListItem = new TenantListItem();
110 tenListItem.setId(tenant.getId());
111 tenListItem.setName(tenant.getName());
112 tenListItem.setDisabled(tenant.isDisabled());
113 list.add(tenListItem);
119 public Tenant getCommonPart() {
124 public void setCommonPart(Tenant tenant) {
125 this.tenant = tenant;
129 public TenantsList getCommonPartList() {
134 public void setCommonPartList(TenantsList tenantList) {
135 this.tenantList = tenantList;
139 public String getQProperty(
145 public DocumentFilter createDocumentFilter() {
146 DocumentFilter filter = new TenantJpaFilter(this.getServiceContext());
151 * @see org.collectionspace.services.common.document.DocumentHandler#initializeDocumentFilter(org.collectionspace.services.common.context.ServiceContext)
153 public void initializeDocumentFilter(ServiceContext ctx) {
154 // set a default document filter in this method