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
}
}
}
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "file.txt"), artifactTemplateSourceDirectoryId);
assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
assertEquals(Optional.empty(), repositoryFileReference.getSubDirectory());
assertEquals("file.txt", repositoryFileReference.getFileName());
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final Path subDirectories = Paths.get("d1", "d2");
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "d1", "d2", "file.txt"), artifactTemplateSourceDirectoryId);
assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
assertEquals(Optional.of(subDirectories), repositoryFileReference.getSubDirectory());
assertEquals("file.txt", repositoryFileReference.getFileName());
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionWithEditableFlagAndChangesInAFileWhichIsNotTheToscaFile.
@Test
public void getVersionWithEditableFlagAndChangesInAFileWhichIsNotTheToscaFile() throws Exception {
this.setRevisionTo("origin/plain");
NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
// Make some changes to an associated file
RepositoryFileReference ref = new RepositoryFileReference(id, EncodingUtil.URLdecode("README.md"));
RepositoryFactory.getRepository().putContentToFile(ref, "someUnguessableContent", MediaType.TEXT_PLAIN);
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
assertTrue(versions.get(0).isEditable());
List<WineryVersion> collect = versions.stream().filter(item -> !item.isEditable()).collect(Collectors.toList());
assertEquals(4, collect.size());
}
Aggregations