private ArrayList<Integer> getCoreChildren(int concept_id, I_IntSet allowed_status, I_Path path)
     throws Exception {
   // TODO replace with passed in config...
   I_ConfigAceFrame config = Terms.get().getActiveAceFrameConfig();
   ArrayList<Integer> ret = new ArrayList<Integer>();
   final I_TermFactory tf = Terms.get();
   I_GetConceptData c = tf.getConcept(concept_id);
   I_IntSet isa_rels = tf.newIntSet();
   isa_rels.add(SNOMED.Concept.IS_A.localize().getNid());
   isa_rels.add(ArchitectonicAuxiliary.Concept.IS_A_REL.localize().getNid());
   for (I_GetConceptData d :
       c.getDestRelOrigins(
           allowed_status,
           isa_rels,
           null,
           config.getPrecedence(),
           config.getConflictResolutionStrategy())) {
     ret.add(d.getConceptId());
   }
   Collections.sort(
       ret,
       new Comparator<Integer>() {
         public int compare(Integer obj1, Integer obj2) {
           try {
             String s1 = tf.getConcept(obj1).getInitialText();
             String s2 = tf.getConcept(obj2).getInitialText();
             return s1.compareTo(s2);
           } catch (Exception e) {
           }
           return obj1.compareTo(obj2);
         }
       });
   return ret;
 }
 public I_IntSet getActiveStatus(I_TermFactory termFactory) throws Exception {
   I_IntSet activeSet = Terms.get().newIntSet();
   I_ConfigAceFrame config = getFrameConfig();
   if (config == null) {
     config =
         NewDefaultProfile.newProfile(
             "fullname", "username", "password", "adminUsername", "adminPassword");
   }
   activeSet.addAll(config.getAllowedStatus().getSetValues());
   for (ArchitectonicAuxiliary.Concept con :
       Arrays.asList(
           ArchitectonicAuxiliary.Concept.ACTIVE,
           ArchitectonicAuxiliary.Concept.CURRENT,
           ArchitectonicAuxiliary.Concept.CONCEPT_RETIRED,
           ArchitectonicAuxiliary.Concept.CURRENT_UNREVIEWED,
           ArchitectonicAuxiliary.Concept.LIMITED,
           ArchitectonicAuxiliary.Concept.PENDING_MOVE,
           ArchitectonicAuxiliary.Concept.READY_TO_PROMOTE,
           ArchitectonicAuxiliary.Concept.PROMOTED)) {
     I_GetConceptData c = getConceptSafe(termFactory, con.getUids());
     if (c != null) {
       activeSet.add(c.getConceptId());
     }
   }
   return activeSet;
 }
 private I_IntSet getActiveStatus() throws Exception {
   final I_TermFactory tf = Terms.get();
   I_IntSet ret = tf.newIntSet();
   for (Integer s :
       getCoreDescendants(ArchitectonicAuxiliary.Concept.ACTIVE.localize().getNid(), null, null)) {
     ret.add(s);
   }
   return ret;
 }
 public void execute() throws MojoExecutionException, MojoFailureException {
   I_TermFactory termFactory = Terms.get();
   try {
     FindComponents find = new FindComponents();
     termFactory.iterateConcepts(find);
     find.getTextWriter().close();
     find.getHtmlWriter().close();
   } catch (Exception e) {
     throw new MojoExecutionException(e.getLocalizedMessage(), e);
   }
 }
 public FindComponents() throws Exception {
   outputHtmlDirectory.mkdirs();
   outputTextDirectory.mkdirs();
   textWriter =
       new BufferedWriter(
           new BufferedWriter(
               new FileWriter(outputTextDirectory + File.separator + outputTextFileName)));
   htmlWriter =
       new BufferedWriter(
           new BufferedWriter(
               new FileWriter(outputHtmlDirectory + File.separator + outputHtmlFileName)));
   termFactory = Terms.get();
   origins = new HashSet<I_Position>();
 }
    public void processConcept(I_GetConceptData concept) throws Exception {
      // get origins
      I_Path architectonicPath =
          termFactory.getPath(ArchitectonicAuxiliary.Concept.ARCHITECTONIC_BRANCH.getUids());

      I_Position latestOnArchitectonicPath =
          termFactory.newPosition(architectonicPath, Integer.MAX_VALUE);

      origins.add(latestOnArchitectonicPath);

      Set<I_Position> branchPositions = new HashSet<I_Position>();

      // TODO replace with passed in config...
      I_ConfigAceFrame config = Terms.get().getActiveAceFrameConfig();

      // get all the concepts/paths/positions for the specified branches
      if (branches == null) {
        branchPositions = null;
      } else {
        for (ConceptDescriptor branch : branches) {
          I_GetConceptData currentConcept = branch.getVerifiedConcept();
          I_Path currentPath = termFactory.getPath(currentConcept.getUids());
          I_Position currentPosition = termFactory.newPosition(currentPath, Integer.MAX_VALUE);
          branchPositions.add(currentPosition);
        }
      }

      // get latest IS-A relationships
      I_IntSet isARel = termFactory.newIntSet();
      isARel.add(
          termFactory.getConcept(ArchitectonicAuxiliary.Concept.IS_A_REL.getUids()).getConceptId());

      List<? extends I_RelTuple> results =
          concept.getDestRelTuples(
              null,
              isARel,
              new PositionSetReadOnly(branchPositions),
              config.getPrecedence(),
              config.getConflictResolutionStrategy());
      if (results.size() > count) {
        String message = "Concept: " + concept + " has > 20 children.";
        getLog().info(message);
        htmlWriter.append(message);
        htmlWriter.append("<br>");
        textWriter.append(concept.getUids().toString());
        textWriter.newLine();
      }

      termFactory.addUncommitted(concept);
    }
 public Condition evaluate(I_EncodeBusinessProcess process, I_Work worker)
     throws TaskFailedException {
   try {
     I_TermFactory tf = Terms.get();
     I_Path editPath = tf.getPath(editPathEntry.ids);
     I_ConfigAceFrame frameConfig = tf.getActiveAceFrameConfig();
     Set<I_Path> editSet = frameConfig.getEditingPathSet();
     editSet.clear();
     frameConfig.addEditingPath(editPath);
     frameConfig.fireUpdateHierarchyView();
     return Condition.CONTINUE;
   } catch (IllegalArgumentException e) {
     throw new TaskFailedException(e);
   } catch (IOException e) {
     throw new TaskFailedException(e);
   } catch (TerminologyException e) {
     throw new TaskFailedException(e);
   }
 }
  /** Start this monitor. Batch processing has commenced. */
  public void start() throws Exception {
    I_TermFactory termFactory = Terms.get();
    activity =
        termFactory.newActivityPanel(
            false, termFactory.getActiveAceFrameConfig(), description, true);
    activity.setProgressInfoUpper(description);
    activity.setProgressInfoLower("Commencing...");
    activity.setMaximum((int) totalEvents);
    activity.setValue(0);
    activity.setIndeterminate(false);

    timer = new BatchReportingThread(this, reportCycleMs, activity);
    if (showMessagePanel) {
      addMessagePanel();
    }
    addFinishedButton();
    timer.activity.getViewPanel(false).validate();

    timer.start();
  }
  private void listRefset() throws Exception {
    // TODO replace with passed in config...
    I_ConfigAceFrame config = Terms.get().getActiveAceFrameConfig();

    getLog().info("refset list");
    list_file.getParentFile().mkdirs();
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(this.list_file)));
    final I_TermFactory tf = Terms.get();
    if (this.path_uuid != null) {
      this.path = tf.getPath(Arrays.asList(UUID.fromString(this.path_uuid)));
    }
    // I_IntSet allowed_status = tf.newIntSet();
    // allowed_status.add(ArchitectonicAuxiliary.Concept.CURRENT.localize().getNid());
    refset_con = tf.getConcept(Arrays.asList(UUID.fromString(this.refset_con_uuid)));
    out.println("<html>");
    out.println("<head>");
    out.println("<style type=\"text/css\">");
    out.println("BODY {font:10pt sans-serif}");
    out.println("TABLE {font:10pt sans-serif; border-collapse:collapse}");
    out.println("TD {border: 1px solid; padding:5px}");
    out.println("</style>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h2>");
    out.println("Refset Report");
    out.println("</h2>");
    out.println("<p>");
    out.println(
        escapeString(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date())));
    ArrayList<Integer> refsets =
        getCoreDescendants(refset_con.getConceptId(), getActiveStatus(), this.path);
    if (this.sort_by_name) {
      Collections.sort(
          refsets,
          new Comparator<Integer>() {
            public int compare(Integer obj1, Integer obj2) {
              try {
                String s1 = tf.getConcept(obj1).getInitialText();
                String s2 = tf.getConcept(obj2).getInitialText();
                return s1.compareTo(s2);
              } catch (Exception e) {
              }
              return obj1.compareTo(obj2);
            }
          });
    }
    for (Integer con_id : refsets) {
      I_GetConceptData con = tf.getConcept(con_id);
      out.println("<h3>");
      out.println(escapeString(con.getInitialText()));
      out.println("</h3>");
      out.println("<table border=\"1\">");
      for (UUID id : con.getUids()) {
        out.println("<tr>");
        out.println("<td>");
        out.println("ID");
        out.println("<td>");
        out.println(escapeString(String.valueOf(id)));
      }
      for (String r :
          Arrays.asList(
              "dd413e49-c124-3b05-8c25-0da5922379d3",
              "7a981930-621f-3935-b26c-47f54413a59d",
              "41fbef7f-7210-3288-97cb-c860dfc90601",
              "f60922c9-cb3d-3099-8960-1097d2c5afdc")) {
        I_GetConceptData r_con = tf.getConcept(Arrays.asList(UUID.fromString(r)));
        if (r_con != null) {
          boolean found = false;
          String head = r_con.getInitialText().replace(" rel", "");
          I_IntSet r_set = tf.newIntSet();
          r_set.add(r_con.getConceptId());
          for (I_GetConceptData val_con :
              con.getSourceRelTargets(
                  getActiveStatus(),
                  r_set,
                  null,
                  config.getPrecedence(),
                  config.getConflictResolutionStrategy())) {
            // for (int val_id : getRelationship(con.getConceptId(),
            // r_con.getConceptId(), null, Integer.MAX_VALUE)) {
            // I_GetConceptData val_con = tf.getConcept(val_id);
            if (val_con != null) {
              found = true;
              out.println("<tr>");
              out.println("<td>");
              out.println(escapeString(head));
              out.println("<td>");
              out.println(escapeString(val_con.getInitialText()));
            }
          }
          if (!found) {
            out.println("<tr>");
            out.println("<td>");
            out.println(escapeString(head));
            out.println("<td>");
          }
        }
      }
      // comments rel "ff1b55d3-2b7b-382c-ae42-eceffcc47c71"
      // promotion rel "9a801240-b3b0-3475-8a7b-07111d3ff564"
      for (String r :
          Arrays.asList(
              "ff1b55d3-2b7b-382c-ae42-eceffcc47c71", "9a801240-b3b0-3475-8a7b-07111d3ff564")) {
        I_GetConceptData r_con = tf.getConcept(Arrays.asList(UUID.fromString(r)));
        if (r_con != null) {
          boolean found = false;
          String head = r_con.getInitialText().replace(" rel", "");
          I_IntSet r_set = tf.newIntSet();
          r_set.add(r_con.getConceptId());
          for (I_GetConceptData val_con :
              con.getSourceRelTargets(
                  getActiveStatus(),
                  r_set,
                  null,
                  config.getPrecedence(),
                  config.getConflictResolutionStrategy())) {
            if (val_con != null) {
              found = true;
              out.println("<tr>");
              out.println("<td>");
              out.println(escapeString(head));
              out.println("<td>");
              // out.println(val_con.getInitialText());
              //
              for (I_ExtendByRef mem : tf.getRefsetExtensionMembers(val_con.getConceptId())) {
                I_GetConceptData mem_con = tf.getConcept(mem.getComponentId());
                I_ExtendByRefPart p = mem.getMutableParts().get(0);
                if (p instanceof I_ExtendByRefPartStr) {
                  I_ExtendByRefPartStr pccs = (I_ExtendByRefPartStr) p;
                  out.println("<tr>");
                  out.println("<td>");
                  out.println("<td>");
                  out.println(escapeString(pccs.getStringValue()));
                } else {
                  getLog().info("Wrong type: " + p.getClass() + " " + mem_con.getInitialText());
                }
              }
              //
            }
          }
          if (!found) {
            out.println("<tr>");
            out.println("<td>");
            out.println(escapeString(head));
            out.println("<td>");
          }
        }
      }
      out.println("</table>");
    }
    out.println("</body>");
    out.println("</html>");
    out.close();

    // make a copy of the report file, in Maven's site folder
    site_output_file.getParentFile().mkdirs();
    copy(list_file, site_output_file);
  }
  public Condition evaluate(I_EncodeBusinessProcess process, I_Work worker)
      throws TaskFailedException {
    try {
      I_ConfigAceFrame config =
          (I_ConfigAceFrame) worker.readAttachement(WorkerAttachmentKeys.ACE_FRAME_CONFIG.name());

      I_TermFactory tf = Terms.get();

      I_ConfigAceFrame workingProfile = (I_ConfigAceFrame) process.getProperty(profilePropName);
      if (workingProfile == null) {
        workingProfile =
            (I_ConfigAceFrame) worker.readAttachement(WorkerAttachmentKeys.ACE_FRAME_CONFIG.name());
      }

      Object conceptObj = process.getProperty(activeConceptPropName);
      I_GetConceptData concept = AceTaskUtil.getConceptFromObject(conceptObj);

      List<? extends I_ConceptAttributeTuple> attrTupels =
          concept.getConceptAttributeTuples(
              workingProfile.getAllowedStatus(), workingProfile.getViewPositionSetReadOnly(),
              workingProfile.getPrecedence(), workingProfile.getConflictResolutionStrategy());

      I_IntSet pathSet = Terms.get().newIntSet();

      ArrayList<UniversalAcePosition> positionList = new ArrayList<UniversalAcePosition>();
      for (I_ConceptAttributeTuple t : attrTupels) {
        positionList.add(
            new UniversalAcePosition(
                tf.getUids(t.getPathId()), tf.convertToThickVersion(t.getVersion())));
        pathSet.add(t.getPathId());
      }
      ArrayList<String> addressList = new ArrayList<String>();

      I_IntList inboxDescTypeList = Terms.get().newIntList();
      inboxDescTypeList.add(ArchitectonicAuxiliary.Concept.USER_INBOX.localize().getNid());
      for (int pathId : pathSet.getSetValues()) {
        I_GetConceptData pathConcept = Terms.get().getConcept(pathId);
        I_DescriptionTuple inboxDesc = pathConcept.getDescTuple(inboxDescTypeList, config);
        if (inboxDesc == null) {
          worker.getLogger().info("Cannot find inbox for: " + pathConcept.getInitialText());
          worker.getLogger().info(" inboxDescTypeList: " + inboxDescTypeList.getListArray());
          for (I_DescriptionVersioned desc : pathConcept.getDescriptions()) {
            for (I_DescriptionTuple tuple : desc.getTuples()) {
              worker.getLogger().info(" desc tuple: " + tuple);
            }
          }
        } else {
          addressList.add(inboxDesc.getText());
        }
      }
      process.setProperty(addressListPropName, addressList);
      process.setProperty(positionListPropName, positionList);
      worker.getLogger().info("Selected status values have these positions: " + positionList);
      worker.getLogger().info("Got addresses from status values: " + addressList);

      return Condition.CONTINUE;
    } catch (IllegalArgumentException e) {
      throw new TaskFailedException(e);
    } catch (IllegalAccessException e) {
      throw new TaskFailedException(e);
    } catch (InvocationTargetException e) {
      throw new TaskFailedException(e);
    } catch (IntrospectionException e) {
      throw new TaskFailedException(e);
    } catch (IOException e) {
      throw new TaskFailedException(e);
    } catch (TerminologyException e) {
      throw new TaskFailedException(e);
    }
  }
  /**
   * @see org.dwfa.bpa.process.I_DefineTask#complete(org.dwfa.bpa.process.I_EncodeBusinessProcess,
   *     org.dwfa.bpa.process.I_Work)
   */
  public Condition evaluate(I_EncodeBusinessProcess process, final I_Work worker)
      throws TaskFailedException {
    try {

      I_HelpMemberRefsetsCalculateConflicts mrc =
          Terms.get().getMemberRefsetConflictCalculator(Terms.get().getActiveAceFrameConfig());
      mrc.setOutputDirectory(new File("."));
      mrc.setValidateOnly(true);
      mrc.run();

      I_ConfigAceFrame config =
          (I_ConfigAceFrame) worker.readAttachement(WorkerAttachmentKeys.ACE_FRAME_CONFIG.name());
      final JPanel signpostPanel = config.getSignpostPanel();
      final JPanel p = new JPanel();
      final JScrollPane jsp = new JScrollPane(p);
      final List<String> details = mrc.getConclictDetails();

      SwingUtilities.invokeAndWait(
          new Runnable() {

            public void run() {
              Component[] components = signpostPanel.getComponents();
              for (int i = 0; i < components.length; i++) {
                signpostPanel.remove(components[i]);
              }

              signpostPanel.setLayout(new GridBagLayout());

              p.setLayout(new GridBagLayout());
              p.setBackground(Color.WHITE);

              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.BOTH;
              c.gridx = 0;
              c.gridy = 0;
              c.gridheight = 5;
              c.weightx = 1.0;
              c.weighty = 1.0;
              c.anchor = GridBagConstraints.NORTHWEST;

              StringBuffer sb = new StringBuffer();
              sb.append("<html><body><tr><td>");
              int counter = 0;
              for (String conflict : details) {
                // Add to signpost
                if (counter == 0) {
                  sb.append("<h1>" + conflict + "</h1><ul>");
                } else {
                  sb.append("<li>" + conflict + "</li>");
                }

                counter++;
              }

              if (details.size() > 0) {
                sb.append("</ul>");
              }

              sb.append("</td></tr></body></html>");

              p.add(new JLabel(sb.toString()), c);
              signpostPanel.add(jsp, c);
              signpostPanel.validate();
              Container cont = signpostPanel;

              while (cont != null) {
                cont.validate();
                cont = cont.getParent();
              }
            }
          });

      if (mrc.hasConflicts()) {
        return Condition.TRUE;
      }
      return Condition.FALSE;
    } catch (InterruptedException e) {
      throw new TaskFailedException(e);
    } catch (InvocationTargetException e) {
      throw new TaskFailedException(e);
    } catch (Exception e) {
      throw new TaskFailedException(e);
    }
  } // End method evaluate