use of org.eclipse.winery.repository.rest.resources.apiData.ArtifactResourcesApiData in project winery by eclipse.
the class ArtifactTemplateResource method copySourceToFilesResource.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response copySourceToFilesResource(@ApiParam(value = "if data contains a non-empty array than only the files" + " whose names are included are copied ", required = true) ArtifactResourcesApiData data) {
List<String> artifactList = data.getArtifactNames();
DirectoryId sourceDir = new ArtifactTemplateSourceDirectoryId((ArtifactTemplateId) this.id);
FilesResource filesResource = getFilesResource();
for (RepositoryFileReference ref : RepositoryFactory.getRepository().getContainedFiles(sourceDir)) {
if (artifactList == null || artifactList.contains(ref.getFileName())) {
try (InputStream inputStream = RepositoryFactory.getRepository().newInputStream(ref)) {
String fileName = ref.getFileName();
String subDirectory = ref.getSubDirectory().map(s -> s.toString()).orElse("");
filesResource.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();
}
Aggregations