001/** 002 * Copyright 2016 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.apilta.files; 017 018import java.util.Arrays; 019 020import core.tut.pori.http.Response; 021import core.tut.pori.http.Response.Status; 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.StringParameter; 026import service.tut.pori.apilta.files.datatypes.FileDetails; 027import service.tut.pori.apilta.files.datatypes.FileDetailsList; 028 029/** 030 * service definitions for files service 031 * 032 */ 033@HTTPService(name = Definitions.SERVICE_FILES) 034public class FilesService { 035 /** 036 * 037 * @param temporaryToken 038 * @return see {@link service.tut.pori.apilta.files.datatypes.FileDetailsList} 039 */ 040 @HTTPServiceMethod(name = Definitions.METHOD_GET_FILE_DETAILS, acceptedMethods={core.tut.pori.http.Definitions.METHOD_GET}) 041 public Response getFileDetails ( 042 @HTTPMethodParameter(name = Definitions.PARAMETER_TEMPORARY_TOKEN) StringParameter temporaryToken 043 ) 044 { 045 FileDetails details = FilesCore.getFileDetailsForToken(temporaryToken.getValue()); 046 if(details == null){ 047 return new Response(Status.FORBIDDEN); 048 }else{ 049 FileDetailsList list = new FileDetailsList(); 050 list.setFiles(Arrays.asList(details)); 051 return new Response(list); 052 } 053 } 054}