From 3547eb8e4d9a7ec4849b0be09471fc1be1af3d20 Mon Sep 17 00:00:00 2001 From: alexrodriguez <alejandro.rodriguez@tecnalia.com> Date: Tue, 29 Nov 2022 11:37:11 +0100 Subject: [PATCH] Simplified rest interface for Anonymice methods. --- .../urbanite/anonymize/model/City.java | 26 +++++++++++++++++ .../urbanite/anonymize}/model/Location.java | 2 +- .../anonymize/rest/AnonymizerAPI.java | 28 +++++++++---------- .../anonymize/service/AnonymizerService.java | 8 +++--- 4 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/tecnalia/urbanite/anonymize/model/City.java rename src/main/java/{ => com/tecnalia/urbanite/anonymize}/model/Location.java (84%) diff --git a/src/main/java/com/tecnalia/urbanite/anonymize/model/City.java b/src/main/java/com/tecnalia/urbanite/anonymize/model/City.java new file mode 100644 index 0000000..e8d5420 --- /dev/null +++ b/src/main/java/com/tecnalia/urbanite/anonymize/model/City.java @@ -0,0 +1,26 @@ +package com.tecnalia.urbanite.anonymize.model; + +import org.apache.commons.lang3.StringUtils; + +public enum City { + bilbao, + messina, + helsinki, + amsterdam; + + public static Boolean any(String id) + { + if(!StringUtils.isBlank(id)) + { + for(City city : City.values()) + { + if(id.equals(city.name())) + { + return true; + } + } + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/model/Location.java b/src/main/java/com/tecnalia/urbanite/anonymize/model/Location.java similarity index 84% rename from src/main/java/model/Location.java rename to src/main/java/com/tecnalia/urbanite/anonymize/model/Location.java index 05d7a7f..fa5c2ae 100644 --- a/src/main/java/model/Location.java +++ b/src/main/java/com/tecnalia/urbanite/anonymize/model/Location.java @@ -1,4 +1,4 @@ -package model; +package com.tecnalia.urbanite.anonymize.model; import java.util.List; diff --git a/src/main/java/com/tecnalia/urbanite/anonymize/rest/AnonymizerAPI.java b/src/main/java/com/tecnalia/urbanite/anonymize/rest/AnonymizerAPI.java index 7e03117..d987c10 100644 --- a/src/main/java/com/tecnalia/urbanite/anonymize/rest/AnonymizerAPI.java +++ b/src/main/java/com/tecnalia/urbanite/anonymize/rest/AnonymizerAPI.java @@ -15,10 +15,7 @@ */ package com.tecnalia.urbanite.anonymize.rest; -import javax.websocket.server.PathParam; - import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Required; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -27,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.tecnalia.urbanite.anonymize.model.City; +import com.tecnalia.urbanite.anonymize.model.Location; import com.tecnalia.urbanite.anonymize.service.AnonymizerService; import io.swagger.v3.oas.annotations.Operation; @@ -34,7 +33,6 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import model.Location; @RestController @Tag(name = "Anonymize", description = "Operations to Anonymize Data") @@ -49,12 +47,12 @@ public class AnonymizerAPI { @ApiResponse(responseCode = "400", description = "Bad request. (User unknow)")}) @Operation(summary = "Anonymize property that has certain value", description = "Change the value {value} of the {property} for a hash.") public ResponseEntity<String> anonymizeUser( - @Parameter(description = "City where is the model to be anonymized", example = "bilbao") @PathVariable String city, + @Parameter(description = "City where is the data to be processed") @PathVariable City city, @Parameter(description = "Model that is going to be anonymized.", example = "vehicle") @PathVariable String model, @Parameter(description = "Property of the model that is going to be anonymized.", example = "name") @PathVariable String property, @Parameter(description = "Only the properties with this value are going to be modified.", example = "Jonh") @PathVariable String value) throws Exception { - return anonymizerService.anonymizeProperty(city,model,property,value); + return anonymizerService.anonymizeProperty(city.name(),model,property,value); } @@ -63,7 +61,8 @@ public class AnonymizerAPI { @ApiResponse(responseCode = "200", description = "Successful operation."), @ApiResponse(responseCode = "400", description = "Bad request. ")}) @Operation(summary = "Given an input polygon, delete the points outside that polygon ", description = "Given an input polygon,{location} delete the points outside that polygon. The points are those defined by the city, property and value model.\n" - + "And they must have a \"location\" field with an array of \"coordinates\". ") + + "And they must have a \"location\" field with an array of \"coordinates\"." + + "<br/><br/><b>THIS SERVICE HAS BEEN DISABLED IN THE TEST ENVIRONMENT</b> ") public ResponseEntity<String> removePointsOutOfArea( @Parameter(description = "Points array to be validated ", example = "{\"location\": {\n" + " \"type\": \"LineString\",\n" @@ -73,27 +72,28 @@ public class AnonymizerAPI { + " [15.4643297195435, 38.1587890805601]\n" + " ]\n" + " }}") @RequestBody Location location, - @Parameter(description = "City where is the model to be anonymized", example = "bilbao") @PathVariable String city, + @Parameter(description = "City where is the data to be processed") @PathVariable City city, @Parameter(description = "Model that is going to be anonymized.", example = "vehicle") @PathVariable String model, @Parameter(description = "Property of the model that is going to be anonymized.", example = "name") @PathVariable String property, @Parameter(description = "Only the properties with this value are going to be modified.", example = "Jonh") @PathVariable String value) throws Exception { - return anonymizerService.removePointsOutOfArea(location,city,model,property,value); + return anonymizerService.removePointsOutOfArea(location,city.name(),model,property,value); } - @RequestMapping(method = RequestMethod.POST, value = "/generateAnonymousVehicleTripFromVehiclePoints") + @RequestMapping(method = RequestMethod.POST, value = "/generateAnonymousVehicleTripFromVehiclePoints/{city}") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successful operation."), @ApiResponse(responseCode = "400", description = "Bad request. ")}) - @Operation(summary = "Generate anonymiced routes from trips.", description = "The service get the messina Vehicle points of ebikes and generate GPS Routes, then anonymice this routas deleting the " + @Operation(summary = "Generate anonymiced routes from vehicles points.", description = "The service get the messina Vehicle points of ebikes and generate GPS Routes, then anonymice this routas deleting the " + " {meters} of the beginnig and the end.") - public ResponseEntity<String> generateAnonymousVehicleTripFromVehiclePoints( - @Parameter(description = "Meters to delete", example = "50", required = false) @RequestParam(required = false) double meters + public ResponseEntity<String> generateAnonymousVehicleTripFromVehiclePoints( + @Parameter(description = "City where is the data to be processed", example = "messina") @PathVariable City city, + @Parameter(description = "Meters to delete", example = "50", required = false) @RequestParam(required = false) double meters ) throws Exception { - return anonymizerService.generateAnonymousVehicleTripFromVehiclePointsString("messina","vehicle","name", meters); + return anonymizerService.generateAnonymousVehicleTripFromVehiclePointsString(city.name(),"vehicle","name", meters); } } diff --git a/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java b/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java index 2860577..1c194a8 100644 --- a/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java +++ b/src/main/java/com/tecnalia/urbanite/anonymize/service/AnonymizerService.java @@ -15,11 +15,11 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import com.tecnalia.urbanite.anonymize.model.Location; import com.tecnalia.urbanite.anonymize.utils.Configuration; import com.tecnalia.urbanite.anonymize.utils.Crypto; import com.tecnalia.urbanite.anonymize.utils.DataUtils; -import model.Location; import sml.gps.datamodel.GPSPoint; import sml.gps.datamodel.GPSRoute; import sml.utils.GeoDistance; @@ -151,7 +151,7 @@ public class AnonymizerService { return new ResponseEntity<>(respuesta, HttpStatus.OK); } else { - return new ResponseEntity<>("Error generation anonymous routes fromvehicles !!", HttpStatus.BAD_REQUEST); + return new ResponseEntity<>("Error generating anonymous routes, no data available !!", HttpStatus.BAD_REQUEST); } @@ -198,7 +198,7 @@ public class AnonymizerService { JSONArray coordinate = josnlocation.getJSONArray("coordinates"); if (!path.contains(coordinate.getDouble(0), coordinate.getDouble(1))) { - System.out.println("Contains!"); + System.out.println("Not Contains!"); /*JSONObject result =dataService.deleteObject(model, city,object.getString("id")); if (result.has("Error")) { return new ResponseEntity<>("Error while anonymizig:" + property + ". Please try again !!\n " + result.getString("Error"), HttpStatus.INTERNAL_SERVER_ERROR); @@ -208,7 +208,7 @@ public class AnonymizerService { }*/ } else{ - System.out.println("Not Contains!"); + System.out.println("Contains!"); } -- GitLab