Updated to include (if present) facet descriptions array

This commit is contained in:
Maria Teresa Paratore 2024-02-13 17:30:14 +01:00
parent 600ea7c55f
commit 9e994551a7
3 changed files with 104 additions and 8 deletions

View File

@ -36,6 +36,7 @@ import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPu
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.service.dto.ContextDTO;
import org.gcube.informationsystem.service.dto.FacetTypeDTO;
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
import org.gcube.informationsystem.tree.Node;
import org.gcube.informationsystem.tree.NodeElaborator;
@ -44,6 +45,8 @@ 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.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.utils.UUIDUtility;
import org.gcube.informationsystem.web.rest.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -120,6 +123,7 @@ public class InformationSystemService {
public ResourceTypeDTO getResourceType(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
log.debug("getResourceType : [currentCtx=]",currentCtx);
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
@ -127,6 +131,59 @@ public class InformationSystemService {
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>();
//TODO: RIEMPI LE FACET
for(LinkedEntity le: fcts) {
/*
log.debug("le.getRelation()..."+le.getRelation());
log.debug("le.getTarget()..."+le.getTarget());
log.debug("le.getDescription()..."+le.getDescription());
log.debug("le.getMin()..."+le.getMin());
log.debug("le.getMax()..."+le.getMax());
*/
facetTypes.add(new FacetTypeDTO(le.getRelation(),le.getTarget(),le.getDescription(),le.getMin(),le.getMax()));
}
dto.setFacetTypes(facetTypes);
}
return dto;
}
/*
public ResourceBuilderDTO getResourceType(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
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);
return dto;
}
*/
/*
public ArrayList<FacetComponentDTO> getFacetsComponents(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
//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();
@ -135,6 +192,8 @@ public class InformationSystemService {
ResourceTypeDTO dto = new ResourceTypeDTO(name, id, desc, abst);
return dto;
}
*/
public String getResourceTypeJson(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
@ -144,6 +203,14 @@ public class InformationSystemService {
}
//per i tipi di risorse come HostingNode, EService, ecc.
public String getResourceTypeSpecs(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
String jsonResult = resourceRegistryClient.getType(typeName, true);
return jsonResult;
}
public List<ContextDTO> getAllContexts() throws Exception {
ArrayList<ContextDTO> res = new ArrayList<ContextDTO>();
//log.debug("GetAllContext: [rootCtx=]",rootCtx);
@ -265,13 +332,6 @@ public class InformationSystemService {
return instancesAsObject;
}
//retrieve available facets for a given resource Type
public void getFacetsPerType(String resourceType) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
//publisher.createResource(new Resource)
}
//CRUD - 1
@ -292,6 +352,16 @@ public class InformationSystemService {
}
//CRUD - 3
public boolean deleteResourceInstance(String resourceType, String uuid) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(currentCtx);
UUIDUtility uuidUtil = new UUIDUtility();
return publisher.deleteResource(resourceType, uuidUtil.fromString(uuid));
//TODO: GESTIRE ERRORI!
}
//CRUD - 4
//TODO: vedi se questo va passato da un REST di JHipster
public void retrieveResourceInstance(String resourceType) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.service.dto;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@ -20,6 +21,7 @@ public class ResourceTypeDTO {
private String fatherId;
private String description;
private boolean astratto;
private ArrayList<FacetTypeDTO> facetTypes;
public boolean isAstratto() {
return astratto;
@ -37,6 +39,11 @@ public class ResourceTypeDTO {
this.description = description;
}
public void setFacetTypes(ArrayList<FacetTypeDTO> fTypes) {
this.facetTypes = fTypes;
}
public void setChildren(List<ResourceTypeDTO> children) {
this.children = children;
}

View File

@ -13,15 +13,19 @@ import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.informationsystem.config.TokenManager;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.service.InformationSystemService;
import org.gcube.informationsystem.service.dto.ContextDTO;
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
import org.gcube.informationsystem.utils.UUIDUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -108,6 +112,7 @@ public class InformationSystemResource {
}
@GetMapping("/resourcetype")
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
public ResponseEntity<String> resourceType(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
@ -126,6 +131,8 @@ public class InformationSystemResource {
}
}
@GetMapping("/resourcetypejson")
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
public ResponseEntity<String> resourceTypeJson(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
@ -142,6 +149,8 @@ public class InformationSystemResource {
}
}
@GetMapping("/resourcejson")
public ResponseEntity<String> resourceInstanceJson(@RequestParam @Nullable String currentContext, @RequestParam String resourceType, @RequestParam String uid) {
log.debug("Request resource json");
@ -191,6 +200,16 @@ public class InformationSystemResource {
}
//CRUD - 3
@PostMapping("/deleteresource")
boolean deleteResource(@RequestParam @Nullable String currentContext, @RequestParam String resourceType, @RequestParam String uuid)throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(currentCtx);
//TODO: dove setto UMA Token?? (altrimenti error 500)
UUIDUtility uuidUtil = new UUIDUtility();
return publisher.deleteResource(resourceType, uuidUtil.fromString(uuid));
//TODO: GESTIRE ERRORI!
}
}