Пример #1
0
  private static String getCurrentUser(ITask task) {
    TaskRepository repository =
        TasksUi.getRepositoryManager()
            .getRepository(task.getConnectorKind(), task.getRepositoryUrl());

    return repository.getUserName();
  }
Пример #2
0
 private void addIndexedAttributes(Document document, ITask task) {
   addIndexedAttribute(document, FIELD_TASK_KEY, task.getTaskKey());
   addIndexedAttribute(document, FIELD_REPOSITORY_URL, task.getRepositoryUrl());
   addIndexedAttribute(document, FIELD_SUMMARY, task.getSummary());
   addIndexedAttribute(document, FIELD_CONTENT, task.getSummary());
   addIndexedAttribute(document, FIELD_CONTENT, ((AbstractTask) task).getNotes());
   addIndexedDateAttributes(document, task);
 }
Пример #3
0
 private void addIndexedDateAttributes(Document document, ITask task) {
   addIndexedAttribute(
       document, DefaultTaskSchema.getInstance().DATE_COMPLETION, task.getCompletionDate());
   addIndexedAttribute(
       document, DefaultTaskSchema.getInstance().DATE_CREATION, task.getCreationDate());
   addIndexedAttribute(document, DefaultTaskSchema.getInstance().DATE_DUE, task.getDueDate());
   addIndexedAttribute(
       document, DefaultTaskSchema.getInstance().DATE_MODIFICATION, task.getModificationDate());
 }
Пример #4
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   status =
       new MultiStatus(
           ITasksCoreConstants.ID_PLUGIN,
           IStatus.OK,
           "Problems occurred while deleting repository tasks",
           null); //$NON-NLS-1$
   try {
     monitor.beginTask(Messages.DeleteTasksJob_Deleting_tasks, tasksToDelete.size() * 100);
     for (ITask task : tasksToDelete) {
       // delete the task on the server using the repository connector
       AbstractRepositoryConnector repositoryConnector =
           repositoryManager.getRepositoryConnector(task.getConnectorKind());
       TaskRepository repository =
           repositoryManager.getRepository(task.getConnectorKind(), task.getRepositoryUrl());
       if (repositoryConnector.canDeleteTask(repository, task)) {
         try {
           repositoryConnector.deleteTask(repository, task, subMonitorFor(monitor, 100));
         } catch (OperationCanceledException e) {
           return Status.CANCEL_STATUS;
         } catch (Exception e) {
           String taskId = task.getTaskKey();
           if (taskId == null) {
             taskId = task.getTaskId();
           }
           status.add(
               new Status(
                   IStatus.ERROR,
                   ITasksCoreConstants.ID_PLUGIN,
                   NLS.bind(
                       "Problems occurred while deleting {0} from {1}.",
                       taskId, task.getRepositoryUrl()),
                   e)); //$NON-NLS-1$
         } catch (LinkageError e) {
           String taskId = task.getTaskKey();
           if (taskId == null) {
             taskId = task.getTaskId();
           }
           status.add(
               new Status(
                   IStatus.ERROR,
                   ITasksCoreConstants.ID_PLUGIN,
                   NLS.bind(
                       "Internal Error occurred while deleting {0} from {1}.",
                       taskId, task.getRepositoryUrl()),
                   e)); //$NON-NLS-1$
         }
       }
     }
   } finally {
     monitor.done();
   }
   return Status.OK_STATUS;
 }
Пример #5
0
  public void indicateActiveTask() {
    if (activeTaskLabel != null && activeTaskLabel.isDisposed()) {
      return;
    }

    // activeTaskLabel.setText(shortenText(activeTask.getSummary()));
    activeTaskLabel.setText(activeTask.getSummary());
    activeTaskLabel.setUnderlined(true);
    activeTaskLabel.setToolTipText(activeTask.getSummary());
    activeTaskSelectionProvider.setSelection(new StructuredSelection(activeTask));
  }
Пример #6
0
  /**
   * @param writer
   * @param task the task
   * @param taskData may be null for local tasks
   * @throws CorruptIndexException
   * @throws IOException
   */
  private void add(IndexWriter writer, ITask task, TaskData taskData)
      throws CorruptIndexException, IOException {
    if (!taskIsIndexable(task, taskData)) {
      return;
    }

    Document document = new Document();

    document.add(
        new Field(
            FIELD_IDENTIFIER.getIndexKey(),
            task.getHandleIdentifier(),
            Store.YES,
            org.apache.lucene.document.Field.Index.ANALYZED));
    if (taskData == null) {
      if ("local".equals(((AbstractTask) task).getConnectorKind())) { // $NON-NLS-1$
        addIndexedAttributes(document, task);
      } else {
        return;
      }
    } else {
      addIndexedAttributes(document, task, taskData.getRoot());
    }
    writer.addDocument(document);
  }
