use of org.eclipse.winery.model.tosca.yaml.YTOperationDefinition in project winery by eclipse.
the class FromCanonical method convert.
public Map<String, YTInterfaceType> convert(TInterfaceType node) {
if (Objects.isNull(node)) {
return null;
}
Map<String, YTOperationDefinition> ops = new HashMap<>();
node.getOperations().forEach((key, value) -> ops.putAll(convert(value)));
YTInterfaceType.Builder interfaceBuilder = new YTInterfaceType.Builder().setDescription(node.getDescription()).setOperations(ops).setDerivedFrom(convert(node.getDerivedFrom(), node.getClass()));
String typeName = node.getName();
if (Objects.nonNull(node.getTargetNamespace()) && !node.getTargetNamespace().isEmpty()) {
Metadata metadata = new Metadata();
metadata.put("targetNamespace", node.getTargetNamespace());
interfaceBuilder.addMetadata(metadata);
if (Objects.nonNull(typeName)) {
typeName = node.getTargetNamespace().concat(".").concat(typeName);
}
}
return Collections.singletonMap(typeName, interfaceBuilder.build());
}
use of org.eclipse.winery.model.tosca.yaml.YTOperationDefinition in project winery by eclipse.
the class YamlRepository method addArtifactFileToTargetOperation.
/**
* Adds artifacts filepath to interfaces for relationship type artifact templates
*
* @param interfaces interfaces of type
* @param target name of artifact
* @param artifact artifact
* @return edited interfaces
*/
private YTInterfaceDefinition addArtifactFileToTargetOperation(YTInterfaceDefinition interfaces, YTArtifactDefinition artifact, String target) {
Map<String, YTOperationDefinition> operations = interfaces.getOperations();
for (Map.Entry<String, YTOperationDefinition> operation : operations.entrySet()) {
if (operation.getKey().equalsIgnoreCase(target)) {
YTImplementation implementation = operation.getValue().getImplementation();
implementation.setPrimaryArtifactName(artifact.getFile());
YTOperationDefinition operationDefinition = operation.getValue();
operationDefinition.setImplementation(implementation);
operation.setValue(operationDefinition);
} else {
YTOperationDefinition operationDefinition = operation.getValue();
if (operationDefinition.getImplementation() != null) {
if (operationDefinition.getImplementation().getPrimaryArtifactName() != null) {
if (operationDefinition.getImplementation().getPrimaryArtifactName().equalsIgnoreCase(target)) {
YTImplementation implementation = operationDefinition.getImplementation();
implementation.setPrimaryArtifactName(artifact.getFile());
operationDefinition.setImplementation(implementation);
}
}
}
operation.setValue(operationDefinition);
}
}
interfaces.setOperations(operations);
return interfaces;
}
use of org.eclipse.winery.model.tosca.yaml.YTOperationDefinition in project winery by eclipse.
the class YamlRepository method removeRelationshipArtifact.
/**
* Deletes artifact from yaml relationship type
*
* @param relationshipType TRelationshipType
* @param targetArtifactName targeted artifact name
* @return updated node type
*/
private YTRelationshipType removeRelationshipArtifact(YTRelationshipType relationshipType, String targetArtifactName) {
Map<String, YTInterfaceDefinition> interfaces = relationshipType.getInterfaces();
for (Map.Entry<String, YTInterfaceDefinition> interfaceDefinition : interfaces.entrySet()) {
Map<String, YTOperationDefinition> operations = interfaceDefinition.getValue().getOperations();
YTOperationDefinition operationWithImplementation = operations.get(targetArtifactName);
if (operationWithImplementation != null) {
operationWithImplementation.setImplementation(null);
operations.replace(targetArtifactName, operationWithImplementation);
} else {
for (Map.Entry<String, YTOperationDefinition> operation : operations.entrySet()) {
YTOperationDefinition operationDefinition = operation.getValue();
if (operationDefinition != null) {
YTImplementation implementation = operationDefinition.getImplementation();
if (implementation != null) {
if (implementation.getPrimaryArtifactName() != null) {
if (implementation.getPrimaryArtifactName().equalsIgnoreCase(targetArtifactName)) {
operationDefinition.setImplementation(null);
} else {
if (implementation.getDependencyArtifactNames() != null) {
List<String> names = implementation.getDependencyArtifactNames();
for (String name : implementation.getDependencyArtifactNames()) {
if (name.equalsIgnoreCase(targetArtifactName)) {
names.remove(name);
}
}
implementation.setDependencyArtifactNames(names);
}
}
operationDefinition.setImplementation(implementation);
}
}
operation.setValue(operationDefinition);
}
}
YTInterfaceDefinition tInterfaceDefinition = interfaceDefinition.getValue();
tInterfaceDefinition.setOperations(operations);
interfaceDefinition.setValue(tInterfaceDefinition);
}
relationshipType.setInterfaces(interfaces);
}
return relationshipType;
}
use of org.eclipse.winery.model.tosca.yaml.YTOperationDefinition in project winery by eclipse.
the class ToCanonical method convert.
private TOperationDefinition convert(YTOperationDefinition node, String id) {
if (Objects.isNull(node)) {
return null;
}
TOperationDefinition def = new TOperationDefinition();
def.setId(id);
def.setName(id);
def.setDescription(node.getDescription());
def.setInputs(convert(node.getInputs()));
def.setOutputs(convert(node.getOutputs()));
def.setImplementation(convert(node.getImplementation()));
return def;
}
use of org.eclipse.winery.model.tosca.yaml.YTOperationDefinition in project winery by eclipse.
the class YamlRepository method removeImplementation.
/**
* Deletes artifact from yaml node type interfaces
*
* @param nodeType TNodeType
* @param targetArtifactName targeted artifact name
* @return updated node type
*/
private YTNodeType removeImplementation(YTNodeType nodeType, String targetArtifactName) {
Map<String, YTInterfaceDefinition> interfaces = nodeType.getInterfaces();
for (Map.Entry<String, YTInterfaceDefinition> interfaceDefinition : interfaces.entrySet()) {
Map<String, YTOperationDefinition> operations = interfaceDefinition.getValue().getOperations();
for (Map.Entry<String, YTOperationDefinition> operation : operations.entrySet()) {
YTOperationDefinition operationDefinition = operation.getValue();
if (operationDefinition != null) {
YTImplementation implementation = operationDefinition.getImplementation();
if (implementation != null) {
if (implementation.getPrimaryArtifactName() != null) {
// TODO
if (implementation.getPrimaryArtifactName().equalsIgnoreCase(targetArtifactName)) {
operationDefinition.setImplementation(null);
} else {
if (implementation.getDependencyArtifactNames() != null) {
List<String> names = implementation.getDependencyArtifactNames();
for (String name : implementation.getDependencyArtifactNames()) {
if (name.equalsIgnoreCase(targetArtifactName)) {
names.remove(name);
}
}
implementation.setDependencyArtifactNames(names);
}
}
}
operationDefinition.setImplementation(implementation);
}
operation.setValue(operationDefinition);
}
}
YTInterfaceDefinition tInterfaceDefinition = interfaceDefinition.getValue();
tInterfaceDefinition.setOperations(operations);
interfaceDefinition.setValue(tInterfaceDefinition);
}
nodeType.setInterfaces(interfaces);
return nodeType;
}
Aggregations