Skip to content
Snippets Groups Projects
Commit 3547eb8e authored by Rodríguez Ortega, Alejandro's avatar Rodríguez Ortega, Alejandro
Browse files

Simplified rest interface for Anonymice methods.

parent 34b4b655
No related branches found
No related tags found
No related merge requests found
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
package model; package com.tecnalia.urbanite.anonymize.model;
import java.util.List; import java.util.List;
......
...@@ -15,10 +15,7 @@ ...@@ -15,10 +15,7 @@
*/ */
package com.tecnalia.urbanite.anonymize.rest; package com.tecnalia.urbanite.anonymize.rest;
import javax.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -27,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -27,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; 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 com.tecnalia.urbanite.anonymize.service.AnonymizerService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
...@@ -34,7 +33,6 @@ import io.swagger.v3.oas.annotations.Parameter; ...@@ -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.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import model.Location;
@RestController @RestController
@Tag(name = "Anonymize", description = "Operations to Anonymize Data") @Tag(name = "Anonymize", description = "Operations to Anonymize Data")
...@@ -49,12 +47,12 @@ public class AnonymizerAPI { ...@@ -49,12 +47,12 @@ public class AnonymizerAPI {
@ApiResponse(responseCode = "400", description = "Bad request. (User unknow)")}) @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.") @Operation(summary = "Anonymize property that has certain value", description = "Change the value {value} of the {property} for a hash.")
public ResponseEntity<String> anonymizeUser( 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 = "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 = "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 { @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 { ...@@ -63,7 +61,8 @@ public class AnonymizerAPI {
@ApiResponse(responseCode = "200", description = "Successful operation."), @ApiResponse(responseCode = "200", description = "Successful operation."),
@ApiResponse(responseCode = "400", description = "Bad request. ")}) @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" @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( public ResponseEntity<String> removePointsOutOfArea(
@Parameter(description = "Points array to be validated ", example = "{\"location\": {\n" @Parameter(description = "Points array to be validated ", example = "{\"location\": {\n"
+ " \"type\": \"LineString\",\n" + " \"type\": \"LineString\",\n"
...@@ -73,27 +72,28 @@ public class AnonymizerAPI { ...@@ -73,27 +72,28 @@ public class AnonymizerAPI {
+ " [15.4643297195435, 38.1587890805601]\n" + " [15.4643297195435, 38.1587890805601]\n"
+ " ]\n" + " ]\n"
+ " }}") @RequestBody Location location, + " }}") @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 = "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 = "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 { @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 = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful operation."), @ApiResponse(responseCode = "200", description = "Successful operation."),
@ApiResponse(responseCode = "400", description = "Bad request. ")}) @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.") + " {meters} of the beginnig and the end.")
public ResponseEntity<String> generateAnonymousVehicleTripFromVehiclePoints( 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 @Parameter(description = "Meters to delete", example = "50", required = false) @RequestParam(required = false) double meters
) throws Exception { ) throws Exception {
return anonymizerService.generateAnonymousVehicleTripFromVehiclePointsString("messina","vehicle","name", meters); return anonymizerService.generateAnonymousVehicleTripFromVehiclePointsString(city.name(),"vehicle","name", meters);
} }
} }
...@@ -15,11 +15,11 @@ import org.springframework.http.HttpStatus; ...@@ -15,11 +15,11 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; 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.Configuration;
import com.tecnalia.urbanite.anonymize.utils.Crypto; import com.tecnalia.urbanite.anonymize.utils.Crypto;
import com.tecnalia.urbanite.anonymize.utils.DataUtils; import com.tecnalia.urbanite.anonymize.utils.DataUtils;
import model.Location;
import sml.gps.datamodel.GPSPoint; import sml.gps.datamodel.GPSPoint;
import sml.gps.datamodel.GPSRoute; import sml.gps.datamodel.GPSRoute;
import sml.utils.GeoDistance; import sml.utils.GeoDistance;
...@@ -151,7 +151,7 @@ public class AnonymizerService { ...@@ -151,7 +151,7 @@ public class AnonymizerService {
return new ResponseEntity<>(respuesta, HttpStatus.OK); return new ResponseEntity<>(respuesta, HttpStatus.OK);
} }
else { 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 { ...@@ -198,7 +198,7 @@ public class AnonymizerService {
JSONArray coordinate = josnlocation.getJSONArray("coordinates"); JSONArray coordinate = josnlocation.getJSONArray("coordinates");
if (!path.contains(coordinate.getDouble(0), coordinate.getDouble(1))) { 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")); /*JSONObject result =dataService.deleteObject(model, city,object.getString("id"));
if (result.has("Error")) { if (result.has("Error")) {
return new ResponseEntity<>("Error while anonymizig:" + property + ". Please try again !!\n " + result.getString("Error"), HttpStatus.INTERNAL_SERVER_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 { ...@@ -208,7 +208,7 @@ public class AnonymizerService {
}*/ }*/
} }
else{ else{
System.out.println("Not Contains!"); System.out.println("Contains!");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment