156 changed files with 6461 additions and 3557 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,182 @@ |
|||||
|
/** |
||||
|
* 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.controller; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.mockito.Mockito; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.thingsboard.server.cluster.TbClusterService; |
||||
|
import org.thingsboard.server.common.data.EntityType; |
||||
|
import org.thingsboard.server.common.data.HasName; |
||||
|
import org.thingsboard.server.common.data.audit.ActionType; |
||||
|
import org.thingsboard.server.common.data.id.CustomerId; |
||||
|
import org.thingsboard.server.common.data.id.EntityId; |
||||
|
import org.thingsboard.server.common.data.id.EntityIdFactory; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.id.UserId; |
||||
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
||||
|
import org.thingsboard.server.common.msg.TbMsg; |
||||
|
import org.thingsboard.server.dao.audit.AuditLogService; |
||||
|
import org.thingsboard.server.dao.model.ModelConstants; |
||||
|
|
||||
|
import java.util.Locale; |
||||
|
|
||||
|
import static org.mockito.Mockito.never; |
||||
|
import static org.mockito.Mockito.times; |
||||
|
import static org.thingsboard.server.service.entitiy.DefaultTbNotificationEntityService.edgeTypeByActionType; |
||||
|
|
||||
|
@Slf4j |
||||
|
public abstract class AbstractNotifyEntityTest extends AbstractWebTest { |
||||
|
|
||||
|
@SpyBean |
||||
|
protected TbClusterService tbClusterService; |
||||
|
|
||||
|
@SpyBean |
||||
|
protected AuditLogService auditLogService; |
||||
|
|
||||
|
protected void testNotifyEntityAllOneTime(HasName entity, EntityId entityId, EntityId originatorId, |
||||
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
||||
|
ActionType actionType, Object... additionalInfo) { |
||||
|
testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType); |
||||
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
||||
|
testPushMsgToRuleEngineOneTime(originatorId, tenantId); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
|
||||
|
protected void testNotifyEntityDeleteOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId, |
||||
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
||||
|
ActionType actionType, Object... additionalInfo) { |
||||
|
testNotificationMsgToEdgeServiceNever(entityId); |
||||
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
||||
|
testPushMsgToRuleEngineOneTime(entityId, tenantId); |
||||
|
testBroadcastEntityStateChangeEventOneTime(entityId, tenantId); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
protected void testNotifyEntityNeverMsgToEdgeServiceOneTime(HasName entity, EntityId entityId, TenantId tenantId, ActionType actionType) { |
||||
|
testSendNotificationMsgToEdgeServiceOneTime(entityId, tenantId, actionType); |
||||
|
testLogEntityActionNever(entityId, entity); |
||||
|
testPushMsgToRuleEngineNever(entityId); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
|
||||
|
protected void testNotifyEntityOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId, |
||||
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
||||
|
ActionType actionType, Object... additionalInfo) { |
||||
|
testNotificationMsgToEdgeServiceNever(entityId); |
||||
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
||||
|
testPushMsgToRuleEngineOneTime(originatorId, tenantId); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
|
||||
|
protected void testNotifyEntityBroadcastEntityStateChangeEventOneTimeMsgToEdgeServiceNever(HasName entity, EntityId entityId, EntityId originatorId, |
||||
|
TenantId tenantId, CustomerId customerId, UserId userId, String userName, |
||||
|
ActionType actionType, Object... additionalInfo) { |
||||
|
testNotificationMsgToEdgeServiceNever(entityId); |
||||
|
testLogEntityActionOneTime(entity, originatorId, tenantId, customerId, userId, userName, actionType, additionalInfo); |
||||
|
testPushMsgToRuleEngineOneTime(originatorId, tenantId); |
||||
|
testBroadcastEntityStateChangeEventOneTime(entityId, tenantId); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
|
||||
|
protected void testNotifyEntityError(HasName entity, TenantId tenantId, |
||||
|
UserId userId, String userName, ActionType actionType, Exception exp, |
||||
|
Object... additionalInfo) { |
||||
|
CustomerId customer_NULL_UUID = (CustomerId) EntityIdFactory.getByTypeAndUuid(EntityType.CUSTOMER, ModelConstants.NULL_UUID); |
||||
|
EntityId entity_NULL_UUID = EntityIdFactory.getByTypeAndUuid(EntityType.valueOf(entity.getClass().toString() |
||||
|
.substring(entity.getClass().toString().lastIndexOf(".") + 1).toUpperCase(Locale.ENGLISH)), |
||||
|
ModelConstants.NULL_UUID); |
||||
|
testNotificationMsgToEdgeServiceNever(entity_NULL_UUID); |
||||
|
if (additionalInfo.length > 0) { |
||||
|
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), |
||||
|
Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName), |
||||
|
Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType), |
||||
|
Mockito.argThat(argument -> |
||||
|
argument.getMessage().equals(exp.getMessage())), Mockito.eq(additionalInfo)); |
||||
|
} else { |
||||
|
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), |
||||
|
Mockito.eq(customer_NULL_UUID), Mockito.eq(userId), Mockito.eq(userName), |
||||
|
Mockito.eq(entity_NULL_UUID), Mockito.any(entity.getClass()), Mockito.eq(actionType), |
||||
|
Mockito.argThat(argument -> |
||||
|
argument.getMessage().equals(exp.getMessage()))); |
||||
|
} |
||||
|
testPushMsgToRuleEngineNever(entity_NULL_UUID); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
|
||||
|
protected void testNotifyEntityNever(EntityId entityId, HasName entity) { |
||||
|
testNotificationMsgToEdgeServiceNever(entityId); |
||||
|
testLogEntityActionNever(entityId, entity); |
||||
|
testPushMsgToRuleEngineNever(entityId); |
||||
|
Mockito.reset(tbClusterService, auditLogService); |
||||
|
} |
||||
|
|
||||
|
private void testNotificationMsgToEdgeServiceNever(EntityId entityId) { |
||||
|
Mockito.verify(tbClusterService, never()).sendNotificationMsgToEdgeService(Mockito.any(), |
||||
|
Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any(), Mockito.any()); |
||||
|
} |
||||
|
|
||||
|
private void testLogEntityActionNever(EntityId entityId, HasName entity) { |
||||
|
Mockito.verify(auditLogService, never()).logEntityAction(Mockito.any(), Mockito.any(), |
||||
|
Mockito.any(), Mockito.any(), Mockito.any(entityId.getClass()), Mockito.any(entity.getClass()), |
||||
|
Mockito.any(), Mockito.any()); |
||||
|
} |
||||
|
|
||||
|
private void testPushMsgToRuleEngineNever(EntityId entityId) { |
||||
|
Mockito.verify(tbClusterService, never()).pushMsgToRuleEngine(Mockito.any(), |
||||
|
Mockito.any(entityId.getClass()), Mockito.any(), Mockito.any()); |
||||
|
} |
||||
|
|
||||
|
private void testLogEntityActionOneTime(HasName entity, EntityId originatorId, TenantId tenantId, CustomerId customerId, |
||||
|
UserId userId, String userName, ActionType actionType, Object... additionalInfo) { |
||||
|
if (additionalInfo.length == 0) { |
||||
|
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), Mockito.eq(customerId), |
||||
|
Mockito.eq(userId), Mockito.eq(userName), Mockito.eq(originatorId), |
||||
|
Mockito.eq(entity), Mockito.eq(actionType), Mockito.isNull()); |
||||
|
} else { |
||||
|
String additionalInfoStr = extractParameter(String.class, 0, additionalInfo); |
||||
|
Mockito.verify(auditLogService, times(1)).logEntityAction(Mockito.eq(tenantId), Mockito.eq(customerId), |
||||
|
Mockito.eq(userId), Mockito.eq(userName), Mockito.eq(originatorId), |
||||
|
Mockito.eq(entity), Mockito.eq(actionType), Mockito.isNull(), Mockito.eq(additionalInfoStr)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void testPushMsgToRuleEngineOneTime(EntityId originatorId, TenantId tenantId) { |
||||
|
Mockito.verify(tbClusterService, times(1)).pushMsgToRuleEngine(Mockito.eq(tenantId), |
||||
|
Mockito.eq(originatorId), Mockito.any(TbMsg.class), Mockito.isNull()); |
||||
|
} |
||||
|
|
||||
|
private void testSendNotificationMsgToEdgeServiceOneTime(EntityId entityId, TenantId tenantId, ActionType actionType) { |
||||
|
Mockito.verify(tbClusterService, times(1)).sendNotificationMsgToEdgeService(Mockito.eq(tenantId), |
||||
|
Mockito.isNull(), Mockito.eq(entityId), Mockito.isNull(), Mockito.isNull(), |
||||
|
Mockito.eq(edgeTypeByActionType(actionType))); |
||||
|
} |
||||
|
|
||||
|
private void testBroadcastEntityStateChangeEventOneTime(EntityId entityId, TenantId tenantId) { |
||||
|
Mockito.verify(tbClusterService, times(1)).broadcastEntityStateChangeEvent(Mockito.eq(tenantId), |
||||
|
Mockito.any(entityId.getClass()), Mockito.any(ComponentLifecycleEvent.class)); |
||||
|
} |
||||
|
|
||||
|
private <T> T extractParameter(Class<T> clazz, int index, Object... additionalInfo) { |
||||
|
T result = null; |
||||
|
if (additionalInfo != null && additionalInfo.length > index) { |
||||
|
Object paramObject = additionalInfo[index]; |
||||
|
if (clazz.isInstance(paramObject)) { |
||||
|
result = clazz.cast(paramObject); |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.util; |
|
||||
|
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
||||
|
|
||||
import java.lang.annotation.Retention; |
|
||||
import java.lang.annotation.RetentionPolicy; |
|
||||
|
|
||||
@Retention(RetentionPolicy.RUNTIME) |
|
||||
@ConditionalOnProperty(prefix = "spring.jpa", value = "database-platform", havingValue = "org.hibernate.dialect.HSQLDialect") |
|
||||
public @interface HsqlDao { |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.util; |
|
||||
|
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
||||
|
|
||||
import java.lang.annotation.Retention; |
|
||||
import java.lang.annotation.RetentionPolicy; |
|
||||
|
|
||||
@Retention(RetentionPolicy.RUNTIME) |
|
||||
@ConditionalOnProperty(prefix = "spring.jpa", value = "database-platform", havingValue = "org.hibernate.dialect.PostgreSQLDialect") |
|
||||
public @interface PsqlDao { |
|
||||
} |
|
||||
@ -1,37 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao; |
|
||||
|
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan; |
|
||||
import org.springframework.context.annotation.ComponentScan; |
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
import org.thingsboard.server.dao.util.SqlTsLatestDao; |
|
||||
import org.thingsboard.server.dao.util.TbAutoConfiguration; |
|
||||
|
|
||||
@Configuration |
|
||||
@TbAutoConfiguration |
|
||||
@ComponentScan({"org.thingsboard.server.dao.sqlts.hsql"}) |
|
||||
@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.insert.latest.hsql", "org.thingsboard.server.dao.sqlts.latest"}) |
|
||||
@EntityScan({"org.thingsboard.server.dao.model.sqlts.latest"}) |
|
||||
@EnableTransactionManagement |
|
||||
@SqlTsLatestDao |
|
||||
@HsqlDao |
|
||||
public class HsqlTsLatestDaoConfig { |
|
||||
|
|
||||
} |
|
||||
@ -1,37 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao; |
|
||||
|
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan; |
|
||||
import org.springframework.context.annotation.ComponentScan; |
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
||||
import org.thingsboard.server.dao.util.PsqlDao; |
|
||||
import org.thingsboard.server.dao.util.SqlTsDao; |
|
||||
import org.thingsboard.server.dao.util.TbAutoConfiguration; |
|
||||
|
|
||||
@Configuration |
|
||||
@TbAutoConfiguration |
|
||||
@ComponentScan({"org.thingsboard.server.dao.sqlts.psql", "org.thingsboard.server.dao.sqlts.insert.psql"}) |
|
||||
@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.psql"}) |
|
||||
@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts"}) |
|
||||
@EnableTransactionManagement |
|
||||
@PsqlDao |
|
||||
@SqlTsDao |
|
||||
public class PsqlTsDaoConfig { |
|
||||
|
|
||||
} |
|
||||
@ -1,76 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.sql.attributes; |
|
||||
|
|
||||
import org.springframework.stereotype.Repository; |
|
||||
import org.springframework.transaction.annotation.Transactional; |
|
||||
import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
|
|
||||
import java.sql.Types; |
|
||||
import java.util.List; |
|
||||
|
|
||||
@HsqlDao |
|
||||
@Repository |
|
||||
@Transactional |
|
||||
public class HsqlAttributesInsertRepository extends AttributeKvInsertRepository { |
|
||||
|
|
||||
private static final String INSERT_OR_UPDATE = |
|
||||
"MERGE INTO attribute_kv USING(VALUES ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " + |
|
||||
"A (entity_type, entity_id, attribute_type, attribute_key, str_v, long_v, dbl_v, bool_v, json_v, last_update_ts) " + |
|
||||
"ON (attribute_kv.entity_type=A.entity_type " + |
|
||||
"AND attribute_kv.entity_id=A.entity_id " + |
|
||||
"AND attribute_kv.attribute_type=A.attribute_type " + |
|
||||
"AND attribute_kv.attribute_key=A.attribute_key) " + |
|
||||
"WHEN MATCHED THEN UPDATE SET attribute_kv.str_v = A.str_v, attribute_kv.long_v = A.long_v, attribute_kv.dbl_v = A.dbl_v, attribute_kv.bool_v = A.bool_v, attribute_kv.json_v = A.json_v, attribute_kv.last_update_ts = A.last_update_ts " + |
|
||||
"WHEN NOT MATCHED THEN INSERT (entity_type, entity_id, attribute_type, attribute_key, str_v, long_v, dbl_v, bool_v, json_v, last_update_ts) " + |
|
||||
"VALUES (A.entity_type, A.entity_id, A.attribute_type, A.attribute_key, A.str_v, A.long_v, A.dbl_v, A.bool_v, A.json_v, A.last_update_ts)"; |
|
||||
|
|
||||
@Override |
|
||||
protected void saveOrUpdate(List<AttributeKvEntity> entities) { |
|
||||
entities.forEach(entity -> { |
|
||||
jdbcTemplate.update(INSERT_OR_UPDATE, ps -> { |
|
||||
ps.setString(1, entity.getId().getEntityType().name()); |
|
||||
ps.setObject(2, entity.getId().getEntityId()); |
|
||||
ps.setString(3, entity.getId().getAttributeType()); |
|
||||
ps.setString(4, entity.getId().getAttributeKey()); |
|
||||
ps.setString(5, entity.getStrValue()); |
|
||||
|
|
||||
if (entity.getLongValue() != null) { |
|
||||
ps.setLong(6, entity.getLongValue()); |
|
||||
} else { |
|
||||
ps.setNull(6, Types.BIGINT); |
|
||||
} |
|
||||
|
|
||||
if (entity.getDoubleValue() != null) { |
|
||||
ps.setDouble(7, entity.getDoubleValue()); |
|
||||
} else { |
|
||||
ps.setNull(7, Types.DOUBLE); |
|
||||
} |
|
||||
|
|
||||
if (entity.getBooleanValue() != null) { |
|
||||
ps.setBoolean(8, entity.getBooleanValue()); |
|
||||
} else { |
|
||||
ps.setNull(8, Types.BOOLEAN); |
|
||||
} |
|
||||
|
|
||||
ps.setString(9, entity.getJsonValue()); |
|
||||
|
|
||||
ps.setLong(10, entity.getLastUpdateTs()); |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,65 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.sql.component; |
|
||||
|
|
||||
import org.springframework.stereotype.Repository; |
|
||||
import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
|
|
||||
import javax.persistence.Query; |
|
||||
|
|
||||
@HsqlDao |
|
||||
@Repository |
|
||||
public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { |
|
||||
|
|
||||
private static final String P_KEY_CONFLICT_STATEMENT = "(component_descriptor.id=UUID(I.id))"; |
|
||||
private static final String UNQ_KEY_CONFLICT_STATEMENT = "(component_descriptor.clazz=I.clazz)"; |
|
||||
|
|
||||
private static final String INSERT_OR_UPDATE_ON_P_KEY_CONFLICT = getInsertString(P_KEY_CONFLICT_STATEMENT); |
|
||||
private static final String INSERT_OR_UPDATE_ON_UNQ_KEY_CONFLICT = getInsertString(UNQ_KEY_CONFLICT_STATEMENT); |
|
||||
|
|
||||
@Override |
|
||||
public ComponentDescriptorEntity saveOrUpdate(ComponentDescriptorEntity entity) { |
|
||||
return saveAndGet(entity, INSERT_OR_UPDATE_ON_P_KEY_CONFLICT, INSERT_OR_UPDATE_ON_UNQ_KEY_CONFLICT); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected Query getQuery(ComponentDescriptorEntity entity, String query) { |
|
||||
return entityManager.createNativeQuery(query, ComponentDescriptorEntity.class) |
|
||||
.setParameter("id", entity.getUuid().toString()) |
|
||||
.setParameter("created_time", entity.getCreatedTime()) |
|
||||
.setParameter("actions", entity.getActions()) |
|
||||
.setParameter("clazz", entity.getClazz()) |
|
||||
.setParameter("configuration_descriptor", entity.getConfigurationDescriptor().toString()) |
|
||||
.setParameter("name", entity.getName()) |
|
||||
.setParameter("scope", entity.getScope().name()) |
|
||||
.setParameter("search_text", entity.getSearchText()) |
|
||||
.setParameter("type", entity.getType().name()); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected ComponentDescriptorEntity doProcessSaveOrUpdate(ComponentDescriptorEntity entity, String query) { |
|
||||
getQuery(entity, query).executeUpdate(); |
|
||||
return entityManager.find(ComponentDescriptorEntity.class, entity.getUuid()); |
|
||||
} |
|
||||
|
|
||||
private static String getInsertString(String conflictStatement) { |
|
||||
return "MERGE INTO component_descriptor USING (VALUES :id, :created_time, :actions, :clazz, :configuration_descriptor, :name, :scope, :search_text, :type) I (id, created_time, actions, clazz, configuration_descriptor, name, scope, search_text, type) ON " |
|
||||
+ conflictStatement |
|
||||
+ " WHEN MATCHED THEN UPDATE SET component_descriptor.id = UUID(I.id), component_descriptor.actions = I.actions, component_descriptor.clazz = I.clazz, component_descriptor.configuration_descriptor = I.configuration_descriptor, component_descriptor.name = I.name, component_descriptor.scope = I.scope, component_descriptor.search_text = I.search_text, component_descriptor.type = I.type" + |
|
||||
" WHEN NOT MATCHED THEN INSERT (id, created_time, actions, clazz, configuration_descriptor, name, scope, search_text, type) VALUES (UUID(I.id), I.created_time, I.actions, I.clazz, I.configuration_descriptor, I.name, I.scope, I.search_text, I.type)"; |
|
||||
} |
|
||||
} |
|
||||
@ -1,63 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.sql.relation; |
|
||||
|
|
||||
import org.springframework.stereotype.Repository; |
|
||||
import org.springframework.transaction.annotation.Transactional; |
|
||||
import org.thingsboard.server.dao.model.sql.RelationCompositeKey; |
|
||||
import org.thingsboard.server.dao.model.sql.RelationEntity; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
|
|
||||
import javax.persistence.Query; |
|
||||
|
|
||||
@HsqlDao |
|
||||
@Repository |
|
||||
@Transactional |
|
||||
public class HsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository { |
|
||||
|
|
||||
private static final String INSERT_ON_CONFLICT_DO_UPDATE = "MERGE INTO relation USING (VALUES :fromId, :fromType, :toId, :toType, :relationTypeGroup, :relationType, :additionalInfo) R " + |
|
||||
"(from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) " + |
|
||||
"ON (relation.from_id = UUID(R.from_id) AND relation.from_type = R.from_type AND relation.relation_type_group = R.relation_type_group AND relation.relation_type = R.relation_type AND relation.to_id = UUID(R.to_id) AND relation.to_type = R.to_type) " + |
|
||||
"WHEN MATCHED THEN UPDATE SET relation.additional_info = R.additional_info " + |
|
||||
"WHEN NOT MATCHED THEN INSERT (from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) VALUES (UUID(R.from_id), R.from_type, UUID(R.to_id), R.to_type, R.relation_type_group, R.relation_type, R.additional_info)"; |
|
||||
|
|
||||
protected Query getQuery(RelationEntity entity, String query) { |
|
||||
Query nativeQuery = entityManager.createNativeQuery(query, RelationEntity.class); |
|
||||
if (entity.getAdditionalInfo() == null) { |
|
||||
nativeQuery.setParameter("additionalInfo", null); |
|
||||
} else { |
|
||||
nativeQuery.setParameter("additionalInfo", entity.getAdditionalInfo().toString()); |
|
||||
} |
|
||||
return nativeQuery |
|
||||
.setParameter("fromId", entity.getFromId().toString()) |
|
||||
.setParameter("fromType", entity.getFromType()) |
|
||||
.setParameter("toId", entity.getToId().toString()) |
|
||||
.setParameter("toType", entity.getToType()) |
|
||||
.setParameter("relationTypeGroup", entity.getRelationTypeGroup()) |
|
||||
.setParameter("relationType", entity.getRelationType()); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public RelationEntity saveOrUpdate(RelationEntity entity) { |
|
||||
return processSaveOrUpdate(entity); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected RelationEntity processSaveOrUpdate(RelationEntity entity) { |
|
||||
getQuery(entity, INSERT_ON_CONFLICT_DO_UPDATE).executeUpdate(); |
|
||||
return entityManager.find(RelationEntity.class, new RelationCompositeKey(entity.toData())); |
|
||||
} |
|
||||
} |
|
||||
@ -1,62 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.sqlts.hsql; |
|
||||
|
|
||||
import com.google.common.util.concurrent.Futures; |
|
||||
import com.google.common.util.concurrent.ListenableFuture; |
|
||||
import com.google.common.util.concurrent.MoreExecutors; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.common.data.id.EntityId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
||||
import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; |
|
||||
import org.thingsboard.server.dao.sqlts.AbstractChunkedAggregationTimeseriesDao; |
|
||||
import org.thingsboard.server.dao.timeseries.TimeseriesDao; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
import org.thingsboard.server.dao.util.SqlTsDao; |
|
||||
|
|
||||
|
|
||||
@Component |
|
||||
@Slf4j |
|
||||
@SqlTsDao |
|
||||
@HsqlDao |
|
||||
public class JpaHsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDao implements TimeseriesDao { |
|
||||
|
|
||||
@Override |
|
||||
public ListenableFuture<Integer> save(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl) { |
|
||||
int dataPointDays = getDataPointDays(tsKvEntry, computeTtl(ttl)); |
|
||||
String strKey = tsKvEntry.getKey(); |
|
||||
Integer keyId = getOrSaveKeyId(strKey); |
|
||||
TsKvEntity entity = new TsKvEntity(); |
|
||||
entity.setEntityId(entityId.getId()); |
|
||||
entity.setTs(tsKvEntry.getTs()); |
|
||||
entity.setKey(keyId); |
|
||||
entity.setStrValue(tsKvEntry.getStrValue().orElse(null)); |
|
||||
entity.setDoubleValue(tsKvEntry.getDoubleValue().orElse(null)); |
|
||||
entity.setLongValue(tsKvEntry.getLongValue().orElse(null)); |
|
||||
entity.setBooleanValue(tsKvEntry.getBooleanValue().orElse(null)); |
|
||||
entity.setJsonValue(tsKvEntry.getJsonValue().orElse(null)); |
|
||||
log.trace("Saving entity: {}", entity); |
|
||||
return Futures.transform(tsQueue.add(entity), v -> dataPointDays, MoreExecutors.directExecutor()); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void cleanup(long systemTtl) { |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,87 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.sqlts.insert.hsql; |
|
||||
|
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
|
||||
import org.springframework.stereotype.Repository; |
|
||||
import org.springframework.transaction.annotation.Transactional; |
|
||||
import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; |
|
||||
import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; |
|
||||
import org.thingsboard.server.dao.sqlts.insert.InsertTsRepository; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
import org.thingsboard.server.dao.util.SqlTsDao; |
|
||||
|
|
||||
import java.sql.PreparedStatement; |
|
||||
import java.sql.SQLException; |
|
||||
import java.sql.Types; |
|
||||
import java.util.List; |
|
||||
|
|
||||
@SqlTsDao |
|
||||
@HsqlDao |
|
||||
@Repository |
|
||||
@Transactional |
|
||||
public class HsqlInsertTsRepository extends AbstractInsertRepository implements InsertTsRepository<TsKvEntity> { |
|
||||
|
|
||||
private static final String INSERT_OR_UPDATE = |
|
||||
"MERGE INTO ts_kv USING(VALUES ?, ?, ?, ?, ?, ?, ?, ?) " + |
|
||||
"T (entity_id, key, ts, bool_v, str_v, long_v, dbl_v, json_v) " + |
|
||||
"ON (ts_kv.entity_id=T.entity_id " + |
|
||||
"AND ts_kv.key=T.key " + |
|
||||
"AND ts_kv.ts=T.ts) " + |
|
||||
"WHEN MATCHED THEN UPDATE SET ts_kv.bool_v = T.bool_v, ts_kv.str_v = T.str_v, ts_kv.long_v = T.long_v, ts_kv.dbl_v = T.dbl_v ,ts_kv.json_v = T.json_v " + |
|
||||
"WHEN NOT MATCHED THEN INSERT (entity_id, key, ts, bool_v, str_v, long_v, dbl_v, json_v) " + |
|
||||
"VALUES (T.entity_id, T.key, T.ts, T.bool_v, T.str_v, T.long_v, T.dbl_v, T.json_v);"; |
|
||||
|
|
||||
@Override |
|
||||
public void saveOrUpdate(List<TsKvEntity> entities) { |
|
||||
jdbcTemplate.batchUpdate(INSERT_OR_UPDATE, new BatchPreparedStatementSetter() { |
|
||||
@Override |
|
||||
public void setValues(PreparedStatement ps, int i) throws SQLException { |
|
||||
TsKvEntity tsKvEntity = entities.get(i); |
|
||||
ps.setObject(1, tsKvEntity.getEntityId()); |
|
||||
ps.setInt(2, tsKvEntity.getKey()); |
|
||||
ps.setLong(3, tsKvEntity.getTs()); |
|
||||
|
|
||||
if (tsKvEntity.getBooleanValue() != null) { |
|
||||
ps.setBoolean(4, tsKvEntity.getBooleanValue()); |
|
||||
} else { |
|
||||
ps.setNull(4, Types.BOOLEAN); |
|
||||
} |
|
||||
|
|
||||
ps.setString(5, tsKvEntity.getStrValue()); |
|
||||
|
|
||||
if (tsKvEntity.getLongValue() != null) { |
|
||||
ps.setLong(6, tsKvEntity.getLongValue()); |
|
||||
} else { |
|
||||
ps.setNull(6, Types.BIGINT); |
|
||||
} |
|
||||
|
|
||||
if (tsKvEntity.getDoubleValue() != null) { |
|
||||
ps.setDouble(7, tsKvEntity.getDoubleValue()); |
|
||||
} else { |
|
||||
ps.setNull(7, Types.DOUBLE); |
|
||||
} |
|
||||
|
|
||||
ps.setString(8, tsKvEntity.getJsonValue()); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public int getBatchSize() { |
|
||||
return entities.size(); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,85 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.sqlts.insert.latest.hsql; |
|
||||
|
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
|
||||
import org.springframework.stereotype.Repository; |
|
||||
import org.springframework.transaction.annotation.Transactional; |
|
||||
import org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity; |
|
||||
import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; |
|
||||
import org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
import org.thingsboard.server.dao.util.SqlTsLatestDao; |
|
||||
|
|
||||
import java.sql.PreparedStatement; |
|
||||
import java.sql.SQLException; |
|
||||
import java.sql.Types; |
|
||||
import java.util.List; |
|
||||
|
|
||||
@SqlTsLatestDao |
|
||||
@HsqlDao |
|
||||
@Repository |
|
||||
@Transactional |
|
||||
public class HsqlLatestInsertTsRepository extends AbstractInsertRepository implements InsertLatestTsRepository { |
|
||||
|
|
||||
private static final String INSERT_OR_UPDATE = |
|
||||
"MERGE INTO ts_kv_latest USING(VALUES ?, ?, ?, ?, ?, ?, ?, ?) " + |
|
||||
"T (entity_id, key, ts, bool_v, str_v, long_v, dbl_v, json_v) " + |
|
||||
"ON (ts_kv_latest.entity_id=T.entity_id " + |
|
||||
"AND ts_kv_latest.key=T.key) " + |
|
||||
"WHEN MATCHED THEN UPDATE SET ts_kv_latest.ts = T.ts, ts_kv_latest.bool_v = T.bool_v, ts_kv_latest.str_v = T.str_v, ts_kv_latest.long_v = T.long_v, ts_kv_latest.dbl_v = T.dbl_v, ts_kv_latest.json_v = T.json_v " + |
|
||||
"WHEN NOT MATCHED THEN INSERT (entity_id, key, ts, bool_v, str_v, long_v, dbl_v, json_v) " + |
|
||||
"VALUES (T.entity_id, T.key, T.ts, T.bool_v, T.str_v, T.long_v, T.dbl_v, T.json_v);"; |
|
||||
|
|
||||
@Override |
|
||||
public void saveOrUpdate(List<TsKvLatestEntity> entities) { |
|
||||
jdbcTemplate.batchUpdate(INSERT_OR_UPDATE, new BatchPreparedStatementSetter() { |
|
||||
@Override |
|
||||
public void setValues(PreparedStatement ps, int i) throws SQLException { |
|
||||
ps.setObject(1, entities.get(i).getEntityId()); |
|
||||
ps.setInt(2, entities.get(i).getKey()); |
|
||||
ps.setLong(3, entities.get(i).getTs()); |
|
||||
|
|
||||
if (entities.get(i).getBooleanValue() != null) { |
|
||||
ps.setBoolean(4, entities.get(i).getBooleanValue()); |
|
||||
} else { |
|
||||
ps.setNull(4, Types.BOOLEAN); |
|
||||
} |
|
||||
|
|
||||
ps.setString(5, entities.get(i).getStrValue()); |
|
||||
|
|
||||
if (entities.get(i).getLongValue() != null) { |
|
||||
ps.setLong(6, entities.get(i).getLongValue()); |
|
||||
} else { |
|
||||
ps.setNull(6, Types.BIGINT); |
|
||||
} |
|
||||
|
|
||||
if (entities.get(i).getDoubleValue() != null) { |
|
||||
ps.setDouble(7, entities.get(i).getDoubleValue()); |
|
||||
} else { |
|
||||
ps.setNull(7, Types.DOUBLE); |
|
||||
} |
|
||||
|
|
||||
ps.setString(8, entities.get(i).getJsonValue()); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public int getBatchSize() { |
|
||||
return entities.size(); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,40 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.util; |
|
||||
|
|
||||
import org.springframework.jdbc.core.JdbcTemplate; |
|
||||
|
|
||||
import java.sql.DriverManager; |
|
||||
|
|
||||
public class DaoTestUtil { |
|
||||
private static final String POSTGRES_DRIVER_CLASS = "org.postgresql.Driver"; |
|
||||
private static final String H2_DRIVER_CLASS = "org.hsqldb.jdbc.JDBCDriver"; |
|
||||
|
|
||||
|
|
||||
public static SqlDbType getSqlDbType(JdbcTemplate template){ |
|
||||
try { |
|
||||
String driverName = DriverManager.getDriver(template.getDataSource().getConnection().getMetaData().getURL()).getClass().getName(); |
|
||||
if (POSTGRES_DRIVER_CLASS.equals(driverName)) { |
|
||||
return SqlDbType.POSTGRES; |
|
||||
} else if (H2_DRIVER_CLASS.equals(driverName)) { |
|
||||
return SqlDbType.H2; |
|
||||
} |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
/** |
|
||||
* 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.dao.util; |
|
||||
|
|
||||
public enum SqlDbType { |
|
||||
POSTGRES, H2; |
|
||||
} |
|
||||
File diff suppressed because it is too large
@ -1,61 +0,0 @@ |
|||||
# |
|
||||
# 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. |
|
||||
# |
|
||||
|
|
||||
FROM thingsboard/openjdk11 |
|
||||
|
|
||||
COPY logback.xml ${pkg.name}.conf start-db.sh stop-db.sh start-tb.sh upgrade-tb.sh install-tb.sh ${pkg.name}.deb /tmp/ |
|
||||
|
|
||||
RUN chmod a+x /tmp/*.sh \ |
|
||||
&& mv /tmp/start-tb.sh /usr/bin \ |
|
||||
&& mv /tmp/upgrade-tb.sh /usr/bin \ |
|
||||
&& mv /tmp/install-tb.sh /usr/bin \ |
|
||||
&& mv /tmp/start-db.sh /usr/bin \ |
|
||||
&& mv /tmp/stop-db.sh /usr/bin |
|
||||
|
|
||||
RUN dpkg -i /tmp/${pkg.name}.deb |
|
||||
RUN rm /tmp/${pkg.name}.deb |
|
||||
|
|
||||
RUN systemctl --no-reload disable --now ${pkg.name}.service > /dev/null 2>&1 || : |
|
||||
|
|
||||
RUN mv /tmp/logback.xml ${pkg.installFolder}/conf \ |
|
||||
&& mv /tmp/${pkg.name}.conf ${pkg.installFolder}/conf |
|
||||
|
|
||||
ENV DATA_FOLDER=/data |
|
||||
|
|
||||
ENV HTTP_BIND_PORT=9090 |
|
||||
ENV DATABASE_TS_TYPE=sql |
|
||||
|
|
||||
ENV SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.HSQLDialect |
|
||||
ENV SPRING_DRIVER_CLASS_NAME=org.hsqldb.jdbc.JDBCDriver |
|
||||
ENV SPRING_DATASOURCE_URL=jdbc:hsqldb:file:/data/db/thingsboardDb;sql.enforce_size=false;hsqldb.log_size=5 |
|
||||
ENV SPRING_DATASOURCE_USERNAME=sa |
|
||||
ENV SPRING_DATASOURCE_PASSWORD= |
|
||||
|
|
||||
RUN mkdir -p /data |
|
||||
RUN chown -R ${pkg.user}:${pkg.user} /data |
|
||||
|
|
||||
RUN chmod 555 ${pkg.installFolder}/bin/${pkg.name}.jar |
|
||||
|
|
||||
USER ${pkg.user} |
|
||||
|
|
||||
EXPOSE 9090 |
|
||||
EXPOSE 1883 |
|
||||
EXPOSE 5683/udp |
|
||||
EXPOSE 5685/udp |
|
||||
|
|
||||
VOLUME ["/data"] |
|
||||
|
|
||||
CMD ["start-tb.sh"] |
|
||||
@ -1,18 +0,0 @@ |
|||||
#!/bin/bash |
|
||||
# |
|
||||
# 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. |
|
||||
# |
|
||||
|
|
||||
# Do nothing |
|
||||
@ -1,18 +0,0 @@ |
|||||
#!/bin/bash |
|
||||
# |
|
||||
# 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. |
|
||||
# |
|
||||
|
|
||||
# Do nothing |
|
||||
File diff suppressed because it is too large
@ -0,0 +1,55 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
--> |
||||
|
<mat-expansion-panel [formGroup] = "dynamicValue" class="device-profile-alarm" style = "margin-bottom: 26px;" fxFlex> |
||||
|
<mat-expansion-panel-header> |
||||
|
<div fxFlex fxLayout="row" fxLayoutAlign="start center"> |
||||
|
<mat-panel-title> |
||||
|
<div fxLayout="row" fxFlex fxLayoutAlign="start center"> |
||||
|
{{'filter.dynamic-value' | translate}} |
||||
|
</div> |
||||
|
</mat-panel-title> |
||||
|
<span fxFlex></span> |
||||
|
</div> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<div fxFlex fxLayout="column"> |
||||
|
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
||||
|
<div fxFlex="40" fxLayout="column"> |
||||
|
<mat-form-field floatLabel="always" hideRequiredMarker class="mat-block"> |
||||
|
<mat-label></mat-label> |
||||
|
<mat-select formControlName="sourceType" placeholder="{{'filter.dynamic-source-type' | translate}}"> |
||||
|
<mat-option [value]="null"> |
||||
|
{{'filter.no-dynamic-value' | translate}} |
||||
|
</mat-option> |
||||
|
<mat-option *ngFor="let sourceType of dynamicValueSourceTypes" [value]="sourceType"> |
||||
|
{{dynamicValueSourceTypeTranslations.get(sourceType) | translate}} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div fxFlex fxLayout="column"> |
||||
|
<mat-form-field floatLabel="always" hideRequiredMarker class="mat-block source-attribute"> |
||||
|
<mat-label></mat-label> |
||||
|
<input matInput formControlName="sourceAttribute" placeholder="{{'filter.source-attribute' | translate}}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div [tb-help-popup]="helpId"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
@ -0,0 +1,99 @@ |
|||||
|
///
|
||||
|
/// 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.
|
||||
|
///
|
||||
|
|
||||
|
import { Component, forwardRef, Input, OnInit } from '@angular/core'; |
||||
|
import { |
||||
|
ControlValueAccessor, |
||||
|
FormBuilder, |
||||
|
FormGroup, |
||||
|
NG_VALUE_ACCESSOR, |
||||
|
} from '@angular/forms'; |
||||
|
import { |
||||
|
DynamicValueSourceType, |
||||
|
dynamicValueSourceTypeTranslationMap, |
||||
|
getDynamicSourcesForAllowUser |
||||
|
} from '@shared/models/query/query.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-alarm-dynamic-value', |
||||
|
templateUrl: './alarm-dynamic-value.component.html', |
||||
|
providers: [{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => AlarmDynamicValue), |
||||
|
multi: true |
||||
|
}] |
||||
|
}) |
||||
|
|
||||
|
export class AlarmDynamicValue implements ControlValueAccessor, OnInit{ |
||||
|
public dynamicValue: FormGroup; |
||||
|
public dynamicValueSourceTypes: DynamicValueSourceType[] = getDynamicSourcesForAllowUser(false); |
||||
|
public dynamicValueSourceTypeTranslations = dynamicValueSourceTypeTranslationMap; |
||||
|
private propagateChange = (v: any) => { }; |
||||
|
|
||||
|
@Input() |
||||
|
helpId: string; |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
constructor(private fb: FormBuilder) { |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.dynamicValue = this.fb.group({ |
||||
|
sourceType: [null, []], |
||||
|
sourceAttribute: [null] |
||||
|
}) |
||||
|
|
||||
|
this.dynamicValue.get('sourceType').valueChanges.subscribe( |
||||
|
(sourceType) => { |
||||
|
if (!sourceType) { |
||||
|
this.dynamicValue.get('sourceAttribute').patchValue(null, {emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
this.dynamicValue.valueChanges.subscribe(() => { |
||||
|
this.updateModel(); |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
writeValue(dynamicValue: {sourceType: string, sourceAttribute: string}): void { |
||||
|
if(dynamicValue) { |
||||
|
this.dynamicValue.patchValue(dynamicValue, {emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
if (this.disabled) { |
||||
|
this.dynamicValue.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.dynamicValue.enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private updateModel() { |
||||
|
this.propagateChange(this.dynamicValue.value); |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue