Class DataNeedsDbService

java.lang.Object
energy.eddie.dataneeds.services.DataNeedsDbService
All Implemented Interfaces:
DataNeedsService

@Component @ConditionalOnProperty(value="eddie.data-needs-config.data-need-source", havingValue="DATABASE") public class DataNeedsDbService extends Object implements DataNeedsService
  • Constructor Details

  • Method Details

    • initializeAndUnproxy

      public static <T> T initializeAndUnproxy(T entity)
      Hibernate always responds with a proxy object instead of the actual implementation. That way it is possible to lazily load parts of the object, but a proxy is not part of the inheritance tree, making it impossible to use the instanceof operator. This method unpacks the hibernate proxy to its actual implementation.
      Type Parameters:
      T - The type of the object to unproxy
      Parameters:
      entity - The object to unproxy
      Returns:
      the actual object and not the proxy
    • getDataNeedIdsAndNames

      public List<DataNeedsNameAndIdProjection> getDataNeedIdsAndNames()
      Description copied from interface: DataNeedsService
      Returns a list of all data needs with only their name and ID.
      Specified by:
      getDataNeedIdsAndNames in interface DataNeedsService
    • findById

      public Optional<DataNeed> findById(String id)
      Description copied from interface: DataNeedsService
      Fetches the data need with the passed ID from the underlying persistence layer.
      Specified by:
      findById in interface DataNeedsService
      Parameters:
      id - The ID of the data need to get.
      Returns:
      The data need or an empty Optional if there is no data need with the given ID.
    • getById

      public DataNeed getById(String id)
      Description copied from interface: DataNeedsService
      Gets a data need by its id. If it cannot be found throws EntityNotFoundException. Should only be used when sure that the data need exists
      Specified by:
      getById in interface DataNeedsService
      Parameters:
      id - The ID of the data need to get.
      Returns:
      the data need
    • enableOrDisableDataNeed

      public void enableOrDisableDataNeed(String id, boolean isEnabled)
      Enables or disables a data need.
      Parameters:
      id - The ID of the data need to enable or disable.
      isEnabled - If the data need should be enabled or disabled.
    • saveNewDataNeed

      public DataNeed saveNewDataNeed(DataNeed newDataNeed)
      Saves the new data need in the database and sets a UUID as DataNeed.id().
      Parameters:
      newDataNeed - Data need to save in the database.
      Returns:
      Persisted data need.
    • findAll

      public List<DataNeed> findAll()
      Returns a list of all data needs saved in the database.
    • existsById

      public boolean existsById(String id)
    • deleteById

      public void deleteById(String id)