View Javadoc

1   /*
2       Copyright (C) 2004 PjEr
3       
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8       
9       This program is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU General Public License for more details.
13      
14      You should have received a copy of the GNU General Public License
15      along with this program; if not, write to the Free Software
16      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18  package ca.pjer.cm.module.cmf.defaultimpl;
19  
20  import ca.pjer.cm.api.access.*;
21  import ca.pjer.cm.api.cmf.ContentManagementService;
22  import ca.pjer.cm.api.store.DuplicateObjectException;
23  import ca.pjer.cm.api.store.ObjectNotFoundException;
24  import ca.pjer.cm.api.store.StoreService;
25  import ca.pjer.cm.api.store.StoreServiceSystemException;
26  import ca.pjer.cm.api.metadata.MetaDataServiceSystemException;
27  import ca.pjer.cm.api.metadata.MetaDataNotFoundException;
28  import ca.pjer.cm.api.metadata.MetaDataService;
29  import ca.pjer.cm.api.metadata.MetaData;
30  
31  import java.io.Serializable;
32  import java.util.List;
33  
34  /***
35   * Default implementation of ContentManagementService that delegate request to AccessService and StoreService.<br />
36   * <br />
37   * $Id: ContentManagementServiceImpl.java,v 1.2 2004/05/19 03:29:17 pjer Exp $<br />
38   * <br />
39   * $RCSfile: ContentManagementServiceImpl.java,v $<br />
40   * $Revision: 1.2 $<br />
41   * $Author: pjer $<br />
42   * $Date: 2004/05/19 03:29:17 $<br />
43   */
44  public class ContentManagementServiceImpl implements ContentManagementService {
45      private AccessService accessService;
46      private StoreService storeService;
47      private MetaDataService metaDataService;
48  
49      public void setAccessService(AccessService accessService) {
50          this.accessService = accessService;
51      }
52  
53      public void setStoreService(StoreService storeService) {
54          this.storeService = storeService;
55      }
56  
57      public void setMetaDataService(MetaDataService metaDataService) {
58          this.metaDataService = metaDataService;
59      }
60  
61      public AccessToken getAccessToken(AccessCredential accessCredential)
62              throws AccessServiceSystemException, InvalidAccessCredentialException {
63          return accessService.getAccessToken(accessCredential);
64      }
65  
66      public boolean hasAccess(AccessToken accessToken, Permission permission, Class clazz)
67              throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException {
68          return accessService.hasAccess(accessToken, permission, clazz);
69      }
70  
71      public Object createObject(AccessToken accessToken, Object object)
72              throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException,
73              StoreServiceSystemException, DuplicateObjectException {
74          if (!accessService.hasAccess(accessToken, Permission.CREATE, object.getClass())) {
75              throw new InsufficientRightsException("Insufficient rights to create " + object.getClass().getName());
76          }
77          return storeService.create(object);
78      }
79  
80      public Object updateObject(AccessToken accessToken, Object object)
81              throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException,
82              StoreServiceSystemException, ObjectNotFoundException {
83          if (!accessService.hasAccess(accessToken, Permission.UPDATE, object.getClass())) {
84              throw new InsufficientRightsException("Insufficient rights to update " + object.getClass().getName());
85          }
86          return storeService.update(object);
87      }
88  
89      public Object getObject(AccessToken accessToken, Class clazz, Serializable id)
90              throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException,
91              StoreServiceSystemException, ObjectNotFoundException {
92          if (!accessService.hasAccess(accessToken, Permission.READ, clazz)) {
93              throw new InsufficientRightsException("Insufficient rights to get " + clazz.getName());
94          }
95          return storeService.get(clazz, id);
96      }
97  
98      public List listObjects(AccessToken accessToken, Class clazz)
99              throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException,
100             StoreServiceSystemException {
101         if (!accessService.hasAccess(accessToken, Permission.READ, clazz)) {
102             throw new InsufficientRightsException("Insufficient rights to list " + clazz.getName());
103         }
104         return storeService.list(clazz);
105     }
106 
107     public List listObjectsFromTemplate(AccessToken accessToken, Object template)
108             throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException,
109             StoreServiceSystemException {
110         if (!accessService.hasAccess(accessToken, Permission.READ, template.getClass())) {
111             throw new InsufficientRightsException("Insufficient rights to list " + template.getClass().getName());
112         }
113         return storeService.listFromTemplate(template);
114     }
115 
116     public void removeObject(AccessToken accessToken, Object object)
117             throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException,
118             StoreServiceSystemException, ObjectNotFoundException {
119         if (!accessService.hasAccess(accessToken, Permission.REMOVE, object.getClass())) {
120             throw new InsufficientRightsException("Insufficient rights to remove " + object.getClass().getName());
121         }
122         storeService.remove(object);
123     }
124 
125     public MetaData getMetaData(AccessToken accessToken, Class clazz) throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException, MetaDataServiceSystemException, MetaDataNotFoundException {
126         // TODO check permission before delegate. filter ?
127         return metaDataService.get(clazz);
128     }
129 
130     public List listRootMetaData(AccessToken accessToken) throws AccessServiceSystemException, InvalidAccessTokenException, InsufficientRightsException, MetaDataServiceSystemException {
131         // TODO check permission before delegate. filter ?
132         return metaDataService.listRoot();
133     }
134 }