adding logic and GUIs for creation and removal of other types

This commit is contained in:
Maria Teresa Paratore 2024-04-17 18:04:40 +02:00
parent 2b93619117
commit 1a27b8a43e
25 changed files with 220 additions and 248 deletions

View File

@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.filter.ValueNode.JsonNode;
import com.nimbusds.jose.shaded.json.JSONUtil;
import net.minidev.json.JSONArray;
@ -402,7 +403,10 @@ public class InformationSystemService {
public void createResourceInstance(String jsonDescription) throws Exception {
String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(currentCtx);
publisher.createResource(jsonDescription);
String res = publisher.createResource(jsonDescription);
System.out.println("*************RES*********");
System.out.println(res);
System.out.println("**********************");
}
//CRUD - 2

View File

@ -8,10 +8,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EServiceDTO {
private String id;
private String lastMod;
private String name;
public class EServiceDTO extends ResourceImplDTO{
private String artifact;
private String version;
private String group;

View File

@ -8,10 +8,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HostingNodeDTO {
private String id;
private String lastMod;
private String name;
public class HostingNodeDTO extends ResourceImplDTO{
private String status;
private String avMemory;
private String hdSpace;

View File

@ -0,0 +1,14 @@
package org.gcube.informationsystem.service.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResourceImplDTO {
private String id;
private String lastMod;
private String name;
}

View File

@ -0,0 +1,14 @@
package org.gcube.informationsystem.service.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VirtualMachineDTO extends ResourceImplDTO{
private String group;
private String version;
}

View File

@ -8,10 +8,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VirtualServiceDTO {
private String id;
private String lastMod;
private String name;
public class VirtualServiceDTO extends ResourceImplDTO{
private String group;
private String version;
}

View File

@ -1,26 +0,0 @@
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

@ -1,119 +0,0 @@
package org.gcube.informationsystem.service.dto.angular;
import java.util.ArrayList;
public class VirtualServiceAngular{
String typeName;
ArrayList<FacetDescription> facets;
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public ArrayList<FacetDescription> getFacets() {
return facets;
}
public void setFacets(ArrayList<FacetDescription> facets) {
this.facets = facets;
}
}
class FacetDescription{
//da elminare - begin
String facetName;
String max;
String min;
String facetDescription;
String relationFacet;
boolean isAdded;
boolean prop_optional;
//da elminare - end
String prop_name;
String prop_group;
String prop_description;
String prop_version;
String prop_qualifier;
ArrayList<ExtraProps> extraProps;
public String getFacetName() {
return facetName;
}
public void setFacetName(String facetName) {
this.facetName = facetName;
}
public String getMax() {
return max;
}
public void setMax(String max) {
this.max = max;
}
public String getMin() {
return min;
}
public void setMin(String min) {
this.min = min;
}
public String getFacetDescription() {
return facetDescription;
}
public void setFacetDescription(String facetDescription) {
this.facetDescription = facetDescription;
}
public String getRelationFacet() {
return relationFacet;
}
public void setRelationFacet(String relationFacet) {
this.relationFacet = relationFacet;
}
public boolean isAdded() {
return isAdded;
}
public void setAdded(boolean isAdded) {
this.isAdded = isAdded;
}
public boolean isProp_optional() {
return prop_optional;
}
public void setProp_optional(boolean prop_optional) {
this.prop_optional = prop_optional;
}
public String getProp_name() {
return prop_name;
}
public void setProp_name(String prop_name) {
this.prop_name = prop_name;
}
public String getProp_group() {
return prop_group;
}
public void setProp_group(String prop_group) {
this.prop_group = prop_group;
}
public String getProp_description() {
return prop_description;
}
public void setProp_description(String prop_description) {
this.prop_description = prop_description;
}
public String getProp_version() {
return prop_version;
}
public void setProp_version(String prop_version) {
this.prop_version = prop_version;
}
public String getProp_qualifier() {
return prop_qualifier;
}
public void setProp_qualifier(String prop_qualifier) {
this.prop_qualifier = prop_qualifier;
}
public ArrayList<ExtraProps> getExtraProps() {
return extraProps;
}
public void setExtraProps(ArrayList<ExtraProps> extraProps) {
this.extraProps = extraProps;
}
}

View File

@ -7,6 +7,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 RES_TYPE_VMACHINE = "VirtualMachine";
public static final String FACET_NETWORKING = "NetworkingFacet";

View File

@ -33,15 +33,15 @@ public class DTOResourceBuilder {
//private static String
//hostingNodes JSONPath queries
private static String HN_DOMAIN_HOST_QUERY = "$..consistsOf[?(@.expectedtype=='IsIdentifiedBy')]['target'][?(@.['expectedtype']=='NetworkingFacet')].['domainName','hostName']";
private static String HN_MEMORY_QUERY = "$..consistsOf[?(@.['type']=='ConsistsOf' && @.['expectedtype']=='HasPersistentMemory')].['target'].['expectedtype','unit','size','used']";
private static String HN_STATUS_QUERY = "$..consistsOf[?(@.['target'])]*[?(@.['expectedtype']=='StateFacet')].['value']";
private static String HN_VOL_MEMORY_QUERY = "$..consistsOf[?(@.['expectedtype']=='HasVolatileMemory')].['target'].['size','unit']";
private static String NETWORKINGFACET_QUERY_DOMAIN = "$..consistsOf[?(@.expectedtype=='IsIdentifiedBy')]['target'][?(@.['expectedtype']=='NetworkingFacet')].['domainName','hostName']";
private static String PERS_MEMORY_QUERY = "$..consistsOf[?(@.['type']=='ConsistsOf' && @.['expectedtype']=='HasPersistentMemory')].['target'].['expectedtype','unit','size','used']";
private static String STATEFACET_QUERY_STATUS = "$..consistsOf[?(@.['target'])]*[?(@.['expectedtype']=='StateFacet')].['value']";
private static String VOLATILE_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']";
private static String ACCESSPOINTFACET_QUERY_ENDPOINT = "$..consistsOf[*]['target'][?(@.['expectedtype']=='AccessPointFacet')].['endpoint','entryName']";
private static String STATEFACET_QUERY_VALUE = "$..consistsOf[*]['target'][?(@.['expectedtype']=='StateFacet')].['value']";
private static String SOFTWAREFACET_QUERY_NAME = "$..consistsOf[*]['target'][?(@.['expectedtype']=='SoftwareFacet')].['name','group','version']";
//VirtualService
/*
@ -81,15 +81,15 @@ public class DTOResourceBuilder {
((HostingNodeDTO) dto).setLastMod(lastUpd);
log.debug("2..."+lastUpd);
myLeaves = JsonPath.parse(resJson).read(HN_DOMAIN_HOST_QUERY);
myLeaves = JsonPath.parse(resJson).read(NETWORKINGFACET_QUERY_DOMAIN);
((HostingNodeDTO) dto).setName(myLeaves.get(0).get("hostName").toString());
log.debug("3..." + myLeaves.get(0).get("hostName").toString());
myLeaves = JsonPath.parse(resJson).read(HN_MEMORY_QUERY);
myLeaves = JsonPath.parse(resJson).read(PERS_MEMORY_QUERY);
((HostingNodeDTO) dto).setAvMemory(myLeaves.get(0).get("size").toString()+" "+myLeaves.get(0).get("unit").toString());
log.debug("4..."+myLeaves.get(0).get("size").toString()+" "+myLeaves.get(0).get("unit").toString());
Object status = null;
status = JsonPath.parse(resJson).read(HN_STATUS_QUERY);
status = JsonPath.parse(resJson).read(STATEFACET_QUERY_STATUS);
status = status.toString().replace("[\"", "").replace("\"]", "");
log.debug("5..."+status);
((HostingNodeDTO) dto).setStatus(status.toString());
@ -98,7 +98,7 @@ public class DTOResourceBuilder {
log.error("Error while building HostingNodeDTO from json");
e.printStackTrace();
}
myLeaves = JsonPath.parse(resJson).read(HN_VOL_MEMORY_QUERY);
myLeaves = JsonPath.parse(resJson).read(VOLATILE_MEMORY_QUERY);
((HostingNodeDTO) dto).setHdSpace(myLeaves.get(0).get("size").toString()+" "+myLeaves.get(0).get("unit").toString());
break;
@ -115,7 +115,7 @@ public class DTOResourceBuilder {
((EServiceDTO) dto).setLastMod(lastUpd);
log.debug("2..."+lastUpd);
myLeaves= JsonPath.parse(resJson).read(ES_ENDPOINT_QUERY);
myLeaves= JsonPath.parse(resJson).read(ACCESSPOINTFACET_QUERY_ENDPOINT);
String ep = myLeaves.get(0).get("endpoint").toString();
String en = myLeaves.get(0).get("entryName").toString();
@ -124,7 +124,7 @@ public class DTOResourceBuilder {
log.debug("3..."+ep);
log.debug("3..."+en);
myLeaves = JsonPath.parse(resJson).read(ES_NGV_QUERY);
myLeaves = JsonPath.parse(resJson).read(SOFTWAREFACET_QUERY_NAME);
String name = myLeaves.get(0).get("name").toString();
String group = myLeaves.get(0).get("group").toString();
String version = myLeaves.get(0).get("version").toString();
@ -134,7 +134,7 @@ public class DTOResourceBuilder {
((EServiceDTO) dto).setGroup(group);
myLeaves = JsonPath.parse(resJson).read(ES_STATUS_QUERY);
myLeaves = JsonPath.parse(resJson).read(STATEFACET_QUERY_VALUE);
String sts = myLeaves.toString().replace("[\"", "").replace("\"]", "");
log.debug("4..."+sts);
((EServiceDTO) dto).setStatus(sts);
@ -146,6 +146,33 @@ public class DTOResourceBuilder {
}
break;
case Constants.RES_TYPE_VMACHINE:
dto = new VirtualServiceDTO();
try {
String uid= JsonPath.parse(resJson).read(UID_QUERY);
((VirtualServiceDTO) dto).setId(uid);
log.debug("1..."+uid);
String lastUpd= JsonPath.parse(resJson).read(LAST_UPDATE_QUERY);
lastUpd = lastUpd.substring(0,lastUpd.length()-10);
((VirtualServiceDTO) dto).setLastMod(lastUpd);
log.debug("2..."+lastUpd);
//Software Facet Fields
myLeaves = JsonPath.parse(resJson).read(SOFTWAREFACET_QUERY_NAME);
String name = myLeaves.get(0).get("name").toString();
String group = myLeaves.get(0).get("group").toString();
String version = myLeaves.get(0).get("version").toString();
log.debug("3..."+myLeaves);
((VirtualServiceDTO) dto).setVersion(version);
((VirtualServiceDTO) dto).setName(name);
((VirtualServiceDTO) dto).setGroup(group);
}catch(Exception e) {
log.error("Error while building VirtualServiceDTO from json");
e.printStackTrace();
}
break;
case Constants.RES_TYPE_VSERVICE:
dto = new VirtualServiceDTO();
try {
@ -159,7 +186,7 @@ public class DTOResourceBuilder {
log.debug("2..."+lastUpd);
//Software Facet Fields
myLeaves = JsonPath.parse(resJson).read(ES_NGV_QUERY);
myLeaves = JsonPath.parse(resJson).read(SOFTWAREFACET_QUERY_NAME);
String name = myLeaves.get(0).get("name").toString();
String group = myLeaves.get(0).get("group").toString();
String version = myLeaves.get(0).get("version").toString();

View File

@ -1,16 +0,0 @@
package org.gcube.informationsystem.web.rest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExtraProp {
String prop_deno;
String prop_val;
String prop_tipo;
}

View File

@ -1,20 +0,0 @@
package org.gcube.informationsystem.web.rest;
import java.util.LinkedHashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnySetter;
//Risorsa da inviare per la creazione
public class FacetProperties {
String type;
Map<String, Object> facetprops = new LinkedHashMap();
@JsonAnySetter
void setDetail(String key, Object value) {
facetprops.put(key, value);
}
}

View File

@ -0,0 +1,47 @@
package org.gcube.informationsystem.web.rest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnySetter;
//Risorsa da inviare per la creazione
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
public class FormDataJson {
private Map<String, String> properties;
private Map<String, String> extraProperties;
public FormDataJson(){
properties = new HashMap<>();
extraProperties = new HashMap<>();
}
@JsonAnySetter
public void addProperty(String property, String value){
properties.put(property, value);
}
@JsonAnySetter
public void addExtraProperty(String extraProp, String value){
properties.put(extraProp, value);
}
}
/*
class Student {
private Map<String, String> properties;
public Student(){
properties = new HashMap<>();
}
public Map<String, String> getProperties(){
return properties;
}
@JsonAnySetter
public void add(String property, String value){
properties.put(property, value);
}
}*/

View File

@ -229,7 +229,7 @@ public class InformationSystemResource {
}
}catch(Exception e) {
log.error("ERROR WHILE FILLING RESOURCEIMPL DTO");
//e.printStackTrace();
e.printStackTrace();
}
try {
ObjectMapper objectMapper = new ObjectMapper();
@ -242,27 +242,37 @@ public class InformationSystemResource {
}
}
//CRUD - 1
@PostMapping("/createresource")
String createresource(@RequestParam String resourceType, @RequestBody String formData) throws Exception {
/*
* ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
UUIDUtility uuidUtil = new UUIDUtility();
return publisher.deleteResource(resourceType, uuidUtil.fromString(uuid));
*/
//CRUD - 1
@PostMapping("/createresource")
String createresource(@RequestParam String resourceType, @RequestBody String formData) throws Exception {
String currentContext = SecretManagerProvider.instance.get().getContext();
String result = "";
informationSystemService.setUma(createUmaToken(currentContext));
formData = informationSystemService.createResourceInternal(resourceType, formData);
try {
//String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
result = publisher.createResource(formData);
//result = publisher.create(formData);
}catch(Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
return result;
}
//CRUD - 2
@PostMapping("/updateresource")
String updateresource(@RequestParam String resourceType, @RequestBody String formData) throws Exception {
String currentContext = SecretManagerProvider.instance.get().getContext();
String result = "";
informationSystemService.setUma(createUmaToken(currentContext));
formData = informationSystemService.createResourceInternal(resourceType, formData);
try {
//String currentCtx = SecretManagerProvider.instance.get().getContext();
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
result = publisher.createResource(formData);
//result = publisher.create(formData);
result = publisher.updateResource(formData);
}catch(Exception e) {
log.error("****************");
e.printStackTrace();
log.error("****************");
log.error(e.getMessage());
}
return result;

View File

@ -14,7 +14,6 @@
<p> {{typeSpec.description}} </p>
</mat-expansion-panel>
<div [formGroup]="myForm">
<div formArrayName="{{facetTemplate.key}}" *ngFor="let facetTemplate of fieldsMap|keyvalue;" >
<div [formGroupName] ="ind" *ngFor="let fct of (getSingleFacetArray(facetTemplate.key)).controls; let ind=index;" style="border: 3px solid rgb(72, 157, 202); padding: 10px; margin: 5px;">
<mat-form-field appearance="outline" >

View File

@ -64,6 +64,9 @@
<div *ngSwitchCase = "'HostingNode'">
<jhi-table-screen [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen>
</div>
<div *ngSwitchCase = "'VirtualMachine'">
<jhi-table-screen [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen>
</div>
<div *ngSwitchCase = "'EService'">
<jhi-table-screen-es [typeObject]="resType" [currentCtx]="myContext"></jhi-table-screen-es>
</div>

View File

@ -0,0 +1,9 @@
export interface IVirtualMachine {
type:string;
name: string;
id: string;
status: string;
lastMod: string;
avMemory: string;
hdSpace: string;
}

View File

@ -7,6 +7,7 @@ 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';
import { IVirtualMachine } from './i-virtual-machine';
@Injectable({
providedIn: 'root'
@ -36,6 +37,10 @@ export class ResourcesImplService {
//console.debug("******GETTING HOSTING NODE*****");
return this.http.get<IHostingNode[]>(resourceUrl,{params:queryParams});
}
if(type==='VirtualMachine'){
//console.debug("******GETTING HOSTING NODE*****");
return this.http.get<IVirtualMachine[]>(resourceUrl,{params:queryParams});
}
if(type==='EService'){
return this.http.get<IEService[]>(resourceUrl,{params:queryParams});
}

View File

@ -0,0 +1,18 @@
class BaseFacet {
uid:string;
facetName: string;
facetDescription: string;
facetMin: string;
facetMax: string;
customProperties: CustomProperty[];
constructor(){
this.uid='';
this.facetName='';
this.facetMin='';
this.facetMax='';
this.facetDescription='';
this.customProperties = [];
}
}

View File

@ -0,0 +1,12 @@
class CustomProperty {
name:string;
value:string;
type:string;
constructor(){
this.name='';
this.value='';
this.type='';
}
}

View File

@ -0,0 +1,22 @@
class SoftwareFacet extends BaseFacet{
name: string;
description: string;
relation: string;
optional: boolean;
group: string;
qualifier:string;
version:string;
constructor(){
super();
this.relation='';
this.name='';
this.group='';
this.description='';
this.qualifier='';
this.version='';
this.optional=false;
}
}

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TableScreenEsComponent } from './table-screen-es.component';
describe('TableScreenEsComponent', () => {
let component: TableScreenEsComponent;
let fixture: ComponentFixture<TableScreenEsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TableScreenEsComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(TableScreenEsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -21,7 +21,6 @@ import { TableScreenVsComponent } from './table-screen-vs.component';
declarations:[TableScreenVsComponent],
exports: [TableScreenVsComponent],
//NB: QUI VA DICHIARATO IL DIALOG DI DATAENTRY COME COMPONENT
entryComponents: [ResourceAddComponent],
bootstrap: [TableScreenVsComponent],
})

View File

@ -165,6 +165,7 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges {
}
reloadTable():void{
alert(this.typeObject.name)
this.myDataService.fetchResourceImpls(this.currentCtx.path,this.typeObject.name).subscribe(res => {
this.dataFromService = res;
this.dataSource.data = res;