Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@
*/
package com.iemr.admin.controller.employeemaster;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.InvalidMediaTypeException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.iemr.admin.data.employeemaster.EmployeeSignature;
import com.iemr.admin.service.employeemaster.EmployeeSignatureServiceImpl;
import com.iemr.admin.utils.mapper.InputMapper;
import com.iemr.admin.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -54,12 +57,10 @@ public class EmployeeSignatureController {
@Autowired
EmployeeSignatureServiceImpl employeeSignatureServiceImpl;

private InputMapper inputMapper = new InputMapper();

private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

@Operation(summary = "Upload")
@RequestMapping(value = "/upload", headers = "Authorization", method = { RequestMethod.POST }, produces = {
@PostMapping(value = "/upload", headers = "Authorization", produces = {
"application/json" })
public String uploadFile(@RequestBody EmployeeSignature emp) {
OutputResponse response = new OutputResponse();
Expand All @@ -83,21 +84,27 @@ public String uploadFile(@RequestBody EmployeeSignature emp) {
}

@Operation(summary = "User id")
@RequestMapping(value = "/{userID}", headers = "Authorization", method = { RequestMethod.GET })
@GetMapping(value = "/{userID}", headers = "Authorization")
public ResponseEntity<byte[]> fetchFile(@PathVariable("userID") Long userID) throws Exception {
OutputResponse response = new OutputResponse();
logger.debug("File download for userID" + userID);

try {

EmployeeSignature userSignID = employeeSignatureServiceImpl.fetchSignature(userID);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.CONTENT_DISPOSITION,
"inline; filename=\"" + userSignID.getFileName() + "\"");
responseHeaders.set("filename", userSignID.getFileName());

return ResponseEntity.ok().contentType(MediaType.parseMediaType(userSignID.getFileType()))
.headers(responseHeaders).body(userSignID.getSignature());
ContentDisposition contentDisposition = ContentDisposition.attachment()
.filename(userSignID.getFileName(), StandardCharsets.UTF_8).build();
responseHeaders.setContentDisposition(contentDisposition);

MediaType mediaType;
try {
mediaType = MediaType.parseMediaType(userSignID.getFileType());
} catch (InvalidMediaTypeException | NullPointerException ex) {
mediaType = MediaType.APPLICATION_OCTET_STREAM;
}

return ResponseEntity.ok().contentType(mediaType).headers(responseHeaders)
.contentLength(userSignID.getSignature().length).body(userSignID.getSignature());

} catch (Exception e) {
logger.error("Unexpected error:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.iemr.admin.data.user.M_User;

@Repository
public interface UserLoginRepo extends CrudRepository<M_User, Long> {
public interface UserLoginRepo extends CrudRepository<M_User, Integer> {

@Query(" SELECT u FROM M_User u WHERE u.userID = :userID AND u.Deleted = false ")
public M_User getUserByUserID(@Param("userID") Long userID);
Expand Down