com.feingto.cloud.domain.converters.ConditionPersistenceConverters Maven / Gradle / Ivy
package com.feingto.cloud.domain.converters;
import com.feingto.cloud.core.json.JSON;
import com.feingto.cloud.dto.monitor.Condition;
import com.feingto.cloud.dto.monitor.Rule;
import com.feingto.cloud.dto.monitor.RuleGroup;
import org.springframework.util.StringUtils;
import javax.persistence.AttributeConverter;
/**
* Condition 规则表达式持久层转换
*
* @author longfei
*/
public class ConditionPersistenceConverters implements AttributeConverter {
@Override
public String convertToDatabaseColumn(Condition attribute) {
return attribute != null ? JSON.build().obj2json(this.convertCondition(attribute)) : null;
}
@Override
public Condition convertToEntityAttribute(String dbData) {
return StringUtils.hasLength(dbData) ? JSON.build().json2pojo(dbData, Condition.class) : null;
}
private Condition convertCondition(Condition condition) {
condition.getConditions().forEach(this::convertCondition);
for (RuleGroup ruleGroup : condition.getGroups()) {
ruleGroup.getRules().forEach(this::clearLabel);
}
condition.getRules().forEach(this::clearLabel);
return condition;
}
private void clearLabel(Rule rule) {
rule.setPropertyLabel(null);
rule.setElementLabel(null);
rule.setOpLabel(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy