Browse Source
- Extract RuleChainDetailsDao from RuleChainDao to reuse JpaAbstractDao save logic (proper @Version increment, flush, detach) - Reduce notes column size from 10MB to 1MB in schema and migration - Catch "value too long" DB error with user-friendly message - Pass tenantId consistently through the details DAO API - Exclude content/markdownCss from RuleChainNote toString - Add tests: save/load notes, update notes, preserve notes on RuleChain save, remove notes, exceeded size limitpull/15121/head
9 changed files with 300 additions and 24 deletions
@ -0,0 +1,29 @@ |
|||
/** |
|||
* 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.dao.rule; |
|||
|
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChainDetails; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface RuleChainDetailsDao { |
|||
|
|||
RuleChainDetails findById(TenantId tenantId, UUID id); |
|||
|
|||
RuleChainDetails save(TenantId tenantId, RuleChainDetails ruleChainDetails); |
|||
|
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
/** |
|||
* 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.dao.sql.rule; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.exception.ExceptionUtils; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.StringUtils; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChainDetails; |
|||
import org.thingsboard.server.dao.model.sql.RuleChainDetailsEntity; |
|||
import org.thingsboard.server.dao.rule.RuleChainDetailsDao; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
import org.thingsboard.server.exception.DataValidationException; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@SqlDao |
|||
@RequiredArgsConstructor |
|||
public class JpaRuleChainDetailsDao extends JpaAbstractDao<RuleChainDetailsEntity, RuleChainDetails> implements RuleChainDetailsDao { |
|||
|
|||
private final RuleChainDetailsRepository ruleChainDetailsRepository; |
|||
|
|||
@Override |
|||
public RuleChainDetails save(TenantId tenantId, RuleChainDetails ruleChainDetails) { |
|||
try { |
|||
return super.save(tenantId, ruleChainDetails); |
|||
} catch (Exception e) { |
|||
String rootMsg = ExceptionUtils.getRootCauseMessage(e); |
|||
if (StringUtils.contains(rootMsg, "value too long")) { |
|||
throw new DataValidationException("Rule chain notes data is too large. Please reduce the number or size of notes."); |
|||
} |
|||
throw e; |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
protected Class<RuleChainDetailsEntity> getEntityClass() { |
|||
return RuleChainDetailsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected JpaRepository<RuleChainDetailsEntity, UUID> getRepository() { |
|||
return ruleChainDetailsRepository; |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue