public IStatus run()

in ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/UpdateTaskHandler.java [94:207]


    public IStatus run(IProgressMonitor monitor) {
      Map<String, Set<String>> typesToCheck = composite.getCheckedTypes();

      File dir = new File(documentSource);
      File[] listFiles = dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File file, String string) {
          return string.endsWith(".xmi");
        }
      });
      if (listFiles == null) {
        return Status.CANCEL_STATUS;
      }

      File dataFile = new File(documentSink, "data.xml");
      List<CheckDocument> docs = new ArrayList<CheckDocument>();
      try {
        docs = CheckDocumentXMLUtils.read(dataFile);
      } catch (SAXException e) {
        RutaAddonsPlugin.error(e);
      } catch (IOException e) {
        RutaAddonsPlugin.error(e);
      }
      setDefaultTypeSystem(documentSource, typeSystem);
      TypeSystemDescription tsd = null;
      try {
        tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(
                new XMLInputSource(typeSystem));
        tsd.resolveImports();
      } catch (InvalidXMLException e) {
        RutaAddonsPlugin.error(e);
      } catch (IOException e) {
        RutaAddonsPlugin.error(e);
      }
      CAS cas = null;
      try {
        cas = CasCreationUtils.createCas(tsd, null, new FsIndexDescription[0]);
      } catch (ResourceInitializationException e) {
        RutaAddonsPlugin.error(e);
      }

      if (tsd == null || cas == null) {
        return Status.CANCEL_STATUS;
      }
      TreePath treePath = null;
      final IAnnotationCheckTreeNode root = new AnnotationCheckRootNode();
      for (File file : listFiles) {
        cas.reset();
        try {
          XmiCasDeserializer.deserialize(new FileInputStream(file), cas, true);
        } catch (FileNotFoundException e) {
          RutaAddonsPlugin.error(e);
        } catch (SAXException e) {
          RutaAddonsPlugin.error(e);
        } catch (IOException e) {
          RutaAddonsPlugin.error(e);
        }
        CheckDocument element = getCheckDocument(docs, file.getAbsolutePath());
        boolean documentAlreadyDone = documentAlreadyDoneforTypes(element, new LinkedList<String>(
                typesToCheck.keySet()));
        if (!documentAlreadyDone) {
          AnnotationCheckTreeNode node = new AnnotationCheckTreeNode(root, element);
          root.addChild(node);
          AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
          for (AnnotationFS each : annotationIndex) {
            boolean annotationAlreadyDoneforTypes = annotationAlreadyDoneforTypes(each,
                    typesToCheck.keySet(), element.checkedTypes);
            if (!annotationAlreadyDoneforTypes) {
              CheckElement ac = new CheckAnnotation(each);
              AnnotationCheckTreeNode anode = new AnnotationCheckTreeNode(node, ac);
              for (String feature : typesToCheck.get(each.getType().getName())) {
                anode.addChild(new FeatureCheckTreeNode(anode, each.getType().getFeatureByBaseName(
                        feature), each.getFeatureValueAsString(each.getType().getFeatureByBaseName(
                        feature))));
              }
              if (treePath == null) {
                treePath = new TreePath(new Object[] { root, node, anode });
              }
              node.addChild(anode);
            }
          }
          if (treePath == null) {
            treePath = new TreePath(new Object[] { root, node });
          }
        }
      }
      if (root.getChildren().length == 0) {
        return Status.OK_STATUS;
      }
      if (previousSelection != null) {
        CheckElement element = previousSelection.getElement();
        TreePath oldPath = getPathTo(element, root);
        if (oldPath != null) {
          treePath = oldPath;
        }
      }
      final TreeSelection firstSelection = new TreeSelection(treePath);

      cas.release();
      composite.setOldDocs(docs);
      composite.getDisplay().asyncExec(new Runnable() {
        @Override
        public void run() {
          TreeViewer treeView = composite.getTreeViewer();
          treeView.setInput(root);
          treeView.setSelection(firstSelection, true);
          treeView.expandToLevel(
                  ((AnnotationCheckTreeNode) firstSelection.getFirstElement()).getParent(),
                  TreeViewer.ALL_LEVELS);
        }
      });

      return Status.OK_STATUS;
    }