Search in sources :

Example 1 with WineryRepositoryException

use of org.eclipse.winery.repository.exceptions.WineryRepositoryException in project winery by eclipse.

the class Converter method convertDefinitionsChildToYaml.

public String convertDefinitionsChildToYaml(DefinitionsChildId id) throws MultiException {
    Path path = Utils.getTmpDir(Paths.get(id.getQName().getLocalPart()));
    convertX2Y(repository.getDefinitions(id), path);
    // convention: single file in root contains the YAML support
    // TODO: Links in the YAML should be changed to real links into Winery
    Optional<Path> rootYamlFile;
    try {
        return Files.find(path, 1, (filePath, basicFileAttributes) -> filePath.getFileName().toString().endsWith(".yml")).findAny().map(p -> {
            try {
                return new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
            } catch (IOException e) {
                LOGGER.debug("Could not read root file", e);
                return "Could not read root file";
            }
        }).orElseThrow(() -> {
            MultiException multiException = new MultiException();
            multiException.add(new WineryRepositoryException("Root YAML file not found."));
            return multiException;
        });
    } catch (IOException e) {
        MultiException multiException = new MultiException();
        multiException.add(new WineryRepositoryException("Root YAML file not found.", e));
        throw multiException;
    }
}
Also used : Definitions(org.eclipse.winery.model.tosca.Definitions) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Utils(org.eclipse.winery.yaml.common.Utils) Y2XConverter(org.eclipse.winery.yaml.converter.yaml.Y2XConverter) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) TServiceTemplate(org.eclipse.winery.model.tosca.yaml.TServiceTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException) Reader(org.eclipse.winery.yaml.common.reader.yaml.Reader) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) java.nio.file(java.nio.file) TOSCAMetaFileParser(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileParser) X2YConverter(org.eclipse.winery.yaml.converter.xml.X2YConverter) Objects(java.util.Objects) IRepository(org.eclipse.winery.repository.backend.IRepository) Map(java.util.Map) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) Optional(java.util.Optional) TOSCAMetaFile(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile) InputStream(java.io.InputStream) IOException(java.io.IOException) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException)

Example 2 with WineryRepositoryException

use of org.eclipse.winery.repository.exceptions.WineryRepositoryException in project winery by eclipse.

the class FilebasedRepository method getZippedContents.

@Override
public void getZippedContents(final GenericId id, OutputStream out) throws WineryRepositoryException {
    Objects.requireNonNull(id);
    Objects.requireNonNull(out);
    SortedSet<RepositoryFileReference> containedFiles = this.getContainedFiles(id);
    try (final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", out)) {
        for (RepositoryFileReference ref : containedFiles) {
            ZipArchiveEntry zipArchiveEntry;
            final Optional<Path> subDirectory = ref.getSubDirectory();
            if (subDirectory.isPresent()) {
                zipArchiveEntry = new ZipArchiveEntry(subDirectory.get().resolve(ref.getFileName()).toString());
            } else {
                zipArchiveEntry = new ZipArchiveEntry(ref.getFileName());
            }
            zos.putArchiveEntry(zipArchiveEntry);
            try (InputStream is = RepositoryFactory.getRepository().newInputStream(ref)) {
                IOUtils.copy(is, zos);
            }
            zos.closeArchiveEntry();
        }
    } catch (ArchiveException e) {
        throw new WineryRepositoryException("Internal error while generating archive", e);
    } catch (IOException e) {
        throw new WineryRepositoryException("I/O exception during export", e);
    }
}
Also used : ArchiveStreamFactory(org.apache.commons.compress.archivers.ArchiveStreamFactory) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) ZipInputStream(java.util.zip.ZipInputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ArchiveException(org.apache.commons.compress.archivers.ArchiveException) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException)

Example 3 with WineryRepositoryException

use of org.eclipse.winery.repository.exceptions.WineryRepositoryException in project winery by eclipse.

the class AbstractFileBasedRepository method getZippedContents.

@Override
public void getZippedContents(final GenericId id, OutputStream out) throws WineryRepositoryException {
    Objects.requireNonNull(id);
    Objects.requireNonNull(out);
    SortedSet<RepositoryFileReference> containedFiles = this.getContainedFiles(id);
    try (final ZipOutputStream zos = new ZipOutputStream(out)) {
        for (RepositoryFileReference ref : containedFiles) {
            ZipEntry zipArchiveEntry;
            final Optional<Path> subDirectory = ref.getSubDirectory();
            if (subDirectory.isPresent()) {
                zipArchiveEntry = new ZipEntry(subDirectory.get().resolve(ref.getFileName()).toString());
            } else {
                zipArchiveEntry = new ZipEntry(ref.getFileName());
            }
            zos.putNextEntry(zipArchiveEntry);
            try (InputStream is = this.newInputStream(ref)) {
                IOUtils.copy(is, zos);
            }
            zos.closeEntry();
        }
    } catch (IOException e) {
        throw new WineryRepositoryException("I/O exception during export", e);
    }
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ZipOutputStream(java.util.zip.ZipOutputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException)

Example 4 with WineryRepositoryException

use of org.eclipse.winery.repository.exceptions.WineryRepositoryException 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);
    LinkedHashMap<String, String> relationshipProperties = ModelUtilities.getPropertiesKV(relationshipTemplate);
    if ((artifactProperties != null) && (relationshipProperties != null) && artifactProperties.containsKey("Driver") && relationshipProperties.containsKey("Driver")) {
        relationshipProperties.put("Driver", artifactProperties.get("Driver"));
        ModelUtilities.setPropertiesKV(relationshipTemplate, relationshipProperties);
    } else {
        throw new WineryRepositoryException("No Property found to set to the driver classname");
    }
}
Also used : QName(javax.xml.namespace.QName) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException)

Aggregations

WineryRepositoryException (org.eclipse.winery.repository.exceptions.WineryRepositoryException)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ZipInputStream (java.util.zip.ZipInputStream)2 File (java.io.File)1 StandardCharsets (java.nio.charset.StandardCharsets)1 java.nio.file (java.nio.file)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 QName (javax.xml.namespace.QName)1 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)1 ArchiveOutputStream (org.apache.commons.compress.archivers.ArchiveOutputStream)1 ArchiveStreamFactory (org.apache.commons.compress.archivers.ArchiveStreamFactory)1 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)1 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)1