Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.ewv.controller;
import java.util.AbstractMap.SimpleEntry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.RestController;
import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.ars.model.request.UserSearchRequest;
import gov.va.med.ars.service.IUserAdminService;
import net.minidev.json.JSONObject;
@RestController
@RequestMapping("/api/v1/ewv/admin")
public class EwvUserAdminController {
private static final Logger logger = LogManager.getLogger(EwvUserAdminController.class);
@Autowired
private IUserAdminService userAdminService;
@PostMapping("/createUser")
public ResponseEntity<JSONObject> createUser(@RequestBody UserSearchRequest request)
throws GenericException {
SimpleEntry <String,Boolean> resultPair;
JSONObject entity = new JSONObject();
try {
resultPair = userAdminService.createUser(request);
if(resultPair.getValue()) {
entity.put(resultPair.getKey(), resultPair.getValue());
return new ResponseEntity<>(entity, HttpStatus.CREATED);
} else {
entity.put("errorCode","Error in creating user");
entity.put("message", resultPair.getKey());
return new ResponseEntity<>(entity, HttpStatus.BAD_REQUEST);
}
} catch (GenericException e) {
logger.debug("Unable to Create User" + e);
entity.put("errorCode","Error in creating user");
entity.put("message","Please try again");
return new ResponseEntity<>(entity, HttpStatus.BAD_REQUEST);
}
}
}