Пример #7
0
  public static boolean isOutgoingNewTask(ITask task, String connectorKind, String url) {
    Assert.isNotNull(task);
    Assert.isNotNull(connectorKind);
    if (!connectorKind.equals(
        task.getAttribute(ITasksCoreConstants.ATTRIBUTE_OUTGOING_NEW_CONNECTOR_KIND))) {
      return false;
    }

    if (url != null) {
      if (!url.equals(
          task.getAttribute(ITasksCoreConstants.ATTRIBUTE_OUTGOING_NEW_REPOSITORY_URL))) {
        return false;
      }
    }
    return true;
  }
 @Test
 public void testUpdateTaskFromTaskData() throws Exception {
   TaskData taskData =
       new TaskData(
           new TaskAttributeMapper(actualFixture.repository()),
           connector.getConnectorKind(),
           actualFixture.repository().getRepositoryUrl(),
           "123");
   ITask task =
       new TaskTask(
           connector.getConnectorKind(), actualFixture.repository().getRepositoryUrl(), "");
   connector.updateTaskFromTaskData(actualFixture.repository(), task, taskData);
   assertThat(
       task.getUrl(),
       equalTo(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/123"));
 }
 @Override
 public Object[] getChildren(Object parent) {
   Set<ITask> children = new HashSet<ITask>();
   if (parent instanceof Person) {
     for (ITaskContainer container : applyFilter(TasksUiPlugin.getTaskList().getRootElements())) {
       for (ITask task : getAllTasks(container.getChildren())) {
         if (task.getOwner() != null
             && task.getOwner().equals(((Person) parent).getHandleIdentifier())
             && TasksUiInternal.shouldShowIncoming(task)) {
           children.add(task);
         }
       }
     }
   }
   return children.toArray();
 }
Пример #10
0
  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    super.selectionChanged(action, selection);

    task = null;

    if (selection instanceof IStructuredSelection) {

      IStructuredSelection ss = (IStructuredSelection) selection;

      if (!ss.isEmpty()) {

        Iterator<?> iter = ss.iterator();
        while (iter.hasNext()) {
          Object sel = iter.next();
          if (sel instanceof IJiraTask) {
            task = ((IJiraTask) sel).getTask();
            try {
              taskData = TasksUiPlugin.getTaskDataManager().getTaskData(task);
            } catch (CoreException e) {
              handleError(
                  Messages.JiraConnectorUiActions_Cannot_get_task_data + task.getTaskKey(), e);
            }

            break;
          }
        }
      }
    }

    update(action);
  }
Пример #11
0
  private void updateHeaderLabel() {
    TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
    final TaskRepository taskRepository =
        (outgoingNewRepository != null)
            ? outgoingNewRepository
            : taskEditorInput.getTaskRepository();

    //		if (taskRepository.getConnectorKind().equals(LocalRepositoryConnector.CONNECTOR_KIND)) {
    //			getHeaderForm().getForm().setText(Messages.TaskEditor_Task_ + task.getSummary());
    //		} else {
    AbstractRepositoryConnectorUi connectorUi =
        TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind());
    String kindLabel = Messages.TaskEditor_Task;
    if (connectorUi != null) {
      kindLabel = connectorUi.getTaskKindLabel(task);
    }

    String idLabel = task.getTaskKey();
    if (idLabel != null) {
      kindLabel += " " + idLabel; // $NON-NLS-1$
    }

    if (hasLeftToolBar() && titleLabel != null) {
      titleLabel.setText(kindLabel);
      getHeaderForm().getForm().setText(null);
      setHeaderImage(null);
    } else {
      getHeaderForm().getForm().setText(kindLabel);
    }
  }
Пример #12
0
  /**
   * Returns a commit comment specific to <code>task</code> and <code>resources</code>. If <code>
   * resources</code> is null or the associated projects do not specify a custom commit comment
   * template the global template is used.
   *
   * <p>This method must be invoked on the UI thread.
   *
   * @param checkTaskRepository if true, a warning dialog is displayed in case <code>task</code> is
   *     associated with a different repository than any of the <code>resources</code>
   * @param task the task to generate the commit comment for
   * @param resources that are being committed or null
   * @return a commit comment or an empty string if the user opted to abort generating the commit
   *     message
   * @since 3.5
   */
  public static String getComment(boolean checkTaskRepository, ITask task, IResource[] resources) {
    // lookup project specific template
    String template = null;
    Set<IProject> projects = new HashSet<IProject>();
    if (resources != null) {
      for (IResource resource : resources) {
        IProject project = resource.getProject();
        if (project != null && project.isAccessible() && !projects.contains(project)) {
          TeamPropertiesLinkProvider provider = new TeamPropertiesLinkProvider();
          template = provider.getCommitCommentTemplate(project);
          if (template != null) {
            break;
          }
          projects.add(project);
        }
      }
    }

    boolean proceed = true;

    // prompt if resources do not match task
    if (checkTaskRepository) {
      boolean unmatchedRepositoryFound = false;
      for (IProject project : projects) {
        TaskRepository repository = TasksUiPlugin.getDefault().getRepositoryForResource(project);
        if (repository != null) {
          if (!repository.getRepositoryUrl().equals(task.getRepositoryUrl())) {
            unmatchedRepositoryFound = true;
          }
        }
      }

      if (unmatchedRepositoryFound) {
        if (Display.getCurrent() != null) {
          proceed =
              MessageDialog.openQuestion(
                  WorkbenchUtil.getShell(),
                  Messages.ContextChangeSet_Mylyn_Change_Set_Management,
                  Messages.ContextChangeSet_ATTEMPTING_TO_COMMIT_RESOURCE);
        } else {
          proceed = false;
        }
      }
    }

    if (proceed) {
      if (template == null) {
        template =
            FocusedTeamUiPlugin.getDefault()
                .getPreferenceStore()
                .getString(FocusedTeamUiPlugin.COMMIT_TEMPLATE);
      }
      return FocusedTeamUiPlugin.getDefault()
          .getCommitTemplateManager()
          .generateComment(task, template);
    } else {
      return ""; //$NON-NLS-1$
    }
  }
