private Set<String> getVersionsByIds(com.atlassian.jira.rest.client.api.domain.Project jiraProject) { Set<String> versionsIds = new HashSet<>(); for (com.atlassian.jira.rest.client.api.domain.Version version : jiraProject.getVersions()) { versionsIds.add(String.valueOf(version.getId())); } return versionsIds; }
private Set<String> getComponentsByIds(com.atlassian.jira.rest.client.api.domain.Project jiraProject) { Set<String> componentsIds = new HashSet<>(); for (com.atlassian.jira.rest.client.api.domain.BasicComponent component : jiraProject.getComponents()) { componentsIds.add(String.valueOf(component.getId())); } return componentsIds; } }
jiraProject.getKey(), lastUpdate); projects.get(jiraProject.getKey()); event.setNewProjects(Lists.newArrayList(jiraProject.getKey())); sendNotification(event); projects.put(jiraProject.getKey(), project); Set<Component> components = getAllComponents(jiraProject.getKey(), jiraProject.getComponents()); Map<String, Component> oldComponentsMap = storage.loadComponents(jiraProject.getKey()); event.setProject(jiraProject.getKey()); for (String id : newComponents) { event.append(Modification.create().component(id)); storage.storeComponents(jiraProject.getKey(), components); Set<org.smartdeveloperhub.harvesters.it.backend.Version> versions = getAllVersions(jiraProject.getKey(), jiraProject.getVersions()); Map<String, org.smartdeveloperhub.harvesters.it.backend.Version> oldVersionsMap = storage.loadVersions(jiraProject.getKey()); storage.storeVersions(jiraProject.getKey(), versions); storage.storeIssues(jiraProject.getKey(), issues.values());
@Override public Project parse(JSONObject json) throws JSONException { URI self = JsonParseUtil.getSelfUri(json); final Iterable<String> expandos = parseExpandos(json); final BasicUser lead = JsonParseUtil.parseBasicUser(json.getJSONObject("lead")); final String key = json.getString("key"); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String name = JsonParseUtil.getOptionalString(json, "name"); final String urlStr = JsonParseUtil.getOptionalString(json, "url"); URI uri; try { uri = urlStr == null || "".equals(urlStr) ? null : new URI(urlStr); } catch (URISyntaxException e) { uri = null; } String description = JsonParseUtil.getOptionalString(json, "description"); if ("".equals(description)) { description = null; } final Collection<Version> versions = JsonParseUtil.parseJsonArray(json.getJSONArray("versions"), versionJsonParser); final Collection<BasicComponent> components = JsonParseUtil.parseJsonArray(json .getJSONArray("components"), componentJsonParser); final JSONArray issueTypesArray = json.optJSONArray("issueTypes"); final OptionalIterable<IssueType> issueTypes = JsonParseUtil.parseOptionalJsonArray(issueTypesArray, issueTypeJsonParser); final Collection<BasicProjectRole> projectRoles = basicProjectRoleJsonParser.parse(JsonParseUtil .getOptionalJsonObject(json, "roles")); return new Project(expandos, self, key, id, name, description, lead, uri, versions, components, issueTypes, projectRoles); }
/** * Method for building {@link Project} from Jira projects. * @param jiraProject for retrieve Project information. * @param topIssues of the project. * @param childIssues of the project. * @return {@link Project} */ public Project createProject(com.atlassian.jira.rest.client.api.domain.Project jiraProject, Set<Issue> topIssues, Set<Issue> childIssues) { Project project = new Project(); project.setId(jiraProject.getKey()); project.setName(jiraProject.getName()); project.setVersions(getVersionsByIds(jiraProject)); project.setComponents(getComponentsByIds(jiraProject)); Set<String> topIds = getIssuesByIds(topIssues); Set<String> issuesIds = getIssuesByIds(childIssues); issuesIds.addAll(topIds); project.setTopIssues(topIds); project.setIssues(issuesIds); return project; }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { Iterable<BasicProject> basicProjects = jiraRestClient.getProjectClient().getAllProjects().get(); if (!basicProjects.iterator().hasNext()) { System.out.println("No projects available or visible to the current user"); } else { System.out.println(String.format(DEFAULT_ROW_FORMAT, "Key", "Name", "Description")); for (BasicProject eachProject : basicProjects) { String description = jiraRestClient.getProjectClient().getProject(eachProject.getKey()).get().getDescription(); System.out.println( String.format(DEFAULT_ROW_FORMAT, eachProject.getKey(), eachProject.getName(), description == null ? "" : removeNewLines(description))); } } } }
@Override public Project parse(JSONObject json) throws JSONException { URI self = JsonParseUtil.getSelfUri(json); final Iterable<String> expandos = parseExpandos(json); final BasicUser lead = JsonParseUtil.parseBasicUser(json.getJSONObject("lead")); final String key = json.getString("key"); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String name = JsonParseUtil.getOptionalString(json, "name"); final String urlStr = JsonParseUtil.getOptionalString(json, "url"); URI uri; try { uri = urlStr == null || "".equals(urlStr) ? null : new URI(urlStr); } catch (URISyntaxException e) { uri = null; } String description = JsonParseUtil.getOptionalString(json, "description"); if ("".equals(description)) { description = null; } final Collection<Version> versions = JsonParseUtil.parseJsonArray(json.getJSONArray("versions"), versionJsonParser); final Collection<BasicComponent> components = JsonParseUtil.parseJsonArray(json .getJSONArray("components"), componentJsonParser); final JSONArray issueTypesArray = json.optJSONArray("issueTypes"); final OptionalIterable<IssueType> issueTypes = JsonParseUtil.parseOptionalJsonArray(issueTypesArray, issueTypeJsonParser); final Collection<BasicProjectRole> projectRoles = basicProjectRoleJsonParser.parse(JsonParseUtil .getOptionalJsonObject(json, "roles")); return new Project(expandos, self, key, id, name, description, lead, uri, versions, components, issueTypes, projectRoles); }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { Iterable<BasicProject> basicProjects = jiraRestClient.getProjectClient().getAllProjects().get(); if (!basicProjects.iterator().hasNext()) { System.out.println("No projects available or visible to the current user"); } else { System.out.println(String.format(DEFAULT_ROW_FORMAT, "Key", "Name", "Description")); for (BasicProject eachProject : basicProjects) { String description = jiraRestClient.getProjectClient().getProject(eachProject.getKey()).get().getDescription(); System.out.println( String.format(DEFAULT_ROW_FORMAT, eachProject.getKey(), eachProject.getName(), description == null ? "" : removeNewLines(description))); } } } }
@Override public boolean isCPReleased(String cpVersion) { // For Jira, only accept GA version format x.y.z.GA, e.g. 7.1.2.GA // ignore CR version like 7.0.7.CR3 Matcher matcher = JIRAFIXVERSION.matcher(cpVersion); if (!matcher.matches()) { return false; } Promise<Project> promise = restClient.getProjectClient().getProject("JBEAP"); Project project = promise.claim(); Optional<Version> version = StreamSupport.stream(project.getVersions().spliterator(), false) .filter(v -> v.getName().equals(cpVersion)) .findAny(); if (version.isPresent()) { return version.get().isReleased(); } return false; } }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey; final Iterable<BasicComponent> components = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getComponents(); if (!components.iterator().hasNext()) { System.out.println("No components found for project '" + theProjectKey + "'"); return; } System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description")); for (BasicComponent eachComponent : components) { System.out.println( String.format(DEFAULT_ROW_FORMAT, eachComponent.getId(), eachComponent.getName(), eachComponent.getDescription() == null ? "" : removeNewLines(eachComponent.getDescription()))); } } }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey; final Iterable<Version> versions = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getVersions(); if (!versions.iterator().hasNext()) { System.out.println("No versions found for project '" + theProjectKey + "'."); return; } System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description")); for (Version eachVersion : versions) { System.out.println( String.format( DEFAULT_ROW_FORMAT, eachVersion.getId(), eachVersion.getName(), eachVersion.getDescription() == null ? "" : removeNewLines(eachVersion.getDescription()))); } } }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey; final Iterable<BasicComponent> components = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getComponents(); if (!components.iterator().hasNext()) { System.out.println("No components found for project '" + theProjectKey + "'"); return; } System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description")); for (BasicComponent eachComponent : components) { System.out.println( String.format(DEFAULT_ROW_FORMAT, eachComponent.getId(), eachComponent.getName(), eachComponent.getDescription() == null ? "" : removeNewLines(eachComponent.getDescription()))); } } }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey; final Iterable<Version> versions = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getVersions(); if (!versions.iterator().hasNext()) { System.out.println("No versions found for project '" + theProjectKey + "'."); return; } System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description")); for (Version eachVersion : versions) { System.out.println( String.format( DEFAULT_ROW_FORMAT, eachVersion.getId(), eachVersion.getName(), eachVersion.getDescription() == null ? "" : removeNewLines(eachVersion.getDescription()))); } } }
IssueInput issueToFluentUpdate(Issue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue, Project project) throws NotFoundException { checkUnsupportedUpdateFields(issue); IssueInputBuilder inputBuilder = new IssueInputBuilder(jiraIssue.getProject().getKey(), jiraIssue.getIssueType().getId()); issue.getSummary().ifPresent(inputBuilder::setSummary); inputBuilder.setFieldInput(new FieldInput(IssueFieldId.COMPONENTS_FIELD, issue.getComponents().stream().map(e -> ComplexIssueInputFieldValue.with("name", e)).collect(Collectors.toList())) ); issue.getDescription().ifPresent(inputBuilder::setDescription); issue.getAssignee().ifPresent(assignee -> inputBuilder.setFieldInput( new FieldInput(IssueFieldId.ASSIGNEE_FIELD, ComplexIssueInputFieldValue.with("name", assignee.getName().orElseThrow(this::nullUsername))))); // this is ok but does nothing if there is no permissions. issue.getStage().getStateMap().entrySet() .stream().filter(entry -> entry.getValue() != FlagStatus.NO_SET) .forEach(entry -> inputBuilder.setFieldInput(new FieldInput(JSON_CUSTOM_FIELD + FLAG_MAP.get(entry.getKey()), entry.getValue().getSymbol()))); Map<String, Version> versionsMap = StreamSupport.stream(project.getVersions().spliterator(), false) .collect(Collectors.toMap(Version::getName, Function.identity())); updateFixVersions(issue, versionsMap, inputBuilder); updateStreamStatus(issue, jiraIssue, versionsMap, inputBuilder); return inputBuilder.build(); }