Search in sources :

Example 16 with ArtifactTemplateId

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;
}
Also used : RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) Definitions(org.eclipse.winery.model.tosca.Definitions) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) GitInfo(org.eclipse.winery.repository.GitInfo) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)

Example 17 with ArtifactTemplateId

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;
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)

Example 18 with ArtifactTemplateId

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;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 19 with ArtifactTemplateId

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");
    }
}
Also used : QName(javax.xml.namespace.QName) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException)

Example 20 with ArtifactTemplateId

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);
}
Also used : QName(javax.xml.namespace.QName) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) Test(org.junit.Test)

Aggregations

ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)23 QName (javax.xml.namespace.QName)10 Test (org.junit.Test)9 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)8 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)6 ArtifactTemplateSourceDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId)6 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)4 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)4 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)3 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)3 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Response (javax.ws.rs.core.Response)2 JAXBException (javax.xml.bind.JAXBException)2 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)2 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)2