Search in sources :

Example 1 with DataChangedEvent

use of org.apache.shenyu.admin.listener.DataChangedEvent in project incubator-shenyu by apache.

the class MetaDataServiceImpl method delete.

@Override
@Transactional(rollbackFor = Exception.class)
public int delete(final List<String> ids) {
    int count = 0;
    Set<String> idSet = Optional.ofNullable(ids).orElseGet(ArrayList::new).stream().filter(StringUtils::isNotEmpty).collect(Collectors.toSet());
    if (CollectionUtils.isNotEmpty(idSet)) {
        List<MetaDataDO> metaDataDoList = metaDataMapper.selectByIdSet(idSet);
        List<MetaData> metaDataList = Optional.ofNullable(metaDataDoList).orElseGet(ArrayList::new).stream().map(MetaDataTransfer.INSTANCE::mapToData).collect(Collectors.toList());
        count = metaDataMapper.deleteByIdSet(idSet);
        eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.META_DATA, DataEventTypeEnum.DELETE, metaDataList));
    }
    return count;
}
Also used : DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) MetaData(org.apache.shenyu.common.dto.MetaData) MetaDataDO(org.apache.shenyu.admin.model.entity.MetaDataDO) MetaDataTransfer(org.apache.shenyu.admin.transfer.MetaDataTransfer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DataChangedEvent

use of org.apache.shenyu.admin.listener.DataChangedEvent in project incubator-shenyu by apache.

the class MetaDataServiceImpl method saveOrUpdateMetaData.

@Override
public void saveOrUpdateMetaData(final MetaDataDO exist, final MetaDataRegisterDTO metaDataDTO) {
    DataEventTypeEnum eventType;
    MetaDataDO metaDataDO = MetaDataTransfer.INSTANCE.mapRegisterDTOToEntity(metaDataDTO);
    if (Objects.isNull(exist)) {
        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
        metaDataDO.setId(UUIDUtils.getInstance().generateShortUuid());
        metaDataDO.setDateCreated(currentTime);
        metaDataDO.setDateUpdated(currentTime);
        metaDataMapper.insert(metaDataDO);
        eventType = DataEventTypeEnum.CREATE;
    } else {
        metaDataDO.setId(exist.getId());
        metaDataMapper.update(metaDataDO);
        eventType = DataEventTypeEnum.UPDATE;
    }
    // publish MetaData's event
    eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.META_DATA, eventType, Collections.singletonList(MetaDataTransfer.INSTANCE.mapToData(metaDataDO))));
}
Also used : DataEventTypeEnum(org.apache.shenyu.common.enums.DataEventTypeEnum) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) MetaDataDO(org.apache.shenyu.admin.model.entity.MetaDataDO) Timestamp(java.sql.Timestamp)

Example 3 with DataChangedEvent

use of org.apache.shenyu.admin.listener.DataChangedEvent in project incubator-shenyu by apache.

the class PluginServiceImpl method createOrUpdate.

/**
 * create or update plugin.
 *
 * @param pluginDTO {@linkplain PluginDTO}
 * @return rows
 */
@Override
@Transactional(rollbackFor = Exception.class)
public String createOrUpdate(final PluginDTO pluginDTO) {
    final String msg = checkData(pluginDTO);
    if (StringUtils.isNoneBlank(msg)) {
        return msg;
    }
    PluginDO pluginDO = PluginDO.buildPluginDO(pluginDTO);
    DataEventTypeEnum eventType = DataEventTypeEnum.CREATE;
    if (StringUtils.isBlank(pluginDTO.getId())) {
        insertPluginDataToResource(pluginDTO);
        pluginMapper.insertSelective(pluginDO);
    } else {
        eventType = DataEventTypeEnum.UPDATE;
        pluginMapper.updateSelective(pluginDO);
    }
    // publish change event.
    eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, eventType, Collections.singletonList(PluginTransfer.INSTANCE.mapToData(pluginDO))));
    return StringUtils.EMPTY;
}
Also used : DataEventTypeEnum(org.apache.shenyu.common.enums.DataEventTypeEnum) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) PluginDO(org.apache.shenyu.admin.model.entity.PluginDO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DataChangedEvent

use of org.apache.shenyu.admin.listener.DataChangedEvent in project incubator-shenyu by apache.

the class RuleServiceImpl method publishEvent.

private void publishEvent(final RuleDO ruleDO, final List<RuleConditionDTO> ruleConditions) {
    SelectorDO selectorDO = selectorMapper.selectById(ruleDO.getSelectorId());
    PluginDO pluginDO = pluginMapper.selectById(selectorDO.getPluginId());
    List<ConditionData> conditionDataList = ruleConditions.stream().map(ConditionTransfer.INSTANCE::mapToRuleDTO).collect(Collectors.toList());
    // publish change event.
    eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.RULE, DataEventTypeEnum.UPDATE, Collections.singletonList(RuleDO.transFrom(ruleDO, pluginDO.getName(), conditionDataList))));
}
Also used : SelectorDO(org.apache.shenyu.admin.model.entity.SelectorDO) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) ConditionData(org.apache.shenyu.common.dto.ConditionData) PluginDO(org.apache.shenyu.admin.model.entity.PluginDO) ConditionTransfer(org.apache.shenyu.admin.transfer.ConditionTransfer)

Example 5 with DataChangedEvent

use of org.apache.shenyu.admin.listener.DataChangedEvent in project incubator-shenyu by apache.

