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.files.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;
028
029import core.tut.pori.utils.ISODateAdapter;
030
031/**
032 * Contains details of a single file.
033 */
034@XmlRootElement(name=Definitions.ELEMENT_FILE_DETAILS)
035@XmlAccessorType(XmlAccessType.NONE)
036public class FileDetails{
037  private static final Logger LOGGER = Logger.getLogger(FileDetails.class);
038  @XmlElement(name=Definitions.ELEMENT_GUID)
039  private String _guid = null;
040  @XmlElement(name=Definitions.ELEMENT_MIME_TYPE)
041  private String _mimeType = null;
042  @XmlElement(name=Definitions.ELEMENT_URL)
043  private String _url = null;
044  @XmlJavaTypeAdapter(ISODateAdapter.class)
045  @XmlElement(name=Definitions.ELEMENT_VALID_UNTIL)
046  private Date _validUntil = null;
047
048  /**
049   * @return the guid
050   * @see #setGUID(String)
051   */
052  public String getGUID() {
053    return _guid;
054  }
055  
056  /**
057   * @param guid the guid to set
058   * @see #getGUID()
059   */
060  public void setGUID(String guid) {
061    _guid = guid;
062  }
063
064  /**
065   * @return the mimeType
066   * @see #setMimeType(String)
067   */
068  public String getMimeType() {
069    return _mimeType;
070  }
071
072  /**
073   * @param mimeType the mimeType to set
074   * @see #getMimeType()
075   */
076  public void setMimeType(String mimeType) {
077    _mimeType = mimeType;
078  }
079
080  /**
081   * @return the url
082   * @see #setUrl(String)
083   */
084  public String getUrl() {
085    return _url;
086  }
087
088  /**
089   * @param url the url to set
090   * @see #getUrl()
091   */
092  public void setUrl(String url) {
093    _url = url;
094  }
095  
096  /**
097   * @return the last date/time the urls provided in this file details object are valid or null if the date is unknown
098   * @see #setValidUntil(Date)
099   */
100  public Date getValidUntil() {
101    return _validUntil;
102  }
103
104  /**
105   * @param validUntil the validUntil to set
106   * @see #getValidUntil()
107   */
108  public void setValidUntil(Date validUntil) {
109    _validUntil = validUntil;
110  }
111
112  /**
113   * for sub-classing, use the static
114   * 
115   * @return true if valid
116   * @see #isValid(FileDetails)
117   */
118  protected boolean isValid() {
119    if(StringUtils.isBlank(_guid)){
120      LOGGER.debug("GUID was null or empty.");
121      return false;
122    }else{
123      return true;
124    }
125  }
126  
127  /**
128   * 
129   * @param details
130   * @return false if details is null or contains invalid data
131   */
132  public static boolean isValid(FileDetails details) {
133    if(details == null){
134      return false;
135    }else{
136      return details.isValid();
137    }
138  }
139}