24 changed files with 475 additions and 72 deletions
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.entity.EntityDaoService; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface QueueStatsService extends EntityDaoService { |
|||
|
|||
QueueStats save(TenantId tenantId, QueueStats queueStats); |
|||
|
|||
QueueStats findQueueStatsById(TenantId tenantId, QueueStatsId queueStatsId); |
|||
|
|||
QueueStats findByTenantIdAndNameAndServiceId(TenantId tenantId, String queueStatsName, String serviceId); |
|||
|
|||
List<QueueStats> findByTenantId(TenantId tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class QueueStatsId extends UUIDBased implements EntityId { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@JsonCreator |
|||
public QueueStatsId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static QueueStatsId fromString(String queueId) { |
|||
return new QueueStatsId(UUID.fromString(queueId)); |
|||
} |
|||
|
|||
@ApiModelProperty(position = 2, required = true, value = "string", example = "QUEUE_STATS", allowableValues = "QUEUE_STATS") |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.QUEUE_STATS; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.BaseDataWithAdditionalInfo; |
|||
import org.thingsboard.server.common.data.HasTenantId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
|
|||
@Data |
|||
public class QueueStats extends BaseDataWithAdditionalInfo<QueueStatsId> implements HasTenantId { |
|||
private TenantId tenantId; |
|||
private String queueName; |
|||
private String serviceId; |
|||
|
|||
public QueueStats() { |
|||
} |
|||
|
|||
public QueueStats(QueueStatsId id) { |
|||
super(id); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.model.sql; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.BaseSqlEntity; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = ModelConstants.QUEUE_STATS_TABLE_NAME) |
|||
public class QueueStatsEntity extends BaseSqlEntity<QueueStats> { |
|||
|
|||
@Column(name = ModelConstants.QUEUE_STATS_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = ModelConstants.QUEUE_STATS_QUEUE_NAME_PROPERTY) |
|||
private String queueName; |
|||
|
|||
@Column(name = ModelConstants.QUEUE_STATS_SERVICE_ID_PROPERTY) |
|||
private String serviceId; |
|||
|
|||
public QueueStatsEntity() { |
|||
} |
|||
|
|||
public QueueStatsEntity(QueueStats queueStats) { |
|||
if (queueStats.getId() != null) { |
|||
this.setId(queueStats.getId().getId()); |
|||
} |
|||
this.setCreatedTime(queueStats.getCreatedTime()); |
|||
this.tenantId = DaoUtil.getId(queueStats.getTenantId()); |
|||
this.queueName = queueStats.getQueueName(); |
|||
this.serviceId = queueStats.getServiceId(); |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats toData() { |
|||
QueueStats queueStats = new QueueStats(new QueueStatsId(getUuid())); |
|||
queueStats.setCreatedTime(createdTime); |
|||
queueStats.setTenantId(new TenantId(tenantId)); |
|||
queueStats.setQueueName(queueName); |
|||
queueStats.setServiceId(serviceId); |
|||
return queueStats; |
|||
} |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.HasId; |
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|||
|
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
|
|||
import static org.thingsboard.server.dao.service.Validator.validateId; |
|||
|
|||
@Service("QueueStatsDaoService") |
|||
@Slf4j |
|||
@RequiredArgsConstructor |
|||
public class BaseQueueStatsService extends AbstractEntityService implements QueueStatsService { |
|||
|
|||
@Autowired |
|||
private QueueStatsDao queueStatsDao; |
|||
|
|||
@Override |
|||
public QueueStats save(TenantId tenantId, QueueStats queueStats) { |
|||
return queueStatsDao.save(tenantId, queueStats); |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats findQueueStatsById(TenantId tenantId, QueueStatsId queueStatsId) { |
|||
log.trace("Executing findQueueStatsById [{}]", queueStatsId); |
|||
validateId(queueStatsId, "Incorrect queueStatsId " + queueStatsId); |
|||
return queueStatsDao.findById(tenantId, queueStatsId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats findByTenantIdAndNameAndServiceId(TenantId tenantId, String queueName, String serviceId) { |
|||
log.trace("Executing findByTenantIdAndNameAndServiceId, tenantId: [{}], queueName: [{}], serviceId: [{}]", tenantId, queueName, serviceId); |
|||
return queueStatsDao.findByTenantIdQueueNameAndServiceId(tenantId, queueName, serviceId); |
|||
} |
|||
|
|||
@Override |
|||
public List<QueueStats> findByTenantId(TenantId tenantId) { |
|||
log.trace("Executing findByTenantId, tenantId: [{}]", tenantId); |
|||
return queueStatsDao.findByTenantId(tenantId); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) { |
|||
return Optional.ofNullable(findQueueStatsById(tenantId, new QueueStatsId(entityId.getId()))); |
|||
} |
|||
|
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface QueueStatsDao extends Dao<QueueStats> { |
|||
|
|||
QueueStats findByTenantIdQueueNameAndServiceId(TenantId tenantId, String name, String serviceId); |
|||
|
|||
List<QueueStats> findByTenantId(TenantId tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.sql.QueueStatsEntity; |
|||
import org.thingsboard.server.dao.queue.QueueStatsDao; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@SqlDao |
|||
public class JpaQueueStatsDao extends JpaAbstractDao<QueueStatsEntity, QueueStats> implements QueueStatsDao { |
|||
|
|||
@Autowired |
|||
private QueueStatsRepository queueStatsRepository; |
|||
|
|||
@Override |
|||
protected Class<QueueStatsEntity> getEntityClass() { |
|||
return QueueStatsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected JpaRepository<QueueStatsEntity, UUID> getRepository() { |
|||
return queueStatsRepository; |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats findByTenantIdQueueNameAndServiceId(TenantId tenantId, String name, String serviceId) { |
|||
return DaoUtil.getData(queueStatsRepository.findByTenantIdAndQueueNameAndServiceId(tenantId.getId(), name, serviceId)); |
|||
} |
|||
|
|||
@Override |
|||
public List<QueueStats> findByTenantId(TenantId tenantId) { |
|||
return DaoUtil.convertDataList(queueStatsRepository.findByTenantId(tenantId.getId())); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.thingsboard.server.dao.model.sql.QueueStatsEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
public interface QueueStatsRepository extends JpaRepository<QueueStatsEntity, UUID> { |
|||
|
|||
QueueStatsEntity findByTenantIdAndQueueNameAndServiceId(UUID tenantId, String name, String serviceId); |
|||
|
|||
List<QueueStatsEntity> findByTenantId(UUID tenantId); |
|||
|
|||
} |
|||
Loading…
Reference in new issue