Skip to content

Commit

Permalink
#183 added archive and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony4m committed Jan 17, 2025
1 parent 9ede23c commit 198b742
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 47 deletions.
13 changes: 13 additions & 0 deletions sormas-api/src/main/java/de/symeda/sormas/api/ebs/EbsCriteria.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.symeda.sormas.api.ebs;

import de.symeda.sormas.api.EntityRelevanceStatus;
import de.symeda.sormas.api.event.EventCriteria;
import de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto;
import de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto;
import de.symeda.sormas.api.infrastructure.region.RegionReferenceDto;
Expand Down Expand Up @@ -42,6 +44,7 @@ public class EbsCriteria extends CriteriaWithDateType implements ExternalShareCr
private YesNo actionInitiated;
private ResponseStatus responseStatus;
private Boolean deleted = Boolean.FALSE;
private EntityRelevanceStatus relevanceStatus;
private RegionReferenceDto region;
private DistrictReferenceDto district;
private CommunityReferenceDto community;
Expand Down Expand Up @@ -95,6 +98,16 @@ public Boolean getDeleted() {
return deleted;
}

public EbsCriteria relevanceStatus(EntityRelevanceStatus relevanceStatus) {
this.relevanceStatus = relevanceStatus;
return this;
}

@IgnoreForUrl
public EntityRelevanceStatus getRelevanceStatus() {
return relevanceStatus;
}

public EbsCriteria region(RegionReferenceDto region) {
this.region = region;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

import de.symeda.sormas.api.ebs.SignalVerificationDto;
import de.symeda.sormas.api.ebs.TriagingDto;
import de.symeda.sormas.backend.event.EventParticipant;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -221,6 +222,7 @@ public static EbsDto toEbsDto(Ebs source) {
target.setEbsLatLon(source.getEbsLatLon());
target.setDeleted(source.isDeleted());
target.setDeletionReason(source.getDeletionReason());
target.setOtherDeletionReason(source.getOtherDeletionReason());
if (source.getTriaging() != null) {
target.setTriaging(TriagingFacadeEjb.toDto(source.getTriaging()));
}
Expand Down Expand Up @@ -347,6 +349,11 @@ public List<String> delete(List<String> uuids, DeletionDetails deletionDetails)
}
return deletedEbsUuids;
}
@Override
@RightsAllowed(UserRight._EVENT_DELETE)
public void restore(String uuid) {
super.restore(uuid);
}

