Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Yassmine Mestiri
thingsboard
Commits
98ad3b98
Commit
98ad3b98
authored
Mar 10, 2023
by
Yassmine Mestiri
Browse files
iot
parent
aea55d6d
Pipeline
#2009
failed with stages
in 0 seconds
Changes
273
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 273+
files are displayed.
Plain diff
Email patch
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/RelationMsgConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor
;
import
org.springframework.stereotype.Component
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.server.common.data.relation.EntityRelation
;
import
org.thingsboard.server.gen.edge.v1.RelationUpdateMsg
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
import
org.thingsboard.server.queue.util.TbCoreComponent
;
@Component
@TbCoreComponent
public
class
RelationMsgConstructor
{
public
RelationUpdateMsg
constructRelationUpdatedMsg
(
UpdateMsgType
msgType
,
EntityRelation
entityRelation
)
{
RelationUpdateMsg
.
Builder
builder
=
RelationUpdateMsg
.
newBuilder
()
.
setMsgType
(
msgType
)
.
setFromIdMSB
(
entityRelation
.
getFrom
().
getId
().
getMostSignificantBits
())
.
setFromIdLSB
(
entityRelation
.
getFrom
().
getId
().
getLeastSignificantBits
())
.
setFromEntityType
(
entityRelation
.
getFrom
().
getEntityType
().
name
())
.
setToIdMSB
(
entityRelation
.
getTo
().
getId
().
getMostSignificantBits
())
.
setToIdLSB
(
entityRelation
.
getTo
().
getId
().
getLeastSignificantBits
())
.
setToEntityType
(
entityRelation
.
getTo
().
getEntityType
().
name
())
.
setType
(
entityRelation
.
getType
());
if
(
entityRelation
.
getAdditionalInfo
()
!=
null
)
{
builder
.
setAdditionalInfo
(
JacksonUtil
.
toString
(
entityRelation
.
getAdditionalInfo
()));
}
if
(
entityRelation
.
getTypeGroup
()
!=
null
)
{
builder
.
setTypeGroup
(
entityRelation
.
getTypeGroup
().
name
());
}
return
builder
.
build
();
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/RuleChainMsgConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.server.common.data.id.RuleChainId
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.rule.RuleChain
;
import
org.thingsboard.server.common.data.rule.RuleChainMetaData
;
import
org.thingsboard.server.gen.edge.v1.EdgeVersion
;
import
org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg
;
import
org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
import
org.thingsboard.server.queue.util.TbCoreComponent
;
import
org.thingsboard.server.service.edge.rpc.constructor.rule.RuleChainMetadataConstructor
;
import
org.thingsboard.server.service.edge.rpc.constructor.rule.RuleChainMetadataConstructorFactory
;
@Component
@Slf4j
@TbCoreComponent
public
class
RuleChainMsgConstructor
{
public
RuleChainUpdateMsg
constructRuleChainUpdatedMsg
(
UpdateMsgType
msgType
,
RuleChain
ruleChain
,
boolean
isRoot
)
{
RuleChainUpdateMsg
.
Builder
builder
=
RuleChainUpdateMsg
.
newBuilder
()
.
setMsgType
(
msgType
)
.
setIdMSB
(
ruleChain
.
getId
().
getId
().
getMostSignificantBits
())
.
setIdLSB
(
ruleChain
.
getId
().
getId
().
getLeastSignificantBits
())
.
setName
(
ruleChain
.
getName
())
.
setRoot
(
isRoot
)
.
setDebugMode
(
ruleChain
.
isDebugMode
())
.
setConfiguration
(
JacksonUtil
.
toString
(
ruleChain
.
getConfiguration
()));
if
(
ruleChain
.
getFirstRuleNodeId
()
!=
null
)
{
builder
.
setFirstRuleNodeIdMSB
(
ruleChain
.
getFirstRuleNodeId
().
getId
().
getMostSignificantBits
())
.
setFirstRuleNodeIdLSB
(
ruleChain
.
getFirstRuleNodeId
().
getId
().
getLeastSignificantBits
());
}
return
builder
.
build
();
}
public
RuleChainMetadataUpdateMsg
constructRuleChainMetadataUpdatedMsg
(
TenantId
tenantId
,
UpdateMsgType
msgType
,
RuleChainMetaData
ruleChainMetaData
,
EdgeVersion
edgeVersion
)
{
RuleChainMetadataConstructor
ruleChainMetadataConstructor
=
RuleChainMetadataConstructorFactory
.
getByEdgeVersion
(
edgeVersion
);
return
ruleChainMetadataConstructor
.
constructRuleChainMetadataUpdatedMsg
(
tenantId
,
msgType
,
ruleChainMetaData
);
}
public
RuleChainUpdateMsg
constructRuleChainDeleteMsg
(
RuleChainId
ruleChainId
)
{
return
RuleChainUpdateMsg
.
newBuilder
()
.
setMsgType
(
UpdateMsgType
.
ENTITY_DELETED_RPC_MESSAGE
)
.
setIdMSB
(
ruleChainId
.
getId
().
getMostSignificantBits
())
.
setIdLSB
(
ruleChainId
.
getId
().
getLeastSignificantBits
()).
build
();
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/UserMsgConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor
;
import
org.springframework.stereotype.Component
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.server.common.data.User
;
import
org.thingsboard.server.common.data.id.UserId
;
import
org.thingsboard.server.common.data.security.UserCredentials
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
import
org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg
;
import
org.thingsboard.server.gen.edge.v1.UserUpdateMsg
;
import
org.thingsboard.server.queue.util.TbCoreComponent
;
@Component
@TbCoreComponent
public
class
UserMsgConstructor
{
public
UserUpdateMsg
constructUserUpdatedMsg
(
UpdateMsgType
msgType
,
User
user
)
{
UserUpdateMsg
.
Builder
builder
=
UserUpdateMsg
.
newBuilder
()
.
setMsgType
(
msgType
)
.
setIdMSB
(
user
.
getId
().
getId
().
getMostSignificantBits
())
.
setIdLSB
(
user
.
getId
().
getId
().
getLeastSignificantBits
())
.
setEmail
(
user
.
getEmail
())
.
setAuthority
(
user
.
getAuthority
().
name
());
if
(
user
.
getCustomerId
()
!=
null
)
{
builder
.
setCustomerIdMSB
(
user
.
getCustomerId
().
getId
().
getMostSignificantBits
());
builder
.
setCustomerIdLSB
(
user
.
getCustomerId
().
getId
().
getLeastSignificantBits
());
}
if
(
user
.
getFirstName
()
!=
null
)
{
builder
.
setFirstName
(
user
.
getFirstName
());
}
if
(
user
.
getLastName
()
!=
null
)
{
builder
.
setLastName
(
user
.
getLastName
());
}
if
(
user
.
getAdditionalInfo
()
!=
null
)
{
builder
.
setAdditionalInfo
(
JacksonUtil
.
toString
(
user
.
getAdditionalInfo
()));
}
return
builder
.
build
();
}
public
UserUpdateMsg
constructUserDeleteMsg
(
UserId
userId
)
{
return
UserUpdateMsg
.
newBuilder
()
.
setMsgType
(
UpdateMsgType
.
ENTITY_DELETED_RPC_MESSAGE
)
.
setIdMSB
(
userId
.
getId
().
getMostSignificantBits
())
.
setIdLSB
(
userId
.
getId
().
getLeastSignificantBits
()).
build
();
}
public
UserCredentialsUpdateMsg
constructUserCredentialsUpdatedMsg
(
UserCredentials
userCredentials
)
{
UserCredentialsUpdateMsg
.
Builder
builder
=
UserCredentialsUpdateMsg
.
newBuilder
()
.
setUserIdMSB
(
userCredentials
.
getUserId
().
getId
().
getMostSignificantBits
())
.
setUserIdLSB
(
userCredentials
.
getUserId
().
getId
().
getLeastSignificantBits
())
.
setEnabled
(
userCredentials
.
isEnabled
())
.
setPassword
(
userCredentials
.
getPassword
());
return
builder
.
build
();
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/WidgetTypeMsgConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor
;
import
org.springframework.stereotype.Component
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.id.WidgetTypeId
;
import
org.thingsboard.server.common.data.widget.WidgetTypeDetails
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
import
org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg
;
import
org.thingsboard.server.queue.util.TbCoreComponent
;
@Component
@TbCoreComponent
public
class
WidgetTypeMsgConstructor
{
public
WidgetTypeUpdateMsg
constructWidgetTypeUpdateMsg
(
UpdateMsgType
msgType
,
WidgetTypeDetails
widgetTypeDetails
)
{
WidgetTypeUpdateMsg
.
Builder
builder
=
WidgetTypeUpdateMsg
.
newBuilder
()
.
setMsgType
(
msgType
)
.
setIdMSB
(
widgetTypeDetails
.
getId
().
getId
().
getMostSignificantBits
())
.
setIdLSB
(
widgetTypeDetails
.
getId
().
getId
().
getLeastSignificantBits
());
if
(
widgetTypeDetails
.
getBundleAlias
()
!=
null
)
{
builder
.
setBundleAlias
(
widgetTypeDetails
.
getBundleAlias
());
}
if
(
widgetTypeDetails
.
getAlias
()
!=
null
)
{
builder
.
setAlias
(
widgetTypeDetails
.
getAlias
());
}
if
(
widgetTypeDetails
.
getName
()
!=
null
)
{
builder
.
setName
(
widgetTypeDetails
.
getName
());
}
if
(
widgetTypeDetails
.
getDescriptor
()
!=
null
)
{
builder
.
setDescriptorJson
(
JacksonUtil
.
toString
(
widgetTypeDetails
.
getDescriptor
()));
}
if
(
widgetTypeDetails
.
getTenantId
().
equals
(
TenantId
.
SYS_TENANT_ID
))
{
builder
.
setIsSystem
(
true
);
}
if
(
widgetTypeDetails
.
getImage
()
!=
null
)
{
builder
.
setImage
(
widgetTypeDetails
.
getImage
());
}
if
(
widgetTypeDetails
.
getDescription
()
!=
null
)
{
builder
.
setDescription
(
widgetTypeDetails
.
getDescription
());
}
return
builder
.
build
();
}
public
WidgetTypeUpdateMsg
constructWidgetTypeDeleteMsg
(
WidgetTypeId
widgetTypeId
)
{
return
WidgetTypeUpdateMsg
.
newBuilder
()
.
setMsgType
(
UpdateMsgType
.
ENTITY_DELETED_RPC_MESSAGE
)
.
setIdMSB
(
widgetTypeId
.
getId
().
getMostSignificantBits
())
.
setIdLSB
(
widgetTypeId
.
getId
().
getLeastSignificantBits
())
.
build
();
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/WidgetsBundleMsgConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor
;
import
com.google.protobuf.ByteString
;
import
org.springframework.stereotype.Component
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.id.WidgetsBundleId
;
import
org.thingsboard.server.common.data.widget.WidgetsBundle
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
import
org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg
;
import
org.thingsboard.server.queue.util.TbCoreComponent
;
import
java.nio.charset.StandardCharsets
;
@Component
@TbCoreComponent
public
class
WidgetsBundleMsgConstructor
{
public
WidgetsBundleUpdateMsg
constructWidgetsBundleUpdateMsg
(
UpdateMsgType
msgType
,
WidgetsBundle
widgetsBundle
)
{
WidgetsBundleUpdateMsg
.
Builder
builder
=
WidgetsBundleUpdateMsg
.
newBuilder
()
.
setMsgType
(
msgType
)
.
setIdMSB
(
widgetsBundle
.
getId
().
getId
().
getMostSignificantBits
())
.
setIdLSB
(
widgetsBundle
.
getId
().
getId
().
getLeastSignificantBits
())
.
setTitle
(
widgetsBundle
.
getTitle
())
.
setAlias
(
widgetsBundle
.
getAlias
());
if
(
widgetsBundle
.
getImage
()
!=
null
)
{
builder
.
setImage
(
ByteString
.
copyFrom
(
widgetsBundle
.
getImage
().
getBytes
(
StandardCharsets
.
UTF_8
)));
}
if
(
widgetsBundle
.
getDescription
()
!=
null
)
{
builder
.
setDescription
(
widgetsBundle
.
getDescription
());
}
if
(
widgetsBundle
.
getTenantId
().
equals
(
TenantId
.
SYS_TENANT_ID
))
{
builder
.
setIsSystem
(
true
);
}
return
builder
.
build
();
}
public
WidgetsBundleUpdateMsg
constructWidgetsBundleDeleteMsg
(
WidgetsBundleId
widgetsBundleId
)
{
return
WidgetsBundleUpdateMsg
.
newBuilder
()
.
setMsgType
(
UpdateMsgType
.
ENTITY_DELETED_RPC_MESSAGE
)
.
setIdMSB
(
widgetsBundleId
.
getId
().
getMostSignificantBits
())
.
setIdLSB
(
widgetsBundleId
.
getId
().
getLeastSignificantBits
())
.
build
();
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/rule/AbstractRuleChainMetadataConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor.rule
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.rule.NodeConnectionInfo
;
import
org.thingsboard.server.common.data.rule.RuleChainConnectionInfo
;
import
org.thingsboard.server.common.data.rule.RuleChainMetaData
;
import
org.thingsboard.server.common.data.rule.RuleNode
;
import
org.thingsboard.server.gen.edge.v1.NodeConnectionInfoProto
;
import
org.thingsboard.server.gen.edge.v1.RuleChainConnectionInfoProto
;
import
org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg
;
import
org.thingsboard.server.gen.edge.v1.RuleNodeProto
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.NavigableSet
;
@Slf4j
@AllArgsConstructor
public
abstract
class
AbstractRuleChainMetadataConstructor
implements
RuleChainMetadataConstructor
{
@Override
public
RuleChainMetadataUpdateMsg
constructRuleChainMetadataUpdatedMsg
(
TenantId
tenantId
,
UpdateMsgType
msgType
,
RuleChainMetaData
ruleChainMetaData
)
{
try
{
RuleChainMetadataUpdateMsg
.
Builder
builder
=
RuleChainMetadataUpdateMsg
.
newBuilder
();
builder
.
setRuleChainIdMSB
(
ruleChainMetaData
.
getRuleChainId
().
getId
().
getMostSignificantBits
())
.
setRuleChainIdLSB
(
ruleChainMetaData
.
getRuleChainId
().
getId
().
getLeastSignificantBits
());
constructRuleChainMetadataUpdatedMsg
(
tenantId
,
builder
,
ruleChainMetaData
);
builder
.
setMsgType
(
msgType
);
return
builder
.
build
();
}
catch
(
JsonProcessingException
ex
)
{
log
.
error
(
"Can't construct RuleChainMetadataUpdateMsg"
,
ex
);
}
return
null
;
}
protected
abstract
void
constructRuleChainMetadataUpdatedMsg
(
TenantId
tenantId
,
RuleChainMetadataUpdateMsg
.
Builder
builder
,
RuleChainMetaData
ruleChainMetaData
)
throws
JsonProcessingException
;
protected
List
<
NodeConnectionInfoProto
>
constructConnections
(
List
<
NodeConnectionInfo
>
connections
)
{
List
<
NodeConnectionInfoProto
>
result
=
new
ArrayList
<>();
if
(
connections
!=
null
&&
!
connections
.
isEmpty
())
{
for
(
NodeConnectionInfo
connection
:
connections
)
{
result
.
add
(
constructConnection
(
connection
));
}
}
return
result
;
}
private
NodeConnectionInfoProto
constructConnection
(
NodeConnectionInfo
connection
)
{
return
NodeConnectionInfoProto
.
newBuilder
()
.
setFromIndex
(
connection
.
getFromIndex
())
.
setToIndex
(
connection
.
getToIndex
())
.
setType
(
connection
.
getType
())
.
build
();
}
protected
List
<
RuleNodeProto
>
constructNodes
(
List
<
RuleNode
>
nodes
)
throws
JsonProcessingException
{
List
<
RuleNodeProto
>
result
=
new
ArrayList
<>();
if
(
nodes
!=
null
&&
!
nodes
.
isEmpty
())
{
for
(
RuleNode
node
:
nodes
)
{
result
.
add
(
constructNode
(
node
));
}
}
return
result
;
}
private
RuleNodeProto
constructNode
(
RuleNode
node
)
throws
JsonProcessingException
{
return
RuleNodeProto
.
newBuilder
()
.
setIdMSB
(
node
.
getId
().
getId
().
getMostSignificantBits
())
.
setIdLSB
(
node
.
getId
().
getId
().
getLeastSignificantBits
())
.
setType
(
node
.
getType
())
.
setName
(
node
.
getName
())
.
setDebugMode
(
node
.
isDebugMode
())
.
setConfiguration
(
JacksonUtil
.
OBJECT_MAPPER
.
writeValueAsString
(
node
.
getConfiguration
()))
.
setAdditionalInfo
(
JacksonUtil
.
OBJECT_MAPPER
.
writeValueAsString
(
node
.
getAdditionalInfo
()))
.
build
();
}
protected
List
<
RuleChainConnectionInfoProto
>
constructRuleChainConnections
(
List
<
RuleChainConnectionInfo
>
ruleChainConnections
,
NavigableSet
<
Integer
>
removedNodeIndexes
)
throws
JsonProcessingException
{
List
<
RuleChainConnectionInfoProto
>
result
=
new
ArrayList
<>();
if
(
ruleChainConnections
!=
null
&&
!
ruleChainConnections
.
isEmpty
())
{
for
(
RuleChainConnectionInfo
ruleChainConnectionInfo
:
ruleChainConnections
)
{
if
(!
removedNodeIndexes
.
isEmpty
())
{
// 3_3_0 only
int
fromIndex
=
ruleChainConnectionInfo
.
getFromIndex
();
// decrease index because of removed nodes
for
(
Integer
removedIndex
:
removedNodeIndexes
)
{
if
(
fromIndex
>
removedIndex
)
{
fromIndex
=
fromIndex
-
1
;
}
}
ruleChainConnectionInfo
.
setFromIndex
(
fromIndex
);
ObjectNode
additionalInfo
=
(
ObjectNode
)
ruleChainConnectionInfo
.
getAdditionalInfo
();
if
(
additionalInfo
.
get
(
"ruleChainNodeId"
)
==
null
)
{
additionalInfo
.
put
(
"ruleChainNodeId"
,
"rule-chain-node-UNDEFINED"
);
}
}
result
.
add
(
constructRuleChainConnection
(
ruleChainConnectionInfo
));
}
}
return
result
;
}
private
RuleChainConnectionInfoProto
constructRuleChainConnection
(
RuleChainConnectionInfo
ruleChainConnectionInfo
)
throws
JsonProcessingException
{
return
RuleChainConnectionInfoProto
.
newBuilder
()
.
setFromIndex
(
ruleChainConnectionInfo
.
getFromIndex
())
.
setTargetRuleChainIdMSB
(
ruleChainConnectionInfo
.
getTargetRuleChainId
().
getId
().
getMostSignificantBits
())
.
setTargetRuleChainIdLSB
(
ruleChainConnectionInfo
.
getTargetRuleChainId
().
getId
().
getLeastSignificantBits
())
.
setType
(
ruleChainConnectionInfo
.
getType
())
.
setAdditionalInfo
(
JacksonUtil
.
OBJECT_MAPPER
.
writeValueAsString
(
ruleChainConnectionInfo
.
getAdditionalInfo
()))
.
build
();
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/rule/RuleChainMetadataConstructor.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor.rule
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.rule.RuleChainMetaData
;
import
org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg
;
import
org.thingsboard.server.gen.edge.v1.UpdateMsgType
;
public
interface
RuleChainMetadataConstructor
{
RuleChainMetadataUpdateMsg
constructRuleChainMetadataUpdatedMsg
(
TenantId
tenantId
,
UpdateMsgType
msgType
,
RuleChainMetaData
ruleChainMetaData
);
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/rule/RuleChainMetadataConstructorFactory.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor.rule
;
import
org.thingsboard.server.gen.edge.v1.EdgeVersion
;
public
final
class
RuleChainMetadataConstructorFactory
{
public
static
RuleChainMetadataConstructor
getByEdgeVersion
(
EdgeVersion
edgeVersion
)
{
switch
(
edgeVersion
)
{
case
V_3_3_0:
return
new
RuleChainMetadataConstructorV330
();
case
V_3_3_3:
case
V_3_4_0:
default
:
return
new
RuleChainMetadataConstructorV340
();
}
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/rule/RuleChainMetadataConstructorV330.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor.rule
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.rule.engine.flow.TbRuleChainInputNode
;
import
org.thingsboard.rule.engine.flow.TbRuleChainInputNodeConfiguration
;
import
org.thingsboard.rule.engine.flow.TbRuleChainOutputNode
;
import
org.thingsboard.server.common.data.id.RuleChainId
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.rule.NodeConnectionInfo
;
import
org.thingsboard.server.common.data.rule.RuleChainConnectionInfo
;
import
org.thingsboard.server.common.data.rule.RuleChainMetaData
;
import
org.thingsboard.server.common.data.rule.RuleNode
;
import
org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.NavigableSet
;
import
java.util.TreeSet
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
@Slf4j
public
class
RuleChainMetadataConstructorV330
extends
AbstractRuleChainMetadataConstructor
{
private
static
final
String
RULE_CHAIN_INPUT_NODE
=
TbRuleChainInputNode
.
class
.
getName
();
private
static
final
String
TB_RULE_CHAIN_OUTPUT_NODE
=
TbRuleChainOutputNode
.
class
.
getName
();
@Override
protected
void
constructRuleChainMetadataUpdatedMsg
(
TenantId
tenantId
,
RuleChainMetadataUpdateMsg
.
Builder
builder
,
RuleChainMetaData
ruleChainMetaData
)
throws
JsonProcessingException
{
List
<
RuleNode
>
supportedNodes
=
filterNodes
(
ruleChainMetaData
.
getNodes
());
NavigableSet
<
Integer
>
removedNodeIndexes
=
getRemovedNodeIndexes
(
ruleChainMetaData
.
getNodes
(),
ruleChainMetaData
.
getConnections
());
List
<
NodeConnectionInfo
>
connections
=
filterConnections
(
ruleChainMetaData
.
getNodes
(),
ruleChainMetaData
.
getConnections
(),
removedNodeIndexes
);
List
<
RuleChainConnectionInfo
>
ruleChainConnections
=
new
ArrayList
<>();
if
(
ruleChainMetaData
.
getRuleChainConnections
()
!=
null
)
{
ruleChainConnections
.
addAll
(
ruleChainMetaData
.
getRuleChainConnections
());
}
ruleChainConnections
.
addAll
(
addRuleChainConnections
(
ruleChainMetaData
.
getNodes
(),
ruleChainMetaData
.
getConnections
()));
builder
.
addAllNodes
(
constructNodes
(
supportedNodes
))
.
addAllConnections
(
constructConnections
(
connections
))
.
addAllRuleChainConnections
(
constructRuleChainConnections
(
ruleChainConnections
,
removedNodeIndexes
));
if
(
ruleChainMetaData
.
getFirstNodeIndex
()
!=
null
)
{
Integer
firstNodeIndex
=
ruleChainMetaData
.
getFirstNodeIndex
();
// decrease index because of removed nodes
for
(
Integer
removedIndex
:
removedNodeIndexes
)
{
if
(
firstNodeIndex
>
removedIndex
)
{
firstNodeIndex
=
firstNodeIndex
-
1
;
}
}
builder
.
setFirstNodeIndex
(
firstNodeIndex
);
}
else
{
builder
.
setFirstNodeIndex
(-
1
);
}
}
private
NavigableSet
<
Integer
>
getRemovedNodeIndexes
(
List
<
RuleNode
>
nodes
,
List
<
NodeConnectionInfo
>
connections
)
{
TreeSet
<
Integer
>
removedIndexes
=
new
TreeSet
<>();
for
(
NodeConnectionInfo
connection
:
connections
)
{
for
(
int
i
=
0
;
i
<
nodes
.
size
();
i
++)
{
RuleNode
node
=
nodes
.
get
(
i
);
if
(
node
.
getType
().
equalsIgnoreCase
(
RULE_CHAIN_INPUT_NODE
)
||
node
.
getType
().
equalsIgnoreCase
(
TB_RULE_CHAIN_OUTPUT_NODE
))
{
if
(
connection
.
getFromIndex
()
==
i
||
connection
.
getToIndex
()
==
i
)
{
removedIndexes
.
add
(
i
);
}
}
}
}
return
removedIndexes
.
descendingSet
();
}
private
List
<
NodeConnectionInfo
>
filterConnections
(
List
<
RuleNode
>
nodes
,
List
<
NodeConnectionInfo
>
connections
,
NavigableSet
<
Integer
>
removedNodeIndexes
)
{
List
<
NodeConnectionInfo
>
result
=
new
ArrayList
<>();
if
(
connections
!=
null
)
{
result
=
connections
.
stream
().
filter
(
conn
->
{
for
(
int
i
=
0
;
i
<
nodes
.
size
();
i
++)
{
RuleNode
node
=
nodes
.
get
(
i
);
if
(
node
.
getType
().
equalsIgnoreCase
(
RULE_CHAIN_INPUT_NODE
)
||
node
.
getType
().
equalsIgnoreCase
(
TB_RULE_CHAIN_OUTPUT_NODE
))
{
if
(
conn
.
getFromIndex
()
==
i
||
conn
.
getToIndex
()
==
i
)
{
return
false
;
}
}
}
return
true
;
}).
map
(
conn
->
{
NodeConnectionInfo
newConn
=
new
NodeConnectionInfo
();
newConn
.
setFromIndex
(
conn
.
getFromIndex
());
newConn
.
setToIndex
(
conn
.
getToIndex
());
newConn
.
setType
(
conn
.
getType
());
return
newConn
;
}).
collect
(
Collectors
.
toList
());
}
// decrease index because of removed nodes
for
(
Integer
removedIndex
:
removedNodeIndexes
)
{
for
(
NodeConnectionInfo
newConn
:
result
)
{
if
(
newConn
.
getToIndex
()
>
removedIndex
)
{
newConn
.
setToIndex
(
newConn
.
getToIndex
()
-
1
);
}
if
(
newConn
.
getFromIndex
()
>
removedIndex
)
{
newConn
.
setFromIndex
(
newConn
.
getFromIndex
()
-
1
);
}
}
}
return
result
;
}
private
List
<
RuleNode
>
filterNodes
(
List
<
RuleNode
>
nodes
)
{
List
<
RuleNode
>
result
=
new
ArrayList
<>();
for
(
RuleNode
node
:
nodes
)
{
if
(
RULE_CHAIN_INPUT_NODE
.
equals
(
node
.
getType
())
||
TB_RULE_CHAIN_OUTPUT_NODE
.
equals
(
node
.
getType
()))
{
log
.
trace
(
"Skipping not supported rule node {}"
,
node
);
}
else
{
result
.
add
(
node
);
}
}
return
result
;
}
private
List
<
RuleChainConnectionInfo
>
addRuleChainConnections
(
List
<
RuleNode
>
nodes
,
List
<
NodeConnectionInfo
>
connections
)
{
List
<
RuleChainConnectionInfo
>
result
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
nodes
.
size
();
i
++)
{
RuleNode
node
=
nodes
.
get
(
i
);
if
(
node
.
getType
().
equalsIgnoreCase
(
RULE_CHAIN_INPUT_NODE
))
{
for
(
NodeConnectionInfo
connection
:
connections
)
{
if
(
connection
.
getToIndex
()
==
i
)
{
RuleChainConnectionInfo
e
=
new
RuleChainConnectionInfo
();
e
.
setFromIndex
(
connection
.
getFromIndex
());
TbRuleChainInputNodeConfiguration
configuration
=
JacksonUtil
.
treeToValue
(
node
.
getConfiguration
(),
TbRuleChainInputNodeConfiguration
.
class
);
e
.
setTargetRuleChainId
(
new
RuleChainId
(
UUID
.
fromString
(
configuration
.
getRuleChainId
())));
e
.
setAdditionalInfo
(
node
.
getAdditionalInfo
());
e
.
setType
(
connection
.
getType
());
result
.
add
(
e
);
}
}
}
}
return
result
;
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/rule/RuleChainMetadataConstructorV340.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.constructor.rule
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.rule.RuleChainMetaData
;
import
org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg
;
import
java.util.TreeSet
;
@Slf4j
public
class
RuleChainMetadataConstructorV340
extends
AbstractRuleChainMetadataConstructor
{
@Override
protected
void
constructRuleChainMetadataUpdatedMsg
(
TenantId
tenantId
,
RuleChainMetadataUpdateMsg
.
Builder
builder
,
RuleChainMetaData
ruleChainMetaData
)
throws
JsonProcessingException
{
builder
.
addAllNodes
(
constructNodes
(
ruleChainMetaData
.
getNodes
()))
.
addAllConnections
(
constructConnections
(
ruleChainMetaData
.
getConnections
()))
.
addAllRuleChainConnections
(
constructRuleChainConnections
(
ruleChainMetaData
.
getRuleChainConnections
(),
new
TreeSet
<>()));
if
(
ruleChainMetaData
.
getFirstNodeIndex
()
!=
null
)
{
builder
.
setFirstNodeIndex
(
ruleChainMetaData
.
getFirstNodeIndex
());
}
else
{
builder
.
setFirstNodeIndex
(-
1
);
}
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/AdminSettingsEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
com.datastax.oss.driver.api.core.uuid.Uuids
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.text.WordUtils
;
import
org.thingsboard.common.util.JacksonUtil
;
import
org.thingsboard.server.common.data.AdminSettings
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.StringUtils
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.AdminSettingsId
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.settings.AdminSettingsService
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
@AllArgsConstructor
@Slf4j
public
class
AdminSettingsEdgeEventFetcher
implements
EdgeEventFetcher
{
private
final
AdminSettingsService
adminSettingsService
;
private
final
Configuration
freemarkerConfig
;
private
static
final
Pattern
startPattern
=
Pattern
.
compile
(
"<div class=\"content\".*?>"
);
private
static
final
Pattern
endPattern
=
Pattern
.
compile
(
"<div class=\"footer\".*?>"
);
private
static
final
List
<
String
>
templatesNames
=
Arrays
.
asList
(
"account.activated.ftl"
,
"account.lockout.ftl"
,
"activation.ftl"
,
"password.was.reset.ftl"
,
"reset.password.ftl"
,
"test.ftl"
);
// TODO: @voba fix format of next templates
// "state.disabled.ftl",
// "state.enabled.ftl",
// "state.warning.ftl",
@Override
public
PageLink
getPageLink
(
int
pageSize
)
{
return
null
;
}
@Override
public
PageData
<
EdgeEvent
>
fetchEdgeEvents
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
throws
Exception
{
List
<
EdgeEvent
>
result
=
new
ArrayList
<>();
AdminSettings
systemMailSettings
=
adminSettingsService
.
findAdminSettingsByKey
(
TenantId
.
SYS_TENANT_ID
,
"mail"
);
result
.
add
(
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
ADMIN_SETTINGS
,
EdgeEventActionType
.
UPDATED
,
null
,
JacksonUtil
.
OBJECT_MAPPER
.
valueToTree
(
systemMailSettings
)));
AdminSettings
tenantMailSettings
=
convertToTenantAdminSettings
(
tenantId
,
systemMailSettings
.
getKey
(),
(
ObjectNode
)
systemMailSettings
.
getJsonValue
());
result
.
add
(
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
ADMIN_SETTINGS
,
EdgeEventActionType
.
UPDATED
,
null
,
JacksonUtil
.
OBJECT_MAPPER
.
valueToTree
(
tenantMailSettings
)));
AdminSettings
systemMailTemplates
=
loadMailTemplates
();
result
.
add
(
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
ADMIN_SETTINGS
,
EdgeEventActionType
.
UPDATED
,
null
,
JacksonUtil
.
OBJECT_MAPPER
.
valueToTree
(
systemMailTemplates
)));
AdminSettings
tenantMailTemplates
=
convertToTenantAdminSettings
(
tenantId
,
systemMailTemplates
.
getKey
(),
(
ObjectNode
)
systemMailTemplates
.
getJsonValue
());
result
.
add
(
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
ADMIN_SETTINGS
,
EdgeEventActionType
.
UPDATED
,
null
,
JacksonUtil
.
OBJECT_MAPPER
.
valueToTree
(
tenantMailTemplates
)));
// return PageData object to be in sync with other fetchers
return
new
PageData
<>(
result
,
1
,
result
.
size
(),
false
);
}
private
AdminSettings
loadMailTemplates
()
throws
Exception
{
Map
<
String
,
Object
>
mailTemplates
=
new
HashMap
<>();
for
(
String
templatesName
:
templatesNames
)
{
Template
template
=
freemarkerConfig
.
getTemplate
(
templatesName
);
if
(
template
!=
null
)
{
String
name
=
validateName
(
template
.
getName
());
Map
<
String
,
String
>
mailTemplate
=
getMailTemplateFromFile
(
template
.
toString
());
if
(
mailTemplate
!=
null
)
{
mailTemplates
.
put
(
name
,
mailTemplate
);
}
else
{
log
.
error
(
"Can't load mail template from file {}"
,
template
.
getName
());
}
}
}
AdminSettings
adminSettings
=
new
AdminSettings
();
adminSettings
.
setId
(
new
AdminSettingsId
(
Uuids
.
timeBased
()));
adminSettings
.
setKey
(
"mailTemplates"
);
adminSettings
.
setJsonValue
(
JacksonUtil
.
OBJECT_MAPPER
.
convertValue
(
mailTemplates
,
JsonNode
.
class
));
return
adminSettings
;
}
private
Map
<
String
,
String
>
getMailTemplateFromFile
(
String
stringTemplate
)
{
Map
<
String
,
String
>
mailTemplate
=
new
HashMap
<>();
Matcher
start
=
startPattern
.
matcher
(
stringTemplate
);
Matcher
end
=
endPattern
.
matcher
(
stringTemplate
);
if
(
start
.
find
()
&&
end
.
find
())
{
String
body
=
StringUtils
.
substringBetween
(
stringTemplate
,
start
.
group
(),
end
.
group
()).
replaceAll
(
"\t"
,
""
);
String
subject
=
StringUtils
.
substringBetween
(
body
,
"<h2>"
,
"</h2>"
);
mailTemplate
.
put
(
"subject"
,
subject
);
mailTemplate
.
put
(
"body"
,
body
);
}
else
{
return
null
;
}
return
mailTemplate
;
}
private
String
validateName
(
String
name
)
throws
Exception
{
StringBuilder
nameBuilder
=
new
StringBuilder
();
name
=
name
.
replace
(
".ftl"
,
""
);
String
[]
nameParts
=
name
.
split
(
"\\."
);
if
(
nameParts
.
length
>=
1
)
{
nameBuilder
.
append
(
nameParts
[
0
]);
for
(
int
i
=
1
;
i
<
nameParts
.
length
;
i
++)
{
String
word
=
WordUtils
.
capitalize
(
nameParts
[
i
]);
nameBuilder
.
append
(
word
);
}
return
nameBuilder
.
toString
();
}
else
{
throw
new
Exception
(
"Error during filename validation"
);
}
}
private
AdminSettings
convertToTenantAdminSettings
(
TenantId
tenantId
,
String
key
,
ObjectNode
jsonValue
)
{
AdminSettings
tenantMailSettings
=
new
AdminSettings
();
tenantMailSettings
.
setTenantId
(
tenantId
);
jsonValue
.
put
(
"useSystemMailSettings"
,
true
);
tenantMailSettings
.
setJsonValue
(
jsonValue
);
tenantMailSettings
.
setKey
(
key
);
return
tenantMailSettings
;
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/AssetProfilesEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.asset.AssetProfile
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.asset.AssetProfileService
;
@AllArgsConstructor
@Slf4j
public
class
AssetProfilesEdgeEventFetcher
extends
BasePageableEdgeEventFetcher
<
AssetProfile
>
{
private
final
AssetProfileService
assetProfileService
;
@Override
PageData
<
AssetProfile
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
return
assetProfileService
.
findAssetProfiles
(
tenantId
,
pageLink
);
}
@Override
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
AssetProfile
assetProfile
)
{
return
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
ASSET_PROFILE
,
EdgeEventActionType
.
ADDED
,
assetProfile
.
getId
(),
null
);
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/AssetsEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.asset.Asset
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.asset.AssetService
;
@AllArgsConstructor
@Slf4j
public
class
AssetsEdgeEventFetcher
extends
BasePageableEdgeEventFetcher
<
Asset
>
{
private
final
AssetService
assetService
;
@Override
PageData
<
Asset
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
return
assetService
.
findAssetsByTenantIdAndEdgeId
(
tenantId
,
edge
.
getId
(),
pageLink
);
}
@Override
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
Asset
asset
)
{
return
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
ASSET
,
EdgeEventActionType
.
ADDED
,
asset
.
getId
(),
null
);
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/BasePageableEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.common.data.page.SortOrder
;
import
java.util.ArrayList
;
import
java.util.List
;
@Slf4j
public
abstract
class
BasePageableEdgeEventFetcher
<
T
>
implements
EdgeEventFetcher
{
@Override
public
PageLink
getPageLink
(
int
pageSize
)
{
return
new
PageLink
(
pageSize
);
}
@Override
public
PageData
<
EdgeEvent
>
fetchEdgeEvents
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
log
.
trace
(
"[{}] start fetching edge events [{}]"
,
tenantId
,
edge
.
getId
());
PageData
<
T
>
pageData
=
fetchPageData
(
tenantId
,
edge
,
pageLink
);
List
<
EdgeEvent
>
result
=
new
ArrayList
<>();
if
(!
pageData
.
getData
().
isEmpty
())
{
for
(
T
entity
:
pageData
.
getData
())
{
result
.
add
(
constructEdgeEvent
(
tenantId
,
edge
,
entity
));
}
}
return
new
PageData
<>(
result
,
pageData
.
getTotalPages
(),
pageData
.
getTotalElements
(),
pageData
.
hasNext
());
}
abstract
PageData
<
T
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
);
abstract
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
T
entity
);
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/BaseUsersEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.User
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.user.UserService
;
@Slf4j
@AllArgsConstructor
public
abstract
class
BaseUsersEdgeEventFetcher
extends
BasePageableEdgeEventFetcher
<
User
>
{
protected
final
UserService
userService
;
@Override
PageData
<
User
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
return
findUsers
(
tenantId
,
pageLink
);
}
@Override
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
User
user
)
{
return
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
USER
,
EdgeEventActionType
.
ADDED
,
user
.
getId
(),
null
);
}
protected
abstract
PageData
<
User
>
findUsers
(
TenantId
tenantId
,
PageLink
pageLink
);
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/BaseWidgetsBundlesEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.common.data.widget.WidgetsBundle
;
import
org.thingsboard.server.dao.widget.WidgetsBundleService
;
@Slf4j
@AllArgsConstructor
public
abstract
class
BaseWidgetsBundlesEdgeEventFetcher
extends
BasePageableEdgeEventFetcher
<
WidgetsBundle
>
{
protected
final
WidgetsBundleService
widgetsBundleService
;
@Override
PageData
<
WidgetsBundle
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
return
findWidgetsBundles
(
tenantId
,
pageLink
);
}
@Override
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
WidgetsBundle
widgetsBundle
)
{
return
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
WIDGETS_BUNDLE
,
EdgeEventActionType
.
ADDED
,
widgetsBundle
.
getId
(),
null
);
}
protected
abstract
PageData
<
WidgetsBundle
>
findWidgetsBundles
(
TenantId
tenantId
,
PageLink
pageLink
);
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/CustomerEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
java.util.ArrayList
;
import
java.util.List
;
@Slf4j
@AllArgsConstructor
public
class
CustomerEdgeEventFetcher
implements
EdgeEventFetcher
{
@Override
public
PageLink
getPageLink
(
int
pageSize
)
{
return
null
;
}
@Override
public
PageData
<
EdgeEvent
>
fetchEdgeEvents
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
List
<
EdgeEvent
>
result
=
new
ArrayList
<>();
result
.
add
(
EdgeUtils
.
constructEdgeEvent
(
edge
.
getTenantId
(),
edge
.
getId
(),
EdgeEventType
.
CUSTOMER
,
EdgeEventActionType
.
ADDED
,
edge
.
getCustomerId
(),
null
));
// @voba - returns PageData object to be in sync with other fetchers
return
new
PageData
<>(
result
,
1
,
result
.
size
(),
false
);
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/CustomerUsersEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
org.thingsboard.server.common.data.User
;
import
org.thingsboard.server.common.data.id.CustomerId
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.user.UserService
;
public
class
CustomerUsersEdgeEventFetcher
extends
BaseUsersEdgeEventFetcher
{
private
final
CustomerId
customerId
;
public
CustomerUsersEdgeEventFetcher
(
UserService
userService
,
CustomerId
customerId
)
{
super
(
userService
);
this
.
customerId
=
customerId
;
}
@Override
protected
PageData
<
User
>
findUsers
(
TenantId
tenantId
,
PageLink
pageLink
)
{
return
userService
.
findCustomerUsers
(
tenantId
,
customerId
,
pageLink
);
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/DashboardsEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.DashboardInfo
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.dashboard.DashboardService
;
@AllArgsConstructor
@Slf4j
public
class
DashboardsEdgeEventFetcher
extends
BasePageableEdgeEventFetcher
<
DashboardInfo
>
{
private
final
DashboardService
dashboardService
;
@Override
PageData
<
DashboardInfo
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
return
dashboardService
.
findDashboardsByTenantIdAndEdgeId
(
tenantId
,
edge
.
getId
(),
pageLink
);
}
@Override
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
DashboardInfo
dashboardInfo
)
{
return
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
DASHBOARD
,
EdgeEventActionType
.
ADDED
,
dashboardInfo
.
getId
(),
null
);
}
}
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/DeviceProfilesEdgeEventFetcher.java
0 → 100644
View file @
98ad3b98
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.thingsboard.server.service.edge.rpc.fetch
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.thingsboard.server.common.data.DeviceProfile
;
import
org.thingsboard.server.common.data.EdgeUtils
;
import
org.thingsboard.server.common.data.edge.Edge
;
import
org.thingsboard.server.common.data.edge.EdgeEvent
;
import
org.thingsboard.server.common.data.edge.EdgeEventActionType
;
import
org.thingsboard.server.common.data.edge.EdgeEventType
;
import
org.thingsboard.server.common.data.id.TenantId
;
import
org.thingsboard.server.common.data.page.PageData
;
import
org.thingsboard.server.common.data.page.PageLink
;
import
org.thingsboard.server.dao.device.DeviceProfileService
;
@AllArgsConstructor
@Slf4j
public
class
DeviceProfilesEdgeEventFetcher
extends
BasePageableEdgeEventFetcher
<
DeviceProfile
>
{
private
final
DeviceProfileService
deviceProfileService
;
@Override
PageData
<
DeviceProfile
>
fetchPageData
(
TenantId
tenantId
,
Edge
edge
,
PageLink
pageLink
)
{
return
deviceProfileService
.
findDeviceProfiles
(
tenantId
,
pageLink
);
}
@Override
EdgeEvent
constructEdgeEvent
(
TenantId
tenantId
,
Edge
edge
,
DeviceProfile
deviceProfile
)
{
return
EdgeUtils
.
constructEdgeEvent
(
tenantId
,
edge
.
getId
(),
EdgeEventType
.
DEVICE_PROFILE
,
EdgeEventActionType
.
ADDED
,
deviceProfile
.
getId
(),
null
);
}
}
Prev
1
…
8
9
10
11
12
13
14
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment