TimedJobEventPresentable.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 java.time.Duration;
  30. import java.util.Collection;
  31. import java.util.List;
  32. import it.tidalwave.role.ui.Displayable;
  33. import it.tidalwave.dci.annotation.DciRole;
  34. import it.tidalwave.accounting.model.spi.TimedJobEventSpi;
  35. import it.tidalwave.role.ui.PresentationModelAggregate;
  36. import static it.tidalwave.accounting.commons.Styleables.RIGHT_ALIGNED;
  37. import static it.tidalwave.accounting.model.spi.util.Formatters.*;
  38. import static it.tidalwave.util.Parameters.r;

  39. /***********************************************************************************************************************
  40.  *
  41.  * @author  Fabrizio Giudici
  42.  *
  43.  **********************************************************************************************************************/
  44. @DciRole(datumType = TimedJobEventSpi.class)
  45. public class TimedJobEventPresentable extends JobEventPresentable<TimedJobEventSpi>
  46.   {
  47.     public TimedJobEventPresentable (@Nonnull final TimedJobEventSpi timedJobEvent)
  48.       {
  49.         super(timedJobEvent);
  50.       }

  51.     @Override @Nonnull
  52.     protected PresentationModelAggregate presentationModelAggregate ()
  53.       {
  54.         return super.presentationModelAggregate()
  55.             .withPmOf(DATE,        r(Displayable.of(DATETIME_FORMATTER.format(jobEvent.getStartDateTime()))))
  56.             .withPmOf(TIME,        r(Displayable.of(DURATION_FORMATTER::format, computeDuration()), RIGHT_ALIGNED))
  57.             .withPmOf(HOURLY_RATE, r(Displayable.of(MONEY_FORMATTER::format, jobEvent.getHourlyRate()), RIGHT_ALIGNED));
  58.       }

  59.     @Nonnull
  60.     private Duration computeDuration()
  61.       {
  62.         return Duration.between(jobEvent.getStartDateTime(), jobEvent.getEndDateTime());
  63.       }

  64.     @Override @Nonnull
  65.     protected Collection<String> getStyles()
  66.       {
  67.         return List.of("timed-job-event");
  68.       }
  69.   }