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.sensors.reference; 017 018import core.tut.pori.http.Response; 019import core.tut.pori.http.annotations.HTTPMethodParameter; 020import core.tut.pori.http.annotations.HTTPService; 021import core.tut.pori.http.annotations.HTTPServiceMethod; 022import core.tut.pori.http.parameters.DataGroups; 023import core.tut.pori.http.parameters.Limits; 024import core.tut.pori.http.parameters.StringParameter; 025 026/** 027 * Generates example XML output 028 * 029 */ 030@HTTPService(name = Definitions.SERVICE_SENSORS_REFERENCE_EXAMPLE) 031public class ExampleService { 032 /** 033 * Generates example traffic data 034 * 035 * @param limits 036 * @return traffic data 037 * @see service.tut.pori.apilta.sensors.datatypes.MeasurementList 038 */ 039 @HTTPServiceMethod(name = service.tut.pori.apilta.sensors.datatypes.Definitions.ELEMENT_MEASUREMENT) 040 public Response trafficData( 041 @HTTPMethodParameter(name = Limits.PARAMETER_DEFAULT_NAME, required=false, defaultValue="0-0") Limits limits 042 ) 043 { 044 Example example = new Example(); 045 example.setMeasurements(SensorsReferenceCore.generateTrafficData(limits)); 046 return new Response(example); 047 } 048 049 /** 050 * Generates example task details 051 * @param taskId 052 * 053 * @param taskType Will default to {@link service.tut.pori.apilta.sensors.Definitions#TASK_TYPE_DATA_COLLECT}, if missing 054 * @return task details 055 * @see service.tut.pori.apilta.sensors.datatypes.SensorTask 056 * @see #taskDetails(StringParameter, StringParameter) 057 */ 058 @HTTPServiceMethod(name = service.tut.pori.tasks.Definitions.ELEMENT_TASK) 059 public Response task( 060 @HTTPMethodParameter(name = service.tut.pori.tasks.Definitions.PARAMETER_TASK_ID, required=false) StringParameter taskId, 061 @HTTPMethodParameter(name = Definitions.PARAMETER_TASK_TYPE, required=false) StringParameter taskType 062 ) 063 { 064 return taskDetails(taskId, taskType); 065 } 066 067 /** 068 * Generates example task details 069 * 070 * @param taskId 071 * @param taskType Will default to {@link service.tut.pori.apilta.sensors.Definitions#TASK_TYPE_DATA_COLLECT}, if missing 072 * @return task details 073 * @see service.tut.pori.apilta.sensors.datatypes.SensorTask 074 */ 075 @HTTPServiceMethod(name = Definitions.METHOD_TASK_DETAILS) 076 public Response taskDetails( 077 @HTTPMethodParameter(name = service.tut.pori.tasks.Definitions.PARAMETER_TASK_ID, required=false) StringParameter taskId, 078 @HTTPMethodParameter(name = Definitions.PARAMETER_TASK_TYPE, required=false) StringParameter taskType 079 ) 080 { 081 Example example = new Example(); 082 example.setTask(SensorsReferenceCore.generateTaskDetails(null, null, (taskId.hasValues() ? taskId.getValues() : null), (taskType.hasValues() ? taskId.getValue() : service.tut.pori.apilta.sensors.Definitions.TASK_TYPE_DATA_COLLECT))); 083 return new Response(example); 084 } 085 086 /** 087 * Generates example task results 088 * 089 * @param dataGroups 090 * @param limits paging limits 091 * @param taskId 092 * @param taskType Will default to {@link service.tut.pori.apilta.sensors.Definitions#TASK_TYPE_DATA_COLLECT}, if missing 093 * @return task details 094 * @see service.tut.pori.apilta.sensors.datatypes.SensorTask 095 */ 096 @HTTPServiceMethod(name = Definitions.METHOD_TASK_RESULTS) 097 public Response taskResults( 098 @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required=false) DataGroups dataGroups, 099 @HTTPMethodParameter(name = Limits.PARAMETER_DEFAULT_NAME, required=false, defaultValue="0-0") Limits limits, 100 @HTTPMethodParameter(name = service.tut.pori.tasks.Definitions.PARAMETER_TASK_ID, required=false) StringParameter taskId, 101 @HTTPMethodParameter(name = Definitions.PARAMETER_TASK_TYPE, required=false, defaultValue=service.tut.pori.apilta.sensors.Definitions.TASK_TYPE_DATA_COLLECT) StringParameter taskType 102 ) 103 { 104 Example example = new Example(); 105 example.setTask(SensorsReferenceCore.generateTaskResults(null, dataGroups, limits, taskId.getValue(), taskType.getValue())); 106 return new Response(example); 107 } 108}