Skip to content

Commit

Permalink
Merge pull request #70 in TELIMA/karnak from feat/update_from_dev to …
Browse files Browse the repository at this point in the history
…release

* commit '04db05ea46792317ed2e76e8bef2e90bfcbfdeac':
  feat: - maven spotless
  feat: - enable/disable save delete buttons destination depending transfer in progress - refactoring loading spinner
  Revert "feat: - upgrade springboot version to 2.5.3 - upgrade junit version to 5.7.2 - upgrade liquibase version to 4.4.3 - test: assert dependencies are in an other location - deactivate EchoController test: will be reactivated in an other US: http://jira.hcuge.ch/browse/TELIMA-198"
  Revert "feat: - liquibase: schemaLocation xsd issue: set url back instead of local file"
  feat: - liquibase: schemaLocation xsd issue: set url back instead of local file
  feat: - upgrade springboot version to 2.5.3 - upgrade junit version to 5.7.2 - upgrade liquibase version to 4.4.3 - test: assert dependencies are in an other location - deactivate EchoController test: will be reactivated in an other US: http://jira.hcuge.ch/browse/TELIMA-198
  • Loading branch information
jdcshug committed Aug 20, 2021
2 parents d722098 + 04db05e commit 4157a29
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 42 deletions.
28 changes: 26 additions & 2 deletions src/main/java/org/karnak/frontend/forwardnode/ForwardNodeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ForwardNodeView extends HorizontalLayout implements HasUrlParameter

public static final String VIEW_NAME = "Gateway";
public static final String ROUTE = "forwardnode";
public static final String SAVE = "Save";
public static final String DELETE = "Delete";

// Forward Node Logic
private final ForwardNodeLogic forwardNodeLogic;
Expand Down Expand Up @@ -139,15 +141,37 @@ private void addEventGridSelectionLayoutNewGrid() {
layoutNewGridForwardNode
.getGridForwardNode()
.asSingleSelect()
.addValueChangeListener(event -> forwardNodeLogic.editForwardNode(event.getValue()));
.addValueChangeListener(
event -> {
if (event.getValue() == null) {
layoutEditForwardNode
.getButtonForwardNodeSaveDeleteCancel()
.getSave()
.setText(SAVE);
layoutEditForwardNode
.getButtonForwardNodeSaveDeleteCancel()
.getDelete()
.setText(DELETE);
}
forwardNodeLogic.editForwardNode(event.getValue());
});
}

/** Add event when click on cancel button in LayoutEditForwardNode */
private void addEventCancelButtonLayoutEdit() {
layoutEditForwardNode
.getButtonForwardNodeSaveDeleteCancel()
.getCancel()
.addClickListener(event -> forwardNodeLogic.cancelForwardNode());
.addClickListener(
event -> {
forwardNodeLogic.cancelForwardNode();
// Case transfer is in progress reset labels
layoutEditForwardNode.getButtonForwardNodeSaveDeleteCancel().getSave().setText(SAVE);
layoutEditForwardNode
.getButtonForwardNodeSaveDeleteCancel()
.getDelete()
.setText(DELETE);
});
}

/** Add event when click on delete button in LayoutEditForwardNode */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ private void initComponents() {
.getFilterBySOPClassesForm()
.getSopFilter()
.setItems(sopClassUIDService.getAllSOPClassUIDsName());

// Set button in view in order to be able to enable/disable it
destinationView.setButtonForwardNodeSaveDeleteCancel(buttonForwardNodeSaveDeleteCancel);

// Set editable form in order to retrieve save button to enable/disable it
destinationView.setNewUpdateDestination(newUpdateDestination);
}

