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;
}
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))));
}
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;
}
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))));
}
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();
}
Aggregations