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.contentstorage; 017 018import service.tut.pori.contentanalysis.CAContentCore.ServiceType; 019import core.tut.pori.http.Response; 020import core.tut.pori.http.Response.Status; 021import core.tut.pori.http.annotations.HTTPAuthenticationParameter; 022import core.tut.pori.http.annotations.HTTPMethodParameter; 023import core.tut.pori.http.annotations.HTTPService; 024import core.tut.pori.http.annotations.HTTPServiceMethod; 025import core.tut.pori.http.parameters.AuthenticationParameter; 026import core.tut.pori.http.parameters.IntegerParameter; 027import core.tut.pori.http.parameters.StringParameter; 028 029/** 030 * Service definitions for the Content Storage service. 031 * 032 * @see service.tut.pori.contentstorage.reference.ClientService 033 */ 034@HTTPService(name=Definitions.SERVICE_CS) 035public class ContentStorageService { 036 037 /** 038 * @see service.tut.pori.contentstorage.reference.ClientService#synchronize(AuthenticationParameter, IntegerParameter, IntegerParameter) 039 * 040 * @param authenticatedUser 041 * @param backendId 042 * @param serviceId 043 */ 044 @HTTPServiceMethod(name=Definitions.METHOD_SYNCHRONIZE) 045 public void synchronize( 046 @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser, 047 @HTTPMethodParameter(name=service.tut.pori.contentanalysis.Definitions.PARAMETER_BACKEND_ID, required = false) IntegerParameter backendId, 048 @HTTPMethodParameter(name=service.tut.pori.contentanalysis.Definitions.PARAMETER_SERVICE_ID) IntegerParameter serviceId 049 ) 050 { 051 ContentStorageCore.synchronize(authenticatedUser.getUserIdentity(), backendId.getValues(), ServiceType.fromIdArray(serviceId.getValues())); 052 } 053 054 /** 055 * @see service.tut.pori.contentstorage.reference.ClientService#addUrl(AuthenticationParameter, IntegerParameter, StringParameter) 056 * 057 * @param authenticatedUser 058 * @param backendId 059 * @param url 060 * @return response 061 */ 062 @HTTPServiceMethod(name=Definitions.METHOD_ADD_URL, acceptedMethods={core.tut.pori.http.Definitions.METHOD_POST}) 063 public Response addUrl( 064 @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser, 065 @HTTPMethodParameter(name=service.tut.pori.contentanalysis.Definitions.PARAMETER_BACKEND_ID, required = false) IntegerParameter backendId, 066 @HTTPMethodParameter(name=service.tut.pori.contentanalysis.Definitions.PARAMETER_URL) StringParameter url 067 ) 068 { 069 MediaList media = ContentStorageCore.addUrls(authenticatedUser.getUserIdentity(), backendId.getValues(), url.getValues()); 070 if(MediaList.isEmpty(media)){ 071 return new Response(Status.BAD_REQUEST); 072 }else{ 073 return new Response(media); 074 } 075 } 076}