/**
   * set a node attribute
   *
   * @param objectID unique ID of the JEVisObject on the Server.
   * @param attributeName unique name of the Attribute under this Object
   * @param value and its value
   */
  public static void writeToJEVis(long objectID, String attributeName, Object value) {
    try {
      // Check if the connection is still alive. An JEVisException will be
      // thrown if you use one of the functions and the connection is lost
      if (jevis.isConnectionAlive()) {

        // Get the JEVisObject with the given ID. You can get the uniqe
        // ID with the help of JEConfig.
        if (jevis.getObject(objectID) != null) {
          JEVisObject myObject = jevis.getObject(objectID);
          Logger.getLogger(WiotechStructureCreator.class.getName())
              .log(Level.INFO, "JEVisObject: " + myObject);

          // Get the JEVisAttribute by its unique identifier.
          if (myObject.getAttribute(attributeName) != null) {
            JEVisAttribute attribute = myObject.getAttribute(attributeName);
            Logger.getLogger(WiotechStructureCreator.class.getName())
                .log(Level.INFO, "JEVisAttribute: " + attribute);

            DateTime timestamp = DateTime.now();

            // Now we let the Attribute creates an JEVisSample,an JEVisSample allways need an
            // Timestamp and an value.
            JEVisSample newSample =
                attribute.buildSample(timestamp, value, "This is an note, imported via SysReader");
            // Until now we created the sample only localy and we have to commit it to the JEVis
            // Server.
            newSample.commit();

            // TODO: we need an example for attribute.addSamples(listOfSamples); function. This
            // function allows to commit a bunch of sample at once
          } else {
            Logger.getLogger(WiotechStructureCreator.class.getName())
                .log(Level.SEVERE, "Could not found the Attribute with the name:" + attributeName);
          }
        } else {
          Logger.getLogger(WiotechStructureCreator.class.getName())
              .log(Level.SEVERE, "Could not found the Object with the id:" + objectID);
        }
      } else {
        Logger.getLogger(WiotechStructureCreator.class.getName())
            .log(Level.SEVERE, "Connection to the JEVisServer is not alive");
        // TODO: the programm could now retry to connect,
        // We dont have to do the isConnectionAlive() but use the JEVisException to handle this
        // problem.
      }
    } catch (JEVisException ex) {
      Logger.getLogger(WiotechStructureCreator.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  /**
   * Creates the needed JEVis structure
   *
   * @param buildingId building node id, where the structure has to be created
   *     <p>TODO Enable mysql server TODO Add units
   */
  public void createStructure(long buildingId) {

    ObjectAndBoolean dsd =
        createObjectCheckNameExistance(
            buildingId, "Data Source Directory", "Data Source Directory");

    ObjectAndBoolean mysqlServer =
        createObjectCheckNameExistance(
            dsd.getJEVisObject().getID(), "MySQL Server", "MySQL Server");

    if (mysqlServer.isNew) {
      long id = mysqlServer.getJEVisObject().getID();
      writeToJEVis(id, "Schema", _schema);
      writeToJEVis(id, "User", _dbUser);
      writeToJEVis(id, "Port", _port);
      writeToJEVis(id, "Host", _host);
      writeToJEVis(id, "Password", _dbPW);
      writeToJEVis(id, "Enabled", true);
    }

    ObjectAndBoolean dataDirectory =
        createObjectCheckNameExistance(buildingId, "Data Directory", "Data Directory");

    for (Sensor sensor : _result) {
      ObjectAndBoolean sqlChannelDir =
          createObjectCheckNameExistance(
              mysqlServer.getJEVisObject().getID(),
              "SQL Channel Directory",
              sensor.getName() + "_" + sensor.getSymbol());
      ObjectAndBoolean channel =
          createObjectCheckNameExistance(
              sqlChannelDir.getJEVisObject().getID(), "SQL Channel", "SQL Channel");
      if (channel.isNew) {
        long id = channel.getJEVisObject().getID();

        writeToJEVis(id, "Column Timestamp", "time");
        writeToJEVis(id, "Column Value", "value");
        writeToJEVis(id, "Table", sensor.getTable());
        writeToJEVis(id, "Timestamp Format", "yyyy-MM-dd HH:mm:ss.s");
      }

      ObjectAndBoolean sqlDPD =
          createObjectCheckNameExistance(
              channel.getJEVisObject().getID(), "SQL Data Point Directory", "DPD");
      ObjectAndBoolean sqlDP =
          createObjectCheckNameExistance(sqlDPD.getJEVisObject().getID(), "SQL Data Point", "DP");
      ObjectAndBoolean device =
          createObjectCheckNameExistance(
              dataDirectory.getJEVisObject().getID(), "Device", sensor.getName());
      if (device.isNew) {
        long id = device.getJEVisObject().getID();
        writeToJEVis(id, "MAC", sensor.getName());
      }
      ObjectAndBoolean data =
          createObjectCheckNameExistance(
              device.getJEVisObject().getID(), "Data", sensor.getSymbol());

      try {
        JEVisAttribute attributeValue = data.getJEVisObject().getAttribute("Value");
        attributeValue.setDisplayUnit(
            new JEVisUnitImp(Unit.valueOf(sensor.getUnit()), "", JEVisUnit.Prefix.NONE));
        attributeValue.setInputUnit(
            new JEVisUnitImp(Unit.valueOf(sensor.getUnit()), "", JEVisUnit.Prefix.NONE));
        attributeValue.commit();
      } catch (JEVisException ex) {
        Logger.getLogger(WiotechStructureCreator.class.getName()).log(Level.SEVERE, null, ex);
      }

      if (data.isNew) {
        writeToJEVis(
            sqlDP.getJEVisObject().getID(), "Target", data.getJEVisObject().getID().toString());
      }
    }
  }