001/**
002 * Copyright 2016 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package service.tut.pori.apilta.sensors.datatypes;
017
018import java.util.Date;
019
020import javax.xml.bind.annotation.XmlAccessType;
021import javax.xml.bind.annotation.XmlAccessorType;
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlRootElement;
024import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
025
026import org.apache.commons.lang3.StringUtils;
027import org.apache.log4j.Logger;
028import org.apache.solr.client.solrj.beans.Field;
029
030import core.tut.pori.dao.SolrDAO;
031import core.tut.pori.utils.ISODateAdapter;
032
033/**
034 * data point data to be used for solr storage
035 *
036 */
037@XmlRootElement(name=Definitions.ELEMENT_DATAPOINT)
038@XmlAccessorType(value=XmlAccessType.NONE)
039public class DataPoint {
040  private static final Logger LOGGER = Logger.getLogger(DataPoint.class);
041  @Field(SolrDAO.SOLR_FIELD_CREATED)
042  @XmlJavaTypeAdapter(ISODateAdapter.class)
043  @XmlElement(name = Definitions.ELEMENT_CREATED_TIMESTAMP)
044  private Date _created = null;
045  @Field(core.tut.pori.dao.SolrDAO.SOLR_FIELD_ID)
046  @XmlElement(name = Definitions.ELEMENT_DATAPOINT_ID)
047  private String _dataPointId = null;
048  @Field(Definitions.SOLR_FIELD_DESCRIPTION)
049  @XmlElement(name = Definitions.ELEMENT_DESCRIPTION)
050  private String _description = null;
051  @Field(Definitions.SOLR_FIELD_KEY)
052  @XmlElement(name = Definitions.ELEMENT_KEY)
053  private String _key = null;
054  @Field(Definitions.SOLR_FIELD_MEASUREMENT_ID)
055  private String _measurementId = null; // This field is not serialized to xml
056  @Field(Definitions.SOLR_FIELD_VALUE)
057  @XmlElement(name = Definitions.ELEMENT_VALUE)
058  private String _value = null;
059  
060  
061
062  /**
063   * @return the dataPointId
064   * @see #setDataPointId(String)
065   */
066  public String getDataPointId() {
067    return _dataPointId;
068  }
069
070  /**
071   * @param dataPointId the dataPointId to set
072   * @see #getDataPointId()
073   */
074  public void setDataPointId(String dataPointId) {
075    _dataPointId = dataPointId;
076  }
077
078  /**
079   * @return the measurementId
080   * @see #setMeasurementId(String)
081   */
082  public String getMeasurementId() {
083    return _measurementId;
084  }
085
086  /**
087   * @param measurementId the measurementId to set
088   * @see #getMeasurementId()
089   */
090  public void setMeasurementId(String measurementId) {
091    _measurementId = measurementId;
092  }
093
094  /**
095   * @return the value
096   * @see #setValue(String)
097   */
098  public String getValue() {
099    return _value;
100  }
101
102  /**
103   * @param value the value to set
104   * @see #getValue()
105   */
106  public void setValue(String value) {
107    _value = value;
108  }
109  
110  /**
111   * @return the description
112   * @see #setDescription(String)
113   */
114  public String getDescription() {
115    return _description;
116  }
117
118  /**
119   * @param description the description to set
120   * @see #getDescription()
121   */
122  public void setDescription(String description) {
123    _description = description;
124  }
125
126  /**
127   * @return the key
128   * @see #setKey(String)
129   */
130  public String getKey() {
131    return _key;
132  }
133
134  /**
135   * @param key the key to set
136   * @see #getKey()
137   */
138  public void setKey(String key) {
139    _key = key;
140  }
141  
142  
143
144  /**
145   * @return the created
146   * @see #setCreated(Date)
147   */
148  public Date getCreated() {
149    return _created;
150  }
151
152  /**
153   * @param created the created to set
154   * @see #getCreated()
155   */
156  public void setCreated(Date created) {
157    _created = created;
158  }
159
160  /**
161   * for sub-classing, use the static
162   * 
163   * @return true if this data point is valid
164   * @see #isValid(DataPoint)
165   */
166  protected boolean isValid() {
167    if(StringUtils.isBlank(_key)){
168      LOGGER.debug("Invalid key.");
169      return false;
170    }else if(StringUtils.isBlank(_value)){
171      LOGGER.debug("Invalid value.");
172      return false;
173    }else{
174      return true;
175    }
176  }
177
178  /**
179   * 
180   * @param dataPoint
181   * @return false if the data point is null or invalid
182   */
183  public static boolean isValid(DataPoint dataPoint) {
184    if(dataPoint == null){
185      return false;
186    }else{
187      return dataPoint.isValid();
188    }
189  }
190}