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 java.util.ArrayList;
019import java.util.Collection;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlRootElement;
024
025import org.apache.commons.lang3.StringUtils;
026import org.apache.log4j.Logger;
027
028
029/**
030 * A special photo list used to list deleted photos.
031 * 
032 * Deleted Photo List element is generally found in the Feedback Task. It is used to notify back-ends that the photo or a list of photos is no longer available.
033 * 
034 * Note that the information in the Photo object is provided only for reference, and the details provided are not guaranteed to valid. Moreover, the Photo object is not guaranteed to be valid. The list is generally only meant to provide the UIDs of the deleted photos; other information may or may not be present.
035 *
036 * <h3>XML Example</h3>
037 * 
038 * {@doc.restlet service="[service.tut.pori.contentanalysis.reference.Definitions#SERVICE_CA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.Definitions#ELEMENT_DELETED_PHOTOLIST]" type="GET" query="" body_uri=""}
039 *  
040 */
041@XmlRootElement(name=Definitions.ELEMENT_DELETED_PHOTOLIST) // override root element name
042@XmlAccessorType(XmlAccessType.NONE)
043public class DeletedPhotoList extends PhotoList{
044  private static final Logger LOGGER = Logger.getLogger(DeletedPhotoList.class);
045  
046  /**
047   * 
048   * @param photos
049   * @param resultInfo optional resultInfo
050   * @return new photo list of null if null or empty photos given
051   */
052  public static DeletedPhotoList getPhotoList(Collection<Photo> photos, ResultInfo resultInfo){
053    if(photos == null || photos.isEmpty()){
054      return null;
055    }
056    
057    DeletedPhotoList photoList = new DeletedPhotoList();
058    photoList.setPhotos(new ArrayList<>(photos));
059    photoList.setResultInfo(resultInfo);
060    return photoList;
061  }
062
063  @Override
064  protected boolean isValid() {
065    if(isEmpty()){
066      return false;
067    }
068    LOGGER.debug("Using "+DeletedPhotoList.class.toString()+" for validation of a photo list.");
069    for(Photo p : getPhotos()){
070      if(StringUtils.isBlank(p.getGUID())){
071        return false;
072      }
073    }
074    return true;
075  }
076}