Search in sources :

Example 1 with ExternalSurveillanceToolException

use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException in project SORMAS-Project by hzi-braunschweig.

the class CaseController method deleteAllSelectedItems.

public void deleteAllSelectedItems(Collection<? extends CaseIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoCasesSelected), I18nProperties.getString(Strings.messageNoCasesSelected), Type.WARNING_MESSAGE, false).show(Page.getCurrent());
    } else {
        VaadinUiUtil.showDeleteConfirmationWindow(String.format(I18nProperties.getString(Strings.confirmationDeleteCases), selectedRows.size()), () -> {
            int countNotDeletedCases = 0;
            StringBuilder nonDeletableCases = new StringBuilder();
            for (CaseIndexDto selectedRow : selectedRows) {
                try {
                    FacadeProvider.getCaseFacade().deleteCase(selectedRow.getUuid());
                } catch (ExternalSurveillanceToolException e) {
                    countNotDeletedCases++;
                    nonDeletableCases.append(selectedRow.getUuid(), 0, 6).append(", ");
                }
            }
            if (nonDeletableCases.length() > 0) {
                nonDeletableCases = new StringBuilder(" " + nonDeletableCases.substring(0, nonDeletableCases.length() - 2) + ". ");
            }
            callback.run();
            if (countNotDeletedCases == 0) {
                new Notification(I18nProperties.getString(Strings.headingCasesDeleted), I18nProperties.getString(Strings.messageCasesDeleted), Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent());
            } else {
                Window response = VaadinUiUtil.showSimplePopupWindow(I18nProperties.getString(Strings.headingSomeCasesNotDeleted), String.format("%1s <br/> <br/> %2s", String.format(I18nProperties.getString(Strings.messageCountCasesNotDeleted), String.format("<b>%s</b>", countNotDeletedCases), String.format("<b>%s</b>", HtmlHelper.cleanHtml(nonDeletableCases.toString()))), I18nProperties.getString(Strings.messageCasesNotDeletedReasonExternalSurveillanceTool)), ContentMode.HTML);
                response.setWidth(600, Sizeable.Unit.PIXELS);
            }
        });
    }
}
Also used : Window(com.vaadin.ui.Window) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) Notification(com.vaadin.ui.Notification) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto)

Example 2 with ExternalSurveillanceToolException

use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException in project SORMAS-Project by hzi-braunschweig.

the class AbstractSormasToSormasInterface method shareEntities.

private void shareEntities(List<String> entityUuids, SormasToSormasOptionsDto options) throws SormasToSormasException {
    User currentUser = userService.getCurrentUser();
    List<ADO> entities = getEntityService().getByUuids(entityUuids);
    validateEntitiesBeforeShare(entities, options.isHandOverOwnership());
    ensureConsistentOptions(options);
    String requestUuid = DataHelper.createUuid();
    ShareRequestInfo requestInfo = createShareRequestInfoForEntities(requestUuid, ShareRequestStatus.ACCEPTED, options, entities, currentUser, false);
    SormasToSormasDto dataToSend = shareDataBuilder.buildShareDataForRequest(requestInfo, currentUser);
    sormasToSormasRestClient.post(options.getOrganization().getId(), saveEndpoint, dataToSend, null);
    shareRequestInfoService.ensurePersisted(requestInfo);
    entities.forEach(e -> {
        SormasToSormasOriginInfo entityOriginInfo = e.getSormasToSormasOriginInfo();
        if (entityOriginInfo != null) {
            entityOriginInfo.setOwnershipHandedOver(!options.isHandOverOwnership());
            originInfoService.ensurePersisted(entityOriginInfo);
        }
    });
    try {
        shareInfoService.handleOwnershipChangeInExternalSurvTool(requestInfo);
    } catch (ExternalSurveillanceToolException e) {
        LOGGER.error("Failed to delete shared entities in external surveillance tool", e);
        throw SormasToSormasException.fromStringPropertyWithWarning(Strings.errorSormasToSormasDeleteFromExternalSurveillanceTool);
    }
}
Also used : User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)

Example 3 with ExternalSurveillanceToolException

use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException in project SORMAS-Project by hzi-braunschweig.

the class EventController method getEventDataEditComponent.

