adding methods and resources to view raw Json for a selected

resourceType
This commit is contained in:
Maria Teresa Paratore 2024-01-17 17:13:42 +01:00
parent f08bf94434
commit 0e6e773c42
13 changed files with 99 additions and 19 deletions

View File

@ -132,10 +132,17 @@ public class InformationSystemService {
String desc = rt.getDescription(); String desc = rt.getDescription();
boolean abst = rt.isAbstract(); boolean abst = rt.isAbstract();
ResourceTypeDTO dto = new ResourceTypeDTO(name, id, desc, abst); ResourceTypeDTO dto = new ResourceTypeDTO(name, id, desc, abst);
return dto; return dto;
} }
public String getResourceTypeJson(String typeName) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx);
String jsonResult = resourceRegistryClient.getType(typeName, true);
return jsonResult;
}
public List<ContextDTO> getAllContexts() throws Exception { public List<ContextDTO> getAllContexts() throws Exception {
ArrayList<ContextDTO> res = new ArrayList<ContextDTO>(); ArrayList<ContextDTO> res = new ArrayList<ContextDTO>();
//log.debug("GetAllContext: [rootCtx=]",rootCtx); //log.debug("GetAllContext: [rootCtx=]",rootCtx);
@ -234,6 +241,8 @@ public class InformationSystemService {
} }
/* /*
* Fetches all the resource instances for a given type * Fetches all the resource instances for a given type
*/ */

View File

@ -124,19 +124,22 @@ public class InformationSystemResource {
return ResponseEntity.noContent() return ResponseEntity.noContent()
.headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build(); .headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build();
} }
/* }
@GetMapping("/resourcetypejson")
// e.g. http://localhost:8081/api/is/resourcetype?typeName=HostingNode
public ResponseEntity<String> resourceTypeJson(@RequestParam String typeName,@RequestParam @Nullable String currentContext) {
try { try {
ArrayList<ResourceTypeDTO> treeNode = informationSystemService.getResourceTypesTree(); informationSystemService.setUma(createUmaToken(currentContext));
ObjectMapper objectMapper = new ObjectMapper(); String raw= informationSystemService.getResourceTypeJson(typeName);
String sc = objectMapper.writeValueAsString(treeNode); return ResponseEntity.ok().body(raw);
return ResponseEntity.ok().body(sc);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
log.error("****ERROR*************"); log.error("****ERROR*************");
log.error(e.getLocalizedMessage(), e); log.error(e.getMessage(), e);
return ResponseEntity.noContent() return ResponseEntity.noContent()
.headers(HeaderUtil.createAlert(applicationName, e.getLocalizedMessage(), "")).build(); .headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build();
} }
*/
} }
@GetMapping("/resourcejson") @GetMapping("/resourcejson")

View File

@ -0,0 +1,3 @@
<div class="bg-light">
<pre>{{ data.fetchedRawData | json }}</pre>
</div>

View File

@ -0,0 +1,14 @@
/* eslint-disable @angular-eslint/no-empty-lifecycle-method */
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'jhi-generic-json',
templateUrl: './generic-json.component.html',
styleUrls: ['./generic-json.component.scss']
})
export class GenericJsonComponent{
constructor(@Inject(MAT_DIALOG_DATA) public data: {fetchedRawData: string}) { }
}

View File

@ -0,0 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GenericJsonComponent } from './generic-json.component';
@NgModule({
declarations: [
GenericJsonComponent
],
imports: [
CommonModule
]
})
export class GenericJsonModule { }

View File

@ -51,14 +51,14 @@
</div> </div>
<div class="d-flex flex-row"> <div class="d-flex flex-row">
<div id="restree" class="col-md-3 ps-3 pt-3 border border-1 rounded-4" > <div id="restree" class="col-md-3 ps-3 pt-3 border rounded" >
<h4>Resource Types</h4> <h4>Resource Types</h4>
<div id="tree-view"> <div id="tree-view">
<jhi-rsc-tree id="leftTree" (typeObjectEm)="buildTableData($event)"></jhi-rsc-tree> <jhi-rsc-tree id="leftTree" (typeObjectEm)="buildTableData($event)"></jhi-rsc-tree>
</div> </div>
</div> </div>
<div class="col-md-9 "> <div class="col-md-9 border rounded">
<div [ngSwitch]="resType.name" > <div [ngSwitch]="resType.name" >
<div *ngSwitchCase = "'HostingNode'"> <div *ngSwitchCase = "'HostingNode'">
<jhi-table-screen [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen> <jhi-table-screen [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen>

View File

@ -31,3 +31,5 @@ Main page styles
z-index: 99; z-index: 99;
} }

View File

@ -2,9 +2,12 @@
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle <mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle
(click)="activeNode = node" [ngClass]="{ 'background-highlight': activeNode === node }"> (click)="activeNode = node" [ngClass]="{ 'background-highlight': activeNode === node }">
<button mat-button (click)="activeNode = node; onClickNodeTree(node);"> <button mat-button (click)="activeNode = node; onClickNodeTree(node);">
<span>{{ node.name }}</span> <span>
{{ node.name }}
<sup *ngIf="node.astratto">A</sup>
</span>
</button> </button>
<sup *ngIf="node.astratto">A</sup>
</mat-tree-node> </mat-tree-node>
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasNestedChild"> <mat-nested-tree-node *matTreeNodeDef="let node; when: hasNestedChild">
@ -16,8 +19,13 @@
</button> </button>
<button mat-button [ngClass]="{ 'background-highlight': activeNode === node }" <button mat-button [ngClass]="{ 'background-highlight': activeNode === node }"
(click)="activeNode = node; onClickNodeTree(node);"> (click)="activeNode = node; onClickNodeTree(node);">
{{ node.name }} <span *ngIf="node.astratto" class="abstr">
<sup *ngIf="node.astratto">A</sup> {{ node.name }}
<sup>A</sup>
</span>
<span *ngIf="!node.astratto">
{{ node.name }}
</span>
</button> </button>
</div> </div>

