@Override
  public void setProtocolStatus(
      Protocol protocol,
      ProtocolStatusEnum protocolStatusEnum,
      User user,
      Committee committee,
      String note) {
    try {
      ProtocolStatus protocolStatus = new ProtocolStatus();
      protocolStatus.setCauseByUser(user);
      protocolStatus.setCausedByCommittee(committee);
      protocolStatus.setModified(new Date());
      protocolStatus.setNote(note);
      protocolStatus.setProtocol(protocol);
      protocolStatus.setProtocolStatus(protocolStatusEnum);
      protocolStatus.setRetired(Boolean.FALSE);

      protocolStatusDao.saveOrUpdate(protocolStatus);

      String protocolMetaDataXml = protocol.getMetaDataXml();

      protocolMetaDataXml =
          xmlProcessor.replaceOrAddNodeValueByPath(
              "/protocol/status",
              protocolMetaDataXml,
              org.apache.commons.lang.StringEscapeUtils.escapeXml(
                  protocolStatusEnum.getDescription()));

      Map<String, String> attributes = Maps.newHashMap();
      attributes.put("priority", protocolStatusEnum.getPriorityLevel());

      protocolMetaDataXml =
          xmlProcessor.addAttributesByPath("/protocol/status", protocolMetaDataXml, attributes);

      protocol.setMetaDataXml(protocolMetaDataXml);
      protocolDao.saveOrUpdate(protocol);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public Protocol consolidateProtocol(Protocol protocol, List<String> xPathList) {
    String protocolMetaData = protocol.getMetaDataXml();

    Map<String, Object> resultMap = Maps.newHashMap();

    for (String xPath : xPathList) {
      try {
        resultMap = xmlProcessor.deleteElementByPath(xPath, protocolMetaData);
      } catch (Exception e) {

      }

      if (resultMap != null && !resultMap.isEmpty())
        protocolMetaData = resultMap.get("finalXml").toString();
    }

    protocol.setMetaDataXml(protocolMetaData);

    protocol = protocolDao.saveOrUpdate(protocol);

    return protocol;
  }
  @Override
  public void addPushedToEpic(Protocol protocol) {
    try {
      String protocolMetaData = protocol.getMetaDataXml();

      protocolMetaData =
          xmlProcessor.replaceOrAddNodeValueByPath(
              "/protocol/pushed-to-epic", protocolMetaData, "y");

      protocolMetaData =
          xmlProcessor.replaceOrAddNodeValueByPath(
              "/protocol/pushed-to-epic-date",
              protocolMetaData,
              DateFormatUtil.formateDateToMDY(new Date()));

      protocol.setMetaDataXml(protocolMetaData);

      protocol = protocolDao.saveOrUpdate(protocol);

    } catch (Exception e) {
      // don't care
    }
  }
  @Override
  public ProtocolFormXmlData creatNewProtocol(ProtocolFormType protocolFormType)
      throws XPathExpressionException, IOException, SAXException {
    Protocol p = new Protocol();
    Date created = new Date();
    p.setCreated(created);
    p.setLocked(false);

    p = protocolDao.saveOrUpdate(p);

    p.setProtocolIdentifier(Long.toString(baseProtocolIdentifier + p.getId()));

    // protocol.metadataxml always start with /protocol/
    // String protocolMetaDataXmlString = "<protocol id=\"" + p.getId() + "\" identifier=\"" +
    // p.getProtocolIdentifier() + "\" type=\""+ protocolFormType.getDescription()
    // +"\"></protocol>";
    String protocolMetaDataXmlString =
        (protocolFormType.equals(ProtocolFormType.NEW_SUBMISSION))
            ? "<protocol id=\""
                + p.getId()
                + "\" identifier=\""
                + p.getProtocolIdentifier()
                + "\"></protocol>"
            : "<protocol id=\""
                + p.getId()
                + "\" identifier=\""
                + p.getProtocolIdentifier()
                + "\" type=\""
                + protocolFormType.getDescription()
                + "\"></protocol>";
    ;

    p.setMetaDataXml(protocolMetaDataXmlString);
    p = protocolDao.saveOrUpdate(p);

    String protocolFormXmlString =
        "<"
            + protocolFormType.getBaseTag()
            + " id=\""
            + p.getId()
            + "\" identifier=\""
            + p.getProtocolIdentifier()
            + "\" type=\""
            + protocolFormType.getDescription()
            + "\"></"
            + protocolFormType.getBaseTag()
            + ">";

    ProtocolForm f = new ProtocolForm();
    f.setProtocolFormType(protocolFormType);
    f.setProtocol(p);
    f.setCreated(created);
    f.setMetaDataXml(protocolFormXmlString);
    f.setParent(f);
    f.setLocked(false);

    f = protocolFormDao.saveOrUpdate(f);

    ProtocolFormXmlData fxd = new ProtocolFormXmlData();
    fxd.setProtocolForm(f);
    fxd.setXmlData(protocolFormXmlString);
    fxd.setProtocolFormXmlDataType(protocolFormType.getDefaultProtocolFormXmlDataType());
    fxd.setParent(fxd);
    fxd.setCreated(created);

    fxd = protocolFormXmlDataDao.saveOrUpdate(fxd);

    Map<ProtocolFormXmlDataType, ProtocolFormXmlData> protocolFormXmlDatas =
        new HashMap<ProtocolFormXmlDataType, ProtocolFormXmlData>(0);
    protocolFormXmlDatas.put(protocolFormType.getDefaultProtocolFormXmlDataType(), fxd);
    f.setTypedProtocolFormXmlDatas(protocolFormXmlDatas);

    User currentUser = userService.getCurrentUser();

    protocolFormService.triggerPIAction("CREATE", f, currentUser, null);

    objectAclService.updateObjectAclByUser(Protocol.class, p.getId(), currentUser);
    return fxd;
  }