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.twitterjazz.reference;
017
018import service.tut.pori.twitterjazz.Definitions;
019import core.tut.pori.http.Response;
020import core.tut.pori.http.annotations.HTTPAuthenticationParameter;
021import core.tut.pori.http.annotations.HTTPMethodParameter;
022import core.tut.pori.http.annotations.HTTPService;
023import core.tut.pori.http.annotations.HTTPServiceMethod;
024import core.tut.pori.http.parameters.AuthenticationParameter;
025import core.tut.pori.http.parameters.BooleanParameter;
026import core.tut.pori.http.parameters.DataGroups;
027import core.tut.pori.http.parameters.Limits;
028import core.tut.pori.http.parameters.SortOptions;
029import core.tut.pori.http.parameters.StringParameter;
030
031/**
032 * Reference implementation for client API methods. This class defines the APIs available for clients.
033 * 
034 * <h1>Implementation Service path {@value service.tut.pori.twitterjazz.Definitions#SERVICE_TJ}</h1>
035 * 
036 * @see service.tut.pori.twitterjazz.TwitterJazzService
037 *
038 */
039@HTTPService(name = service.tut.pori.twitterjazz.reference.Definitions.SERVICE_TJ_REFERENCE_CLIENT)
040public class ClientService {
041  /**
042   * Clients can use this method for retrieving a list of tags extracted by the profile summarization. This will always return the tags for the currently authenticated user.
043   * 
044   * <h2>Example Query:</h2>
045   *
046   * GET /rest/{@value service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_CLIENT}/{@value service.tut.pori.twitterjazz.Definitions#METHOD_RETRIEVE_TAGS_FOR_USER}<br>
047   *
048   * <h2>Example Result:</h2>
049   * 
050   * {@doc.restlet service="[service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_CLIENT]" method="[service.tut.pori.twitterjazz.Definitions#METHOD_RETRIEVE_TAGS_FOR_USER]" type="GET" query="" body_uri=""}
051   * 
052   * @param authenticatedUser Note: this method requires authentication, but for the reference implementation, anonymous access is granted.
053   * @param sortOptions supported element names are {@value service.tut.pori.contentanalysis.Definitions#ELEMENT_CONFIDENCE}, {@value service.tut.pori.contentanalysis.Definitions#ELEMENT_RANK} and {@value service.tut.pori.contentanalysis.Definitions#ELEMENT_VALUE}. Default sorting order is the original addition order of the objects.
054   * @param dataGroups For supported data groups see {@link service.tut.pori.contentanalysis.reference.ClientService#retrieveMediaObjects(AuthenticationParameter, DataGroups, Limits, core.tut.pori.http.parameters.IntegerParameter, StringParameter)}.
055   * @param limits paging limits
056   * @return See {@link service.tut.pori.contentanalysis.MediaObjectList}
057   */
058  @HTTPServiceMethod(name = Definitions.METHOD_RETRIEVE_TAGS_FOR_USER, acceptedMethods={core.tut.pori.http.Definitions.METHOD_GET})
059  public Response retrieveTagsForUser(
060      @HTTPAuthenticationParameter(required=false) AuthenticationParameter authenticatedUser,
061      @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required = false) DataGroups dataGroups,
062      @HTTPMethodParameter(name = Limits.PARAMETER_DEFAULT_NAME, required = false) Limits limits,
063      @HTTPMethodParameter(name = service.tut.pori.contentanalysis.Definitions.PARAMETER_SORT, required = false) SortOptions sortOptions
064      )
065  {
066    return new Response(TJReferenceCore.retrieveTagsForUser(authenticatedUser.getUserIdentity(), dataGroups, limits, sortOptions));
067  }
068  
069  /**
070   * Clients can use this method for ranking (rating) tags.
071   * 
072   * <h2>Example Query:</h2>
073   *
074   * GET /rest/{@value service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_CLIENT}/{@value service.tut.pori.twitterjazz.Definitions#METHOD_SET_RANK}?{@value service.tut.pori.twitterjazz.Definitions#PARAMETER_RANK}=1;100,2;-10<br>
075   *
076   * <h2>Example Result:</h2>
077   * 
078   * {@doc.restlet service="[service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_CLIENT]" method="[service.tut.pori.twitterjazz.Definitions#METHOD_SET_RANK]" type="POST" query="[service.tut.pori.twitterjazz.Definitions#PARAMETER_RANK]=1;100,2;-10" body_uri=""}
079   * 
080   * @param authenticatedUser Note: this method requires authentication and the user must have authorized the use of his/her Twitter account, but for the reference implementation, anonymous access is granted.
081   * @param ranks with format {@value service.tut.pori.facebookjazz.Definitions#PARAMETER_RANK}={@value service.tut.pori.contentanalysis.Definitions#ELEMENT_MEDIA_OBJECT_ID}{@value core.tut.pori.http.Definitions#SEPARATOR_URI_QUERY_TYPE_VALUE}VALUE{@value core.tut.pori.http.Definitions#SEPARATOR_URI_QUERY_PARAM_VALUES}{@value service.tut.pori.contentanalysis.Definitions#ELEMENT_MEDIA_OBJECT_ID}{@value core.tut.pori.http.Definitions#SEPARATOR_URI_QUERY_TYPE_VALUE}VALUE{@value core.tut.pori.http.Definitions#SEPARATOR_URI_QUERY_PARAM_VALUES} ...
082   */
083  @HTTPServiceMethod(name = Definitions.METHOD_SET_RANK, acceptedMethods={core.tut.pori.http.Definitions.METHOD_POST})
084  public void setRank(
085      @HTTPAuthenticationParameter(required=false) AuthenticationParameter authenticatedUser,
086      @HTTPMethodParameter(name = Definitions.PARAMETER_RANK) StringParameter ranks)
087  {
088    TJReferenceCore.setRank(authenticatedUser.getUserIdentity(), ranks.getValues());
089  }
090  
091  /**
092   * Clients can use this method to initialize account summarization, and optionally perform synchronization for photo content.
093   * 
094   * <h2>Example Query:</h2>
095   *
096   * GET /rest/{@value service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_CLIENT}/{@value service.tut.pori.twitterjazz.Definitions#METHOD_SUMMARIZE}<br>
097   *
098   * <h2>Example Result:</h2>
099   * 
100   * {@doc.restlet service="[service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_CLIENT]" method="[service.tut.pori.twitterjazz.Definitions#METHOD_SUMMARIZE]" type="GET" query="" body_uri=""}
101   * 
102   * @param authenticatedUser Note: this method requires authentication, but for the reference implementation, anonymous access is granted.
103   * @param contentTypes Any combination of content types. By default, all content types will be used. See {@link service.tut.pori.twitterjazz.TwitterExtractor.ContentType}
104   * @param screenNames The screen names of the accounts to be summarized. The authenticated user must have permissions granted by Twitter to summarize the accounts for the operation to complete successfully. If no screen names are given, the summarization is performed for the user's own Twitter account.
105   * @param synchronize On <i>true</i> synchronizes the photo content of the user's account. Photo analysis tasks will be created and fully executed for new content using default analysis back-ends prior to starting the summarization task.
106   */
107  @HTTPServiceMethod(name = Definitions.METHOD_SUMMARIZE)
108  public void summarize(
109      @HTTPAuthenticationParameter(required=false) AuthenticationParameter authenticatedUser,
110      @HTTPMethodParameter(name = Definitions.PARAMETER_CONTENT_TYPES, required = false) StringParameter contentTypes,
111      @HTTPMethodParameter(name = Definitions.PARAMETER_SCREEN_NAMES, required = false) StringParameter screenNames,
112      @HTTPMethodParameter(name = Definitions.PARAMETER_SYNCHRONIZE, required = false) BooleanParameter synchronize)
113  {
114    TJReferenceCore.summarize(authenticatedUser.getUserIdentity(), contentTypes.getValues(), screenNames.getValues(), synchronize.isTrue());
115  }
116}