@Override public Worklog createAndRetainRemainingEstimate(JiraServiceContext jiraServiceContext, WorklogResult worklogResult, boolean dispatchEvent) { return create(jiraServiceContext, worklogResult, null, dispatchEvent); }
@Override public boolean deleteAndRetainRemainingEstimate(JiraServiceContext jiraServiceContext, WorklogResult worklogResult, boolean dispatchEvent) { return delete(jiraServiceContext, worklogResult, null, dispatchEvent); }
public List<Worklog> getByIssueVisibleToUser(JiraServiceContext jiraServiceContext, Issue issue) { final List allWorklogs = getByIssue(jiraServiceContext, issue); final List<Worklog> visibleWorklogs = new ArrayList<Worklog>(allWorklogs.size()); for (final Object allWorklog : allWorklogs) { Worklog worklog = (Worklog) allWorklog; if (hasPermissionToView(jiraServiceContext.getLoggedInApplicationUser(), worklog)) { visibleWorklogs.add(worklog); } } return visibleWorklogs; }
@Override public WorklogNewEstimateResult validateDeleteWithNewEstimate(JiraServiceContext jiraServiceContext, Long worklogId, String newEstimate) { WorklogResult originalWorklogResult = validateDelete(jiraServiceContext, worklogId); if (originalWorklogResult != null && isValidNewEstimate(jiraServiceContext, newEstimate)) { final Long estimate = (newEstimate == null) ? null : getDurationForFormattedString(newEstimate, jiraServiceContext); return WorklogResultFactory.createNewEstimate(originalWorklogResult, estimate); } return null; }
@Override public WorklogAdjustmentAmountResult validateDeleteWithManuallyAdjustedEstimate(JiraServiceContext jiraServiceContext, Long worklogId, String adjustmentAmount) { WorklogResult originalWorklogResult = validateDelete(jiraServiceContext, worklogId); if (originalWorklogResult != null && isValidAdjustmentAmount(jiraServiceContext, adjustmentAmount)) { return WorklogResultFactory.createAdjustmentAmount(originalWorklogResult, getDurationForFormattedString(adjustmentAmount, jiraServiceContext)); } return null; }
ErrorCollection errorCollection = new SimpleErrorCollection(); if (!isTimeTrackingEnabled()) jiraServiceContext.getErrorCollection().addErrorMessage(getText(jiraServiceContext, "worklog.service.error.time.tracking.not.enabed")); return false; validateUpdateOrDeletePermissionCheckParams(worklog, errorCollection, jiraServiceContext); if (!hasDeleteAllPermission(user, worklog.getIssue()) && !hasDeleteOwnPermission(user, worklog)) errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.delete.permission", user.getDisplayName())); errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.delete.permission.no.user"));
ErrorCollection errorCollection = new SimpleErrorCollection(); if (!isTimeTrackingEnabled()) jiraServiceContext.getErrorCollection().addErrorMessage(getText(jiraServiceContext, "worklog.service.error.time.tracking.not.enabed")); return false; validateUpdateOrDeletePermissionCheckParams(worklog, errorCollection, jiraServiceContext); if (!hasEditAllPermission(user, worklog.getIssue()) && !hasEditOwnPermission(user, worklog)) errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.edit.permission", user.getDisplayName())); errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.edit.permission.no.user"));
@Override public Worklog createWithManuallyAdjustedEstimate(final JiraServiceContext jiraServiceContext, final WorklogAdjustmentAmountResult worklogResult, final boolean dispatchEvent) { ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); if (worklogResult == null || worklogResult.getWorklog() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.null")); return null; } if (worklogResult.getWorklog().getIssue() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return null; } // Calculate the new remaining estimate final Worklog worklog = worklogResult.getWorklog(); Long newEstimate = reduceEstimate(worklog.getIssue(), worklogResult.getAdjustmentAmount()); return create(jiraServiceContext, worklogResult, newEstimate, dispatchEvent); }
@Override public boolean deleteWithManuallyAdjustedEstimate(JiraServiceContext jiraServiceContext, WorklogAdjustmentAmountResult worklogResult, boolean dispatchEvent) { ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); if (worklogResult == null || worklogResult.getWorklog() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.null")); return false; } if (worklogResult.getWorklog().getIssue() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return false; } // Calculate the new remaining estimate Long newEstimate = increaseEstimate(worklogResult.getWorklog().getIssue(), worklogResult.getAdjustmentAmount()); return delete(jiraServiceContext, worklogResult, newEstimate, dispatchEvent); }
@Override public WorklogAdjustmentAmountResult validateCreateWithManuallyAdjustedEstimate(JiraServiceContext jiraServiceContext, WorklogAdjustmentAmountInputParameters params) { WorklogResult worklogResult = validateCreate(jiraServiceContext, params); if (isValidAdjustmentAmount(jiraServiceContext, params.getAdjustmentAmount(), params.getErrorFieldPrefix()) && worklogResult != null) { return WorklogResultFactory.createAdjustmentAmount(worklogResult, getDurationForFormattedString(params.getAdjustmentAmount(), jiraServiceContext)); } return null; }
@Override public WorklogNewEstimateResult validateCreateWithNewEstimate(JiraServiceContext jiraServiceContext, WorklogNewEstimateInputParameters params) { WorklogResult worklogResult = validateCreate(jiraServiceContext, params); if (isValidNewEstimate(jiraServiceContext, params.getNewEstimate(), params.getErrorFieldPrefix()) && worklogResult != null) { final Long estimate = (params.getNewEstimate() == null) ? null : getDurationForFormattedString(params.getNewEstimate(), jiraServiceContext); return WorklogResultFactory.createNewEstimate(worklogResult, estimate); } return null; }
@Override public WorklogNewEstimateResult validateUpdateWithNewEstimate(JiraServiceContext jiraServiceContext, final WorklogNewEstimateInputParameters params) { notNull("params", params); WorklogResult worklogResult = validateUpdate(jiraServiceContext, params); if (isValidNewEstimate(jiraServiceContext, params.getNewEstimate(), params.getErrorFieldPrefix()) && worklogResult != null) { final Long estimate = (params.getNewEstimate() == null) ? null : getDurationForFormattedString(params.getNewEstimate(), jiraServiceContext); return WorklogResultFactory.createNewEstimate(worklogResult, estimate); } return null; }
ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); if (!isTimeTrackingEnabled()) errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.time.tracking.not.enabed")); return false; errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return false; if (isEditableCheckRequired && !isIssueInEditableWorkflowState(issue)) errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.not.editable.workflow.state")); return false; errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.permission", user.getDisplayName())); errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.permission.no.user"));
errorCollection.addError(errorField, getText(jiraServiceContext, "worklog.service.error.timespent.required")); else if (!isValidDuration(timeSpent, jiraServiceContext)) errorCollection.addError(errorField, getText(jiraServiceContext, "worklog.service.error.invalid.time.duration")); else if (getDurationForFormattedString(timeSpent, jiraServiceContext) == 0) errorCollection.addError(errorField, getText(jiraServiceContext, "worklog.service.error.timespent.zero")); errorCollection.addError(errorField, getText(jiraServiceContext, "worklog.service.error.invalid.worklog.date"));
errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.null")); return null; errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return null; errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.id.null")); return null; errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.no.worklog.for.id", worklogResult.getWorklog().getId().toString())); return null; Long newTimeSpent = worklogResult.getWorklog().getTimeSpent(); Long newEstimate = getAutoAdjustNewEstimateOnUpdate(worklogResult.getWorklog().getIssue(), newTimeSpent, originalTimeSpent); return update(jiraServiceContext, worklogResult, newEstimate, dispatchEvent);
protected boolean isValidNewEstimate(JiraServiceContext jiraServiceContext, String newEstimate, final String errorFieldPrefix) { ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); String errorField = "newEstimate"; if (StringUtils.isNotBlank(errorFieldPrefix)) { errorField = errorFieldPrefix + errorField; } if (TextUtils.stringSet(newEstimate)) { if (!isValidDuration(newEstimate, jiraServiceContext)) { errorCollection.addError(errorField, getText(jiraServiceContext, "worklog.service.error.newestimate")); return false; } } else { errorCollection.addError(errorField, getText(jiraServiceContext, "worklog.service.error.new.estimate.not.specified")); return false; } return true; }
void validateUpdateOrDeletePermissionCheckParams(Worklog worklog, ErrorCollection errorCollection, final JiraServiceContext jiraServiceContext) { if (worklog == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.null")); return; } Issue issue = worklog.getIssue(); if (issue == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return; } if (!isIssueInEditableWorkflowState(issue)) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.not.editable.workflow.state")); return; } if (worklog.getId() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.id.null")); } }
final List<Worklog> nextDbPage = filter(user, worklogsUpdatedSince); return createChangePage(sinceInMilliseconds, result, true); return createChangePage(sinceInMilliseconds, result, false); return createChangePage(sinceInMilliseconds, result, false);
protected Worklog update(JiraServiceContext jiraServiceContext, WorklogResult worklogResult, Long newEstimate, boolean dispatchEvent) { Worklog updatedWorklog = null; ApplicationUser user = jiraServiceContext.getLoggedInApplicationUser(); ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); if (worklogResult == null || worklogResult.getWorklog() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.null")); return null; } if (worklogResult.getWorklog().getIssue() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return null; } if (worklogResult.getWorklog().getId() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.id.null")); return null; } // Re-do the permission check if (hasPermissionToUpdate(jiraServiceContext, worklogResult.getWorklog())) { updatedWorklog = worklogManager.update(user, worklogResult.getWorklog(), newEstimate, dispatchEvent); } return updatedWorklog; }
protected boolean delete(JiraServiceContext jiraServiceContext, WorklogResult worklogResult, Long newEstimate, boolean dispatchEvent) { ApplicationUser user = jiraServiceContext.getLoggedInApplicationUser(); ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); if (worklogResult == null || worklogResult.getWorklog() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.null")); return false; } if (worklogResult.getWorklog().getIssue() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.issue.null")); return false; } if (worklogResult.getWorklog().getId() == null) { errorCollection.addErrorMessage(getText(jiraServiceContext, "worklog.service.error.worklog.id.null")); return false; } // Re-do the permission check if (hasPermissionToDelete(jiraServiceContext, worklogResult.getWorklog())) { return worklogManager.delete(user, worklogResult.getWorklog(), newEstimate, dispatchEvent); } return false; }