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 */
023
024package dk.netarkivet.harvester.datamodel.extendedfield;
025
026import dk.netarkivet.common.exceptions.ArgumentNotValid;
027
028/**
029 * Class for holding a value of one ExtendedField.
030 */
031public class ExtendedFieldValue {
032
033    /** The ID of the value of the ExtendedField. */
034    private Long extendedFieldValueID;
035    /** The ID of the ExtendedField. */
036    private Long extendedFieldID;
037    /** The contents of the value itself. */
038    private String content;
039    /** The instanceid. */
040    private Long instanceID;
041
042    /**
043     * @return the ID of the value of the ExtendedField
044     */
045    public Long getExtendedFieldValueID() {
046        return extendedFieldValueID;
047    }
048
049    /**
050     * Set the ID of value of the ExtendedField.
051     *
052     * @param extendedFieldValueID the ID of the value of the ExtendedField
053     */
054    public void setExtendedFieldValueID(Long extendedFieldValueID) {
055        ArgumentNotValid.checkNotNull(extendedFieldValueID, "Long extendedFieldValueID");
056        this.extendedFieldValueID = extendedFieldValueID;
057    }
058
059    /**
060     * @return the ID of the ExtendedField
061     */
062    public Long getExtendedFieldID() {
063        return extendedFieldID;
064    }
065
066    /**
067     * Set the ID of the ExtendedField.
068     *
069     * @param extendedFieldID the ID of the ExtendedField
070     */
071    public void setExtendedFieldID(Long extendedFieldID) {
072        ArgumentNotValid.checkNotNull(extendedFieldID, "Long extendedFieldID");
073        this.extendedFieldID = extendedFieldID;
074    }
075
076    /**
077     * @return the content of the value
078     */
079    public String getContent() {
080        return content;
081    }
082
083    /**
084     * Set the content. Null arg is not accepted.
085     *
086     * @param content The content of the value
087     */
088    public void setContent(String content) {
089        this.content = content;
090    }
091
092    /**
093     * @return the instanceid of the value
094     */
095    public Long getInstanceID() {
096        return instanceID;
097    }
098
099    /**
100     * Set the instanceId. Null arg is not accepted.
101     *
102     * @param instanceID The instanceid
103     */
104    public void setInstanceID(Long instanceID) {
105        this.instanceID = instanceID;
106    }
107
108    /**
109     * Default constructor initializing the contents to the empty string.
110     */
111    public ExtendedFieldValue() {
112        content = "";
113    }
114
115    /**
116     * Constructor initializing all instance members. Used when reading from persistent storage.
117     *
118     * @param aExtendedFieldValueID The ID of the value of the ExtendedField.
119     * @param aExtendedFieldID The ID of the ExtendedField.
120     * @param aInstanceID The instance id of the value
121     * @param aContent The contents of the value (the value itself) TODO argument validation
122     */
123    public ExtendedFieldValue(Long aExtendedFieldValueID, Long aExtendedFieldID, Long aInstanceID, String aContent) {
124        extendedFieldValueID = aExtendedFieldValueID;
125        extendedFieldID = aExtendedFieldID;
126        instanceID = aInstanceID;
127        content = aContent;
128    }
129
130    /**
131     * @return the boolean value of the contents
132     */
133    public boolean getBooleanValue() {
134        String aValue = getContent();
135        if (aValue == null) {
136            return false;
137        }
138
139        aValue = aValue.toLowerCase();
140        for (String val : ExtendedFieldDefaultValue.possibleTrueValues) {
141            if (aValue.equals(val)) {
142                return true;
143            }
144        }
145
146        return false;
147    }
148
149    public String toString() {
150        return "" + "extendedFieldValueID:[" + extendedFieldValueID + "]\n" + "extendedFieldID:[" + extendedFieldID
151                + "]\n" + "content:[" + content + "]\n" + "instanceID:[" + instanceID + "]\n";
152    }
153
154}