001/** 002 * Copyright 2018 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.shock; 017 018import service.tut.pori.apilta.shock.GroupCalculator.GroupMethod; 019import service.tut.pori.apilta.shock.datatypes.LocationLimits; 020import service.tut.pori.apilta.shock.datatypes.ShockMeasurementList; 021import core.tut.pori.http.Response; 022import core.tut.pori.http.annotations.HTTPAuthenticationParameter; 023import core.tut.pori.http.annotations.HTTPMethodParameter; 024import core.tut.pori.http.annotations.HTTPService; 025import core.tut.pori.http.annotations.HTTPServiceMethod; 026import core.tut.pori.http.parameters.AuthenticationParameter; 027import core.tut.pori.http.parameters.DataGroups; 028import core.tut.pori.http.parameters.DateIntervalParameter; 029import core.tut.pori.http.parameters.DoubleParameter; 030import core.tut.pori.http.parameters.InputStreamParameter; 031import core.tut.pori.http.parameters.IntegerParameter; 032import core.tut.pori.http.parameters.Limits; 033import core.tut.pori.http.parameters.LongParameter; 034import core.tut.pori.http.parameters.StringParameter; 035import core.tut.pori.utils.XMLFormatter; 036 037/** 038 * 039 */ 040@HTTPService(name = Definitions.SERVICE_SHOCK) 041public class ShockService { 042 private XMLFormatter _formatter = new XMLFormatter(); 043 044 /** 045 * 046 * @param authenticatedUser 047 * @param xml {@link ShockMeasurementList} 048 */ 049 @HTTPServiceMethod(name = Definitions.METHOD_CREATE_MEASUREMENT, acceptedMethods={core.tut.pori.http.Definitions.METHOD_POST}) 050 public void createMeasurement ( 051 @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser, 052 @HTTPMethodParameter(name = InputStreamParameter.PARAMETER_DEFAULT_NAME, bodyParameter = true) InputStreamParameter xml 053 ) 054 { 055 ShockCore.createMeasurement(authenticatedUser.getUserIdentity(), _formatter.toObject(xml.getValue(), ShockMeasurementList.class)); 056 } 057 058 /** 059 * 060 * @param authenticatedUser 061 * @param locationLimits 062 * @param dataGroups 063 * @param levelFilter 064 * @param dateInterval 065 * @param limits 066 * @param groupMethod 067 * @param groupRange 068 * @param userIdFilter 069 * @return see {@link service.tut.pori.apilta.shock.datatypes.ShockMeasurementList} 070 */ 071 @HTTPServiceMethod(name = Definitions.METHOD_GET_MEASUREMENTS, acceptedMethods={core.tut.pori.http.Definitions.METHOD_GET}) 072 public Response getMeasurements ( 073 @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser, 074 @HTTPMethodParameter(name = LocationLimits.PARAMETER_DEFAULT_NAME, required = false) LocationLimits locationLimits, 075 @HTTPMethodParameter(name = DataGroups.PARAMETER_DEFAULT_NAME, required = false) DataGroups dataGroups, 076 @HTTPMethodParameter(name = Definitions.PARAMETER_LEVEL, required = false) IntegerParameter levelFilter, 077 @HTTPMethodParameter(name = Definitions.PARAMETER_TIMESTAMP, required = false) DateIntervalParameter dateInterval, 078 @HTTPMethodParameter(name = Limits.PARAMETER_DEFAULT_NAME, required = false) Limits limits, 079 @HTTPMethodParameter(name = Definitions.PARAMETER_GROUP_METHOD, required = false) StringParameter groupMethod, 080 @HTTPMethodParameter(name = Definitions.PARAMETER_GROUP_RANGE, required = false) IntegerParameter groupRange, 081 @HTTPMethodParameter(name = service.tut.pori.users.Definitions.PARAMETER_USER_ID, required = false) LongParameter userIdFilter 082 ) 083 { 084 return new Response(ShockCore.getMeasurements(authenticatedUser.getUserIdentity(), locationLimits, dataGroups, dateInterval, levelFilter.getValues(), limits, (groupMethod.hasValues() ? GroupMethod.fromString(groupMethod.getValue()) : null), groupRange.getValue(), userIdFilter.getValues())); 085 } 086 087 /** 088 * 089 * @param authenticatedUser 090 * @param minMeasurements 091 * @param range 092 * @param locationLimits 093 * @param levelFilter 094 * @param dateInterval 095 * @param limits 096 * @param userIdFilter 097 * @return see {@link service.tut.pori.apilta.shock.datatypes.ShockHighlightList} 098 */ 099 @HTTPServiceMethod(name = Definitions.METHOD_GET_HIGHLIGHTS, acceptedMethods={core.tut.pori.http.Definitions.METHOD_GET}) 100 public Response getHighlights ( 101 @HTTPAuthenticationParameter AuthenticationParameter authenticatedUser, 102 @HTTPMethodParameter(name = Definitions.PARAMETER_MIN_MEASUREMENTS) IntegerParameter minMeasurements, 103 @HTTPMethodParameter(name = Definitions.PARAMETER_RANGE) DoubleParameter range, 104 @HTTPMethodParameter(name = LocationLimits.PARAMETER_DEFAULT_NAME, required = false) LocationLimits locationLimits, 105 @HTTPMethodParameter(name = Definitions.PARAMETER_LEVEL, required = false) IntegerParameter levelFilter, 106 @HTTPMethodParameter(name = Definitions.PARAMETER_TIMESTAMP, required = false) DateIntervalParameter dateInterval, 107 @HTTPMethodParameter(name = Limits.PARAMETER_DEFAULT_NAME, required = false) Limits limits, 108 @HTTPMethodParameter(name = service.tut.pori.users.Definitions.PARAMETER_USER_ID, required = false) LongParameter userIdFilter 109 ) 110 { 111 return new Response(ShockCore.getHighlights(authenticatedUser.getUserIdentity(), minMeasurements.getValue(), range.getValue(), locationLimits, dateInterval, levelFilter.getValues(), limits, userIdFilter.getValues())); 112 } 113}