adding code to manage 'extra' facets

This commit is contained in:
Maria Teresa Paratore 2024-06-25 16:57:22 +02:00
parent edf27b2271
commit 4760074ea8
5 changed files with 122 additions and 48 deletions

View File

@ -121,7 +121,7 @@ public class InformationSystemService {
FacetSpecDTO fsdto = new FacetSpecDTO(); FacetSpecDTO fsdto = new FacetSpecDTO();
ArrayList<FacetPropGui> propsGui = new ArrayList<FacetPropGui>(); ArrayList<FacetPropGui> propsGui = new ArrayList<FacetPropGui>();
FacetType ft = (FacetType) type; FacetType ft = (FacetType) type;
fsdto.setName(ft.getTypeName()); fsdto.setName(ft.getName());
fsdto.setDescription(ft.getDescription()); fsdto.setDescription(ft.getDescription());
if(ft.getProperties()!=null ) { if(ft.getProperties()!=null ) {
for(PropertyDefinition pd:ft.getProperties() ) { for(PropertyDefinition pd:ft.getProperties() ) {
@ -146,6 +146,7 @@ public class InformationSystemService {
fsdto.setGuiProps(propsGui); fsdto.setGuiProps(propsGui);
return fsdto; return fsdto;
} }
public FacetSpecDTO getFacetSpecification(String facetName) throws Exception { public FacetSpecDTO getFacetSpecification(String facetName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext(); String currentCtx = SecretManagerProvider.instance.get().getContext();
@ -213,7 +214,10 @@ public class InformationSystemService {
case "Integer": tmp="number"; case "Integer": tmp="number";
break; break;
//TODO: per ora uso "typeprop" come tipo speciale (ad es. per le authorization) //TODO: per ora uso "typeprop" come tipo speciale (ad es. per le authorization)
case "Property": tmp="typeprop";
//case "Property": tmp="typeprop";
case "PropertyType": tmp="typeprop";
log.debug("what?..."+typeForClient);
break; break;
default: try { default: try {
tmp = client.getType(typeForClient, false); tmp = client.getType(typeForClient, false);

View File

@ -161,8 +161,11 @@ public class InformationSystemResource{
try { try {
informationSystemService.setUma(createUmaToken(currentContext)); informationSystemService.setUma(createUmaToken(currentContext));
List<Type> facets = informationSystemService.getFacetTypes(); List<Type> facets = informationSystemService.getFacetTypes();
facets.remove(0); //tolgo la facet madre
for(Type facet : facets) { for(Type facet : facets) {
FacetSpecDTO facetSpec = informationSystemService.getFacetStructure(facet); FacetSpecDTO facetSpec = informationSystemService.getFacetStructure(facet);
facetSpec.setRelation("ConsistsOf");
facetSpec.setRelationOptions(informationSystemService.getFacetRelationsOptions("ConsistsOf"));
facetSpecs.add(facetSpec); facetSpecs.add(facetSpec);
} }
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();

View File

@ -105,10 +105,10 @@
<input matInput formControlName="val" type="text"/> <input matInput formControlName="val" type="text"/>
<mat-error>{{checkForErrorsIn(facetTemplate.key,ind,i,'number')}}</mat-error> <mat-error>{{checkForErrorsIn(facetTemplate.key,ind,i,'number')}}</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="x.get('tipo')?.value === 'complexType'"> <mat-form-field *ngIf="x.get('tipo')?.value === 'propertyType'">
<mat-label for="val">value</mat-label> <mat-label for="val">value</mat-label>
<textarea matInput style="width: 400px" formControlName="val"></textarea> <textarea matInput style="width: 400px" formControlName="val"></textarea>
<mat-error>{{checkForErrorsIn(facetTemplate.key,ind,i,'complexType')}}</mat-error> <mat-error>{{checkForErrorsIn(facetTemplate.key,ind,i,'propertyType')}}</mat-error>
</mat-form-field > </mat-form-field >
<mat-form-field *ngIf="x.get('tipo')?.value === 'boolean'"> <mat-form-field *ngIf="x.get('tipo')?.value === 'boolean'">
<mat-label for="val">value</mat-label> <mat-label for="val">value</mat-label>
@ -160,12 +160,25 @@
(click)="removeFacet(facetTemplate.key,ind)" matTooltip="remove {{facetTemplate.key}}" matTooltipClass="tableTooltip" (click)="removeFacet(facetTemplate.key,ind)" matTooltip="remove {{facetTemplate.key}}" matTooltipClass="tableTooltip"
matTooltipPosition="above"><mat-icon>delete_outline</mat-icon></button> matTooltipPosition="above"><mat-icon>delete_outline</mat-icon></button>
</div> </div>
</div> </div>
<button mat-flat-button color="primary"
(click)="addFacet(facetTemplate.key)" [disabled]="facetTemplate.value.max==='1'"> </div>
<mat-icon>add</mat-icon>Add new </button>
</div> <!--per facet extra-->
</div> <!-- ends the form --> <div [formGroup]="pippo">
<span>extra facets container</span>
</div>
<!--per facet extra/fine -->
<span>Add new facet</span>
<mat-label for="facetSelector" >Choose</mat-label>
<mat-select >
<mat-option id="facetSelector" *ngFor="let opt of allFacetsMap|keyvalue" [value]="opt.key" (onSelectionChange)="addGFacet(opt.key)">
{{opt.key}}
</mat-option>
</mat-select>
</div><!-- ends the form -->
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions align="end">
<button mat-button type="submit" (click)="onSubmit()">Submit</button> <button mat-button type="submit" (click)="onSubmit()">Submit</button>

View File

@ -42,11 +42,13 @@ export class FacetComposerComponent implements OnInit {
selectedCredentialType: string|any; selectedCredentialType: string|any;
myForm: FormGroup; //form complessiva myForm: FormGroup; //form complessiva
pippo: FormGroup; //form con facet extra
typeSpec: ITypeSpecification; typeSpec: ITypeSpecification;
fieldsMap: Map<string, IFacetComposer>; fieldsMap: Map<string, IFacetComposer>;
showPassword:boolean; showPassword:boolean;
datePipe:DatePipe; datePipe:DatePipe;
allFacetsMap: Map<string,IFacetComposer>;
// eslint-disable-next-line @typescript-eslint/member-ordering // eslint-disable-next-line @typescript-eslint/member-ordering
constructor(private guiService: FacetComposerService, private fb: FormBuilder, constructor(private guiService: FacetComposerService, private fb: FormBuilder,
@ -58,7 +60,9 @@ export class FacetComposerComponent implements OnInit {
this.selectedType = ''; this.selectedType = '';
this.typeSpec = {} as ITypeSpecification; this.typeSpec = {} as ITypeSpecification;
this.fieldsMap = new Map<string,IFacetComposer>(); this.fieldsMap = new Map<string,IFacetComposer>();
this.allFacetsMap = new Map<string,IFacetComposer>();
this.myForm = this.fb.group({}); this.myForm = this.fb.group({});
this.pippo = this.fb.group({});
this.showPassword = false; this.showPassword = false;
this.datePipe = new DatePipe('en-US'); this.datePipe = new DatePipe('en-US');
} }
@ -66,20 +70,25 @@ export class FacetComposerComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.guiService.getFormStructure(this.titlePath,this.titleType).subscribe(res => { this.guiService.getFormStructure(this.titlePath,this.titleType).subscribe(res => {
this.typeSpec = res; this.typeSpec = res;
this.fieldsMap = new Map(res.facetSpecs.map((obj) => [obj.name+'_'+obj.relation, obj])); this.fieldsMap = new Map(res.facetSpecs.map((obj) => [obj.name+'_'+obj.relation, obj]));
//parto con una facet per tipo
this.createForm(res);
});
this.guiService.getAllFacets(this.titlePath).subscribe(
res2 => {
const allFacets = new Map(res2.map((item:IFacetComposer)=>[item.name,item]));
this.createForm(res,allFacets);
this.allFacetsMap = allFacets;
}
);
});
} }
optionTypes = [ optionTypes = [
{ value: 'boolean'}, { value: 'boolean'},
{ value: 'complexType'}, { value: 'propertyType'},
{ value: 'date'},//text { value: 'date'},//text
{ value: 'datetime'},//text { value: 'datetime'},//text
{ value: 'password'}, { value: 'password'},
@ -88,37 +97,47 @@ export class FacetComposerComponent implements OnInit {
{ value: 'text'} { value: 'text'}
]; ];
/* <TextField
variant="standard"
style={{width:"50%"}}
//type='datetime'
type='datetime'
InputLabelProps={{
shrink: true
}}
defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().indexOf("T")|0) + 6|0)}
/>
*/
credentialTypes: string[] = ['username/password', 'clientId/secret', 'token/secret']; credentialTypes: string[] = ['username/password', 'clientId/secret', 'token/secret'];
//TODO: NOTA BENE--> FormGroup->access by NAME, FormArray->access by INDEX!!
createForm(fData:ITypeSpecification, gfacetsMap:Map<string,IFacetComposer>):void{
//TODO: NOTA BENE--> FormGroup->access by NAME, FormArray->access by INDEX!!
createForm(fData:ITypeSpecification):void{
for(let i=0; i<fData.facetSpecs.length; i++){ for(let i=0; i<fData.facetSpecs.length; i++){
const facetSpec = fData.facetSpecs[i]; const facetSpec = fData.facetSpecs[i];
this.createFacetArrayEntry(facetSpec); this.createFacetArrayEntry(facetSpec);
} }
/*
console.debug('---------/gfacetsMap--------');
console.debug(gfacetsMap);
console.debug('---------gfacetsMap/--------');
*/
gfacetsMap.forEach((obj,deno)=>{
this.createGenericFacetArrayEntry(obj)
}
);
} }
createFacetArrayEntry(item: IFacetComposer):void{ createFacetArrayEntry(item: IFacetComposer):void{
const nameplus:string = item.name+'_'+item.relation; const nameplus:string = item.name+'_'+item.relation;
const singleFacetArray: FormArray = this.fb.array([]); const singleFacetArray: FormArray = this.fb.array([]);
singleFacetArray.push(this.createFacetGroup(item,false)); singleFacetArray.push(this.createFacetGroup(item,false,false));
this.myForm.addControl(nameplus,singleFacetArray); this.myForm.addControl(nameplus,singleFacetArray);
} }
createGenericFacetArrayEntry(item: IFacetComposer):void{
const genericFacetArray: FormArray = this.fb.array([]);
//TODO: QUI NON CREA CORRETTAMENTE
genericFacetArray.push(this.createFacetGroup(item,false,true));
this.myForm.addControl(item.name,genericFacetArray);
/*
console.debug('---------/CONTROLS (generic)--------');
console.debug(this.myForm.controls);
console.debug('---------CONTROLS (generic)/--------');
*/
}
get extraProps():FormArray { get extraProps():FormArray {
return this.fb.array([ return this.fb.array([
this.extraProp this.extraProp
@ -146,9 +165,20 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
}) })
} }
get selectfacets():FormControl{
return this.fb.control({
})
}
getGPropsGroup(denoFacet:string, index:number):FormGroup{
return (this.getGenericFacetArray(denoFacet).controls[index]).get('gprops') as FormGroup;
}
getGExtraPropsArray(denoFacet:string, index:number):FormArray{
return (this.getGenericFacetArray(denoFacet).controls[index]).get('gextraProps') as FormArray;
}
getPropsGroup(denoFacet:string, index:number):FormGroup{ getPropsGroup(denoFacet:string, index:number):FormGroup{
return (this.getSingleFacetArray(denoFacet).controls[index]).get('props') as FormGroup; return (this.getSingleFacetArray(denoFacet).controls[index]).get('props') as FormGroup;
} }
@ -175,7 +205,7 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
// eslint-disable-next-line no-useless-escape // eslint-disable-next-line no-useless-escape
valFc.setValidators([Validators.required,Validators.pattern('^\s*(true|false)\s*$')]); valFc.setValidators([Validators.required,Validators.pattern('^\s*(true|false)\s*$')]);
} }
if(newValue==='complexType'){ if(newValue==='propertyType'){
valFc.setValue('{}'); valFc.setValue('{}');
// eslint-disable-next-line no-useless-escape // eslint-disable-next-line no-useless-escape
valFc.setValidators([Validators.required, this.validateJsonString()]); valFc.setValidators([Validators.required, this.validateJsonString()]);
@ -206,13 +236,15 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
addFacet(deno:string): void { addFacet(deno:string): void {
const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(deno); const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(deno);
const singleFacetArray = this.myForm.controls[deno] as FormArray; const singleFacetArray = this.myForm.controls[deno] as FormArray;
singleFacetArray.push(this.createFacetGroup(icf,true)); singleFacetArray.push(this.createFacetGroup(icf,true,false));
} }
addFacet2(deno:string): void {
const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(deno); addGFacet(deno:string): void {
const icf: IFacetComposer = <IFacetComposer>this.allFacetsMap.get(deno);
const singleFacetArray = this.myForm.controls[deno] as FormArray; const singleFacetArray = this.myForm.controls[deno] as FormArray;
singleFacetArray.push(this.createFacetGroup(icf,true)); singleFacetArray.push(this.createFacetGroup(icf,true,true));
} }
@ -253,7 +285,7 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
return errorMsg; return errorMsg;
} }
}else if(!this.checkIfEmpty(valFc.value)&& inputType==='complexType'){ }else if(!this.checkIfEmpty(valFc.value)&& inputType==='propertyType'){
if(!this.isJsonString(valFc.value)){ if(!this.isJsonString(valFc.value)){
errorMsg = 'Please insert a valid JSON string'; errorMsg = 'Please insert a valid JSON string';
return errorMsg; return errorMsg;
@ -262,7 +294,6 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
{ {
if(valFc.hasError('pattern')){ if(valFc.hasError('pattern')){
if(!this.checkIfEmpty(valFc.value)&& inputType==='number'){ if(!this.checkIfEmpty(valFc.value)&& inputType==='number'){
console.debug('++++++++ NAN - IS NUMBER +++++++');
errorMsg = valFc.value +' is not an integer'; errorMsg = valFc.value +' is not an integer';
return errorMsg; return errorMsg;
} }
@ -292,7 +323,6 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
// set parse error if it fails // set parse error if it fails
isOk = false; isOk = false;
} }
console.debug('>>>>>>>>JSON OK?.........'+isOk);
return isOk; return isOk;
} }
@ -318,7 +348,6 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
let errorMsg: string; let errorMsg: string;
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
errorMsg=''; errorMsg='';
console.debug('************');
const valFc = this.getPropsGroup(denoFacet,indexFct).get(prop.name)!; const valFc = this.getPropsGroup(denoFacet,indexFct).get(prop.name)!;
/* /*
if(prop.validations.length>1){ if(prop.validations.length>1){
@ -348,7 +377,15 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
createFacetGroup(item: IFacetComposer,isAdded: boolean):FormGroup{ createFacetGroup(item: IFacetComposer,isAdded: boolean,isGeneral:boolean):FormGroup{
//OK: da qui ci passa 22 volte
//console.debug('------->>>> In createFacetGroup - isGeneral? '+isGeneral);
if(isGeneral){
console.debug('-------/ In createFacetGroup - isGeneral - guiProps');
console.debug(item.guiProps);
console.debug('------- In createFacetGroup -----/');
}
const facetFg: FormGroup = this.fb.group({}); const facetFg: FormGroup = this.fb.group({});
const nameFc = this.fb.control(item.name); const nameFc = this.fb.control(item.name);
@ -365,7 +402,6 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
const relationFc = this.fb.control(item.relation); const relationFc = this.fb.control(item.relation);
facetFg.addControl('relationFacet', relationFc); facetFg.addControl('relationFacet', relationFc);
//this.itemRelations = item.relationOptions;
const addedFc = this.fb.control(isAdded); const addedFc = this.fb.control(isAdded);
facetFg.addControl('isAdded', addedFc); facetFg.addControl('isAdded', addedFc);
@ -374,7 +410,7 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
//1. creo group con le properties //1. creo group con le properties
//2. aggiungo formgroup delle properties ai controls per la facet //2. aggiungo formgroup delle properties ai controls per la facet
return this.addPropertyControls(facetFg,item.guiProps); return this.addPropertyControls(facetFg,item.guiProps,isGeneral);
} }
@ -389,7 +425,7 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
} }
addPropertyControls(facetFg:FormGroup, props: IFacetProps[]):FormGroup{ addPropertyControls(facetFg:FormGroup, props: IFacetProps[], isGeneral:boolean):FormGroup{
const propsFg = this.fb.group({}); const propsFg = this.fb.group({});
let fc:FormControl; let fc:FormControl;
@ -427,13 +463,23 @@ defaultValue={new Date().toISOString().substring(0, (new Date().toISOString().in
propsFg.addControl(prop.name,fc); //formGroup.addControl(prop_'controlName', formControl); propsFg.addControl(prop.name,fc); //formGroup.addControl(prop_'controlName', formControl);
} }
} }
facetFg.addControl('props',propsFg); if(!isGeneral){
facetFg.addControl('props',propsFg);
}else{
facetFg.addControl('gprops',propsFg);
}
return facetFg; return facetFg;
} }
getSingleFacetArray(nameplus:string): FormArray { getSingleFacetArray(nameplus:string): FormArray {
return this.myForm.controls[nameplus] as FormArray; return this.myForm.controls[nameplus] as FormArray;
} }
getGenericFacetArray(facetName:string): FormArray {
return this.myForm.controls[facetName] as FormArray;
}
onSubmit() { onSubmit() {

View File

@ -45,6 +45,14 @@ export class FacetComposerService {
return this.http.get<string>(serviceUrl,{params:queryParams}); return this.http.get<string>(serviceUrl,{params:queryParams});
} }
getAllFacets(ctxPath:string): Observable<IFacetComposer[]> {
const serviceUrl = this.applicationConfigService.getEndpointFor('api/is/allfacets');
let queryParams = new HttpParams();
queryParams = queryParams.append("currentContext",ctxPath);
return this.http.get<IFacetComposer[]>(serviceUrl,{params:queryParams});
}
createResource(type:string, body:string): Observable<string> { createResource(type:string, body:string): Observable<string> {
const headers = new HttpHeaders() const headers = new HttpHeaders()