the class AppAuthServiceImpl method updateDetailPath.

@Override
public ShenyuAdminResult updateDetailPath(final AuthPathWarpDTO authPathWarpDTO) {
    AppAuthDO appAuthDO = appAuthMapper.selectById(authPathWarpDTO.getId());
    if (Objects.isNull(appAuthDO)) {
        return ShenyuAdminResult.error(AdminConstants.ID_NOT_EXIST);
    }
    List<AuthPathDTO> authPathDTOList = authPathWarpDTO.getAuthPathDTOList();
    if (CollectionUtils.isNotEmpty(authPathDTOList)) {
        authPathMapper.deleteByAuthId(authPathWarpDTO.getId());
        List<AuthPathDO> collect = authPathDTOList.stream().filter(Objects::nonNull).map(authPathDTO -> AuthPathDO.create(authPathDTO.getPath(), appAuthDO.getId(), authPathDTO.getAppName())).collect(Collectors.toList());
        authPathMapper.batchSave(collect);
    }
    eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.APP_AUTH, DataEventTypeEnum.UPDATE, Lists.newArrayList(buildByEntity(appAuthDO))));
    return ShenyuAdminResult.success();
}
Also used : AuthParamDTO(org.apache.shenyu.admin.model.dto.AuthParamDTO) AuthApplyDTO(org.apache.shenyu.admin.model.dto.AuthApplyDTO) AppAuthQuery(org.apache.shenyu.admin.model.query.AppAuthQuery) AppAuthService(org.apache.shenyu.admin.service.AppAuthService) AuthPathWarpDTO(org.apache.shenyu.admin.model.dto.AuthPathWarpDTO) AuthParamMapper(org.apache.shenyu.admin.mapper.AuthParamMapper) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) AppAuthVO(org.apache.shenyu.admin.model.vo.AppAuthVO) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AuthParamVO(org.apache.shenyu.admin.model.vo.AuthParamVO) SignUtils(org.apache.shenyu.common.utils.SignUtils) Lists(com.google.common.collect.Lists) AuthParamDO(org.apache.shenyu.admin.model.entity.AuthParamDO) BaseDO(org.apache.shenyu.admin.model.entity.BaseDO) CommonPager(org.apache.shenyu.admin.model.page.CommonPager) ShenyuAdminResult(org.apache.shenyu.admin.model.result.ShenyuAdminResult) DataEventTypeEnum(org.apache.shenyu.common.enums.DataEventTypeEnum) Service(org.springframework.stereotype.Service) Map(java.util.Map) AuthPathDO(org.apache.shenyu.admin.model.entity.AuthPathDO) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) AuthPathVO(org.apache.shenyu.admin.model.vo.AuthPathVO) AuthParamData(org.apache.shenyu.common.dto.AuthParamData) AppAuthTransfer(org.apache.shenyu.admin.transfer.AppAuthTransfer) AppAuthData(org.apache.shenyu.common.dto.AppAuthData) AdminConstants(org.apache.shenyu.common.constant.AdminConstants) AppAuthDTO(org.apache.shenyu.admin.model.dto.AppAuthDTO) Set(java.util.Set) Collectors(java.util.stream.Collectors) PageResultUtils(org.apache.shenyu.admin.model.page.PageResultUtils) Objects(java.util.Objects) AppAuthMapper(org.apache.shenyu.admin.mapper.AppAuthMapper) List(java.util.List) AuthPathMapper(org.apache.shenyu.admin.mapper.AuthPathMapper) AppAuthDO(org.apache.shenyu.admin.model.entity.AppAuthDO) Optional(java.util.Optional) ConfigGroupEnum(org.apache.shenyu.common.enums.ConfigGroupEnum) AuthPathDTO(org.apache.shenyu.admin.model.dto.AuthPathDTO) ShenyuResultMessage(org.apache.shenyu.admin.utils.ShenyuResultMessage) Collections(java.util.Collections) AuthPathData(org.apache.shenyu.common.dto.AuthPathData) Transactional(org.springframework.transaction.annotation.Transactional) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) AuthPathDO(org.apache.shenyu.admin.model.entity.AuthPathDO) AuthPathDTO(org.apache.shenyu.admin.model.dto.AuthPathDTO) Objects(java.util.Objects) AppAuthDO(org.apache.shenyu.admin.model.entity.AppAuthDO)

Aggregations

DataChangedEvent (org.apache.shenyu.admin.listener.DataChangedEvent)24 Transactional (org.springframework.transaction.annotation.Transactional)12 DataEventTypeEnum (org.apache.shenyu.common.enums.DataEventTypeEnum)11 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)8 AppAuthDO (org.apache.shenyu.admin.model.entity.AppAuthDO)8 PluginDO (org.apache.shenyu.admin.model.entity.PluginDO)8 AppAuthData (org.apache.shenyu.common.dto.AppAuthData)8 Lists (com.google.common.collect.Lists)7 Collections (java.util.Collections)7 List (java.util.List)7 Map (java.util.Map)7 Objects (java.util.Objects)7 Optional (java.util.Optional)7 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 CollectionUtils (org.apache.commons.collections4.CollectionUtils)7 StringUtils (org.apache.commons.lang3.StringUtils)7 CommonPager (org.apache.shenyu.admin.model.page.CommonPager)7 PageResultUtils (org.apache.shenyu.admin.model.page.PageResultUtils)7