Project.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.model;

  28. import javax.annotation.Nonnull;
  29. import javax.annotation.concurrent.Immutable;
  30. import java.time.LocalDate;
  31. import java.util.Collections;
  32. import java.util.List;
  33. import it.tidalwave.util.As;
  34. import it.tidalwave.util.Id;
  35. import it.tidalwave.role.Identifiable;
  36. import it.tidalwave.role.SimpleComposite;
  37. import it.tidalwave.accounting.model.ProjectRegistry.JobEventFinder;
  38. import it.tidalwave.accounting.model.types.Money;
  39. import it.tidalwave.accounting.model.spi.ObjectFactory;
  40. import lombok.AllArgsConstructor;
  41. import lombok.Getter;
  42. import lombok.ToString;
  43. import lombok.With;

  44. /***********************************************************************************************************************
  45.  *
  46.  * This class models a project.
  47.  *
  48.  * @author  Fabrizio Giudici
  49.  *
  50.  **********************************************************************************************************************/
  51. @Immutable
  52. public interface Project extends SimpleComposite<JobEvent>, Identifiable, As
  53.   {
  54.     public enum Status { OPEN, CLOSED }

  55.     /*******************************************************************************************************************
  56.      *
  57.      *
  58.      *
  59.      ******************************************************************************************************************/
  60.     @AllArgsConstructor // FIXME (access = PROTECTED)
  61.     @Immutable @With @Getter @ToString
  62.     public static class Builder
  63.       {
  64.         public static interface Callback // Lombok @With doesn't support builder subclasses
  65.           {
  66.             public void register (@Nonnull final Project project);

  67.             public static final Callback DEFAULT = (project) -> {};
  68.           }

  69.         private final Id id;
  70.         private final Customer customer;
  71.         private final String name;
  72.         private final String number;
  73.         private final String description;
  74.         private final String notes;
  75.         private final Status status;
  76.         private final Money hourlyRate;
  77.         private final Money budget;
  78.         private final LocalDate startDate;
  79.         private final LocalDate endDate;
  80.         private final List<? extends JobEvent> events; // FIXME: immutable
  81.         private final Callback callback;

  82.         public Builder()
  83.           {
  84.             this(Callback.DEFAULT);
  85.           }

  86.         public Builder (@Nonnull final Callback callback)
  87.           {
  88.              // FIXME: avoid null
  89.             this(new Id(""), null, "", "", "", "", Status.OPEN, Money.ZERO, Money.ZERO, null, null,
  90.                  Collections.emptyList(), callback);
  91.           }

  92.         @Nonnull
  93.         public Builder with (@Nonnull final Builder builder)
  94.           {
  95.             return builder.withCallback(callback);
  96.           }

  97.         @Nonnull
  98.         public Project create()
  99.           {
  100.             final var project = ObjectFactory.getInstance().createProject(this);
  101.             callback.register(project);
  102.             return project;
  103.           }
  104.       }

  105.     /*******************************************************************************************************************
  106.      *
  107.      *
  108.      *
  109.      ******************************************************************************************************************/
  110.     @Nonnull
  111.     public static Project.Builder builder()
  112.       {
  113.         return new Project.Builder();
  114.       }

  115.     /*******************************************************************************************************************
  116.      *
  117.      *
  118.      *
  119.      ******************************************************************************************************************/
  120.     @Nonnull
  121.     public Customer getCustomer();

  122.     /*******************************************************************************************************************
  123.      *
  124.      * {@inheritDoc}
  125.      *
  126.      ******************************************************************************************************************/
  127.     @Nonnull
  128.     public JobEventFinder findChildren();

  129.     /*******************************************************************************************************************
  130.      *
  131.      * Returns a builder pre-populated with all the attributes.
  132.      *
  133.      * @return  the builder
  134.      *
  135.      ******************************************************************************************************************/
  136.     @Nonnull
  137.     public Builder toBuilder();
  138.   }