001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023package dk.netarkivet.harvester.datamodel.extendedfield; 024 025import java.io.Serializable; 026import java.util.Map; 027 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030 031import dk.netarkivet.common.exceptions.ArgumentNotValid; 032import dk.netarkivet.harvester.webinterface.ExtendedFieldConstants; 033 034/** 035 * This class represents one Extended Field. 036 */ 037@SuppressWarnings({"serial"}) 038public class ExtendedField implements Serializable { 039 040 private static final Logger log = LoggerFactory.getLogger(ExtendedField.class); 041 042 /** persistent id of this extended field. */ 043 private Long extendedFieldID; 044 /** The Id of the Reference to which the extended field belongs. */ 045 private Long extendedFieldTypeID; 046 047 /** name of the extended Field. This name will not be translated. */ 048 private String name; 049 /** formatting patterns of the extended Field. */ 050 private String formattingPattern; 051 /** datatype of the extended Field. see datatype list. */ 052 private int datatype; 053 /** is extendedfield mandatory. */ 054 private boolean mandatory; 055 /** sequencenr to sort fields. */ 056 private int sequencenr = 1; 057 /** maxlen of extended Field. */ 058 private int maxlen = ExtendedFieldConstants.MAXLEN_EXTF_NAME; 059 060 /** default value for this field. */ 061 private String defaultValue; 062 063 /** key-value pairs for Options. */ 064 private String options; 065 066 /** 067 * @return the extendedFieldID 068 */ 069 public Long getExtendedFieldID() { 070 return extendedFieldID; 071 } 072 073 /** 074 * Set the ID of the extendedField.. 075 * 076 * @param extendedFieldID the ID of the extendedField.. 077 */ 078 public void setExtendedFieldID(Long extendedFieldID) { 079 ArgumentNotValid.checkNotNull(extendedFieldID, "Long extendedFieldID"); 080 this.extendedFieldID = extendedFieldID; 081 } 082 083 /** 084 * @return the extendedFieldTypeID 085 */ 086 public Long getExtendedFieldTypeID() { 087 return extendedFieldTypeID; 088 } 089 090 /** 091 * Set the name of the extendedFieldTypeID. 092 * 093 * @param extendedFieldTypeID an extendedfieldtypeId 094 */ 095 public void setExtendedFieldTypeID(Long extendedFieldTypeID) { 096 ArgumentNotValid.checkNotNull(extendedFieldID, "Long extendedFieldID"); 097 this.extendedFieldTypeID = extendedFieldTypeID; 098 } 099 100 /** 101 * @return the name of the extendedField 102 */ 103 public String getName() { 104 return name; 105 } 106 107 /** 108 * Set the name of the extendedField. 109 * 110 * @param name the name of the extendedField 111 */ 112 public void setName(String name) { 113 ArgumentNotValid.checkNotNull(name, "String name"); 114 this.name = name; 115 } 116 117 /** 118 * @return the formatting pattern of the extendedField 119 */ 120 public String getFormattingPattern() { 121 return formattingPattern; 122 } 123 124 /** 125 * Set a formatting pattern for this extendefield. 126 * 127 * @param aFormattingPattern a formatting pattern for this extendedfield 128 */ 129 public void setFormattingPattern(String aFormattingPattern) { 130 ArgumentNotValid.checkNotNull(aFormattingPattern, "String aFormattingPattern"); 131 this.formattingPattern = aFormattingPattern; 132 } 133 134 /** 135 * @return the datatype of the extendedField 136 */ 137 public int getDatatype() { 138 return datatype; 139 } 140 141 /** 142 * Set the datatype of this extendedField. 143 * 144 * @param datatype a datatype for this extendedfield 145 */ 146 public void setDatatype(int datatype) { 147 this.datatype = datatype; 148 } 149 150 /** 151 * @return true, if extendedfield is mandatory, otherwise false. 152 */ 153 public boolean isMandatory() { 154 return mandatory; 155 } 156 157 /** 158 * Set the mandatory-state of this extendedField. 159 * 160 * @param mandatory A mandatory-state of this extendedField 161 */ 162 public void setMandatory(boolean mandatory) { 163 this.mandatory = mandatory; 164 } 165 166 /** 167 * @return the sequencenr of the extendedField 168 */ 169 public int getSequencenr() { 170 return sequencenr; 171 } 172 173 /** 174 * Set the sequencenr of this extendedField. 175 * 176 * @param sequencenr a new sequencenr of this extendedField. 177 */ 178 public void setSequencenr(int sequencenr) { 179 this.sequencenr = sequencenr; 180 } 181 182 /** 183 * @return the default value of the extendedField 184 */ 185 public String getDefaultValue() { 186 return defaultValue; 187 } 188 189 /** 190 * Set the defaultvalue of this extendedField. 191 * 192 * @param defaultValue the defaultvalue of this extendedField. 193 */ 194 public void setDefaultValue(String defaultValue) { 195 ArgumentNotValid.checkNotNull(defaultValue, "String defaultValue"); 196 this.defaultValue = defaultValue; 197 } 198 199 /** 200 * @return the options of the extendedField 201 */ 202 public String getOptions() { 203 return options; 204 } 205 206 /** 207 * @return the max length of the extendedField 208 */ 209 public int getMaxlen() { 210 return maxlen; 211 } 212 213 /** 214 * Set the maxlen of this extendedField. 215 * 216 * @param aMaxlen for this extendedfield 217 */ 218 public void setMaxlen(int aMaxlen) { 219 maxlen = aMaxlen; 220 } 221 222 /** 223 * Set the options of the extendedField. 224 * 225 * @param options the options of the extendedField 226 */ 227 public void setOptions(String options) { 228 ArgumentNotValid.checkNotNull(options, "String options"); 229 this.options = options; 230 } 231 232 /** 233 * Constructor for the extendedfield with only one value - the id. 234 * 235 * @param aExtendedFieldTypeID the Id of the extendededfieldtype 236 */ 237 public ExtendedField(String aExtendedFieldTypeID) { 238 ArgumentNotValid.checkNotNull(aExtendedFieldTypeID, "aExtendedFieldTypeID"); 239 240 extendedFieldTypeID = Long.parseLong(aExtendedFieldTypeID); 241 datatype = ExtendedFieldDataTypes.STRING; 242 mandatory = false; 243 name = ""; 244 formattingPattern = ""; 245 defaultValue = ""; 246 options = ""; 247 } 248 249 /** 250 * Constructor for ExtendedField, that requires all data. 251 * 252 * @param aExtendedFieldID The extendedfieldId of the extendedfield 253 * @param aExtendedFieldTypeID The extendedfieldtypeId of the extendedfield 254 * @param aName The name of the extendedfield 255 * @param aFormattingPattern The name of the extendedfield 256 * @param aDatatype The datatype of the extendedfield 257 * @param aMandatory The mandatory state of the extendedfield 258 * @param aSequenceNr The sequencenr of the extendedfield 259 * @param aDefaultValue The default value of the extendedfield 260 * @param aOptions The options of the extendedfield 261 * @param aMaxlen The maxlen of the extendedfield 262 */ 263 public ExtendedField(Long aExtendedFieldID, Long aExtendedFieldTypeID, String aName, String aFormattingPattern, 264 int aDatatype, boolean aMandatory, int aSequenceNr, String aDefaultValue, String aOptions, int aMaxlen) { 265 extendedFieldID = aExtendedFieldID; 266 extendedFieldTypeID = aExtendedFieldTypeID; 267 name = aName; 268 formattingPattern = aFormattingPattern; 269 datatype = aDatatype; 270 mandatory = aMandatory; 271 sequencenr = aSequenceNr; 272 defaultValue = aDefaultValue; 273 options = aOptions; 274 maxlen = aMaxlen; 275 276 log.debug(toString()); 277 } 278 279 /** 280 * @return a map of option values. 281 */ 282 public Map<String, String> getOptionValues() { 283 return new ExtendedFieldOptions(getOptions()).getOptions(); 284 } 285 286 /** 287 * @return the JSP field name. 288 */ 289 public String getJspFieldname() { 290 return ExtendedFieldConstants.EXTF_PREFIX + getExtendedFieldID() + "_" + getDatatype(); 291 } 292 293 public String toString() { 294 return "" + "extendedFieldID:[" + extendedFieldID + "]\n" + "extendedFieldTypeID:[" + extendedFieldTypeID 295 + "]\n" + "name:[" + name + "]\n" + "formattingPattern:[" + formattingPattern + "]\n" + "datatype:[" 296 + datatype + "]\n" + "mandatory:[" + mandatory + "]\n" + "sequencenr:[" + sequencenr + "]\n" 297 + "defaultValue:[" + defaultValue + "]\n" + "options:[" + options + "]\n" + "maxlen:[" + maxlen + "]\n"; 298 } 299 300}