View Javadoc
1   /*
2    * The coLAB project
3    * Copyright (C) 2021-2023 AlbaSim, MEI, HEIG-VD, HES-SO
4    *
5    * Licensed under the MIT License
6    */
7   package ch.colabproject.colab.api.model;
8   
9   import ch.colabproject.colab.api.exceptions.ColabMergeException;
10  import ch.colabproject.colab.generator.model.interfaces.WithId;
11  import ch.colabproject.colab.generator.model.interfaces.WithJsonDiscriminator;
12  import ch.colabproject.colab.generator.model.tools.PolymorphicDeserializer;
13  import javax.json.bind.annotation.JsonbTypeDeserializer;
14  
15  /**
16   * Simple interface which depicts persisted object that may be exchanged with clients
17   *
18   * @author maxence
19   */
20  @JsonbTypeDeserializer(PolymorphicDeserializer.class)
21  public interface ColabEntity
22      extends WithId, WithTrackingData, WithDeletionStatus, WithPermission, WithJsonDiscriminator {
23  
24      /**
25       * Update this object according to values provided by other.
26       * <p>
27       * This is used when an object is prepared to be updated in database.
28       *
29       * @param other object to take new values from
30       *
31       * @throws ColabMergeException if merging is not possible
32       */
33      void mergeToUpdate(ColabEntity other) throws ColabMergeException;
34  
35      /**
36       * Update this object according to values provided by other.
37       * <p>
38       * This is used when an object is prepared to be duplicated.
39       *
40       * @param other object to take new values from
41       *
42       * @throws ColabMergeException if merging is not possible
43       */
44      default void mergeToDuplicate(ColabEntity other) throws ColabMergeException {
45          mergeToUpdate(other);
46      }
47  }