Compare commits

...

2 Commits

Author SHA1 Message Date
Maria Teresa Paratore adfb060279 debugging on types 2024-05-08 18:06:30 +02:00
Maria Teresa Paratore f51a0a632f removed unused file 2024-05-07 15:19:42 +02:00
11 changed files with 26581 additions and 218 deletions

View File

@ -31,16 +31,19 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

26415
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,6 @@ import java.util.List;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.JWTSecret;
@ -28,10 +27,12 @@ import org.gcube.informationsystem.service.dto.FacetTypeDTO;
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
import org.gcube.informationsystem.service.dto.ValidationObjDTO;
import org.gcube.informationsystem.tree.Tree;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.impl.entities.FacetTypeImpl;
import org.gcube.informationsystem.types.impl.entities.ResourceTypeImpl;
import org.gcube.informationsystem.types.knowledge.TypeInformation;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.UUIDUtility;
@ -41,9 +42,13 @@ import org.gcube.informationsystem.web.rest.TypeProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.jayway.jsonpath.JsonPath;
import net.minidev.json.JSONArray;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Service class for managing InformationSystem resources.
*/
@ -106,36 +111,34 @@ public class InformationSystemService {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
String jsonResult = resourceRegistryClient.getType(facetName, true);
ObjectMapper objectMapper = new ObjectMapper();
//resourceRegistryClient returns an array of one element
FacetTypeImpl ft = objectMapper.readValue(jsonResult, FacetTypeImpl[].class)[0];
ArrayList<FacetPropGui> propsGui = new ArrayList<FacetPropGui>();
Type type = TypeMapper.deserializeTypeDefinitions(jsonResult).get(0); //only one result
FacetSpecDTO fsdto = new FacetSpecDTO();
fsdto.setName(ft.getName());
fsdto.setDescription(ft.getDescription());
if(ft.getProperties()!=null ) {
for(PropertyDefinition pd:ft.getProperties() ) {
try {
FacetPropertyDTO prop = new FacetPropertyDTO();
prop.setDescription(pd.getDescription());
prop.setMandatory(pd.isMandatory());
//prop.setMax(pd.getMax());
//prop.setMin(pd.getMin());
prop.setName(pd.getName());
prop.setNotnull(pd.isNotnull());
prop.setPropertyType(pd.getPropertyType());
//prop.setReadonly(pd.isReadonly());
prop.setRegexp(pd.getRegexp());
prop.setType(pd.getTypeName());
propsGui.add(toFacetPropGui(prop, resourceRegistryClient));
}catch(Exception e) {
e.printStackTrace();
ArrayList<FacetPropGui> propsGui = new ArrayList<FacetPropGui>();
FacetType ft = (FacetType) type;
fsdto.setName(ft.getTypeName());
fsdto.setDescription(ft.getDescription());
if(ft.getProperties()!=null ) {
for(PropertyDefinition pd:ft.getProperties() ) {
try {
FacetPropertyDTO prop = new FacetPropertyDTO();
prop.setDescription(pd.getDescription());
prop.setMandatory(pd.isMandatory());
//prop.setMax(pd.getMax());
//prop.setMin(pd.getMin());
prop.setName(pd.getName());
prop.setNotnull(pd.isNotnull());
prop.setPropertyType(pd.getPropertyType());
//prop.setReadonly(pd.isReadonly());
prop.setRegexp(pd.getRegexp());
prop.setType(pd.getTypeName());
propsGui.add(toFacetPropGui(prop, resourceRegistryClient));
}catch(Exception e) {
e.printStackTrace();
}
}
}
}
fsdto.setGuiProps(propsGui);
return fsdto;
fsdto.setGuiProps(propsGui);
return fsdto;
}
@ -209,29 +212,46 @@ public class InformationSystemService {
public ResourceTypeDTO getResourceType(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
String currentCtx = null;
try {
currentCtx = SecretManagerProvider.instance.get().getContext();
}catch(Exception e) {
log.error("**********");
log.error(e.getMessage(),e);
log.error("**********");
}
log.debug("getResourceType : [currentCtx=]",currentCtx);
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
//questo è un array di un elemento
String jsonResult = resourceRegistryClient.getType(typeName, true);
ObjectMapper objectMapper = new ObjectMapper();
//resourceRegistryClient returns an array of one element
ResourceTypeImpl rt = objectMapper.readValue(jsonResult, ResourceTypeImpl[].class)[0];
String name = rt.getName();
String id = rt.getID().toString();
String desc = rt.getDescription();
boolean abst = rt.isAbstract();
ResourceTypeDTO dto = new ResourceTypeDTO(name, id, desc, abst);
List<LinkedEntity> fcts = rt.getFacets();
if(fcts!=null) {
ArrayList<FacetTypeDTO> facetTypes = new ArrayList<FacetTypeDTO>();
for(LinkedEntity le: fcts) {
FacetTypeDTO ftDto = new FacetTypeDTO(le.getRelation(),le.getTarget(),le.getDescription(),le.getMin(),le.getMax());
facetTypes.add(new FacetTypeDTO(le.getRelation(),le.getTarget(),le.getDescription(),le.getMin(),le.getMax()));
}
dto.setFacetTypes(facetTypes);
ResourceTypeDTO dto = null;
try {
List<Type> types = TypeMapper.deserializeTypeDefinitions(jsonResult);
for(Type type : types) {
ResourceType resType = (ResourceType) type;
String name = resType.getName();
String id = resType.getID().toString();
String desc = resType.getDescription();
boolean abst = resType.isAbstract();
dto = new ResourceTypeDTO(name, id, desc, abst);
List<LinkedEntity> fcts = resType.getFacets();
if(fcts!=null) {
ArrayList<FacetTypeDTO> facetTypes = new ArrayList<FacetTypeDTO>();
for(LinkedEntity le: fcts) {
FacetTypeDTO ftDto = new FacetTypeDTO(le.getRelation(),le.getTarget(),le.getDescription(),le.getMin(),le.getMax());
facetTypes.add(new FacetTypeDTO(le.getRelation(),le.getTarget(),le.getDescription(),le.getMin(),le.getMax()));
}
dto.setFacetTypes(facetTypes);
}
}
}catch(Exception e) {
log.error("**********");
log.error(e.getMessage(),e);
log.error("**********");
}
return dto;
}
@ -316,7 +336,6 @@ public class InformationSystemService {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
ModelKnowledge <Type, TypeInformation> modelKnowledge = resourceRegistryClient.getModelKnowledge();
//Type resourcesType = modelKnowledge.getTypeByName(AccessType.RESOURCE.getName());
Type resourcesType = modelKnowledge.getTypeByName(resourceTypeName);
Tree<Type> typeTree = modelKnowledge.getTree(resourcesType.getAccessType());
SimpleTreeMaker treeMaker = new SimpleTreeMaker();
@ -406,17 +425,6 @@ public class InformationSystemService {
ArrayList<JSONArray> extraProps = new ArrayList<JSONArray>();
JSONArray props = new JSONArray();
String sendingJson="";
/*
ResourceDescription(type=EService, consistsOf=[FacetDescription(type=IsIdentifiedBy,
target={optional=true, name=Maria Teresa Paratore, group=gr, description=, version=v56, qualifier=}),
FacetDescription(type=ConsistsOf, target={optional=true, name=name, group=ggg, description=, version=v4,
qualifier=}), FacetDescription(type=ConsistsOf, target={protocol=proto, endpoint=endpoint,
entryName=EntryNameMio, description=dddd, authorization={type=ValueSchema, schema=mariateresa, value=mtPwd}}),
FacetDescription(type=ConsistsOf, target={event=on, date=2024-05-21}),
FacetDescription(type=ConsistsOf, target={value=v7}),
FacetDescription(type=ConsistsOf, target={textURL=myUrl, name=myName})],
isRelatedTo=[])
*/
try {
facetNames = JsonPath.parse(formData).read("$..facetName");
facetRelations = JsonPath.parse(formData).read("$..relationFacet");
@ -424,16 +432,29 @@ public class InformationSystemService {
props = JsonPath.parse(formData).read("$..props");
ResourceDescription rd = new ResourceDescription();
rd = buildSendingJson(resourceType,facetNames,facetRelations,extraProps,props);
ObjectMapper om = new ObjectMapper();
// Getting object as a json string
sendingJson = om.writeValueAsString(rd);
// Displaying JSON String on console
// create object mapper instance
ObjectMapper mapper = new ObjectMapper();
// convert object to `JsonNode`
JsonNode node = mapper.valueToTree(rd);
// System.out.println(node.toPrettyString());
log.debug("******** JSON STRING TO BE SENT:");
log.debug(sendingJson);
log.debug("********");
//ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
//sendingJson = ow.writeValueAsString(rd);
/*
try {
// create object mapper instance
ObjectMapper mapper = new ObjectMapper();
// convert object to `JsonNode`
JsonNode node = mapper.valueToTree(rd);
System.out.println(node.toPrettyString());
}catch(Exception e) {
e.printStackTrace();
}
*/
}catch(Exception e) {
log.error(e.getMessage(),e);
}
@ -461,14 +482,6 @@ public class InformationSystemService {
//modifica per tipo ValueSchema e campo authorization
if (facetName_i.equals("AccessPointFacet")&& propMap_i.keySet().contains("schema")&& propMap_i.keySet().contains("value")) {
TypeProperty vs = new TypeProperty();
/*LinkedHashMap authTypeMap = new LinkedHashMap<String, Object>();
authTypeMap.put("type", "ValueSchema");
authTypeMap.put("schema", (String)targetMap_i.get("schema"));
authTypeMap.put("value", (String)targetMap_i.get("value"));
targetMap_i.put("authorization", authTypeMap);
targetMap_i.remove("schema");
targetMap_i.remove("value");
*/
vs.setType("ValueSchema");
vs.setSchema((String)targetMap_i.get("schema"));
vs.setValue((String)targetMap_i.get("value"));
@ -494,7 +507,7 @@ public class InformationSystemService {
rd.setConsistsOf(new ArrayList<FacetDescription>());
}
rd.getConsistsOf().add(facet_i);
rd.setIsRelatedTo(new ArrayList<String>());
//rd.setIsRelatedTo(new ArrayList<String>());
}
return rd;

View File

@ -16,7 +16,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class FacetDescription {
String type;
Map<String,String> target;
Map<String,Object> target;
}

View File

@ -126,8 +126,7 @@ public class InformationSystemResource{
//DOES NOT WORK TO RETRIEVE FACETS
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
public ResponseEntity<String> resourceType(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
try {
try {
ResourceTypeDTO dto = informationSystemService.getResourceType(typeName);
ObjectMapper objectMapper = new ObjectMapper();
String sc = objectMapper.writeValueAsString(dto);
@ -142,6 +141,7 @@ public class InformationSystemResource{
}
// ritorna l'elenco delle facet e come costruirle
@GetMapping("/facetspecifications")
public ResponseEntity<String> resourceTypeComplete(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
@ -157,6 +157,7 @@ public class InformationSystemResource{
fs.setMax(ft.getMax());
fs.setMin(ft.getMin());
fs.setRelation(ft.getRelation());
fs.setName(ft.getTarget());
fs.setRelationOptions(informationSystemService.getFacetRelationsOptions(ft.getRelation()));
facetSpecs.add(fs);
}

View File

@ -1,61 +1,74 @@
package org.gcube.informationsystem.web.rest;
import java.io.Reader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.Paths;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
public class ProveVarie2 {
/*
* {
---"type" : "ConsistsOf",
"target" : {
"authorization":{
"schema" : "myname",
"value" : "mypassword",
"type" : "ValueSchema"
},
"protocol" : "proto",
"endpoint" : "eeeeeee",
"entryName" : "een",
"description" : "dede",
"type" : "AccessPointFacet"
}*/
public static void main(String[] args) {
ResourceDescription rd = new ResourceDescription();
rd.setType("EService");
//
ArrayList<FacetDescription> arrFd = new ArrayList<FacetDescription>();
FacetDescription fd1 = new FacetDescription();
fd1.setType("ConsistsOf");
Map<String,Object> targetMap = new HashMap<String,Object>();
targetMap.put("protocol","proto");
targetMap.put("endpoint","https://pippo.topolino.eeeeeee");
targetMap.put("entryName","een");
targetMap.put("description","dede");
targetMap.put("type","AccessPointFacet");
TypeProperty tp = new TypeProperty();
tp.setType("ValueSchema");
tp.setSchema("myschema");
tp.setValue("myvalue");
targetMap.put("authorization", tp);
fd1.setTarget(targetMap);
arrFd.add(fd1);
rd.setConsistsOf(arrFd);
try {
// create Gson instance
Gson gson = new Gson();
// create a reader
Reader reader = Files.newBufferedReader(java.nio.file.Paths.get("./test.json"));
// convert JSON file to map
Map<?, ?> map = gson.fromJson(reader, Map.class);
// print map entries
for (Map.Entry<?, ?> entry : map.entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
// close reader
reader.close();
} catch (Exception ex) {
ex.printStackTrace();
// create object mapper instance
ObjectMapper mapper = new ObjectMapper();
// convert user object to `JsonNode`
JsonNode node = mapper.valueToTree(rd);
System.out.println(node.toPrettyString());
}catch(Exception e) {
e.printStackTrace();
}
//rd.setIsRelatedTo(new ArrayList<ExtraPropertyString>());
}
static void createUno(String jsnStr) {
/*
Gson gson = new GsonBuilder()
//.registerTypeAdapter(null, jsnStr)
.enableComplexMapKeySerialization()
.serializeNulls()
.setDateFormat(DateFormat.LONG)
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.setPrettyPrinting()
.setVersion(1.0)
.create();
*/
}
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import org.gcube.informationsystem.service.dto.Serialization.ExtraProperty;
import com.fasterxml.jackson.annotation.JsonAnySetter;
//Risorsa da inviare per la creazione
@ -17,7 +19,7 @@ import lombok.NoArgsConstructor;
public class ResourceDescription {
String type;
ArrayList<FacetDescription> consistsOf;
ArrayList<String> isRelatedTo;
//ArrayList<String> isRelatedTo;
}

View File

@ -0,0 +1,53 @@
{
"type" : "EService",
"consistsOf" : [ {
"type" : "IsIdentifiedBy",
"target" : {
"name" : "nnnnn",
"optional" : "true",
"group" : "gggrgrgrgr",
"description" : "",
"version" : "vsvsvs",
"qualifier" : "",
"type" : "SoftwareFacet"
}
}, {
"type" : "ConsistsOf",
"target" : {
"name" : "nnnn",
"optional" : "true",
"group" : "ggggg",
"description" : "",
"version" : "vvvvv",
"qualifier" : "",
"type" : "SoftwareFacet"
}
}, {
"type" : "ConsistsOf",
"target" : {
"authorization":{
"schema" : "myname",
"value" : "mypassword",
"type" : "ValueSchema"
},
"protocol" : "proto",
"endpoint" : "eeeeeee",
"entryName" : "een",
"description" : "dede",
"type" : "AccessPointFacet"
}
}, {
"type" : "HasAddAction",
"target" : {
"event" : "eve",
"date" : "2024-05-31",
"type" : "EventFacet"
}
}, {
"type" : "ConsistsOf",
"target" : {
"value" : "vsvs",
"type" : "StateFacet"
}
} ]
}

View File

@ -1,30 +0,0 @@
{
"SoftwareFacet_IsIdentifiedBy": [
{
"facetName": "SoftwareFacet",
"max": "many",
"min": "1",
"facetDescription": "SoftwareFacet captures information on any software associated with the resource.",
"relationFacet": "IsIdentifiedBy",
"isAdded": false,
"extraProps": [
{
"prop_deno": "custom 1",
"prop_val": "value 1",
"prop_tipo": "String"
},
{
"prop_deno": "custom 2",
"prop_val": "value 2",
"prop_tipo": "String"
}
],
"prop_optional": true,
"prop_name": "npome",
"prop_group": "gruppo",
"prop_description": "",
"prop_version": "versione",
"prop_qualifier": ""
}
]
}

View File

@ -81,15 +81,17 @@ export class HomeComponent implements OnInit, OnDestroy {
let resTypeName:string;
//alert("fetching types--id:"+this.resType.id);
if(this.resType.id === undefined){ //if object is empty
resTypeName = 'HostingNode';
}else{
resTypeName = this.resType.name;
}
this.resTypeService.fetchOne(resTypeName).subscribe(res => {
this.resType = res;
}) ;
this.resType = res;
},
err=>(console.log('******* HTTP Error *******',err)),
() => console.log('******* HTTP request completed *******')
) ;
//for the contexts form
this.ctxLoaderService.fetchAll().subscribe(res => {

View File

@ -19,7 +19,6 @@ export class RestypesService {
//TODO: pipe per gestione errori
fetchAll(): Observable<IResource[]> {
//return this.http.get<IResource[]>(appProperties.BASEURL_API+'is/resourcetypes');
const resourceUrl = this.applicationConfigService.getEndpointFor('api/is/resourcetypes');
return this.http.get<IResource[]>(resourceUrl);
}