From edf27b2271d19afd88927b187490656b10ea206f Mon Sep 17 00:00:00 2001 From: mariateresa Date: Fri, 21 Jun 2024 17:37:46 +0200 Subject: [PATCH] Work in Progress: adding REST to retrieve all facet types --- .../service/InformationSystemService.java | 59 ++++++++++++++++++- .../web/rest/InformationSystemResource.java | 22 +++++++ .../facet-composer.component.ts | 6 ++ 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java b/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java index 7513c56..c39ab6c 100644 --- a/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java +++ b/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java @@ -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 propsGui = new ArrayList(); + 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 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 types = resourceRegistryClient.getType(Resource.class, true); - log.debug("getResourceTypes:",types); + //log.debug("getResourceTypes:",types); + return types; + + } + + public List getFacetTypes() throws Exception { + + String currentCtx = SecretManagerProvider.instance.get().getContext(); + //log.debug("getFacetTypes : [currentCtx=]",currentCtx); + ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx); + List 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; } diff --git a/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java b/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java index 9df85d7..328899c 100644 --- a/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java +++ b/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java @@ -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 getAllFacets(@RequestParam @Nullable String currentContext) { + ArrayList facetSpecs = new ArrayList(); + try { + informationSystemService.setUma(createUmaToken(currentContext)); + List 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") diff --git a/src/main/webapp/app/facet-composer/facet-composer.component.ts b/src/main/webapp/app/facet-composer/facet-composer.component.ts index f1f0220..e62c949 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.ts +++ b/src/main/webapp/app/facet-composer/facet-composer.component.ts @@ -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 = this.fieldsMap.get(deno); + const singleFacetArray = this.myForm.controls[deno] as FormArray; + singleFacetArray.push(this.createFacetGroup(icf,true)); + } + private validateDatetime():ValidatorFn { // alert('prova!');