Search in sources :

Example 1 with ExternalSurveillanceToolResponse

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());
            }
    }
}
Also used : ExternalSurveillanceToolResponse(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) ExternalSurveillanceToolResponse(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse)

Example 2 with ExternalSurveillanceToolResponse

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));
    }
}
Also used : ExternalSurveillanceToolResponse(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) ExternalSurveillanceToolResponse(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)

Aggregations

ExternalSurveillanceToolException (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)2 ExternalSurveillanceToolResponse (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Response (javax.ws.rs.core.Response)2