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.EnumSet; 019import java.util.Set; 020 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlElementWrapper; 025import javax.xml.bind.annotation.XmlRootElement; 026 027import core.tut.pori.http.parameters.DataGroups; 028 029 030/** 031 * Contains details of a single analysis back-end. 032 * 033 * <h3>XML Example</h3> 034 * 035 * {@doc.restlet service="[service.tut.pori.contentanalysis.reference.Definitions#SERVICE_CA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.Definitions#ELEMENT_BACKEND]" type="GET" query="" body_uri=""} 036 * 037 */ 038@XmlRootElement(name=Definitions.ELEMENT_BACKEND) 039@XmlAccessorType(XmlAccessType.NONE) 040public class AnalysisBackend { 041 @XmlElement(name = Definitions.ELEMENT_URL) 042 private String _analysisUri = null; 043 @XmlElement(name = Definitions.ELEMENT_BACKEND_ID) 044 private Integer _backendId = null; 045 private EnumSet<Capability> _capabilities = null; 046 private DataGroups _defaultTaskDataGroups = null; 047 @XmlElement(name = Definitions.ELEMENT_DESCRIPTION) 048 private String _description = null; 049 @XmlElement(name = Definitions.ELEMENT_ENABLED) 050 private Boolean _enabled = null; 051 052 /** 053 * Capability of a back-end. 054 * 055 */ 056 public enum Capability{ 057 /** back-end is capable of processing photo content */ 058 PHOTO_ANALYSIS(1), 059 /** back-end is capable of search/query operations for photos */ 060 PHOTO_SEARCH(2), 061 /** should this back-end receive directly or indirectly generated user feedback */ 062 USER_FEEDBACK(3), 063 /** is this back-end capable of processing tasks without user information */ 064 ANONYMOUS_TASK(4), 065 /** back-end is capable of processing facebook profiles */ 066 FACEBOOK_SUMMARIZATION(5), 067 /** should this back-end receive feedback based on analysis results generated by other back-ends */ 068 BACKEND_FEEDBACK(6), 069 /** back-end is capable of processing twitter profiles */ 070 TWITTER_SUMMARIZATION(7), 071 /** back-end is capable of processing video content */ 072 VIDEO_ANALYSIS(8), 073 /** back-end is capable of search/query operations for videos */ 074 VIDEO_SEARCH(2); 075 076 private int _value; 077 078 /** 079 * 080 * @param value 081 */ 082 private Capability(int value){ 083 _value = value; 084 } 085 086 /** 087 * 088 * @return Capability as integer 089 */ 090 public int toInt(){ 091 return _value; 092 } 093 094 /** 095 * 096 * @param value 097 * @return the value converted to Capability 098 * @throws IllegalArgumentException on bad value 099 */ 100 public static Capability fromInt(int value) throws IllegalArgumentException { 101 for(Capability c : Capability.values()){ 102 if(c._value == value){ 103 return c; 104 } 105 } 106 throw new IllegalArgumentException("Bad "+Capability.class.toString()+" : "+value); 107 } 108 } // enum Capability 109 110 /** 111 * 112 * @param capabilities 113 */ 114 public void setCapabilities(EnumSet<Capability> capabilities) { 115 _capabilities = capabilities; 116 } 117 118 /** 119 * 120 * @param capability 121 * @return true if the back-end has the given capability 122 */ 123 public boolean hasCapability(Capability capability){ 124 if(_capabilities != null){ 125 return _capabilities.contains(capability); 126 }else{ 127 return false; 128 } 129 } 130 131 /** 132 * 133 * @param capabilities 134 * @return true if this back-end has all of the given capabilities 135 */ 136 public boolean hasCapabilities(Set<Capability> capabilities){ 137 if(capabilities == null || capabilities.isEmpty() || _capabilities == null){ 138 return false; 139 }else{ 140 return _capabilities.containsAll(capabilities); 141 } 142 } 143 144 /** 145 * 146 * @param capability 147 */ 148 public void addCapability(Capability capability){ 149 if(_capabilities == null){ 150 _capabilities = EnumSet.of(capability); 151 }else{ 152 _capabilities.add(capability); 153 } 154 } 155 156 /** 157 * 158 * @return back-ends capabilities 159 */ 160 @XmlElementWrapper(name = Definitions.ELEMENT_CAPABILITY_LIST) 161 @XmlElement(name = Definitions.ELEMENT_CAPABILITY) 162 public EnumSet<Capability> getCapabilities() { 163 return _capabilities; 164 } 165 166 /** 167 * 168 * @return back-end description 169 */ 170 public String getDescription() { 171 return _description; 172 } 173 174 /** 175 * 176 * @param description 177 */ 178 public void setDescription(String description) { 179 _description = description; 180 } 181 182 /** 183 * 184 * @return true if this back-end is enabled 185 */ 186 public Boolean isEnabled() { 187 return _enabled; 188 } 189 190 /** 191 * 192 * @param enabled 193 */ 194 public void setEnabled(Boolean enabled) { 195 _enabled = enabled; 196 } 197 198 /** 199 * 200 * @return the analysis service uri 201 */ 202 public String getAnalysisUri() { 203 return _analysisUri; 204 } 205 206 /** 207 * 208 * @param analysisUri 209 */ 210 public void setAnalysisUri(String analysisUri) { 211 _analysisUri = analysisUri; 212 } 213 214 /** 215 * 216 * @return back-end id 217 */ 218 public Integer getBackendId() { 219 return _backendId; 220 } 221 222 /** 223 * 224 * @param backendId 225 */ 226 public void setBackendId(Integer backendId) { 227 _backendId = backendId; 228 } 229 230 /** 231 * @return the defaultTaskDataGroups 232 */ 233 public DataGroups getDefaultTaskDataGroups() { 234 return _defaultTaskDataGroups; 235 } 236 237 /** 238 * @param defaultTaskDataGroups the defaultTaskDataGroups to set 239 */ 240 public void setDefaultTaskDataGroups(DataGroups defaultTaskDataGroups) { 241 _defaultTaskDataGroups = defaultTaskDataGroups; 242 } 243 244 /** 245 * 246 */ 247 public AnalysisBackend(){ 248 // nothing needed 249 } 250 251 /** 252 * 253 * @param backendId 254 */ 255 public AnalysisBackend(Integer backendId){ 256 _backendId = backendId; 257 } 258}