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.subtitles;
017
018import service.tut.pori.subtitles.SubtitlesCore.FileFormat;
019import service.tut.pori.subtitles.SubtitlesCore.SubtitleFormat;
020import core.tut.pori.http.Response.Status;
021import core.tut.pori.http.StringResponse;
022import core.tut.pori.http.StringResponse.StringData;
023import core.tut.pori.http.annotations.HTTPAuthenticationParameter;
024import core.tut.pori.http.annotations.HTTPMethodParameter;
025import core.tut.pori.http.annotations.HTTPService;
026import core.tut.pori.http.annotations.HTTPServiceMethod;
027import core.tut.pori.http.parameters.AuthenticationParameter;
028import core.tut.pori.http.parameters.LongParameter;
029import core.tut.pori.http.parameters.StringParameter;
030
031/**
032 * This service enables subtitle generation.
033 * 
034 * @see service.tut.pori.subtitles.reference.ClientService
035 */
036@HTTPService(name=Definitions.SERVICE_SUBS)
037public class SubtitlesService {
038
039  /**
040   * 
041   * @param authenticatedUser
042   * @param guid
043   * @param fileFormat
044   * @param subtitleFormat
045   * @param userIdFilter 
046   * @return the formatted subtitles
047   * @see service.tut.pori.subtitles.reference.ClientService#generateSubtitles(AuthenticationParameter, StringParameter, StringParameter, StringParameter, core.tut.pori.http.parameters.LongParameter)
048   */
049  @HTTPServiceMethod(name = Definitions.METHOD_GENERATE_SUBTITLES, acceptedMethods={core.tut.pori.http.Definitions.METHOD_GET})
050  public StringResponse generateSubtitles(
051      @HTTPAuthenticationParameter(required = false) AuthenticationParameter authenticatedUser,
052      @HTTPMethodParameter(name=service.tut.pori.contentanalysis.Definitions.PARAMETER_GUID) StringParameter guid,
053      @HTTPMethodParameter(name=Definitions.PARAMETER_FILE_FORMAT) StringParameter fileFormat,
054      @HTTPMethodParameter(name=Definitions.PARAMETER_SUBTITLE_FORMAT) StringParameter subtitleFormat,
055      @HTTPMethodParameter(name=service.tut.pori.users.Definitions.PARAMETER_USER_ID, required = false) LongParameter userIdFilter
056      )
057  {
058    StringData data = SubtitlesCore.generateSubtitles(authenticatedUser.getUserIdentity(), guid.getValue(), FileFormat.fromFormatString(fileFormat.getValue()), SubtitleFormat.fromFormatString(subtitleFormat.getValue()), userIdFilter.getValues());
059    if(data == null){
060      return new StringResponse(Status.BAD_REQUEST);
061    }else{
062      return new StringResponse(data);
063    }
064  }
065}
066