Commit a464ba3f authored by root's avatar root
Browse files

Changes in the getAccess API to POST and requestBody as input parameter

parent 41f5e216
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
package com.tecnalia.DVPolicyEngine.api; package com.tecnalia.DVPolicyEngine.api;
import com.tecnalia.DVPolicyEngine.model.Access; import com.tecnalia.DVPolicyEngine.model.Access;
import com.tecnalia.DVPolicyEngine.model.Input;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.enums.ParameterIn;
...@@ -34,7 +36,7 @@ import java.util.Map; ...@@ -34,7 +36,7 @@ import java.util.Map;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-07-16T07:58:35.159Z[GMT]") @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-07-16T07:58:35.159Z[GMT]")
@Validated @Validated
public interface GetAccessApi { /*public interface GetAccessApi {
@Operation(summary = "", description = "Get if the access is granted to a specific seeker", tags={ }) @Operation(summary = "", description = "Get if the access is granted to a specific seeker", tags={ })
@ApiResponses(value = { @ApiResponses(value = {
...@@ -46,5 +48,21 @@ public interface GetAccessApi { ...@@ -46,5 +48,21 @@ public interface GetAccessApi {
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<List<Access>> getAccessByAttributes(@NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DatasetID_list", required = true) List<String> datasetIDList, @NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DataSeekerID", required = true) String dataSeekerID); ResponseEntity<List<Access>> getAccessByAttributes(@NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DatasetID_list", required = true) List<String> datasetIDList, @NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DataSeekerID", required = true) String dataSeekerID);
} }*/
public interface GetAccessApi {
@Operation(summary = "", description = "Get if the access is granted to a specific seeker", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "access requested", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Access.class)))),
@ApiResponse(responseCode = "500", description = "internal system error") })
@RequestMapping(value = "/getAccess",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.POST)
ResponseEntity<List<Access>> getAccessByAttributes(@Parameter(in = ParameterIn.DEFAULT, description = "", required=true, schema=@Schema()) @Valid @RequestBody Input body);
}
...@@ -2,7 +2,9 @@ package com.tecnalia.DVPolicyEngine.api; ...@@ -2,7 +2,9 @@ package com.tecnalia.DVPolicyEngine.api;
import com.tecnalia.DVPolicyEngine.model.Access; import com.tecnalia.DVPolicyEngine.model.Access;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.tecnalia.DVPolicyEngine.model.Input;
import com.tecnalia.DVPolicyEngine.service.PolicyService; import com.tecnalia.DVPolicyEngine.service.PolicyService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.enums.ParameterIn;
...@@ -34,6 +36,7 @@ import java.util.ArrayList; ...@@ -34,6 +36,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -56,23 +59,46 @@ public class GetAccessApiController implements GetAccessApi { ...@@ -56,23 +59,46 @@ public class GetAccessApiController implements GetAccessApi {
this.objectMapper = objectMapper; this.objectMapper = objectMapper;
this.request = request; this.request = request;
} }
public ResponseEntity<List<Access>> getAccessByAttributes(@Parameter(in = ParameterIn.DEFAULT, description = "", required=true, schema=@Schema()) @Valid @RequestBody Input body) {
public ResponseEntity<List<Access>> getAccessByAttributes(@NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DatasetID_list", required = true) List<String> datasetIDList,@NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DataSeekerID", required = true) String dataSeekerID) { // public ResponseEntity<List<Access>> getAccessByAttributes(@NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DatasetID_list", required = true) List<String> datasetIDList,@NotNull @Parameter(in = ParameterIn.QUERY, description = "" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "DataSeekerID", required = true) String dataSeekerID) {
String accept = request.getHeader("Accept"); String accept = request.getHeader("Accept");
String dataSeekerID="";
String organizationAttributesAsString="";
List<String> datasetIDList=null;
/* 1.-GetDataSeekersOrganisationPolicy (DataSeekerID) -> de aqui obtenemos los atributos de la organización /* 1.-GetDataSeekersOrganisationPolicy (DataSeekerID) -> de aqui obtenemos los atributos de la organización
*/ */
String organizationAttributesAsString=policyService.getDataSeekersOrganizationPolicy(dataSeekerID);
/* {
"dataseekerID":"462626262",
"DatasetIDs":[
"1421515",
"616266262"
]
}*/ try{
dataSeekerID=body.getDataseekerID();
organizationAttributesAsString=policyService.getDataSeekersOrganizationPolicy(dataSeekerID);
System.out.println("organizationAttributesAsString:"+organizationAttributesAsString);
datasetIDList=new ArrayList<String>();
datasetIDList=body.getDatasetIDs();
}
catch(Exception e){
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
// organizationAttributesAsString="{\"name\":\"Test Organization\",\"sector\":\"Test Sector\",\"continent\":\"EU\",\"country\":\"GRE\",\"type\":\"Private Entity\",\"size\":\"medium\",\"reputation\":7}"; // organizationAttributesAsString="{\"name\":\"Test Organization\",\"sector\":\"Test Sector\",\"continent\":\"EU\",\"country\":\"GRE\",\"type\":\"Private Entity\",\"size\":\"medium\",\"reputation\":7}";
System.out.println("organizationAttributesAsString:"+organizationAttributesAsString);
/*" /*"
2.- GetDatasetPolicies (DatasetID) -> de aqui obtendremos la politica con la siguiente información. -> llamada a API blockchain 2.- GetDatasetPolicies (DatasetID) -> de aqui obtendremos la politica con la siguiente información. -> llamada a API blockchain
...@@ -86,6 +112,11 @@ public class GetAccessApiController implements GetAccessApi { ...@@ -86,6 +112,11 @@ public class GetAccessApiController implements GetAccessApi {
} }
*/ */
JSONObject organizationAttributesJson = null; JSONObject organizationAttributesJson = null;
JSONObject accessPolicyAsJSON = null; JSONObject accessPolicyAsJSON = null;
List<Access> listAccess =new ArrayList<Access>(); List<Access> listAccess =new ArrayList<Access>();
......
package com.tecnalia.DVPolicyEngine.model;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.ArrayList;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* Input
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-09-10T10:28:26.192Z[GMT]")
public class Input {
@JsonProperty("dataseekerID")
private String dataseekerID = null;
@JsonProperty("DatasetIDs")
@Valid
private List<String> datasetIDs = null;
public Input dataseekerID(String dataseekerID) {
this.dataseekerID = dataseekerID;
return this;
}
/**
* Get dataseekerID
* @return dataseekerID
**/
@Schema(description = "")
public String getDataseekerID() {
return dataseekerID;
}
public void setDataseekerID(String dataseekerID) {
this.dataseekerID = dataseekerID;
}
public Input datasetIDs(List<String> datasetIDs) {
this.datasetIDs = datasetIDs;
return this;
}
public Input addDatasetIDsItem(String datasetIDsItem) {
if (this.datasetIDs == null) {
this.datasetIDs = new ArrayList<String>();
}
this.datasetIDs.add(datasetIDsItem);
return this;
}
/**
* Get datasetIDs
* @return datasetIDs
**/
@Schema(description = "")
public List<String> getDatasetIDs() {
return datasetIDs;
}
public void setDatasetIDs(List<String> datasetIDs) {
this.datasetIDs = datasetIDs;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Input input = (Input) o;
return Objects.equals(this.dataseekerID, input.dataseekerID) &&
Objects.equals(this.datasetIDs, input.datasetIDs);
}
@Override
public int hashCode() {
return Objects.hash(dataseekerID, datasetIDs);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Input {\n");
sb.append(" dataseekerID: ").append(toIndentedString(dataseekerID)).append("\n");
sb.append(" datasetIDs: ").append(toIndentedString(datasetIDs)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
...@@ -185,13 +185,13 @@ public class PolicyService { ...@@ -185,13 +185,13 @@ public class PolicyService {
String sNonConformities=""; String sNonConformities="";
while (orgKeys.hasNext()) { while (orgKeys.hasNext()) {
orgKey = orgKeys.next(); orgKey = orgKeys.next();
System.out.println("Key organization:"+orgKey); //System.out.println("Key organization:"+orgKey);
String lowerOrgKey=orgKey.toLowerCase(); String lowerOrgKey=orgKey.toLowerCase();
policyKeys=accessPolicyAsJSON.keys(); policyKeys=accessPolicyAsJSON.keys();
while (policyKeys.hasNext()) { while (policyKeys.hasNext()) {
policyKey = policyKeys.next(); policyKey = policyKeys.next();
System.out.println("Key policy:"+policyKey); //System.out.println("Key policy:"+policyKey);
String lowerPolicyKey=policyKey.toLowerCase(); String lowerPolicyKey=policyKey.toLowerCase();
...@@ -236,11 +236,11 @@ public class PolicyService { ...@@ -236,11 +236,11 @@ public class PolicyService {
int iOrgValue=-1; int iOrgValue=-1;
try{ try{
sOrgValue=organizationAttributesJson.getString(parameterOrg); sOrgValue=organizationAttributesJson.getString(parameterOrg);
System.out.println("Value for organization:"+sOrgValue); // System.out.println("Value for organization:"+sOrgValue);
} }
catch(Exception e){ catch(Exception e){
iOrgValue=organizationAttributesJson.getInt(parameterOrg); iOrgValue=organizationAttributesJson.getInt(parameterOrg);
System.out.println("Value for organization:"+iOrgValue); //System.out.println("Value for organization:"+iOrgValue);
} }
...@@ -251,7 +251,7 @@ public class PolicyService { ...@@ -251,7 +251,7 @@ public class PolicyService {
if (jArray.toString().contains(sOrgValue)){ if (jArray.toString().contains(sOrgValue)){
result=true; result=true;
System.out.println("Is the same value?:"+result); // System.out.println("Is the same value?:"+result);
} }
} }
...@@ -260,7 +260,7 @@ public class PolicyService { ...@@ -260,7 +260,7 @@ public class PolicyService {
if (iValue==iOrgValue){ if (iValue==iOrgValue){
result=true; result=true;
System.out.println("Is the same value?:"+result); // System.out.println("Is the same value?:"+result);
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment