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.oneconsult.seoc.api.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;

import gov.va.oneconsult.seoc.api.model.Seoc;
import gov.va.oneconsult.seoc.api.serializer.SeocExternalSerializer;
import gov.va.oneconsult.seoc.api.serializer.StringSerializer;
import gov.va.oneconsult.seoc.api.service.SeocService;
import gov.va.oneconsult.seoc.api.util.Constants;
import gov.va.oneconsult.seoc.api.util.EncodeLoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
* RestController for Seoc
* <p>
* Provides SEOC Services to external systems
* </p>
*
* @author AbleVets
* @version 1.0
*/
@RestController
@CrossOrigin
@RequestMapping(value = Constants.ROOT_SEOC_V2)
@Api(value = "ExternalSeocController")
public class ExternalSeocController
{
/**
* {@link SeocService}
*/
@Autowired
private SeocService seocService;

public static final Logger logger = EncodeLoggerFactory.getLogger(ExternalSeocController.class);

private static ObjectMapper seocToolBoxMapper = new ObjectMapper();
private static SimpleModule seocToolBoxModule = new SimpleModule("SeocExternalSerializer",
new Version(1, 0, 0, null, null, null));

private static ObjectMapper seocExternalMapper = new ObjectMapper();
private static SimpleModule seocExternalModule = new SimpleModule("SeocExternalSerializer",
new Version(1, 0, 0, null, null, null));

private static SeocExternalSerializer toolBoxSerializer = new SeocExternalSerializer();
private static SeocExternalSerializer externalSerializer = new SeocExternalSerializer();



static {
List<Seoc> seocsList = new ArrayList<Seoc>();
toolBoxSerializer.setExternalSystem(Constants.TOOLBOX_V2);
seocToolBoxModule.addSerializer((Class<List<Seoc>>) seocsList.getClass(), toolBoxSerializer);
seocToolBoxModule.addSerializer((Class<String>) String.class, new StringSerializer());
seocToolBoxMapper.registerModule(seocToolBoxModule);

externalSerializer.setExternalSystem(Constants.HSRM_V2);
seocExternalModule.addSerializer((Class<List<Seoc>>) seocsList.getClass(), externalSerializer);
seocExternalModule.addSerializer((Class<String>) String.class, new StringSerializer());
seocExternalMapper.registerModule(seocExternalModule);
}

@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
binder.setDisallowedFields();
}

/**
* Description: Read all Active Seocs
*
* @return Returns {@link ResponseEntity} with the list of {@link Seoc} objects
* and status of the response
*/
@ApiOperation(value = "readAllActiveSeocs", notes = "Get all active Seocs", nickname = "getActiveSeocs")
@ApiResponses(value = { @ApiResponse(code = 204, message = "No Content Found"),
@ApiResponse(code = 200, message = "Successful retrieval", response = SeocController.class, responseContainer = "List") })
@RequestMapping(value = "/active", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<String> readAllActiveSeocs() {

logger.info("Obtaining all active seocs");

List<Seoc> seocList = seocService.getActiveSeocs();

try {
if (!seocList.isEmpty()) {
String result = seocToolBoxMapper.writeValueAsString(seocList);

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return new ResponseEntity<String>(result, headers, HttpStatus.OK);
} else {// "204 No Content"

logger.error("No seoc available");
return new ResponseEntity<String>("No seoc available", HttpStatus.NO_CONTENT);
}
} catch (JsonProcessingException e) {
logger.error("Json Exception occured in retreiving active SEOC data." + e.getMessage());
return new ResponseEntity<String>("Exception occured generating JSON", HttpStatus.NO_CONTENT);
}
}


/**
* Description: Read all Active/Discontinued Seocs
*
* @return Returns {@link ResponseEntity} with the list of {@link Seoc} objects
* and status of the response
*/
@ApiOperation(value = "readPublishedSeocs", notes = "Get all date hold, active, or discontinued Seocs", nickname = "getPublishedSeocs")
@ApiResponses(value = { @ApiResponse(code = 204, message = "No Content Found"),
@ApiResponse(code = 200, message = "Successful retrieval", response = SeocController.class, responseContainer = "List") })
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<String> readAllConditionSeocs() {

logger.info("Obtaining all Date Hold, Active, or Discontinued seocs");

List<Seoc> seocList = seocService.getPublishedSeocs();
try {
if (!seocList.isEmpty()) {
String result = seocExternalMapper.writeValueAsString(seocList);

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return new ResponseEntity<String>(result, headers, HttpStatus.OK);
} else {// "204 No Content"

logger.error("No seoc available");
return new ResponseEntity<String>("No seoc available", HttpStatus.NO_CONTENT);
}
} catch (JsonProcessingException e) {
logger.error("Json Exception occured in retreiving published SEOC data." + e.getMessage());
return new ResponseEntity<String>("Exception occured generating JSON", HttpStatus.NO_CONTENT);
}
}

}