Skip to content

Commit

Permalink
Merge pull request #974 from qbicsoftware/development
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferboedker authored Nov 24, 2022
2 parents 718dfbe + 9b28b16 commit c0f2d2a
Show file tree
Hide file tree
Showing 24 changed files with 577 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import life.qbic.business.offers.create.CreateOffer
import life.qbic.business.offers.create.CreateOfferDataSource
import life.qbic.business.offers.fetch.FetchOffer
import life.qbic.business.offers.fetch.FetchOfferDataSource
import life.qbic.business.persons.affiliation.archive.ArchiveAffiliation
import life.qbic.business.persons.affiliation.archive.ArchiveAffiliationDataSource
import life.qbic.business.persons.affiliation.archive.ArchiveAffiliationOutput
import life.qbic.business.persons.affiliation.create.CreateAffiliation
import life.qbic.business.persons.affiliation.create.CreateAffiliationDataSource
import life.qbic.business.persons.affiliation.list.ListAffiliationsDataSource
Expand Down Expand Up @@ -38,6 +41,8 @@ import life.qbic.portal.offermanager.components.AppViewModel
import life.qbic.portal.offermanager.components.affiliation.create.CreateAffiliationController
import life.qbic.portal.offermanager.components.affiliation.create.CreateAffiliationPresenter
import life.qbic.portal.offermanager.components.affiliation.create.CreateAffiliationView
import life.qbic.portal.offermanager.components.affiliation.search.ArchiveAffiliationController
import life.qbic.portal.offermanager.components.affiliation.search.ArchiveAffiliationPresenter
import life.qbic.portal.offermanager.components.affiliation.search.SearchAffiliationView
import life.qbic.portal.offermanager.components.affiliation.search.SearchAffiliationViewModel
import life.qbic.portal.offermanager.components.affiliation.update.UpdateAffiliationController
Expand Down Expand Up @@ -142,6 +147,7 @@ class DependencyManager {
private ListAffiliationsDataSource listAffiliationsDataSource
private UpdateAffiliationDataSource updateAffiliationDataSource
private SearchPersonDataSource searchPersonDataSource
private ArchiveAffiliationDataSource archiveAffiliationDataSource
// Implemented by life.qbic.portal.offermanager.dataresources.products.ProductsDbConnector
private ArchiveProductDataSource archiveProductDataSource
private CreateProductDataSource createProductDataSource
Expand Down Expand Up @@ -200,6 +206,7 @@ class DependencyManager {
createAffiliationDataSource = affiliationDbConnector
updateAffiliationDataSource = affiliationDbConnector
listAffiliationsDataSource = affiliationDbConnector
archiveAffiliationDataSource = affiliationDbConnector

ProductsDbConnector productsDbConnector = new ProductsDbConnector(DatabaseSession.getInstance())
archiveProductDataSource = productsDbConnector
Expand Down Expand Up @@ -333,9 +340,11 @@ class DependencyManager {
private SearchAffiliationView createSearchAffiliationView() {
ResourcesService<Affiliation> affiliationResourcesService = this.affiliationService
SearchAffiliationViewModel searchAffiliationViewModel = new SearchAffiliationViewModel(affiliationResourcesService)

ArchiveAffiliationOutput archiveAffiliationOutput = new ArchiveAffiliationPresenter(affiliationResourcesService, this.viewModel)
ArchiveAffiliation archiveAffiliation = new ArchiveAffiliation(archiveAffiliationOutput, archiveAffiliationDataSource)
UpdateAffiliationView updateAffiliationView = createUpdateAffiliationView()
SearchAffiliationView searchAffiliationView = new SearchAffiliationView(searchAffiliationViewModel, updateAffiliationView)
ArchiveAffiliationController controller = new ArchiveAffiliationController(archiveAffiliation)
SearchAffiliationView searchAffiliationView = new SearchAffiliationView(searchAffiliationViewModel, updateAffiliationView, controller)
return searchAffiliationView
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package life.qbic.portal.offermanager.components.affiliation.search;

import java.util.Objects;
import life.qbic.business.RefactorConverter;
import life.qbic.business.persons.affiliation.archive.ArchiveAffiliationInput;
import life.qbic.datamodel.dtos.business.Affiliation;

public class ArchiveAffiliationController {

private final ArchiveAffiliationInput archiveAffiliationInput;

public ArchiveAffiliationController(ArchiveAffiliationInput archiveAffiliationInput) {
this.archiveAffiliationInput = Objects.requireNonNull(archiveAffiliationInput);
}

public void archive(Affiliation affiliation) {
life.qbic.business.persons.affiliation.Affiliation convertedAffiliation = RefactorConverter.toAffiliation(affiliation);
archiveAffiliationInput.archive(convertedAffiliation);
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package life.qbic.portal.offermanager.components.affiliation.search;

import java.util.Objects;
import life.qbic.business.RefactorConverter;
import life.qbic.business.persons.affiliation.archive.ArchiveAffiliationOutput;
import life.qbic.datamodel.dtos.business.Affiliation;
import life.qbic.portal.offermanager.components.AppViewModel;
import life.qbic.portal.offermanager.dataresources.ResourcesService;

public class ArchiveAffiliationPresenter implements ArchiveAffiliationOutput {

private final ResourcesService<Affiliation> affiliationResourcesService;

private final AppViewModel sharedViewModel;

public ArchiveAffiliationPresenter(ResourcesService<Affiliation> affiliationResourcesService,
AppViewModel sharedViewModel) {
this.affiliationResourcesService = Objects.requireNonNull(affiliationResourcesService);
this.sharedViewModel = Objects.requireNonNull(sharedViewModel);
}


@Override
public void failNotification(String notification) {
sharedViewModel.getFailureNotifications().add(notification);
}

@Override
public void archivedAffiliation(life.qbic.business.persons.affiliation.Affiliation affiliation) {
affiliationResourcesService.reloadResources();
affiliationResourcesService.removeFromResource(RefactorConverter.toAffiliationDto(affiliation));
sharedViewModel.getSuccessNotifications().add("Archived affiliation successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.vaadin.ui.themes.ValoTheme
import groovy.util.logging.Log4j2
import life.qbic.business.RefactorConverter
import life.qbic.datamodel.dtos.business.Affiliation
import life.qbic.portal.offermanager.components.ConfirmationDialog
import life.qbic.portal.offermanager.components.GridUtils
import life.qbic.portal.offermanager.components.affiliation.update.UpdateAffiliationView

Expand All @@ -20,7 +21,7 @@ import life.qbic.portal.offermanager.components.affiliation.update.UpdateAffilia
* @since 1.0.0
*/
@Log4j2
class SearchAffiliationView extends FormLayout{
class SearchAffiliationView extends FormLayout implements Observer {

private final SearchAffiliationViewModel viewModel
private final UpdateAffiliationView updateAffiliationView
Expand All @@ -29,14 +30,26 @@ class SearchAffiliationView extends FormLayout{
private Panel selectedAffiliationDetails
private VerticalLayout searchAffiliationLayout

SearchAffiliationView(SearchAffiliationViewModel viewModel, UpdateAffiliationView updateAffiliationView) {
private ConfirmationDialog confirmationDialog

private ArchiveAffiliationController controller

private Button updateAffiliationButton

private Button archiveAffiliationButton

SearchAffiliationView(SearchAffiliationViewModel viewModel, UpdateAffiliationView updateAffiliationView,
ArchiveAffiliationController affiliationController) {
this.viewModel = viewModel
this.updateAffiliationView = updateAffiliationView
this.controller = Objects.requireNonNull(affiliationController, "affiliaiton controller must not be null")

initLayout()
generateAffiliationGrid()
listenToAffiliationSelection()
listenToUpdateAffiliationView()
// Register for changes in the affiliation list
this.viewModel.addObserver(this)
}

private void initLayout() {
Expand All @@ -57,19 +70,53 @@ class SearchAffiliationView extends FormLayout{
updateAffiliationView.setMargin(false)
updateAffiliationView.setVisible(false)

this.addComponents(searchAffiliationLayout,updateAffiliationView)
this.addComponents(searchAffiliationLayout, updateAffiliationView)
this.setMargin(false)
}

private HorizontalLayout generateButtonLayout(){
private HorizontalLayout generateButtonLayout() {
HorizontalLayout buttonLayout = new HorizontalLayout()
def updateButton = generateUpdateButton()
buttonLayout.addComponent(updateButton)
this.updateAffiliationButton = generateUpdateButton()
this.archiveAffiliationButton = generateArchivingButton()
buttonLayout.addComponent(updateAffiliationButton)
buttonLayout.addComponent(archiveAffiliationButton)

return buttonLayout
}

private Button generateUpdateButton(){
private Button generateArchivingButton() {
Button archive = new Button("Archive", VaadinIcons.ARCHIVE)
archive.setEnabled(false)
archive.setStyleName(ValoTheme.BUTTON_LARGE)

archive.addClickListener({
confirmationDialog = new ConfirmationDialog("This archives the selected affiliation and removes it from all related persons!\n\n Existing offers are not affected.")
UI.getCurrent().addWindow(confirmationDialog)

confirmationDialog.confirm.caption = "Archive"
confirmationDialog.confirm.setIcon(VaadinIcons.ARCHIVE)
confirmationDialog.confirm.addStyleName(ValoTheme.BUTTON_DANGER)

confirmationDialog.decline.caption = "Abort"
confirmationDialog.decline.setIcon(VaadinIcons.CLOSE)

confirmationDialog.confirm.addClickListener({
controller.archive(viewModel.getSelectedAffiliation().get())
})
})

affiliationGrid.addSelectionListener({
if (it.firstSelectedItem.isPresent()) {
archive.setEnabled(true)
} else {
archive.setEnabled(false)
}
})

return archive
}

private Button generateUpdateButton() {
Button update = new Button("Update Affiliation", VaadinIcons.EDIT)
update.setEnabled(false)
update.setStyleName(ValoTheme.BUTTON_LARGE)
Expand All @@ -79,17 +126,17 @@ class SearchAffiliationView extends FormLayout{
showUpdateAffiliation()
})
affiliationGrid.addSelectionListener({
if(it.firstSelectedItem.isPresent()){
if (it.firstSelectedItem.isPresent()) {
update.setEnabled(true)
}else{
} else {
update.setEnabled(false)
}
})

return update
}

private void listenToUpdateAffiliationView(){
private void listenToUpdateAffiliationView() {
updateAffiliationView.addAbortListener(this::hideUpdateAffiliation)
updateAffiliationView.addSubmitListener(this::hideUpdateAffiliation)
}
Expand Down Expand Up @@ -136,8 +183,7 @@ class SearchAffiliationView extends FormLayout{
}

/**
* Sets a listener to the affiliation grid.
*/
* Sets a listener to the affiliation grid.*/
private void listenToAffiliationSelection() {
this.affiliationGrid.addSelectionListener({
viewModel.selectedAffiliation = it.firstSelectedItem
Expand Down Expand Up @@ -225,5 +271,18 @@ class SearchAffiliationView extends FormLayout{
return stringBuilder.toString().trim()
}

@Override
void update(Observable o, Object arg) {
// We want to refresh the grid, so that cached items are removed and the content
// reflects the current content of available (active) affiliations
this.affiliationGrid.getDataProvider().refreshAll()
disableActionButtons()
}

private void disableActionButtons() {
this.archiveAffiliationButton.setEnabled(false)
this.updateAffiliationButton.setEnabled(false)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import life.qbic.portal.offermanager.dataresources.ResourcesService
*
* @since 1.0.0
*/
class SearchAffiliationViewModel {
class SearchAffiliationViewModel extends Observable {

/**
* A list of available affiliations. All items are of class {@link Affiliation}
Expand Down Expand Up @@ -41,6 +41,9 @@ class SearchAffiliationViewModel {
selectedAffiliation = Optional.empty()

affiliations.addAll(affiliationResourcesService.iterator())

setChanged()
notifyObservers()
}

/**
Expand All @@ -53,4 +56,6 @@ class SearchAffiliationViewModel {
resetAffiliations()
})
}


}
Loading

0 comments on commit c0f2d2a

Please sign in to comment.