Пример #13
0
  public String createCustomFieldTask() throws Exception {
    final TaskMapping taskMappingInit =
        new TaskMapping() {

          @Override
          public String getProduct() {
            return "ManualTest";
          }
        };
    final TaskMapping taskMappingSelect =
        new TaskMapping() {
          @Override
          public String getComponent() {
            return "ManualC2";
          }

          @Override
          public String getSummary() {
            return "test Bug with Custom Fields";
          }

          @Override
          public String getDescription() {
            return "The Description of the test with Custom Fields Bug";
          }
        };

    // create Task
    TaskData taskDataNew = createTaskData(taskMappingInit, taskMappingSelect, null);
    RepositoryResponse response = createNewTask(taskDataNew);
    assertNotNull(response);
    assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString());
    String taskId = response.getTaskId();

    ITask task = getTask(taskId);
    assertNotNull(task);
    TaskData taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);

    TaskMapper mapper = new TaskMapper(taskData);
    TaskAttribute cf_multiselect = mapper.getTaskData().getRoot().getAttribute("cf_multiselect");
    cf_multiselect.setValue("Green");
    response = fixture.submitTask(taskData, priviledgedClient());

    return taskId;
  }
 @Override
 public Object[] getElements(Object parent) {
   people.clear();
   if (parent instanceof Person) {
     return getChildren(parent);
   } else {
     for (ITaskContainer container : applyFilter(TasksUiPlugin.getTaskList().getRootElements())) {
       for (ITask task : getAllTasks(container.getChildren())) {
         if (task.getOwner() != null && TasksUiInternal.shouldShowIncoming(task)) {
           people.add(
               new Person(task.getOwner(), task.getConnectorKind(), task.getRepositoryUrl()));
         }
       }
     }
   }
   return people.toArray();
 }
Пример #15
0
  public void testUpdateQueryHits() {
    MockTask hit1 = new MockTask("1");
    MockTask hit2 = new MockTask("2");
    MockTask hit3 = new MockTask("3");

    MockTask hit1twin = new MockTask("1");
    MockTask hit2twin = new MockTask("2");
    MockTask hit3twin = new MockTask("3");

    MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
    taskList.addQuery(query1);

    taskList.addTask(hit1, query1);
    taskList.addTask(hit2, query1);
    taskList.addTask(hit3, query1);

    taskList.addTask(hit1twin, query1);
    taskList.addTask(hit2twin, query1);
    taskList.addTask(hit3twin, query1);

    assertEquals(3, query1.getChildren().size());
    for (ITask child : query1.getChildren()) {
      taskList.removeFromContainer(query1, child);
    }
    assertEquals(0, query1.getChildren().size());
    taskList.addTask(hit1, query1);
    taskList.addTask(hit2, query1);
    assertEquals(2, query1.getChildren().size());
    hit1.setNotified(true);

    taskList.addTask(hit1twin, query1);
    taskList.addTask(hit2twin, query1);
    taskList.addTask(hit3twin, query1);
    assertEquals(3, query1.getChildren().size());
    assertTrue(query1.getChildren().contains(hit1twin));
    assertTrue(query1.getChildren().contains(hit2twin));
    assertTrue(query1.getChildren().contains(hit3twin));
    for (ITask hit : query1.getChildren()) {
      if (hit.equals(hit1twin)) {
        assertTrue(((AbstractTask) hit).isNotified());
      } else {
        assertFalse(((AbstractTask) hit).isNotified());
      }
    }
  }
