Fixed bugs on resource creation
This commit is contained in:
parent
7f1a2e96bd
commit
e9d5de90a3
|
@ -7,9 +7,21 @@ import java.util.Map;
|
||||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||||
|
|
||||||
//Risorsa da inviare per la creazione
|
//Risorsa da inviare per la creazione
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class FacetDescription {
|
public class FacetDescription {
|
||||||
|
String type;
|
||||||
|
Map<String,String> target;
|
||||||
|
/*
|
||||||
String type;
|
String type;
|
||||||
FacetProperties target;
|
FacetPropertyGroup target;
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.web.rest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -10,6 +11,7 @@ import java.util.UUID;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectWriter;
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
import org.gcube.informationsystem.config.TokenManager;
|
import org.gcube.informationsystem.config.TokenManager;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
|
@ -22,8 +24,6 @@ import org.gcube.informationsystem.service.dto.FacetSpecDTO;
|
||||||
import org.gcube.informationsystem.service.dto.FacetTypeDTO;
|
import org.gcube.informationsystem.service.dto.FacetTypeDTO;
|
||||||
import org.gcube.informationsystem.service.dto.ResourceBuilderDTO;
|
import org.gcube.informationsystem.service.dto.ResourceBuilderDTO;
|
||||||
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
|
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
|
||||||
import org.gcube.informationsystem.service.dto.VirtualServiceDTO;
|
|
||||||
import org.gcube.informationsystem.service.dto.angular.VirtualServiceAngular;
|
|
||||||
import org.gcube.informationsystem.utils.UUIDUtility;
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -37,7 +37,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.util.UriUtils;
|
import org.springframework.web.util.UriUtils;
|
||||||
|
|
||||||
|
import com.jayway.jsonpath.JsonPath;
|
||||||
|
|
||||||
|
import io.swagger.v3.core.util.Json;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.minidev.json.JSONArray;
|
||||||
import tech.jhipster.web.util.HeaderUtil;
|
import tech.jhipster.web.util.HeaderUtil;
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,44 +245,39 @@ public class InformationSystemResource {
|
||||||
|
|
||||||
//CRUD - 1
|
//CRUD - 1
|
||||||
@PostMapping("/createresource")
|
@PostMapping("/createresource")
|
||||||
String createResource(@RequestParam String resourceType, @RequestBody String rawJson) throws Exception {
|
String createResource(@RequestParam String resourceType, @RequestBody String formData) throws Exception {
|
||||||
//NB: non serve UmaToken e context!
|
//NB: non serve UmaToken e context!
|
||||||
|
ArrayList<String> facetNames = new ArrayList<>();
|
||||||
|
ArrayList<String> facetRelations = new ArrayList<>();
|
||||||
|
ArrayList<JSONArray> extraProps = new ArrayList<JSONArray>();
|
||||||
|
JSONArray props = new JSONArray();
|
||||||
|
|
||||||
log.debug("********** RAWJSON ******");
|
String sendingJson="";
|
||||||
String eccolo = rawJson;
|
try {
|
||||||
log.debug("****************");
|
|
||||||
|
|
||||||
String rawJson2="";
|
facetNames = JsonPath.parse(formData).read("$..facetName");
|
||||||
ObjectMapper om = new ObjectMapper();
|
facetRelations = JsonPath.parse(formData).read("$..relationFacet");
|
||||||
/*
|
extraProps = JsonPath.parse(formData).read("$..extraProps");
|
||||||
* switch(this.getPropertyType()) {
|
props = JsonPath.parse(formData).read("$..props");
|
||||||
case "Boolean": tmp="boolean";
|
|
||||||
break;
|
ResourceDescription rd = new ResourceDescription();
|
||||||
case "Date": tmp="date";
|
rd = buildSendingJson(resourceType,facetNames,facetRelations,extraProps,props);
|
||||||
break;
|
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
|
||||||
case "String": tmp="text";
|
sendingJson = ow.writeValueAsString(rd);
|
||||||
break;
|
//System.out.println(Json.pretty(rd));
|
||||||
case "Long": tmp="number";
|
}catch(Exception e) {
|
||||||
break;
|
log.error(e.getMessage());
|
||||||
case "Integer": tmp="number";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
switch(resourceType) {
|
|
||||||
|
|
||||||
case "VirtualService": {
|
|
||||||
VirtualServiceAngular inputObject = om.readValue(rawJson.toString(), VirtualServiceAngular.class);
|
|
||||||
inputObject.setTypeName("VirtualService");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// String currentCtx = SecretManagerProvider.instance.get().getContext();
|
// String currentCtx = SecretManagerProvider.instance.get().getContext();
|
||||||
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
|
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
|
||||||
String uid = publisher.createResource(rawJson2);
|
String uid="";
|
||||||
|
try {
|
||||||
|
uid = publisher.createResource(sendingJson);
|
||||||
|
}catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
return uid;
|
return uid;
|
||||||
//TODO: GESTIRE ERRORI!
|
//TODO: GESTIRE ERRORI!
|
||||||
}
|
}
|
||||||
|
@ -296,4 +295,47 @@ public class InformationSystemResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceDescription buildSendingJson(String resourceType, ArrayList<String> facetNames, ArrayList<String> relations, ArrayList<JSONArray> extraProps, JSONArray props ) {
|
||||||
|
|
||||||
|
ResourceDescription rd = new ResourceDescription();
|
||||||
|
rd.setType(resourceType);
|
||||||
|
for(int i=0; i<facetNames.size(); i++) {
|
||||||
|
LinkedHashMap targetMap_i = new LinkedHashMap<String, Object>();
|
||||||
|
FacetDescription facet_i = new FacetDescription();
|
||||||
|
facet_i.setType(relations.get(i));
|
||||||
|
FacetDescription facet_d = new FacetDescription();
|
||||||
|
LinkedHashMap joProp_i = (LinkedHashMap)props.get(i);
|
||||||
|
joProp_i.put("type", facetNames.get(i));
|
||||||
|
Iterator<String> keyit = (Iterator) joProp_i.keySet().iterator();
|
||||||
|
while(keyit.hasNext()) {
|
||||||
|
String key = keyit.next();
|
||||||
|
if(key.equals("optional")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
targetMap_i.put(key, joProp_i.get(key).toString());
|
||||||
|
}
|
||||||
|
JSONArray extra_joProps_i = (JSONArray)extraProps.get(i);
|
||||||
|
if(extra_joProps_i.size()!=0) {
|
||||||
|
for(int j=0; j<extra_joProps_i.size(); j++) {
|
||||||
|
LinkedHashMap extraProps_ij = (LinkedHashMap)extra_joProps_i.get(j);
|
||||||
|
Iterator<String> it = (Iterator) extraProps_ij.keySet().iterator();
|
||||||
|
while(it.hasNext()) {
|
||||||
|
String key = it.next();
|
||||||
|
targetMap_i.put(extraProps_ij.get("deno").toString(),extraProps_ij.get("val").toString());//to avoid ClassCastException
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
facet_i.setTarget(targetMap_i);
|
||||||
|
if(rd.getConsistsOf()==null) {
|
||||||
|
rd.setConsistsOf(new ArrayList<FacetDescription>());
|
||||||
|
}
|
||||||
|
rd.getConsistsOf().add(facet_i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,13 @@ import java.util.Map;
|
||||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||||
|
|
||||||
//Risorsa da inviare per la creazione
|
//Risorsa da inviare per la creazione
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class ResourceDescription {
|
public class ResourceDescription {
|
||||||
String type;
|
String type;
|
||||||
ArrayList<FacetDescription> consistsOf;
|
ArrayList<FacetDescription> consistsOf;
|
||||||
|
|
Loading…
Reference in New Issue