001/**
002 * Copyright 2014 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.contentanalysis;
017
018import javax.xml.bind.annotation.XmlAccessType;
019import javax.xml.bind.annotation.XmlAccessorType;
020import javax.xml.bind.annotation.XmlElement;
021import javax.xml.bind.annotation.XmlRootElement;
022
023
024/**
025 * Class for representing details of a feedback given by the user.
026 * 
027 * Feedback Lists are used by the clients to deliver feedback to the front-end.
028 * 
029 * The feedback must always contain {@link service.tut.pori.contentanalysis.PhotoList} with at least one {@link service.tut.pori.contentanalysis.Photo}. The photos in the {@link service.tut.pori.contentanalysis.SimilarPhotoList} and {@link service.tut.pori.contentanalysis.DissimilarPhotoList} are similar and not similar to the photos listed in the {@link service.tut.pori.contentanalysis.ReferencePhotoList}.
030 * 
031 * <h2>Conditional Elements</h2>
032 * <ul>
033 *  <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_SIMILAR_PHOTOLIST}</li>
034 *  <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_DISSIMILAR_PHOTOLIST}</li>
035 * </ul>
036 * At least one of the conditional elements must be present, and have valid content.
037 * 
038 * <h3>XML Example</h3>
039 * 
040 * {@doc.restlet service="[service.tut.pori.contentanalysis.reference.Definitions#SERVICE_CA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.Definitions#ELEMENT_FEEDBACKLIST]" type="GET" query="" body_uri=""}
041 * 
042 * @see service.tut.pori.contentanalysis.DissimilarPhotoList
043 * @see service.tut.pori.contentanalysis.ReferencePhotoList
044 * @see service.tut.pori.contentanalysis.SimilarPhotoList
045 */
046@XmlRootElement(name=Definitions.ELEMENT_FEEDBACKLIST)
047@XmlAccessorType(XmlAccessType.NONE)
048public class PhotoFeedbackList {
049  @XmlElement(name = Definitions.ELEMENT_DISSIMILAR_PHOTOLIST)
050  private DissimilarPhotoList _dissimilarPhotos = null;
051  @XmlElement(name = Definitions.ELEMENT_REFERENCE_PHOTOLIST)
052  private ReferencePhotoList _referencePhotos = null;
053  @XmlElement(name = Definitions.ELEMENT_SIMILAR_PHOTOLIST)
054  private SimilarPhotoList _similarPhotos = null;
055
056  /**
057   * references must be given, similars and/or dissimilars must be given
058   * @param dissimilars
059   * @param references
060   * @param similars
061   * 
062   */
063  public PhotoFeedbackList(DissimilarPhotoList dissimilars, ReferencePhotoList references, SimilarPhotoList similars){
064    _referencePhotos = references;
065    _similarPhotos = similars;
066    _dissimilarPhotos = dissimilars;
067  }
068
069  /**
070   * for serialization
071   */
072  protected PhotoFeedbackList(){
073    // nothing needed
074  }
075
076  /**
077   * 
078   * @return reference photos
079   */
080  public ReferencePhotoList getReferencePhotos() {
081    return _referencePhotos;
082  }
083
084  /**
085   * 
086   * @param referencePhotos
087   */
088  public void setReferencePhotos(ReferencePhotoList referencePhotos) {
089    _referencePhotos = referencePhotos;
090  }
091
092  /**
093   * 
094   * @return similar photos
095   */
096  public SimilarPhotoList getSimilarPhotos() {
097    return _similarPhotos;
098  }
099
100  /**
101   * 
102   * @param similarPhotos
103   */
104  public void setSimilarPhotos(SimilarPhotoList similarPhotos) {
105    _similarPhotos = similarPhotos;
106  }
107
108  /**
109   * 
110   * @return dissimilar photos
111   */
112  public DissimilarPhotoList getDissimilarPhotos() {
113    return _dissimilarPhotos;
114  }
115
116  /**
117   * 
118   * @param dissimilarPhotos
119   */
120  public void setDissimilarPhotos(DissimilarPhotoList dissimilarPhotos) {
121    _dissimilarPhotos = dissimilarPhotos;
122  }
123
124  /**
125   * 
126   * @param list can be null
127   * @return true if the given list is valid
128   */
129  public static boolean isValid(PhotoFeedbackList list){
130    if(list == null){
131      return false;
132    }else{
133      return list.isValid();
134    }
135  }
136
137  /**
138   * only for sub-classing, use the static
139   * @return true if this list is valid
140   * @see #isValid(PhotoFeedbackList)
141   */
142  protected boolean isValid(){
143    if(!ReferencePhotoList.isValid(_referencePhotos) || (_similarPhotos == null && _dissimilarPhotos == null)){
144      return false;
145    }else if(_similarPhotos != null && !SimilarPhotoList.isValid(_similarPhotos)){
146      return false;
147    }else if(_dissimilarPhotos != null && !DissimilarPhotoList.isValid(_dissimilarPhotos)){
148      return false;
149    }else{
150      return true;
151    }
152  }
153}