Search in sources :

Example 6 with ZhydException

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("/");
    }
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) JapUser(com.fujieid.jap.core.JapUser) JapConfig(com.fujieid.jap.core.config.JapConfig) User(com.zyd.blog.business.entity.User) JapUser(com.fujieid.jap.core.JapUser) SocialStrategy(com.fujieid.jap.social.SocialStrategy) JapResponse(com.fujieid.jap.core.result.JapResponse) SocialConfig(com.zyd.blog.business.entity.SocialConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ZhydException

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);
    }
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) FatalBeanException(org.springframework.beans.FatalBeanException)

Example 8 with ZhydException

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) LocalApiClient(com.zyd.blog.file.LocalApiClient) QiniuApiClient(com.zyd.blog.file.QiniuApiClient) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) SysConfigService(com.zyd.blog.business.service.SysConfigService) AliyunOssApiClient(com.zyd.blog.file.AliyunOssApiClient) QiniuApiClient(com.zyd.blog.file.QiniuApiClient) AliyunOssApiClient(com.zyd.blog.file.AliyunOssApiClient) LocalApiClient(com.zyd.blog.file.LocalApiClient) ApiClient(com.zyd.blog.file.ApiClient)

Example 9 with ZhydException

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) BizArticleTags(com.zyd.blog.persistence.beans.BizArticleTags) RedisCache(com.zyd.blog.business.annotation.RedisCache) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ZhydException

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) Date(java.util.Date) RedisCache(com.zyd.blog.business.annotation.RedisCache) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ZhydException (com.zyd.blog.framework.exception.ZhydException)11 Transactional (org.springframework.transaction.annotation.Transactional)4 RedisCache (com.zyd.blog.business.annotation.RedisCache)3 User (com.zyd.blog.business.entity.User)2 GlobalFileException (com.zyd.blog.file.exception.GlobalFileException)2 BizArticleTags (com.zyd.blog.persistence.beans.BizArticleTags)2 Date (java.util.Date)2 JapUser (com.fujieid.jap.core.JapUser)1 JapConfig (com.fujieid.jap.core.config.JapConfig)1 JapResponse (com.fujieid.jap.core.result.JapResponse)1 SocialStrategy (com.fujieid.jap.social.SocialStrategy)1 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)1 Article (com.zyd.blog.business.entity.Article)1 Resources (com.zyd.blog.business.entity.Resources)1 SocialConfig (com.zyd.blog.business.entity.SocialConfig)1 Tags (com.zyd.blog.business.entity.Tags)1 ResponseStatus (com.zyd.blog.business.enums.ResponseStatus)1 SysConfigService (com.zyd.blog.business.service.SysConfigService)1 AliyunOssApiClient (com.zyd.blog.file.AliyunOssApiClient)1 ApiClient (com.zyd.blog.file.ApiClient)1