use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class BackendUtils method getGitInformation.
/**
* @param directoryId DirectoryId of the ArtifactTemplate that should contain a reference to a git repository.
* @return The URL and the branch/tag that contains the files for the ArtifactTemplate. null if no git information
* is given.
*/
public static GitInfo getGitInformation(DirectoryId directoryId) {
if (!(directoryId.getParent() instanceof ArtifactTemplateId)) {
return null;
}
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions((ArtifactTemplateId) directoryId.getParent());
try (InputStream is = RepositoryFactory.getRepository().newInputStream(ref)) {
Unmarshaller u = JAXBSupport.createUnmarshaller();
Definitions defs = ((Definitions) u.unmarshal(is));
Map<QName, String> atts = defs.getOtherAttributes();
String src = atts.get(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "gitsrc"));
String branch = atts.get(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "gitbranch"));
// ^ is the XOR operator
if (src == null ^ branch == null) {
LOGGER.error("Git information not complete, URL or branch missing");
return null;
} else if (src == null && branch == null) {
return null;
}
return new GitInfo(src, branch);
} catch (IOException e) {
LOGGER.error("Error reading definitions of " + directoryId.getParent() + " at " + ref.getFileName(), e);
} catch (JAXBException e) {
LOGGER.error("Error in XML in " + ref.getFileName(), e);
}
return null;
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class IGenericRepository method getReferencedTOSCAComponentImplementationArtifactIds.
/**
* Helper method
*
* @param ids the list of ids to add the new ids to
* @param implementationArtifacts the implementation artifacts belonging to the given id
* @param id the id to handle
*/
default Collection<DefinitionsChildId> getReferencedTOSCAComponentImplementationArtifactIds(Collection<DefinitionsChildId> ids, TImplementationArtifacts implementationArtifacts, DefinitionsChildId id) {
if (implementationArtifacts != null) {
for (TImplementationArtifact ia : implementationArtifacts.getImplementationArtifact()) {
QName qname;
if ((qname = ia.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
ids.add(new ArtifactTypeId(ia.getArtifactType()));
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies.getPolicy()) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
if (serviceTemplate.getTopologyTemplate() != null) {
for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class DriverInjection method setDriverProperty.
public static void setDriverProperty(TRelationshipTemplate relationshipTemplate, TDeploymentArtifact driverDeploymentArtifact) throws Exception {
QName DAArtifactTemplateQName = driverDeploymentArtifact.getArtifactRef();
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId(DAArtifactTemplateQName);
TArtifactTemplate artifactTemplate = RepositoryFactory.getRepository().getElement(artifactTemplateId);
Map<String, String> artifactProperties = ModelUtilities.getPropertiesKV(artifactTemplate);
Map<String, String> relationshipProperties = ModelUtilities.getPropertiesKV(relationshipTemplate);
if ((artifactProperties != null) && (relationshipProperties != null) && artifactProperties.containsKey("Driver") && relationshipProperties.containsKey("Driver")) {
relationshipProperties.put("Driver", artifactProperties.get("Driver"));
relationshipTemplate.getProperties().setKVProperties(relationshipProperties);
} else {
throw new WineryRepositoryException("No Property found to set to the driver classname");
}
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class TestWineryRepositoryClient method createArtifactTemplate.
@Test
public void createArtifactTemplate() throws IOException, QNameAlreadyExistsException {
// assure that the artifact type exists
QName artifactTypeQName = TestWineryRepositoryClient.client.getArtifactTypeQNameForExtension("war");
Assert.assertNotNull("Artifact Type for .war does not exist", artifactTypeQName);
// assure that the artifact template does not yet exist
// one possibility is to delete the artifact template, the other
// possibility is to
QName artifactTemplateQName = new QName(TestWineryRepositoryClient.namespaceForNewArtifacts, "artifactTemplate");
ArtifactTemplateId atId = new ArtifactTemplateId(artifactTemplateQName);
// ensure that the template does not exist yet
TestWineryRepositoryClient.client.forceDelete(atId);
TestWineryRepositoryClient.client.createArtifactTemplate(artifactTemplateQName, artifactTypeQName);
}
Aggregations