001package service.tut.pori.twitterjazz; 002 003import javax.xml.bind.annotation.XmlAccessType; 004import javax.xml.bind.annotation.XmlAccessorType; 005import javax.xml.bind.annotation.XmlElement; 006import javax.xml.bind.annotation.XmlRootElement; 007 008import org.apache.commons.lang3.StringUtils; 009import org.apache.log4j.Logger; 010 011import service.tut.pori.contentanalysis.MediaObject; 012import service.tut.pori.contentanalysis.CAContentCore.ServiceType; 013import service.tut.pori.contentanalysis.MediaObject.MediaObjectType; 014 015/** 016 * Tag of a photo retrieved from Twitter. 017 * 018 * <h2>Optional Elements</h2> 019 * <ul> 020 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_SERVICE_ID}. Not present if the tag was created by the user or internally by the service.</li> 021 * </ul> 022 * 023 * <h3>XML Example</h3> 024 * 025 * {@doc.restlet service="[service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_EXAMPLE]" method="[service.tut.pori.twitterjazz.Definitions#ELEMENT_PHOTO_TAG]" type="GET" query="" body_uri=""} 026 * 027 */ 028@XmlRootElement(name=Definitions.ELEMENT_PHOTO_TAG) 029@XmlAccessorType(XmlAccessType.NONE) 030public class TwitterPhotoTag { 031 private static final Logger LOGGER = Logger.getLogger(TwitterPhotoTag.class); 032 @XmlElement(name=service.tut.pori.contentanalysis.Definitions.ELEMENT_SERVICE_ID) 033 private ServiceType _serviceType = null; 034 @XmlElement(name=Definitions.ELEMENT_VALUE) 035 private String _value = null; 036 037 /** 038 * @return the serviceType 039 */ 040 public ServiceType getServiceType() { 041 return _serviceType; 042 } 043 044 /** 045 * @param serviceType the serviceType to set 046 */ 047 public void setServiceType(ServiceType serviceType) { 048 _serviceType = serviceType; 049 } 050 051 /** 052 * @return the value 053 */ 054 public String getValue() { 055 return _value; 056 } 057 058 /** 059 * @param value the value to set 060 */ 061 public void setValue(String value) { 062 _value = value; 063 } 064 065 /** 066 * 067 * @param object 068 * @return the object as a tag or null if null was passed 069 * @throws IllegalArgumentException on bad object 070 */ 071 public static TwitterPhotoTag getTwitterTag(MediaObject object) throws IllegalArgumentException { 072 if(object == null){ 073 LOGGER.debug("null tag."); 074 return null; 075 } 076 if(!MediaObjectType.KEYWORD.equals(object.getMediaObjectType())){ 077 throw new IllegalArgumentException("Invalid media object type: "+object.getMediaObjectTypeValue()); 078 } 079 String value = object.getValue(); 080 if(StringUtils.isBlank(value) && StringUtils.isBlank((value = object.getName()))){ 081 throw new IllegalArgumentException("Invalid name and/or value for tag."); 082 } 083 TwitterPhotoTag tag = new TwitterPhotoTag(); 084 tag._value = value; 085 tag._serviceType = object.getServiceType(); 086 return tag; 087 } 088}