Class AssetStorageService

java.lang.Object
org.apache.camel.builder.BuilderSupport
org.apache.camel.builder.RouteBuilder
org.openremote.manager.asset.AssetStorageService
All Implemented Interfaces:
org.apache.camel.builder.ModelRoutesBuilder, org.apache.camel.CamelContextAware, org.apache.camel.Ordered, org.apache.camel.RoutesBuilder, org.apache.camel.spi.HasCamelContext, org.apache.camel.spi.ResourceAware, org.openremote.model.ContainerService

public class AssetStorageService extends org.apache.camel.builder.RouteBuilder implements org.openremote.model.ContainerService
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
    protected static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.openremote.model.util.LockByKey
     
     
    protected ExecutorService
     
    protected GatewayService
     
     
    protected org.openremote.container.persistence.PersistenceService
     
    static final int
     
    protected org.openremote.container.timer.TimerService
     

    Fields inherited from class org.apache.camel.builder.RouteBuilder

    log

    Fields inherited from interface org.openremote.model.ContainerService

    DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITY

    Fields inherited from interface org.apache.camel.Ordered

    HIGHEST, LOWEST
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static boolean
    addAttributePredicateGroupQuery(StringBuilder sb, List<AssetStorageService.ParameterBinder> binders, int groupIndex, Consumer<String> selectInserter, org.openremote.model.query.LogicGroup<org.openremote.model.query.filter.AttributePredicate> attributePredicateGroup, Supplier<Long> timeProvider)
     
    protected static boolean
    addNameValuePredicates(List<? extends org.openremote.model.query.filter.NameValuePredicate> nameValuePredicates, StringBuilder sb, List<AssetStorageService.ParameterBinder> binders, String jsonObjName, Consumer<String> selectInserter, boolean useOr, Supplier<Long> timeProvider)
     
    protected static boolean
    appendWhereClause(StringBuilder sb, org.openremote.model.query.AssetQuery query, int level, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
     
    static <T extends org.openremote.model.event.shared.SharedEvent & org.openremote.model.asset.AssetInfo>
    EventSubscriptionAuthorizer
    assetInfoAuthorizer(ManagerIdentityService identityService, AssetStorageService assetStorageService)
     
    boolean
    authorizeAssetQuery(org.openremote.model.query.AssetQuery query, org.openremote.container.security.AuthContext authContext, String requestRealm)
    Authorizes an AssetQuery by validating it against security constraints and/or applying default options to the query based on security constraints.
    protected static String
    buildAttributeSelect(org.openremote.model.query.AssetQuery query, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
     
    protected jakarta.persistence.TypedQuery<org.openremote.model.asset.UserAssetLink>
    buildFindUserAssetLinksQuery(jakarta.persistence.EntityManager em, String realm, Collection<String> userIds, Collection<String> assetIds)
     
    protected static String
    buildFromString(org.openremote.model.query.AssetQuery query, int level)
     
    protected static String
    buildLimitString(org.openremote.model.query.AssetQuery query)
     
    protected static String
    buildNameValuePredicateFilter(org.openremote.model.query.filter.NameValuePredicate nameValuePredicate, String jsonObjName, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
     
    protected static String
    buildOperatorFilter(org.openremote.model.query.AssetQuery.Operator operator, boolean negate, int pos)
     
    protected static String
    buildOrderByString(org.openremote.model.query.AssetQuery query)
     
    protected static org.openremote.model.util.Pair<AssetStorageService.PreparedAssetQuery,Boolean>
    buildQuery(org.openremote.model.query.AssetQuery query, Supplier<Long> timeProvider)
     
    protected static String
    buildSelectString(org.openremote.model.query.AssetQuery query, int level, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
     
    protected static boolean
    calendarEventPredicateMatches(Supplier<Long> currentMillisSupplier, org.openremote.model.query.AssetQuery query, org.openremote.model.asset.Asset<?> asset)
    Will evaluate each CalendarEventPredicate and apply it depending on the LogicGroup type that each appears in.
    protected static boolean
    calendarEventPredicateMatches(Supplier<Long> currentMillisSupplier, org.openremote.model.query.LogicGroup<org.openremote.model.query.filter.AttributePredicate> group, org.openremote.model.asset.Asset<?> asset)
     
    void
     
    protected void
    createUserAssetLinks(jakarta.persistence.EntityManager em, List<org.openremote.model.asset.UserAssetLink> userAssets)
     
    boolean
    delete(List<String> assetIds)
     
    boolean
    delete(List<String> assetIds, boolean skipGatewayCheck)
     
    void
    Delete all UserAssetLinks for the specified User
    void
    deleteUserAssetLinks(List<org.openremote.model.asset.UserAssetLink> userAssetLinks)
    Delete specific UserAssetLinks.
    org.openremote.model.asset.Asset<?>
    find(jakarta.persistence.EntityManager em, String assetId, boolean loadComplete)
     
    protected org.openremote.model.asset.Asset<?>
    find(jakarta.persistence.EntityManager em, String assetId, boolean loadComplete, org.openremote.model.query.AssetQuery.Access access)
     
    org.openremote.model.asset.Asset<?>
    find(jakarta.persistence.EntityManager em, org.openremote.model.query.AssetQuery query)
     
    org.openremote.model.asset.Asset<?>
    find(String assetId)
     
    org.openremote.model.asset.Asset<?>
    find(String assetId, boolean loadComplete)
     
    <T extends org.openremote.model.asset.Asset<?>>
    T
    find(String assetId, boolean loadComplete, Class<T> assetType)
     
    org.openremote.model.asset.Asset<?>
    find(String assetId, boolean loadComplete, org.openremote.model.query.AssetQuery.Access access)
     
    <T extends org.openremote.model.asset.Asset<?>>
    T
    find(String assetId, Class<T> assetType)
     
    org.openremote.model.asset.Asset<?>
    find(org.openremote.model.query.AssetQuery query)
     
    protected List<org.openremote.model.asset.Asset<?>>
    findAll(jakarta.persistence.EntityManager em, org.openremote.model.query.AssetQuery query)
     
    List<org.openremote.model.asset.Asset<?>>
    findAll(org.openremote.model.query.AssetQuery query)
     
    findNames(String... ids)
     
    List<org.openremote.model.asset.UserAssetLink>
    findUserAssetLinks(String realm, String userId, String assetId)
     
    List<org.openremote.model.asset.UserAssetLink>
     
    int
     
    void
    init(org.openremote.model.Container container)
     
    boolean
    isDescendantAsset(String parentAssetId, String assetId)
     
    boolean
    isDescendantAssets(String parentAssetId, List<String> assetIds)
     
    boolean
    isRealmAsset(String realm, String assetId)
    Indicates if the specified asset belongs to the specified realm
    boolean
    isRealmAssets(String realm, List<String> assetIds)
    Indicates if the specified assets belong to the specified realm
    boolean
     
    boolean
    isUserAsset(String userId, String assetId)
     
    boolean
    isUserAsset(List<String> userIds, String assetId)
     
    boolean
    isUserAssets(String userId, List<String> assetIds)
     
    <T extends org.openremote.model.asset.Asset<?>>
    T
    merge(T asset)
     
    <T extends org.openremote.model.asset.Asset<?>>
    T
    merge(T asset, boolean overrideVersion)
     
    <T extends org.openremote.model.asset.Asset<?>>
    T
    merge(T asset, boolean overrideVersion, org.openremote.model.asset.impl.GatewayAsset requestingGatewayAsset, String userName)
    Merge the requested Asset checking that it meets all constraint requirements before doing so; the timestamp of each Attribute will also be updated to the current system time if it has changed to assist with Attribute equality (see Attribute.equals(java.lang.Object)).
    <T extends org.openremote.model.asset.Asset<?>>
    T
    merge(T asset, String userName)
     
    protected <T extends org.openremote.model.asset.HasAssetQuery & org.openremote.model.event.RespondableEvent>
    void
    onReadRequest(T event)
     
    protected void
    publishModificationEvents(org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent)
     
    void
    start(org.openremote.model.Container container)
     
    void
    stop(org.openremote.model.Container container)
     
    void
    storeUserAssetLinks(List<org.openremote.model.asset.UserAssetLink> userAssetLinks)
    Create specified UserAssetLinks.
     
    protected boolean
    updateAttributeValue(jakarta.persistence.EntityManager em, org.openremote.model.attribute.AttributeEvent event)
    This does a low level JDBC update so hibernate event interceptor doesn't get called and we 'manually' generate the AttributeEvent
    <R> R
    withAssetLock(String assetId, Supplier<R> action)
     

    Methods inherited from class org.apache.camel.builder.RouteBuilder

    addLifecycleInterceptor, addRoutes, addRoutesToCamelContext, addTemplatedRoutesToCamelContext, bindToRegistry, bindToRegistry, checkInitialized, configuration, configureRest, configureRests, configureRoute, configureRouteConfiguration, configureRoutes, configureRouteTemplate, configureTemplatedRoute, customize, customize, dataFormat, errorHandler, errorHandler, expression, from, from, from, fromF, fromV, fromV, getBeans, getOrder, getResource, getRestCollection, getRestConfiguration, getRests, getRouteCollection, getRoutes, getRouteTemplateCollection, getTemplatedRouteCollection, initializeCamelContext, intercept, interceptFrom, interceptFrom, interceptSendToEndpoint, loadRoutesBuilder, loadRoutesBuilder, onCompletion, onException, onException, populateBeans, populateOrUpdateRoutes, populateRests, populateRoutes, populateRouteTemplates, populateTemplatedRoutes, populateTransformers, populateValidators, prepareModel, property, propertyInject, removeLifecycleInterceptor, rest, rest, restConfiguration, routeTemplate, setErrorHandlerFactory, setResource, setRestCollection, setRouteTemplateCollection, setTemplatedRouteCollection, templatedRoute, tokenizer, transformer, updateRoutesToCamelContext, validator

    Methods inherited from class org.apache.camel.builder.BuilderSupport

    body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, java, java, joor, joor, jq, jq, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, variable, xpath, xpath, xpath, xpath

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • PRIORITY

      public static final int PRIORITY
      See Also:
    • timerService

      protected org.openremote.container.timer.TimerService timerService
    • persistenceService

      protected org.openremote.container.persistence.PersistenceService persistenceService
    • identityService

      protected ManagerIdentityService identityService
    • clientEventService

      protected ClientEventService clientEventService
    • gatewayService

      protected GatewayService gatewayService
    • executorService

      protected ExecutorService executorService
    • assetLocks

      protected final org.openremote.model.util.LockByKey assetLocks
  • Constructor Details

    • AssetStorageService

      public AssetStorageService()
  • Method Details

    • assetInfoAuthorizer

      public static <T extends org.openremote.model.event.shared.SharedEvent & org.openremote.model.asset.AssetInfo> EventSubscriptionAuthorizer assetInfoAuthorizer(ManagerIdentityService identityService, AssetStorageService assetStorageService)
    • calendarEventPredicateMatches

      protected static boolean calendarEventPredicateMatches(Supplier<Long> currentMillisSupplier, org.openremote.model.query.AssetQuery query, org.openremote.model.asset.Asset<?> asset)
      Will evaluate each CalendarEventPredicate and apply it depending on the LogicGroup type that each appears in. It tests the recurrence rule as simple start/end is checked in the DB query.
    • calendarEventPredicateMatches

      protected static boolean calendarEventPredicateMatches(Supplier<Long> currentMillisSupplier, org.openremote.model.query.LogicGroup<org.openremote.model.query.filter.AttributePredicate> group, org.openremote.model.asset.Asset<?> asset)
    • getPriority

      public int getPriority()
      Specified by:
      getPriority in interface org.openremote.model.ContainerService
    • init

      public void init(org.openremote.model.Container container) throws Exception
      Specified by:
      init in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • start

      public void start(org.openremote.model.Container container) throws Exception
      Specified by:
      start in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • stop

      public void stop(org.openremote.model.Container container) throws Exception
      Specified by:
      stop in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • configure

      public void configure() throws Exception
      Specified by:
      configure in class org.apache.camel.builder.RouteBuilder
      Throws:
      Exception
    • authorizeAssetQuery

      public boolean authorizeAssetQuery(org.openremote.model.query.AssetQuery query, org.openremote.container.security.AuthContext authContext, String requestRealm)
      Authorizes an AssetQuery by validating it against security constraints and/or applying default options to the query based on security constraints.
    • find

      public org.openremote.model.asset.Asset<?> find(String assetId)
    • find

      public <T extends org.openremote.model.asset.Asset<?>> T find(String assetId, Class<T> assetType)
    • find

      public org.openremote.model.asset.Asset<?> find(String assetId, boolean loadComplete)
      Parameters:
      loadComplete - If the whole asset data (including attributes) should be loaded.
    • find

      public <T extends org.openremote.model.asset.Asset<?>> T find(String assetId, boolean loadComplete, Class<T> assetType)
    • find

      public org.openremote.model.asset.Asset<?> find(jakarta.persistence.EntityManager em, String assetId, boolean loadComplete)
      Parameters:
      loadComplete - If the whole asset data (including path and attributes) should be loaded.
    • find

      public org.openremote.model.asset.Asset<?> find(String assetId, boolean loadComplete, org.openremote.model.query.AssetQuery.Access access)
      Parameters:
      loadComplete - If the whole asset data (including path and attributes) should be loaded.
      access - The required access permissions of the asset data.
    • find

      public org.openremote.model.asset.Asset<?> find(org.openremote.model.query.AssetQuery query)
    • find

      public org.openremote.model.asset.Asset<?> find(jakarta.persistence.EntityManager em, org.openremote.model.query.AssetQuery query)
    • findAll

      public List<org.openremote.model.asset.Asset<?>> findAll(org.openremote.model.query.AssetQuery query)
    • findNames

      public List<String> findNames(String... ids)
    • merge

      public <T extends org.openremote.model.asset.Asset<?>> T merge(T asset) throws IllegalStateException, jakarta.validation.ConstraintViolationException
      Returns:
      The current stored asset state.
      Throws:
      IllegalArgumentException - if the realm or parent is illegal, or other asset constraint is violated.
      IllegalStateException
      jakarta.validation.ConstraintViolationException
    • merge

      public <T extends org.openremote.model.asset.Asset<?>> T merge(T asset, boolean overrideVersion) throws IllegalStateException, jakarta.validation.ConstraintViolationException
      Parameters:
      overrideVersion - If true, the merge will override the data in the database, independent of version.
      Returns:
      The current stored asset state.
      Throws:
      IllegalArgumentException - if the realm or parent is illegal, or other asset constraint is violated.
      IllegalStateException
      jakarta.validation.ConstraintViolationException
    • merge

      public <T extends org.openremote.model.asset.Asset<?>> T merge(T asset, String userName) throws IllegalStateException, jakarta.validation.ConstraintViolationException
      Parameters:
      userName - the user which this asset needs to be assigned to.
      Returns:
      The current stored asset state.
      Throws:
      IllegalArgumentException - if the realm or parent is illegal, or other asset constraint is violated.
      IllegalStateException
      jakarta.validation.ConstraintViolationException
    • merge

      public <T extends org.openremote.model.asset.Asset<?>> T merge(T asset, boolean overrideVersion, org.openremote.model.asset.impl.GatewayAsset requestingGatewayAsset, String userName) throws IllegalStateException, jakarta.validation.ConstraintViolationException
      Merge the requested Asset checking that it meets all constraint requirements before doing so; the timestamp of each Attribute will also be updated to the current system time if it has changed to assist with Attribute equality (see Attribute.equals(java.lang.Object)).
      Parameters:
      overrideVersion - If true, the merge will override the data in the database, independent of version.
      requestingGatewayAsset - If set this is the GatewayAsset merging the asset so skip standard checks
      userName - the user which this asset needs to be assigned to.
      Returns:
      The current stored asset state.
      Throws:
      IllegalArgumentException - if the realm or parent is illegal, or other asset constraint is violated.
      IllegalStateException
      jakarta.validation.ConstraintViolationException
    • delete

      public boolean delete(List<String> assetIds)
      Returns:
      true if the assets were deleted, false if any of the assets still have children and can't be deleted.
    • delete

      public boolean delete(List<String> assetIds, boolean skipGatewayCheck)
    • isUserAsset

      public boolean isUserAsset(String assetId)
    • isUserAsset

      public boolean isUserAsset(String userId, String assetId)
    • isUserAsset

      public boolean isUserAsset(List<String> userIds, String assetId)
    • isUserAssets

      public boolean isUserAssets(String userId, List<String> assetIds)
    • isRealmAsset

      public boolean isRealmAsset(String realm, String assetId)
      Indicates if the specified asset belongs to the specified realm
    • isRealmAssets

      public boolean isRealmAssets(String realm, List<String> assetIds)
      Indicates if the specified assets belong to the specified realm
    • isDescendantAsset

      public boolean isDescendantAsset(String parentAssetId, String assetId)
    • isDescendantAssets

      public boolean isDescendantAssets(String parentAssetId, List<String> assetIds)
    • findUserAssetLinks

      public List<org.openremote.model.asset.UserAssetLink> findUserAssetLinks(String realm, String userId, String assetId)
    • findUserAssetLinks

      public List<org.openremote.model.asset.UserAssetLink> findUserAssetLinks(String realm, Collection<String> userIds, Collection<String> assetIds)
    • buildFindUserAssetLinksQuery

      protected jakarta.persistence.TypedQuery<org.openremote.model.asset.UserAssetLink> buildFindUserAssetLinksQuery(jakarta.persistence.EntityManager em, String realm, Collection<String> userIds, Collection<String> assetIds)
    • deleteUserAssetLinks

      public void deleteUserAssetLinks(List<org.openremote.model.asset.UserAssetLink> userAssetLinks)
      Delete specific UserAssetLinks.
    • deleteUserAssetLinks

      public void deleteUserAssetLinks(String userId)
      Delete all UserAssetLinks for the specified User
    • storeUserAssetLinks

      public void storeUserAssetLinks(List<org.openremote.model.asset.UserAssetLink> userAssetLinks)
      Create specified UserAssetLinks.
    • withAssetLock

      public <R> R withAssetLock(String assetId, Supplier<R> action)
    • createUserAssetLinks

      protected void createUserAssetLinks(jakarta.persistence.EntityManager em, List<org.openremote.model.asset.UserAssetLink> userAssets)
    • find

      protected org.openremote.model.asset.Asset<?> find(jakarta.persistence.EntityManager em, String assetId, boolean loadComplete, org.openremote.model.query.AssetQuery.Access access)
    • findAll

      protected List<org.openremote.model.asset.Asset<?>> findAll(jakarta.persistence.EntityManager em, org.openremote.model.query.AssetQuery query)
    • updateAttributeValue

      protected boolean updateAttributeValue(jakarta.persistence.EntityManager em, org.openremote.model.attribute.AttributeEvent event) throws jakarta.validation.ConstraintViolationException
      This does a low level JDBC update so hibernate event interceptor doesn't get called and we 'manually' generate the AttributeEvent
      Throws:
      jakarta.validation.ConstraintViolationException
    • publishModificationEvents

      protected void publishModificationEvents(org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent)
    • toString

      public String toString()
      Overrides:
      toString in class org.apache.camel.builder.RouteBuilder
    • buildQuery

      protected static org.openremote.model.util.Pair<AssetStorageService.PreparedAssetQuery,Boolean> buildQuery(org.openremote.model.query.AssetQuery query, Supplier<Long> timeProvider)
    • buildSelectString

      protected static String buildSelectString(org.openremote.model.query.AssetQuery query, int level, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
    • buildAttributeSelect

      protected static String buildAttributeSelect(org.openremote.model.query.AssetQuery query, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
    • buildFromString

      protected static String buildFromString(org.openremote.model.query.AssetQuery query, int level)
    • buildOrderByString

      protected static String buildOrderByString(org.openremote.model.query.AssetQuery query)
    • buildLimitString

      protected static String buildLimitString(org.openremote.model.query.AssetQuery query)
    • appendWhereClause

      protected static boolean appendWhereClause(StringBuilder sb, org.openremote.model.query.AssetQuery query, int level, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
    • addAttributePredicateGroupQuery

      protected static boolean addAttributePredicateGroupQuery(StringBuilder sb, List<AssetStorageService.ParameterBinder> binders, int groupIndex, Consumer<String> selectInserter, org.openremote.model.query.LogicGroup<org.openremote.model.query.filter.AttributePredicate> attributePredicateGroup, Supplier<Long> timeProvider)
    • addNameValuePredicates

      protected static boolean addNameValuePredicates(List<? extends org.openremote.model.query.filter.NameValuePredicate> nameValuePredicates, StringBuilder sb, List<AssetStorageService.ParameterBinder> binders, String jsonObjName, Consumer<String> selectInserter, boolean useOr, Supplier<Long> timeProvider)
    • buildNameValuePredicateFilter

      protected static String buildNameValuePredicateFilter(org.openremote.model.query.filter.NameValuePredicate nameValuePredicate, String jsonObjName, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider)
    • buildOperatorFilter

      protected static String buildOperatorFilter(org.openremote.model.query.AssetQuery.Operator operator, boolean negate, int pos)
    • onReadRequest

      protected <T extends org.openremote.model.asset.HasAssetQuery & org.openremote.model.event.RespondableEvent> void onReadRequest(T event)