View File

@ -43,4 +43,8 @@
padding-left: 25px; padding-left: 25px;
} }
.abstr{
font-style:italic;
}

View File

@ -30,6 +30,13 @@ export class RestypesService {
queryParams = queryParams.append("typeName",name); queryParams = queryParams.append("typeName",name);
return this.http.get<IResourceType>(resourceUrl,{params:queryParams}); return this.http.get<IResourceType>(resourceUrl,{params:queryParams});
} }
fetchRawJson(name:string): Observable<string> {
const resourceUrl = this.applicationConfigService.getEndpointFor('api/is/resourcetypejson');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",name);
return this.http.get<string>(resourceUrl,{params:queryParams});
}
} }

View File

@ -6,7 +6,7 @@
<mat-icon class="icon-infodescr" (click)="openDialogDescription()">info</mat-icon> <mat-icon class="icon-infodescr" (click)="openDialogDescription()">info</mat-icon>
</button> </button>
<button mat-button color="primary" matTooltip="view raw JSON" matTooltipPosition="right"> <button mat-button color="primary" matTooltip="view raw JSON" matTooltipPosition="right">
<mat-icon class="icon-infodescr" (click)="openDialogDescription()">visibility</mat-icon> <mat-icon class="icon-infodescr" (click)="openDialogJson()">visibility</mat-icon>
</button> </button>
</div> </div>

View File

@ -28,13 +28,15 @@ import { ResourceAddComponent } from 'app/resource-add/resource-add.component';
import { GenericInfoComponent } from 'app/generic-info/generic-info.component'; import { GenericInfoComponent } from 'app/generic-info/generic-info.component';
import { IResource } from 'app/services/i-resource'; import { IResource } from 'app/services/i-resource';
import { IResourceType } from 'app/services/i-resource-type'; import { IResourceType } from 'app/services/i-resource-type';
import { GenericJsonComponent } from 'app/generic-json/generic-json.component';
import { RestypesService } from 'app/services/restypes.service';
@Component({ @Component({
selector: 'jhi-table-screen', selector: 'jhi-table-screen',
templateUrl: './table-screen.component.html', templateUrl: './table-screen.component.html',
styleUrls: ['./table-screen.component.scss'], styleUrls: ['./table-screen.component.scss'],
providers: [ResourcesImplService], providers: [ResourcesImplService, RestypesService],
}) })
export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges { export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
@ -45,6 +47,7 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
tableDetail: IHostingNode; tableDetail: IHostingNode;
dialogAddRef: MatDialogRef<ResourceAddComponent> |undefined; dialogAddRef: MatDialogRef<ResourceAddComponent> |undefined;
dialogInfoRef: MatDialogRef<GenericInfoComponent> |undefined; dialogInfoRef: MatDialogRef<GenericInfoComponent> |undefined;
dialogJsonRef: MatDialogRef<GenericJsonComponent> |undefined;
@Input() currentCtx: IContextNode; //fetching event from parent @Input() currentCtx: IContextNode; //fetching event from parent
@Input() currentCtxPath: string; //fetching event from parent @Input() currentCtxPath: string; //fetching event from parent
@ -63,10 +66,11 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
selectedIdx = 0; selectedIdx = 0;
chosenIds: string[] = []; chosenIds: string[] = [];
//TODO: a regime questa sarà la nuova resource creata (visualizzerò il titolo) //TODO: a regime questa sarà la nuova resource creata (visualizzerò il titolo)
dummyRes: string; rawJson: string;
dummyRes :string;
////////// fine tabbed view ////////// fine tabbed view
constructor(private myDataService: ResourcesImplService, private myDialog: MatDialog) { constructor(private myDataService: ResourcesImplService, private myTypesService: RestypesService, private myDialog: MatDialog) {
this.currentCtx = {} as IContextNode; this.currentCtx = {} as IContextNode;
this.tableDetail = {} as IHostingNode; this.tableDetail = {} as IHostingNode;
this.dataFromService = []; this.dataFromService = [];
@ -75,6 +79,7 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
//this.resourceType = ''; //this.resourceType = '';
this.typeObject = {} as IResourceType; this.typeObject = {} as IResourceType;
this.currentCtxPath = ''; this.currentCtxPath = '';
this.rawJson = '';
this.dummyRes = ''; this.dummyRes = '';
} }
@ -100,6 +105,11 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
return record.name.indexOf(filter)!==-1; return record.name.indexOf(filter)!==-1;
} }
}); });
this.myTypesService.fetchRawJson(this.typeObject.name).subscribe(res => {
this.rawJson = res;
return res;
});
} }
@ -186,6 +196,11 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
data: {description: this.typeObject.description} data: {description: this.typeObject.description}
}); });
} }
openDialogJson(): void {
this.dialogJsonRef = this.myDialog.open(GenericJsonComponent, {
data: {fetchedRawData: this.rawJson}
});
}
/* /*