Search in sources :

Example 1 with SourceDbBasicEntity

use of org.apache.inlong.manager.dao.entity.SourceDbBasicEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method getBasicByIdentifier.

@Override
public SourceDbBasicInfo getBasicByIdentifier(String groupId, String streamId) {
    LOGGER.info("begin to get db data source basic by groupId={}, streamId={}", groupId, streamId);
    Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
    Preconditions.checkNotNull(streamId, Constant.STREAM_ID_IS_EMPTY);
    SourceDbBasicEntity entity = dbBasicMapper.selectByIdentifier(groupId, streamId);
    SourceDbBasicInfo basicInfo = new SourceDbBasicInfo();
    if (entity == null) {
        LOGGER.error("file data source basic not found by streamId={}", streamId);
        // throw new BusinessException(ErrorCodeEnum.DATA_SOURCE_BASIC_NOTFOUND);
        return basicInfo;
    }
    BeanUtils.copyProperties(entity, basicInfo);
    LOGGER.info("success to get db data source basic");
    return basicInfo;
}
Also used : SourceDbBasicInfo(org.apache.inlong.manager.common.pojo.source.SourceDbBasicInfo) SourceDbBasicEntity(org.apache.inlong.manager.dao.entity.SourceDbBasicEntity)

Example 2 with SourceDbBasicEntity

use of org.apache.inlong.manager.dao.entity.SourceDbBasicEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method logicDeleteBasic.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
    LOGGER.info("begin to delete db data source basic, id={}", id);
    Preconditions.checkNotNull(id, "db data source basic's id is null");
    SourceDbBasicEntity entity = dbBasicMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("db data source basic not found by id={}, delete failed", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
    }
    String groupId = entity.getInlongGroupId();
    String streamId = entity.getInlongStreamId();
    // Check if it can be deleted
    this.checkGroupIsTempStatus(groupId);
    // If there are related data source details, it is not allowed to delete
    List<SourceDbDetailEntity> detailEntities = dbDetailMapper.selectByIdentifier(groupId, streamId);
    if (CollectionUtils.isNotEmpty(detailEntities)) {
        LOGGER.error("the data source basic have [{}] details, delete failed", detailEntities.size());
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_DELETE_HAS_DETAIL);
    }
    entity.setIsDeleted(1);
    entity.setModifier(operator);
    int resultCount = dbBasicMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete db data source basic");
    return resultCount >= 0;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbBasicEntity(org.apache.inlong.manager.dao.entity.SourceDbBasicEntity) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SourceDbBasicEntity

use of org.apache.inlong.manager.dao.entity.SourceDbBasicEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method saveBasic.

@Override
public Integer saveBasic(SourceDbBasicInfo basicInfo, String operator) {
    LOGGER.info("begin to save db data source basic={}", basicInfo);
    Preconditions.checkNotNull(basicInfo, "db data source basic");
    String groupId = basicInfo.getInlongGroupId();
    String streamId = basicInfo.getInlongStreamId();
    Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
    Preconditions.checkNotNull(streamId, Constant.STREAM_ID_IS_EMPTY);
    // Check if it can be added
    this.checkGroupIsTempStatus(groupId);
    // Each groupId + streamId has only 1 valid basic information
    SourceDbBasicEntity exist = dbBasicMapper.selectByIdentifier(groupId, streamId);
    if (exist != null) {
        LOGGER.error("db data source basic already exists");
        throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
    }
    SourceDbBasicEntity entity = CommonBeanUtils.copyProperties(basicInfo, SourceDbBasicEntity::new);
    entity.setCreator(operator);
    entity.setModifier(operator);
    entity.setCreateTime(new Date());
    dbBasicMapper.insertSelective(entity);
    LOGGER.info("success to save db data source basic");
    return entity.getId();
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbBasicEntity(org.apache.inlong.manager.dao.entity.SourceDbBasicEntity) Date(java.util.Date)

Example 4 with SourceDbBasicEntity

use of org.apache.inlong.manager.dao.entity.SourceDbBasicEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method updateBasic.

@Override
public boolean updateBasic(SourceDbBasicInfo basicInfo, String operator) {
    LOGGER.info("begin to update db data source basic={}", basicInfo);
    Preconditions.checkNotNull(basicInfo, "db data source basic is empty");
    // The groupId may be modified, it is necessary to determine whether the inlong group status of
    // the modified groupId supports modification
    this.checkGroupIsTempStatus(basicInfo.getInlongGroupId());
    // If id is empty, add
    if (basicInfo.getId() == null) {
        this.saveBasic(basicInfo, operator);
    } else {
        SourceDbBasicEntity basicEntity = dbBasicMapper.selectByPrimaryKey(basicInfo.getId());
        if (basicEntity == null) {
            LOGGER.error("db data source basic not found by id={}, update failed", basicInfo.getId());
            throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
        }
        BeanUtils.copyProperties(basicInfo, basicEntity);
        basicEntity.setModifier(operator);
        dbBasicMapper.updateByPrimaryKeySelective(basicEntity);
    }
    LOGGER.info("success to update db data source basic");
    return true;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbBasicEntity(org.apache.inlong.manager.dao.entity.SourceDbBasicEntity)

Aggregations

SourceDbBasicEntity (org.apache.inlong.manager.dao.entity.SourceDbBasicEntity)4 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)3 Date (java.util.Date)1 SourceDbBasicInfo (org.apache.inlong.manager.common.pojo.source.SourceDbBasicInfo)1 SourceDbDetailEntity (org.apache.inlong.manager.dao.entity.SourceDbDetailEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1