001/**
002 * Copyright 2015 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.video;
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
028import service.tut.pori.contentanalysis.ResultInfo;
029
030/**
031 * A special video list used to list deleted video.
032 * 
033 * Deleted Video List element is generally found in the Feedback Task. It is used to notify back-ends that the video or a list of videos is no longer available.
034 * 
035 * Note that the information in the Video object is provided only for reference, and the details provided are not guaranteed to valid. Moreover, the Video object is not guaranteed to be valid. The list is generally only meant to provide the UIDs of the deleted videos; other information may or may not be present.
036 *
037 * <h3>XML Example</h3>
038 * 
039 * {@doc.restlet service="[service.tut.pori.contentanalysis.video.reference.Definitions#SERVICE_VCA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.video.Definitions#ELEMENT_DELETED_VIDEOLIST]" type="GET" query="" body_uri=""}
040 *  
041 */
042@XmlRootElement(name=Definitions.ELEMENT_DELETED_VIDEOLIST)
043@XmlAccessorType(value=XmlAccessType.NONE)
044public class DeletedVideoList extends VideoList {
045  private static final Logger LOGGER = Logger.getLogger(DeletedVideoList.class);
046  
047  @Override
048  protected boolean isValid() {
049    if(isEmpty()){
050      return false;
051    }
052    LOGGER.debug("Using "+DeletedVideoList.class.toString()+" for validation of a video list.");
053    for(Video p : getVideos()){
054      if(StringUtils.isBlank(p.getGUID())){
055        return false;
056      }
057    }
058    return true;
059  }
060
061  /**
062   * 
063   * @param videos
064   * @param resultInfo
065   * @return new video list or null if the given collection of videos was null or empty
066   */
067  public static DeletedVideoList getVideoList(Collection<Video> videos, ResultInfo resultInfo) {
068    if(videos == null || videos.isEmpty()){
069      LOGGER.debug("Empty video list.");
070      return null;
071    }
072    
073    DeletedVideoList videoList = new DeletedVideoList();
074    videoList.setResultInfo(resultInfo);
075    videoList.setVideos(new ArrayList<>(videos));
076    return videoList;
077  }
078}