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