Skip to content
Snippets Groups Projects
Commit a464ba3f authored by root's avatar root
Browse files

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

parent 41f5e216
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@
package com.tecnalia.DVPolicyEngine.api;
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.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
......@@ -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]")
@Validated
public interface GetAccessApi {
/*public interface GetAccessApi {
@Operation(summary = "", description = "Get if the access is granted to a specific seeker", tags={ })
@ApiResponses(value = {
......@@ -46,5 +48,21 @@ public interface GetAccessApi {
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);
}
}*/
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;
import com.tecnalia.DVPolicyEngine.model.Access;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tecnalia.DVPolicyEngine.model.Input;
import com.tecnalia.DVPolicyEngine.service.PolicyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
......@@ -34,6 +36,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,23 +59,46 @@ public class GetAccessApiController implements GetAccessApi {
this.objectMapper = objectMapper;
this.request = request;
}
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(@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) {
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
*/
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}";
System.out.println("organizationAttributesAsString:"+organizationAttributesAsString);
/*"
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 {
}
*/
JSONObject organizationAttributesJson = null;
JSONObject accessPolicyAsJSON = null;
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 {
String sNonConformities="";
while (orgKeys.hasNext()) {
orgKey = orgKeys.next();
System.out.println("Key organization:"+orgKey);
//System.out.println("Key organization:"+orgKey);
String lowerOrgKey=orgKey.toLowerCase();
policyKeys=accessPolicyAsJSON.keys();
while (policyKeys.hasNext()) {
policyKey = policyKeys.next();
System.out.println("Key policy:"+policyKey);
//System.out.println("Key policy:"+policyKey);
String lowerPolicyKey=policyKey.toLowerCase();
......@@ -236,11 +236,11 @@ public class PolicyService {
int iOrgValue=-1;
try{
sOrgValue=organizationAttributesJson.getString(parameterOrg);
System.out.println("Value for organization:"+sOrgValue);
// System.out.println("Value for organization:"+sOrgValue);
}
catch(Exception e){
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 {
if (jArray.toString().contains(sOrgValue)){
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 {
if (iValue==iOrgValue){
result=true;
System.out.println("Is the same value?:"+result);
// System.out.println("Is the same value?:"+result);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment