use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class CsarImporter method importIcon.
void importIcon(VisualAppearanceId visId, Path visPath, String fileName, TOSCAMetaFile tmf, Path rootPath, final List<String> errors) {
Path file = visPath.resolve(fileName);
if (Files.exists(file)) {
RepositoryFileReference ref = new RepositoryFileReference(visId, fileName);
importFile(file, ref, tmf, rootPath, errors);
}
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class YamlCsarImporter method importArtifact.
private void importArtifact(Path rootPath, TArtifact a, DirectoryId artifactDir, TOSCAMetaFile tmf, final List<String> errors) {
String fileName = rootPath.resolve(a.getFile()).getFileName().toString();
RepositoryFileReference ref = new RepositoryFileReference(artifactDir, fileName);
importFile(rootPath.resolve(a.getFile()), ref, tmf, rootPath, errors);
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class YamlCsarImporter method storeDefs.
private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
IRepository repo = RepositoryFactory.getRepository();
FromCanonical converter = null;
if (repo instanceof GitBasedRepository) {
GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
converter = new FromCanonical((YamlRepository) wrapper.getRepository());
} else if (repo instanceof YamlRepository) {
converter = new FromCanonical((YamlRepository) repo);
}
if (Objects.nonNull(converter)) {
YamlWriter writer = new YamlWriter();
writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
}
}
use of org.eclipse.winery.repository.common.RepositoryFileReference 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.common.RepositoryFileReference in project container by OpenTOSCA.
the class WineryExporter method getEntryDefs.
private org.eclipse.winery.model.tosca.TDefinitions getEntryDefs(Csar csar, IRepository repo) {
Collection<RepositoryFileReference> entryDefRefs = new HashSet<RepositoryFileReference>();
entryDefRefs.addAll(repo.getContainedFiles(new ServiceTemplateId(new QName(csar.entryServiceTemplate().getTargetNamespace(), csar.entryServiceTemplate().getId()))));
for (RepositoryFileReference ref : entryDefRefs) {
if (ref.getFileName().endsWith(".tosca")) {
try {
return repo.definitionsFromRef(ref);
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
Aggregations