use of de.symeda.sormas.ui.SormasUI in project SORMAS-Project by hzi-braunschweig.
the class EventGroupController method getEventGroupEditComponent.
public CommitDiscardWrapperComponent<?> getEventGroupEditComponent(String uuid) {
EventGroupDto eventGroup = FacadeProvider.getEventGroupFacade().getEventGroupByUuid(uuid);
EventGroupDataForm eventGroupEditForm = new EventGroupDataForm(false);
eventGroupEditForm.setValue(eventGroup);
UserProvider user = UserProvider.getCurrent();
final CommitDiscardWrapperComponent<EventGroupDataForm> editView = new CommitDiscardWrapperComponent<>(eventGroupEditForm, user.hasUserRight(UserRight.EVENTGROUP_EDIT), eventGroupEditForm.getFieldGroup());
List<RegionReferenceDto> regions = FacadeProvider.getEventGroupFacade().getEventGroupRelatedRegions(uuid);
boolean hasRegion = user.hasNationalJurisdictionLevel() || regions.stream().allMatch(user::hasRegion);
editView.setReadOnly(hasRegion);
if (user.hasUserRight(UserRight.EVENTGROUP_EDIT) && hasRegion) {
editView.addCommitListener(() -> {
if (!eventGroupEditForm.getFieldGroup().isModified()) {
EventGroupDto updatedEventGroup = eventGroupEditForm.getValue();
FacadeProvider.getEventGroupFacade().saveEventGroup(updatedEventGroup);
Notification.show(I18nProperties.getString(Strings.messageEventGroupSaved), Notification.Type.WARNING_MESSAGE);
SormasUI.refreshView();
}
});
}
if (user.hasUserRight(UserRight.EVENTGROUP_DELETE) && hasRegion) {
editView.addDeleteListener(() -> {
deleteEventGroup(eventGroup);
UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
}, I18nProperties.getString(Strings.entityEventGroup));
}
// Initialize 'Archive' button
if (user.hasUserRight(UserRight.EVENTGROUP_ARCHIVE) && hasRegion) {
boolean archived = FacadeProvider.getEventGroupFacade().isArchived(uuid);
Button archiveEventButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
archiveOrDearchiveEventGroup(uuid, !archived);
}, ValoTheme.BUTTON_LINK);
editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
}
editView.addDiscardListener(SormasUI::refreshView);
return editView;
}
use of de.symeda.sormas.ui.SormasUI in project SORMAS-Project by hzi-braunschweig.
the class SourceContactListComponent method createSourceContactListComponent.
private void createSourceContactListComponent(SourceContactList sourceContactList) {
setWidth(100, Unit.PERCENTAGE);
setMargin(false);
setSpacing(false);
HorizontalLayout componentHeader = new HorizontalLayout();
componentHeader.setMargin(false);
componentHeader.setSpacing(false);
componentHeader.setWidth(100, Unit.PERCENTAGE);
addComponent(componentHeader);
list = sourceContactList;
addComponent(list);
list.reload();
Label sourceContactsHeader = new Label(I18nProperties.getString(Strings.headingEpiDataSourceCaseContacts));
sourceContactsHeader.addStyleName(CssStyles.H3);
componentHeader.addComponent(sourceContactsHeader);
if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CREATE)) {
Button createButton = ButtonHelper.createIconButton(Captions.contactNewContact, VaadinIcons.PLUS_CIRCLE, e -> view.showNavigationConfirmPopupIfDirty(() -> ControllerProvider.getContactController().create(caseReference, true, SormasUI::refreshView)), ValoTheme.BUTTON_PRIMARY);
componentHeader.addComponent(createButton);
componentHeader.setComponentAlignment(createButton, Alignment.MIDDLE_RIGHT);
}
}
use of de.symeda.sormas.ui.SormasUI in project SORMAS-Project by hzi-braunschweig.
the class ExpressionProcessorTest method setupClass.
@BeforeClass
public static void setupClass() {
UI ui = new SormasUI();
final MockedStatic<UI> uiMockedStatic = Mockito.mockStatic(UI.class);
uiMockedStatic.when(UI::getCurrent).thenReturn(ui);
Page page = new Page(UI.getCurrent(), new PageState());
MockedStatic<Page> pageMockedStatic = Mockito.mockStatic(Page.class);
pageMockedStatic.when(Page::getCurrent).thenReturn(page);
}
use of de.symeda.sormas.ui.SormasUI in project SORMAS-Project by hzi-braunschweig.
the class CaseControllerTest method initUI.
@Before
public void initUI() throws Exception {
creator.createUser(null, null, null, "ad", "min", UserRole.ADMIN, UserRole.NATIONAL_USER);
VaadinRequest request = Mockito.mock(VaadinServletRequest.class);
when(request.getUserPrincipal()).thenReturn((Principal) () -> "admin");
CurrentInstance.set(VaadinRequest.class, request);
VaadinService service = Mockito.mock(VaadinService.class);
CurrentInstance.set(VaadinService.class, service);
VaadinSession session = Mockito.mock(VaadinSession.class);
ConverterFactory converterFactory = new SormasDefaultConverterFactory();
when(session.getConverterFactory()).thenReturn(converterFactory);
when(session.getService()).thenReturn(service);
CurrentInstance.set(VaadinSession.class, session);
ui = new SormasUI();
CurrentInstance.set(UI.class, ui);
java.lang.reflect.Field pageField = UI.class.getDeclaredField("page");
pageField.setAccessible(true);
pageField.set(ui, Mockito.mock(Page.class));
}
use of de.symeda.sormas.ui.SormasUI in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantDataView method initView.
@Override
protected void initView(String params) {
EventParticipantDto eventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(getReference().getUuid());
setHeightUndefined();
DetailSubComponentWrapper container = new DetailSubComponentWrapper(() -> editComponent);
container.setWidth(100, Unit.PERCENTAGE);
container.setMargin(true);
setSubComponent(container);
CustomLayout layout = new CustomLayout();
layout.addStyleName(CssStyles.ROOT_COMPONENT);
layout.setTemplateContents(HTML_LAYOUT);
layout.setWidth(100, Unit.PERCENTAGE);
layout.setHeightUndefined();
container.addComponent(layout);
final EventParticipantReferenceDto eventParticipantRef = getReference();
editComponent = ControllerProvider.getEventParticipantController().getEventParticipantDataEditComponent(eventParticipantRef.getUuid());
editComponent.setMargin(false);
editComponent.setWidth(100, Unit.PERCENTAGE);
editComponent.getWrappedComponent().setWidth(100, Unit.PERCENTAGE);
editComponent.addStyleName(CssStyles.MAIN_COMPONENT);
layout.addComponent(editComponent, EDIT_LOC);
EventDto event = FacadeProvider.getEventFacade().getEventByUuid(eventParticipant.getEvent().getUuid(), false);
SampleCriteria sampleCriteria = new SampleCriteria().eventParticipant(eventParticipantRef);
if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_VIEW)) {
SampleListComponent sampleList = new SampleListComponent(sampleCriteria.sampleAssociationType(SampleAssociationType.EVENT_PARTICIPANT), e -> showNavigationConfirmPopupIfDirty(() -> ControllerProvider.getSampleController().create(eventParticipantRef, event.getDisease(), SormasUI::refreshView)));
SampleListComponentLayout sampleListComponentLayout = new SampleListComponentLayout(sampleList, I18nProperties.getString(Strings.infoCreateNewSampleDiscardsChangesEventParticipant));
layout.addComponent(sampleListComponentLayout, SAMPLES_LOC);
}
if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_VIEW)) {
VerticalLayout contactsLayout = new VerticalLayout();
contactsLayout.setMargin(false);
contactsLayout.setSpacing(false);
ContactListComponent contactList = new ContactListComponent(eventParticipantRef);
contactList.addStyleName(CssStyles.SIDE_COMPONENT);
contactsLayout.addComponent(contactList);
layout.addComponent(contactsLayout, CONTACTS_LOC);
}
boolean sormasToSormasEnabled = FacadeProvider.getSormasToSormasFacade().isSharingEventsEnabledForUser();
if (sormasToSormasEnabled || eventParticipant.getSormasToSormasOriginInfo() != null) {
VerticalLayout sormasToSormasLocLayout = new VerticalLayout();
sormasToSormasLocLayout.setMargin(false);
sormasToSormasLocLayout.setSpacing(false);
SormasToSormasListComponent sormasToSormasListComponent = new SormasToSormasListComponent(eventParticipant, sormasToSormasEnabled);
sormasToSormasListComponent.addStyleNames(CssStyles.SIDE_COMPONENT);
sormasToSormasLocLayout.addComponent(sormasToSormasListComponent);
layout.addComponent(sormasToSormasLocLayout, SORMAS_TO_SORMAS_LOC);
}
VaccinationListCriteria vaccinationCriteria = new VaccinationListCriteria.Builder(eventParticipant.getPerson().toReference()).withDisease(event.getDisease()).build();
QuarantineOrderDocumentsComponent.addComponentToLayout(layout, eventParticipantRef, DocumentWorkflow.QUARANTINE_ORDER_EVENT_PARTICIPANT, sampleCriteria, vaccinationCriteria);
boolean isEditAllowed = FacadeProvider.getEventParticipantFacade().isEventParticipantEditAllowed(eventParticipantRef.getUuid());
if (!isEditAllowed) {
container.setEnabled(false);
}
if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.IMMUNIZATION_MANAGEMENT) && UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_VIEW) && event.getDisease() != null) {
if (!FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
final ImmunizationListCriteria immunizationListCriteria = new ImmunizationListCriteria.Builder(eventParticipant.getPerson().toReference()).wihDisease(event.getDisease()).build();
layout.addComponent(new SideComponentLayout(new ImmunizationListComponent(immunizationListCriteria)), IMMUNIZATION_LOC);
} else {
VaccinationListCriteria criteria = vaccinationCriteria;
layout.addComponent(new SideComponentLayout(new VaccinationListComponent(getReference(), criteria, eventParticipant.getRegion() != null ? eventParticipant.getRegion() : event.getEventLocation().getRegion(), eventParticipant.getDistrict() != null ? eventParticipant.getDistrict() : event.getEventLocation().getDistrict(), this)), VACCINATIONS_LOC);
}
}
}
Aggregations