From 9bed3c6ea4839dfd77bd0c41e905c5ad582cd8b5 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Fri, 5 Apr 2024 17:21:35 +0200 Subject: [PATCH] work in progress... --- .../service/InformationSystemService.java | 11 +- .../web/rest/InformationSystemResource.java | 28 +- .../facet-composer.component.html | 39 ++- .../facet-composer.component.ts | 246 +++++++++++++++--- .../facet-editor/facet-editor.component.ts | 65 ++++- 5 files changed, 305 insertions(+), 84 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java b/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java index 7aa1544..99d1652 100644 --- a/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java +++ b/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java @@ -27,6 +27,8 @@ import org.gcube.informationsystem.service.dto.FacetSpecDTO; import org.gcube.informationsystem.service.dto.FacetTypeDTO; import org.gcube.informationsystem.service.dto.ResourceTypeDTO; import org.gcube.informationsystem.tree.Tree; +import org.gcube.informationsystem.types.PropertyTypeName; +import org.gcube.informationsystem.types.PropertyTypeName.BaseType; import org.gcube.informationsystem.types.impl.entities.FacetTypeImpl; import org.gcube.informationsystem.types.impl.entities.ResourceTypeImpl; import org.gcube.informationsystem.types.knowledge.TypeInformation; @@ -168,7 +170,10 @@ public class InformationSystemService { return dto; } + + public String[] getFacetRelationsOptions(String parentRelation) throws Exception { + JSONArray res = new JSONArray(); String tmp = this.getResourceTypeJson(parentRelation); try { @@ -328,17 +333,17 @@ public class InformationSystemService { //CRUD - 1 - public void createResourceInstance(String resourceType) throws Exception { + public void createResourceInstance(String resourceType,String jsonDescription) throws Exception { String currentCtx = SecretManagerProvider.instance.get().getContext(); ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(currentCtx); - String jsonDescription=""; + //String jsonDescription=""; publisher.createResource(jsonDescription); //publisher.createResource(new Resource) } //CRUD - 2 - public void updateResourceInstance(String resourceType) throws Exception { + public void updateResourceInstance(String resourceType, String uuid) throws Exception { String currentCtx = SecretManagerProvider.instance.get().getContext(); //TODO: uso la getResource (riga 206)? PerĂ² restituisce una String (JSON)... //publisher.update(resourceTypeString, jsonString); 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 9c72db3..d98b823 100644 --- a/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java +++ b/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java @@ -238,16 +238,28 @@ 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)); + //CRUD - 1 + @PostMapping("/createresource") + String createResource(@RequestParam String rawJson) throws Exception { +// String currentCtx = SecretManagerProvider.instance.get().getContext(); + ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); + String uid = publisher.createResource(rawJson); + return uid; //TODO: GESTIRE ERRORI! + + } + //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(); + //TODO: dove setto UMA Token?? (altrimenti error 500) + UUIDUtility uuidUtil = new UUIDUtility(); + return publisher.deleteResource(resourceType, uuidUtil.fromString(uuid)); + //TODO: GESTIRE ERRORI! + } + } diff --git a/src/main/webapp/app/facet-composer/facet-composer.component.html b/src/main/webapp/app/facet-composer/facet-composer.component.html index 8cb0648..89fef5c 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.html +++ b/src/main/webapp/app/facet-composer/facet-composer.component.html @@ -46,7 +46,7 @@
{{prop.label}} -
@@ -55,17 +55,17 @@ Custom Properties
- name - + name + - value - + value + - type - - + type + + {{tp.value}} @@ -90,23 +90,22 @@ (click)="removeFacet(facetTemplate.key,ind)" matTooltip="remove {{facetTemplate.key}}" matTooltipClass="tableTooltip" matTooltipPosition="above">delete_outline
- + addAdd new - Form's Value: -{{ myForm.value | json }} -
-Form is Valid ? : -{{ myForm.valid }} + Form's Value: + {{ myForm.value | json }} +
+ Form is Valid ? : + {{ myForm.valid }} - - - - - + + + + + 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 5f08376..b211221 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.ts +++ b/src/main/webapp/app/facet-composer/facet-composer.component.ts @@ -17,8 +17,6 @@ import { IFacetComposer, IFacetProps } from './i-facet-composer'; import { SharedModule } from 'app/shared/shared.module'; import { MatSelectFilterModule } from 'mat-select-filter'; - - @Component({ standalone: true, selector: 'jhi-facet-composer', @@ -39,6 +37,7 @@ export class FacetComposerComponent implements OnInit { myForm: FormGroup; //form complessiva typeSpec: ITypeSpecification; fieldsMap: Map; + // eslint-disable-next-line @typescript-eslint/member-ordering @@ -64,14 +63,36 @@ export class FacetComposerComponent implements OnInit { } + /* + //TODO: A REGIME LA TENDINA DOVRA' NESSERE RIEMPITA SECONDO QUESTO CRITERIO + //(LATO JAVA, VIA CHIAMATA A SERVIZIO) + if( PropertyTypeName.BaseType.BOOLEAN.ordinal() + BaseType.PROPERTY.ordinal()) { + // Tipi Base + } + + PropertyTypeName ptn = new PropertyTypeName("ValueSchema"); + ptn.getBaseType(); + if(ptn.isGenericType()){ + ptn.getGenericBaseType(); + ptn.getGenericClassName(); + } + */ + optionTypes = [ - { value: 'boolean'}, - { value: 'number'}, - { value: 'text'} + { value: 'Boolean'}, + { value: 'Integer'}, + { value: 'Short'}, + { value: 'Long'}, + { value: 'Float'}, + { value: 'Double'}, + { value: 'Date'}, + { value: 'String'}, + { value: 'Binary'}, + { value: 'Byte'} ]; + - - onOptionsSelected(value:string): void { this.selectedOption = value; //console.debug('******onOptionsSelected?...'+value); @@ -101,9 +122,9 @@ export class FacetComposerComponent implements OnInit { get extraProp():FormGroup{ return this.fb.group({ - deno: ['',Validators.required], - value: ['',Validators.required], - tipo:['text'] + prop_deno: ['',Validators.required], + prop_val: ['',Validators.required], + prop_tipo:['String'] }) } @@ -120,31 +141,10 @@ export class FacetComposerComponent implements OnInit { } - /* - removeExtraProp(facetDeno:string, index:number) { - const singleFacetArray = this.myForm.controls[facetDeno] as FormArray; - (singleFacetArray.get("extraProps") as FormArray).removeAt(index); - // this.typeSpec.facetSpecs.splice(index,1); - } - */ - - /* - addExtraProp(facetDeno:string) { - console.debug('----------------'); - const bla = (this.getSingleFacetArray('CPUFacet_ConsistsOf').controls[0]).get('extraProps') as FormArray; - console.debug(bla.controls[0].get('tipo')?.value); - console.debug('----------------'); - } -*/ - - - addFacet(deno:string): void { const icf: IFacetComposer = this.fieldsMap.get(deno); const singleFacetArray = this.myForm.controls[deno] as FormArray; singleFacetArray.push(this.createFacetGroup(icf,true)); - //singleFacetArray.push(this.createExtraPropGroup()); - } @@ -205,13 +205,8 @@ export class FacetComposerComponent implements OnInit { } } } - facetFg.addControl(prop.name,fc); //formGroup.addControl('controlName', formControl); + facetFg.addControl("prop_"+prop.name,fc); //formGroup.addControl(prop_'controlName', formControl); } - /* - console.debug("------------------"); - console.debug(facetFg); - console.debug("------------------"); -*/ return facetFg; } @@ -219,14 +214,24 @@ export class FacetComposerComponent implements OnInit { return this.myForm.controls[nameplus] as FormArray; } - + /* onSubmit() { if (this.myForm.valid) { const formData = this.myForm.value; - // console.log("***** FORMDATA *****"); - //console.log(formData); - //TODO Process formData + console.log("***** FORMDATA *****"); + console.log(formData); + //TODO Process formData + }else{ + alert('please fix errors in form values!') } + } + */ + + onSubmit() { + const formData = this.testData; + console.log("***** FORMDATA *****"); + console.log(this.testData); + //TODO Process formData } resetForm() { @@ -245,6 +250,165 @@ export class FacetComposerComponent implements OnInit { this.dialogRef.close({event:'cancel'}); } //chiude e basta + + //////////////////////////////////////////////////////////////////////////////////////////////////////// + + + testData:any= { + "NetworkingFacet_IsIdentifiedBy": [ + { + "facetName": "NetworkingFacet", + "max": "1", + "min": "1", + "facetDescription": "NetworkingFacet captures information on any (computer) network interface associated with the resource.It is mainly used to describe the network interface of a host. It should not be confused with the {@link AccessPointFacet} which instead describes the protocol and the endpoint of a web-based service.", + "relationFacet": "IsIdentifiedBy", + "isAdded": false, + "extraProps": [], + "prop_broadcastAddress": "broadcastAddress_1", + "prop_IPAddress": "12.66.86", + "prop_hostName": "host name 1", + "prop_domainName": "domain name 1", + "prop_mask": "mask 1" + } + ], + "CPUFacet_ConsistsOf": [ + { + "facetName": "CPUFacet", + "max": "many", + "min": "1", + "facetDescription": "CPUFacet captures information on the Central Processing Unit (CPU) of the resource it is associated with. A resource which needs to indicate a multi-processor/multi-core CPU will consist of more than one CPUFacet. Even if more than one CPUFacet is associated with a resource (i.e., an {@link HostingNode}), we did not find any reason to differentiate the CPUs.", + "relationFacet": "ConsistsOf", + "isAdded": false, + "extraProps": [ + { + "prop_deno": "extra1", + "prop_val": "value1", + "prop_tipo": "String" + }, + { + "prop_deno": "extra2", + "prop_val": "value2", + "prop_tipo": "String" + } + ], + "prop_model": "aaaaaaa", + "prop_vendor": "bbbbb", + "prop_clockSpeed": "45" + }, + { + "facetName": "CPUFacet", + "max": "many", + "min": "1", + "facetDescription": "CPUFacet captures information on the Central Processing Unit (CPU) of the resource it is associated with. A resource which needs to indicate a multi-processor/multi-core CPU will consist of more than one CPUFacet. Even if more than one CPUFacet is associated with a resource (i.e., an {@link HostingNode}), we did not find any reason to differentiate the CPUs.", + "relationFacet": "HasRemoveAction", + "isAdded": true, + "extraProps": [ + { + "prop_deno": "extra deno 1", + "prop_val": "extra value 1", + "prop_tipo": "String" + } + ], + "prop_model": "ccccc", + "prop_vendor": "dddd", + "prop_clockSpeed": "124" + } + ], + "MemoryFacet_HasPersistentMemory": [ + { + "facetName": "MemoryFacet", + "max": "many", + "min": "1", + "facetDescription": "MemoryFacet captures information on computer memory equipping the resource and its usage. Any resource describing a computing machine must have at least two types of memories i.e., persistent and volatile. For such a reason, it has been identified the ConsistsOf relation called {@link HasMemory}. It is in charge of the specialisation {@link HasVolatileMemory} and {@link HasPersistentMemory} to clarify the semantics of the memory.", + "relationFacet": "HasPersistentMemory", + "isAdded": false, + "extraProps": [], + "prop_used": "2355", + "prop_unit": "MB", + "prop_size": "2466" + } + ], + "MemoryFacet_HasVolatileMemory": [ + { + "facetName": "MemoryFacet", + "max": "many", + "min": "1", + "facetDescription": "MemoryFacet captures information on computer memory equipping the resource and its usage. Any resource describing a computing machine must have at least two types of memories i.e., persistent and volatile. For such a reason, it has been identified the ConsistsOf relation called {@link HasMemory}. It is in charge of the specialisation {@link HasVolatileMemory} and {@link HasPersistentMemory} to clarify the semantics of the memory.", + "relationFacet": "HasVolatileMemory", + "isAdded": false, + "extraProps": [], + "prop_used": "222", + "prop_unit": "MB", + "prop_size": "1000" + } + ], + "EventFacet_ConsistsOf": [ + { + "facetName": "EventFacet", + "max": "many", + "min": "1", + "facetDescription": "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. Examples of an event are the start time of a virtual machine or the activation time of an electronic service.", + "relationFacet": "ConsistsOf", + "isAdded": false, + "extraProps": [], + "prop_event": "ddddd", + "prop_date": "2024-04-24" + } + ], + "StateFacet_ConsistsOf": [ + { + "facetName": "StateFacet", + "max": "1", + "min": "1", + "facetDescription": "StateFacet captures information on state to be associated with the resource. The state is captured by any controlled vocabulary which is an integral part of the facet. Examples of usage are the state of service e.g., running or down or the state of a virtual machine e.g., activated or unreachable.", + "relationFacet": "ConsistsOf", + "isAdded": false, + "extraProps": [ + { + "prop_deno": "custom A", + "prop_val": "valuecustom A", + "prop_tipo": "String" + }, + { + "prop_deno": "custom B", + "prop_val": "valuecustom B", + "prop_tipo": "String" + } + ], + "prop_value": "On" + } + ], + "SimplePropertyFacet_ConsistsOf": [ + { + "facetName": "SimplePropertyFacet", + "max": "many", + "min": "0", + "facetDescription": "Collect name-value property", + "relationFacet": "ConsistsOf", + "isAdded": false, + "extraProps": [], + "prop_value": "mmmmmm", + "prop_name": "ttttt" + } + ], + "SoftwareFacet_ConsistsOf": [ + { + "facetName": "SoftwareFacet", + "max": "many", + "min": "0", + "facetDescription": "SoftwareFacet captures information on any software associated with the resource.", + "relationFacet": "ConsistsOf", + "isAdded": false, + "extraProps": [], + "prop_name": "zzzzzz", + "prop_optional": true, + "prop_group": "ffffffff", + "prop_description": "description", + "prop_version": "14.9", + "prop_qualifier": "qualifier" + } + ] +} } diff --git a/src/main/webapp/app/facet-editor/facet-editor.component.ts b/src/main/webapp/app/facet-editor/facet-editor.component.ts index 86fa511..1f68103 100644 --- a/src/main/webapp/app/facet-editor/facet-editor.component.ts +++ b/src/main/webapp/app/facet-editor/facet-editor.component.ts @@ -44,7 +44,21 @@ export class FacetEditorComponent implements OnInit { typeSpec: ITypeSpecification; fieldsMap: Map; rawjson: string|any; - + + optionTypes = [ + { value: 'Boolean'}, + { value: 'Integer'}, + { value: 'Short'}, + { value: 'Long'}, + { value: 'Float'}, + { value: 'Double'}, + { value: 'Date'}, + { value: 'String'}, + { value: 'Binary'}, + { value: 'Byte'} + ]; + + //TODO: PASSARE UID COME STRINGA constructor(private dataService: ResourcesImplService, private guiService: FacetComposerService, private fb: FormBuilder, private dialogRef:MatDialogRef, @@ -60,16 +74,6 @@ export class FacetEditorComponent implements OnInit { } ngOnInit(): void { - /* - if(this.resourceTypeName===''){ - paramType = 'HostingNode'; - }else{ - paramType = this.resourceTypeName; - } - this.service.getJsonDetails('',paramType,this.chosenId).subscribe(res => { - this.fetchedRawData = res; - }); - */ //TODO: al posto di '' metti titlePath (sembra dare errore) this.dataService.getJsonDetails('',this.titleType,this.uid).subscribe(res => { @@ -97,6 +101,8 @@ export class FacetEditorComponent implements OnInit { } + + createAndFillForm(rawSource:string, fData:ITypeSpecification):void{ /* console.debug("*******RAW STRING*********"); @@ -111,7 +117,7 @@ export class FacetEditorComponent implements OnInit { this.createFacetArrayEntry(facetSpec); } } - + createFacetArrayEntry(item: IFacetComposer):void{ const nameplus:string = item.name+'_'+item.relation; const singleFacetArray: FormArray = this.fb.array([]); @@ -119,7 +125,40 @@ export class FacetEditorComponent implements OnInit { this.myForm.addControl(nameplus,singleFacetArray); } + get extraProps():FormArray { + return this.fb.array([ + this.extraProp + ]) + } + get extraProp():FormGroup{ + return this.fb.group({ + deno: ['',Validators.required], + value: ['',Validators.required], + tipo:['String'] + }) + } + + getExtraPropsArray(denoFacet:string, index:number):FormArray{ + return (this.getSingleFacetArray(denoFacet).controls[index]).get('extraProps') as FormArray; + } + + addExtraProp(denoFacet:string, index:number):void{ + this.getExtraPropsArray(denoFacet, index).push(this.extraProp); + } + + removeExtraProp(denoFacet:string, indexFct:number, index:number):void{ + this.getExtraPropsArray(denoFacet, indexFct).removeAt(index); + } + + + addFacet(deno:string): void { + const icf: IFacetComposer = this.fieldsMap.get(deno); + const singleFacetArray = this.myForm.controls[deno] as FormArray; + singleFacetArray.push(this.createFacetGroup(icf,true)); + } + + createFacetGroup(item: IFacetComposer,isAdded: boolean):FormGroup{ const facetFg: FormGroup = this.fb.group({}); const nameFc = this.fb.control(item.name); @@ -147,6 +186,8 @@ export class FacetEditorComponent implements OnInit { const addedFc = this.fb.control(isAdded); facetFg.addControl('isAdded', addedFc); + facetFg.addControl('extraProps', this.extraProps); + //1. creo group con le properties //2. aggiungo formgroup delle properties ai controls per la facet // facetFg.addControl('properties',this.createPropertyControls(item.guiProps));