コード例 #1
0
  // IdName values can be found in ParameterValue entities which are used in Dashboards widget
  // parameters or Scheduler report runtime parameters
  private void convertOldIdNameClass() throws RepositoryException {
    String searchRoot = "/jcr:root" + ISO9075.encodePath(StorageConstants.NEXT_SERVER_ROOT);
    String searchPropertyName = "className";
    String searchPropertyValue = "com.asf.nextserver.domain.ParameterValue";
    String statement =
        searchRoot + "//*[@" + searchPropertyName + "='" + searchPropertyValue + "']";
    QueryResult queryResult = getTemplate().query(statement);

    NodeIterator nodes = queryResult.getNodes();
    LOG.info("Found " + nodes.getSize() + " parameter value nodes");
    while (nodes.hasNext()) {
      Node node = nodes.nextNode();
      Property property = null;
      try {
        property = node.getProperty("value");
      } catch (PathNotFoundException ex) {
        continue;
      }
      try {
        Object value = deserialize(property.getBinary().getStream());
        if (value instanceof Object[]) {
          Object[] values = (Object[]) value;
          Object[] convertedValues = new Object[values.length];
          boolean converted = false;
          for (int i = 0; i < values.length; i++) {
            Object tmp = values[i];
            if (tmp instanceof com.asf.nextreports.engine.queryexec.IdName) {
              com.asf.nextreports.engine.queryexec.IdName oldIdName =
                  (com.asf.nextreports.engine.queryexec.IdName) tmp;
              IdName idName = new IdName();
              idName.setId(oldIdName.getId());
              idName.setName(oldIdName.getName());
              convertedValues[i] = idName;
              converted = true;
            } else {
              convertedValues[i] = tmp;
            }
          }

          if (converted) {
            ValueFactory valueFactory = node.getSession().getValueFactory();
            Binary binary =
                valueFactory.createBinary(new ByteArrayInputStream(serialize(convertedValues)));
            property.setValue(binary);
          }
        } else if (value instanceof com.asf.nextreports.engine.queryexec.IdName) {
          com.asf.nextreports.engine.queryexec.IdName oldIdName =
              (com.asf.nextreports.engine.queryexec.IdName) value;
          IdName idName = new IdName();
          idName.setId(oldIdName.getId());
          idName.setName(oldIdName.getName());

          ValueFactory valueFactory = node.getSession().getValueFactory();
          Binary binary = valueFactory.createBinary(new ByteArrayInputStream(serialize(idName)));
          property.setValue(binary);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    getTemplate().save();
  }