public void setEditView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.karnak.frontend.forwardnode.edit.destination;

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.data.provider.ListDataProvider;
import java.util.HashSet;
Expand All @@ -30,6 +31,9 @@
public class DestinationLogic extends ListDataProvider<DestinationEntity> {

private static final Logger LOGGER = LoggerFactory.getLogger(DestinationLogic.class);
public static final String TRANSFER_IN_PROGRESS = "Transfer in progress";
public static final String SAVE = "Save";
public static final String DELETE = "Delete";

// View
private DestinationView destinationView;
Expand Down Expand Up @@ -72,14 +76,157 @@ public void refreshAll() {
@Scheduled(fixedRate = 1000)
public void checkStatusTransfers() {
if (forwardNodeEntity != null) {
List<DestinationEntity> destinationEntities =
forwardNodeEntity.getDestinationEntities().stream()
// Refreshed destinations from DB
List<DestinationEntity> refreshedDestinations =
destinationService.retrieveDestinationsFromIds(
forwardNodeEntity.getDestinationEntities().stream()
.map(DestinationEntity::getId)
.collect(Collectors.toList()));

// Loading spinner
checkActivityLoadingSpinner(
refreshedDestinations.stream()
.filter(DestinationEntity::isActivate)
.collect(Collectors.toList());
checkActivityDestinations(destinationEntities);
.collect(Collectors.toList()));

// Buttons save/delete enable/disable
checkActivityEnableDisableButtons(refreshedDestinations);
}
}

/**
* Enable/disable Save and Delete buttons depending on activity on a destination. If a transfer is
* in progress disable buttons save and delete for all destinations of the forward node (activated
* or not)
*
* @param destinationEntities Refreshed destinations from DB
*/
private void checkActivityEnableDisableButtons(List<DestinationEntity> destinationEntities) {
// If a transfer is in progress: disable
if (destinationEntities.stream().anyMatch(DestinationEntity::isTransferInProgress)) {
destinationView.getUi().access(this::disableSaveDeleteButtons);
} else {
// If no transfer: enable
destinationView.getUi().access(this::enableSaveDeleteButtons);
}
}

/**
* Check activity for loading spinner
*
* @param activatedDestinationEntities Destinations to check
*/
private void checkActivityLoadingSpinner(List<DestinationEntity> activatedDestinationEntities) {
activatedDestinationEntities.forEach(
d -> {
// Retrieve the loading image of the corresponding destination
Image loadingImage =
destinationView
.getGridDestination()
.getLoadingImages()
.get(forwardNodeEntity.getFwdAeTitle())
.get(d.getId());

// Check there is some activity on the destination: if yes set the loading spinner visible
// otherwise set it invisible
if (d.isTransferInProgress() && !loadingImage.isVisible()) {
// Loading spinner visible
destinationView.getUi().access(() -> loadingImage.setVisible(true));
} else if (!d.isTransferInProgress() && loadingImage.isVisible()) {
// Loading spinner invisible
destinationView.getUi().access(() -> loadingImage.setVisible(false));
}
});
}

/** Enable save delete buttons */
private void enableSaveDeleteButtons() {
// Forward node
enableButtonTransferInProgress(
destinationView.getButtonForwardNodeSaveDeleteCancel().getSave(),
destinationView.getButtonForwardNodeSaveDeleteCancel().getDelete());

// Disable save button editable form stow/dicom
// Dicom
enableButtonTransferInProgress(
destinationView
.getNewUpdateDestination()
.getButtonDestinationDICOMSaveDeleteCancel()
.getSave(),
destinationView
.getNewUpdateDestination()
.getButtonDestinationDICOMSaveDeleteCancel()
.getDelete());

// Stow
enableButtonTransferInProgress(
destinationView
.getNewUpdateDestination()
.getButtonDestinationSTOWSaveDeleteCancel()
.getSave(),
destinationView
.getNewUpdateDestination()
.getButtonDestinationSTOWSaveDeleteCancel()
.getDelete());
}

/** Disable save delete buttons */
private void disableSaveDeleteButtons() {
// Forward node
disableButtonTransferInProgress(
destinationView.getButtonForwardNodeSaveDeleteCancel().getSave(),
destinationView.getButtonForwardNodeSaveDeleteCancel().getDelete());

// Disable save button editable form stow/dicom
// Dicom
disableButtonTransferInProgress(
destinationView
.getNewUpdateDestination()
.getButtonDestinationDICOMSaveDeleteCancel()
.getSave(),
destinationView
.getNewUpdateDestination()
.getButtonDestinationDICOMSaveDeleteCancel()
.getDelete());

// Stow
disableButtonTransferInProgress(
destinationView
.getNewUpdateDestination()
.getButtonDestinationSTOWSaveDeleteCancel()
.getSave(),
destinationView
.getNewUpdateDestination()
.getButtonDestinationSTOWSaveDeleteCancel()
.getDelete());
}

/**
* Enable buttons
*
* @param saveButton Save button
* @param deleteButton Delete button
*/
private void enableButtonTransferInProgress(Button saveButton, Button deleteButton) {
saveButton.setEnabled(true);
deleteButton.setEnabled(true);
saveButton.setText(SAVE);
deleteButton.setText(DELETE);
}

/**
* Disable buttons
*
* @param saveButton Save button
* @param deleteButton Delete button
*/
private void disableButtonTransferInProgress(Button saveButton, Button deleteButton) {
saveButton.setEnabled(false);
deleteButton.setEnabled(false);
saveButton.setText(TRANSFER_IN_PROGRESS);
deleteButton.setText(TRANSFER_IN_PROGRESS);
}

/**
* Sets the filter to use for this data provider and refreshes data.
*
Expand Down Expand Up @@ -146,36 +293,4 @@ public void deleteDestination(DestinationEntity destinationEntity) {
destinationService.delete(destinationEntity);
refreshAll();
}

/**
* Check activity for specific destinations
*
* @param destinationEntities Destinations to check
*/
private void checkActivityDestinations(List<DestinationEntity> destinationEntities) {
// Refresh entities from db
List<Long> entitiesId =
destinationEntities.stream().map(DestinationEntity::getId).collect(Collectors.toList());
List<DestinationEntity> refreshedDestinationEntities =
destinationService.retrieveDestinationsFromIds(entitiesId);

refreshedDestinationEntities.forEach(
d -> {
// Retrieve the loading image of the corresponding destination
Image loadingImage =
destinationView
.getGridDestination()
.getLoadingImages()
.get(forwardNodeEntity.getFwdAeTitle())
.get(d.getId());

// Check there is some activity on the destination: if yes set the progress bar visible
// otherwise set it invisible
if (d.isTransferInProgress() && !loadingImage.isVisible()) {
destinationView.getUi().access(() -> loadingImage.setVisible(true));
} else if (!d.isTransferInProgress() && loadingImage.isVisible()) {
destinationView.getUi().access(() -> loadingImage.setVisible(false));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.vaadin.flow.component.textfield.TextField;
import org.karnak.backend.data.entity.ForwardNodeEntity;
import org.karnak.frontend.forwardnode.ForwardNodeLogic;
import org.karnak.frontend.forwardnode.edit.component.ButtonSaveDeleteCancel;
import org.karnak.frontend.forwardnode.edit.destination.component.GridDestination;
import org.karnak.frontend.forwardnode.edit.destination.component.NewUpdateDestination;
import org.karnak.frontend.util.UIS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -40,6 +42,8 @@ public class DestinationView extends VerticalLayout {
private Button newDestinationSTOW;
private GridDestination gridDestination;
private HorizontalLayout layoutFilterButton;
private ButtonSaveDeleteCancel buttonForwardNodeSaveDeleteCancel;
private NewUpdateDestination newUpdateDestination;

private final String LABEL_NEW_DESTINATION_DICOM = "DICOM";
private final String LABEL_NEW_DESTINATION_STOW = "STOW";
Expand Down Expand Up @@ -147,4 +151,21 @@ public UI getUi() {
public void setUi(UI ui) {
this.ui = ui;
}

public ButtonSaveDeleteCancel getButtonForwardNodeSaveDeleteCancel() {
return buttonForwardNodeSaveDeleteCancel;
}

public void setButtonForwardNodeSaveDeleteCancel(
ButtonSaveDeleteCancel buttonForwardNodeSaveDeleteCancel) {
this.buttonForwardNodeSaveDeleteCancel = buttonForwardNodeSaveDeleteCancel;
}

public NewUpdateDestination getNewUpdateDestination() {
return newUpdateDestination;
}

public void setNewUpdateDestination(NewUpdateDestination newUpdateDestination) {
this.newUpdateDestination = newUpdateDestination;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
import java.util.Objects;
import org.karnak.backend.data.entity.DestinationEntity;
import org.karnak.backend.enums.DestinationType;
import org.karnak.frontend.forwardnode.edit.component.ButtonSaveDeleteCancel;
Expand All @@ -27,6 +28,7 @@ public class NewUpdateDestination extends VerticalLayout {
private final ButtonSaveDeleteCancel buttonDestinationDICOMSaveDeleteCancel;
private final ButtonSaveDeleteCancel buttonDestinationSTOWSaveDeleteCancel;
private DestinationEntity currentDestinationEntity;
public static final String TRANSFER_IN_PROGRESS = "Transfer in progress";

public NewUpdateDestination() {
setSizeFull();
Expand All @@ -45,8 +47,11 @@ public NewUpdateDestination() {
public void load(DestinationEntity destinationEntity, DestinationType type) {
if (destinationEntity != null) {
currentDestinationEntity = destinationEntity;
buttonDestinationDICOMSaveDeleteCancel.getDelete().setEnabled(true);
buttonDestinationSTOWSaveDeleteCancel.getDelete().setEnabled(true);
if (!Objects.equals(
buttonDestinationDICOMSaveDeleteCancel.getDelete().getText(), TRANSFER_IN_PROGRESS)) {
buttonDestinationDICOMSaveDeleteCancel.getDelete().setEnabled(true);
buttonDestinationSTOWSaveDeleteCancel.getDelete().setEnabled(true);
}
} else {
currentDestinationEntity =
type == DestinationType.stow
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/db/changelog/changes/db.changelog-1.1.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog-4.0.xsd">
<changeSet author="karnak" id="1.1-1">
Expand Down

0 comments on commit 4157a29

Please sign in to comment.