Getting resources

master
Luca Frosini 3 years ago
parent 7e58e23727
commit e58d3c34a7

@ -11,6 +11,14 @@
"port": 9225,
"webRoot": "${workspaceFolder}",
"url": "http://localhost:4200/#"
},
{
"name": "Launch Chrome localhost",
"type": "chrome",
"request": "launch",
"port": 9227,
"webRoot": "${workspaceFolder}",
"url": "http://localhost:4200/"
}
]
}

@ -10,10 +10,6 @@
<div id="content" class="content" role="main">
<app-resource-types-tree></app-resource-types-tree>
<div id="list-and-details">
<app-resource-list></app-resource-list>
<app-resource-details></app-resource-details>
</div>
<app-basket></app-basket>
</div>

@ -1,3 +1,4 @@
export class ISManageable {
'@class': string;
'@superClasses'?: Array<string>;
}

@ -5,7 +5,7 @@ import { Facet } from './Facet';
export class Resource extends Entity {
consistsOf: Array<ConsistsOf<Resource, Facet>>;
isRelatedTo: Array<IsRelatedTo<Resource, Resource>>;
consistsOf?: Array<ConsistsOf<Resource, Facet>>;
isRelatedTo?: Array<IsRelatedTo<Resource, Resource>>;
}

@ -1,42 +1,45 @@
import { Property } from './Property';
export enum RemoveConstraint {
type RemoveConstraint = 'cascadeWhenOrphan' | 'cascade' | 'keep';
export const RemoveConstraint = {
/*
* When the source Entity is removed also the target
* Entity is removed but if and only if the latter has no other
* incoming Relation.
*/
cascadeWhenOrphan,
cascadeWhenOrphan: 'cascadeWhenOrphan' as RemoveConstraint,
/*
* When the source Entity is removed also the target
* Entity is removed.
*/
cascade,
* Entity is removed. */
cascade: 'cascade' as RemoveConstraint,
/*
* When the source Entity is removed the target Entity
* is keep.
*/
keep
keep: 'keep' as RemoveConstraint
}
};
export enum AddConstraint {
type AddConstraint = 'propagate' | 'unpropagate';
export const AddConstraint = {
propagate,
propagate: 'propagate' as AddConstraint,
unpropagate
unpropagate: 'unpropagate' as AddConstraint
}
};
export class PropagationConstraint extends Property {
remove: RemoveConstraint;
add: AddConstraint;
constructor(remove: RemoveConstraint, add: AddConstraint){
constructor(remove: RemoveConstraint, add: AddConstraint) {
super();
this.remove = remove;
this.add = add;

@ -17,11 +17,11 @@ export class IsService {
private baseURL = 'http://pc-frosini.isti.cnr.it:8080/resource-registry';
private typesURL = this.baseURL + '/types';
private instancesURL = this.baseURL + '/instances';
private queryURL = this.baseURL + '/query';
// private queryURL = this.baseURL + '/query';
/* NextNext Token */
private token = '';
private token = '7c66c94c-7f6e-49cd-9a34-909cd3832f3e-98187548';
/**
* Handle Http operation that failed.
@ -39,8 +39,8 @@ export class IsService {
};
}
public getResourceTypes(callback: (isTypes: TypeDefinition[]) => void): void {
const url = this.typesURL + '/Resource?polymorphic=true&gcube-token=' + this.token;
public getTypeDefinition(typeName: string, polymorphic: boolean = true, callback: (isTypes: TypeDefinition[]) => void): void {
const url = this.typesURL + '/' + typeName + '?polymorphic=' + polymorphic + '&gcube-token=' + this.token;
// const observable: Observable<ISType[]> = of(types);
const observable: Observable<TypeDefinition[]> = this.httpClient.get<TypeDefinition[]>(url);
observable.pipe(
@ -49,7 +49,7 @@ export class IsService {
}
public getResourceInstances(resourceType: string, callback: (instances: Resource[]) => void): void {
const url = this.queryURL + resourceType + '?polymorphic=true&gcube-token=' + this.token;
const url = this.instancesURL + '/' + resourceType + '?polymorphic=true&gcube-token=' + this.token;
// const observable: Observable<ISType[]> = of(types);
const observable: Observable<any[]> = this.httpClient.get<any[]>(url);
observable.pipe(

@ -0,0 +1,59 @@
import { TypeDefinition } from '../is-model/types/TypeDefinition';
export const CLASS_PROPERTY_KEY = '@class';
export const SUPERCLASSES_PROPERTY_KEY = '@superClasses';
export const HEADER_PROPERTY_KEY = 'header';
export class FacetDefinition {
public typeName: string;
public mandatoryProperties: Set<string>;
public typeDefinition: TypeDefinition;
// private first = true;
constructor(typeName: string, typeDefinition: TypeDefinition) {
this.typeName = typeName;
this.typeDefinition = typeDefinition;
this.analyseType();
}
public analyseType() {
this.mandatoryProperties = new Set<string>();
for (const p of this.typeDefinition.properties) {
switch (p.name) {
case (CLASS_PROPERTY_KEY || SUPERCLASSES_PROPERTY_KEY || HEADER_PROPERTY_KEY) : {
continue;
}
default: {
if (p.mandatory) {
this.mandatoryProperties.add(p.name);
}
}
}
}
/*
if (this.first) {
const facet = resource.consistsOf[0].target;
for (const propertyKey in facet) {
if (propertyKey.localeCompare(CLASS_PROPERTY_KEY) === 0) {
continue;
}
if (propertyKey.localeCompare(SUPERCLASSES_PROPERTY_KEY) === 0) {
continue;
}
if (propertyKey.localeCompare(HEADER_PROPERTY_KEY) === 0) {
continue;
}
this.mandatoryProperties.add(propertyKey);
}
this.first = false;
}
*/
}
}

@ -2,7 +2,7 @@
<table class="table table-striped table-bordered" *ngFor="let key of resources.keys()">
<thead>
<tr>
<th [attr.colspan]="resources.get(key).mandatoryProperties.size+2" class="header">Resources identified by {{resources.get(key).type}}</th>
<th [attr.colspan]="resources.get(key).mandatoryProperties.size+2" class="header">{{ resourceType }}s identified by {{resources.get(key).type}}</th>
</tr>
<tr>
<th>Resource Type</th>

@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { IsService } from '../is.service';
import { ResourceIdentification, TYPE_PROPERTY_KEY } from './resourceidentification';
import { FacetDefinition, CLASS_PROPERTY_KEY } from './resourceidentification';
import { Resource } from '../is-model/reference/entities/Resource';
import { TypeDefinition } from '../is-model/types/TypeDefinition';
@Component({
selector: 'app-resource-list',
@ -10,30 +11,52 @@ import { Resource } from '../is-model/reference/entities/Resource';
})
export class ResourceListComponent implements OnInit {
public resources: Map<string, ResourceIdentification>;
constructor(private isService: IsService) { }
set resourceType(resourceType: string) {
// tslint:disable-next-line: no-console
console.debug('Going to retrieve ' + resourceType + ' instances');
this._resourceType = resourceType;
this.isService.getResourceInstances(this._resourceType, res => { this.resources = this.analyseResources(res); });
}
get resourceType(): string {
return this._resourceType;
}
public static facetTypes: Map<string, TypeDefinition> = new Map<string, TypeDefinition>();
// <FacetType, Array<Resource>>
public resources: Map<string, Array<Resource>>;
// tslint:disable-next-line: variable-name
private _resourceType: string;
ngOnInit() {
this.isService.getResourceInstances('Service', res => { this.resources = this.analyseResources(res); });
this.resourceType = 'Service';
}
analyseResources(resources: Resource[]): Map<string, ResourceIdentification> {
analyseResources(resources: Resource[]): Map<string, Array<Resource>> {
const map = new Map<string, ResourceIdentification>();
const map = new Map<string, Array<Resource>>();
for (const resource of resources) {
const facetType: string = resource.consistsOf[0].target[TYPE_PROPERTY_KEY];
let resourceIdentification: ResourceIdentification;
const facetType: string = resource.consistsOf[0].target[CLASS_PROPERTY_KEY];
let res: Array<Resource>;
if (map.has(facetType)) {
resourceIdentification = map.get(facetType);
if (!ResourceListComponent.facetTypes.has(facetType)) {
let typeDefinition: TypeDefinition;
this.isService.getTypeDefinition(facetType, false, types => { typeDefinition = types[0]; } );
ResourceListComponent.facetTypes.set(facetType, typeDefinition);
}
res = map.get(facetType);
} else {
resourceIdentification = new ResourceIdentification(facetType);
map.set(facetType, resourceIdentification);
res = new Array<Resource>();
map.set(facetType, res);
}
resourceIdentification.addResource(resource);
res.push(resource);
}
return map;

@ -1,36 +0,0 @@
import { Resource } from '../is-model/reference/entities/Resource';
export const TYPE_PROPERTY_KEY = '@class';
export const HEADER_PROPERTY_KEY = 'header';
export class ResourceIdentification {
public type: string;
public mandatoryProperties: Set<string>;
public resources: Array<Resource>;
private first = true;
constructor(type: string) {
this.type = type;
this.mandatoryProperties = new Set<string>();
this.resources = new Array<Resource>();
}
public addResource(resource: Resource) {
if (this.first) {
const facet = resource.consistsOf[0].target;
for (const propertyKey in facet) {
if (propertyKey.localeCompare(TYPE_PROPERTY_KEY) === 0) {
continue;
}
if (propertyKey.localeCompare(HEADER_PROPERTY_KEY) === 0) {
continue;
}
this.mandatoryProperties.add(propertyKey);
}
this.first = false;
}
this.resources.push(resource);
}
}

@ -1,11 +1,15 @@
<ul id="resource-tree" class="list-group">
<ng-template #recursiveList let-resources>
<li *ngFor="let type of resources" class="list-group-item">
<a class="nav-link" href="#" [title]="type.description" (click)="loadResources(type.name)">{{ type.name }}</a>
<a class="nav-link" href="#" [title]="type.description" (click)="list.resourceType = type.name">{{ type.name }}</a>
<ul *ngIf="type.children.length > 0">
<ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: type.children }"></ng-container>
</ul>
</li>
</ng-template>
<ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: resources }"></ng-container>
</ul>
</ul>
<div id="list-and-details">
<app-resource-list #list></app-resource-list>
<app-resource-details></app-resource-details>
</div>

@ -17,7 +17,7 @@ export class ResourceTypesTreeComponent implements OnInit {
}
ngOnInit() {
this.isService.getResourceTypes(isTypes => { this.resources = this.analyseTypes(isTypes); });
this.isService.getTypeDefinition('Resource', true, isTypes => { this.resources = this.analyseTypes(isTypes); });
}
analyseUnassociated(type: Type, map: Map<string, Type>, unassociated: Map<string, TypeDefinition>) {
@ -67,10 +67,6 @@ export class ResourceTypesTreeComponent implements OnInit {
return map.get('Resource').children;
}
loadResources(typeName: string) {
window.alert('Loading ' + typeName + ' resources');
}
}

@ -0,0 +1,85 @@
import { Resource } from './is-model/reference/entities/Resource';
export const resources: Array<Resource> = [
{
'@class': 'HostingNode',
header: {
'@class': 'Header',
uuid: 'f0460614-9ffb-4ecd-bf52-d91e8d81d604',
creator: 'luca.frosini',
modifiedBy: 'luca.frosini',
creationTime: '2109-06-29 12:00:00.000 CEST',
lastUpdateTime: '2109-06-29 12:00:00.000 CEST'
},
consistsOf: [
{
'@class': 'IsIdentifiedBy',
header: {
'@class': 'Header',
uuid: '84d5756a-693e-4b4d-99dd-a150cf843c3e',
creator: 'luca.frosini',
modifiedBy: 'luca.frosini',
creationTime: '2109-06-29 12:00:00.000 CEST',
lastUpdateTime: '2109-06-29 12:00:00.000 CEST'
},
target: {
'@class': 'NetworkingFacet',
header: {
'@class': 'Header',
uuid: 'aff4173c-ef7d-4f4f-9195-6b33d852e033',
creator: 'luca.frosini',
modifiedBy: 'luca.frosini',
creationTime: '2109-06-29 12:00:00.000 CEST',
lastUpdateTime: '2109-06-29 12:00:00.000 CEST'
},
hostName: 'pc-frosini.isti.cnr.it',
domainName: 'isti.cnr.it',
mask: null,
broadcastAddress: null,
ipaddress: '127.0.1.1',
Port: 8080
}
}
],
isRelatedTo: []
},
{
'@class': 'EService',
header: {
'@class': 'Header',
uuid: '23b6145f-b5f0-42d1-9630-17590d9831d6',
creator: 'luca.frosini',
modifiedBy: 'luca.frosini',
creationTime: '2109-06-29 12:00:00.000 CEST',
lastUpdateTime: '2109-06-29 12:00:00.000 CEST'
},
consistsOf: [
{
'@class': 'IsIdentifiedBy',
header: {
'@class': 'Header',
uuid: '7fcff150-4007-4ad0-8618-a8f3ba83a366',
creator: 'luca.frosini',
modifiedBy: 'luca.frosini',
creationTime: '2109-06-29 12:00:00.000 CEST',
lastUpdateTime: '2109-06-29 12:00:00.000 CEST'
},
target: {
'@class': 'SoftwareFacet',
header: {
'@class': 'Header',
uuid: '4e664568-1669-4b38-a3db-acf1de789c96',
creator: 'luca.frosini',
modifiedBy: 'luca.frosini',
creationTime: '2109-06-29 12:00:00.000 CEST',
lastUpdateTime: '2109-06-29 12:00:00.000 CEST'
},
group: 'vre-management',
name: 'whn-manager',
version: '1.3.0'
}
}
],
isRelatedTo: []
}
];

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save