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);
}
});
}
}
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);
}
}
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;
}
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));
}
}
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());
}
}
}
Aggregations