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 reference photos. 031 * 032 * In general, only a single photo is given as a reference for similarity search, but per the implementation of this class, multiple photos could be used as well. 033 * 034 * <h3>XML Example</h3> 035 * 036 * {@doc.restlet service="[service.tut.pori.contentanalysis.reference.Definitions#SERVICE_CA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.Definitions#ELEMENT_REFERENCE_PHOTOLIST]" type="GET" query="" body_uri=""} 037 * 038 */ 039@XmlRootElement(name=Definitions.ELEMENT_REFERENCE_PHOTOLIST) // override root element name 040@XmlAccessorType(XmlAccessType.NONE) 041public class ReferencePhotoList extends PhotoList{ 042 private static final Logger LOGGER = Logger.getLogger(ReferencePhotoList.class); 043 044 @Override 045 protected boolean isValid() { 046 if(isEmpty()){ 047 return false; 048 } 049 LOGGER.debug("Using "+ReferencePhotoList.class.toString()+" for validation of a photo list."); 050 for(Photo p : getPhotos()){ 051 if(StringUtils.isBlank(p.getGUID())){ 052 return false; 053 } 054 } 055 return true; 056 } 057 058 /** 059 * 060 * @param photos 061 * @return new photo list of null if null or empty photos given 062 */ 063 public static ReferencePhotoList getPhotoList(Collection<Photo> photos){ 064 if(photos == null || photos.isEmpty()){ 065 return null; 066 } 067 068 ReferencePhotoList photoList = new ReferencePhotoList(); 069 photoList.setPhotos(new ArrayList<>(photos)); 070 return photoList; 071 } 072}