Java Code Examples for com.atlassian.bitbucket.setting.Settings#getString()

The following examples show how to use com.atlassian.bitbucket.setting.Settings#getString() . 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: FileSizeHook.java    From stash-filehooks-plugin with Apache License 2.0 6 votes vote down vote up
private List<FileSizeHookSetting> getSettings(Settings settings) {
    List<FileSizeHookSetting> configurations = new ArrayList<>();
    String includeRegex;
    Long size;
    String excludeRegex;
    String branchesRegex;

    for (int i = 1; i <= MAX_SETTINGS; i++) {
        includeRegex = settings.getString(SETTINGS_INCLUDE_PATTERN_PREFIX + i);
        if (includeRegex != null) {
            excludeRegex = settings.getString(SETTINGS_EXCLUDE_PATTERN_PREFIX + i);
            size = settings.getLong(SETTINGS_SIZE_PREFIX + i);
            branchesRegex = settings.getString(SETTINGS_BRANCHES_PATTERN_PREFIX + i);
            configurations.add(new FileSizeHookSetting(size, includeRegex, excludeRegex, branchesRegex));
        }
    }

    return configurations;
}
 
Example 2
Source File: RepositoryHookSettingsValidator.java    From TeamcityTriggerHook with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Validates form data in repository triggers tab
 *
 * @param settings - to be validated.
 * @param errors - callback for reporting validation errors.
 * @throws IOException if JSON parsing error occurs
 */
private void validaterepositoryTriggersTab(final Settings settings, final SettingsValidationErrors errors) throws IOException {
    final String repositoryTriggersJson = settings.getString(Field.REPOSITORY_TRIGGERS_JSON, StringUtils.EMPTY);
    final ObjectMapper mapper = new ObjectMapper();
    final Map<String, Trigger> triggerMap = mapper.readValue(repositoryTriggersJson, mapper.getTypeFactory().constructParametricType(HashMap.class, String.class, Trigger.class));
    for (final Map.Entry<String, Trigger> triggerEntry : triggerMap.entrySet()) {
        final Trigger trigger = triggerEntry.getValue();
        if (StringUtils.isBlank(trigger.getTarget())) {
            errors.addFieldError(triggerEntry.getKey(), this.i18n.getText("error.string.empty"));
        } else if (StringUtils.containsWhitespace(trigger.getTarget())) {
            errors.addFieldError(triggerEntry.getKey(), this.i18n.getText("error.string.contains.whitespace"));
        }
        try {
            final Pattern pattern = Pattern.compile(triggerEntry.getValue().getRegex(), Pattern.CASE_INSENSITIVE);
            final Matcher matcher = pattern.matcher(BRANCH_TEST_STRING);
            if (matcher.groupCount() != 1) {
                errors.addFieldError(triggerEntry.getKey(), this.i18n.getText("error.regex.needs.capturing"));
            }
        } catch (final PatternSyntaxException e) {
            errors.addFieldError(triggerEntry.getKey(), e.getLocalizedMessage());
        }
    }
}
 
Example 3
Source File: MirrorRepositoryHook.java    From stash-hook-mirror with MIT License 6 votes vote down vote up
private List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes, boolean defAtomic) {
    Map<String, Object> allSettings = settings.asMap();
    int count = 0;

    List<MirrorSettings> results = new ArrayList<>();
    for (String key : allSettings.keySet()) {
        if (key.startsWith(SETTING_MIRROR_REPO_URL)) {
            String suffix = key.substring(SETTING_MIRROR_REPO_URL.length());

            MirrorSettings ms = new MirrorSettings();
            ms.mirrorRepoUrl = settings.getString(SETTING_MIRROR_REPO_URL + suffix, "");
            ms.username = settings.getString(SETTING_USERNAME + suffix, "");
            ms.password = settings.getString(SETTING_PASSWORD + suffix, "");
            ms.refspec = (settings.getString(SETTING_REFSPEC + suffix, ""));
            ms.tags = (settings.getBoolean(SETTING_TAGS + suffix, defTags));
            ms.notes = (settings.getBoolean(SETTING_NOTES + suffix, defNotes));
            ms.atomic = (settings.getBoolean(SETTING_ATOMIC + suffix, defAtomic));
            ms.suffix = String.valueOf(count++);

            results.add(ms);
        }
    }

    return results;
}
 
Example 4
Source File: FileNameHook.java    From stash-filehooks-plugin with Apache License 2.0 5 votes vote down vote up
private FileNameHookSetting getSettings(Settings settings) {
    String includeRegex = settings.getString(SETTINGS_INCLUDE_PATTERN);
    String excludeRegex = settings.getString(SETTINGS_EXCLUDE_PATTERN);
    String branchesRegex = settings.getString(SETTINGS_BRANCHES_PATTERN);

    return new FileNameHookSetting(includeRegex, excludeRegex, branchesRegex);
}
 
Example 5
Source File: RepositoryHookSettingsValidator.java    From TeamcityTriggerHook with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Validates form fields in connections tab
 *
 * @param settings - to be validated.
 * @param errors - callback for reporting validation errors.
 */
private void validateConnectionTab(final Settings settings, final SettingsValidationErrors errors) {
    
    final Boolean isDebugOn = settings.getBoolean(Field.DEBUG);
            
    final String bitbucketUrl = settings.getString(Field.BITBUCKET_URL, StringUtils.EMPTY);
    if (!URL_VALIDATION_PATTERN.matcher(bitbucketUrl).matches()) {
        errors.addFieldError(Field.BITBUCKET_URL, this.i18n.getText("error.invalid.url"));
    }

    final String teamCityUrl = settings.getString(Field.TEAMCITY_URL, StringUtils.EMPTY);
    if (!URL_VALIDATION_PATTERN.matcher(teamCityUrl).matches()) {
        errors.addFieldError(Field.TEAMCITY_URL, this.i18n.getText("error.invalid.url"));
    }

    final String teamCityUserName = settings.getString(Field.TEAMCITY_USERNAME, StringUtils.EMPTY);
    if (StringUtils.EMPTY.equals(teamCityUserName)) {
        errors.addFieldError(Field.TEAMCITY_USERNAME, this.i18n.getText("error.required.field"));
    }

    final String teamCityPassword = settings.getString(Field.TEAMCITY_PASSWORD, StringUtils.EMPTY);
    if (StringUtils.EMPTY.equals(teamCityPassword)) {
        errors.addFieldError(Field.TEAMCITY_PASSWORD, this.i18n.getText("error.required.field"));
    }

    if (!Constant.TEAMCITY_PASSWORD_SAVED_VALUE.equals(teamCityPassword)) {
        errors.addFieldError(Field.TEAMCITY_PASSWORD, this.i18n.getText("error.require.validation", this.i18n.getText("connetion.test.button")));
    }
}