View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.document.service;
35  
36  import fr.paris.lutece.plugins.document.business.DocumentType;
37  import fr.paris.lutece.plugins.document.business.DocumentTypeHome;
38  import fr.paris.lutece.portal.service.rbac.Permission;
39  import fr.paris.lutece.portal.service.rbac.ResourceIdService;
40  import fr.paris.lutece.portal.service.rbac.ResourceType;
41  import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
42  import fr.paris.lutece.util.ReferenceList;
43  
44  import java.util.Locale;
45  
46  
47  /**
48   * Resource Id service for RBAC features to control access to document depending their type
49   */
50  public class DocumentTypeResourceIdService extends ResourceIdService
51  {
52      /** Permission for creating a document */
53      public static final String PERMISSION_CREATE = "CREATE";
54  
55      /** Permission for viewing a document */
56      public static final String PERMISSION_VIEW = "VIEW";
57  
58      /** Permission for deleting a document */
59      public static final String PERMISSION_DELETE = "DELETE";
60  
61      /** Permission for modifying a document */
62      public static final String PERMISSION_MODIFY = "MODIFY";
63  
64      /** Permission for modifying a document */
65      public static final String PERMISSION_CHANGE = "CHANGE";
66  
67      /** Permission for moving a document */
68      public static final String PERMISSION_MOVE = "MOVE";
69  
70      /** Permission for validating a document */
71      public static final String PERMISSION_VALIDATE = "VALIDATE";
72  
73      /** Permission for submiting a document */
74      public static final String PERMISSION_SUBMIT = "SUBMIT";
75  
76      /** Permission for archiving a document */
77      public static final String PERMISSION_ARCHIVE = "ARCHIVE";
78  
79      /** Permission for publishing a document */
80      public static final String PERMISSION_PUBLISH = "PUBLISH";
81  
82      /** Permission for assigning a document */
83      public static final String PERMISSION_ASSIGN = "ASSIGN";
84  
85      /** Permission for viewing a space history */
86      public static final String PERMISSION_VIEW_HISTORY = "VIEW_HISTORY";
87      private static final String PROPERTY_LABEL_RESOURCE_TYPE = "document.workflow.resourceType";
88      private static final String PROPERTY_LABEL_CREATE = "document.workflow.permission.label.create";
89      private static final String PROPERTY_LABEL_VIEW = "document.workflow.permission.label.view";
90      private static final String PROPERTY_LABEL_DELETE = "document.workflow.permission.label.delete";
91      private static final String PROPERTY_LABEL_MODIFY = "document.workflow.permission.label.modify";
92      private static final String PROPERTY_LABEL_CHANGE = "document.workflow.permission.label.change";
93      private static final String PROPERTY_LABEL_MOVE = "document.workflow.permission.label.move";
94      private static final String PROPERTY_LABEL_VALIDATE = "document.workflow.permission.label.validate";
95      private static final String PROPERTY_LABEL_SUBMIT = "document.workflow.permission.label.submit";
96      private static final String PROPERTY_LABEL_ARCHIVE = "document.workflow.permission.label.archive";
97      private static final String PROPERTY_LABEL_PUBLISH = "document.workflow.permission.label.publish";
98      private static final String PROPERTY_LABEL_ASSIGN = "document.workflow.permission.label.assign";
99      private static final String PROPERTY_LABEL_VIEW_HISTORY = "document.workflow.permission.label.viewHistory";
100     private static final String PLUGIN_NAME = "document";
101 
102     /** Creates a new instance of DocumentTypeResourceIdService */
103     public DocumentTypeResourceIdService(  )
104     {
105         setPluginName( PLUGIN_NAME );
106     }
107 
108     /**
109      * Initializes the service
110      */
111     public void register(  )
112     {
113         ResourceType rt = new ResourceType(  );
114         rt.setResourceIdServiceClass( DocumentTypeResourceIdService.class.getName(  ) );
115         rt.setPluginName( PLUGIN_NAME );
116         rt.setResourceTypeKey( DocumentType.RESOURCE_TYPE );
117         rt.setResourceTypeLabelKey( PROPERTY_LABEL_RESOURCE_TYPE );
118 
119         Permission p = new Permission(  );
120         p.setPermissionKey( PERMISSION_CREATE );
121         p.setPermissionTitleKey( PROPERTY_LABEL_CREATE );
122         rt.registerPermission( p );
123 
124         p = new Permission(  );
125         p.setPermissionKey( PERMISSION_VIEW );
126         p.setPermissionTitleKey( PROPERTY_LABEL_VIEW );
127         rt.registerPermission( p );
128 
129         p = new Permission(  );
130         p.setPermissionKey( PERMISSION_DELETE );
131         p.setPermissionTitleKey( PROPERTY_LABEL_DELETE );
132         rt.registerPermission( p );
133 
134         p = new Permission(  );
135         p.setPermissionKey( PERMISSION_MODIFY );
136         p.setPermissionTitleKey( PROPERTY_LABEL_MODIFY );
137         rt.registerPermission( p );
138 
139         p = new Permission(  );
140         p.setPermissionKey( PERMISSION_CHANGE );
141         p.setPermissionTitleKey( PROPERTY_LABEL_CHANGE );
142         rt.registerPermission( p );
143 
144         p = new Permission(  );
145         p.setPermissionKey( PERMISSION_MOVE );
146         p.setPermissionTitleKey( PROPERTY_LABEL_MOVE );
147         rt.registerPermission( p );
148 
149         p = new Permission(  );
150         p.setPermissionKey( PERMISSION_VALIDATE );
151         p.setPermissionTitleKey( PROPERTY_LABEL_VALIDATE );
152         rt.registerPermission( p );
153 
154         p = new Permission(  );
155         p.setPermissionKey( PERMISSION_SUBMIT );
156         p.setPermissionTitleKey( PROPERTY_LABEL_SUBMIT );
157         rt.registerPermission( p );
158 
159         p = new Permission(  );
160         p.setPermissionKey( PERMISSION_ARCHIVE );
161         p.setPermissionTitleKey( PROPERTY_LABEL_ARCHIVE );
162         rt.registerPermission( p );
163 
164         p = new Permission(  );
165         p.setPermissionKey( PERMISSION_PUBLISH );
166         p.setPermissionTitleKey( PROPERTY_LABEL_PUBLISH );
167         rt.registerPermission( p );
168 
169         p = new Permission(  );
170         p.setPermissionKey( PERMISSION_ASSIGN );
171         p.setPermissionTitleKey( PROPERTY_LABEL_ASSIGN );
172         rt.registerPermission( p );
173 
174         p = new Permission(  );
175         p.setPermissionKey( PERMISSION_VIEW_HISTORY );
176         p.setPermissionTitleKey( PROPERTY_LABEL_VIEW_HISTORY );
177         rt.registerPermission( p );
178 
179         ResourceTypeManager.registerResourceType( rt );
180     }
181 
182     /**
183      * Returns a list of resource ids
184      * @param locale The current locale
185      * @return A list of resource ids
186      */
187     public ReferenceList getResourceIdList( Locale locale )
188     {
189         return DocumentTypeHome.getDocumentTypesList(  );
190     }
191 
192     /**
193      * Returns the Title of a given resource
194      * @param strId The Id of the resource
195      * @param locale The current locale
196      * @return The Title of a given resource
197      */
198     public String getTitle( String strId, Locale locale )
199     {
200         DocumentType type = DocumentTypeHome.findByPrimaryKey( strId );
201 
202         return type.getName(  );
203     }
204 }