Пример #16
0
  public void testSortWithError() {
    final TaskListSorter sorter = new TaskListSorter();
    ITask task1 = new LocalTask("1", null);
    ITask task2 = new MockTask("local", "", "1");
    Object[] tasks = {task1, task2};
    Date start = new Date();
    task2.setCreationDate(start);
    task1.setCreationDate(new Date(start.getTime() - 1));
    task1.setPriority("P5");
    task2.setPriority("P1");

    sorter.getComparator().getSortCriterion(0).setKey(SortCriterion.SortKey.TASK_ID);
    sorter.sort(new EmptyViewer(), tasks);
    assertEquals(task1, tasks[1]);
    assertEquals(task2, tasks[0]);

    sorter.getComparator().getSortCriterion(0).setKey(SortCriterion.SortKey.DATE_CREATED);
    sorter.sort(new EmptyViewer(), tasks);
    assertEquals(task1, tasks[0]);
    assertEquals(task2, tasks[1]);

    sorter.getComparator().getSortCriterion(0).setKey(SortCriterion.SortKey.PRIORITY);
    sorter.sort(new EmptyViewer(), tasks);
    assertEquals(task1, tasks[1]);
    assertEquals(task2, tasks[0]);

    sorter.getComparator().getSortCriterion(0).setKey(SortCriterion.SortKey.SUMMARY);
    sorter.getComparator().getSortCriterion(0).setDirection((-1));
    sorter.sort(new EmptyViewer(), tasks);
    assertEquals(task1, tasks[0]);
    assertEquals(task2, tasks[1]);
  }
Пример #17
0
  @Override
  public boolean hasTaskChanged(TaskRepository taskRepository, ITask task, TaskData taskData) {
    TaskAttribute attribute = taskData.getRoot().getAttribute(TaskAttribute.DATE_MODIFICATION);

    if (attribute != null) {
      Date dataModificationDate = taskData.getAttributeMapper().getDateValue(attribute);

      if (dataModificationDate != null) {
        Date taskModificationDate = task.getModificationDate();

        if (taskModificationDate != null) return !taskModificationDate.equals(dataModificationDate);
      }
    }

    return true;
  }
Пример #18
0
 private void updateTitleImage() {
   if (task != null) {
     AbstractRepositoryConnectorUi connectorUi =
         TasksUiPlugin.getConnectorUi(task.getConnectorKind());
     if (connectorUi != null) {
       ImageDescriptor overlayDescriptor = connectorUi.getTaskKindOverlay(task);
       setTitleImage(
           CommonImages.getCompositeTaskImage(TasksUiImages.TASK, overlayDescriptor, false));
     } else {
       setTitleImage(CommonImages.getImage(TasksUiImages.TASK));
     }
     //		} else if (getEditorInput() instanceof AbstractRepositoryTaskEditorInput) {
     //			setTitleImage(CommonImages.getImage(TasksUiImages.TASK_REMOTE));
   } else {
     setTitleImage(CommonImages.getImage(TasksUiImages.TASK));
   }
 }
Пример #19
0
 public void testLocalTaskSort() {
   final TaskListSorter sorter = new TaskListSorter();
   ITask task1 = new LocalTask("1", "task1");
   ITask task2 = new LocalTask("2", "task2");
   ITask task3 = new LocalTask("3", "task3");
   ITask[] tasks = {task1, task2, task3};
   Date start = new Date();
   task1.setCreationDate(start);
   task2.setCreationDate(new Date(start.getTime() - 1));
   task3.setCreationDate(new Date(start.getTime() - 2));
   sorter.getComparator().getSortCriterion(0).setKey(SortCriterion.SortKey.DATE_CREATED);
   sorter.sort(new EmptyViewer(), tasks);
   sorter.getComparator().getSortCriterion(0).setDirection((-1));
   sorter.sort(new EmptyViewer(), tasks);
 }
Пример #20
0
 public void containersChanged(Set<TaskContainerDelta> containers) {
   // update label in case task changes
   if (activeTask != null) {
     for (TaskContainerDelta taskContainerDelta : containers) {
       if (activeTask.equals(taskContainerDelta.getElement())) {
         if (taskContainerDelta.getKind().equals(TaskContainerDelta.Kind.CONTENT)) {
           Display.getDefault()
               .asyncExec(
                   new Runnable() {
                     public void run() {
                       if (activeTask != null && activeTask.isActive()) {
                         indicateActiveTask();
                       }
                     }
                   });
           return;
         }
       }
     }
   }
 }
  @Before
  public void setUp() {
    mockTask1 = new TaskTask("mock", "http://mock", "taskID");

    mockTask1.setAttribute("CODE_REVIEW", "0");
    mockTask1.setAttribute("VERIFIED", "0");
    mockTask1.setAttribute("INCOMING_REVIEW", "true");

    myTaskReview1 = new TaskReview(mockTask1);

    mockTask2 = new TaskTask("mock", "http://mock", "taskID");
    mockTask2.setSummary(summaryString);

    mockTask2.setAttribute("CODE_REVIEW", "2");
    mockTask2.setAttribute("VERIFIED", "2");
    mockTask2.setAttribute("INCOMING_REVIEW", incomingString);

    myTaskReview2 = new TaskReview(mockTask2);

    myLabelProvider = new ReviewColumnLabelProvider();
  }
