added new endpoint
This commit is contained in:
parent
731a8a3dd2
commit
a4aa2444ac
@ -32,6 +32,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedField;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.EntityIdFactory;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.config.annotations.ApiOperation;
|
||||
@ -40,7 +42,8 @@ import org.thingsboard.server.service.entitiy.cf.TbCalculatedFieldService;
|
||||
import org.thingsboard.server.service.security.permission.Operation;
|
||||
|
||||
import static org.thingsboard.server.controller.ControllerConstants.CF_TEXT_SEARCH_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.PAGE_DATA_PARAMETERS;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.ENTITY_ID_PARAM_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.ENTITY_TYPE_PARAM_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.PAGE_NUMBER_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.PAGE_SIZE_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_DESCRIPTION;
|
||||
@ -91,25 +94,25 @@ public class CalculatedFieldController extends BaseController {
|
||||
return calculatedField;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get Calculated Fields (getCalculatedFields)",
|
||||
notes = "Returns a page of calculated fields. " + PAGE_DATA_PARAMETERS
|
||||
@ApiOperation(value = "Get Calculated Fields (getCalculatedFieldsByEntityId)",
|
||||
notes = "Fetch the Calculated Fields based on the provided Entity Id."
|
||||
)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/calculatedFields", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/{entityType}/{entityId}/calculatedField", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public PageData<CalculatedField> getCalculatedFields(
|
||||
@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@Parameter(description = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@RequestParam int page,
|
||||
@Parameter(description = CF_TEXT_SEARCH_DESCRIPTION)
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@Parameter(description = SORT_PROPERTY_DESCRIPTION, schema = @Schema(allowableValues = {"createdTime", "name"}))
|
||||
@RequestParam(required = false) String sortProperty,
|
||||
@Parameter(description = SORT_ORDER_DESCRIPTION, schema = @Schema(allowableValues = {"ASC", "DESC"}))
|
||||
@RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
||||
public PageData<CalculatedField> getCalculatedFieldsByEntityId(
|
||||
@Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE")) @PathVariable("entityType") String entityType,
|
||||
@Parameter(description = ENTITY_ID_PARAM_DESCRIPTION, required = true) @PathVariable("entityId") String entityIdStr,
|
||||
@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize,
|
||||
@Parameter(description = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page,
|
||||
@Parameter(description = CF_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch,
|
||||
@Parameter(description = SORT_PROPERTY_DESCRIPTION, schema = @Schema(allowableValues = {"createdTime", "name"})) @RequestParam(required = false) String sortProperty,
|
||||
@Parameter(description = SORT_ORDER_DESCRIPTION, schema = @Schema(allowableValues = {"ASC", "DESC"})) @RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
return checkNotNull(calculatedFieldService.findAllCalculatedFields(pageLink));
|
||||
checkParameter("entityId", entityIdStr);
|
||||
EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, entityIdStr);
|
||||
checkEntityId(entityId, Operation.READ_CALCULATED_FIELD);
|
||||
return checkNotNull(tbCalculatedFieldService.findAllByTenantIdAndEntityId(entityId, getCurrentUser(), pageLink));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Delete Calculated Field (deleteCalculatedField)",
|
||||
|
||||
@ -29,6 +29,8 @@ import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.dao.cf.CalculatedFieldService;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
import org.thingsboard.server.service.entitiy.AbstractTbEntityService;
|
||||
@ -74,6 +76,13 @@ public class DefaultTbCalculatedFieldService extends AbstractTbEntityService imp
|
||||
return calculatedFieldService.findById(user.getTenantId(), calculatedFieldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CalculatedField> findAllByTenantIdAndEntityId(EntityId entityId, SecurityUser user, PageLink pageLink) {
|
||||
TenantId tenantId = user.getTenantId();
|
||||
checkEntityExistence(tenantId, entityId);
|
||||
return calculatedFieldService.findAllCalculatedFieldsByEntityId(tenantId, entityId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(CalculatedField calculatedField, SecurityUser user) {
|
||||
|
||||
@ -18,6 +18,9 @@ package org.thingsboard.server.service.entitiy.cf;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedField;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
public interface TbCalculatedFieldService {
|
||||
@ -26,6 +29,8 @@ public interface TbCalculatedFieldService {
|
||||
|
||||
CalculatedField findById(CalculatedFieldId calculatedFieldId, SecurityUser user);
|
||||
|
||||
PageData<CalculatedField> findAllByTenantIdAndEntityId(EntityId entityId, SecurityUser user, PageLink pageLink);
|
||||
|
||||
void delete(CalculatedField calculatedField, SecurityUser user);
|
||||
|
||||
}
|
||||
|
||||
@ -44,6 +44,8 @@ public interface CalculatedFieldService extends EntityDaoService {
|
||||
|
||||
PageData<CalculatedField> findAllCalculatedFields(PageLink pageLink);
|
||||
|
||||
PageData<CalculatedField> findAllCalculatedFieldsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink);
|
||||
|
||||
void deleteCalculatedField(TenantId tenantId, CalculatedFieldId calculatedFieldId);
|
||||
|
||||
int deleteAllCalculatedFieldsByEntityId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
@ -118,6 +118,14 @@ public class BaseCalculatedFieldService extends AbstractEntityService implements
|
||||
return calculatedFieldDao.findAll(pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CalculatedField> findAllCalculatedFieldsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink) {
|
||||
log.trace("Executing findAllByEntityId, entityId [{}], pageLink [{}]", entityId, pageLink);
|
||||
validateId(entityId.getId(), id -> INCORRECT_ENTITY_ID + id);
|
||||
validatePageLink(pageLink);
|
||||
return calculatedFieldDao.findAllByEntityId(tenantId, entityId, pageLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCalculatedField(TenantId tenantId, CalculatedFieldId calculatedFieldId) {
|
||||
validateId(tenantId, id -> INCORRECT_TENANT_ID + id);
|
||||
|
||||
@ -37,6 +37,8 @@ public interface CalculatedFieldDao extends Dao<CalculatedField> {
|
||||
|
||||
PageData<CalculatedField> findAll(PageLink pageLink);
|
||||
|
||||
PageData<CalculatedField> findAllByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink);
|
||||
|
||||
List<CalculatedField> removeAllByEntityId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
boolean existsByEntityId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.thingsboard.server.dao.sql.cf;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.dao.model.sql.CalculatedFieldEntity;
|
||||
@ -30,6 +32,8 @@ public interface CalculatedFieldRepository extends JpaRepository<CalculatedField
|
||||
|
||||
List<CalculatedFieldEntity> findAllByTenantIdAndEntityId(UUID tenantId, UUID entityId);
|
||||
|
||||
Page<CalculatedFieldEntity> findAllByTenantIdAndEntityId(UUID tenantId, UUID entityId, Pageable pageable);
|
||||
|
||||
List<CalculatedFieldEntity> findAllByTenantId(UUID tenantId);
|
||||
|
||||
List<CalculatedFieldEntity> removeAllByTenantIdAndEntityId(UUID tenantId, UUID entityId);
|
||||
|
||||
@ -83,7 +83,7 @@ public class DefaultNativeCalculatedFieldRepository implements NativeCalculatedF
|
||||
CalculatedField calculatedField = new CalculatedField();
|
||||
calculatedField.setId(new CalculatedFieldId(id));
|
||||
calculatedField.setCreatedTime(createdTime);
|
||||
calculatedField.setTenantId(new TenantId(tenantId));
|
||||
calculatedField.setTenantId(TenantId.fromUUID(tenantId));
|
||||
calculatedField.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId));
|
||||
calculatedField.setType(type);
|
||||
calculatedField.setName(name);
|
||||
|
||||
@ -71,6 +71,12 @@ public class JpaCalculatedFieldDao extends JpaAbstractDao<CalculatedFieldEntity,
|
||||
return nativeCalculatedFieldRepository.findCalculatedFields(DaoUtil.toPageable(pageLink));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CalculatedField> findAllByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink) {
|
||||
log.debug("Try to find calculated fields by entityId[{}] and pageLink [{}]", entityId, pageLink);
|
||||
return DaoUtil.toPageData(calculatedFieldRepository.findAllByTenantIdAndEntityId(tenantId.getId(), entityId.getId(), DaoUtil.toPageable(pageLink)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<CalculatedField> removeAllByEntityId(TenantId tenantId, EntityId entityId) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user