Package org.openremote.manager.asset
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 ClassesModifier and TypeClassDescriptionstatic interfaceprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.openremote.model.util.LockByKeyprotected ClientEventServiceprotected ExecutorServiceprotected GatewayServiceprotected ManagerIdentityServiceprotected org.openremote.container.persistence.PersistenceServicestatic final intprotected org.openremote.container.timer.TimerServiceFields inherited from class org.apache.camel.builder.RouteBuilder
logFields inherited from interface org.openremote.model.ContainerService
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITYFields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static booleanaddAttributePredicateGroupQuery(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 booleanaddNameValuePredicates(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 booleanappendWhereClause(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>
EventSubscriptionAuthorizerassetInfoAuthorizer(ManagerIdentityService identityService, AssetStorageService assetStorageService) booleanauthorizeAssetQuery(org.openremote.model.query.AssetQuery query, org.openremote.container.security.AuthContext authContext, String requestRealm) Authorizes anAssetQueryby validating it against security constraints and/or applying default options to the query based on security constraints.protected static StringbuildAttributeSelect(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 StringbuildFromString(org.openremote.model.query.AssetQuery query, int level) protected static StringbuildLimitString(org.openremote.model.query.AssetQuery query) protected static StringbuildNameValuePredicateFilter(org.openremote.model.query.filter.NameValuePredicate nameValuePredicate, String jsonObjName, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider) protected static StringbuildOperatorFilter(org.openremote.model.query.AssetQuery.Operator operator, boolean negate, int pos) protected static StringbuildOrderByString(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 StringbuildSelectString(org.openremote.model.query.AssetQuery query, int level, List<AssetStorageService.ParameterBinder> binders, Supplier<Long> timeProvider) protected static booleancalendarEventPredicateMatches(Supplier<Long> currentMillisSupplier, org.openremote.model.query.AssetQuery query, org.openremote.model.asset.Asset<?> asset) Will evaluate eachCalendarEventPredicateand apply it depending on theLogicGrouptype that each appears in.protected static booleancalendarEventPredicateMatches(Supplier<Long> currentMillisSupplier, org.openremote.model.query.LogicGroup<org.openremote.model.query.filter.AttributePredicate> group, org.openremote.model.asset.Asset<?> asset) voidprotected voidcreateUserAssetLinks(jakarta.persistence.EntityManager em, List<org.openremote.model.asset.UserAssetLink> userAssets) booleanbooleanvoiddeleteUserAssetLinks(String userId) Delete allUserAssetLinks for the specifiedUservoiddeleteUserAssetLinks(List<org.openremote.model.asset.UserAssetLink> userAssetLinks) Delete specificUserAssetLinks.org.openremote.model.asset.Asset<?> 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<?> org.openremote.model.asset.Asset<?> <T extends org.openremote.model.asset.Asset<?>>
Torg.openremote.model.asset.Asset<?> <T extends org.openremote.model.asset.Asset<?>>
Torg.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) List<org.openremote.model.asset.UserAssetLink> findUserAssetLinks(String realm, String userId, String assetId) List<org.openremote.model.asset.UserAssetLink> findUserAssetLinks(String realm, Collection<String> userIds, Collection<String> assetIds) intvoidinit(org.openremote.model.Container container) booleanisDescendantAsset(String parentAssetId, String assetId) booleanisDescendantAssets(String parentAssetId, List<String> assetIds) booleanisRealmAsset(String realm, String assetId) Indicates if the specified asset belongs to the specified realmbooleanisRealmAssets(String realm, List<String> assetIds) Indicates if the specified assets belong to the specified realmbooleanisUserAsset(String assetId) booleanisUserAsset(String userId, String assetId) booleanisUserAsset(List<String> userIds, String assetId) booleanisUserAssets(String userId, List<String> assetIds) <T extends org.openremote.model.asset.Asset<?>>
Tmerge(T asset) <T extends org.openremote.model.asset.Asset<?>>
Tmerge(T asset, boolean overrideVersion) <T extends org.openremote.model.asset.Asset<?>>
Tmerge(T asset, boolean overrideVersion, org.openremote.model.asset.impl.GatewayAsset requestingGatewayAsset, String userName) Merge the requestedAssetchecking that it meets all constraint requirements before doing so; the timestamp of eachAttributewill also be updated to the current system time if it has changed to assist withAttributeequality (seeAttribute.equals(java.lang.Object)).<T extends org.openremote.model.asset.Asset<?>>
Tprotected <T extends org.openremote.model.asset.HasAssetQuery & org.openremote.model.event.RespondableEvent>
voidonReadRequest(T event) protected voidpublishModificationEvents(org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) voidstart(org.openremote.model.Container container) voidstop(org.openremote.model.Container container) voidstoreUserAssetLinks(List<org.openremote.model.asset.UserAssetLink> userAssetLinks) Create specifiedUserAssetLinks.toString()protected booleanupdateAttributeValue(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 theAttributeEvent<R> RwithAssetLock(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, validatorMethods 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
-
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
-
clientEventService
-
gatewayService
-
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 eachCalendarEventPredicateand apply it depending on theLogicGrouptype that each appears in. It tests the recurrence rule as simple start/end is checked in the DB query. -
calendarEventPredicateMatches
-
getPriority
public int getPriority()- Specified by:
getPriorityin interfaceorg.openremote.model.ContainerService
-
init
- Specified by:
initin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
start
- Specified by:
startin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
stop
- Specified by:
stopin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
configure
- Specified by:
configurein classorg.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 anAssetQueryby validating it against security constraints and/or applying default options to the query based on security constraints. -
find
-
find
-
find
- Parameters:
loadComplete- If the whole asset data (including attributes) should be loaded.
-
find
-
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
-
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.IllegalStateExceptionjakarta.validation.ConstraintViolationException
-
merge
public <T extends org.openremote.model.asset.Asset<?>> T merge(T asset, boolean overrideVersion) throws IllegalStateException, jakarta.validation.ConstraintViolationException - Parameters:
overrideVersion- Iftrue, 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.IllegalStateExceptionjakarta.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.IllegalStateExceptionjakarta.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 requestedAssetchecking that it meets all constraint requirements before doing so; the timestamp of eachAttributewill also be updated to the current system time if it has changed to assist withAttributeequality (seeAttribute.equals(java.lang.Object)).- Parameters:
overrideVersion- Iftrue, the merge will override the data in the database, independent of version.requestingGatewayAsset- If set this is theGatewayAssetmerging the asset so skip standard checksuserName- 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.IllegalStateExceptionjakarta.validation.ConstraintViolationException
-
delete
- Returns:
trueif the assets were deleted, false if any of the assets still have children and can't be deleted.
-
delete
-
isUserAsset
-
isUserAsset
-
isUserAsset
-
isUserAssets
-
isRealmAsset
Indicates if the specified asset belongs to the specified realm -
isRealmAssets
Indicates if the specified assets belong to the specified realm -
isDescendantAsset
-
isDescendantAssets
-
findUserAssetLinks
-
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
Delete specificUserAssetLinks. -
deleteUserAssetLinks
Delete allUserAssetLinks for the specifiedUser -
storeUserAssetLinks
Create specifiedUserAssetLinks. -
withAssetLock
-
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 theAttributeEvent- Throws:
jakarta.validation.ConstraintViolationException
-
publishModificationEvents
protected void publishModificationEvents(org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) -
toString
- Overrides:
toStringin classorg.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
-
buildOrderByString
-
buildLimitString
-
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
-
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)
-