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 @@ -1051,7 +1051,7 @@ public String getEmployeeByDesignation(@RequestBody String getDesignation) {

ArrayList<M_User1> employeeBydesiganation = employeeMasterInter.getEmployeeByDesiganationID(
employeeMaster.getDesignationID(), employeeMaster1.getServiceProviderID());

response.setResponse(employeeBydesiganation.toString());

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,33 @@
*/
package com.iemr.admin.controller.employeemaster;

import java.net.URLEncoder;
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;
import jakarta.servlet.http.HttpServletRequest;


@PropertySource("classpath:application.properties")
Expand All @@ -54,12 +59,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,22 +86,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 cd = ContentDisposition.attachment()
.filename(userSignID.getFileName(), StandardCharsets.UTF_8).build();
responseHeaders.setContentDisposition(cd);

MediaType mediaType;
try {
mediaType = MediaType.parseMediaType(userSignID.getFileType());
} catch (InvalidMediaTypeException | NullPointerException e) {
mediaType = MediaType.APPLICATION_OCTET_STREAM;
}
byte[] fileBytes = userSignID.getSignature(); // MUST be byte[]
return ResponseEntity.ok().headers(responseHeaders).contentType(mediaType).contentLength(fileBytes.length)
.body(fileBytes);
} catch (Exception e) {
logger.error("Unexpected error:", e);
logger.error("File download for userID failed with exception " + e.getMessage(), e);
Expand Down Expand Up @@ -128,4 +136,19 @@ public String existFile(@PathVariable("userID") Long userID) throws Exception {
logger.debug("response" + response);
return response.toString();
}
}

@Operation(summary = "Active or DeActive user Signature")
@PostMapping(value = "/activateOrdeActivateSignature", headers = "Authorization", produces = { "application/json" })
public String ActivateUser(@RequestBody String activateUser, HttpServletRequest request) {
OutputResponse response = new OutputResponse();
try {
EmployeeSignature empSignature = employeeSignatureServiceImpl.updateUserSignatureStatus(activateUser);
boolean active = empSignature.getDeleted() == null ? false : !empSignature.getDeleted();
response.setResponse("{\"userID\":" + empSignature.getUserID() + ",\"active\":" + active + "}");
} catch (Exception e) {
logger.error("Active or Deactivate User Signature failed with exception " + e.getMessage(), e);
response.setError(e);
}
return response.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.iemr.admin.data.employeemaster.EmployeeSignature;
import com.iemr.admin.repo.employeemaster.EmployeeSignatureRepo;
import org.json.JSONObject;

@Service
public class EmployeeSignatureServiceImpl implements EmployeeSignatureService {
Expand Down Expand Up @@ -67,4 +68,17 @@ public Boolean existSignature(Long userID) {
return employeeSignatureRepo.countByUserIDAndSignatureNotNull(userID)>0;
}

@Override
public EmployeeSignature updateUserSignatureStatus(String activateUser) {
JSONObject obj = new JSONObject(activateUser);
Long userID = obj.getLong("userID");
// String role = obj.getString("role");
boolean active = obj.getBoolean("active");
EmployeeSignature signature = employeeSignatureRepo.findOneByUserID(userID);
if (signature == null) {
throw new IllegalArgumentException("No signature found for userID: " + userID);
}
signature.setDeleted(!active);
return employeeSignatureRepo.save(signature);
}
}