Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add active flag, make biometrics APIs with Auth #30

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
@@ -1,33 +1,28 @@
package com.iemr.hwc.controller.wo;
package com.iemr.hwc.controller.userBiomectrics;

import com.google.gson.Gson;
import com.iemr.hwc.controller.common.master.CommonMasterController;
import com.iemr.hwc.data.registrar.FingerPrintDTO;
import com.iemr.hwc.data.registrar.UserBiometricsMapping;
import com.iemr.hwc.service.location.LocationServiceImpl;
import com.iemr.hwc.service.registrar.RegistrarServiceImpl;
import com.iemr.hwc.utils.response.OutputResponse;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping(value = "wo/user_biometrics")
@RequestMapping(value = "/user_biometrics", headers = "Authorization")
public class UserBiomectrics {
// private OutputResponse response;
private Logger logger = LoggerFactory.getLogger(CommonMasterController.class);

@Autowired
private RegistrarServiceImpl registrarService;
@CrossOrigin()
@ApiOperation(value = "add fingerprint for a given username", consumes = "application/json", produces = "application/json")
@RequestMapping(value = "add/fingerprint/wo", method = { RequestMethod.POST }, produces = {
@RequestMapping(value = "add/fingerprint", method = { RequestMethod.POST }, produces = {
"application/json" })
public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) {
OutputResponse response = new OutputResponse();
Expand All @@ -40,6 +35,9 @@ public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) {
else if(resp !=null && resp.equals("ko")){
response.setError(500, "Error adding fingerprints");
}
else if(resp !=null && resp.equals("fingerprint_already_added")){
response.setError(210, "Fingerprints already added");
}
} else {
response.setError(400, "Invalid request");
}
Expand All @@ -51,7 +49,7 @@ else if(resp !=null && resp.equals("ko")){
}

@ApiOperation(value = "Get fingerprint by username", consumes = "application/json", produces = "application/json")
@RequestMapping(value = "/get/fingerprint/{userID}/wo", method = RequestMethod.GET)
@RequestMapping(value = "/get/fingerprint/{userID}", method = RequestMethod.GET)
public String getFingerprintsByUsername(@PathVariable("userID") Long userID) {
logger.info("Get fingerprint by username ..." + userID);
OutputResponse response = new OutputResponse();
Expand All @@ -68,6 +66,7 @@ public String getFingerprintsByUsername(@PathVariable("userID") Long userID) {
userBiometricsMapping.setRightIndexFinger(user.getRightIndexFinger());
userBiometricsMapping.setLeftThumb(user.getLeftThumb());
userBiometricsMapping.setLeftIndexFinger(user.getLeftIndexFinger());
userBiometricsMapping.setActive(user.getActive());

response.setResponse(gson.toJson(userBiometricsMapping));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ public class UserBiometricsMapping {
@Column(name = "left_index_finger")
private String leftIndexFinger;

@Column(name = "active")
@Expose
private Boolean active;

}
Original file line number Diff line number Diff line change
Expand Up @@ -845,24 +845,29 @@ public int searchAndSubmitBeneficiaryToNurse(String requestOBJ) throws Exception
public String saveFingerprints(FingerPrintDTO comingRequest) {
String response = "";
Users user = userRepo.getUserByUsername(comingRequest.getUserName());
if(user !=null){
UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping();
userBiometricsMapping.setUserID(user.getUserID());
userBiometricsMapping.setFirstName(user.getFirstName());
userBiometricsMapping.setLastName(user.getLastName());
userBiometricsMapping.setUserName(user.getUserName());
userBiometricsMapping.setCreatedBy(user.getUserName());
userBiometricsMapping.setRightThumb(comingRequest.getRightThumb());
userBiometricsMapping.setRightIndexFinger(comingRequest.getRightIndexFinger());
userBiometricsMapping.setLeftThumb(comingRequest.getLeftThumb());
userBiometricsMapping.setLeftIndexFinger(comingRequest.getLeftIndexFinger());

UserBiometricsMapping resp = userBiometricsRepo.save(userBiometricsMapping);
if(resp !=null){
response = "ok";
}
else{
response = "ko";
if(user !=null) {
UserBiometricsMapping userBiomectric = userBiometricsRepo.getFingerprintsByUserID(user.getUserID());
if (userBiomectric == null || (userBiomectric != null && userBiomectric.getActive() == false)) { // If the user don't have fingerprint yet, otherwise check if active equals false
UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping();
userBiometricsMapping.setUserID(user.getUserID());
userBiometricsMapping.setFirstName(user.getFirstName());
userBiometricsMapping.setLastName(user.getLastName());
userBiometricsMapping.setUserName(user.getUserName());
userBiometricsMapping.setCreatedBy(user.getUserName());
userBiometricsMapping.setRightThumb(comingRequest.getRightThumb());
userBiometricsMapping.setRightIndexFinger(comingRequest.getRightIndexFinger());
userBiometricsMapping.setLeftThumb(comingRequest.getLeftThumb());
userBiometricsMapping.setLeftIndexFinger(comingRequest.getLeftIndexFinger());
userBiometricsMapping.setActive(true);

UserBiometricsMapping resp = userBiometricsRepo.save(userBiometricsMapping);
if (resp != null) {
response = "ok";
} else {
response = "ko";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the string ko.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change done @roopesh-beehyv

} else {
response = "fingerprint_already_added";
}
}
else{
Expand Down