work in progress...

This commit is contained in:
Maria Teresa Paratore 2024-04-05 17:21:35 +02:00
parent 910d7ce8bd
commit 9bed3c6ea4
5 changed files with 305 additions and 84 deletions

View File

@ -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);

View File

@ -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!
}
}

View File

@ -46,7 +46,7 @@
<div *ngFor="let prop of facetTemplate.value.guiProps">
<mat-form-field>
<mat-label>{{prop.label}}</mat-label>
<input matInput formControlName="{{prop.name}}" id="{{prop.name}}"
<input matInput formControlName="prop_{{prop.name}}" id="prop_{{prop.name}}"
type="{{prop.type}}"/>
</mat-form-field>
</div>
@ -55,17 +55,17 @@
<span [style.width.px]="350" [style.font-weight]="900">Custom Properties</span>
<div [formGroupName] ="i" *ngFor="let x of getExtraPropsArray(facetTemplate.key,ind).controls; let i=index;">
<mat-form-field>
<mat-label for="deno">name</mat-label>
<input matInput formControlName="deno" type="text"/>
<mat-label for="prop_deno">name</mat-label>
<input matInput formControlName="prop_deno" type="text"/>
</mat-form-field>
<mat-form-field>
<mat-label for="value">value</mat-label>
<input matInput formControlName="value" type="text"/>
<mat-label for="prop_val">value</mat-label>
<input matInput formControlName="prop_val" type="text"/>
</mat-form-field>
<mat-form-field>
<mat-label for="tipo" >type</mat-label>
<mat-select formControlName="tipo" id="tipo">
<mat-option *ngFor="let tp of optionTypes" [value]="tp.value">
<mat-label for="prop_tipo" >type</mat-label>
<mat-select formControlName="prop_tipo" id="tipo">
<mat-option *ngFor="let tp of optionTypes" [value]="tp.value" >
{{tp.value}}
</mat-option>
</mat-select>
@ -90,23 +90,22 @@
(click)="removeFacet(facetTemplate.key,ind)" matTooltip="remove {{facetTemplate.key}}" matTooltipClass="tableTooltip"
matTooltipPosition="above"><mat-icon>delete_outline</mat-icon></button>
</div>
</div>
<button mat-flat-button color="primary"
(click)="addFacet(facetTemplate.key)" [disabled]="facetTemplate.value.max==='1'">
<mat-icon>add</mat-icon>Add new {{facetTemplate.key}}</button>
<mat-icon>add</mat-icon>Add new </button>
</div>
</div> <!-- chiude la form -->
<b>Form's Value:</b>
{{ myForm.value | json }}
<br />
<b>Form is Valid ? :</b>
{{ myForm.valid }}
<b>Form's Value:</b>
{{ myForm.value | json }}
<br />
<b>Form is Valid ? :</b>
{{ myForm.valid }}
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button type="submit">Submit</button>
<button mat-button (click)="close()">Cancel</button>
</mat-dialog-actions>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button type="submit" (click)="onSubmit()">Submit</button>
<button mat-button (click)="close()">Cancel</button>
</mat-dialog-actions>

View File

@ -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<string, IFacetComposer>;
// 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 = <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"
}
]
}
}

View File

@ -44,7 +44,21 @@ export class FacetEditorComponent implements OnInit {
typeSpec: ITypeSpecification;
fieldsMap: Map<string, IFacetComposer>;
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<FacetEditorComponent>,
@ -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 = <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));