Skip to content

Commit

Permalink
Remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszkononowicz committed Dec 1, 2018
1 parent 63eb31e commit 676195b
Showing 1 changed file with 1 addition and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,75 +61,7 @@ public class AttachmentControler extends MainController {
@Value("${attachments.directory:/home/attachments/}")
private String attachmentsDirectory;

// @PostMapping(path = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
// @PreAuthorize("@securityService.isCollaborator(#request, #projectId)")
// public ResponseEntity upload(
// @RequestParam("File") MultipartFile multipartFile,
// @RequestParam("Type") String type,
// @RequestParam("ProjectId") String projectId,
// @RequestParam("Visibility") String visibility,
// @RequestParam("MainPhoto") String mainPhoto,
// HttpServletRequest request) {
//
// if (multipartFile.getSize() < MAX_ATTACHMENT_SIZE_IN_BYTES) {
// Attachment attachment = new Attachment();
//
// try {
// Project project = super.projectRepository.getOne(Long.parseLong(projectId));
// String filename = new File(multipartFile.getOriginalFilename()).getName();
// attachment.setFileName(filename);
// attachment.setFileSize(multipartFile.getSize());
// attachment.setType(AttachmentType.valueOf(type));
// attachment.setProject(project);
// attachment.setVisibility(Visibility.valueOf(visibility));
// attachment.setMainPhoto(Boolean.parseBoolean(mainPhoto));
// } catch (NumberFormatException ex) {
// return ExceptionHandlingUtils.handleException(ex);
// }
//
// try {
// attachment = attachmentRepository.saveAndFlush(attachment);
// } catch (Exception ex) {
// attachmentService.rollbackSaveAttachment(attachment);
// return ExceptionHandlingUtils.handleException(ex);
// }
//
// try {
// log.info("SAVED ATTACHMENT WITH ID " + attachment.getId() + ", FILE SIZE = " + attachment.getFileSize());
// DataSource ds = (DataSource) appContext.getBean("dataSource");
// String insertQuery = "INSERT INTO `attachments_files` (attachments_id, file) VALUES (?, ?)";
//
// try (
// Connection connection = ds.getConnection();
// PreparedStatement preparedStatement = connection.prepareStatement(insertQuery)
// ) {
//
// preparedStatement.setLong(1, attachment.getId());
// preparedStatement.setBlob(2, multipartFile.getInputStream(), attachment.getFileSize());
// int affectedRows = preparedStatement.executeUpdate();
// if (affectedRows == 0) {
// log.info("ERROR: affectedRows = 0");
// return new ResponseEntity<>("ERROR: PREPARED STATEMENT AFFECTED 0 ROWS", HttpStatus.EXPECTATION_FAILED);
// }
// log.info("EVERYTHING OK! SAVED " + affectedRows + " ROWS!");
// }
// } catch (Error ex) {
// attachmentService.rollbackSaveAttachment(attachment);
// log.info("Error: " + ex.getMessage());
// return ExceptionHandlingUtils.handleException(ex);
// } catch (Exception ex) {
// attachmentService.rollbackSaveAttachment(attachment);
// log.info("Exception: " + ex.getMessage());
// return ExceptionHandlingUtils.handleException(ex);
// }
//
// return new ResponseEntity<>(HttpStatus.OK);
// } else {
// String error = "Plik nie może być większy niż " + MAX_ATTACHMENT_SIZE_IN_BYTES + " MB.";
// log.info("Błąd. " + error);
// return new ResponseEntity(error, HttpStatus.BAD_REQUEST);
// }
// }


@PostMapping(path = "/updateMetadata")
@PreAuthorize("@securityService.isCollaborator(#request, #projectId)")
Expand All @@ -146,22 +78,6 @@ public ResponseEntity updateMetadata(
attachmentRepository.save(attachment);
return new ResponseEntity(HttpStatus.OK);
}

// @PostMapping(path = "/remove")
// @PreAuthorize("@securityService.isCollaborator(#request, #projectId)")
// public ResponseEntity removeAttachment(@RequestBody List<Long> attachmentsToRemove,
// @RequestParam("projectId") long projectId,
// HttpServletRequest request) {
// try {
// for (Long a : attachmentsToRemove) {
// attachmentFileRepository.deleteById(a);
// attachmentRepository.deleteById(a);
// }
// } catch (Exception ex) {
// return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
// }
// return new ResponseEntity<>(HttpStatus.OK);
// }

@PostMapping(path = "/remove")
@PreAuthorize("@securityService.isCollaborator(#request, #projectId)")
Expand All @@ -178,41 +94,6 @@ public ResponseEntity removeAttachment(@RequestBody List<Long> attachmentsToRemo
}
return new ResponseEntity<>(HttpStatus.OK);
}

// @GetMapping(path = "/download")
// @PreAuthorize("@visibilityService.checkAttachmentVisibility(#request, #id)")
// public ResponseEntity downloadAttachment(@RequestParam("id") long id,
// HttpServletResponse response,
// HttpServletRequest request) {
// Optional<AttachmentFile> attachmentFile = attachmentFileRepository.findById(id);
// Optional<Attachment> attachment = attachmentRepository.findById(id);
// if (attachmentService.attachmentExists(attachmentFile, attachment)) {
// try {
// attachmentService.prepareAndSaveAttachment(attachment, attachmentFile, response);
// return new ResponseEntity<>(HttpStatus.OK);
// } catch (Exception ex) {
// return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
// }
// }
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
// }

// @GetMapping(path = "/downloadPhoto")
// @PreAuthorize("@visibilityService.checkAttachmentVisibility(#request, #id)")
// public ResponseEntity downloadPhoto(@RequestParam("id") long id,
// HttpServletResponse response,
// HttpServletRequest request) {
// Optional<AttachmentFile> attachmentFile = attachmentFileRepository.findById(id);
// Optional<Attachment> attachment = attachmentRepository.findById(id);
// if (attachmentService.attachmentExists(attachmentFile, attachment) && attachment.get().getType() == AttachmentType.PHOTO) {
// try {
// attachmentService.prepareAndSaveAttachment(attachment, attachmentFile, response);
// } catch (Exception ex) {
// return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
// }
// }
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
// }

@PostMapping(path = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PreAuthorize("@securityService.isCollaborator(#request, #projectId)")
Expand Down

0 comments on commit 676195b

Please sign in to comment.