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 ArtifactTemplateFilesResource method copySourceToFiles.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response copySourceToFiles(@ApiParam(value = "if data contains a non-empty array than only the files" + " whose names are included are copied ", required = true) ArtifactResourcesApiData data) {
if (Objects.isNull(this.destinationDir)) {
return Response.status(Status.BAD_REQUEST).build();
}
List<String> artifactList = data.getArtifactNames();
for (RepositoryFileReference ref : RepositoryFactory.getRepository().getContainedFiles(this.fileDir)) {
if (artifactList == null || artifactList.contains(ref.getFileName())) {
try (InputStream inputStream = RepositoryFactory.getRepository().newInputStream(ref)) {
String fileName = ref.getFileName();
String subDirectory = ref.getSubDirectory().map(java.nio.file.Path::toString).orElse("");
this.destinationDir.putFile(fileName, subDirectory, inputStream);
} catch (IOException e) {
LOGGER.debug("The artifact source " + ref.getFileName() + " could not be copied to the files directory.", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}
}
return Response.status(Status.CREATED).build();
}
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 winery by eclipse.
the class ToscaExportUtil method prepareForExport.
/**
* Synchronizes the plan model references and adds the plans to the csar (putRefAsReferencedItemInCsar)
*/
private void prepareForExport(IRepository repository, ServiceTemplateId id) throws IOException {
// ensure that the plans stored locally are the same ones as stored in the definitions
BackendUtils.synchronizeReferences(id, repository);
// add all plans as reference in the CSAR
// the data model is consistent with the repository
// we crawl through the repository to as putRefAsReferencedItemInCsar expects a repository file reference
PlansId plansContainerId = new PlansId(id);
SortedSet<PlanId> nestedPlans = repository.getNestedIds(plansContainerId, PlanId.class);
for (PlanId planId : nestedPlans) {
SortedSet<RepositoryFileReference> containedFiles = repository.getContainedFiles(planId);
// even if we currently support only one file in the directory, we just add everything
for (RepositoryFileReference ref : containedFiles) {
putRefAsReferencedItemInCsar(repository, ref);
}
}
}
Aggregations