work in progress

This commit is contained in:
Maria Teresa Paratore 2024-04-08 17:55:14 +02:00
parent 9bed3c6ea4
commit b2c7130612
11 changed files with 291 additions and 168 deletions

View File

@ -0,0 +1,26 @@
package org.gcube.informationsystem.service.dto.angular;
class ExtraProps{
String prop_deno;
public String getProp_deno() {
return prop_deno;
}
public void setProp_deno(String prop_deno) {
this.prop_deno = prop_deno;
}
public String getProp_val() {
return prop_val;
}
public void setProp_val(String prop_val) {
this.prop_val = prop_val;
}
public String getProp_tipo() {
return prop_tipo;
}
public void setProp_tipo(String prop_tipo) {
this.prop_tipo = prop_tipo;
}
String prop_val;
String prop_tipo;
}

View File

@ -6,6 +6,7 @@ public final class Constants {
public static final String RES_TYPE_HOSTINGNODE = "HostingNode";
public static final String RES_TYPE_ESERVICE = "EService";
public static final String RES_TYPE_VSERVICE = "VirtualService";
public static final String FACET_NETWORKING = "NetworkingFacet";

View File

@ -37,12 +37,21 @@ public class DTOResourceBuilder {
private static String HN_STATUS_QUERY = "$..consistsOf[?(@.['target'])]*[?(@.['expectedtype']=='StateFacet')].['value']";
private static String HN_VOL_MEMORY_QUERY = "$..consistsOf[?(@.['expectedtype']=='HasVolatileMemory')].['target'].['size','unit']";
//EService
private static String ES_ENDPOINT_QUERY = "$..consistsOf[*]['target'][?(@.['expectedtype']=='AccessPointFacet')].['endpoint','entryName']";
private static String ES_STATUS_QUERY = "$..consistsOf[*]['target'][?(@.['expectedtype']=='StateFacet')].['value']";
private static String ES_NGV_QUERY = "$..consistsOf[*]['target'][?(@.['expectedtype']=='SoftwareFacet')].['name','group','version']";
//VirtualService
/*
* private String id;
private String lastMod;
private String name;
private String group;
private String version;
private String qualifier;
*/
//private static String ES_
public DTOResourceBuilder(String type) {
resType = type;
pathConfiguration = Configuration.builder().options(Option.DEFAULT_PATH_LEAF_TO_NULL).build();
@ -135,7 +144,15 @@ public class DTOResourceBuilder {
e.printStackTrace();
}
break;
case Constants.RES_TYPE_VSERVICE:
try {
}catch(Exception e) {
log.error("Error while building VirtualServiceDTO from json");
e.printStackTrace();
}
break;
default:
break;
}

View File

@ -2,6 +2,7 @@ package org.gcube.informationsystem.web.rest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@ -21,6 +22,8 @@ import org.gcube.informationsystem.service.dto.FacetSpecDTO;
import org.gcube.informationsystem.service.dto.FacetTypeDTO;
import org.gcube.informationsystem.service.dto.ResourceBuilderDTO;
import org.gcube.informationsystem.service.dto.ResourceTypeDTO;
import org.gcube.informationsystem.service.dto.VirtualServiceDTO;
import org.gcube.informationsystem.service.dto.angular.VirtualServiceAngular;
import org.gcube.informationsystem.utils.UUIDUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,7 +36,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriUtils;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.filter.ValueNode.JsonNode;
import lombok.RequiredArgsConstructor;
import net.minidev.json.JSONArray;
@ -240,14 +245,49 @@ public class InformationSystemResource {
//CRUD - 1
@PostMapping("/createresource")
String createResource(@RequestParam String rawJson) throws Exception {
String createResource(@RequestParam String resourceType, @RequestParam String rawJson) throws Exception {
//NB: Luca dice che non serve UmaToken e context!
//TODO: modifica rawjson in versione compliant col servizio
//TODO: aggiungere resType sul rawJson
//JsonNode jsonNode = objectMapper.readTree(json);
//String color = jsonNode.get("color").asText();
log.debug("********** RAWJSON ******");
log.debug(rawJson);
log.debug("****************");
String rawJson2="";
ObjectMapper om = new ObjectMapper();
/*
* switch(this.getPropertyType()) {
case "Boolean": tmp="boolean";
break;
case "Date": tmp="date";
break;
case "String": tmp="text";
break;
case "Long": tmp="number";
break;
case "Integer": tmp="number";
break;
}
*/
switch(resourceType) {
case "VirtualService": {
VirtualServiceAngular inputObject = om.readValue(rawJson, VirtualServiceAngular.class);
inputObject.setTypeName("VirtualService");
inputObject.getFacets(); }
break;
}
// String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
String uid = publisher.createResource(rawJson);
String uid = publisher.createResource(rawJson2);
return uid;
//TODO: GESTIRE ERRORI!
}
//CRUD - 3
@ -258,6 +298,7 @@ public class InformationSystemResource {
//TODO: dove setto UMA Token?? (altrimenti error 500)
UUIDUtility uuidUtil = new UUIDUtility();
return publisher.deleteResource(resourceType, uuidUtil.fromString(uuid));
//TODO: GESTIRE ERRORI!
}

View File

@ -42,7 +42,7 @@ export class FacetComposerComponent implements OnInit {
// eslint-disable-next-line @typescript-eslint/member-ordering
constructor(private guiService: FacetComposerService, private fb: FormBuilder,
private dialogRef:MatDialogRef<FacetComposerComponent>,
private dialogRef:MatDialogRef<FacetComposerComponent>,
@Inject(MAT_DIALOG_DATA) data: {type: IResource ,context:IContextNode}){
this.titleType = data.type.name;
this.titlePath = data.context.path;
@ -214,25 +214,65 @@ 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
}else{
alert('please fix errors in form values!')
}
}
*/
onSubmit() {
const formData = this.testData;
console.log("***** FORMDATA *****");
console.log(this.testData);
//TODO Process formData
}
this.guiService.createResource(this.titleType, formData);
}
onSubmit2() {
const formData = this.testData;
const jsonString = JSON.stringify(formData)
//console.log("***** FORMDATA *****");
//console.log(this.testData);
// const tobesaved = new Map<string,any>();
/*
const tobesaved = {
'type':'',
'consistsOf':[{
'type':'',
'target':{}
}]
};
*/
const tobesaved = {
'type':'',
'consistsOf':[{}]
};
tobesaved.type=this.titleType;
// tobesaved.consistsOf.push
//tobesaved.set("consistsOf",array di singlefacet):
const inputObj = JSON.parse(jsonString, (key, value) => {
const facetObj = new Map();
const targetObj = new Map();
console.debug('key...'+key);
console.debug('value...'+value);
if(key==="relationFacet"){
facetObj.set('type',value);
// this.guiService.createResource(this.titleType, formData);
}
//targetObj
if(key==="facetName"){
targetObj.set('type',value);
// this.guiService.createResource(this.titleType, formData);
}
//target
if(key==="facetName"){
targetObj.set('type',value);
// this.guiService.createResource(this.titleType, formData);
}
if(key.startsWith('prop_')){
targetObj.set(key.substring(5,key.length),value);
// this.guiService.createResource(this.titleType, formData);
}
facetObj.set('target',targetObj);
tobesaved.consistsOf.push(facetObj);
});
console.debug(tobesaved);
}
resetForm() {
this.myForm.reset();
@ -255,157 +295,53 @@ export class FacetComposerComponent implements OnInit {
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": [
"SoftwareFacet_IsIdentifiedBy": [
{
"facetName": "SoftwareFacet",
"max": "many",
"min": "0",
"min": "1",
"facetDescription": "SoftwareFacet captures information on any software associated with the resource.",
"relationFacet": "ConsistsOf",
"relationFacet": "IsIdentifiedBy",
"isAdded": false,
"extraProps": [],
"prop_name": "zzzzzz",
"extraProps": [
{
"prop_deno": "custom 1",
"prop_val": "value 1",
"prop_tipo": "String"
},
{
"prop_deno": "custom 2",
"prop_val": "value 2",
"prop_tipo": "String"
}
],
"prop_optional": true,
"prop_group": "ffffffff",
"prop_name": "npome",
"prop_group": "gruppo",
"prop_description": "",
"prop_version": "versione",
"prop_qualifier": ""
},
{
"facetName": "SoftwareFacet",
"max": "many",
"min": "1",
"facetDescription": "SoftwareFacet captures information on any software associated with the resource.",
"relationFacet": "IsIdentifiedBy",
"isAdded": true,
"extraProps": [
{
"prop_deno": "custom11",
"prop_val": "value11",
"prop_tipo": "String"
}
],
"prop_optional": true,
"prop_name": "name2",
"prop_group": "group2",
"prop_description": "description",
"prop_version": "14.9",
"prop_qualifier": "qualifier"
"prop_version": "version2",
"prop_qualifier": ""
}
]
}

View File

@ -39,5 +39,23 @@ export class FacetComposerService {
queryParams = queryParams.append("typeName",type).append("currentContext",ctxPath);
return this.http.get<string>(serviceUrl,{params:queryParams});
}
createResource(type:string, data:string): Observable<string> {
//alert('create?');
const serviceUrl = this.applicationConfigService.getEndpointFor('api/is/createresource');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",type).append("data",data);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
let res : Observable<string>|undefined;
try{ alert('prima')
res = this.http.post<string>(serviceUrl, {params:queryParams});
}catch(error){
alert('errore')
console.error('---------------------');
console.error(error);
return new Observable<string>();
};
return new Observable<string>();
}
}

View File

@ -67,6 +67,9 @@
<div *ngSwitchCase = "'EService'">
<jhi-table-screen-es [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen-es>
</div>
<div *ngSwitchCase = "'VirtualService'">
<jhi-table-screen-vs [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen-vs>
</div>
<div *ngSwitchDefault class="mx-4">At the moment there are no objects of this type.</div>
</div>

View File

@ -0,0 +1,69 @@
jest.mock('app/core/auth/account.service');
jest.mock('app/login/login.service');
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { of } from 'rxjs';
import { AccountService } from 'app/core/auth/account.service';
import { Account } from 'app/core/auth/account.model';
import { LoginService } from 'app/login/login.service';
import { HomeComponent } from './home.component';
describe('Home Component', () => {
let comp: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
let mockAccountService: AccountService;
let mockLoginService: LoginService;
const account: Account = {
activated: true,
authorities: [],
email: '',
firstName: null,
langKey: '',
lastName: null,
login: 'login',
imageUrl: null,
};
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [HomeComponent],
providers: [AccountService, LoginService],
})
.overrideTemplate(HomeComponent, '')
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
comp = fixture.componentInstance;
mockAccountService = TestBed.inject(AccountService);
mockAccountService.identity = jest.fn(() => of(null));
mockAccountService.getAuthenticationState = jest.fn(() => of(null));
mockLoginService = TestBed.inject(LoginService);
});
describe('ngOnInit', () => {
it('Should synchronize account variable with current account', () => {
// GIVEN
mockAccountService.identity = jest.fn(() => of(account));
// WHEN
comp.ngOnInit();
// THEN
expect(comp.account).toEqual(account);
});
});
describe('login', () => {
it('Should call loginService.login on login', () => {
// WHEN
comp.login();
// THEN
expect(mockLoginService.login).toHaveBeenCalled();
});
});
});

View File

@ -16,6 +16,7 @@ import { AsyncPipe, NgSwitchCase, NgSwitchDefault } from '@angular/common';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { TypeHeadlineModule } from 'app/type-headline/type-headline.module';
import { TableScreenModule } from 'app/table-screen/table-screen.module';
import { TableScreenVsModule } from 'app/table-screen-vs/table-screen-vs.module';
@NgModule({
@ -31,6 +32,7 @@ import { TableScreenModule } from 'app/table-screen/table-screen.module';
MatProgressBarModule,
TableScreenModule,
TableScreenEsModule,
TableScreenVsModule,
AsyncPipe,
NgSwitchCase,
NgSwitchDefault,

View File

@ -0,0 +1,5 @@
export interface IVirtualService {
id: string;
lastMod: string;
//name: string;
}

View File

@ -6,6 +6,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { IHostingNode } from './i-hosting-node';
import { IEService } from './i-e-service';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { IVirtualService } from './i-virtual-service';
@Injectable({
providedIn: 'root'
@ -38,6 +39,10 @@ export class ResourcesImplService {
if(type==='EService'){
return this.http.get<IEService[]>(resourceUrl,{params:queryParams});
}
if(type==='VirtualService'){
return this.http.get<IVirtualService[]>(resourceUrl,{params:queryParams});
}
return new Observable<any[]>();
}