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;
}
}
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);
}
}
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);
}
}
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");
}
}
Aggregations