use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class OAuthController method renderAuth.
@RequestMapping("/social/{source}")
public ModelAndView renderAuth(@PathVariable("source") String source, HttpServletResponse response, HttpServletRequest request) {
SocialConfig socialConfig = sysSocialConfigService.getByPlatform(source);
if (null == socialConfig) {
throw new ZhydException(source + " 平台的配置尚未完成,暂时不支持登录!");
}
SocialStrategy socialStrategy = new SocialStrategy(japUserService, new JapConfig());
JapResponse japResponse = socialStrategy.authenticate(JapUtil.blogSocialConfig2JapSocialConfig(socialConfig, source), request, response);
if (!japResponse.isSuccess()) {
throw new ZhydException(japResponse.getMessage());
}
if (japResponse.isRedirectUrl()) {
return ResultUtil.redirect((String) japResponse.getData());
} else {
JapUser japUser = (JapUser) japResponse.getData();
User user = (User) japUser.getAdditional();
SessionUtil.setUser(user);
return ResultUtil.redirect("/");
}
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class BeanConvertUtil method doConvert.
/**
* source --> target 的转换
*
* @param source 被转换的对象
* @param target 转换成的对象
* @param <T>
* @return
*/
public static <T> T doConvert(Object source, Class<T> target) {
if (null == source || null == target) {
return null;
}
try {
T t = target.newInstance();
BeanUtils.copyProperties(source, t);
return t;
} catch (InstantiationException e) {
throw new ZhydException(target + " - 可能为一个抽象类、接口、数组类、基本类型或者该类缺少无参构造方法!", e);
} catch (IllegalAccessException e) {
throw new ZhydException(target + " - 该类或其构造方法是不可访问的,或该类缺少无参构造方法!", e);
} catch (FatalBeanException e) {
throw new ZhydException(target + " - 序列化失败!", e);
}
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class BaseFileUploader method getApiClient.
ApiClient getApiClient(String uploadType) {
SysConfigService configService = SpringContextHolder.getBean(SysConfigService.class);
Map<String, Object> config = configService.getConfigs();
String storageType = null;
if (null == config || StringUtils.isEmpty((storageType = (String) config.get(ConfigKeyEnum.STORAGE_TYPE.getKey())))) {
throw new ZhydException("[文件服务]当前系统暂未配置文件服务相关的内容!");
}
ApiClient res = null;
switch(storageType) {
case "local":
String localFileUrl = (String) config.get(ConfigKeyEnum.LOCAL_FILE_URL.getKey()), localFilePath = (String) config.get(ConfigKeyEnum.LOCAL_FILE_PATH.getKey());
res = new LocalApiClient().init(localFileUrl, localFilePath, uploadType);
break;
case "qiniu":
String accessKey = (String) config.get(ConfigKeyEnum.QINIU_ACCESS_KEY.getKey()), secretKey = (String) config.get(ConfigKeyEnum.QINIU_SECRET_KEY.getKey()), qiniuBucketName = (String) config.get(ConfigKeyEnum.QINIU_BUCKET_NAME.getKey()), baseUrl = (String) config.get(ConfigKeyEnum.QINIU_BASE_PATH.getKey());
res = new QiniuApiClient().init(accessKey, secretKey, qiniuBucketName, baseUrl, uploadType);
break;
case "aliyun":
String endpoint = (String) config.get(ConfigKeyEnum.ALIYUN_ENDPOINT.getKey()), accessKeyId = (String) config.get(ConfigKeyEnum.ALIYUN_ACCESS_KEY.getKey()), accessKeySecret = (String) config.get(ConfigKeyEnum.ALIYUN_ACCESS_KEY_SECRET.getKey()), url = (String) config.get(ConfigKeyEnum.ALIYUN_FILE_URL.getKey()), aliYunBucketName = (String) config.get(ConfigKeyEnum.ALIYUN_BUCKET_NAME.getKey());
res = new AliyunOssApiClient().init(endpoint, accessKeyId, accessKeySecret, url, aliYunBucketName, uploadType);
break;
case "youpaiyun":
break;
default:
break;
}
if (null == res) {
throw new GlobalFileException("[文件服务]当前系统暂未配置文件服务相关的内容!");
}
return res;
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class BizTagsServiceImpl method removeByPrimaryKey.
@Override
@Transactional(rollbackFor = Exception.class)
@RedisCache(flush = true)
public boolean removeByPrimaryKey(Long primaryKey) {
BizArticleTags articleTag = new BizArticleTags();
articleTag.setTagId(primaryKey);
List<BizArticleTags> articleTags = bizArticleTagsMapper.select(articleTag);
if (!CollectionUtils.isEmpty(articleTags)) {
throw new ZhydException("当前标签下存在文章信息,禁止删除!");
}
return bizTagsMapper.deleteByPrimaryKey(primaryKey) > 0;
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class BizTagsServiceImpl method insert.
@Override
@Transactional(rollbackFor = Exception.class)
@RedisCache(flush = true)
public Tags insert(Tags entity) {
Assert.notNull(entity, "Tags不可为空!");
if (this.getByName(entity.getName()) != null) {
throw new ZhydException("标签添加失败,标签已存在![" + entity.getName() + "]");
}
entity.setUpdateTime(new Date());
entity.setCreateTime(new Date());
bizTagsMapper.insertSelective(entity.getBizTags());
return entity;
}
Aggregations