Created JHipster's REST services to get facet properties, also related
to resource types
This commit is contained in:
parent
9e994551a7
commit
53f861e0be
|
@ -36,16 +36,20 @@ import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPu
|
||||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
import org.gcube.informationsystem.service.dto.ContextDTO;
|
import org.gcube.informationsystem.service.dto.ContextDTO;
|
||||||
|
import org.gcube.informationsystem.service.dto.FacetPropertyDTO;
|
||||||
|
import org.gcube.informationsystem.service.dto.FacetSpecificationDTO;
|
||||||
import org.gcube.informationsystem.service.dto.FacetTypeDTO;
|
import org.gcube.informationsystem.service.dto.FacetTypeDTO;
|
||||||
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
|
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
|
||||||
import org.gcube.informationsystem.tree.Node;
|
import org.gcube.informationsystem.tree.Node;
|
||||||
import org.gcube.informationsystem.tree.NodeElaborator;
|
import org.gcube.informationsystem.tree.NodeElaborator;
|
||||||
import org.gcube.informationsystem.tree.Tree;
|
import org.gcube.informationsystem.tree.Tree;
|
||||||
|
import org.gcube.informationsystem.types.impl.entities.FacetTypeImpl;
|
||||||
import org.gcube.informationsystem.types.impl.entities.ResourceTypeImpl;
|
import org.gcube.informationsystem.types.impl.entities.ResourceTypeImpl;
|
||||||
import org.gcube.informationsystem.types.knowledge.TypeInformation;
|
import org.gcube.informationsystem.types.knowledge.TypeInformation;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||||
import org.gcube.informationsystem.utils.UUIDUtility;
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
||||||
import org.gcube.informationsystem.web.rest.Constants;
|
import org.gcube.informationsystem.web.rest.Constants;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -122,6 +126,53 @@ public class InformationSystemService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
public String getFacetSpecificationJson(String typeName) throws Exception {
|
||||||
|
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
||||||
|
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
|
||||||
|
String jsonResult = resourceRegistryClient.getType(typeName, true);
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public FacetSpecificationDTO getFacetSpecification(String facetName) throws Exception {
|
||||||
|
|
||||||
|
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<FacetPropertyDTO> properties = new ArrayList<FacetPropertyDTO>();
|
||||||
|
FacetSpecificationDTO fsdto = new FacetSpecificationDTO();
|
||||||
|
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());
|
||||||
|
properties.add(prop);
|
||||||
|
}catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fsdto.setProperties(properties);
|
||||||
|
return fsdto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ResourceTypeDTO getResourceType(String typeName) throws Exception {
|
public ResourceTypeDTO getResourceType(String typeName) throws Exception {
|
||||||
|
|
||||||
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
||||||
|
@ -156,44 +207,6 @@ public class InformationSystemService {
|
||||||
return dto;
|
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();
|
|
||||||
String desc = rt.getDescription();
|
|
||||||
boolean abst = rt.isAbstract();
|
|
||||||
ResourceTypeDTO dto = new ResourceTypeDTO(name, id, desc, abst);
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
public String getResourceTypeJson(String typeName) throws Exception {
|
public String getResourceTypeJson(String typeName) throws Exception {
|
||||||
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
||||||
|
@ -203,6 +216,8 @@ public class InformationSystemService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//per i tipi di risorse come HostingNode, EService, ecc.
|
//per i tipi di risorse come HostingNode, EService, ecc.
|
||||||
public String getResourceTypeSpecs(String typeName) throws Exception {
|
public String getResourceTypeSpecs(String typeName) throws Exception {
|
||||||
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
String currentCtx = SecretManagerProvider.instance.get().getContext();
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
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;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
//descrive una facet che concorre a comporre un oggetto
|
||||||
|
|
||||||
|
public class FacetPropertyDTO {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FacetPropertyDTO.class);
|
||||||
|
private String type;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private boolean mandatory;
|
||||||
|
private boolean readonly;
|
||||||
|
private boolean notnull;
|
||||||
|
private Integer max;
|
||||||
|
private Integer min;
|
||||||
|
private String regexp;
|
||||||
|
private String propertyType;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public boolean isMandatory() {
|
||||||
|
return mandatory;
|
||||||
|
}
|
||||||
|
public void setMandatory(boolean mandatory) {
|
||||||
|
this.mandatory = mandatory;
|
||||||
|
}
|
||||||
|
public boolean isReadonly() {
|
||||||
|
return readonly;
|
||||||
|
}
|
||||||
|
public void setReadonly(boolean readonly) {
|
||||||
|
this.readonly = readonly;
|
||||||
|
}
|
||||||
|
public boolean isNotnull() {
|
||||||
|
return notnull;
|
||||||
|
}
|
||||||
|
public void setNotnull(boolean notnull) {
|
||||||
|
this.notnull = notnull;
|
||||||
|
}
|
||||||
|
public Integer getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
public void setMax(Integer max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
public Integer getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
public void setMin(Integer min) {
|
||||||
|
this.min = min;
|
||||||
|
}
|
||||||
|
public String getRegexp() {
|
||||||
|
return regexp;
|
||||||
|
}
|
||||||
|
public void setRegexp(String regexp) {
|
||||||
|
this.regexp = regexp;
|
||||||
|
}
|
||||||
|
public String getPropertyType() {
|
||||||
|
return propertyType;
|
||||||
|
}
|
||||||
|
public void setPropertyType(String propertyType) {
|
||||||
|
this.propertyType = propertyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
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;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
//descrive una facet che concorre a comporre un oggetto
|
||||||
|
|
||||||
|
public class FacetSpecificationDTO {
|
||||||
|
|
||||||
|
//"type":"PropertyDefinition","name":"optional","description":"Used to indicate the software optionality, e.g., optional in maven coordinates","mandatory":false,"readonly":false,"notnull":false,"max":null,"min":null,"regexp":null,"propertyType":"Boolean"}
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FacetSpecificationDTO.class);
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public ArrayList<FacetPropertyDTO> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
public void setProperties(ArrayList<FacetPropertyDTO> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
private String name; //nome della facet
|
||||||
|
private String description; //descrizione della facet
|
||||||
|
private ArrayList<FacetPropertyDTO> properties;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
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;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
//descrive una facet che concorre a comporre un oggetto
|
||||||
|
|
||||||
|
public class FacetTypeDTO {
|
||||||
|
|
||||||
|
public FacetTypeDTO(String relation, String target, String description, Integer min, Integer max) {
|
||||||
|
this.relation = relation;
|
||||||
|
this.target = target;
|
||||||
|
this.description = description;
|
||||||
|
this.min = min;
|
||||||
|
if(max==null) {
|
||||||
|
//prefer to avoid null in a field (MEANS MAX>1)
|
||||||
|
max=-1;
|
||||||
|
}
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FacetTypeDTO.class);
|
||||||
|
//TODO: vedi se a regime può servire ID
|
||||||
|
private String relation;
|
||||||
|
private String target; //il nome della facet
|
||||||
|
private String description;
|
||||||
|
private Integer min;
|
||||||
|
private Integer max;
|
||||||
|
//private ArrayList<FacetPropertyDTO> properties;
|
||||||
|
|
||||||
|
/*
|
||||||
|
public ArrayList<FacetPropertyDTO> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
public void setProperties(ArrayList<FacetPropertyDTO> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getRelation() {
|
||||||
|
return relation;
|
||||||
|
}
|
||||||
|
public void setRelation(String relation) {
|
||||||
|
this.relation = relation;
|
||||||
|
}
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
public void setTarget(String target) {
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public Integer getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
public void setMin(Integer min) {
|
||||||
|
this.min = min;
|
||||||
|
}
|
||||||
|
public Integer getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
public void setMax(Integer max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,14 @@ public class ResourceTypeDTO {
|
||||||
private boolean astratto;
|
private boolean astratto;
|
||||||
private ArrayList<FacetTypeDTO> facetTypes;
|
private ArrayList<FacetTypeDTO> facetTypes;
|
||||||
|
|
||||||
|
public ArrayList<FacetTypeDTO> getFacetTypes() {
|
||||||
|
return facetTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFacetTypes(ArrayList<FacetTypeDTO> facetTypes) {
|
||||||
|
this.facetTypes = facetTypes;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAstratto() {
|
public boolean isAstratto() {
|
||||||
return astratto;
|
return astratto;
|
||||||
}
|
}
|
||||||
|
@ -39,10 +47,6 @@ public class ResourceTypeDTO {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacetTypes(ArrayList<FacetTypeDTO> fTypes) {
|
|
||||||
this.facetTypes = fTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setChildren(List<ResourceTypeDTO> children) {
|
public void setChildren(List<ResourceTypeDTO> children) {
|
||||||
this.children = children;
|
this.children = children;
|
||||||
|
@ -65,6 +69,7 @@ public class ResourceTypeDTO {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.astratto = astratto;
|
this.astratto = astratto;
|
||||||
this.children = new LinkedList<>();
|
this.children = new LinkedList<>();
|
||||||
|
this.facetTypes = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChild(ResourceTypeDTO childNode) {
|
public void addChild(ResourceTypeDTO childNode) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPu
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
import org.gcube.informationsystem.service.InformationSystemService;
|
import org.gcube.informationsystem.service.InformationSystemService;
|
||||||
import org.gcube.informationsystem.service.dto.ContextDTO;
|
import org.gcube.informationsystem.service.dto.ContextDTO;
|
||||||
|
import org.gcube.informationsystem.service.dto.FacetSpecificationDTO;
|
||||||
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
|
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
|
||||||
import org.gcube.informationsystem.utils.UUIDUtility;
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -114,6 +115,7 @@ public class InformationSystemResource {
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/resourcetype")
|
@GetMapping("/resourcetype")
|
||||||
|
//DOES NOT WORK TO RETRIEVE FACETS
|
||||||
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
|
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
|
||||||
public ResponseEntity<String> resourceType(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
|
public ResponseEntity<String> resourceType(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
|
||||||
try {
|
try {
|
||||||
|
@ -131,6 +133,25 @@ public class InformationSystemResource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/facetspecification")
|
||||||
|
//DOES NOT WORK TO RETRIEVE FACETS
|
||||||
|
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
|
||||||
|
public ResponseEntity<String> facetSpecification(@RequestParam String facetName,@RequestParam @Nullable String currentContext) {
|
||||||
|
try {
|
||||||
|
informationSystemService.setUma(createUmaToken(currentContext));
|
||||||
|
FacetSpecificationDTO dto = informationSystemService.getFacetSpecification(facetName);
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String sc = objectMapper.writeValueAsString(dto);
|
||||||
|
return ResponseEntity.ok().body(sc);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("****ERROR*************");
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return ResponseEntity.noContent()
|
||||||
|
.headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/resourcetypejson")
|
@GetMapping("/resourcetypejson")
|
||||||
|
|
Loading…
Reference in New Issue