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;
|
||||
|
||||
//Risorsa da inviare per la creazione
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FacetDescription {
|
||||
String type;
|
||||
Map<String,String> target;
|
||||
/*
|
||||
String type;
|
||||
FacetProperties target;
|
||||
FacetPropertyGroup target;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.web.rest;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -10,6 +11,7 @@ import java.util.UUID;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
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.informationsystem.config.TokenManager;
|
||||
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.ResourceBuilderDTO;
|
||||
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.slf4j.Logger;
|
||||
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.util.UriUtils;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minidev.json.JSONArray;
|
||||
import tech.jhipster.web.util.HeaderUtil;
|
||||
|
||||
|
||||
|
@ -241,44 +245,39 @@ public class InformationSystemResource {
|
|||
|
||||
//CRUD - 1
|
||||
@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!
|
||||
|
||||
log.debug("********** RAWJSON ******");
|
||||
String eccolo = rawJson;
|
||||
log.debug("****************");
|
||||
|
||||
String rawJson2="";
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
/*
|
||||
* switch(this.getPropertyType()) {
|
||||
case "Boolean": tmp="boolean";
|
||||
break;
|
||||
case "Date": tmp="date";
|
||||
break;
|
||||
case "String": tmp="text";
|
||||
break;
|
||||
case "Long": tmp="number";
|
||||
break;
|
||||
case "Integer": tmp="number";
|
||||
break;
|
||||
ArrayList<String> facetNames = new ArrayList<>();
|
||||
ArrayList<String> facetRelations = new ArrayList<>();
|
||||
ArrayList<JSONArray> extraProps = new ArrayList<JSONArray>();
|
||||
JSONArray props = new JSONArray();
|
||||
|
||||
String sendingJson="";
|
||||
try {
|
||||
|
||||
facetNames = JsonPath.parse(formData).read("$..facetName");
|
||||
facetRelations = JsonPath.parse(formData).read("$..relationFacet");
|
||||
extraProps = JsonPath.parse(formData).read("$..extraProps");
|
||||
props = JsonPath.parse(formData).read("$..props");
|
||||
|
||||
ResourceDescription rd = new ResourceDescription();
|
||||
rd = buildSendingJson(resourceType,facetNames,facetRelations,extraProps,props);
|
||||
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
|
||||
sendingJson = ow.writeValueAsString(rd);
|
||||
//System.out.println(Json.pretty(rd));
|
||||
}catch(Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
*/
|
||||
switch(resourceType) {
|
||||
|
||||
case "VirtualService": {
|
||||
VirtualServiceAngular inputObject = om.readValue(rawJson.toString(), VirtualServiceAngular.class);
|
||||
inputObject.setTypeName("VirtualService");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// String currentCtx = SecretManagerProvider.instance.get().getContext();
|
||||
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;
|
||||
//TODO: GESTIRE ERRORI!
|
||||
}
|
||||
|
@ -295,5 +294,48 @@ public class InformationSystemResource {
|
|||
//TODO: GESTIRE ERRORI!
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
//Risorsa da inviare per la creazione
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ResourceDescription {
|
||||
String type;
|
||||
ArrayList<FacetDescription> consistsOf;
|
||||
|
|
Loading…
Reference in New Issue