Пример #22
0
  private Image getBrandingImage() {
    String connectorKind;
    TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
    if (outgoingNewRepository != null) {
      connectorKind = outgoingNewRepository.getConnectorKind();
    } else {
      connectorKind = task.getConnectorKind();
    }

    if (LocalRepositoryConnector.CONNECTOR_KIND.equals(connectorKind)) {
      return CommonImages.getImage(TasksUiImages.TASK);
    } else {
      ImageDescriptor overlay;
      if (outgoingNewRepository != null) {
        overlay =
            TasksUiPlugin.getDefault().getBrandManager().getOverlayIcon(outgoingNewRepository);
      } else {
        overlay = TasksUiPlugin.getDefault().getBrandManager().getOverlayIcon(task);
      }
      Image image =
          CommonImages.getImageWithOverlay(TasksUiImages.REPOSITORY, overlay, false, false);
      return image;
    }
  }
Пример #23
0
  public String createXmlRpcTask() throws Exception {
    final TaskMapping taskMappingInit =
        new TaskMapping() {

          @Override
          public String getProduct() {
            return "TestProduct";
          }
        };
    final TaskMapping taskMappingSelect =
        new TaskMapping() {
          @Override
          public String getComponent() {
            return "TestComponent";
          }

          @Override
          public String getSummary() {
            return "test XMLRPC getBugData";
          }

          @Override
          public String getDescription() {
            return "The Description of the XMLRPC getBugData Bug";
          }
        };
    TaskAttribute flagA = null;
    TaskAttribute flagB = null;
    TaskAttribute flagC = null;
    TaskAttribute flagD = null;
    TaskAttribute stateA = null;
    TaskAttribute stateB = null;
    TaskAttribute stateC = null;
    TaskAttribute stateD = null;

    // create Task
    TaskData taskDataNew = createTaskData(taskMappingInit, taskMappingSelect, null);
    RepositoryResponse response = createNewTask(taskDataNew);

    assertNotNull(response);
    assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString());
    String taskId = response.getTaskId();

    ITask task = getTask(taskId);
    assertNotNull(task);
    TaskData taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);
    TaskAttribute attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData);
    TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment);

    /* Test uploading a proper file */
    String fileName = "test-attach-1.txt";
    File attachFile = new File(fileName);
    attachFile.createNewFile();
    attachFile.deleteOnExit();
    BufferedWriter write = new BufferedWriter(new FileWriter(attachFile));
    write.write("test file from " + System.currentTimeMillis());
    write.close();

    FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile);
    attachment.setContentType("text/plain");
    attachment.setDescription("Description");
    attachment.setName("My Attachment 1");
    try {
      priviledgedClient()
          .postAttachment(
              taskData.getTaskId(),
              attachmentMapper.getComment(),
              attachment,
              attrAttachment,
              new NullProgressMonitor());
    } catch (Exception e) {
      fail("never reach this!");
    }
    taskData = fixture.getTask(taskData.getTaskId(), priviledgedClient());
    assertNotNull(taskData);

    TaskAttribute attachmentAttribute =
        taskData
            .getAttributeMapper()
            .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
            .get(0);
    int flagCount = 0;
    int flagCountUnused = 0;
    TaskAttribute attachmentFlag1 = null;
    TaskAttribute attachmentFlag2 = null;
    for (TaskAttribute attribute : attachmentAttribute.getAttributes().values()) {
      if (!attribute.getId().startsWith(BugzillaAttribute.KIND_FLAG)) {
        continue;
      }
      flagCount++;
      if (attribute.getId().startsWith(BugzillaAttribute.KIND_FLAG_TYPE)) {
        flagCountUnused++;
        TaskAttribute stateAttribute =
            taskData.getAttributeMapper().getAssoctiatedAttribute(attribute);
        if (stateAttribute.getMetaData().getLabel().equals("AttachmentFlag1")) {
          attachmentFlag1 = attribute;
        }
        if (stateAttribute.getMetaData().getLabel().equals("AttachmentFlag2")) {
          attachmentFlag2 = attribute;
        }
      }
    }
    assertEquals(2, flagCount);
    assertEquals(2, flagCountUnused);
    assertNotNull(attachmentFlag1);
    assertNotNull(attachmentFlag2);
    TaskAttribute stateAttribute1 =
        taskData.getAttributeMapper().getAssoctiatedAttribute(attachmentFlag1);
    stateAttribute1.setValue("?");
    TaskAttribute requestee = attachmentFlag1.getAttribute("requestee"); // $NON-NLS-1$
    requestee.setValue("*****@*****.**");
    priviledgedClient().postUpdateAttachment(attachmentAttribute, "update", null);

    task = getTask(taskId);
    assertNotNull(task);
    taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);

    for (TaskAttribute taskAttribute : taskData.getRoot().getAttributes().values()) {
      if (taskAttribute.getId().startsWith(BugzillaAttribute.KIND_FLAG)) {
        TaskAttribute state = taskAttribute.getAttribute("state");
        if (state.getMetaData().getLabel().equals("BugFlag1")) {
          flagA = taskAttribute;
          stateA = state;
        } else if (state.getMetaData().getLabel().equals("BugFlag2")) {
          flagB = taskAttribute;
          stateB = state;
        } else if (state.getMetaData().getLabel().equals("BugFlag3")) {
          flagC = taskAttribute;
          stateC = state;
        } else if (state.getMetaData().getLabel().equals("BugFlag4")) {
          flagD = taskAttribute;
          stateD = state;
        }
      }
    }
    assertNotNull(flagA);
    assertNotNull(flagB);
    assertNotNull(flagC);
    assertNotNull(flagD);
    assertNotNull(stateA);
    assertNotNull(stateB);
    assertNotNull(stateC);
    assertNotNull(stateD);
    if (flagD != null) {
      TaskAttribute requesteeD = flagD.getAttribute("requestee");
      requesteeD.setValue("*****@*****.**");
    }
    if (stateA != null) {
      stateA.setValue("+");
    }
    if (stateB != null) {
      stateB.setValue("?");
    }
    if (stateC != null) {
      stateC.setValue("?");
    }
    if (stateD != null) {
      stateD.setValue("?");
    }

    TaskAttribute cf_freetext = taskData.getRoot().getAttribute("cf_freetext");
    TaskAttribute cf_dropdown = taskData.getRoot().getAttribute("cf_dropdown");
    TaskAttribute cf_largetextbox = taskData.getRoot().getAttribute("cf_largetextbox");
    TaskAttribute cf_multiselect = taskData.getRoot().getAttribute("cf_multiselect");
    TaskAttribute cf_datetime = taskData.getRoot().getAttribute("cf_datetime");
    TaskAttribute cf_bugid = taskData.getRoot().getAttribute("cf_bugid");
    cf_freetext.setValue("Freetext");
    cf_dropdown.setValue("one");
    cf_largetextbox.setValue("large text box");
    cf_multiselect.setValue("Blue");
    cf_datetime.setValue("2012-01-01 00:00:00");
    String cf_bugidValue = taskCfBugIdExists();
    if (cf_bugidValue == null) {
      cf_bugidValue = createCfBugIdTask();
    }
    cf_bugid.setValue(cf_bugidValue);
    response = fixture.submitTask(taskData, priviledgedClient());

    return taskId;
  }
