Skip to content

Commit

Permalink
Enable direct usage of TOSCA artifacts and bump to 0.3 (#8)
Browse files Browse the repository at this point in the history
* add artifacts to core

* refactored property editing via dialogs

* continue adjust

* improved ui for artifacts and enabled saving

* added TOSCA export

* added artifacts to tosca parsing

* switched from property to artifact key in tosca and started adding artifact types

* updated tosca profile to use artifacts directly
  • Loading branch information
r0light authored Jun 5, 2024
1 parent 7e1e7f3 commit 1399200
Show file tree
Hide file tree
Showing 21 changed files with 1,326 additions and 1,339 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cna-quality-tool-vue",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
143 changes: 143 additions & 0 deletions src/core/common/artifact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@


// TODO parse artifact types from TOSCA profiles

import { all_profiles } from "@/totypa/parsedProfiles/v2dot0-profiles/all_profiles";

function getAvailableArtifactTypes() {

return all_profiles.flatMap(profile => {
return Object.entries(profile.artifact_types).map(([typeKey, typeDefinition]) => {
return typeKey;
})
})
}


// Aligned to 5.3.7.2 Artifact definition
class Artifact {
#type: string;
#file: string;
#repository: string;
#description: string;
#deployPath: string;
#artifactVersion: string;
#checksum: string;
#checksumAlgorithm: string;

constructor(
type: string,
file: string,
repository: string,
description: string,
deployPath: string,
artifactVersion: string,
checksum: string,
checksumAlgorithm: string,
) {
this.#type = type;
this.#file = file;
this.#repository = repository;
this.#description = description;
this.#deployPath = deployPath;
this.#artifactVersion = artifactVersion;
this.#checksum = checksum;
this.#checksumAlgorithm = checksumAlgorithm;
}

getType(): string {
return this.#type;
}

getFile(): string {
return this.#file;
}

getRepository(): string {
return this.#repository;
}

getDescription(): string {
return this.#description;
}

getDeployPath(): string {
return this.#deployPath;
}

getArtifactVersion(): string {
return this.#artifactVersion;
}

getChecksum(): string {
return this.#checksum;
}

getChecksumAlgorithm(): string {
return this.#checksumAlgorithm;
}

setType(type: string): void {
this.#type = type;
}

setFile(file: string): void {
this.#file = file;
}

setRepository(repository: string): void {
this.#repository = repository;
}

setDescription(description: string): void {
this.#description = description;
}

setDeployPath(deployPath: string): void {
this.#deployPath = deployPath;
}

setArtifactVersion(artifactVersion: string): void {
this.#artifactVersion = artifactVersion;
}

setChecksum(checksum: string): void {
this.#checksum = checksum;
}

setChecksumAlgorithm(checksumAlgorithm: string): void {
this.#checksumAlgorithm = checksumAlgorithm;
}

getAsSimpleObject(keyToAssign: string) {
if (keyToAssign) {
return {
key: keyToAssign,
type: this.#type,
file: this.#file,
repository: this.#repository,
description: this.#description,
deploy_path: this.#deployPath,
artifact_version: this.#artifactVersion,
checksum: this.#checksum,
checksum_algorithm: this.#checksumAlgorithm
}
} else {
return {
type: this.#type,
file: this.#file,
repository: this.#repository,
description: this.#description,
deploy_path: this.#deployPath,
artifact_version: this.#artifactVersion,
checksum: this.#checksum,
checksum_algorithm: this.#checksumAlgorithm
}
}


}

}

export { Artifact, getAvailableArtifactTypes }
31 changes: 15 additions & 16 deletions src/core/entities/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MetaData } from '../common/entityDataTypes.js'
import { RelationToDataAggregate } from './relationToDataAggregate.js'
import { RelationToBackingData } from './relationToBackingData.js'
import { BackingService } from './backingService.js'
import { Artifact } from '../common/artifact.js'


/**
Expand Down Expand Up @@ -75,10 +76,10 @@ class Component {

#dataAggregateEntities = new Array<{ data: DataAggregate, relation: RelationToDataAggregate }>();

#includedLinkEntities = new Array();

#proxiedBy: BackingService;

#artifacts: Map<string, Artifact> = new Map<string, Artifact>();

#properties: EntityProperty[] = new Array();

/**
Expand Down Expand Up @@ -133,11 +134,6 @@ class Component {
this.#backingDataEntities.push({backingData: entityToAdd, relation: relation });
}

addLinkEntity(linkEntity) {
// TODO add check
this.#includedLinkEntities.push(linkEntity);
}

/**
* Returns the ID of this Component entity.
* @returns {string}
Expand Down Expand Up @@ -198,15 +194,6 @@ class Component {
return this.#backingDataEntities;
}

/**
* Returns the {@link Link} entities included in this Component.
* @returns {Link[]}
*/
get getIncludedLinkEntities() {
return this.#includedLinkEntities;
}