@Override
public List<String> restore(List<String> uuids) {
Expand Down Expand Up @@ -878,6 +885,7 @@ public Ebs fillOrBuildEntity(@NotNull EbsDto source, Ebs target, boolean checkCh
target.setResponsibleUser(userService.getByReferenceDto(source.getResponsibleUser()));
target.setDeleted(source.isDeleted());
target.setDeletionReason(source.getDeletionReason());
target.setOtherDeletionReason(source.getOtherDeletionReason());
target.setEbsLatLon(source.getEbsLatLon());
target.setAutomaticScanningType(source.getAutomaticScanningType());
target.setManualScanningType(source.getManualScanningType());
Expand Down Expand Up @@ -919,6 +927,24 @@ public void archiveAllArchivableEbss(int daysAfterEbsGetsArchived) {
archiveAllArchivableEbss(daysAfterEbsGetsArchived, LocalDate.now());
}

@Override
@RightsAllowed(UserRight._EVENT_ARCHIVE)
public void archive(String eventUuid, Date endOfProcessingDate) {
super.archive(eventUuid, endOfProcessingDate);
}

@Override
@RightsAllowed(UserRight._EVENT_ARCHIVE)
public void archive(List<String> eventUuids) {
super.archive(eventUuids);
}

@Override
@RightsAllowed(UserRight._EVENT_ARCHIVE)
public void dearchive(List<String> eventUuids, String dearchiveReason) {
super.dearchive(eventUuids, dearchiveReason);
}

@Override
@RightsAllowed(UserRight._SYSTEM)
public void archiveAllArchivableEbss(int daysAfterEbsGetsArchived, @NotNull LocalDate referenceDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.EditPermissionType;
import de.symeda.sormas.api.EntityRelevanceStatus;
import de.symeda.sormas.api.RequestContextHolder;
import de.symeda.sormas.api.common.DeletionDetails;
import de.symeda.sormas.api.document.DocumentRelatedEntityType;
Expand Down Expand Up @@ -495,6 +496,22 @@ public Predicate buildCriteriaFilter(EbsCriteria ebsCriteria, EbsQueryContext eb
if (ebsCriteria.getCommunity() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getCommunity().get(Community.UUID), ebsCriteria.getCommunity().getUuid()));
}
if (ebsCriteria.getRelevanceStatus() == null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.or(cb.equal(from.get(Ebs.ARCHIVED), false), cb.isNull(from.get(Ebs.ARCHIVED))));
filter = CriteriaBuilderHelper.and(cb, filter, cb.or(cb.equal(from.get(Ebs.DELETED), false), cb.isNull(from.get(Ebs.DELETED))));
}
if (ebsCriteria.getRelevanceStatus() != null) {
if (ebsCriteria.getRelevanceStatus() == EntityRelevanceStatus.ACTIVE) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.or(cb.equal(from.get(Ebs.ARCHIVED), false), cb.isNull(from.get(Ebs.ARCHIVED))));
} else if (ebsCriteria.getRelevanceStatus() == EntityRelevanceStatus.ARCHIVED) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Ebs.ARCHIVED), true));
} else if (ebsCriteria.getRelevanceStatus() == EntityRelevanceStatus.DELETED) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Ebs.DELETED), true));
}
}
if (ebsCriteria.getRelevanceStatus() != EntityRelevanceStatus.DELETED) {
filter = CriteriaBuilderHelper.and(cb, filter, createDefaultFilter(cb, from));
}
if (CollectionUtils.isNotEmpty(ebsCriteria.getExcludedUuids())) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.not(from.get(AbstractDomainObject.UUID).in(ebsCriteria.getExcludedUuids())));
}
Expand Down
173 changes: 128 additions & 45 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/ebs/EBSView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;
import java.util.Set;

import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Label;
import de.symeda.sormas.api.EntityRelevanceStatus;
import de.symeda.sormas.api.common.CoreEntityType;
import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.feature.FeatureTypeProperty;
import de.symeda.sormas.ui.utils.ComboBoxHelper;
import de.symeda.sormas.ui.utils.LayoutUtil;
import org.vaadin.hene.popupbutton.PopupButton;

