use of org.eclipse.winery.model.tosca.yaml.YTImplementation 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.YTImplementation 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.YTImplementation in project winery by eclipse.
the class ToCanonical method convert.
private TImplementation convert(YTImplementation node) {
if (Objects.isNull(node)) {
return null;
}
TImplementation def = new TImplementation();
def.setPrimary(node.getPrimaryArtifactName());
def.setDependencies(node.getDependencyArtifactNames());
def.setTimeout(node.getTimeout());
def.setOperationHost(node.getOperationHost());
return def;
}
use of org.eclipse.winery.model.tosca.yaml.YTImplementation 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;
}
use of org.eclipse.winery.model.tosca.yaml.YTImplementation in project winery by eclipse.
the class YamlBuilder method buildOperationDefinition.
@Nullable
@SuppressWarnings("unchecked")
public YTOperationDefinition buildOperationDefinition(Object object, Parameter<YTOperationDefinition> parameter) {
if (Objects.isNull(object) || !validate(YTOperationDefinition.class, object, parameter)) {
return null;
}
if (!(object instanceof Map)) {
return null;
}
Map<String, Object> map = (Map<String, Object>) object;
String description = buildDescription(map.get(YamlSpecKeywords.DESCRIPTION));
Map<String, YTParameterDefinition> inputs = buildParameterDefinitions(map.get(YamlSpecKeywords.INPUTS), new Parameter<>(parameter.getContext()).addContext(YamlSpecKeywords.INPUTS).setValue(parameter.getValue()));
Map<String, YTParameterDefinition> outputs = buildParameterDefinitions(map.get(YamlSpecKeywords.OUTPUTS), new Parameter<>(parameter.getContext()).addContext(YamlSpecKeywords.OUTPUTS).setValue(parameter.getValue()));
YTImplementation implementation = buildImplementation(map.get(YamlSpecKeywords.IMPLEMENTATION), new Parameter<YTImplementation>(parameter.getContext()).addContext(YamlSpecKeywords.IMPLEMENTATION));
return new YTOperationDefinition.Builder().setDescription(description).setInputs(inputs).setOutputs(outputs).setImplementation(implementation).build();
}
Aggregations