View Javadoc

1   package com.sri.emo.wizard.creation.persistence;
2   
3   import com.jcorporate.expresso.core.db.DBConnection;
4   import com.jcorporate.expresso.core.db.DBException;
5   import com.jcorporate.expresso.core.dbobj.DBField;
6   import com.jcorporate.expresso.core.dbobj.SecurDBObject;
7   import com.jcorporate.expresso.core.dbobj.ValidValue;
8   import com.jcorporate.expresso.core.security.ReadOnlyUser;
9   import com.jcorporate.expresso.core.security.filters.AllowedHtmlPlusURLFilter;
10  import com.sri.emo.dbobj.Part;
11  import com.sri.emo.dbobj.PartsFactory;
12  import com.sri.emo.wizard.creation.model.FieldCompletion;
13  
14  import java.util.Vector;
15  import com.sri.emo.wizard.creation.ExtendedAllowedHtmlPlusURLFilter;
16  
17  
18  /***
19   * Per-Part Details of the Completion Wizards.
20   *
21   * @author Michael Rimov
22   * @version 1.0
23   */
24  public class CreationDetails extends SecurDBObject {
25  
26  
27      /***
28       * Constant for access to field 'Completion Details Number'.
29       */
30      public static final String FLD_SURROGATE_KEY = "DetailsNumber";
31  
32  
33      /***
34       * Constant for access to field 'Wizard Id'
35       */
36      public static final String FLD_WIZARD_ID = "WizardId";
37  
38      /***
39       * Table Name
40       */
41      public static final String TABLE_NAME = "EMOCREATIONNDTL";
42  
43      /***
44       * Constant for access to field 'Part Id'
45       */
46      public static final String FLD_PART_ID = "PartId";
47  
48  
49      public static final String FLD_PART_ORDER = "PartOrder";
50  
51      /***
52       * Constant for access to field 'Is FreeText'
53       */
54      public static final String FLD_FREETEXT = "IsFreeText";
55  
56      /***
57       * added by rich
58       * Constant for acces to field 'isSearch'
59       */
60      public static final String FLD_SEARCH = "IsSearch";
61      public static final String FLD_SEARCH_TXT = "SearchTxt";
62      /***
63       * added by rich
64       * Constant for acces to field 'isSearch'
65       */
66      public static final String FLD_CREATE = "IsCreate";
67      public static final String FLD_CREATE_TXT = "CreateTxt";
68  
69      /***
70       * added by rich
71       * Constant for acces to field 'isSearch'
72       */
73      public static final String FLD_BROWSE = "IsBrowse";
74      public static final String FLD_BROWSE_TXT = "BrowseTxt";
75  
76  
77      /***
78       * added by rich
79       * Constant for acces to field 'isSearch'
80       */
81      public static final String FLD_REQUIRED = "IsRequired";
82  
83      /***
84       * Constant for access to field 'Min Entries'
85       */
86      public static final String FLD_MIN_ENTRIES = "MinEntries";
87  
88      /***
89       * Constant for access to field 'Max Entries'
90       */
91      public static final String FLD_MAX_ENTRIES = "MaxEntries";
92  
93  
94      /***
95       * Constant for acces to field 'Directive'
96       */
97      public static final String FLD_DIRECTIVE = "Directive";
98  
99      /***
100      * Constant fo access ot field 'Help Text';
101      */
102     public static final String FLD_HELPTEXT = "HelpText";
103 
104     /***
105      * Field Completion Type
106      */
107     public static final String FLD_COMPLETION = "Completion";
108 
109 
110     /***
111      * Field for single entry.
112      */
113     public static final String FLD_SINGLE_ENTRY = "SingleEntry";
114 
115 
116     /***
117      * Completion wizard use fixed constant.
118      */
119     public static final String COMPLETION_FIXED = FieldCompletion.NOT_INCLUDED.toString();
120 
121     /***
122      * Completion method use wizard constant.
123      */
124     public static final String COMPLETION_WIZARD = FieldCompletion.WIZARD.toString();
125 
126 
127     /***
128      * Default constructor to create a new object.
129      *
130      * @throws DBException upon construction error.
131      */
132     public CreationDetails() throws DBException {
133         super();
134     }
135 
136     /***
137      * Constructor that takes a <tt>DBConnection</tt> for use inside a transaction.
138      *
139      * @param newConnection DBConnection the transaction connection.
140      * @throws DBException upon construction error.
141      */
142     public CreationDetails(DBConnection newConnection) throws DBException {
143         super(newConnection);
144     }
145 
146     /***
147      * Constructor taht takes a <tt>ReadOnlyUser</tt> security context.  This
148      * is most often set by the default constructor, so you only want to do this
149      * if you want to use special security permissions (such as Admin or SuperUser)
150      *
151      * @param readOnlyUser ReadOnlyUser the ReadOnlyUser instance.
152      * @throws DBException upon construction error.
153      */
154     public CreationDetails(ReadOnlyUser readOnlyUser) throws DBException {
155         super(readOnlyUser);
156     }
157 
158 
159     /***
160      * Retrieve the part.
161      *
162      * @return Part
163      * @throws DBException
164      */
165     public Part getPart() throws DBException {
166         return PartsFactory.getPart(this.getFieldInt(FLD_PART_ID));
167     }
168 
169     /***
170      * Method to set up the fields for this database object.
171      *
172      * @throws DBException If there is an error setting up the fields as
173      *                     requested. For example, if a field allowing null is requested as
174      *                     part of the key
175      */
176     protected void setupFields() throws DBException {
177         setTargetTable(TABLE_NAME);
178         setDescription("Completion Details");
179         setCharset("ISO-8859-1");
180 
181 
182         addField(FLD_SURROGATE_KEY, DBField.AUTOINC_TYPE, 0, false, "Completion Details Number");
183         addKey(FLD_SURROGATE_KEY);
184 
185         addField(FLD_WIZARD_ID, DBField.INTEGER_TYPE, 0, false, "Wizard Id");
186         addField(FLD_PART_ID, DBField.INTEGER_TYPE, 0, false, "Part Id");
187         addField(FLD_MIN_ENTRIES, DBField.INTEGER_TYPE, 0, true, "Min Entries");
188         addField(FLD_MAX_ENTRIES, DBField.INTEGER_TYPE, 0, true, "Max Entries");
189         addField(FLD_PART_ORDER, DBField.INTEGER_TYPE, 0, false, "Order");
190         addField(FLD_FREETEXT, DBField.CHAR_TYPE, 1, true, "Is FreeText");
191 
192         //added by rich
193         addField(FLD_CREATE, DBField.CHAR_TYPE, 1, true, "Is Create");
194         addField(FLD_BROWSE, DBField.CHAR_TYPE, 1, true, "Is Browse");
195         addField(FLD_SEARCH, DBField.CHAR_TYPE, 1, true, "Is Search");
196         addField(FLD_REQUIRED, DBField.CHAR_TYPE, 1, true, "Is Skip");
197 
198         //added by rich
199         addField(FLD_SEARCH_TXT, DBField.TEXT_TYPE, 0, true, "Search Text");
200         DBField fieldMeta = (DBField) getMetaData().getFieldMetadata(FLD_SEARCH_TXT);
201         fieldMeta.setFilterClass(ExtendedAllowedHtmlPlusURLFilter.class);
202         addField(FLD_BROWSE_TXT, DBField.TEXT_TYPE, 0, true, "Browse Text");
203         fieldMeta = (DBField) getMetaData().getFieldMetadata(FLD_BROWSE_TXT);
204         fieldMeta.setFilterClass(ExtendedAllowedHtmlPlusURLFilter.class);
205         addField(FLD_CREATE_TXT, DBField.TEXT_TYPE, 0, true, "Create Text");
206         fieldMeta = (DBField) getMetaData().getFieldMetadata(FLD_CREATE_TXT);
207         fieldMeta.setFilterClass(ExtendedAllowedHtmlPlusURLFilter.class);
208 
209 
210         addField(FLD_COMPLETION, DBField.VARCHAR_TYPE, 254, true, "Completion Directive");
211         fieldMeta = (DBField) getMetaData().getFieldMetadata(FLD_COMPLETION);
212         fieldMeta.setFilterClass(AllowedHtmlPlusURLFilter.class);
213 
214         addField(FLD_DIRECTIVE, DBField.VARCHAR_TYPE, 254, true, "Directive");
215         fieldMeta = (DBField) getMetaData().getFieldMetadata(FLD_DIRECTIVE);
216         fieldMeta.setFilterClass(AllowedHtmlPlusURLFilter.class);
217 
218         addField(FLD_HELPTEXT, DBField.TEXT_TYPE, 0, true, "Help Text");
219         fieldMeta = (DBField) getMetaData().getFieldMetadata(FLD_HELPTEXT);
220         fieldMeta.setFilterClass(AllowedHtmlPlusURLFilter.class);
221 
222         addField(FLD_SINGLE_ENTRY, DBField.CHAR_TYPE, 1, true, "Is Single Entry");
223 
224         this.addIndex("CompletionDetailsWizardId", FLD_WIZARD_ID + "," + FLD_PART_ID + "," + FLD_PART_ORDER, false);
225 
226     }
227 
228     /***
229      * New method to replace getValues with a structure of valid values and
230      * descriptions.
231      *
232      * @param fieldName The name of the fields for which a value set is
233      *                  requested
234      * @return A Vector of ValidValue objects
235      * @throws DBException upon error.
236      */
237     public synchronized Vector getValidValues(final String fieldName) throws DBException {
238         if (fieldName.equals(FLD_COMPLETION)) {
239             Vector vv = new Vector(2);
240             vv.add(new ValidValue(COMPLETION_FIXED, COMPLETION_FIXED));
241             vv.add(new ValidValue(COMPLETION_WIZARD, COMPLETION_WIZARD));
242             return vv;
243         } else {
244             return super.getValidValues(fieldName);
245         }
246     }
247 
248 }