private Option<String> worklogComment(JiraActivityItem item) { for (Long worklogId : getWorklogId(item)) { Worklog worklog = worklogService.getById(new JiraServiceContextImpl(authenticationContext.getLoggedInUser()), worklogId); if (worklog != null) { String comment = worklog.getComment(); if (!isBlank(comment)) { return some(comment); } } } return none(); }
public Response getWorklogForIssue(String worklogId, Issue issue) { try { final JiraServiceContextImpl serviceContext = new JiraServiceContextImpl(authenticationContext.getUser()); final Worklog worklog = worklogService.getById(serviceContext, Long.parseLong(worklogId)); if (worklog != null) { if (issue.getId().equals(worklog.getIssue().getId())) { return Response.ok(WorklogJsonBean.getWorklog(worklog, jiraBaseUrls, userManager, timeTrackingConfiguration, authenticationContext.getUser(), emailFormatter)).cacheControl(never()).build(); } else { final ErrorCollection errors = ErrorCollection.of(serviceContext.getErrorCollection()); return Response.status(Response.Status.NOT_FOUND).entity(errors).cacheControl(never()).build(); } } else { final ErrorCollection errors = ErrorCollection.of(serviceContext.getErrorCollection()); return Response.status(Response.Status.NOT_FOUND).entity(errors).cacheControl(never()).build(); } } catch (NumberFormatException e) { throw new NotFoundWebException(ErrorCollection.of(i18n.getText("worklog.service.error.no.worklog.for.id", worklogId))); } }
public boolean hasPermissionToDeleteWorklog(User user, String worklogId) throws RemoteException, RemoteValidationException { JiraServiceContext serviceContext = new JiraServiceContextImpl(user, new SimpleErrorCollection()); Long id = SoapUtils.toLongRequired(worklogId); Worklog worklog = worklogService.getById(serviceContext, id); // getById does not currenty return errors but it might so we do this code checkAndThrowValidationException(serviceContext.getErrorCollection()); return worklog != null && worklogService.hasPermissionToDelete(serviceContext, worklog); }
public boolean hasPermissionToUpdateWorklog(User user, String worklogId) throws RemoteException, RemoteValidationException { JiraServiceContext serviceContext = new JiraServiceContextImpl(user, new SimpleErrorCollection()); Long id = SoapUtils.toLongRequired(worklogId); Worklog worklog = worklogService.getById(serviceContext, id); // getById does not currenty return errors but it might so we do this code checkAndThrowValidationException(serviceContext.getErrorCollection()); return worklog != null && worklogService.hasPermissionToUpdate(serviceContext, worklog); }
private static Worklog getAndValidateExistingWorklog(WorklogJsonBean request, ErrorCollection errors, JiraServiceContext serviceContext) { String id = request.getId(); if (!errors.hasAnyErrors()) { if (id == null) { errors.addError(IssueFieldConstants.WORKLOG, serviceContext.getI18nBean().getText("rest.worklog.error.id.missing")); return null; } Worklog existingWorklog = getWorklogService().getById(serviceContext, Long.parseLong(id)); if (existingWorklog == null) { throw new NotFoundWebException(com.atlassian.jira.rest.api.util.ErrorCollection.of(serviceContext.getI18nBean().getText("worklog.service.error.no.worklog.for.id", id))); } return existingWorklog; } else { return null; } }
public String doDefault() throws Exception { // Retrieve the worklog worklog = worklogService.getById(getJiraServiceContext(), getWorklogId()); if (worklog == null) { addErrorMessage(getText("logwork.error.update.invalid.id", (getWorklogId() == null) ? null : getWorklogId().toString())); return ERROR; } if (!worklogService.hasPermissionToUpdate(getJiraServiceContext(), worklog)) { //user doesn't have permission to run this action return "securitybreach"; } //pre-populate the fields final BigDecimal hoursPerDay = getHoursPerDay(); final BigDecimal daysPerWeek = getDaysPerWeek(); final BigDecimal secondsPerHour = BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds()); final long secondsPerDay = hoursPerDay.multiply(secondsPerHour).longValueExact(); final long secondsPerWeek = daysPerWeek.multiply(hoursPerDay).multiply(secondsPerHour).longValueExact(); setTimeLogged(DateUtils.getDurationStringSeconds(worklog.getTimeSpent(), secondsPerDay, secondsPerWeek)); setStartDate(getFormattedStartDate(worklog.getStartDate())); setComment(worklog.getComment()); setCommentLevel(CommentVisibility.getCommentLevelFromLevels(worklog.getGroupLevel(), worklog.getRoleLevelId())); return super.doDefault(); }