import com.vaadin.icons.VaadinIcons;
Expand Down Expand Up @@ -46,19 +55,20 @@ public class EBSView extends AbstractView {

private static final long serialVersionUID = -3048977745713631500L;
public static final String VIEW_NAME = "ebs";
private EbsCriteria ebsCriteria;
private final EbsCriteria ebsCriteria;
private final EbsViewConfiguration viewConfiguration;
public static String currentview = "signallist";

private FilteredGrid<?, ?> grid;
private Button createButton;
private HashMap<Button, String> srcButtons;
private Button activeStatusButton;
// Filter
private EbsFilterForm ebsFilterForm;
private ComboBox contactCountMethod;

private VerticalLayout gridLayout;
private HashMap<Button, String> statusButtons;
private Label relevanceStatusInfoLabel;
private ComboBox relevanceStatusFilter;

public EBSView() {
super(VIEW_NAME);
Expand All @@ -78,6 +88,7 @@ public EBSView() {
}
gridLayout = new VerticalLayout();
gridLayout.addComponent(createFilterBar());
gridLayout.addComponent(createStatusFilterBar());
gridLayout.addComponent(grid);
gridLayout.setMargin(true);
gridLayout.setSpacing(false);
Expand Down Expand Up @@ -205,6 +216,90 @@ public EBSView() {
}
}

public HorizontalLayout createStatusFilterBar() {
HorizontalLayout statusFilterLayout = new HorizontalLayout();
statusFilterLayout.setSpacing(true);
statusFilterLayout.setMargin(false);
statusFilterLayout.setWidth(100, Unit.PERCENTAGE);
statusFilterLayout.addStyleName(CssStyles.VSPACE_3);

statusButtons = new HashMap<>();

Button statusAll = ButtonHelper.createButton(Captions.all, e -> {
ebsCriteria.sourceInformation(null);
navigateTo(ebsCriteria);
}, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
statusAll.setCaptionAsHtml(true);

statusFilterLayout.addComponent(statusAll);
statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
activeStatusButton = statusAll;

for (EbsSourceType source : EbsSourceType.values()) {
Button statusButton = ButtonHelper.createButton(source.toString(), e -> {
ebsCriteria.sourceInformation(source);
navigateTo(ebsCriteria);
}, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER, CssStyles.BUTTON_FILTER_LIGHT);
statusButton.setData(source);
statusButton.setCaptionAsHtml(true);

statusFilterLayout.addComponent(statusButton);
statusButtons.put(statusButton, source.toString());
}

HorizontalLayout actionButtonsLayout = new HorizontalLayout();
actionButtonsLayout.setSpacing(true);
{

// Show active/archived/all dropdown
if (Objects.nonNull(UserProvider.getCurrent()) && UserProvider.getCurrent().hasUserRight(UserRight.EVENT_VIEW)) {

if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.AUTOMATIC_ARCHIVING, CoreEntityType.EVENT)) {
int daysAfterCaseGetsArchived = FacadeProvider.getFeatureConfigurationFacade()
.getProperty(FeatureType.AUTOMATIC_ARCHIVING, CoreEntityType.EBS, FeatureTypeProperty.THRESHOLD_IN_DAYS, Integer.class);
if (daysAfterCaseGetsArchived > 0) {
relevanceStatusInfoLabel = new Label(
VaadinIcons.INFO_CIRCLE.getHtml() + " "
+ String.format(I18nProperties.getString(Strings.infoArchivedEbs), daysAfterCaseGetsArchived),
ContentMode.HTML);
relevanceStatusInfoLabel.setVisible(false);
relevanceStatusInfoLabel.addStyleName(CssStyles.LABEL_VERTICAL_ALIGN_SUPER);
actionButtonsLayout.addComponent(relevanceStatusInfoLabel);
actionButtonsLayout.setComponentAlignment(relevanceStatusInfoLabel, Alignment.MIDDLE_RIGHT);
}
}
relevanceStatusFilter = ComboBoxHelper.createComboBoxV7();
relevanceStatusFilter.setId("relevanceStatus");
relevanceStatusFilter.setWidth(210, Unit.PIXELS);
relevanceStatusFilter.setNullSelectionAllowed(false);
relevanceStatusFilter.addItems((Object[]) EntityRelevanceStatus.values());
relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ACTIVE, I18nProperties.getCaption(Captions.Ebs_Active_Signals));
relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ARCHIVED, I18nProperties.getCaption(Captions.Ebs_Archived_Signals));
relevanceStatusFilter
.setItemCaption(EntityRelevanceStatus.ACTIVE_AND_ARCHIVED, I18nProperties.getCaption(Captions.Ebs_All_Active_And_Archived_Signals));

if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_DELETE)) {
relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.DELETED, I18nProperties.getCaption(Captions.Ebs_Deleted_Signals));
} else {
relevanceStatusFilter.removeItem(EntityRelevanceStatus.DELETED);
}
relevanceStatusFilter.addValueChangeListener(e -> {
if (relevanceStatusInfoLabel != null) {
relevanceStatusInfoLabel.setVisible(EntityRelevanceStatus.ARCHIVED.equals(e.getProperty().getValue()));
}
ebsCriteria.relevanceStatus((EntityRelevanceStatus) e.getProperty().getValue());
navigateTo(ebsCriteria);
});
actionButtonsLayout.addComponent(relevanceStatusFilter);
}
}
statusFilterLayout.addComponent(actionButtonsLayout);
statusFilterLayout.setComponentAlignment(actionButtonsLayout, Alignment.TOP_RIGHT);
statusFilterLayout.setExpandRatio(actionButtonsLayout, 1);

return statusFilterLayout;
}

