public boolean hasUnpositioned() {
   for (ProcessNode<?, ?> node : getModelNodes()) {
     if (!node.hasPos()) {
       return true;
     }
   }
   return false;
 }
示例#2
0
  /** Returns whether a certain ProcessNode is graphically contained or not. */
  @Override
  public boolean isContainedGraphically(
      List<ProcessNode> nodes, ProcessNode node, boolean onTopRequired) {
    if (node == null) return false;
    // Check boundaries for floating Lane
    if (!getProperty(PROP_FLOATING).equals("0")) {
      return super.isContainedGraphically(nodes, node, true);
    }
    // Check boundaries for non-floating Lane
    if ((node.getPos().y >= (this.getPos().y - this.getSize().height / 2))
        && (node.getPos().y <= (this.getPos().y + this.getSize().height / 2))) {
      return true;
    }

    return false;
  }
 /**
  * Normalize the process model. By default this may do nothing.
  *
  * @return The model (this).
  */
 public M normalize(SplitFactory<? extends T, M> splitFactory) {
   ensureIds();
   // Make all nodes directly refer to other nodes.
   for (T childNode : mProcessNodes) {
     childNode.resolveRefs();
   }
   for (T childNode : mProcessNodes) {
     // Create a copy as we are actually going to remove all successors, but need to keep the list
     ArrayList<Identifiable> successors = new ArrayList<>(childNode.getSuccessors());
     if (successors.size() > 1 && !(childNode instanceof Split)) {
       for (Identifiable suc2 : successors) { // Remove the current node as predecessor.
         ProcessNode<?, ?> suc = (ProcessNode) suc2;
         suc.removePredecessor(childNode);
         childNode.removeSuccessor(suc); // remove the predecessor from the current node
       }
       // create a new join, this should
       Split<? extends T, M> newSplit = splitFactory.createSplit(asM(), successors);
       childNode.addSuccessor(newSplit);
     }
   }
   return this.asM();
 }
 public void ensureIds() {
   Set<String> ids = new HashSet<>();
   List<ProcessNode<?, ?>> unnamedNodes = new ArrayList<>();
   for (ProcessNode<?, ?> node : getModelNodes()) {
     String id = node.getId();
     if (id == null) {
       unnamedNodes.add(node);
     } else {
       ids.add(id);
     }
   }
   Map<String, Integer> startCounts = new HashMap<>();
   for (ProcessNode<?, ?> unnamed : unnamedNodes) {
     String idBase = unnamed.getIdBase();
     int startCount = getOrDefault(startCounts, idBase, 1);
     for (String id = idBase + Integer.toString(startCount);
         ids.contains(id);
         id = idBase + Integer.toString(startCount)) {
       ++startCount;
     }
     unnamed.setId(idBase + Integer.toString(startCount));
     startCounts.put(idBase, startCount + 1);
   }
 }