public CommitDiscardWrapperComponent<EventDataForm> getEventDataEditComponent(final String eventUuid, Consumer<EventStatus> saveCallback) {
    EventDto event = findEvent(eventUuid);
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getEventFacade().getAutomaticDeletionInfo(eventUuid);
    EventDataForm eventEditForm = new EventDataForm(false, event.isPseudonymized());
    eventEditForm.setValue(event);
    final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<EventDataForm>(eventEditForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENT_EDIT), eventEditForm.getFieldGroup());
    if (automaticDeletionInfoDto != null) {
        editView.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    editView.addCommitListener(() -> {
        if (!eventEditForm.getFieldGroup().isModified()) {
            EventDto eventDto = eventEditForm.getValue();
            final UserDto user = UserProvider.getCurrent().getUser();
            final RegionReferenceDto userRegion = user.getRegion();
            final DistrictReferenceDto userDistrict = user.getDistrict();
            final RegionReferenceDto epEventRegion = eventDto.getEventLocation().getRegion();
            final DistrictReferenceDto epEventDistrict = eventDto.getEventLocation().getDistrict();
            final Boolean eventOutsideJurisdiction = (userRegion != null && !userRegion.equals(epEventRegion) || userDistrict != null && !userDistrict.equals(epEventDistrict));
            if (eventOutsideJurisdiction) {
                VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingEventJurisdictionUpdated), new Label(I18nProperties.getString(Strings.messageEventJurisdictionUpdated)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 500, confirmed -> {
                    if (confirmed) {
                        saveEvent(saveCallback, eventDto);
                    }
                });
            } else {
                saveEvent(saveCallback, eventDto);
            }
        }
    });
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_DELETE)) {
        editView.addDeleteListener(() -> {
            if (!existEventParticipantsLinkedToEvent(event)) {
                try {
                    FacadeProvider.getEventFacade().deleteEvent(event.getUuid());
                } catch (ExternalSurveillanceToolException e) {
                    Notification.show(String.format(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationEntryNotDeleted), DataHelper.getShortUuid(event.getUuid())), "", Type.ERROR_MESSAGE);
                }
            } else {
                VaadinUiUtil.showSimplePopupWindow(I18nProperties.getString(Strings.headingEventNotDeleted), I18nProperties.getString(Strings.messageEventsNotDeletedReason));
            }
            UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityEvent));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_ARCHIVE)) {
        boolean archived = FacadeProvider.getEventFacade().isArchived(eventUuid);
        Button archiveEventButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            if (editView.isModified()) {
                editView.commit();
            }
            if (archived) {
                ControllerProvider.getArchiveController().dearchiveEntity(event, FacadeProvider.getEventFacade(), Strings.headingDearchiveEvent, Strings.confirmationDearchiveEvent, Strings.entityEvent, Strings.messageEventDearchived, () -> navigateToData(event.getUuid()));
            } else {
                ControllerProvider.getArchiveController().archiveEntity(event, FacadeProvider.getEventFacade(), Strings.headingArchiveEvent, Strings.confirmationArchiveEvent, Strings.entityEvent, Strings.messageEventArchived, () -> navigateToData(event.getUuid()));
            }
        }, ValoTheme.BUTTON_LINK);
        editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
        editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
    }
    return editView;
}
Also used : UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel) Label(com.vaadin.ui.Label) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Example 4 with ExternalSurveillanceToolException

use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException 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)

Example 5 with ExternalSurveillanceToolException

use of de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException 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)

Aggregations

ExternalSurveillanceToolException (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)9 ExternalSurveillanceToolResponse (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolResponse)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Response (javax.ws.rs.core.Response)3 Button (com.vaadin.ui.Button)2 Notification (com.vaadin.ui.Notification)2 Window (com.vaadin.ui.Window)2 EventDto (de.symeda.sormas.api.event.EventDto)2 ShareRequestInfo (de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo)2 Label (com.vaadin.ui.Label)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CaseIndexDto (de.symeda.sormas.api.caze.CaseIndexDto)1 AutomaticDeletionInfoDto (de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto)1 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 SormasToSormasOriginInfo (de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo)1 User (de.symeda.sormas.backend.user.User)1