View Javadoc
1   /*
2    * Copyright (c) 2002-2025, 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.pluginwizard.business.model;
35  
36  import org.apache.commons.lang3.StringUtils;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  import java.util.Locale;
41  
42  import javax.validation.constraints.NotEmpty;
43  import javax.validation.constraints.Pattern;
44  import javax.validation.constraints.Size;
45  
46  import org.hibernate.validator.constraints.URL;
47  
48  import com.fasterxml.jackson.annotation.JsonIgnore;
49  
50  /**
51   * This is the business class for the object PluginModel
52   */
53  public class PluginModel
54  {
55      // Variables declarations
56      private int _nIdPlugin;
57      private String _strPluginName;
58      private String _strPluginClass;
59      @NotEmpty( message = "pluginwizard.error.plugin.description.notEmpty" )
60      @Size( min = 5, max = 255, message = "pluginwizard.error.plugin.description.size" )
61      private String _strPluginDescription;
62      private String _strPluginDocumentation;
63      private String _strType;
64      private String _strPluginInstallation;
65      private String _strPluginChanges;
66      private String _strPluginUserGuide;
67      @NotEmpty( message = "pluginwizard.error.plugin.version.notEmpty" )
68      @Pattern( regexp = "[0-9].[0-9].[0-9]", message = "pluginwizard.error.plugin.version.pattern" )
69      private String _strPluginVersion;
70      @NotEmpty( message = "pluginwizard.error.plugin.copyright.notEmpty" )
71      private String _strPluginCopyright;
72      private String _strPluginIconUrl;
73      @NotEmpty( message = "pluginwizard.error.plugin.provider.notEmpty" )
74      @Size( min = 5, max = 255, message = "pluginwizard.error.plugin.description.size" )
75      private String _strPluginProvider;
76      @NotEmpty( message = "pluginwizard.error.plugin.urlProvider.notEmpty" )
77      @URL( message = "pluginwizard.error.plugin.urlProvider.url" )
78      private String _strPluginProviderUrl;
79      private String _strPluginDbPoolRequired;
80      private Locale _locale;
81      private List<Application> _listPluginApplications;
82      private List<Feature> _listPluginFeatures;
83      private List<Portlet> _listPluginPortlets;
84      private List<BusinessClass> _listBusinessClasses;
85      private Rest _rest;
86      private Configuration _configuration;
87      private boolean _bIsModule;
88  
89      /**
90       *
91       */
92      public PluginModel( )
93      {
94          _listPluginApplications = new ArrayList<>( );
95          _listPluginFeatures = new ArrayList<>( );
96          _listPluginPortlets = new ArrayList<>( );
97          _listBusinessClasses = new ArrayList<>( );
98          _rest = new Rest( );
99          _configuration = new Configuration( );
100     }
101 
102     /**
103      * Returns the IdPlugin
104      * 
105      * @return The IdPlugin
106      */
107     public int getIdPlugin( )
108     {
109         return _nIdPlugin;
110     }
111 
112     /**
113      * Sets the IdPlugin
114      * 
115      * @param nIdPlugin
116      *            The IdPlugin
117      */
118     public void setIdPlugin( int nIdPlugin )
119     {
120         _nIdPlugin = nIdPlugin;
121     }
122 
123     /**
124      * Returns the PluginName
125      * 
126      * @return The PluginName
127      */
128     public String getPluginName( )
129     {
130         return _strPluginName;
131     }
132 
133     /**
134      * Returns the Plugin or Module name formatted with dots as package
135      * 
136      * @return The PluginName
137      */
138     @JsonIgnore
139     public String getPluginNameAsRadicalPackage( )
140     {
141         if ( isModule( ) )
142         {
143             return _strPluginName.split( "-" ) [0] + ".modules." + _strPluginName.split( "-" ) [1];
144         }
145         else if ( isWorkflowTask( ) ) 
146 		{
147 			return "workflow.modules." + _strPluginName;
148 		} 
149         else
150         {
151             return _strPluginName;
152         }
153     }
154 
155     /**
156      * Returns the Plugin or Module name formatted with slashes as Path
157      *
158      * @return The PluginName
159      */
160     @JsonIgnore
161     public String getPluginNameAsRadicalPath( )
162     {
163         if ( isModule( ) )
164         {
165             return _strPluginName.split( "-" ) [0] + "/modules/" + _strPluginName.split( "-" ) [1];
166         }
167         else if ( isWorkflowTask( ) ) 
168 		{
169 			return "workflow/modules/" + _strPluginName;
170 		} 
171         else
172         {
173             return _strPluginName;
174         }
175     }
176 
177     /**
178      * Returns the Plugin or Module name for i18n keys
179      * 
180      * @return The PluginName
181      */
182     @JsonIgnore
183     public String getPluginNameAsPackage( )
184     {
185         if ( isModule( ) )
186         {
187             return "module." + _strPluginName.replace( "-", "." );
188         }
189         else if ( isWorkflowTask( ) ) 
190 		{
191 			return "module." + _strPluginName;
192 		} 
193         else
194         {
195             return _strPluginName;
196         }
197     }
198 
199     /**
200      * Returns the Plugin or Module name for Ressource
201      * 
202      * @return The PluginName
203      */
204     @JsonIgnore
205     public String getPluginNameForRessource( )
206     {
207         if ( isModule( ) )
208         {
209             return getModuleName( ).toLowerCase( );
210         } 
211         else
212         {
213             return _strPluginName.toLowerCase( );
214         }
215 
216     }
217 
218     /**
219      * Returns the workflow task name with prefix workflow
220      * 
221      * @return "workflow taskname"
222      */
223     @JsonIgnore
224     public String getWorkflowNameWithPrefix( )
225     {
226     	return "workflow." + _strPluginName.toLowerCase( );
227     }
228 
229     /**
230      * Returns the Plugin or Module name
231      * 
232      * @return The PluginName
233      */
234     @JsonIgnore
235     public String getModuleName( )
236     {
237         if ( isModule( ) )
238         {
239             return getPluginName( ).split( "-" ) [1];
240         }
241         else
242         {
243             return "";
244         }
245     }
246 
247     /**
248      * Sets the PluginName
249      * 
250      * @param strPluginName
251      *            The PluginName
252      */
253     public void setPluginName( String strPluginName )
254     {
255         _strPluginName = strPluginName;
256     }
257 
258     /**
259      * Returns the PluginClass
260      * 
261      * @return The PluginClass
262      */
263     public String getPluginClass( )
264     {
265         return _strPluginClass;
266     }
267 
268     /**
269      * Sets the PluginClass
270      * 
271      * @param strPluginClass
272      *            The PluginClass
273      */
274     public void setPluginClass( String strPluginClass )
275     {
276         _strPluginClass = strPluginClass;
277     }
278 
279     /**
280      * Returns the PluginDescription
281      * 
282      * @return The PluginDescription
283      */
284     public String getPluginDescription( )
285     {
286         return _strPluginDescription;
287     }
288 
289     /**
290      * Sets the PluginDescription
291      * 
292      * @param strPluginDescription
293      *            The PluginDescription
294      */
295     public void setPluginDescription( String strPluginDescription )
296     {
297         _strPluginDescription = strPluginDescription;
298     }
299 
300     /**
301      * Returns the PluginDocumentation
302      * 
303      * @return The PluginDocumentation
304      */
305     public String getPluginDocumentation( )
306     {
307         return _strPluginDocumentation;
308     }
309 
310     /**
311      * Sets the PluginDocumentation
312      * 
313      * @param strPluginDocumentation
314      *            The PluginDocumentation
315      */
316     public void setPluginDocumentation( String strPluginDocumentation )
317     {
318         _strPluginDocumentation = strPluginDocumentation;
319     }
320 
321     /**
322      * Returns the PluginInstallation
323      * 
324      * @return The PluginInstallation
325      */
326     public String getPluginInstallation( )
327     {
328         return _strPluginInstallation;
329     }
330 
331     /**
332      * Sets the PluginInstallation
333      * 
334      * @param strPluginInstallation
335      *            The PluginInstallation
336      */
337     public void setPluginInstallation( String strPluginInstallation )
338     {
339         _strPluginInstallation = strPluginInstallation;
340     }
341 
342     /**
343      * Returns the PluginChanges
344      * 
345      * @return The PluginChanges
346      */
347     public String getPluginChanges( )
348     {
349         return _strPluginChanges;
350     }
351 
352     /**
353      * Sets the PluginChanges
354      * 
355      * @param strPluginChanges
356      *            The PluginChanges
357      */
358     public void setPluginChanges( String strPluginChanges )
359     {
360         _strPluginChanges = strPluginChanges;
361     }
362 
363     /**
364      * Returns the PluginUserGuide
365      * 
366      * @return The PluginUserGuide
367      */
368     public String getPluginUserGuide( )
369     {
370         return _strPluginUserGuide;
371     }
372 
373     /**
374      * Sets the PluginUserGuide
375      * 
376      * @param strPluginUserGuide
377      *            The PluginUserGuide
378      */
379     public void setPluginUserGuide( String strPluginUserGuide )
380     {
381         _strPluginUserGuide = strPluginUserGuide;
382     }
383 
384     /**
385      * Returns the PluginVersion
386      * 
387      * @return The PluginVersion
388      */
389     public String getPluginVersion( )
390     {
391         return _strPluginVersion;
392     }
393 
394     /**
395      * Sets the PluginVersion
396      * 
397      * @param strPluginVersion
398      *            The PluginVersion
399      */
400     public void setPluginVersion( String strPluginVersion )
401     {
402         _strPluginVersion = strPluginVersion;
403     }
404 
405     /**
406      * Returns the PluginCopyright
407      * 
408      * @return The PluginCopyright
409      */
410     public String getPluginCopyright( )
411     {
412         return _strPluginCopyright;
413     }
414 
415     /**
416      * Sets the PluginCopyright
417      * 
418      * @param strPluginCopyright
419      *            The PluginCopyright
420      */
421     public void setPluginCopyright( String strPluginCopyright )
422     {
423         _strPluginCopyright = strPluginCopyright;
424     }
425 
426     /**
427      * Returns the PluginIconUrl
428      * 
429      * @return The PluginIconUrl
430      */
431     public String getPluginIconUrl( )
432     {
433         return _strPluginIconUrl;
434     }
435 
436     /**
437      * Sets the PluginIconUrl
438      * 
439      * @param strPluginIconUrl
440      *            The PluginIconUrl
441      */
442     public void setPluginIconUrl( String strPluginIconUrl )
443     {
444         _strPluginIconUrl = strPluginIconUrl;
445     }
446 
447     /**
448      * Returns the PluginProvider
449      * 
450      * @return The PluginProvider
451      */
452     public String getPluginProvider( )
453     {
454         return _strPluginProvider;
455     }
456 
457     /**
458      * Sets the PluginProvider
459      * 
460      * @param strPluginProvider
461      *            The PluginProvider
462      */
463     public void setPluginProvider( String strPluginProvider )
464     {
465         _strPluginProvider = strPluginProvider;
466     }
467 
468     /**
469      * Returns the PluginProviderUrl
470      * 
471      * @return The PluginProviderUrl
472      */
473     public String getPluginProviderUrl( )
474     {
475         return _strPluginProviderUrl;
476     }
477 
478     /**
479      * Sets the PluginProviderUrl
480      * 
481      * @param strPluginProviderUrl
482      *            The PluginProviderUrl
483      */
484     public void setPluginProviderUrl( String strPluginProviderUrl )
485     {
486         _strPluginProviderUrl = strPluginProviderUrl;
487     }
488 
489     /**
490      * Returns the PluginDbPoolRequired
491      * 
492      * @return The PluginDbPoolRequired
493      */
494     public String getPluginDbPoolRequired( )
495     {
496         return _strPluginDbPoolRequired;
497     }
498 
499     /**
500      * Sets the PluginDbPoolRequired
501      * 
502      * @param strPluginDbPoolRequired
503      *            The PluginDbPoolRequired
504      */
505     public void setPluginDbPoolRequired( String strPluginDbPoolRequired )
506     {
507         _strPluginDbPoolRequired = strPluginDbPoolRequired;
508     }
509 
510     /**
511      * Gets the locale of the plugin
512      * 
513      * @return The Locale
514      */
515     public Locale getLocale( )
516     {
517         return _locale;
518     }
519 
520     /**
521      * Gets the locale of the plugin
522      * 
523      * @param locale
524      *            The locale
525      */
526     public void setLocale( Locale locale )
527     {
528         _locale = locale;
529     }
530 
531     /**
532      * Sets the list of plugin applications
533      * 
534      * @param listPluginApplications
535      *            The list of plugin applications
536      */
537     public void setApplications( List<Application> listPluginApplications )
538     {
539         if ( listPluginApplications != null )
540         {
541             _listPluginApplications = new ArrayList<>( listPluginApplications );
542         }
543         else
544         {
545             _listPluginApplications = null;
546         }
547     }
548 
549     /**
550      * Returns the list of plugin applications
551      * 
552      * @return The collection of applications
553      */
554     public List<Application> getApplications( )
555     {
556         return new ArrayList<>( _listPluginApplications );
557     }
558 
559     /**
560      * Sets the rest
561      * 
562      * @param rest
563      *            The rest
564      */
565     public void setRest( Rest rest )
566     {
567         _rest = rest;
568     }
569 
570     /**
571      * Returns the rest
572      * 
573      * @return The rest
574      */
575     public Rest getRest( )
576     {
577         return _rest;
578     }
579 
580     /**
581      * Returns the configuration
582      * 
583      * @return The configuration
584      */
585     public Configuration getConfiguration( )
586     {
587         return _configuration;
588     }
589     
590     /**
591      * Sets the configuration
592      * 
593      * @param configuration
594      *            The configuration
595      */
596 	public void setConfiguration( Configuration configuration ) 
597 	{	
598 		_configuration = configuration;
599 	}
600 
601     /**
602      * Sets the list of plugin features
603      * 
604      * @param listPluginFeatures
605      *            The list of plugi features
606      */
607     public void setFeatures( List<Feature> listPluginFeatures )
608     {
609         if ( listPluginFeatures != null )
610         {
611             _listPluginFeatures = new ArrayList<>( listPluginFeatures );
612         }
613         else
614         {
615             _listPluginFeatures = null;
616         }
617     }
618 
619     /**
620      * Returns the list of plugin features
621      * 
622      * @return The plugin features
623      */
624     public List<Feature> getFeatures( )
625     {
626         return new ArrayList<>( _listPluginFeatures );
627     }
628 
629     /**
630      * Sets the list of plugin portlets
631      * 
632      * @param listPluginPortlets
633      *            The list of plugin portlets
634      */
635     public void setPortlets( List<Portlet> listPluginPortlets )
636     {
637         if ( listPluginPortlets != null )
638         {
639             _listPluginPortlets = new ArrayList<>( listPluginPortlets );
640         }
641         else
642         {
643             _listPluginPortlets = null;
644         }
645     }
646 
647     /**
648      * Returns the list of plugin portlets
649      * 
650      * @return The list of portlets
651      */
652     public List<Portlet> getPortlets( )
653     {
654         return new ArrayList<>( _listPluginPortlets );
655     }
656 
657     /**
658      * Returns the list of business classes attached to the generated plugin
659      * 
660      * @return The list of business classes
661      */
662     public List<BusinessClass> getBusinessClasses( )
663     {
664         return new ArrayList<>( _listBusinessClasses );
665     }
666 
667     public void setBusinessClasses( List<BusinessClass> listBusinessClasses )
668     {
669         _listBusinessClasses = new ArrayList<>( listBusinessClasses );
670     }
671 
672     public List<Feature> BusinessClass( )
673     {
674         throw new UnsupportedOperationException( "Not supported yet." ); // To change body of generated methods, choose Tools | Templates.
675     }
676 
677     /**
678      * Returns the Type (module, plugin or workflowtask)
679      * 
680      * @return The Type
681      */
682     public String getType( )
683     {
684         return _strType;
685     }
686 
687     /**
688      * Sets the Type
689      * 
690      * @param The
691      *            Type
692      */
693     public void setType( String strType )
694     {
695         _strType = strType;
696     }
697 
698     /**
699      * Returns the isModule boolean value
700      * 
701      * @return The isModule
702      */
703     public boolean isModule( )
704     {
705         return ( _bIsModule || "MODULE".equals( _strType ) );
706     }
707 
708     /**
709      * Returns the isModule boolean value
710      * 
711      * @return The isModule
712      */
713     @JsonIgnore
714     public boolean getModule( )
715     {
716         return _bIsModule;
717     }
718 
719     /**
720      * Sets the isModule flag
721      * 
722      * @param _bIsModule
723      *            The isModule boolean value
724      */
725     public void setModule( boolean bIsModule )
726     {
727         this._bIsModule = bIsModule;
728     }
729 
730     /**
731      * Returns true if this instance is a workflow task
732      * 
733      * @return True if _strType is equal to "WORKFLOWTASK"
734      */
735     public boolean isWorkflowTask( )
736     {
737         return ( StringUtils.equals( "WORKFLOWTASK", _strType ) );
738     }
739 }