View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de 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.insertajax.business;
35  
36  import fr.paris.lutece.plugins.insertajax.service.InsertAjaxWorkgroupRemovalListener;
37  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
38  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
39  import fr.paris.lutece.portal.service.workgroup.WorkgroupRemovalListenerService;
40  
41  
42  /**
43   * This class represents business object InsertAjax
44   */
45  public class InsertAjax implements AdminWorkgroupResource
46  {
47      /////////////////////////////////////////////////////////////////////////////////
48      // Constants
49      public static final String RESOURCE_TYPE = "INSERTAJAX";
50      public static final String ROLE_NONE = "none";
51  	private static final String ID_PRIMARY_KEY = "ID_PRIMARY_KEY";
52      private static InsertAjaxWorkgroupRemovalListener _listenerWorkgroup;
53      private int _nId;
54      private String _strName;
55      private String _strHtml;
56      private String _strSql;
57      private String _strWorkgroupKey;
58      private String _strAdminWorkgroup;
59      private String _strRole;
60  
61      /** Creates a new instance of InsertAjax */
62      public InsertAjax(  )
63      {
64      }
65  
66      /**
67      * Initialize the InsertAjaxList
68      */
69      public static void init(  )
70      {
71          // Create removal listeners and register them
72          if ( _listenerWorkgroup == null )
73          {
74              _listenerWorkgroup = new InsertAjaxWorkgroupRemovalListener(  );
75              WorkgroupRemovalListenerService.getService(  ).registerListener( _listenerWorkgroup );
76          }
77      }
78  
79      /**
80       * getters and setters
81       */
82      public int getId(  )
83      {
84          return _nId;
85      }
86  
87      public void setId( int nId )
88      {
89          _nId = nId;
90      }
91  
92      public String getName(  )
93      {
94          return _strName;
95      }
96  
97      public void setName( String name )
98      {
99          _strName = name;
100     }
101 
102     public String getHtml(  )
103     {
104         return _strHtml;
105     }
106 
107     public void setHtml( String html )
108     {
109         _strHtml = html;
110     }
111 
112     public String getSql(  )
113     {
114         return _strSql;
115     }
116 
117     public void setSql( String sql )
118     {
119         _strSql = sql;
120     }
121 
122     ////////////////////////////////////////////////////////////////////////////////////////
123     // Workgtoup management
124 
125     /**
126      * Return the WorkgroupKey Contact Label
127      * @return The label of the selected Workgroup Key
128      */
129     public String getWorkgroupKey(  )
130     {
131         return _strWorkgroupKey;
132     }
133 
134     /**
135      * Sets the description of the Contact with the specified String
136      * @param strWorkgroupKey The workgroup key
137      */
138     public void setWorkgroupKey( String strWorkgroupKey )
139     {
140         _strWorkgroupKey = strWorkgroupKey;
141     }
142 
143     /**
144      * Returns the workgroup
145      * @return The workgroup
146      */
147     public String getWorkgroup(  )
148     {
149         return _strAdminWorkgroup;
150     }
151 
152     /**
153      * Sets the workgroup
154      * @param strAdminWorkgroup The workgroup
155      */
156     public void setWorkgroup( String strAdminWorkgroup )
157     {
158         _strAdminWorkgroup = AdminWorkgroupService.normalizeWorkgroupKey( strAdminWorkgroup );
159     }
160 
161     public String getRole(  )
162     {
163         return _strRole;
164     }
165 
166     public void setRole( String role )
167     {
168         _strRole = role;
169     }
170 
171     /**
172      * The javascript generated for a linkservice can use the DB id from the insertajax
173      * But we don't know it in advance. This method subtitute the ID_PRIMARY_KEY string 
174      * with the one given by the database.
175      * @param id
176      */
177 	public void replacePrimaryKey(int id)
178 	{
179 		String html = getHtml();
180 		html = html.replaceAll(ID_PRIMARY_KEY, id+"");
181 		setHtml(html);
182 	}
183 }