use of org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final TDefinitions definitions = createWrapperDefinitions(id, repository);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof DataTypeId) {
element = new TDataType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof ComplianceRuleId) {
element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
} else if (id instanceof PatternRefinementModelId) {
element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
} else if (id instanceof TopologyFragmentRefinementModelId) {
element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
} else if (id instanceof TestRefinementModelId) {
element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
} else if (id instanceof InterfaceTypeId) {
element = new TInterfaceType();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class YamlRepository method convertToYamlModel.
private YTServiceTemplate convertToYamlModel(RepositoryFileReference existing, TDefinitions definitions) throws IOException, MultiException {
FromCanonical converter = new FromCanonical(this);
YTServiceTemplate serviceTemplate;
if (existing.getParent() instanceof NodeTypeImplementationId) {
serviceTemplate = readServiceTemplate(existing);
serviceTemplate = converter.convertNodeTypeImplementation(serviceTemplate, definitions.getNodeTypeImplementations().get(0));
} else if (existing.getParent() instanceof RelationshipTypeImplementationId) {
serviceTemplate = readServiceTemplate(existing);
serviceTemplate = converter.convertRelationshipTypeImplementation(serviceTemplate, definitions.getRelationshipTypeImplementations().get(0));
} else if (existing.getParent() instanceof NodeTypeId) {
serviceTemplate = converter.convert(definitions);
if (exists(existing)) {
YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
serviceTemplate = replaceOldWithNewData(serviceTemplate, oldServiceTemplate);
}
} else if (existing.getParent() instanceof RelationshipTypeId) {
serviceTemplate = converter.convert(definitions);
if (exists(existing)) {
YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
serviceTemplate = replaceOldRelationshipTypeWithNewData(serviceTemplate, oldServiceTemplate);
}
} else if (existing.getParent() instanceof ArtifactTemplateId) {
ArtifactTemplateId id = (ArtifactTemplateId) existing.getParent();
TArtifactTemplate artifactTemplate = definitions.getArtifactTemplates().get(0);
YTArtifactDefinition artifact = converter.convertArtifactTemplate(artifactTemplate);
List<YTMapImportDefinition> imports = converter.convertImports();
Path targetPath = ref2AbsolutePath(existing);
if (Files.exists(targetPath)) {
serviceTemplate = readServiceTemplate(targetPath);
if (serviceTemplate == null) {
serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
} else if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
YTNodeType nodeType = serviceTemplate.getNodeTypes().entrySet().iterator().next().getValue();
Map<String, YTArtifactDefinition> artifacts = nodeType.getArtifacts();
if (artifacts.containsKey(artifactTemplate.getIdFromIdOrNameField())) {
artifacts.replace(artifactTemplate.getIdFromIdOrNameField(), artifact);
} else {
artifacts.put(artifactTemplate.getIdFromIdOrNameField(), artifact);
}
} else if (existing.getParent() instanceof PolicyTypeId || existing.getParent() instanceof CapabilityTypeId) {
// we simply take the new definition as is
serviceTemplate = converter.convert(definitions);
} else {
serviceTemplate = converter.convert(definitions);
if (exists(existing)) {
YTServiceTemplate existingServiceTemplate = readServiceTemplate(existing);
serviceTemplate = replaceTopologyTemplate(serviceTemplate, existingServiceTemplate);
}
}
} else {
serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
}
} else {
serviceTemplate = converter.convert(definitions);
}
return serviceTemplate;
}
use of org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class IRepository method getReferenceCount.
default int getReferenceCount(ArtifactTemplateId id) {
// We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
// DAs and IAs point to an artifact template
// DAs are contained in Node Type Implementations and Node Templates
// IAs are contained in Node Type Implementations and Relationship Type Implementations
int count = 0;
Collection<TDeploymentArtifact> allDAs = new HashSet<>();
Collection<TImplementationArtifact> allIAs = new HashSet<>();
// handle Node Type Implementation, which contains DAs and IAs
SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts);
}
List<TImplementationArtifact> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts);
}
}
// check all RelationshipTypeImplementations for IAs
SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
List<TImplementationArtifact> implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts);
}
}
// check all node templates for DAs
SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
for (ServiceTemplateId sid : serviceTemplates) {
TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
if (topologyTemplate != null) {
List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
if (template instanceof TNodeTemplate) {
TNodeTemplate nodeTemplate = (TNodeTemplate) template;
List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts);
}
}
}
}
}
// now we have all DAs and IAs
QName ourQName = id.getQName();
// check DAs for artifact templates
for (TDeploymentArtifact da : allDAs) {
QName artifactRef = da.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
// check IAs for artifact templates
for (TImplementationArtifact ia : allIAs) {
QName artifactRef = ia.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
return count;
}
use of org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class VersionSupport method getDefinitionInTheGivenVersion.
public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
if (childId.getVersion().compareTo(otherVersion) == 0) {
return childId;
}
String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
if (childId instanceof RelationshipTypeImplementationId) {
return new RelationshipTypeImplementationId(qName);
} else if (childId instanceof NodeTypeImplementationId) {
return new NodeTypeImplementationId(qName);
} else if (childId instanceof RequirementTypeId) {
return new RequirementTypeId(qName);
} else if (childId instanceof NodeTypeId) {
return new NodeTypeId(qName);
} else if (childId instanceof RelationshipTypeId) {
return new RelationshipTypeId(qName);
} else if (childId instanceof CapabilityTypeId) {
return new CapabilityTypeId(qName);
} else if (childId instanceof ArtifactTypeId) {
return new ArtifactTypeId(qName);
} else if (childId instanceof PolicyTypeId) {
return new PolicyTypeId(qName);
} else if (childId instanceof PolicyTemplateId) {
return new PolicyTemplateId(qName);
} else if (childId instanceof ServiceTemplateId) {
return new ServiceTemplateId(qName);
} else if (childId instanceof ArtifactTemplateId) {
return new ArtifactTemplateId(qName);
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
}
use of org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class YamlRepository method getRequestedDefinition.
/**
* Parses only requested Definition from converted yaml service template
*
* @param id Definitions Child id
* @param definitions converted definitions
* @return requested definitions
*/
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
if (id instanceof ArtifactTemplateId) {
String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
for (TArtifactTemplate artifactTemplate : artifactTemplates) {
if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
requestedArtifactTemplates.add(artifactTemplate);
TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
return requestedDefinitions.build();
}
}
// we did not find the artifact template id (this should not happen!)
LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
return definitions;
} else {
TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
if (id instanceof NodeTypeId) {
requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
} else if (id instanceof RelationshipTypeId) {
requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
} else if (id instanceof NodeTypeImplementationId) {
requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
} else if (id instanceof RelationshipTypeImplementationId) {
requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
} else if (id instanceof ArtifactTypeId) {
requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
} else if (id instanceof CapabilityTypeId) {
requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
} else if (id instanceof DataTypeId) {
requestedDefinitions.addDataTypes(definitions.getDataTypes());
} else if (id instanceof RequirementTypeId) {
requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
} else if (id instanceof PolicyTypeId) {
requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
} else if (id instanceof InterfaceTypeId) {
requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
} else {
// we do not need to filter anything
return definitions;
}
return requestedDefinitions.build();
}
}
Aggregations