Commit 84bc2cfe authored by root's avatar root
Browse files

Include the functionality for read dataset info

parent 9d0833a8
......@@ -67,7 +67,7 @@ public class GetAccessApiController implements GetAccessApi {
*/
String organizationAttributesAsString=policyService.getDataSeekersOrganizationPolicy(dataSeekerID);
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);
......@@ -83,33 +83,57 @@ public class GetAccessApiController implements GetAccessApi {
}
*/
JSONObject organizationAttributesJson = null;
JSONObject accessPolicyAsJSON = null;
List<Access> listAccess =new ArrayList<Access>();
try{
organizationAttributesJson=new JSONObject(organizationAttributesAsString);
for (String datasetID : datasetIDList) {
String accessPolicyasString=policyService.getDatasetPolicies(datasetID);
String accessPolicyasString=policyService.getDatasetPolicy(datasetID);
try
{
accessPolicyAsJSON = new JSONObject(accessPolicyasString);
System.out.println("accessPolicyasString:"+accessPolicyasString);
// 3.-Comparar los atributos de la organización con los de la politica y construir el objeto Access y añadirlo a la lista
Access access=policyService.checkAtributesInPolicy( datasetID, organizationAttributesAsString, accessPolicyasString);
Access access=policyService.checkAtributesInPolicy( datasetID, organizationAttributesJson, accessPolicyAsJSON);
if (access!=null)
listAccess.add(access);
}
}
catch(Exception e){
Access access=new Access();
access.datasetID(datasetID);
access.setGranted(Boolean.FALSE);
access.setNonConformities(accessPolicyasString);
listAccess.add(access);
//return new ResponseEntity<List<Access>>(listAccess, HttpStatus.INTERNAL_SERVER_ERROR);
}
/* if (accept != null && accept.contains("application/json")) {
try {
return new ResponseEntity<List<Access>>(objectMapper.readValue("[ {\n \"Dataset_ID\" : \"Dataset_ID\",\n \"non_conformities\" : \"non_conformities\",\n \"granted\" : true\n}, {\n \"Dataset_ID\" : \"Dataset_ID\",\n \"non_conformities\" : \"non_conformities\",\n \"granted\" : true\n} ]", List.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<List<Access>>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}catch (Exception e){
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<List<Access>>(HttpStatus.NOT_IMPLEMENTED);*/
return new ResponseEntity<List<Access>>(listAccess, HttpStatus.OK);
......
......@@ -86,7 +86,7 @@ public class PolicyService {
}
public String getDatasetPolicies(String datasetID) {
public String getDatasetPolicy(String datasetID) {
String accessPolicyAsString="";
try {
......@@ -104,9 +104,10 @@ public class PolicyService {
//{"DatasetId":"ActivityData-Riccardo"}
String jsondata="{\"DatasetId\":"+"\""+datasetID+"\""+"}";
String datasetInformationAsString="";
String address="https://datavaults-test-126.euprojects.net/readDatasetId";
datasetInformationAsString = httpUtils.sendHttpPostRequest(address, jsondata);
String datasetInformationAsString = httpUtils.sendHttpPostRequest(address, jsondata);
JSONObject accessPolicyAsJSON = new JSONObject();
try{
accessPolicyAsJSON = new JSONObject(datasetInformationAsString);
......@@ -114,7 +115,7 @@ public class PolicyService {
accessPolicyAsString=policy.toString();
}
catch (Exception e) {
accessPolicyAsString=datasetInformationAsString;
}
......@@ -122,16 +123,17 @@ public class PolicyService {
}
return accessPolicyAsString;
}
public Access checkAtributesInPolicy(String datasetID,String organizationAttributesAsString, String accessPolicyasString){
public Access checkAtributesInPolicy(String datasetID,JSONObject organizationAttributesJson, JSONObject accessPolicyAsJSON){
Access access=new Access();
Iterator<String> orgKeys = null;
Iterator<String> policyKeys = null;
JSONObject organizationAttributesJson = null;
JSONObject accessPolicyAsJSON = null;
/* JSONObject organizationAttributesJson = null;
JSONObject accessPolicyAsJSON = null;*/
//Example
//organizationAttributesAsString:{"name":"Test Organization","sector":"Test Sector","continent":"EU","country":"GRE","type":"Private Entity","size":"medium","reputation":7}
......@@ -139,7 +141,7 @@ public class PolicyService {
try{
organizationAttributesJson = new JSONObject(organizationAttributesAsString);
// organizationAttributesJson = new JSONObject(organizationAttributesAsString);
orgKeys = organizationAttributesJson.keys();
......@@ -159,7 +161,7 @@ public class PolicyService {
try{
accessPolicyAsJSON = new JSONObject(accessPolicyasString);
// accessPolicyAsJSON = new JSONObject(accessPolicyasString);
//policyKeys=accessPolicyAsJSON.keys();
/* JSONArray jArrayContinent=accessPolicyAsJSON.getJSONArray("Continent");
......
......@@ -10,7 +10,7 @@ springdoc.swagger-ui.path=/swagger-ui.html
datavaults.api.url=https://datavaults-cloud.euprojects.net/api/v1/group
datavaults.api.url=https://platform.datavaults.eu/api/v1/group
datavaults.auth.server.url=https://datavaults-auth.euprojects.net/auth/realms/platform/protocol/openid-connect/token
datavaults.auth.client.id=backend-service
datavaults.auth.client.secret=04892d79-f600-4410-a9ac-6860aa5bdf3e
......
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