public int compare(final IssueLink issueLink1, final IssueLink issueLink2) { if (issueLink1 == null || issueLink2 == null) throw new IllegalArgumentException("Cannot compare null values"); Long sequence1 = issueLink1.getSequence(); Long sequence2 = issueLink2.getSequence(); if (sequence1 != null && sequence2 != null) { // If we have both sequences then use their way of comparing return sequence1.compareTo(sequence2); } else if (sequence1 == null && sequence2 == null) { // If neither sequence exists they objects are equal return 0; } else if (sequence1 == null) { // o1 should come first as its sequence is null return -1; } else { // o2 should come first as its sequence is null return 1; } } }
@Override public SubTaskBean getSubTaskBean(Issue issue, ApplicationUser remoteUser) { SubTaskBeanImpl subTaskBean = new SubTaskBeanImpl(); final Collection<IssueLink> subTaskIssueLinks = getSubTaskIssueLinks(issue.getId()); for (final IssueLink subTaskIssueLink : subTaskIssueLinks) { Issue subTaskIssue = subTaskIssueLink.getDestinationObject(); // Check that the remote user has the permissions to actually see the sub-task due to issue level security. // Even though we keep the issue security level the same on sub-tasks and parent issues // due to things like 'assignee' and 'reporter' permissions, it is possible to have // a situation where a user can see the parent issue but not its sub task, or vice versa if (permissionManager.hasPermission(Permissions.BROWSE, subTaskIssue, remoteUser)) { subTaskBean.addSubTask(subTaskIssueLink.getSequence(), subTaskIssue, issue); } } return subTaskBean; }
@Override public FieldMap fieldMapFrom(final IssueLink value) { return new FieldMap("id", value.getId()) .add("linktype", value.getLinkTypeId()) .add("source", value.getSourceId()) .add("destination", value.getDestinationId()) .add("sequence", value.getSequence()); } }