2121*/
2222package com .iemr .admin .controller .employeemaster ;
2323
24+ import java .net .URLEncoder ;
25+ import java .nio .charset .StandardCharsets ;
2426import java .util .Base64 ;
2527
2628import org .slf4j .Logger ;
2729import org .slf4j .LoggerFactory ;
2830import org .springframework .beans .factory .annotation .Autowired ;
2931import org .springframework .context .annotation .PropertySource ;
32+ import org .springframework .http .ContentDisposition ;
3033import org .springframework .http .HttpHeaders ;
34+ import org .springframework .http .InvalidMediaTypeException ;
3135import org .springframework .http .MediaType ;
3236import org .springframework .http .ResponseEntity ;
33-
37+ import org . springframework . web . bind . annotation . GetMapping ;
3438import org .springframework .web .bind .annotation .PathVariable ;
39+ import org .springframework .web .bind .annotation .PostMapping ;
3540import org .springframework .web .bind .annotation .RequestBody ;
3641import org .springframework .web .bind .annotation .RequestMapping ;
3742import org .springframework .web .bind .annotation .RequestMethod ;
3843import org .springframework .web .bind .annotation .RestController ;
3944
4045import com .iemr .admin .data .employeemaster .EmployeeSignature ;
4146import com .iemr .admin .service .employeemaster .EmployeeSignatureServiceImpl ;
42- import com .iemr .admin .utils .mapper .InputMapper ;
4347import com .iemr .admin .utils .response .OutputResponse ;
4448
4549import io .swagger .v3 .oas .annotations .Operation ;
50+ import jakarta .servlet .http .HttpServletRequest ;
4651
4752
4853@ PropertySource ("classpath:application.properties" )
@@ -54,12 +59,10 @@ public class EmployeeSignatureController {
5459 @ Autowired
5560 EmployeeSignatureServiceImpl employeeSignatureServiceImpl ;
5661
57- private InputMapper inputMapper = new InputMapper ();
58-
5962 private Logger logger = LoggerFactory .getLogger (this .getClass ().getSimpleName ());
6063
6164 @ Operation (summary = "Upload" )
62- @ RequestMapping (value = "/upload" , headers = "Authorization" , method = { RequestMethod . POST } , produces = {
65+ @ PostMapping (value = "/upload" , headers = "Authorization" , produces = {
6366 "application/json" })
6467 public String uploadFile (@ RequestBody EmployeeSignature emp ) {
6568 OutputResponse response = new OutputResponse ();
@@ -83,22 +86,27 @@ public String uploadFile(@RequestBody EmployeeSignature emp) {
8386 }
8487
8588 @ Operation (summary = "User id" )
86- @ RequestMapping (value = "/{userID}" , headers = "Authorization" , method = { RequestMethod . GET } )
89+ @ GetMapping (value = "/{userID}" , headers = "Authorization" )
8790 public ResponseEntity <byte []> fetchFile (@ PathVariable ("userID" ) Long userID ) throws Exception {
88- OutputResponse response = new OutputResponse ();
8991 logger .debug ("File download for userID" + userID );
9092
9193 try {
9294
9395 EmployeeSignature userSignID = employeeSignatureServiceImpl .fetchSignature (userID );
9496 HttpHeaders responseHeaders = new HttpHeaders ();
95- responseHeaders .set (HttpHeaders .CONTENT_DISPOSITION ,
96- "inline; filename=\" " + userSignID .getFileName () + "\" " );
97- responseHeaders .set ("filename" , userSignID .getFileName ());
98-
99- return ResponseEntity .ok ().contentType (MediaType .parseMediaType (userSignID .getFileType ()))
100- .headers (responseHeaders ).body (userSignID .getSignature ());
101-
97+ ContentDisposition cd = ContentDisposition .attachment ()
98+ .filename (userSignID .getFileName (), StandardCharsets .UTF_8 ).build ();
99+ responseHeaders .setContentDisposition (cd );
100+
101+ MediaType mediaType ;
102+ try {
103+ mediaType = MediaType .parseMediaType (userSignID .getFileType ());
104+ } catch (InvalidMediaTypeException | NullPointerException e ) {
105+ mediaType = MediaType .APPLICATION_OCTET_STREAM ;
106+ }
107+ byte [] fileBytes = userSignID .getSignature (); // MUST be byte[]
108+ return ResponseEntity .ok ().headers (responseHeaders ).contentType (mediaType ).contentLength (fileBytes .length )
109+ .body (fileBytes );
102110 } catch (Exception e ) {
103111 logger .error ("Unexpected error:" , e );
104112 logger .error ("File download for userID failed with exception " + e .getMessage (), e );
@@ -128,4 +136,19 @@ public String existFile(@PathVariable("userID") Long userID) throws Exception {
128136 logger .debug ("response" + response );
129137 return response .toString ();
130138 }
131- }
139+
140+ @ Operation (summary = "Active or DeActive user Signature" )
141+ @ PostMapping (value = "/activateOrdeActivateSignature" , headers = "Authorization" , produces = { "application/json" })
142+ public String ActivateUser (@ RequestBody String activateUser , HttpServletRequest request ) {
143+ OutputResponse response = new OutputResponse ();
144+ try {
145+ EmployeeSignature empSignature = employeeSignatureServiceImpl .updateUserSignatureStatus (activateUser );
146+ boolean active = empSignature .getDeleted () == null ? false : !empSignature .getDeleted ();
147+ response .setResponse ("{\" userID\" :" + empSignature .getUserID () + ",\" active\" :" + active + "}" );
148+ } catch (Exception e ) {
149+ logger .error ("Active or Deactivate User Signature failed with exception " + e .getMessage (), e );
150+ response .setError (e );
151+ }
152+ return response .toString ();
153+ }
154+ }
0 commit comments