protected long getIssueNumberFromKey(final String pkey) { return IssueKey.from(pkey).getIssueNumber(); }
/** * Helper method to mung an issue key to the given project key. * @param originalProjectKey The project key that the issue should be under. * @param issueKey The issue key to mung. * @return Munged issue key with the specified original project key as the issue prefix. */ public static String computeIssueKeyForOriginalProjectKey(final String originalProjectKey, final String issueKey) { final long issueNumber = IssueKey.from(issueKey).getIssueNumber(); return IssueKey.format(originalProjectKey, issueNumber); }
public long parseKeyNum(final String issueKey) { // For backward compatibility, return -1 on invalid input if (IssueKey.isValidKey(issueKey)) { return IssueKey.from(issueKey).getIssueNumber(); } else { return -1; } }
public String getProjectKeyFromIssueKey(String key) { return IssueKey.from(key).getProjectKey(); }
private GenericValue getIssueFromIssueEntity(final String key) { final IssueKey issueKey; try { issueKey = IssueKey.from(key); } catch (IllegalArgumentException ex) { // For backward compatibility in the getIssue methods which returned null for invalid input return null; } Long projectId = getProjectByKey(issueKey.getProjectKey()); if (projectId == null) { return null; } return getIssueFromIssueEntityByProjectAndNumber(projectId, issueKey.getIssueNumber()); }
@Override @Nullable public File getAttachmentDirectory(@Nonnull final String issueKey) { final IssueKey ik = IssueKey.from(issueKey); final Project project = projectManager.getProjectObjByKey(ik.getProjectKey()); if (project != null) { return getAttachmentDirectory(getAttachmentDirName(), project.getOriginalKey(), IssueKey.format(project.getOriginalKey(), ik.getIssueNumber())); } return null; }
@Override public String apply(final String projectKey) { return IssueKey.format(projectKey, issue.getNumber()); } }))
/** * Returns true if the key is considered "valid" * * @param issueKey the key * @return true if the key is considered "valid" */ public static boolean isValidKey(final String issueKey) { try { from(issueKey); return true; } catch (RuntimeException ex) { return false; } }
@Override public boolean apply(final String issueKey) { return IssueKey.isValidKey(issueKey); } }
/** * Creates an IssueKey object form the given issue key String. * <p> * This does some validation on the format of the given String. * It must contain a dash ('-'), and the substring following the final dash must be a valid number. * It validates that there is at least one character preceding the dash, but it does not validate that this is an * existing key on this instance of JIRA. * * @param key The issue key as a string. eg "ABC_X20-1193" * @return the corresponding IssueKey object. * @throws IllegalArgumentException if the given String is not a valid JIRA Issue key */ public static IssueKey from(final String key) { final int dividerIndex = key.lastIndexOf("-"); if (dividerIndex == -1) { throw new IllegalArgumentException("Invalid Issue Key '" + key + "' - it must contain a dash."); } if (dividerIndex == 0) { throw new IllegalArgumentException("Invalid Issue Key '" + key + "' - it must contain at least one character in the project key part."); } final long number = Long.parseLong(key.substring(dividerIndex + 1)); return new IssueKey(key.substring(0, dividerIndex), number); }
private Pair<Set<String>, Map<String, Set<Long>>> breakDownIssueKeys(@Nonnull final Set<String> issueKeys) { Set<String> invalidKeys = new HashSet<>(); Map<String, Set<Long>> projectKeyIssueNumbers = new HashMap<>(); for (String issueKey : issueKeys) { IssueKey issueKeyObject; try { issueKeyObject = IssueKey.from(issueKey); } catch (IllegalArgumentException ex) { invalidKeys.add(issueKey); continue; } Set<Long> issueNumbers = projectKeyIssueNumbers.get(issueKeyObject.getProjectKey()); if (issueNumbers == null) { issueNumbers = new HashSet<>(); projectKeyIssueNumbers.put(issueKeyObject.getProjectKey(), issueNumbers); } issueNumbers.add(issueKeyObject.getIssueNumber()); } return Pair.of(invalidKeys, projectKeyIssueNumbers); }
public String parseProjectKey(final String issueKey) { if (StringUtils.isBlank(issueKey)) { return null; } else { return IssueKey.from(issueKey).getProjectKey(); } } }
public static String format(final Project project, final long issueNumber) { return format(project.getKey(), issueNumber); }
public long getCountFromKey(String key) { return IssueKey.from(key).getIssueNumber(); }
public void setKey(String key) { setProjectId(null); setNumber(null); if (key != null) { final IssueKey issueKey = IssueKey.from(key); final Project project = projectManager.getProjectObjByKey(issueKey.getProjectKey()); if (project == null) { throw new IllegalArgumentException(String.format("Invalid project key '%s'", issueKey.getProjectKey())); } setProjectObject(project); setNumber(issueKey.getIssueNumber()); } initializeKey(); }
@Override public Promise<Void> move(final Attachment metaData, final String newIssueKey) { final AttachmentKey oldAttachmentKey = attachmentKeyMapper.fromAttachment(metaData); final IssueKey ik = IssueKey.from(newIssueKey); final Project project = projectManager.getProjectObjByKey(ik.getProjectKey()); final String originalProjectKey = project.getOriginalKey(); final AttachmentKey newAttachmentKey = AttachmentKeys.from( originalProjectKey, newIssueKey, oldAttachmentKey.getAttachmentFilename(), oldAttachmentKey.getAttachmentId()); return moveAttachment(oldAttachmentKey, newAttachmentKey).map(unitToVoid()); }
/** * This is a sanity check to ensure that we are only giving out project keys that haven't already been given out. * <p> In an ideal world, this should never return true. </p> Note that this method isn't guaranteed to avoid * duplicates, as it will only work if the Issue has already been inserted in the DB. * * @param incCount the suggested Issue number * @param project The project * @return true if this Issue Key already exists in the DB. */ private boolean counterAlreadyExists(final long incCount, final Project project) throws GenericEntityException { final String issueKey = IssueKey.format(project, incCount); final boolean alreadyExists = issueManager.isExistingIssueKey(issueKey); if (alreadyExists) { log.warn("Existing issue found for key " + issueKey + ". Incrementing key."); } return (alreadyExists); }
Set<String> issueKeysForThisProject = new HashSet<>(); for (Long issueKey : entry.getValue()) issueKeysForThisProject.add(new IssueKey(projectKey, issueKey).toString()); Long projectId = projectKeyStore.getProjectId(entry.getKey()); if (projectId == null) public String apply(@Nonnull final GenericValue genericValue) return new IssueKey(projectKey, genericValue.getLong("number")).toString();
public void setKey(String key) { this.key = key; if (key == null) { number = null; } else { IssueKey issueKey = IssueKey.from(key); this.number = issueKey.getIssueNumber(); } }