Search in sources :

Example 21 with DefinitionsChildId

use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>(1);
    final TRequirementType element = this.getElement(id);
    QName requiredCapabilityType = element.getRequiredCapabilityType();
    if (requiredCapabilityType != null) {
        CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
        ids.add(capId);
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Example 22 with DefinitionsChildId

use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

/**
 * Determines the referenced definition children Ids. Does NOT return the included files.
 *
 * @return a collection of referenced definition child Ids
 */
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ArtifactTemplateId id) throws RepositoryCorruptException {
    Collection<DefinitionsChildId> ids = new ArrayList<>();
    final TArtifactTemplate artifactTemplate = this.getElement(id);
    // "Export" type
    QName type = artifactTemplate.getType();
    if (type == null) {
        throw new RepositoryCorruptException("Type is null for " + id.toReadableString());
    } else {
        ids.add(new ArtifactTypeId(type));
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException)

Example 23 with DefinitionsChildId

use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class FilebasedRepository method getAllIdsInNamespace.

public Collection<? extends DefinitionsChildId> getAllIdsInNamespace(Class<? extends DefinitionsChildId> clazz, Namespace namespace) {
    Collection<DefinitionsChildId> result = new HashSet<>();
    String rootPathFragment = Util.getRootPathFragment(clazz);
    Path dir = this.repositoryRoot.resolve(rootPathFragment);
    dir = dir.resolve(namespace.getEncoded());
    if (Files.exists(dir) && Files.isDirectory(dir)) {
        DirectoryStream<Path> directoryStream = null;
        try {
            directoryStream = Files.newDirectoryStream(dir);
            for (Path path : directoryStream) {
                Constructor<? extends DefinitionsChildId> constructor = null;
                constructor = clazz.getConstructor(String.class, String.class, boolean.class);
                DefinitionsChildId definitionsChildId = constructor.newInstance(namespace.getDecoded(), path.getFileName().toString(), false);
                result.add(definitionsChildId);
            }
            directoryStream.close();
        } catch (IOException e) {
            FilebasedRepository.LOGGER.debug("Cannot close ds", e);
        } catch (NoSuchMethodException e) {
            FilebasedRepository.LOGGER.debug("Cannot find constructor", e);
        } catch (InstantiationException e) {
            FilebasedRepository.LOGGER.debug("Cannot instantiate object", e);
        } catch (IllegalAccessException e) {
            FilebasedRepository.LOGGER.debug("IllegalAccessException", e);
        } catch (InvocationTargetException e) {
            FilebasedRepository.LOGGER.debug("InvocationTargetException", e);
        }
    }
    return result;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 with DefinitionsChildId

use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class CsarExporter method writeCsar.

/**
 * Writes a complete CSAR containing all necessary things reachable from the given service template
 *
 * @param entryId the id of the service template to export
 * @param out     the output stream to write to
 */
public void writeCsar(IRepository repository, DefinitionsChildId entryId, OutputStream out) throws ArchiveException, IOException, JAXBException, RepositoryCorruptException {
    CsarExporter.LOGGER.trace("Starting CSAR export with {}", entryId.toString());
    Map<RepositoryFileReference, String> refMap = new HashMap<>();
    Collection<String> definitionNames = new ArrayList<>();
    try (final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", out)) {
        ToscaExportUtil exporter = new ToscaExportUtil();
        Map<String, Object> conf = new HashMap<>();
        ExportedState exportedState = new ExportedState();
        DefinitionsChildId currentId = entryId;
        do {
            String defName = CsarExporter.getDefinitionsPathInsideCSAR(repository, currentId);
            definitionNames.add(defName);
            zos.putArchiveEntry(new ZipArchiveEntry(defName));
            Collection<DefinitionsChildId> referencedIds;
            referencedIds = exporter.exportTOSCA(repository, currentId, zos, refMap, conf);
            zos.closeArchiveEntry();
            exportedState.flagAsExported(currentId);
            exportedState.flagAsExportRequired(referencedIds);
            currentId = exportedState.pop();
        } while (currentId != null);
        // if we export a ServiceTemplate, data for the self-service portal might exist
        if (entryId instanceof ServiceTemplateId) {
            ServiceTemplateId serviceTemplateId = (ServiceTemplateId) entryId;
            this.addSelfServiceMetaData(repository, serviceTemplateId, refMap);
            this.addSelfServiceFiles(repository, serviceTemplateId, refMap, zos);
        }
        // now, refMap contains all files to be added to the CSAR
        // write manifest directly after the definitions to have it more at the beginning of the ZIP rather than having it at the very end
        this.addManifest(repository, entryId, definitionNames, refMap, zos);
        // used for generated XSD schemas
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer;
        try {
            transformer = tFactory.newTransformer();
        } catch (TransformerConfigurationException e1) {
            CsarExporter.LOGGER.debug(e1.getMessage(), e1);
            throw new IllegalStateException("Could not instantiate transformer", e1);
        }
        // write all referenced files
        for (RepositoryFileReference ref : refMap.keySet()) {
            String archivePath = refMap.get(ref);
            CsarExporter.LOGGER.trace("Creating {}", archivePath);
            if (ref instanceof DummyRepositoryFileReferenceForGeneratedXSD) {
                addDummyRepositoryFileReferenceForGeneratedXSD(zos, transformer, (DummyRepositoryFileReferenceForGeneratedXSD) ref, archivePath);
            } else {
                if (ref.getParent() instanceof DirectoryId) {
                    // special handling for artifact template directories "source" and "files"
                    addArtifactTemplateToZipFile(zos, repository, ref, archivePath);
                } else {
                    addFileToZipArchive(zos, repository, ref, archivePath);
                    zos.closeArchiveEntry();
                }
            }
        }
        this.addNamespacePrefixes(zos, repository);
    }
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ArchiveStreamFactory(org.apache.commons.compress.archivers.ArchiveStreamFactory) ServiceTemplateSelfServiceFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ServiceTemplateSelfServiceFilesDirectoryId) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream)

Example 25 with DefinitionsChildId

use of org.eclipse.winery.common.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class AbstractComponentsResource method getAll.

/**
 * Returns resources for all known component instances
 * <p>
 * Required by XaaSPackager logic
 * <p>
 * TODO: remove that method and refactor callers
 */
public Collection<AbstractComponentInstanceResource> getAll() {
    Class<? extends DefinitionsChildId> idClass = RestUtils.getComponentIdClassForComponentContainer(this.getClass());
    SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(idClass);
    ArrayList<AbstractComponentInstanceResource> res = new ArrayList<>(allDefinitionsChildIds.size());
    for (DefinitionsChildId id : allDefinitionsChildIds) {
        AbstractComponentInstanceResource r = AbstractComponentsResource.getComponentInstaceResource(id);
        res.add(r);
    }
    return res;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId)

Aggregations

DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)30 QName (javax.xml.namespace.QName)12 ArrayList (java.util.ArrayList)9 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)7 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 IOException (java.io.IOException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)5 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)5 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)4 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)4 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)4 TOSCAModelHelper.createNodeTypeId (org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId)4 TOSCAModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate)4 TOSCAModelHelper.createTNodeType (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeType)4 TComplianceRule (org.eclipse.winery.model.tosca.TComplianceRule)4 TNodeType (org.eclipse.winery.model.tosca.TNodeType)4