use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class JsonBasedMultiNamespaceManager method loadNamespacePropertiesFromFile.
private Map<IRepository, Map<String, NamespaceProperties>> loadNamespacePropertiesFromFile() {
Map<IRepository, Map<String, NamespaceProperties>> result = new HashMap<>();
Map<String, NamespaceProperties> nsProps = new HashMap<>();
for (IRepository repo : this.repository.getRepositories()) {
RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId());
File file = repo.ref2AbsolutePath(ref).toFile();
try {
if (file.exists()) {
TypeReference<HashMap<String, NamespaceProperties>> hashMapTypeReference = new TypeReference<HashMap<String, NamespaceProperties>>() {
};
nsProps = JacksonProvider.mapper.readValue(file, hashMapTypeReference);
}
} catch (IOException e) {
LOGGER.debug("Error while loading the namespace file.", e);
throw new RuntimeException();
}
result.put(repo, nsProps);
}
return result;
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class CsarExporter method addLicenseAndReadmeFiles.
protected void addLicenseAndReadmeFiles(DefinitionsChildId entryId, Map<CsarContentProperties, CsarEntry> refMap) {
final RepositoryFileReference licenseRef = new RepositoryFileReference(entryId, Constants.LICENSE_FILE_NAME);
if (repository.exists(licenseRef)) {
refMap.put(new CsarContentProperties(BackendUtils.getPathInsideRepo(licenseRef)), new RepositoryRefBasedCsarEntry(repository, licenseRef));
}
final RepositoryFileReference readmeRef = new RepositoryFileReference(entryId, Constants.README_FILE_NAME);
if (repository.exists(readmeRef)) {
refMap.put(new CsarContentProperties(BackendUtils.getPathInsideRepo(readmeRef)), new RepositoryRefBasedCsarEntry(repository, readmeRef));
}
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class CsarExporter method addNamespacePrefixes.
/**
* Writes the configured mapping namespace prefix -> namespace to the archive
* <p>
* This is kind of a quick hack. TODO: during the import, the prefixes should be extracted using JAXB and stored in
* the NamespacesResource
*/
private void addNamespacePrefixes(Map<CsarContentProperties, CsarEntry> refMap) {
// ensure that the namespaces are saved as json
SortedSet<RepositoryFileReference> references = repository.getContainedFiles(new NamespacesId());
references.forEach(repositoryFileReference -> {
if (repositoryFileReference.getFileName().toLowerCase().endsWith(Constants.SUFFIX_JSON)) {
CsarContentProperties csarContentProperties = new CsarContentProperties(CsarExporter.PATH_TO_NAMESPACES_JSON);
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, repositoryFileReference));
}
});
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class CsarExporter method putRefIntoRefMap.
private void putRefIntoRefMap(String targetDir, Map<CsarContentProperties, CsarEntry> refMap, GenericId id, String fileName) {
RepositoryFileReference ref = new RepositoryFileReference(id, fileName);
if (repository.exists(ref)) {
CsarContentProperties csarContentProperties = new CsarContentProperties(targetDir + fileName);
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, ref));
} else {
CsarExporter.LOGGER.error("Data corrupt: pointing to non-existent file " + ref);
}
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class YamlToscaExportUtil method prepareServiceTemplateForExport.
/**
* Prepares artifacts in Service Template
*/
private void prepareServiceTemplateForExport(IRepository repository, ServiceTemplateId id, TDefinitions entryDefinitions) throws IOException {
BackendUtils.synchronizeReferences(id, repository);
TServiceTemplate st = repository.getElement(id);
String serviceTemplatePath = BackendUtils.getPathInsideRepo(id);
if (Objects.nonNull(st.getTopologyTemplate())) {
for (TNodeTemplate nodeTemplate : st.getTopologyTemplate().getNodeTemplates()) {
List<TArtifact> artifacts = nodeTemplate.getArtifacts();
if (Objects.nonNull(artifacts)) {
// update file paths in the exported service template
artifacts.forEach(a -> {
UrlValidator customValidator = new UrlValidator();
if (customValidator.isValid(a.getFile())) {
LOGGER.info("Specified file is a valid URL, start processing the reference");
try {
String templateArtifactPath = nodeTemplate.getId() + "/" + a.getName();
String pathInsideRepo = putRemoteRefAsReferencedItemInCsar(new URL(a.getFile()), serviceTemplatePath, templateArtifactPath);
updatePathsInTopologyTemplateArtifacts(entryDefinitions, nodeTemplate, a, pathInsideRepo);
} catch (MalformedURLException e) {
LOGGER.warn("Supplied URL is invalid: {}", e.getMessage());
}
} else {
Path p = Paths.get("files", nodeTemplate.getId(), a.getId());
RepositoryFileReference ref = new RepositoryFileReference(id, p, a.getFile());
try {
if (repository.exists(ref)) {
putRefAsReferencedItemInCsar(repository, ref);
String pathInsideRepo = BackendUtils.getPathInsideRepo(ref);
updatePathsInTopologyTemplateArtifacts(entryDefinitions, nodeTemplate, a, pathInsideRepo);
}
} catch (Exception e) {
LOGGER.warn("Could not add artifact reference: {}", e.getMessage());
}
}
});
// TODO: update "primary" field in the exported service template
}
}
}
}
Aggregations