Пример #24
0
  public String createAttachmentAttributesTask() throws Exception {
    final TaskMapping taskMappingInit =
        new TaskMapping() {

          @Override
          public String getProduct() {
            return "ManualTest";
          }
        };
    final TaskMapping taskMappingSelect =
        new TaskMapping() {
          @Override
          public String getComponent() {
            return "ManualC2";
          }

          @Override
          public String getSummary() {
            return "test Bug with Attachment";
          }

          @Override
          public String getDescription() {
            return "The Description of the test with Attachment Bug";
          }
        };

    // create Task
    TaskData taskDataNew = createTaskData(taskMappingInit, taskMappingSelect, null);
    RepositoryResponse response = createNewTask(taskDataNew);

    assertNotNull(response);
    assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString());
    String taskId = response.getTaskId();

    ITask task = getTask(taskId);
    assertNotNull(task);
    TaskData taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);
    TaskAttribute attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData);
    TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment);

    String fileName = "test-attach-1.txt";
    File attachFile = new File(fileName);
    attachFile.createNewFile();
    attachFile.deleteOnExit();
    BufferedWriter write = new BufferedWriter(new FileWriter(attachFile));
    write.write("test file from " + System.currentTimeMillis());
    write.close();

    FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile);
    attachment.setContentType("text/plain");
    attachment.setDescription("My Attachment 1");
    attachment.setName("My Attachment 1");
    try {
      priviledgedClient()
          .postAttachment(
              taskData.getTaskId(),
              attachmentMapper.getComment(),
              attachment,
              attrAttachment,
              new NullProgressMonitor());
    } catch (Exception e) {
      fail("never reach this!");
    }
    taskData = fixture.getTask(taskData.getTaskId(), priviledgedClient());
    assertNotNull(taskData);

    task = getTask(taskId);
    assertNotNull(task);
    taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);
    attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData);
    attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment);

    fileName = "test-attach-2.txt";
    attachFile = new File(fileName);
    attachFile.createNewFile();
    attachFile.deleteOnExit();
    write = new BufferedWriter(new FileWriter(attachFile));
    write.write("test file 2 from " + System.currentTimeMillis());
    write.close();

    attachment = new FileTaskAttachmentSource(attachFile);
    attachment.setContentType("text/plain");
    attachment.setDescription("My Attachment 2");
    attachment.setName("My Attachment 2");
    try {
      priviledgedClient()
          .postAttachment(
              taskData.getTaskId(),
              attachmentMapper.getComment(),
              attachment,
              attrAttachment,
              new NullProgressMonitor());
    } catch (Exception e) {
      fail("never reach this!");
    }
    taskData = fixture.getTask(taskData.getTaskId(), priviledgedClient());
    assertNotNull(taskData);

    task = getTask(taskId);
    assertNotNull(task);
    taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);
    attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData);
    attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment);

    fileName = "test-attach-3.txt";
    attachFile = new File(fileName);
    attachFile.createNewFile();
    attachFile.deleteOnExit();
    write = new BufferedWriter(new FileWriter(attachFile));
    write.write("test file 3 from " + System.currentTimeMillis());
    write.close();

    attachment = new FileTaskAttachmentSource(attachFile);
    attachment.setContentType("text/plain");
    attachment.setDescription("My Attachment 3");
    attachment.setName("My Attachment 3");
    TaskAttribute child = attrAttachment.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH);
    if (child != null) {
      child.setValue("1");
    }
    try {
      priviledgedClient()
          .postAttachment(
              taskData.getTaskId(),
              attachmentMapper.getComment(),
              attachment,
              attrAttachment,
              new NullProgressMonitor());
    } catch (Exception e) {
      fail("never reach this!");
    }
    taskData = fixture.getTask(taskData.getTaskId(), priviledgedClient());
    assertNotNull(taskData);

    task = getTask(taskId);
    assertNotNull(task);
    taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);
    attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData);
    attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment);

    fileName = "test-attach-4.txt";
    attachFile = new File(fileName);
    attachFile.createNewFile();
    attachFile.deleteOnExit();
    write = new BufferedWriter(new FileWriter(attachFile));
    write.write("test file 4 from " + System.currentTimeMillis());
    write.close();

    attachment = new FileTaskAttachmentSource(attachFile);
    attachment.setContentType("text/plain");
    attachment.setDescription("My Attachment 4");
    attachment.setName("My Attachment 4");
    child = attrAttachment.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH);
    if (child != null) {
      child.setValue("1");
    }
    try {
      priviledgedClient()
          .postAttachment(
              taskData.getTaskId(),
              attachmentMapper.getComment(),
              attachment,
              attrAttachment,
              new NullProgressMonitor());
    } catch (Exception e) {
      fail("never reach this!");
    }
    taskData = fixture.getTask(taskData.getTaskId(), priviledgedClient());
    assertNotNull(taskData);

    TaskAttribute attachment1 =
        taskData
            .getAttributeMapper()
            .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
            .get(1);
    assertNotNull(attachment1);
    TaskAttribute obsolete = attachment1.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED);
    assertNotNull(obsolete);
    obsolete.setValue("1"); // $NON-NLS-1$
    ((BugzillaTaskDataHandler) connector().getTaskDataHandler())
        .postUpdateAttachment(
            repository(), attachment1, "update", new NullProgressMonitor()); // $NON-NLS-1$

    task = getTask(taskId);
    assertNotNull(task);
    taskData = fixture.connector().getTaskData(repository(), task.getTaskId(), null);
    assertNotNull(taskData);

    TaskAttribute attachment2 =
        taskData
            .getAttributeMapper()
            .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
            .get(3);
    assertNotNull(attachment);
    obsolete = attachment2.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED);
    assertNotNull(obsolete);
    obsolete.setValue("1"); // $NON-NLS-1$
    ((BugzillaTaskDataHandler) connector().getTaskDataHandler())
        .postUpdateAttachment(
            repository(), attachment2, "update", new NullProgressMonitor()); // $NON-NLS-1$

    return taskId;
  }
