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.contentanalysistest;
017
018import service.tut.pori.contentanalysis.Definitions;
019import core.tut.pori.http.RedirectResponse;
020import core.tut.pori.http.Response;
021import core.tut.pori.http.Response.Status;
022import core.tut.pori.http.annotations.HTTPAuthenticationParameter;
023import core.tut.pori.http.annotations.HTTPMethodParameter;
024import core.tut.pori.http.annotations.HTTPService;
025import core.tut.pori.http.annotations.HTTPServiceMethod;
026import core.tut.pori.http.parameters.AuthenticationParameter;
027import core.tut.pori.http.parameters.BooleanParameter;
028import core.tut.pori.http.parameters.DataGroups;
029import core.tut.pori.http.parameters.InputStreamParameter;
030import core.tut.pori.http.parameters.IntegerParameter;
031import core.tut.pori.http.parameters.LongParameter;
032import core.tut.pori.http.parameters.StringParameter;
033
034
035/**
036 * This service includes test API for contentAnalysis service (analysis example APIs & such)
037 * 
038 * The reference implementations will not belong here anymore, clean this class of unneeded methods,
039 * or remove the whole class if needed
040 */
041@Deprecated
042@HTTPService(name = "catest")
043public class ContentAnalysisTestService { 
044  /**
045   * 
046   * @param guid
047   * @param userId 
048   * @return response
049   * 
050   */
051  @HTTPServiceMethod(name = "hasAccess")
052  public Response hasAccess(
053      @HTTPMethodParameter(name = Definitions.PARAMETER_GUID) StringParameter guid, 
054      @HTTPAuthenticationParameter AuthenticationParameter userId
055      )
056  {
057    Response r = new Response();
058    r.setMessage(ContentAnalysisTestUtils.hasAccess(guid.getValue(), userId.getUserIdentity()));
059    return r;
060  }
061
062  /**
063   * 
064   * @param backendId 
065   * @return response
066   */
067  @HTTPServiceMethod(name = "listAnalysisBackends")
068  public Response listAnalysisBackends(
069      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID, required = false) IntegerParameter backendId)
070  {
071    return new Response(ContentAnalysisTestUtils.listAnalysisBackends(backendId.getValues()));
072  }
073
074  /**
075   * 
076   * @param dataGroups
077   * @param identity
078   * @return response
079   */
080  @HTTPServiceMethod(name = "extractFacebookProfile")
081  public Response extractFacebookProfile(
082      @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required = false) DataGroups dataGroups,
083      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity
084      )
085  {
086    return new Response(ContentAnalysisTestUtils.extractFacebookProfile(dataGroups, identity.getUserIdentity()));
087  }
088  
089  /**
090   * 
091   * @param dataGroups
092   * @param identity
093   * @return response
094   */
095  @HTTPServiceMethod(name = "extractTwitterProfile")
096  public Response extractTwitterProfile(
097      @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required = false) DataGroups dataGroups,
098      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity
099      )
100  {
101    return new Response(ContentAnalysisTestUtils.extractTwitterProfile(dataGroups, identity.getUserIdentity()));
102  }
103
104  /**
105   * 
106   * @param backendId
107   * @param capabilityString
108   * @param description
109   * @param enabled
110   * @param identity
111   * @param taskDataGroups
112   * @param url
113   */
114  @HTTPServiceMethod(name = "modifyAnalysisBackend")
115  public void modifyAnalysisBackend(
116      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID) IntegerParameter backendId,
117      @HTTPMethodParameter(name = "capability_string") StringParameter capabilityString,
118      @HTTPMethodParameter(name = "description") StringParameter description,
119      @HTTPMethodParameter(name = "enabled") BooleanParameter enabled,
120      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity,
121      @HTTPMethodParameter(name = "task_data_groups") DataGroups taskDataGroups,
122      @HTTPMethodParameter(name = Definitions.PARAMETER_URL) StringParameter url
123      )
124  {
125    ContentAnalysisTestUtils.modifyAnalysisBackend(backendId.getValue(), capabilityString.getValues(), description.getValue(), enabled.getValue(), taskDataGroups, url.getValue());
126  }
127
128  /**
129   * 
130   * @param backendId
131   * @param identity
132   */
133  @HTTPServiceMethod(name = "removeAnalysisBackend")
134  public void removeAnalysisBackend(
135      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID) IntegerParameter backendId,
136      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity
137      )
138  {
139    ContentAnalysisTestUtils.removeAnalysisBackend(backendId.getValue());
140  }
141
142  /**
143   * 
144   * @param capabilityString
145   * @param description
146   * @param enabled
147   * @param identity
148   * @param taskDataGroups
149   * @param url
150   * @return response
151   */
152  @HTTPServiceMethod(name = "createAnalysisBackend")
153  public Response createAnalysisBackend(
154      @HTTPMethodParameter(name = "capability_string") StringParameter capabilityString,
155      @HTTPMethodParameter(name = "description") StringParameter description,
156      @HTTPMethodParameter(name = "enabled", defaultValue = "false") BooleanParameter enabled,
157      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity,
158      @HTTPMethodParameter(name = "task_data_groups", defaultValue = "all") DataGroups taskDataGroups,
159      @HTTPMethodParameter(name = Definitions.PARAMETER_URL) StringParameter url
160      )
161  {
162    Response r = new Response();
163    r.setMessage(String.valueOf(ContentAnalysisTestUtils.createAnalysisBackend(capabilityString.getValues(), description.getValue(), enabled.getValue(), taskDataGroups, url.getValue())));
164    return r;
165  }
166  
167  /**
168   * 
169   * @param backendId
170   * @param taskId
171   */
172  @HTTPServiceMethod(name = "reschedulePhotoTask")
173  public void reschedulePhotoTask(
174      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID) IntegerParameter backendId,
175      @HTTPMethodParameter(name = Definitions.PARAMETER_TASK_ID) LongParameter taskId
176      )
177  {
178    ContentAnalysisTestUtils.reschedulePhotoTask(backendId.getValues(), taskId.getValue());
179  }
180  
181  /**
182   * 
183   * @param backendId
184   * @param taskId
185   */
186  @HTTPServiceMethod(name = "rescheduleVideoTask")
187  public void rescheduleVideoTask(
188      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID) IntegerParameter backendId,
189      @HTTPMethodParameter(name = Definitions.PARAMETER_TASK_ID) LongParameter taskId
190      )
191  {
192    ContentAnalysisTestUtils.rescheduleVideoTask(backendId.getValues(), taskId.getValue());
193  }
194  
195  /**
196   * 
197   * @param identity
198   * @param backendId 
199   * @param enabled 
200   */
201  @HTTPServiceMethod(name = "enableBackend")
202  public void enableBackend(
203      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity,
204      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID) IntegerParameter backendId,
205      @HTTPMethodParameter(name = "enabled") BooleanParameter enabled
206      )
207  {
208    ContentAnalysisTestUtils.enableBackend(backendId.getValue(), enabled.getValue());
209  }
210  
211  /**
212   * @param identity
213   * @param albumId
214   * @param includeGUIDs
215   * @param resolveNames 
216   * @return list of picasa albums
217   */
218  @HTTPServiceMethod(name = "getPicasaAlbums")
219  public Response getPicasaAlbums(
220      @HTTPAuthenticationParameter AuthenticationParameter identity,
221      @HTTPMethodParameter(name = "album_id", required = false) StringParameter albumId,
222      @HTTPMethodParameter(name = "include_uids", defaultValue = "false", required = false) BooleanParameter includeGUIDs,
223      @HTTPMethodParameter(name = "resolve_names", defaultValue = "true", required = false) BooleanParameter resolveNames
224      )
225  {
226    return new Response(ContentAnalysisTestUtils.getPicasaAlbums(identity.getUserIdentity(), albumId.getValues(), includeGUIDs.isTrue(), resolveNames.isTrue()));
227  }
228  
229  /**
230   * 
231   * @param identity
232   * @param guid
233   * @return url redirection to picasa
234   */
235  @HTTPServiceMethod(name = "getPicasaUri")
236  public Response getPicasaUri(
237      @HTTPAuthenticationParameter AuthenticationParameter identity,
238      @HTTPMethodParameter(name = "guid") StringParameter guid
239      )
240  {
241    return new RedirectResponse(ContentAnalysisTestUtils.getPicasaUri(identity.getUserIdentity(), guid.getValue()));
242  }
243  
244  /**
245   * 
246   * @param identity
247   * @param backendId 
248   * @param dataGroups optional data groups
249   * @param url
250   * @return response
251   */
252  @HTTPServiceMethod(name = "analyzePage")
253  public Response analyzePage(
254      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity,
255      @HTTPMethodParameter(name = Definitions.PARAMETER_BACKEND_ID, required=false) IntegerParameter backendId,
256      @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required = false, defaultValue=ContentAnalysisTestUtils.DATA_GROUPS_HREF) DataGroups dataGroups,
257      @HTTPMethodParameter(name = "url") StringParameter url
258      )
259  {
260    if(ContentAnalysisTestUtils.analyzePage(identity.getUserIdentity(), backendId.getValues(), dataGroups, url.getValue())){
261      return new Response();
262    }else{
263      return new Response(Status.BAD_REQUEST);
264    }
265  }
266  
267  /**
268   * 
269   * @param identity
270   * @param file
271   * @return the extracted words in the message
272   */
273  @HTTPServiceMethod(name = "fuzzyFile")
274  public Response fuzzyFile(
275      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity,
276      @HTTPMethodParameter(name = InputStreamParameter.PARAMETER_DEFAULT_NAME, bodyParameter=true) InputStreamParameter file
277      )
278  {
279    return new Response(Status.OK, ContentAnalysisTestUtils.fuzzyFile(file.getValue()));
280  }
281  
282  /**
283   * 
284   * @param identity
285   * @param url
286   * @return the extracted words in the message
287   */
288  @HTTPServiceMethod(name = "fuzzyUrl")
289  public Response fuzzyUrl(
290      @HTTPAuthenticationParameter(showLoginPrompt=true) AuthenticationParameter identity,
291      @HTTPMethodParameter(name = "url") StringParameter url
292      )
293  {
294    return new Response(Status.OK, ContentAnalysisTestUtils.fuzzyUrl(url.getValue()));
295  }
296}