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();
boolean abst = rt.isAbstract();
ResourceTypeDTO dto = new ResourceTypeDTO(name, id, desc, abst);
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 {
ArrayList<ContextDTO> res = new ArrayList<ContextDTO>();
//log.debug("GetAllContext: [rootCtx=]",rootCtx);
@ -234,6 +241,8 @@ public class InformationSystemService {
}
/*
* Fetches all the resource instances for a given type
*/

View File

@ -124,19 +124,22 @@ public class InformationSystemResource {
return ResponseEntity.noContent()
.headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build();
}
/*
try {
ArrayList<ResourceTypeDTO> treeNode = informationSystemService.getResourceTypesTree();
ObjectMapper objectMapper = new ObjectMapper();
String sc = objectMapper.writeValueAsString(treeNode);
return ResponseEntity.ok().body(sc);
} catch (Exception e) {
log.error("****ERROR*************");
log.error(e.getLocalizedMessage(), e);
return ResponseEntity.noContent()
.headers(HeaderUtil.createAlert(applicationName, e.getLocalizedMessage(), "")).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 {
informationSystemService.setUma(createUmaToken(currentContext));
String raw= informationSystemService.getResourceTypeJson(typeName);
return ResponseEntity.ok().body(raw);
} catch (Exception e) {
e.printStackTrace();
log.error("****ERROR*************");
log.error(e.getMessage(), e);
return ResponseEntity.noContent()
.headers(HeaderUtil.createAlert(applicationName, e.getMessage(), "ERRORE")).build();
}
}
@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 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>
<div id="tree-view">
<jhi-rsc-tree id="leftTree" (typeObjectEm)="buildTableData($event)"></jhi-rsc-tree>
</div>
</div>
<div class="col-md-9 ">
<div class="col-md-9 border rounded">
<div [ngSwitch]="resType.name" >
<div *ngSwitchCase = "'HostingNode'">
<jhi-table-screen [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen>

View File

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

View File

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

View File

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

View File

@ -31,5 +31,12 @@ export class RestypesService {
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>
</button>
<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>
</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 { IResource } from 'app/services/i-resource';
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({
selector: 'jhi-table-screen',
templateUrl: './table-screen.component.html',
styleUrls: ['./table-screen.component.scss'],
providers: [ResourcesImplService],
providers: [ResourcesImplService, RestypesService],
})
export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
@ -45,6 +47,7 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
tableDetail: IHostingNode;
dialogAddRef: MatDialogRef<ResourceAddComponent> |undefined;
dialogInfoRef: MatDialogRef<GenericInfoComponent> |undefined;
dialogJsonRef: MatDialogRef<GenericJsonComponent> |undefined;
@Input() currentCtx: IContextNode; //fetching event from parent
@Input() currentCtxPath: string; //fetching event from parent
@ -63,10 +66,11 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
selectedIdx = 0;
chosenIds: string[] = [];
//TODO: a regime questa sarà la nuova resource creata (visualizzerò il titolo)
dummyRes: string;
rawJson: string;
dummyRes :string;
////////// 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.tableDetail = {} as IHostingNode;
this.dataFromService = [];
@ -75,6 +79,7 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
//this.resourceType = '';
this.typeObject = {} as IResourceType;
this.currentCtxPath = '';
this.rawJson = '';
this.dummyRes = '';
}
@ -100,6 +105,11 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
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}
});
}
openDialogJson(): void {
this.dialogJsonRef = this.myDialog.open(GenericJsonComponent, {
data: {fetchedRawData: this.rawJson}
});
}
/*