Browse Source

Implements support notes in RuleChain entity

pull/15121/head
Vladyslav_Prykhodko 7 months ago
parent
commit
db87b489f1
  1. 6
      application/src/main/data/upgrade/basic/schema_update.sql
  2. 4
      common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChain.java
  3. 5
      common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChainMetaData.java
  4. 58
      common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChainNote.java
  5. 1
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  6. 5
      dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleChainEntity.java
  7. 7
      dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java
  8. 1
      dao/src/main/resources/sql/schema-entities.sql

6
application/src/main/data/upgrade/basic/schema_update.sql

@ -14,3 +14,9 @@
-- limitations under the License.
--
-- RULE CHAIN NOTES START
ALTER TABLE rule_chain ADD COLUMN IF NOT EXISTS notes text;
-- RULE CHAIN NOTES END

4
common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChain.java

@ -61,6 +61,9 @@ public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implement
private RuleChainId externalId;
private Long version;
@JsonIgnore
private String notes;
@JsonIgnore
private byte[] configurationBytes;
@ -82,6 +85,7 @@ public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implement
this.setConfiguration(ruleChain.getConfiguration());
this.setExternalId(ruleChain.getExternalId());
this.version = ruleChain.getVersion();
this.notes = ruleChain.getNotes();
}
@Override

5
common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChainMetaData.java

@ -15,6 +15,7 @@
*/
package org.thingsboard.server.common.data.rule;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.thingsboard.server.common.data.HasVersion;
@ -48,6 +49,10 @@ public class RuleChainMetaData implements HasVersion {
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "List of JSON objects that represent connections between rule nodes and other rule chains.")
private List<RuleChainConnectionInfo> ruleChainConnections;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED, description = "List of sticky notes placed on the rule chain canvas")
private List<RuleChainNote> notes;
public void addConnectionInfo(int fromIndex, int toIndex, String type) {
NodeConnectionInfo connectionInfo = new NodeConnectionInfo();
connectionInfo.setFromIndex(fromIndex);

58
common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChainNote.java

@ -0,0 +1,58 @@
/**
* Copyright © 2016-2026 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.common.data.rule;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* Represents a sticky note on the rule chain canvas.
* Notes are purely visual metadata and are stored as part of the rule chain.
*/
@Schema
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RuleChainNote {
@Schema(description = "Unique identifier of the note on the canvas")
private String id;
@Schema(description = "Horizontal position of the note on the canvas, in pixels")
private int x;
@Schema(description = "Vertical position of the note on the canvas, in pixels")
private int y;
@Schema(description = "Width of the note, in pixels")
private int width;
@Schema(description = "Height of the note, in pixels")
private int height;
@Schema(description = "Markdown or HTML content of the note")
private String content;
@Schema(description = "Background color of the note in CSS hex format, e.g. '#FFF9C4'")
private String backgroundColor;
@Schema(description = "Whether to apply the default markdown stylesheet to the note content")
private Boolean applyDefaultMarkdownStyle;
@Schema(description = "Custom CSS styles applied to the note content")
private String markdownCss;
}

1
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -420,6 +420,7 @@ public class ModelConstants {
public static final String RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY = "first_rule_node_id";
public static final String RULE_CHAIN_ROOT_PROPERTY = "root";
public static final String RULE_CHAIN_CONFIGURATION_PROPERTY = "configuration";
public static final String RULE_CHAIN_NOTES_PROPERTY = "notes";
/**
* Rule node constants.

5
dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleChainEntity.java

@ -69,6 +69,9 @@ public class RuleChainEntity extends BaseVersionedEntity<RuleChain> {
@Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY)
private JsonNode additionalInfo;
@Column(name = ModelConstants.RULE_CHAIN_NOTES_PROPERTY, columnDefinition = "TEXT")
private String notes;
@Column(name = ModelConstants.EXTERNAL_ID_PROPERTY)
private UUID externalId;
@ -87,6 +90,7 @@ public class RuleChainEntity extends BaseVersionedEntity<RuleChain> {
this.debugMode = ruleChain.isDebugMode();
this.configuration = ruleChain.getConfiguration();
this.additionalInfo = ruleChain.getAdditionalInfo();
this.notes = ruleChain.getNotes();
if (ruleChain.getExternalId() != null) {
this.externalId = ruleChain.getExternalId().getId();
}
@ -107,6 +111,7 @@ public class RuleChainEntity extends BaseVersionedEntity<RuleChain> {
ruleChain.setDebugMode(debugMode);
ruleChain.setConfiguration(configuration);
ruleChain.setAdditionalInfo(additionalInfo);
ruleChain.setNotes(notes);
if (externalId != null) {
ruleChain.setExternalId(new RuleChainId(externalId));
}

7
dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java

@ -16,6 +16,7 @@
package org.thingsboard.server.dao.rule;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.util.concurrent.FluentFuture;
@ -53,6 +54,7 @@ import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo;
import org.thingsboard.server.common.data.rule.RuleChainData;
import org.thingsboard.server.common.data.rule.RuleChainImportResult;
import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.common.data.rule.RuleChainNote;
import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.common.data.rule.RuleChainUpdateResult;
import org.thingsboard.server.common.data.rule.RuleNode;
@ -316,6 +318,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
if (!relations.isEmpty()) {
relationService.saveRelations(tenantId, relations);
}
ruleChain.setNotes(ruleChainMetaData.getNotes() != null && !ruleChainMetaData.getNotes().isEmpty()
? JacksonUtil.toString(ruleChainMetaData.getNotes()) : null);
ruleChain = ruleChainDao.save(tenantId, ruleChain);
eventPublisher.publishEvent(SaveEntityEvent.builder().tenantId(tenantId).entity(ruleChain)
.entityId(ruleChain.getId()).broadcastEvent(publishSaveEvent).build());
@ -376,6 +380,9 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
Collections.sort(ruleChainMetaData.getConnections(), Comparator.comparingInt(NodeConnectionInfo::getFromIndex)
.thenComparing(NodeConnectionInfo::getToIndex).thenComparing(NodeConnectionInfo::getType));
}
if (ruleChain.getNotes() != null) {
ruleChainMetaData.setNotes(JacksonUtil.fromString(ruleChain.getNotes(), new TypeReference<List<RuleChainNote>>() {}));
}
return ruleChainMetaData;
}

1
dao/src/main/resources/sql/schema-entities.sql

@ -169,6 +169,7 @@ CREATE TABLE IF NOT EXISTS rule_chain (
debug_mode boolean,
tenant_id uuid,
external_id uuid,
notes text,
version BIGINT DEFAULT 1,
CONSTRAINT rule_chain_external_id_unq_key UNIQUE (tenant_id, external_id)
);

Loading…
Cancel
Save