use of org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
// add all implementations
Collection<RelationshipTypeImplementationId> allTypeImplementations = this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName());
for (RelationshipTypeImplementationId ntiId : allTypeImplementations) {
ids.add(ntiId);
}
final TRelationshipType relationshipType = this.getElement(id);
TRelationshipType.ValidSource validSource = relationshipType.getValidSource();
if (validSource != null) {
QName typeRef = validSource.getTypeRef();
// can be a node type or a requirement type
// similar code as for valid target (difference: req/cap)
NodeTypeId ntId = new NodeTypeId(typeRef);
if (this.exists(ntId)) {
ids.add(ntId);
} else {
RequirementTypeId rtId = new RequirementTypeId(typeRef);
ids.add(rtId);
}
}
TRelationshipType.ValidTarget validTarget = relationshipType.getValidTarget();
if (validTarget != null) {
QName typeRef = validTarget.getTypeRef();
// can be a node type or a capability type
// similar code as for valid target (difference: req/cap)
NodeTypeId ntId = new NodeTypeId(typeRef);
if (this.exists(ntId)) {
ids.add(ntId);
} else {
CapabilityTypeId capId = new CapabilityTypeId(typeRef);
ids.add(capId);
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class ImplementationsOfOneRelationshipTypeResource method getJSON.
@Override
public Response getJSON() {
Collection<RelationshipTypeImplementationId> allImplementations = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, this.getTypeId().getQName());
List<QNameApiData> res = new ArrayList<>(allImplementations.size());
QNameConverter adapter = new QNameConverter();
for (RelationshipTypeImplementationId id : allImplementations) {
res.add(adapter.marshal(id.getQName()));
}
return Response.ok().entity(res).build();
}
use of org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class ImplementationsOfOneRelationshipTypeResource method getImplementationsTableData.
/**
* required by implementations.jsp
* <p>
* Method similar top the one of ImplementationsOfOneNodeTypeResource
*
* @return for each node type implementation implementing the associated node type
*/
@Override
public String getImplementationsTableData() {
String res;
JsonFactory jsonFactory = new JsonFactory();
StringWriter tableDataSW = new StringWriter();
try {
JsonGenerator jGenerator = jsonFactory.createGenerator(tableDataSW);
jGenerator.writeStartArray();
Collection<RelationshipTypeImplementationId> allNTIids = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, this.getTypeId().getQName());
for (RelationshipTypeImplementationId ntiID : allNTIids) {
jGenerator.writeStartArray();
jGenerator.writeString(ntiID.getNamespace().getDecoded());
jGenerator.writeString(ntiID.getXmlId().getDecoded());
jGenerator.writeEndArray();
}
jGenerator.writeEndArray();
jGenerator.close();
tableDataSW.close();
res = tableDataSW.toString();
} catch (Exception e) {
ImplementationsOfOneRelationshipTypeResource.LOGGER.error(e.getMessage(), e);
res = "[]";
}
return res;
}
use of org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId in project winery by eclipse.
the class IGenericRepository 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);
TDeploymentArtifacts deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
}
TImplementationArtifacts implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts.getImplementationArtifact());
}
}
// check all Relationshiptype Implementations for IAs
SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
TImplementationArtifacts implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts.getImplementationArtifact());
}
}
// 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;
TDeploymentArtifacts deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
}
}
}
}
}
// 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;
}
Aggregations