Search in sources :

Example 1 with SourceFileBasicEntity

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

the class SourceFileServiceImpl method updateBasic.

@Override
public boolean updateBasic(SourceFileBasicInfo basicInfo, String operator) {
    LOGGER.info("begin to update file data source basic={}", basicInfo);
    Preconditions.checkNotNull(basicInfo, "file 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 {
        SourceFileBasicEntity basicEntity = fileBasicMapper.selectByPrimaryKey(basicInfo.getId());
        if (basicEntity == null) {
            LOGGER.error("file 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);
        fileBasicMapper.updateByPrimaryKeySelective(basicEntity);
    }
    LOGGER.info("success to update file data source basic");
    return true;
}
Also used : SourceFileBasicEntity(org.apache.inlong.manager.dao.entity.SourceFileBasicEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException)

Example 2 with SourceFileBasicEntity

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

the class SourceFileServiceImpl method logicDeleteBasic.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
    LOGGER.info("begin to delete file data source basic, id={}", id);
    Preconditions.checkNotNull(id, "file data source basic's id is null");
    SourceFileBasicEntity entity = fileBasicMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("file 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<SourceFileDetailEntity> detailEntities = fileDetailMapper.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 = fileBasicMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete file data source basic");
    return resultCount >= 0;
}
Also used : SourceFileBasicEntity(org.apache.inlong.manager.dao.entity.SourceFileBasicEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceFileDetailEntity(org.apache.inlong.manager.dao.entity.SourceFileDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SourceFileBasicEntity

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

the class SourceFileServiceImpl method getBasicByIdentifier.

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

Example 4 with SourceFileBasicEntity

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

the class SourceFileServiceImpl method saveBasic.

@Override
public Integer saveBasic(SourceFileBasicInfo basicInfo, String operator) {
    LOGGER.info("begin to save file data source basic={}", basicInfo);
    Preconditions.checkNotNull(basicInfo, "file data source basic is empty");
    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
    SourceFileBasicEntity exist = fileBasicMapper.selectByIdentifier(groupId, streamId);
    if (exist != null) {
        LOGGER.error("file data source basic already exists, please check");
        throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
    }
    SourceFileBasicEntity entity = CommonBeanUtils.copyProperties(basicInfo, SourceFileBasicEntity::new);
    entity.setCreator(operator);
    entity.setModifier(operator);
    entity.setCreateTime(new Date());
    fileBasicMapper.insertSelective(entity);
    LOGGER.info("success to save file data source basic");
    return entity.getId();
}
Also used : SourceFileBasicEntity(org.apache.inlong.manager.dao.entity.SourceFileBasicEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) Date(java.util.Date)

Aggregations

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