get getProxiedBy() {
return this.#proxiedBy;
}
Expand All @@ -215,6 +202,18 @@ class Component {
this.#proxiedBy = proxy;
}

get getArtifacts() {
return this.#artifacts;
}

setArtifact(artifactKey: string, artifact: Artifact) {
this.#artifacts.set(artifactKey, artifact)
}

removeArtifact(artifactKey: string) {
this.#artifacts.delete(artifactKey);
}

/**
* Adds additional properties to this entity, only intended for subtypes to add additional properties
*
Expand Down
15 changes: 15 additions & 0 deletions src/core/entities/infrastructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EntityProperty, SelectEntityProperty, parseProperties } from "../common
import { cna_modeling_profile } from '../../totypa/parsedProfiles/v2dot0-profiles/cna_modeling_profile.js'
import { MetaData } from "../common/entityDataTypes.js";
import { RelationToBackingData } from "./relationToBackingData.js";
import { Artifact } from "../common/artifact.js";


/**
Expand Down Expand Up @@ -186,6 +187,8 @@ class Infrastructure {

#backingDataEntities = new Array<{ backingData: BackingData, relation: RelationToBackingData }>();

#artifacts: Map<string, Artifact> = new Map<string, Artifact>();

#properties: EntityProperty[];

/**
Expand Down Expand Up @@ -251,6 +254,18 @@ class Infrastructure {
return this.#backingDataEntities;
}

get getArtifacts() {
return this.#artifacts;
}

setArtifact(artifactKey: string, artifact: Artifact) {
this.#artifacts.set(artifactKey, artifact)
}

removeArtifact(artifactKey: string) {
this.#artifacts.delete(artifactKey);
}

/**
* Returns all properties of this entity
* @returns {EntityProperty[]}
Expand Down
16 changes: 16 additions & 0 deletions src/core/tosca-adapter/EntitiesToToscaConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ class EntitiesToToscaConverter {
template.properties = this.#parsePropertiesForYaml(infrastructure.getProperties());
}

if (infrastructure.getArtifacts.size > 0) {
template.artifacts = {};
for (const [key, artifact] of infrastructure.getArtifacts.entries()) {
//TODO include only keys with a value
template.artifacts[key] = artifact.getAsSimpleObject("");
}
}

return template;
}

Expand Down Expand Up @@ -412,6 +420,14 @@ class EntitiesToToscaConverter {
template.properties = properties;
}

if (component.getArtifacts.size > 0) {
template.artifacts = {};
for (const [key, artifact] of component.getArtifacts.entries()) {
//TODO include only keys with a value
template.artifacts[key] = artifact.getAsSimpleObject("");
}
}

return template;
}

Expand Down
31 changes: 31 additions & 0 deletions src/core/tosca-adapter/ToscaToEntitesConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RelationToDataAggregate } from '../entities/relationToDataAggregate';
import { RelationToBackingData } from '../entities/relationToBackingData';
import { TOSCA_File } from '@/totypa/tosca-types/v2dot0-types/definition-types';
import { TOSCA_Node_Template, TOSCA_Service_Template } from '@/totypa/tosca-types/v2dot0-types/template-types';
import { Artifact } from '../common/artifact';

const MATCH_UNDERSCORE = new RegExp(/_/g);
const MATCH_FIRST_CHARACTER = new RegExp(/^./g);
Expand Down Expand Up @@ -161,6 +162,21 @@ class ToscaToEntitesConverter {
infrastructure.setPropertyValue(key, value);
}
}

if (node.artifacts) {
for (const [key, value] of Object.entries(node.artifacts)) {
infrastructure.setArtifact(key, new Artifact(
value.type ? value.type : "",
value.file ? value.file : "",
value.repository ? value.repository : "",
value.description ? value.description : "",
value.deploy_path ? value.deploy_path : "",
value.artifact_version ? value.artifact_version : "",
value.checksum ? value.checksum : "",
value.checksum_algorithm ? value.checksum_algorithm : ""
))
}
}
}
}

Expand Down Expand Up @@ -262,6 +278,21 @@ class ToscaToEntitesConverter {
component.setPropertyValue(key, value);
}
}

if (node.artifacts) {
for (const [key, value] of Object.entries(node.artifacts)) {
component.setArtifact(key, new Artifact(
value.type ? value.type : "",
value.file ? value.file : "",
value.repository ? value.repository : "",
value.description ? value.description : "",
value.deploy_path ? value.deploy_path : "",
value.artifact_version ? value.artifact_version : "",
value.checksum ? value.checksum : "",
value.checksum_algorithm ? value.checksum_algorithm : ""
))
}
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/modeling/config/actionDialogConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { dia } from '@joint/core'
import { PropertyConfig } from "./detailsSidebarConfig"

export type DialogConfig = {
Expand Down
Loading

0 comments on commit 1399200

Please sign in to comment.