@Override public void update( Comment comment, Map<String, JSONObject> commentProperties, boolean dispatchEvent) { if (comment == null) { throw new IllegalArgumentException("Comment must not be null"); } if (comment.getId() == null) { throw new IllegalArgumentException("Comment ID must not be null"); } // create persistable generic value GenericValue commentGV; // We need an in-memory copy of the old comment so we can pass it through in the fired event and // to make sure // that some fields have changed. Comment originalComment = getCommentById(comment.getId()); if (originalComment == null) { throw new IllegalArgumentException( "Can not find a comment in the datastore with id: " + comment.getId()); } // Make sure that either the comment body or visibility data has changed, otherwise do not // update the datastore if (!areCommentsEquivalent(originalComment, comment)) { try { commentGV = delegator.findById(COMMENT_ENTITY, comment.getId()); populateGenericValueFromComment(comment, commentGV); commentGV.store(); } catch (GenericEntityException e) { throw new DataAccessException(e); } // Update the issue object IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class); GenericValue issueGV = comment.getIssue().getGenericValue(); MutableIssue mutableIssue = issueFactory.getIssue(issueGV); mutableIssue.setUpdated(UtilDateTime.nowTimestamp()); mutableIssue.store(); } // Update comment properties if (commentProperties != null) { setProperties(comment.getAuthorApplicationUser(), comment, commentProperties); } // Dispatch an event if required if (dispatchEvent) { dispatchIssueCommentEditedEvent( comment, MapBuilder.build( "eventsource", IssueEventSource.ACTION, EVENT_ORIGINAL_COMMENT_PARAMETER, originalComment)); } }
/** * Defines whether the given user has permission to see the given issue using the issue's value of * the named custom field. * * @param user the user whose permission is being checked. * @param issueCreation unused. * @param issueGv a GenericValue representing the issue. * @param customFieldName user custom field to use to determine which users have permission to the * issue. * @return true only if the user has permission to see the issue based on the custom field value. */ @Override protected boolean hasIssuePermission( User user, boolean issueCreation, GenericValue issueGv, String customFieldName) { CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class); CustomField field = customFieldManager.getCustomFieldObject(customFieldName); if (field != null) { Set<User> values = convertToUserSet(getValuesFromIssue(field, issueFactory.getIssue(issueGv))); return values.contains(user); } return false; }
private String getViewHtmlForId( Issue baseIssue, final FieldLayoutItem fieldLayoutItem, OrderableField field, Long id, final boolean showProject) { // -1 means no value if (id == null || id == -1L) { return getText("common.words.unknown"); } // dummy up the value for an issue Object value; if (field instanceof CustomField) { value = getValueForId((CustomField) field, id); } else { value = getValueForId(field, id); } // set the value in a field values holder final Map<String, Object> fieldValuesHolder = new LinkedHashMap<String, Object>(); fieldValuesHolder.put(field.getId(), value); // update an issue with these values final MutableIssue dummyIssue = issueFactory.cloneIssue(baseIssue); field.updateIssue(fieldLayoutItem, dummyIssue, fieldValuesHolder); // now render the field if (showProject) { return field.getViewHtml( fieldLayoutItem, this, dummyIssue, MapBuilder.singletonMap("showProject", true)); } else { return field.getViewHtml(fieldLayoutItem, this, dummyIssue); } }
public void processDocument(Document document) { Issue issue = issueFactory.getIssue(document); issueCount++; Iterator<CustomField> customFieldIterator = customFields.iterator(); Iterator<List<Double>> customFieldSampleIterator = customFieldSamples.iterator(); while (customFieldIterator.hasNext() && customFieldSampleIterator.hasNext()) { CustomField customField = customFieldIterator.next(); List<Double> customFieldSample = customFieldSampleIterator.next(); Object value = issue.getCustomFieldValue(customField); if (value instanceof Double) customFieldSample.add((Double) value); } }
protected MutableIssue getIssueObject(GenericValue issueGV) { return issueFactory.getIssue(issueGV); }
public Comment create( Issue issue, ApplicationUser author, ApplicationUser updateAuthor, String body, String groupLevel, Long roleLevelId, Date created, Date updated, Map<String, JSONObject> commentProperties, boolean dispatchEvent, boolean modifyIssueUpdateDate) { if (textFieldCharacterLengthValidator.isTextTooLong(body)) { final long maximumNumberOfCharacters = textFieldCharacterLengthValidator.getMaximumNumberOfCharacters(); String errorMessage = getText("field.error.text.toolong", String.valueOf(maximumNumberOfCharacters)); throw new IllegalArgumentException(errorMessage); } // create new instance of comment CommentImpl comment = new CommentImpl( projectRoleManager, author, updateAuthor, body, groupLevel, roleLevelId, created, updated, issue); // create persistable generic value Map<String, Object> fields = new HashMap<String, Object>(); fields.put("issue", issue.getId()); fields.put("type", ActionConstants.TYPE_COMMENT); ApplicationUser commentAuthor = comment.getAuthorApplicationUser(); ApplicationUser commentUpdateAuthor = comment.getUpdateAuthorApplicationUser(); fields.put("author", commentAuthor == null ? null : commentAuthor.getKey()); fields.put("updateauthor", commentUpdateAuthor == null ? null : commentUpdateAuthor.getKey()); fields.put("body", comment.getBody()); fields.put("level", comment.getGroupLevel()); fields.put("rolelevel", comment.getRoleLevelId()); fields.put("created", new Timestamp(comment.getCreated().getTime())); fields.put("updated", new Timestamp(comment.getUpdated().getTime())); GenericValue commentGV = EntityUtils.createValue(COMMENT_ENTITY, fields); // set the ID on comment object comment.setId(commentGV.getLong(COMMENT_ID)); // Update the issue object if required if (modifyIssueUpdateDate) { // JRA-36334: Only modify the Issue updated date if it would move forward - we don't want it // to go back in time if (comment.getUpdated().getTime() > issue.getUpdated().getTime()) { IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class); MutableIssue mutableIssue = issueFactory.getIssue(issue.getGenericValue()); // JRA-15723: Use the comments updated time for the updated time of the issue. This allows // users to // import old comments without setting the updated time on the issue to now, but to the date // of the old comments. mutableIssue.setUpdated(new Timestamp(comment.getUpdated().getTime())); issue.store(); } } if (commentProperties != null) { setProperties(author, comment, commentProperties); } // Dispatch an event if required if (dispatchEvent) { Map<String, Object> params = new HashMap<String, Object>(); params.put("eventsource", IssueEventSource.ACTION); dispatchIssueCommentAddedEvent(comment, params); } return comment; }