Пример #1
0
  public static void updateTaskData(
      final TaskRepository repository,
      final TaskData taskData,
      final Configuration cfg,
      final Issue issue)
      throws CoreException {

    final TaskAttribute root = taskData.getRoot();
    TaskAttribute taskAttribute = null;

    /* Default Attributes */
    for (final RedmineAttribute redmineAttribute : RedmineAttribute.values()) {
      final String taskKey = redmineAttribute.getTaskKey();
      if (taskKey == null) {
        continue;
      }

      taskAttribute = root.getAttribute(taskKey);
      if (taskAttribute != null) {
        final Field field = redmineAttribute.getAttributeField();

        if (field != null) {
          try {
            setValue(taskAttribute, field.get(issue));
          } catch (final Exception e) {
            final IStatus status =
                RedmineCorePlugin.toStatus(
                    e, Messages.ERRMSG_CANT_READ_PROPERTY_X, redmineAttribute.name());
            final ILogService log = RedmineCorePlugin.getLogService(IssueMapper.class);
            log.error(e, status.getMessage());
            throw new CoreException(status);
          }
        } else {
          switch (redmineAttribute) {
            case WATCHERS:
              for (final int watcherId : issue.getWatcherIds()) {
                taskAttribute.addValue(Integer.toString(watcherId));
              }
              break;
            default:
              break;
          }
        }
      }
    }

    /* Custom Attributes */
    if (issue.getCustomValues() != null) {
      for (final CustomValue customValue : issue.getCustomValues().getAll()) {
        taskAttribute =
            taskData
                .getRoot()
                .getAttribute(
                    IRedmineConstants.TASK_KEY_PREFIX_ISSUE_CF + customValue.getCustomFieldId());
        if (taskAttribute != null) {
          setValue(taskAttribute, customValue.getValue());
        }
      }
    }

    /* Journals */
    if (issue.getJournals() != null) {
      int jrnlCount = 1;
      for (final Journal journal : issue.getJournals().getAll()) {
        final TaskCommentMapper mapper = new TaskCommentMapper();
        mapper.setAuthor(repository.createPerson("" + journal.getUserId())); // $NON-NLS-1$
        mapper.setCreationDate(journal.getCreatedOn());
        mapper.setText(journal.getNotes());
        final String issueUrl =
            RedmineRepositoryConnector.getTaskUrl(repository.getUrl(), issue.getId());
        mapper.setUrl(
            issueUrl + String.format(IRedmineConstants.REDMINE_URL_PART_COMMENT, journal.getId()));
        mapper.setNumber(jrnlCount++);
        mapper.setCommentId(String.valueOf(journal.getId()));

        taskAttribute =
            taskData
                .getRoot()
                .createAttribute(TaskAttribute.PREFIX_COMMENT + mapper.getCommentId());
        mapper.applyTo(taskAttribute);
      }
    }

    /* Attachments */
    if (issue.getAttachments() != null) {
      for (final Attachment attachment : issue.getAttachments().getAll()) {
        final TaskAttachmentMapper mapper = new TaskAttachmentMapper();
        mapper.setAttachmentId("" + attachment.getId()); // $NON-NLS-1$
        mapper.setAuthor(repository.createPerson("" + attachment.getAuthorId())); // $NON-NLS-1$
        mapper.setDescription(attachment.getDescription());
        mapper.setCreationDate(attachment.getCreatedOn());
        mapper.setContentType(attachment.getContentType());
        mapper.setFileName(attachment.getFilename());
        mapper.setLength(attachment.getFilesize());
        mapper.setUrl(
            String.format(
                IRedmineConstants.REDMINE_URL_ATTACHMENT_DOWNLOAD,
                repository.getUrl(),
                attachment.getId()));

        taskAttribute =
            taskData
                .getRoot()
                .createAttribute(TaskAttribute.PREFIX_ATTACHMENT + mapper.getAttachmentId());
        mapper.applyTo(taskAttribute);
      }
    }

    if (issue.getTimeEntries() != null && issue.getTimeEntries().isViewAllowed()) {
      // TODO kind/label
      taskAttribute =
          taskData.getRoot().createAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_TOTAL);

      if (issue.getTimeEntries() != null) {
        taskAttribute.setValue("" + issue.getTimeEntries().getSum()); // $NON-NLS-1$

        for (final TimeEntry timeEntry : issue.getTimeEntries().getAll()) {
          final RedmineTaskTimeEntryMapper mapper = new RedmineTaskTimeEntryMapper();
          mapper.setTimeEntryId(timeEntry.getId());
          mapper.setUser(repository.createPerson("" + timeEntry.getUserId())); // $NON-NLS-1$
          mapper.setActivityId(timeEntry.getActivityId());
          mapper.setHours(timeEntry.getHours());
          mapper.setSpentOn(timeEntry.getSpentOn());
          mapper.setComments(timeEntry.getComments());
          mapper.setCustomValues(timeEntry.getCustomValues().getAll());

          taskAttribute =
              taskData
                  .getRoot()
                  .createAttribute(
                      IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_PREFIX + mapper.getTimeEntryId());
          mapper.applyTo(taskAttribute, cfg);
        }
      }
    }

    setTaskKind(issue, cfg, root);
  }