use of org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry in project winery by eclipse.
the class YamlExporter method addManifest.
private String addManifest(IRepository repository, DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
String entryDefinitionsReference = getDefinitionsPathInsideCSAR(repository, id);
out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
StringBuilder stringBuilder = new StringBuilder();
// Setting Versions
stringBuilder.append(TOSCA_META_FILE_VERSION).append(": ").append(TOSCA_META_FILE_VERSION_VALUE).append("\n");
stringBuilder.append(CSAR_VERSION).append(": ").append(CSAR_VERSION_VALUE_FOR_YAML).append("\n");
stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
// Winery currently is unaware of tDefinitions, therefore, we use the
// name of the service template
stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
stringBuilder.append("\n");
assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
// Setting other files, mainly files belonging to artifacts
for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
final CsarEntry csarEntry = item.getValue();
final CsarContentProperties fileProperties = item.getKey();
stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
String mimeType;
if (csarEntry instanceof DocumentBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_XSD;
} else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof YAMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
} else if (csarEntry instanceof RemoteRefBasedCsarEntry) {
mimeType = repository.getMimeType((RemoteRefBasedCsarEntry) csarEntry);
} else {
mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
}
stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
stringBuilder.append("\n");
}
String manifestString = stringBuilder.toString();
out.write(manifestString.getBytes());
out.closeEntry();
return manifestString;
}
use of org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry in project winery by eclipse.
the class CsarExporter method addSelfServiceMetaData.
/**
* Adds all self-service metadata to the targetDir
*
* @param entryId the service template to export for
* @param targetDir the directory in the CSAR where to put the content to
* @param refMap is used later to create the CSAR
*/
private void addSelfServiceMetaData(ServiceTemplateId entryId, String targetDir, Map<CsarContentProperties, CsarEntry> refMap) throws IOException {
final SelfServiceMetaDataId selfServiceMetaDataId = new SelfServiceMetaDataId(entryId);
// This method is also called if the directory SELF-SERVICE-Metadata exists without content and even if the directory does not exist at all,
// but the ServiceTemplate itself exists.
// The current assumption is that this is enough for an existence.
// Thus, we have to take care of the case of an empty directory and add a default data.xml
SelfServiceMetaDataUtils.ensureDataXmlExists(repository, selfServiceMetaDataId);
CsarContentProperties csarContentProperties = new CsarContentProperties(targetDir + "data.xml");
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, SelfServiceMetaDataUtils.getDataXmlRef(selfServiceMetaDataId)));
// The schema says that the images have to exist
// However, at a quick modeling, there might be no images
// Therefore, we check for existence
final RepositoryFileReference iconJpgRef = SelfServiceMetaDataUtils.getIconJpgRef(selfServiceMetaDataId);
if (repository.exists(iconJpgRef)) {
csarContentProperties = new CsarContentProperties(targetDir + "icon.jpg");
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, iconJpgRef));
}
final RepositoryFileReference imageJpgRef = SelfServiceMetaDataUtils.getImageJpgRef(selfServiceMetaDataId);
if (repository.exists(imageJpgRef)) {
csarContentProperties = new CsarContentProperties(targetDir + "image.jpg");
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, imageJpgRef));
}
Application application = SelfServiceMetaDataUtils.getApplication(repository, selfServiceMetaDataId);
// set to true only if changes are applied to application
boolean isApplicationChanged = false;
if (application.getCsarName() != null) {
// clear CSAR name as this may change.
application.setCsarName(null);
isApplicationChanged = true;
}
if (application.getVersion() == null || !application.getVersion().equals("1.0")) {
// hack for the OpenTOSCA container to display something
application.setVersion("1.0");
isApplicationChanged = true;
}
List<String> authors = application.getAuthors();
if (authors.isEmpty()) {
authors.add("Winery");
isApplicationChanged = true;
}
if (isApplicationChanged) {
// make the patches to data.xml permanent
try {
BackendUtils.persist(application, SelfServiceMetaDataUtils.getDataXmlRef(selfServiceMetaDataId), MediaTypes.MEDIATYPE_TEXT_XML, repository);
} catch (IOException e) {
LOGGER.error("Could not persist patches to data.xml", e);
}
}
Options options = application.getOptions();
if (options != null) {
SelfServiceMetaDataId id = new SelfServiceMetaDataId(entryId);
for (ApplicationOption option : options.getOption()) {
String url = option.getIconUrl();
if (Util.isRelativeURI(url)) {
putRefIntoRefMap(targetDir, refMap, id, url);
}
url = option.getPlanInputMessageUrl();
if (Util.isRelativeURI(url)) {
putRefIntoRefMap(targetDir, refMap, id, url);
}
}
}
}
use of org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry in project winery by eclipse.
the class CsarExporter method addManifest.
private String addManifest(DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
String entryDefinitionsReference = CsarExporter.getDefinitionsPathInsideCSAR(repository, id);
out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
StringBuilder stringBuilder = new StringBuilder();
// Setting Versions
stringBuilder.append(TOSCA_META_VERSION).append(": 1.0").append("\n");
stringBuilder.append(CSAR_VERSION).append(": 1.0").append("\n");
stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
// Winery currently is unaware of tDefinitions, therefore, we use the
// name of the service template
stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
stringBuilder.append("\n");
assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
// Setting other files, mainly files belonging to artifacts
for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
final CsarEntry csarEntry = item.getValue();
final CsarContentProperties fileProperties = item.getKey();
stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
String mimeType;
if (csarEntry instanceof DocumentBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_XSD;
} else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
} else {
mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
}
stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
if (exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_HASHES.name()) && Objects.nonNull(fileProperties.getFileHash())) {
stringBuilder.append(HASH).append(": ").append(fileProperties.getFileHash()).append("\n");
}
if (exportConfiguration.containsKey(CsarExportConfiguration.STORE_IMMUTABLY.name()) && Objects.nonNull(fileProperties.getImmutableAddress())) {
stringBuilder.append(IMMUTABLE_ADDRESS).append(": ").append(fileProperties.getImmutableAddress()).append("\n");
}
stringBuilder.append("\n");
}
String manifestString = stringBuilder.toString();
out.write(manifestString.getBytes());
out.closeEntry();
return manifestString;
}
use of org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry in project winery by eclipse.
the class CsarExporter method addSelfServiceFiles.
private void addSelfServiceFiles(ServiceTemplateId serviceTemplateId, Map<CsarContentProperties, CsarEntry> refMap) {
ServiceTemplateSelfServiceFilesDirectoryId selfServiceFilesDirectoryId = new ServiceTemplateSelfServiceFilesDirectoryId(serviceTemplateId);
repository.getContainedFiles(selfServiceFilesDirectoryId).forEach(repositoryFileReference -> {
String file = IdNames.SELF_SERVICE_PORTAL_FILES + "/" + BackendUtils.getFilenameAndSubDirectory(repositoryFileReference);
CsarContentProperties csarContentProperties = new CsarContentProperties(file);
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, repositoryFileReference));
});
}
use of org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry in project winery by eclipse.
the class ToscaExportUtil method putRefAsReferencedItemInCsar.
/**
* Puts the given reference as item in the CSAR
* <p>
* Thereby, it uses the global variable referencesToPathInCSARMap
*/
protected void putRefAsReferencedItemInCsar(IRepository repository, RepositoryFileReference ref) {
// Determine path
String pathInsideRepo = BackendUtils.getPathInsideRepo(ref);
// put mapping reference to path into global map
// the path is the same as put in "synchronizeReferences"
this.referencesToPathInCSARMap.put(new CsarContentProperties(pathInsideRepo), new RepositoryRefBasedCsarEntry(repository, ref));
}
Aggregations