Work in Progress: adding REST to retrieve all facet types

This commit is contained in:
Maria Teresa Paratore 2024-06-21 17:37:46 +02:00
parent d10e8ef3b5
commit edf27b2271
3 changed files with 85 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
@ -109,6 +110,42 @@ public class InformationSystemService {
public FacetSpecDTO getFacetStructure(Type facetType) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
String jsonResult = resourceRegistryClient.getType(facetType.getName(), true);
Type type = TypeMapper.deserializeTypeDefinitions(jsonResult).get(0); //only one result
FacetSpecDTO fsdto = new FacetSpecDTO();
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;
}
public FacetSpecDTO getFacetSpecification(String facetName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
@ -346,10 +383,28 @@ public class InformationSystemService {
public List<Type> getResourceTypes() throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
log.debug("getResourceTypes : [currentCtx=]",currentCtx);
//log.debug("getResourceTypes : [currentCtx=]",currentCtx);
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
List<Type> types = resourceRegistryClient.getType(Resource.class, true);
log.debug("getResourceTypes:",types);
//log.debug("getResourceTypes:",types);
return types;
}
public List<Type> getFacetTypes() throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
//log.debug("getFacetTypes : [currentCtx=]",currentCtx);
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
List<Type> types = resourceRegistryClient.getType(Facet.class, true);
/*
for(Type tp:types) {
Type ciccio = tp;
String aa = ciccio.getName();
String bb = ciccio.getAccessType().getName();
}
*/
//log.debug("getFacetTypes:",types);
return types;
}

View File

@ -12,6 +12,7 @@ import java.util.UUID;
import javax.annotation.Nullable;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.ObjectWriter;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
@ -153,7 +154,28 @@ public class InformationSystemResource{
}
}
//TODO: come prendo il nome della facet (per tutte name="FacetType"--> vedi: allfacets.json)
@GetMapping("/allfacets")
public ResponseEntity<String> getAllFacets(@RequestParam @Nullable String currentContext) {
ArrayList<FacetSpecDTO> facetSpecs = new ArrayList<FacetSpecDTO>();
try {
informationSystemService.setUma(createUmaToken(currentContext));
List<Type> facets = informationSystemService.getFacetTypes();
for(Type facet : facets) {
FacetSpecDTO facetSpec = informationSystemService.getFacetStructure(facet);
facetSpecs.add(facetSpec);
}
ObjectMapper objectMapper = new ObjectMapper();
String sc = objectMapper.writeValueAsString(facetSpecs);
return ResponseEntity.ok().body(sc);
} catch (Exception e) {
log.error("****ERROR*************");
log.error(e.getMessage(), e);
return ResponseEntity.noContent()
.headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build();
}
}
// ritorna l'elenco delle facet e come costruirle
@GetMapping("/facetspecifications")

View File

@ -209,6 +209,12 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
singleFacetArray.push(this.createFacetGroup(icf,true));
}
addFacet2(deno:string): void {
const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(deno);
const singleFacetArray = this.myForm.controls[deno] as FormArray;
singleFacetArray.push(this.createFacetGroup(icf,true));
}
private validateDatetime():ValidatorFn {
// alert('prova!');