public MeasuredValueList getMeasuredValueListRest(
      MeasureDescriptor md, MeasuredValueFilter filter) throws MonitorException {

    // Find the data to create the URL
    String url;

    nodedirectory nd =
        db.get(
            nodedirectory.class,
            md.getMeasurementTypeId().substring(0, md.getMeasurementTypeId().indexOf(".measure")));

    VEEReplica rep;

    if (nd == null
        || (nd.getTipo() != nodedirectory.TYPE_REPLICA && nd.getTipo() != nodedirectory.TYPE_NIC))
      return new MeasuredValueList(md);

    String path;

    if (nd.getTipo() == nodedirectory.TYPE_REPLICA) {
      path = URICreation.getURIVEEReplica(md.getMeasurementTypeId());
      rep = db.get(VEEReplica.class, nd.getInternalNodeId());
    } else if (nd.getTipo() == nodedirectory.TYPE_NIC) {
      path = URICreation.getURIHwItem(md.getMeasurementTypeId());
      path = translateNetInfrastructureId(path, nd.getFqnString());
      rep =
          db.get(
              VEEReplica.class,
              nd.getFqnString().substring(0, md.getMeasurementTypeId().indexOf(".network")));
    } else {
      return new MeasuredValueList(md);
    }

    if (rep.getDeployedOn() == null) return new MeasuredValueList(md);
    else {
      url =
          "http://"
              + rep.getDeployedOn().getHost()
              + ":"
              + rep.getDeployedOn().getPort()
              + path
              + URICreation.MONITOR
              + "/"
              + md.getName()
              + URICreation.VALUES;

      // Get the measures
      return restClient.getReplicaMeasure(url, filter, md);
    }
  }
  public MeasuredValueList getMeasuredValueListBD(MeasureDescriptor md, MeasuredValueFilter filter)
      throws MonitorException {
    String id = md.getMeasurementTypeId();
    String element = id.substring(0, id.indexOf(URICreation.FQN_SEPARATOR_MEASURE) - 1);

    nodedirectory nd = db.get(nodedirectory.class, element);
    List<MeasuredValue> valueList;

    if ((md.getName().contains("netInput_") || md.getName().contains("netOutput_"))
        && nd.getTipo() != nodedirectory.TYPE_NIC) {
      valueList =
          db.getNetworkValues(
              nd,
              filter.getFrom(),
              filter.getTo(),
              filter.getSamples(),
              filter.getInterval(),
              md.getName(),
              md.getValueType());
    } else {
      valueList =
          db.getMeasureValues(
              nd,
              filter.getFrom(),
              filter.getTo(),
              filter.getSamples(),
              filter.getInterval(),
              md.getName(),
              md.getValueType());
    }

    MeasuredValueList mvl = new MeasuredValueList(md);

    for (MeasuredValue mv : valueList) {
      mvl.add(mv);
    }

    return mvl;
  }
  public MeasureDescriptor getGenericMeasureDescriptor(
      String orgName,
      String vdcName,
      List<String> vappNames,
      String measureId,
      String hwItem,
      String networkName)
      throws MonitorException {

    String[] elementHref = getElementAndHref(orgName, vdcName, vappNames, hwItem, networkName);
    System.out.println(elementHref[0]);

    nodedirectory nd = db.get(nodedirectory.class, elementHref[0]);

    if ((measureId.contains("netInput_") || measureId.contains("netOutput_"))
        && nd.getTipo() != nodedirectory.TYPE_NIC) {
      return new MeasureDescriptor(
          measureId,
          nd.getFqnString() + "." + URICreation.FQN_SEPARATOR_MEASURE + "." + measureId,
          "",
          DataTypesUtils.STANDARD_BANDWIDTH_UNIT_DEFAULT,
          "0",
          "0",
          "");
    } else if (measureId.equals("diskUsage")) {
      return db.getDiskMeasureDescriptor(nd);

    } else {
      MeasureDescriptor result = db.getMeasureDescriptors(nd, measureId);

      if (result == null) throw new MonitorException("Measure " + measureId + " not available.");

      result.setHref(elementHref[1]);

      return result;
    }
  }
  public MeasureDescriptorList getGenericMeasureDescriptorList(
      String orgName, String vdcName, List<String> vappNames, String item, String networkName)
      throws MonitorException {

    String[] elementHref = getElementAndHref(orgName, vdcName, vappNames, item, networkName);

    MeasureDescriptorList result = new MeasureDescriptorList(elementHref[1], "");
    System.out.println(result.getHref());
    nodedirectory nd = db.get(nodedirectory.class, elementHref[0]);

    if (nd == null) return result;

    List<MeasureDescriptor> descriptorList = db.getMeasureDescriptorsList(nd);

    for (MeasureDescriptor md : descriptorList) {
      md.setHref(elementHref[1] + md.getName());
      result.add(md);
    }

    if (nd.getTipo() == nodedirectory.TYPE_VDC) {
      VDC vdc = db.get(VDC.class, nd.getFqnString());

      for (Zone z : vdc.getZones())
        for (Network network : z.getNetworks()) {
          result.add(
              new MeasureDescriptor(
                  "netInput_" + network.getName(),
                  nd.getFqnString()
                      + "."
                      + URICreation.FQN_SEPARATOR_MEASURE
                      + "."
                      + "netInput_"
                      + network.getName(),
                  "",
                  DataTypesUtils.STANDARD_BANDWIDTH_UNIT_DEFAULT,
                  "0",
                  "0",
                  ""));
          result.add(
              new MeasureDescriptor(
                  "netOutput_" + network.getName(),
                  nd.getFqnString()
                      + "."
                      + URICreation.FQN_SEPARATOR_MEASURE
                      + "."
                      + "netOutput_"
                      + network.getName(),
                  "",
                  DataTypesUtils.STANDARD_BANDWIDTH_UNIT_DEFAULT,
                  "0",
                  "0",
                  ""));
        }

    } else if (nd.getTipo() == nodedirectory.TYPE_SERVICE) {

      ServiceApplication sap = db.getServiceApplication(nd.getFqnString());

      for (Network network : sap.getNetworks()) {
        result.add(
            new MeasureDescriptor(
                "netInput_" + network.getName(),
                nd.getFqnString()
                    + "."
                    + URICreation.FQN_SEPARATOR_MEASURE
                    + "."
                    + "netInput_"
                    + network.getName(),
                "",
                DataTypesUtils.STANDARD_BANDWIDTH_UNIT_DEFAULT,
                "0",
                "0",
                ""));
        result.add(
            new MeasureDescriptor(
                "netOutput_" + network.getName(),
                nd.getFqnString()
                    + "."
                    + URICreation.FQN_SEPARATOR_MEASURE
                    + "."
                    + "netOutput_"
                    + network.getName(),
                "",
                DataTypesUtils.STANDARD_BANDWIDTH_UNIT_DEFAULT,
                "0",
                "0",
                ""));
      }
    }

    return result;
  }