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 javax.xml.bind.annotation.XmlAccessType; 019import javax.xml.bind.annotation.XmlAccessorType; 020import javax.xml.bind.annotation.XmlRootElement; 021 022import service.tut.pori.contentanalysis.CAContentCore.ServiceType; 023import service.tut.pori.contentanalysis.CAContentCore.Visibility; 024import service.tut.pori.contentanalysis.Media; 025import core.tut.pori.users.UserIdentity; 026import core.tut.pori.utils.MediaUrlValidator.MediaType; 027 028/** 029 * Contains metadata information of a single video. 030 * 031 * <h2>Optional elements</h2> 032 * <ul> 033 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_BACKEND_STATUS_LIST}</li> 034 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_CONFIDENCE}</li> 035 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_CREDITS}</li> 036 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_DESCRIPTION}</li> 037 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_NAME}</li> 038 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_MEDIA_OBJECTLIST}</li> 039 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_VISIBILITY}</li> 040 * </ul> 041 * 042 * <h2>Back-end Video List elements</h2> 043 * 044 * Certain elements are not applicable when Video is used with back-end responses. The following elements can be omitted in back-end responses: 045 * <ul> 046 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_SERVICE_ID}</li> 047 * <li>{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_URL}</li> 048 * <li>{@value core.tut.pori.users.Definitions#ELEMENT_USER_ID}</li> 049 * </ul> 050 * 051 * The elements will be ignored, and thus, will not cause errors. 052 * 053 * <h3>XML Example</h3> 054 * 055 * {@doc.restlet service="[service.tut.pori.contentanalysis.video.reference.Definitions#SERVICE_VCA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.video.Definitions#ELEMENT_VIDEO]" type="GET" query="" body_uri=""} 056 * 057 * @see service.tut.pori.contentanalysis.BackendStatusList 058 * @see service.tut.pori.contentanalysis.MediaObjectList 059 */ 060@XmlRootElement(name=Definitions.ELEMENT_VIDEO) 061@XmlAccessorType(value=XmlAccessType.NONE) 062public class Video extends Media { 063 /** Default media type for Video */ 064 public static final MediaType MEDIA_TYPE = MediaType.VIDEO; 065 066 /** 067 * If URL is not set, this will try to generate default redirect URL with serviceId, and GUID, 068 * finally, returns null if the required information is not available. 069 * 070 * Default data groups: {@value core.tut.pori.http.parameters.DataGroups#DATA_GROUP_BASIC}, {@value core.tut.pori.http.parameters.DataGroups#DATA_GROUP_DEFAULTS} 071 * 072 * @return URL 073 * @see #setUrl(String) 074 */ 075 @Override 076 public String getUrl() { 077 String url = super.getUrl(); 078 if(url != null){ 079 return url; 080 }else{ 081 return VideoContentCore.generateRedirectUrl(getGUID(), getServiceType()); 082 } 083 } 084 085 /** 086 * for serialization, must be public for solr. 087 */ 088 public Video(){ 089 super.setMediaType(MEDIA_TYPE); 090 } 091 092 /** 093 * 094 * @param guid 095 */ 096 public Video(String guid){ 097 super(guid); 098 super.setMediaType(MEDIA_TYPE); 099 } 100 101 /** 102 * 103 * @param guid 104 * @param ownerUserId 105 * @param serviceType 106 * @param visibility 107 */ 108 public Video(String guid, UserIdentity ownerUserId, ServiceType serviceType, Visibility visibility){ 109 super(guid, ownerUserId, serviceType, visibility); 110 super.setMediaType(MEDIA_TYPE); 111 } 112 113 /** 114 * @param mediaType if null, the default media type will be used 115 * @throws IllegalArgumentException on bad media type, i.e. not the default media or null 116 * @see #MEDIA_TYPE 117 */ 118 @Override 119 public void setMediaType(MediaType mediaType) throws IllegalArgumentException { 120 if(mediaType != null && !MEDIA_TYPE.equals(mediaType)){ // the pre-defined media type cannot be changed, so only check if the value being set is valid 121 throw new IllegalArgumentException("Invalid media type for video : "+mediaType.name()); 122 } 123 } 124}