private boolean isDefaultViewType() {
return viewConfiguration.getViewType() == EbsViewType.DEFAULT;
}
Expand Down Expand Up @@ -245,7 +340,14 @@ public void updateFilterComponents() {

// TODO replace with Vaadin 8 databinding
applyingCriteria = true;
updateStatusButtons();
if (relevanceStatusFilter != null) {
relevanceStatusFilter.setValue(ebsCriteria.getRelevanceStatus());
} if ( ebsCriteria.getRelevanceStatus() == null) {
relevanceStatusFilter.setValue(EntityRelevanceStatus.ACTIVE);
ebsCriteria.relevanceStatus(EntityRelevanceStatus.ACTIVE);

}
ebsFilterForm.setValue(ebsCriteria);

applyingCriteria = false;
Expand Down Expand Up @@ -281,6 +383,28 @@ public HorizontalLayout createFilterBar() {

return filterLayout;
}
private void updateStatusButtons() {
long dataCount;
statusButtons.keySet().forEach(b -> {
CssStyles.style(b, CssStyles.BUTTON_FILTER_LIGHT);
b.setCaption(statusButtons.get(b));
if (b.getData() == ebsCriteria.getSourceInformation()) {
activeStatusButton = b;
}
});
CssStyles.removeStyles(activeStatusButton, CssStyles.BUTTON_FILTER_LIGHT);

if (isDefaultViewType()){
dataCount = FacadeProvider.getEbsFacade().count(ebsCriteria);
}else {
dataCount = FacadeProvider.getEbsFacade().eventCount(ebsCriteria);
}

if (activeStatusButton != null) {
activeStatusButton
.setCaption(statusButtons.get(activeStatusButton) + LayoutUtil.spanCss(CssStyles.BADGE, String.valueOf(dataCount)));
}
}

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
Expand All @@ -289,7 +413,6 @@ public void enter(ViewChangeListener.ViewChangeEvent event) {
params = params.substring(1);
}
if (isDefaultViewType()) {

updateFilterComponents();
((EbsSignalGrid) grid).reload();
} else {
Expand All @@ -302,44 +425,4 @@ public void enter(ViewChangeListener.ViewChangeEvent event) {
private Set<String> getSelectedRowUuids() {
return viewConfiguration.isInEagerMode() ? (Set<String>) grid.asMultiSelect().getSelectedItems() : Collections.emptySet();
}

public HorizontalLayout createStatusFilterBar() {

HorizontalLayout srcFilterLayout = new HorizontalLayout();
srcFilterLayout.setSpacing(true);
srcFilterLayout.setMargin(false);
srcFilterLayout.setWidth(100, Unit.PERCENTAGE);
srcFilterLayout.addStyleName(CssStyles.VSPACE_3);
srcButtons = new HashMap<>();

if (isDefaultViewType()) {
Button srcAll = ButtonHelper.createButton(Captions.all, e -> {
ebsCriteria.setSourceInformation(null);
ebsCriteria.setTriagingDecision(null);
navigateTo(ebsCriteria);
}, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
srcAll.setCaptionAsHtml(true);

srcFilterLayout.addComponent(srcAll);

srcButtons.put(srcAll, I18nProperties.getCaption(Captions.all));
activeStatusButton = srcAll;

for (EbsSourceType src : EbsSourceType.values()) {
Button srcButton = ButtonHelper.createButton("status-" + src, src.toString(), e -> {
ebsCriteria.setSourceInformation(src);
navigateTo(ebsCriteria);
}, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER, CssStyles.BUTTON_FILTER_LIGHT);
srcButton.setCaptionAsHtml(true);
srcButton.setData(src);

srcFilterLayout.addComponent(srcButton);

srcButtons.put(srcButton, src.toString());
}
}

return srcFilterLayout;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent;

import static com.vaadin.ui.Notification.Type.ERROR_MESSAGE;
import static com.vaadin.ui.Notification.Type.WARNING_MESSAGE;


Expand All @@ -40,7 +39,7 @@ protected void initView(String params) {
ControllerProvider.getEbsController().navigateToIndex();
}
CommitDiscardWrapperComponent<SignalVerificationDataForm> signalVerficationForm = ControllerProvider.getEbsController()
.getEbsCreateSignalVerficationComponent(getEbsRef().getUuid(),
.getEbsCreateSignalVerificationComponent(getEbsRef().getUuid(),
UserProvider.getCurrent().hasUserRight(UserRight.EVENT_EDIT));
setSubComponent(signalVerficationForm);
}
Expand Down

0 comments on commit 198b742

Please sign in to comment.