protected File addFile(InputStream inputStream, File file) { uploadFile(inputStream, file); return catalogService.addFile(file); }
protected File addOrUpdateFile(Long fileId, InputStream inputStream, File file) { uploadFile(inputStream, file); return catalogService.addOrUpdateFile(fileId, file); }
/** * Downloads a given {@link File} resource for given {@code fileId} * * @param fileId */ @Timed @GET @Produces({"application/octet-stream", "application/json"}) @Path("/files/download/{fileId}") public Response downloadFile(@PathParam("fileId") Long fileId, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, READ, EXECUTE); File file = catalogService.getFile(fileId); if (file != null) { StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput(catalogService.downloadFileFromStorage(file.getStoredFileName())); return Response.ok(streamOutput).build(); } throw EntityNotFoundException.byId(fileId.toString()); }
/** * Deletes the file of given {@code fileId} * * @param fileId */ @DELETE @Path("/files/{id}") @Timed public Response removeFile(@PathParam("id") Long fileId, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, DELETE); try { File removedFile = catalogService.removeFile(fileId); SecurityUtil.removeAcl(authorizer, securityContext, File.NAMESPACE, fileId); log.info("Removed File entry is [{}]", removedFile); if (removedFile != null) { boolean removed = catalogService.deleteFileFromStorage(removedFile.getStoredFileName()); logDeletionMessage(removedFile.getStoredFileName(), removed); return WSUtils.respondEntity(removedFile, OK); } } catch (IOException ex) { log.error("Encountered error in removing file with id [{}]", fileId, ex); throw ex; } log.info("File entry with id [{}] is not found", fileId); throw EntityNotFoundException.byId(fileId.toString()); }
/** * * @param inputStream * @param contentDispositionHeader * @param file */ @Timed @PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/files/{id}") public Response updateFile(@PathParam("id") Long fileId, @FormDataParam("file") final InputStream inputStream, @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("fileInfo") final File file, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, WRITE); log.info("Received fileInfo: [{}]", file); String oldFileStorageName = null; final File existingFile = catalogService.getFile(fileId); if(existingFile != null) { oldFileStorageName = existingFile.getStoredFileName(); } final File updatedFile = addOrUpdateFile(fileId, inputStream, file); if(oldFileStorageName != null) { final boolean deleted = catalogService.deleteFileFromStorage(oldFileStorageName); logDeletionMessage(oldFileStorageName, deleted); } return WSUtils.respondEntity(updatedFile, CREATED); }
public File addOrUpdateFile(Long fileId, File file) { file.setId(fileId); file.setTimestamp(System.currentTimeMillis()); validateFileInfo(file); this.dao.addOrUpdate(file); return file; }
@GET @Path("/files/{id}") @Timed public Response getFile(@PathParam("id") Long fileId, @Context SecurityContext securityContext) { SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, READ); File result = catalogService.getFile(fileId); if (result != null) { return WSUtils.respondEntity(result, OK); } throw EntityNotFoundException.byId(fileId.toString()); }
@GET @Path("/files") @Timed public Response listFiles(@Context UriInfo uriInfo, @Context SecurityContext securityContext) { Collection<File> files = null; MultivaluedMap<String, String> params = uriInfo.getQueryParameters(); if (params == null || params.isEmpty()) { files = catalogService.listFiles(); } else { files = catalogService.listFiles(WSUtils.buildQueryParameters(params)); } Collection<File> result = SecurityUtil.filter(authorizer, securityContext, File.NAMESPACE, files, READ); return WSUtils.respondEntities(result, OK); }
private void uploadFile(InputStream inputStream, File file) { try { final String updatedFileStorageName = getFileStorageName(file.getName()); file.setStoredFileName(updatedFileStorageName); log.info("Uploading File with fileInfo [{}]", file); final String uploadedFileStoragePath = catalogService.uploadFileToStorage(inputStream, updatedFileStorageName); log.info("Received File with fileInfo is uploaded to [{}]", uploadedFileStoragePath); file.setTimestamp(System.currentTimeMillis()); } catch (IOException ex) { log.error("Got exception while uploading file"); throw new RuntimeException("Got exception while uploading file", ex); } }
final EnvironmentService environmentService = new EnvironmentService(storageManager); TagClient tagClient = new TagClient(catalogRootUrl); final CatalogService catalogService = new CatalogService(storageManager, fileStorage, tagClient); final TopologyActionsService topologyActionsService = new TopologyActionsService(streamcatalogService, environmentService, fileStorage, modelRegistryClient, config, subject, transactionManager);
public File addFile(File file) { if (file.getId() == null) { file.setId(dao.nextId(FILE_NAMESPACE)); } if (file.getTimestamp() == null) { file.setTimestamp(System.currentTimeMillis()); } validateFileInfo(file); dao.addOrUpdate(file); return file; }