use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse in project SORMAS-Project by hzi-braunschweig.
the class ExternalSurveillanceToolGatewayFacadeEjb method sendRequest.
private void sendRequest(ExportParameters params) throws ExternalSurveillanceToolException {
String serviceUrl = configFacade.getExternalSurveillanceToolGatewayUrl().trim();
Response response = ClientBuilder.newBuilder().connectTimeout(30, TimeUnit.SECONDS).build().target(serviceUrl).path("export").request().post(Entity.json(params));
int status = response.getStatus();
switch(status) {
case HttpServletResponse.SC_OK:
case HttpServletResponse.SC_NO_CONTENT:
if (params.getCaseUuids() != null) {
caseService.getByUuids(params.getCaseUuids()).forEach(caze -> shareInfoService.createAndPersistShareInfo(caze, ExternalShareStatus.SHARED));
}
if (params.getEventUuids() != null) {
eventService.getByUuids(params.getEventUuids()).forEach(event -> shareInfoService.createAndPersistShareInfo(event, ExternalShareStatus.SHARED));
}
return;
case HttpServletResponse.SC_NOT_FOUND:
throw new ExternalSurveillanceToolException(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationErrorSending));
case HttpServletResponse.SC_BAD_REQUEST:
throw new ExternalSurveillanceToolException(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationEntryNotSent));
default:
ExternalSurveillanceToolResponse entity = response.readEntity(ExternalSurveillanceToolResponse.class);
if (entity == null || StringUtils.isBlank(entity.getMessage())) {
throw new ExternalSurveillanceToolException(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationErrorSending));
} else if (StringUtils.isNotBlank(entity.getErrorCode())) {
throw new ExternalSurveillanceToolException(entity.getMessage(), entity.getErrorCode());
} else {
throw new ExternalSurveillanceToolException(entity.getMessage());
}
}
}
use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse in project SORMAS-Project by hzi-braunschweig.
the class ExternalSurveillanceToolGatewayFacadeEjb method getVersion.
@Override
public String getVersion() throws ExternalSurveillanceToolException {
String serviceUrl = configFacade.getExternalSurveillanceToolGatewayUrl().trim();
String versionEndpoint = configFacade.getExternalSurveillanceToolVersionEndpoint().trim();
try {
Response response = ClientBuilder.newBuilder().connectTimeout(30, TimeUnit.SECONDS).build().target(serviceUrl).path(versionEndpoint).request().get();
int status = response.getStatus();
if (status != HttpServletResponse.SC_OK) {
throw new ExternalSurveillanceToolException(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_versionRequestError));
}
ExternalSurveillanceToolResponse entity = response.readEntity(ExternalSurveillanceToolResponse.class);
return entity.getMessage();
} catch (Exception e) {
logger.error("Couldn't get version of external surveillance tool at {}{}", serviceUrl, versionEndpoint, e);
throw new ExternalSurveillanceToolException(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_versionRequestError));
}
}
Aggregations