]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
33be18a03c0e00a1eecfe96a353bb6586d36849d
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.account.storage;
25
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.List;
29 import java.util.UUID;
30
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;
35
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;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  *
49  * @author 
50  */
51 public class TenantDocumentHandler
52         extends JpaDocumentHandler<Tenant, TenantsList, Tenant, List> {
53
54     private final Logger logger = LoggerFactory.getLogger(AccountDocumentHandler.class);
55     private Tenant tenant;
56     private TenantsList tenantList;
57
58     @Override
59     public void handleCreate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
60     }
61
62     @Override
63     public void handleUpdate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
64     }
65
66     @Override
67     public void completeUpdate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
68         Tenant upAcc = wrapDoc.getWrappedObject();
69         getServiceContext().setOutput(upAcc);
70     }
71
72     @Override
73     public void handleGet(DocumentWrapper<Tenant> wrapDoc) throws Exception {
74         setCommonPart(extractCommonPart(wrapDoc));
75         getServiceContext().setOutput(tenant);
76     }
77
78     @Override
79     public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
80         TenantsList tenList = extractCommonPartList(wrapDoc);
81         setCommonPartList(tenList);
82         getServiceContext().setOutput(getCommonPartList());
83     }
84
85     @Override
86     public Tenant extractCommonPart(
87             DocumentWrapper<Tenant> wrapDoc)
88             throws Exception {
89         return wrapDoc.getWrappedObject();
90     }
91
92     @Override
93     public void fillCommonPart(Tenant obj, DocumentWrapper<Tenant> wrapDoc)
94             throws Exception {
95         throw new UnsupportedOperationException("operation not relevant for TenantDocumentHandler");
96     }
97
98     @Override
99     public TenantsList extractCommonPartList(
100             DocumentWrapper<List> wrapDoc)
101             throws Exception {
102
103         TenantsList tenList = this.extractPagingInfo(new TenantsList(), wrapDoc);
104 //        TenantsList accList = new TenantsList();
105         List<TenantListItem> list = tenList.getTenantListItem();
106
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);
114         }
115         return tenList;
116     }
117
118     @Override
119     public Tenant getCommonPart() {
120         return tenant;
121     }
122
123     @Override
124     public void setCommonPart(Tenant tenant) {
125         this.tenant = tenant;
126     }
127
128     @Override
129     public TenantsList getCommonPartList() {
130         return tenantList;
131     }
132
133     @Override
134     public void setCommonPartList(TenantsList tenantList) {
135         this.tenantList = tenantList;
136     }
137
138     @Override
139     public String getQProperty(
140             String prop) {
141         return null;
142     }
143
144     @Override
145     public DocumentFilter createDocumentFilter() {
146         DocumentFilter filter = new TenantJpaFilter(this.getServiceContext());
147         return filter;
148     }
149
150     /* (non-Javadoc)
151      * @see org.collectionspace.services.common.document.DocumentHandler#initializeDocumentFilter(org.collectionspace.services.common.context.ServiceContext)
152      */
153     public void initializeDocumentFilter(ServiceContext ctx) {
154         // set a default document filter in this method
155     }
156 }