Пример #25
0
  private void indexQueuedTasks(SubMonitor monitor)
      throws CorruptIndexException, LockObtainFailedException, IOException, CoreException {

    synchronized (reindexQueue) {
      if (reindexQueue.isEmpty()) {
        return;
      }

      monitor.beginTask(Messages.TaskListIndex_task_rebuilding_index, reindexQueue.size());
    }

    try {
      IndexWriter writer = null;
      try {
        Map<ITask, TaskData> workingQueue = new HashMap<ITask, TaskData>();

        // reindex tasks that are in the reindexQueue, making multiple passes so that we catch
        // anything
        // added/changed while we were reindexing
        for (; ; ) {
          workingQueue.clear();

          synchronized (reindexQueue) {
            if (reindexQueue.isEmpty()) {
              break;
            }
            // move items from the reindexQueue to the temporary working queue
            workingQueue.putAll(reindexQueue);
            reindexQueue.keySet().removeAll(workingQueue.keySet());
          }

          if (writer == null) {
            try {
              writer = createIndexWriter(false);
            } catch (CorruptIndexException e) {
              rebuildIndex = true;
              synchronized (reindexQueue) {
                reindexQueue.clear();
              }
              rebuildIndexCompletely(monitor);
              return;
            }
          }

          monitor.setWorkRemaining(workingQueue.size());

          for (Entry<ITask, TaskData> entry : workingQueue.entrySet()) {
            ITask task = entry.getKey();
            TaskData taskData = entry.getValue();

            writer.deleteDocuments(
                new Term(FIELD_IDENTIFIER.getIndexKey(), task.getHandleIdentifier()));

            add(writer, task, taskData);

            monitor.worked(1);
          }
        }
      } finally {
        if (writer != null) {
          writer.close();
        }
      }
    } finally {
      monitor.done();
    }
  }