示例#5
0
  private void createGraph() {
    graph = new Graph();
    String[] columns = Arrays.copyOf(assayTable[0], assayTable[0].length, String[].class);

    int index = 0;

    ProcessNode lastProcess = null;
    NodeWithComments lastMaterialOrData = null;
    NodeWithComments lastSample = null;
    ISAFactorValue lastFactorValue = null;
    ProtocolExecutionNode lastProtocolExecutionNode = null;
    List<ProtocolExecutionNode> protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();

    for (String column : columns) {

      if (column.matches(Date.REGEXP)) {
        Date date = new Date(index, column);
        if (lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.addDate(date);
        }

      } else if (column.matches(Performer.REGEXP)) {
        Performer performer = new Performer(index, column);
        if (lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.addPerformer(performer);
        }

      } else if (column.matches(ProtocolExecutionNode.REGEXP)) {
        ProtocolExecutionNode protocolExecutionNode = new ProtocolExecutionNode(index, column);
        protocolExecutionNodes.add(protocolExecutionNode);
        lastProtocolExecutionNode = protocolExecutionNode;

        if (lastMaterialOrData != null) {
          protocolExecutionNode.setInputNode(lastMaterialOrData);
        }

        graph.addNode(protocolExecutionNode);

      } else if (column.matches(ProcessNode.REGEXP)) {
        ProcessNode processNode = new ProcessNode(index, column);

        graph.addNode(processNode);
        if (lastMaterialOrData != null) {
          // but it could be a DataNode rather than a material node... do I need a new object?
          // processNode.setInputNode(
          //       new MaterialNode(lastMaterialOrData.getIndex(), lastMaterialOrData.getName()));
          processNode.setInputNode(lastMaterialOrData);
        }
        lastProcess = processNode;
        if (lastProcess != null) {
          lastProcess.addProtocolExecutionNodes(protocolExecutionNodes);
          protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();
        }

      } else if (column.contains(ISADataNode.CONTAINS) && !column.contains("Comment")) {
        NodeWithComments dataNode = new DataNode(index, column);
        graph.addNode(dataNode);
        lastMaterialOrData = dataNode;

        if (lastProcess != null) {
          lastProcess.setOutputNode(dataNode);
          lastProcess = null;
        } else if (lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.setOutputNode(dataNode);
          lastProtocolExecutionNode = null;
        }

        if (lastMaterialOrData != null
            && lastProcess == null
            && lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.setOutputNode(dataNode);
          protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();
        }

      } else if (column.matches(ISAMaterialAttribute.REGEXP)) {

        ISAMaterialAttribute materialAttribute = new MaterialAttribute(index, column);
        if (lastMaterialOrData != null && lastMaterialOrData instanceof MaterialNode) {
          ((MaterialNode) graph.getNode(lastMaterialOrData.getIndex()))
              .addMaterialAttribute(materialAttribute);
        }

      } else if (column.matches(MaterialNode.REGEXP)) {

        NodeWithComments materialNode = null;
        if (column.matches(ISASampleNode.REGEXP)) {
          materialNode = new SampleNode(index, column);
          lastSample = materialNode;
        } else {
          materialNode = new MaterialNode(index, column);
        }
        // if there is a previous material node
        // and no process node, add a dummy process node
        if (lastMaterialOrData != null
            && lastProcess == null
            && lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.setOutputNode(materialNode);
          protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();
        }

        graph.addNode(materialNode);
        lastMaterialOrData = materialNode;
        if (lastProcess != null) {
          lastProcess.setOutputNode(materialNode);
          lastProcess = null;
        }

      } else if (column.matches(ISAFactorValue.REGEXP)) {

        ISAFactorValue factorValue = new FactorValue(index, column);
        lastFactorValue = factorValue;
        if (lastSample != null && lastSample instanceof SampleNode) {
          ((SampleNode) graph.getNode(lastSample.getIndex())).addFactorValue(factorValue);
        }

      } else if (column.matches(ISAUnit.REGEXP)) {

        ISAUnit unit = new Unit(index, column);
        if (lastFactorValue != null) {
          lastFactorValue.setUnit(unit);
        }

      } else if (column.matches(ProcessParameter.REGEXP)) {

        ProcessParameter parameter = new ProcessParameter(index, column);

        if (lastProtocolExecutionNode != null) {
          ((ProcessNode) graph.getNode(lastProtocolExecutionNode.getIndex()))
              .addParameter(parameter);
        }

      } else if (column.matches(CommentNode.REGEXP)) {

        CommentNode commentNode = new CommentNode(index, column);

        if (lastProcess != null
            && lastMaterialOrData != null
            && lastProtocolExecutionNode != null) {

          // lastProcess greater index
          if (lastProcess.getIndex() > lastMaterialOrData.getIndex()
              && lastProcess.getIndex() > lastProtocolExecutionNode.getIndex()) {
            lastProcess.addComment(commentNode);
          } else if (lastMaterialOrData.getIndex() > lastProcess.getIndex()
              && lastMaterialOrData.getIndex() > lastProtocolExecutionNode.getIndex()) {
            lastMaterialOrData.addComment(commentNode);
          } else if (lastProtocolExecutionNode.getIndex() > lastProcess.getIndex()
              && lastProtocolExecutionNode.getIndex() > lastMaterialOrData.getIndex()) {
            lastProtocolExecutionNode.addComment(commentNode);
          }

        } else { // one of them is null

          if (lastProcess != null && lastMaterialOrData != null) {

            if (lastProcess.getIndex() > lastMaterialOrData.getIndex()) {
              lastProcess.addComment(commentNode);
            } else {
              lastMaterialOrData.addComment(commentNode);
            }

          } else if (lastProcess != null && lastProtocolExecutionNode != null) {

            if (lastProcess.getIndex() > lastProtocolExecutionNode.getIndex()) {
              lastProcess.addComment(commentNode);
            } else {
              lastProtocolExecutionNode.addComment(commentNode);
            }

          } else if (lastMaterialOrData != null && lastProtocolExecutionNode != null) {

            if (lastMaterialOrData.getIndex() > lastProtocolExecutionNode.getIndex()) {
              lastMaterialOrData.addComment(commentNode);
            } else {
              lastProtocolExecutionNode.addComment(commentNode);
            }

          } else {

            // only one is not null

            if (lastMaterialOrData != null) {
              lastMaterialOrData.addComment(commentNode);
            } else if (lastProcess != null) {
              lastProcess.addComment(commentNode);
            } else if (lastProtocolExecutionNode != null) {
              lastProtocolExecutionNode.addComment(commentNode);
            }
          }
        }
      }
      index++;
    }
  }