Fix equals method for CF
This commit is contained in:
parent
cb8b7bbbeb
commit
8f1fff61df
@ -144,6 +144,9 @@ public class DefaultCalculatedFieldCache implements CalculatedFieldCache {
|
|||||||
calculatedFieldFetchLock.lock();
|
calculatedFieldFetchLock.lock();
|
||||||
try {
|
try {
|
||||||
CalculatedField calculatedField = calculatedFieldService.findById(tenantId, calculatedFieldId);
|
CalculatedField calculatedField = calculatedFieldService.findById(tenantId, calculatedFieldId);
|
||||||
|
if (calculatedField == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
EntityId cfEntityId = calculatedField.getEntityId();
|
EntityId cfEntityId = calculatedField.getEntityId();
|
||||||
|
|
||||||
calculatedFields.put(calculatedFieldId, calculatedField);
|
calculatedFields.put(calculatedFieldId, calculatedField);
|
||||||
|
|||||||
@ -31,7 +31,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
|
|||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
||||||
import org.thingsboard.server.common.data.sync.ie.EntityImportResult;
|
import org.thingsboard.server.common.data.sync.ie.EntityImportResult;
|
||||||
import org.thingsboard.server.common.data.util.ThrowingRunnable;
|
import org.thingsboard.server.common.data.util.ThrowingRunnable;
|
||||||
import org.thingsboard.server.dao.cf.CalculatedFieldService;
|
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
import org.thingsboard.server.dao.relation.RelationService;
|
import org.thingsboard.server.dao.relation.RelationService;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
@ -62,7 +61,6 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
|||||||
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
|
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
|
||||||
|
|
||||||
private final RelationService relationService;
|
private final RelationService relationService;
|
||||||
private final CalculatedFieldService calculatedFieldService;
|
|
||||||
private final RateLimitService rateLimitService;
|
private final RateLimitService rateLimitService;
|
||||||
private final TbLogEntityActionService logEntityActionService;
|
private final TbLogEntityActionService logEntityActionService;
|
||||||
|
|
||||||
|
|||||||
@ -621,6 +621,7 @@ public class VersionControlTest extends AbstractControllerTest {
|
|||||||
assertThat(importedField.getName()).isEqualTo(deviceCalculatedField.getName());
|
assertThat(importedField.getName()).isEqualTo(deviceCalculatedField.getName());
|
||||||
assertThat(importedField.getType()).isEqualTo(deviceCalculatedField.getType());
|
assertThat(importedField.getType()).isEqualTo(deviceCalculatedField.getType());
|
||||||
assertThat(importedField.getId()).isNotEqualTo(deviceCalculatedField.getId());
|
assertThat(importedField.getId()).isNotEqualTo(deviceCalculatedField.getId());
|
||||||
|
assertThat(importedField.getConfiguration().getArguments().get("T").getRefEntityId()).isEqualTo(importedAsset.getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
List<CalculatedField> importedAssetCalculatedFields = findCalculatedFieldsByEntityId(importedAsset.getId());
|
List<CalculatedField> importedAssetCalculatedFields = findCalculatedFieldsByEntityId(importedAsset.getId());
|
||||||
@ -629,6 +630,7 @@ public class VersionControlTest extends AbstractControllerTest {
|
|||||||
assertThat(importedField.getName()).isEqualTo(assetCalculatedField.getName());
|
assertThat(importedField.getName()).isEqualTo(assetCalculatedField.getName());
|
||||||
assertThat(importedField.getType()).isEqualTo(assetCalculatedField.getType());
|
assertThat(importedField.getType()).isEqualTo(assetCalculatedField.getType());
|
||||||
assertThat(importedField.getId()).isNotEqualTo(assetCalculatedField.getId());
|
assertThat(importedField.getId()).isNotEqualTo(assetCalculatedField.getId());
|
||||||
|
assertThat(importedField.getConfiguration().getArguments().get("T").getRefEntityId()).isEqualTo(importedDevice.getId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.thingsboard.server.common.data.BaseData;
|
import org.thingsboard.server.common.data.BaseData;
|
||||||
@ -37,10 +36,10 @@ import org.thingsboard.server.common.data.validation.Length;
|
|||||||
import org.thingsboard.server.common.data.validation.NoXss;
|
import org.thingsboard.server.common.data.validation.NoXss;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Schema
|
@Schema
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class CalculatedField extends BaseData<CalculatedFieldId> implements HasName, HasTenantId, HasVersion, HasDebugSettings {
|
public class CalculatedField extends BaseData<CalculatedFieldId> implements HasName, HasTenantId, HasVersion, HasDebugSettings {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
@ -112,6 +111,48 @@ public class CalculatedField extends BaseData<CalculatedFieldId> implements HasN
|
|||||||
return super.getCreatedTime();
|
return super.getCreatedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getter is ignored for serialization
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isDebugMode() {
|
||||||
|
return debugMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter is annotated for deserialization
|
||||||
|
@JsonSetter
|
||||||
|
public void setDebugMode(boolean debugMode) {
|
||||||
|
this.debugMode = debugMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof CalculatedField that)) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
return Objects.equals(tenantId, that.tenantId) &&
|
||||||
|
Objects.equals(entityId, that.entityId) &&
|
||||||
|
Objects.equals(name, that.name) &&
|
||||||
|
Objects.equals(debugSettings, that.debugSettings) &&
|
||||||
|
Objects.equals(configuration, that.configuration) &&
|
||||||
|
type == that.type && debugMode == that.debugMode &&
|
||||||
|
configurationVersion == that.configurationVersion &&
|
||||||
|
Objects.equals(version, that.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + Objects.hashCode(tenantId);
|
||||||
|
result = 31 * result + Objects.hashCode(entityId);
|
||||||
|
result = 31 * result + Objects.hashCode(type);
|
||||||
|
result = 31 * result + Objects.hashCode(name);
|
||||||
|
result = 31 * result + Boolean.hashCode(debugMode);
|
||||||
|
result = 31 * result + Objects.hashCode(debugSettings);
|
||||||
|
result = 31 * result + Integer.hashCode(configurationVersion);
|
||||||
|
result = 31 * result + Objects.hashCode(configuration);
|
||||||
|
result = 31 * result + Objects.hashCode(version);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringBuilder()
|
return new StringBuilder()
|
||||||
@ -128,16 +169,4 @@ public class CalculatedField extends BaseData<CalculatedFieldId> implements HasN
|
|||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter is ignored for serialization
|
|
||||||
@JsonIgnore
|
|
||||||
public boolean isDebugMode() {
|
|
||||||
return debugMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setter is annotated for deserialization
|
|
||||||
@JsonSetter
|
|
||||||
public void setDebugMode(boolean debugMode) {
|
|
||||||
this.debugMode = debugMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,13 +16,16 @@
|
|||||||
package org.thingsboard.server.common.data.cf.configuration;
|
package org.thingsboard.server.common.data.cf.configuration;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import org.thingsboard.server.common.data.cf.CalculatedFieldType;
|
import org.thingsboard.server.common.data.cf.CalculatedFieldType;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class ScriptCalculatedFieldConfiguration extends BaseCalculatedFieldConfiguration implements CalculatedFieldConfiguration {
|
public class ScriptCalculatedFieldConfiguration extends BaseCalculatedFieldConfiguration implements CalculatedFieldConfiguration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatedFieldType getType() {
|
public CalculatedFieldType getType() {
|
||||||
return CalculatedFieldType.SCRIPT;
|
return CalculatedFieldType.SCRIPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,11 @@
|
|||||||
package org.thingsboard.server.common.data.cf.configuration;
|
package org.thingsboard.server.common.data.cf.configuration;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import org.thingsboard.server.common.data.cf.CalculatedFieldType;
|
import org.thingsboard.server.common.data.cf.CalculatedFieldType;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class SimpleCalculatedFieldConfiguration extends BaseCalculatedFieldConfiguration implements CalculatedFieldConfiguration {
|
public class SimpleCalculatedFieldConfiguration extends BaseCalculatedFieldConfiguration implements CalculatedFieldConfiguration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user