DefaultJobEventExplorerPresentationControl.java

  1. /*
  2.  * #%L
  3.  * *********************************************************************************************************************
  4.  *
  5.  * blueHour
  6.  * http://bluehour.tidalwave.it - git clone git@bitbucket.org:tidalwave/bluehour-src.git
  7.  * %%
  8.  * Copyright (C) 2013 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
  9.  * %%
  10.  * *********************************************************************************************************************
  11.  *
  12.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  13.  * the License. You may obtain a copy of the License at
  14.  *
  15.  *     http://www.apache.org/licenses/LICENSE-2.0
  16.  *
  17.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  18.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations under the License.
  20.  *
  21.  * *********************************************************************************************************************
  22.  *
  23.  *
  24.  * *********************************************************************************************************************
  25.  * #L%
  26.  */
  27. package it.tidalwave.accounting.ui.jobeventexplorer.impl;

  28. import javax.annotation.Nonnull;
  29. import it.tidalwave.role.ui.Visible;
  30. import it.tidalwave.util.annotation.VisibleForTesting;
  31. import it.tidalwave.dci.annotation.DciContext;
  32. import it.tidalwave.messagebus.MessageBus;
  33. import it.tidalwave.messagebus.annotation.ListensTo;
  34. import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
  35. import it.tidalwave.accounting.commons.ProjectSelectedEvent;
  36. import it.tidalwave.accounting.model.Project;
  37. import it.tidalwave.accounting.model.spi.JobEventSpi;
  38. import it.tidalwave.accounting.ui.jobeventexplorer.JobEventExplorerPresentation;
  39. import it.tidalwave.accounting.ui.jobeventexplorer.JobEventExplorerPresentationControl;
  40. import lombok.RequiredArgsConstructor;
  41. import lombok.extern.slf4j.Slf4j;
  42. import static java.util.Comparator.comparing;
  43. import static it.tidalwave.util.Parameters.r;
  44. import static it.tidalwave.role.ui.Presentable._Presentable_;
  45. import static it.tidalwave.role.ui.spi.PresentationModelCollectors.toCompositePresentationModel;

  46. /***********************************************************************************************************************
  47.  *
  48.  * @author  Fabrizio Giudici
  49.  *
  50.  **********************************************************************************************************************/
  51. @RequiredArgsConstructor @DciContext @SimpleMessageSubscriber @Slf4j
  52. public class DefaultJobEventExplorerPresentationControl implements JobEventExplorerPresentationControl
  53.   {
  54.     @Nonnull
  55.     private final MessageBus messageBus;

  56.     @Nonnull
  57.     private final JobEventExplorerPresentation presentation;

  58.     /*******************************************************************************************************************
  59.      *
  60.      *
  61.      *
  62.      ******************************************************************************************************************/
  63.     @Override
  64.     public void initialize()
  65.       {
  66.         log.info("initialize()");  
  67.       }
  68.    
  69.     /*******************************************************************************************************************
  70.      *
  71.      * Reacts to the notification that a {@link Project} has been selected by populating the presentation with
  72.      * its job events.
  73.      *
  74.      * @param  event  the notification event
  75.      *
  76.      ******************************************************************************************************************/
  77.     @VisibleForTesting void onProjectSelectedEvent (@Nonnull @ListensTo final ProjectSelectedEvent event)
  78.       {
  79.         log.info("onProjectSelectedEvent({})", event);
  80.         presentation.populate(event.getProject().findChildren()
  81.                                                 .stream()
  82.                                                 .map(jobEvent -> (JobEventSpi)jobEvent)
  83.                                                 .sorted(comparing(JobEventSpi::getDateTime))
  84.                                                 .map(jobEvent -> jobEvent.as(_Presentable_).createPresentationModel())
  85.                                                 .collect(toCompositePresentationModel(r(Visible.INVISIBLE))));
  86.       }
  87.   }