Пример #26
0
  /**
   * Indicates if the given task matches the given pattern string. Uses the backing index to detect
   * a match by looking for tasks that match the given pattern string. The results of the search are
   * cached such that future calls to this method using the same pattern string do not require use
   * of the backing index, making this method very efficient for multiple calls with the same
   * pattern string. Cached results for a given pattern string are discarded if this method is
   * called with a different pattern string.
   *
   * @param task the task to match
   * @param patternString the pattern used to detect a match
   */
  public boolean matches(ITask task, String patternString) {
    if (patternString.equals(COMMAND_RESET_INDEX)) {
      reindex();
    }
    Lock readLock = indexReaderLock.readLock();
    readLock.lock();
    try {

      IndexReader indexReader = getIndexReader();
      if (indexReader != null) {
        Set<String> hits;

        final boolean needIndexHit;
        synchronized (this) {
          needIndexHit =
              lastResults == null
                  || (lastPatternString == null || !lastPatternString.equals(patternString));
        }
        if (needIndexHit) {
          this.lastPatternString = patternString;

          hits = new HashSet<String>();

          IndexSearcher indexSearcher = new IndexSearcher(indexReader);
          try {
            Query query = computeQuery(patternString);
            TopDocs results = indexSearcher.search(query, maxMatchSearchHits);
            for (ScoreDoc scoreDoc : results.scoreDocs) {
              Document document = indexReader.document(scoreDoc.doc);
              hits.add(document.get(FIELD_IDENTIFIER.getIndexKey()));
            }
          } catch (IOException e) {
            StatusHandler.log(
                new Status(
                    IStatus.ERROR,
                    TasksIndexCore.ID_PLUGIN,
                    "Unexpected failure within task list index",
                    e)); //$NON-NLS-1$
          } finally {
            try {
              indexSearcher.close();
            } catch (IOException e) {
              // ignore
            }
          }

        } else {
          hits = lastResults;
        }
        synchronized (this) {
          if (this.indexReader == indexReader) {
            this.lastPatternString = patternString;
            this.lastResults = hits;
          }
        }
        String taskIdentifier = task.getHandleIdentifier();
        return hits != null && hits.contains(taskIdentifier);
      }

    } finally {
      readLock.unlock();
    }
    return false;
  }
 @Override
 public void updateTaskFromTaskData(TaskRepository taskRepository, ITask task, TaskData taskData) {
   task.setUrl(taskData.getRepositoryUrl() + "/rest.cgi/bug/" + taskData.getTaskId());
 }
Пример #28
0
  private void addIndexedAttributes(Document document, ITask task, TaskAttribute root) {
    addIndexedAttribute(document, FIELD_TASK_KEY, task.getTaskKey());
    addIndexedAttribute(document, FIELD_REPOSITORY_URL, task.getRepositoryUrl());
    addIndexedAttribute(document, FIELD_SUMMARY, root.getMappedAttribute(TaskAttribute.SUMMARY));

    for (TaskAttribute contentAttribute : computeContentAttributes(root)) {
      addIndexedAttribute(document, FIELD_CONTENT, contentAttribute);
    }

    addIndexedDateAttributes(document, task);

    TaskData taskData = root.getTaskData();

    List<TaskAttribute> commentAttributes =
        taskData.getAttributeMapper().getAttributesByType(taskData, TaskAttribute.TYPE_COMMENT);
    for (TaskAttribute commentAttribute : commentAttributes) {

      TaskComment taskComment =
          new TaskComment(
              taskData.getAttributeMapper().getTaskRepository(), task, commentAttribute);
      taskData.getAttributeMapper().updateTaskComment(taskComment, commentAttribute);

      String text = taskComment.getText();
      if (text.length() != 0) {
        addIndexedAttribute(document, FIELD_CONTENT, text);
      }
      IRepositoryPerson author = taskComment.getAuthor();
      if (author != null) {
        addIndexedAttribute(document, FIELD_PERSON, author.getPersonId());
      }
    }

    List<TaskAttribute> personAttributes =
        taskData.getAttributeMapper().getAttributesByType(taskData, TaskAttribute.TYPE_PERSON);
    for (TaskAttribute personAttribute : personAttributes) {
      addIndexedAttribute(document, FIELD_PERSON, personAttribute);
    }

    TaskRepository repository =
        getRepositoryManager().getRepository(task.getConnectorKind(), task.getRepositoryUrl());

    if (repository != null) {
      List<TaskAttribute> attachmentAttributes =
          taskData
              .getAttributeMapper()
              .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT);
      Set<String> attachmentNames = new HashSet<String>();
      for (TaskAttribute attribute : attachmentAttributes) {
        TaskAttachment taskAttachment = new TaskAttachment(repository, task, attribute);
        taskData.getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);

        if (attachmentNames.add(taskAttachment.getFileName())) {
          addIndexedAttribute(document, FIELD_ATTACHMENT_NAME, taskAttachment.getFileName());
        }
        addIndexedAttribute(document, FIELD_CONTENT, taskAttachment.getDescription());
      }
    }

    for (AbstractTaskSchema.Field field : indexedFields) {
      if (!specialFields.contains(field)) {
        addIndexedAttribute(document, field, root.getMappedAttribute(field.getKey()));
      }
    }
  }