Java Code Examples for cn.hutool.core.convert.Convert#toBool()

The following examples show how to use cn.hutool.core.convert.Convert#toBool() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinIOServiceImpl.java    From zfile with MIT License 10 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();
    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withPathStyleAccessEnabled(true)
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "minio")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 2
Source File: MonitorListController.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 开启或关闭监控
 *
 * @param id     id
 * @param status 状态
 * @param type   类型
 * @return json
 */
@RequestMapping(value = "changeStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@OptLog(UserOperateLogV1.OptType.ChangeStatusMonitor)
@Feature(method = MethodFeature.EDIT)
public String changeStatus(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "id不能为空")) String id,
                           String status, String type) {
    MonitorModel monitorModel = monitorService.getItem(id);
    if (monitorModel == null) {
        return JsonMessage.getString(405, "不存在监控项啦");
    }
    boolean bStatus = Convert.toBool(status, false);
    if ("status".equalsIgnoreCase(type)) {
        monitorModel.setStatus(bStatus);
    } else if ("restart".equalsIgnoreCase(type)) {
        monitorModel.setAutoRestart(bStatus);
    } else {
        return JsonMessage.getString(405, "type不正确");
    }
    monitorService.updateItem(monitorModel);
    return JsonMessage.getString(200, "修改成功");
}
 
Example 3
Source File: TencentServiceImpl.java    From zfile with MIT License 6 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String secretId = stringStorageConfigMap.get(StorageConfigConstant.SECRET_ID_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();
    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(secretId) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(secretId, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "cos")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 4
Source File: SystemConfigController.java    From Jpom with MIT License 5 votes vote down vote up
@RequestMapping(value = "save_config.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String saveConfig(String content, String restart) {
    if (StrUtil.isEmpty(content)) {
        return JsonMessage.getString(405, "内容不能为空");
    }
    try {
        YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader();
        ByteArrayResource resource = new ByteArrayResource(content.getBytes());
        yamlPropertySourceLoader.load("test", resource);
    } catch (Exception e) {
        DefaultSystemLog.getLog().warn("内容格式错误,请检查修正", e);
        return JsonMessage.getString(500, "内容格式错误,请检查修正:" + e.getMessage());
    }
    if (JpomManifest.getInstance().isDebug()) {
        return JsonMessage.getString(405, "调试模式不支持在线修改,请到resource目录下");
    }
    File resourceFile = ExtConfigBean.getResourceFile();
    FileUtil.writeString(content, resourceFile, CharsetUtil.CHARSET_UTF_8);

    if (Convert.toBool(restart, false)) {
        // 重启
        ThreadUtil.execute(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ignored) {
            }
            JpomApplication.restart();
        });
    }
    return JsonMessage.getString(200, "修改成功");
}
 
Example 5
Source File: SystemConfigController.java    From Jpom with MIT License 5 votes vote down vote up
@RequestMapping(value = "save_config.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@OptLog(UserOperateLogV1.OptType.EditSysConfig)
@SystemPermission
public String saveConfig(String nodeId, String content, String restart) {
    if (StrUtil.isNotEmpty(nodeId)) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.SystemSaveConfig).toString();
    }
    if (StrUtil.isEmpty(content)) {
        return JsonMessage.getString(405, "内容不能为空");
    }
    try {
        YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader();
        ByteArrayResource resource = new ByteArrayResource(content.getBytes(StandardCharsets.UTF_8));
        yamlPropertySourceLoader.load("test", resource);
    } catch (Exception e) {
        DefaultSystemLog.getLog().warn("内容格式错误,请检查修正", e);
        return JsonMessage.getString(500, "内容格式错误,请检查修正:" + e.getMessage());
    }
    if (JpomManifest.getInstance().isDebug()) {
        return JsonMessage.getString(405, "调试模式不支持在线修改,请到resource目录下");
    }
    File resourceFile = ExtConfigBean.getResourceFile();
    FileUtil.writeString(content, resourceFile, CharsetUtil.CHARSET_UTF_8);

    if (Convert.toBool(restart, false)) {
        // 重启
        ThreadUtil.execute(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ignored) {
            }
            JpomApplication.restart();
        });
    }
    return JsonMessage.getString(200, "修改成功");
}
 
Example 6
Source File: HuaweiServiceImpl.java    From zfile with MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "obs")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 7
Source File: S3ServiceImpl.java    From zfile with MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    super.domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    super.bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    super.isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    String pathStyle = stringStorageConfigMap.get(StorageConfigConstant.PATH_STYLE).getValue();

    boolean isPathStyle = "path-style".equals(pathStyle);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withPathStyleAccessEnabled(isPathStyle)
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 8
Source File: AliyunServiceImpl.java    From zfile with MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
        storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    super.domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    super.bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    super.isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

        super.s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "oss")).build();
        testConnection();
        isInitialized = true;
    }
}
 
Example 9
Source File: QiniuServiceImpl.java    From zfile with MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint =  stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "kodo")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 10
Source File: BaseJpomInterceptor.java    From Jpom with MIT License 4 votes vote down vote up
public static boolean isPage(HttpServletRequest request) {
    return Convert.toBool(request.getAttribute("Page_Req"), true);
}
 
Example 11
Source File: Global.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
/**
 * 获取ip地址开关
 */
public static Boolean isAddressEnabled() {
    return Convert.toBool(getConfig("ruoyi.addressEnabled"));
}
 
Example 12
Source File: Global.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
/**
 * 是否开启演示实例
 */
public static Boolean isDemoEnabled() {
    return Convert.toBool(getConfig("ruoyi.demoEnabled"), false);
}
 
Example 13
Source File: Kv.java    From magic-starter with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 获得特定类型值
 *
 * @param attr 字段名
 * @return 字段值
 */
public Boolean getBool(String attr) {
	return Convert.toBool(get(attr), null);
}
 
Example 14
Source File: JSONObject.java    From RuoYi with Apache License 2.0 2 votes vote down vote up
/**
 * 获取指定字段的布尔值。如果字段不存在,或者无法转换为布尔型,返回defaultValue。
 *
 * @param name         字段名,支持多级。
 * @param defaultValue 查询失败时,返回的值。
 * @return 返回指定的布尔值,或者defaultValue。
 */
public Boolean boolValue(final String name, final Boolean defaultValue) {
    return Convert.toBool(boolValue(name), defaultValue);
}
 
Example 15
Source File: JSONObject.java    From RuoYi with Apache License 2.0 2 votes vote down vote up
/**
 * 字段值按照布尔类型返回。如果不存在,返回defaultValue。
 *
 * @param name         字段名。
 * @param defaultValue 字段不存在时,返回的值。
 * @return 字段值。
 */
public Boolean getBool(final String name, final Boolean defaultValue) {
    return Convert.toBool(getBool(name), defaultValue);
}