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;
017
018import java.util.EnumSet;
019
020import service.tut.pori.contentanalysis.PhotoTaskResponse;
021import service.tut.pori.facebookjazz.FBJContentCore;
022import service.tut.pori.twitterjazz.TwitterExtractor.ContentType;
023import core.tut.pori.http.Response;
024import core.tut.pori.http.annotations.HTTPAuthenticationParameter;
025import core.tut.pori.http.annotations.HTTPMethodParameter;
026import core.tut.pori.http.annotations.HTTPService;
027import core.tut.pori.http.annotations.HTTPServiceMethod;
028import core.tut.pori.http.parameters.AuthenticationParameter;
029import core.tut.pori.http.parameters.BooleanParameter;
030import core.tut.pori.http.parameters.DataGroups;
031import core.tut.pori.http.parameters.InputStreamParameter;
032import core.tut.pori.http.parameters.Limits;
033import core.tut.pori.http.parameters.SortOptions;
034import core.tut.pori.http.parameters.StringParameter;
035import core.tut.pori.utils.XMLFormatter;
036
037/**
038 * This service enables twitter profile summarization
039 * 
040 * @see service.tut.pori.twitterjazz.reference.ClientService
041 * @see service.tut.pori.twitterjazz.reference.BackendService
042 */
043@HTTPService(name = Definitions.SERVICE_TJ)
044public class TwitterJazzService {
045  private XMLFormatter _formatter = new XMLFormatter();
046
047  /**
048   * @see service.tut.pori.twitterjazz.reference.ServerService#taskFinished(InputStreamParameter)
049   * 
050   * @param xml
051   */
052  @HTTPServiceMethod(name = service.tut.pori.contentanalysis.Definitions.METHOD_TASK_FINISHED, acceptedMethods={core.tut.pori.http.Definitions.METHOD_POST})
053  public void taskFinished(@HTTPMethodParameter(name = InputStreamParameter.PARAMETER_DEFAULT_NAME, bodyParameter = true) InputStreamParameter xml) {
054    TJContentCore.taskFinished(_formatter.toObject(xml.getValue(), TwitterTaskResponse.class, PhotoTaskResponse.class));
055  }
056  
057  /**
058   * @see service.tut.pori.twitterjazz.reference.ClientService#retrieveTagsForUser(AuthenticationParameter, DataGroups, Limits, SortOptions)
059   * 
060   * @param authenticatedUser
061   * @param sortOptions
062   * @param dataGroups
063   * @param limits
064   * @return response
065   */
066  @HTTPServiceMethod(name = Definitions.METHOD_RETRIEVE_TAGS_FOR_USER, acceptedMethods={core.tut.pori.http.Definitions.METHOD_GET})
067  public Response retrieveTagsForUser(
068      @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser,
069      @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required = false) DataGroups dataGroups,
070      @HTTPMethodParameter(name = Limits.PARAMETER_DEFAULT_NAME, required = false) Limits limits,
071      @HTTPMethodParameter(name = service.tut.pori.contentanalysis.Definitions.PARAMETER_SORT, required = false) SortOptions sortOptions
072      )
073  {
074    return new Response(TJContentCore.retrieveTagsForUser(authenticatedUser.getUserIdentity(), dataGroups, limits, sortOptions));
075  }
076
077  /**
078   * @see service.tut.pori.twitterjazz.reference.ClientService#setRank(AuthenticationParameter, StringParameter)
079   * 
080   * @param authenticatedUser
081   * @param ranks
082   */
083  @HTTPServiceMethod(name = Definitions.METHOD_SET_RANK, acceptedMethods={core.tut.pori.http.Definitions.METHOD_POST})
084  public void setRank(
085      @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser,
086      @HTTPMethodParameter(name = Definitions.PARAMETER_RANK) StringParameter ranks)
087  {
088    TJContentCore.setRanks(authenticatedUser.getUserIdentity(), FBJContentCore.parseRankStrings(ranks.getValues()));
089  }
090  
091  /**
092   * @see service.tut.pori.twitterjazz.reference.ClientService#summarize(AuthenticationParameter, StringParameter, StringParameter, BooleanParameter)
093   * 
094   * @param authenticatedUser
095   * @param contentTypes
096   * @param screenNames
097   * @param synchronize
098   */
099  @HTTPServiceMethod(name = Definitions.METHOD_SUMMARIZE)
100  public void summarize(
101      @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser,
102      @HTTPMethodParameter(name = Definitions.PARAMETER_CONTENT_TYPES, required = false) StringParameter contentTypes,
103      @HTTPMethodParameter(name = Definitions.PARAMETER_SCREEN_NAMES, required = false) StringParameter screenNames,
104      @HTTPMethodParameter(name = Definitions.PARAMETER_SYNCHRONIZE, required = false) BooleanParameter synchronize)
105  {
106    TJContentCore.summarize(authenticatedUser.getUserIdentity(), (contentTypes.hasValues() ? ContentType.fromString(contentTypes.getValues()) : EnumSet.allOf(ContentType.class)), screenNames.getValues(), true, synchronize.isTrue());
107  }
108}