コード例 #1
0
ファイル: LoginToMSRSense.java プロジェクト: joheben/OpenIoT
  /**
   * Tries to delete a virtual sensor. Returns an integer for status.
   *
   * @param username username for sensorweb user account
   * @param password password for sensorweb user account
   * @param conf configuration of the virtual sensor
   * @return status of operation is integer. 0 for not deleted (already exists), 1 for deleted.
   * @throws java.rmi.RemoteException java.rmi.RemoteException
   */
  public static int delete_sensor(String username, String password, VSensorConfig conf)
      throws RemoteException {

    logger.warn("Deleting sensor " + conf.getName() + " from Sensormap...");
    gsn.msr.sensormap.sensorman.ServiceStub stub = new gsn.msr.sensormap.sensorman.ServiceStub();
    gsn.msr.sensormap.sensorman.ServiceStub.Guid passGUID = login_to_sensor_map(username, password);

    // create DeleteVectorSensor object
    gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor deleteVectorSensorParams =
        new gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor();
    deleteVectorSensorParams.setPassCode(passGUID);
    deleteVectorSensorParams.setPublisherName(username);
    deleteVectorSensorParams.setOriginalPublisherName(username);
    deleteVectorSensorParams.setSensorName(conf.getName());

    logger.warn("Calling DeleteVectorSensor with parameters:");
    logger.warn("...passCode: " + deleteVectorSensorParams.getPassCode());
    logger.warn("...PublisherName: " + deleteVectorSensorParams.getPublisherName());
    logger.warn("...OriginalPublisherName: " + deleteVectorSensorParams.getOriginalPublisherName());
    logger.warn("...SensorName: " + deleteVectorSensorParams.getSensorName());

    gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensorResponse output =
        stub.DeleteVectorSensor(deleteVectorSensorParams);
    String call_output = output.getDeleteVectorSensorResult();

    if (call_output.indexOf("OK") >= 0) {
      logger.warn(
          "Sensor " + conf.getName() + " deleted correctly. SensorMap says: " + call_output);
      return DELETE_SENSOR_OK;
    } else {
      logger.warn("Sensor " + conf.getName() + " not deleted. SensorMap says: " + call_output);
      return DELETE_SENSOR_ERROR_DOESNT_EXIST;
    }
  }
コード例 #2
0
ファイル: LoginToMSRSense.java プロジェクト: joheben/OpenIoT
  public static int register_sensor(
      String username, String password, VSensorConfig conf, String gsnURI)
      throws RemoteException, FileNotFoundException {

    gsn.msr.sensormap.sensorman.ServiceStub.Guid passGUID = login_to_sensor_map(username, password);
    HashMap<String, MetaData> output =
        MetaData.createMetaData(Main.getContainerConfig().getMsrMap().get("metadata"));

    logger.warn("Registering sensor " + conf.getName() + " on Sensormap...");

    gsn.msr.sensormap.sensorman.ServiceStub stub =
        new gsn.msr.sensormap.sensorman.ServiceStub(); // the
    // default
    // implementation
    // should
    // point
    // to
    // the
    // right
    // endpoint

    StringBuilder pComments = new StringBuilder();
    StringBuilder pNames = new StringBuilder();
    StringBuilder pMetadata = new StringBuilder();
    StringBuilder pTypes = new StringBuilder();
    String groupName = Main.getContainerConfig().getMsrMap().get("group-name");

    for (DataField df : conf.getOutputStructure()) {
      MetaData metaData = output.get(df.getName().toLowerCase().trim());
      String pType = null;
      String pUnit = "";

      if (metaData != null) {
        pTypes.append(metaData.getSensorType()).append("|");
        pType = metaData.getSensorType();
        pMetadata.append(metaData.getMetadata()).append("|");
        pComments.append(metaData.getComments()).append("|");
        pNames.append(metaData.getSensorName()).append("|");
        pUnit = metaData.getUnit();
      } else {
        pTypes.append(df.getName()).append("|");
        pNames.append(df.getName()).append("|");
        pType = df.getName();
      }
      if (!dataTypeCache.contains(pType)) {
        gsn.msr.sensormap.sensorman.ServiceStub.CreateSingularSensorType createType =
            new gsn.msr.sensormap.sensorman.ServiceStub.CreateSingularSensorType();
        createType.setPublisherName(username);
        createType.setPassCode(passGUID);
        createType.setName(pType);
        createType.setUnit(pUnit);
        createType.setDataType("scalar");
        createType.setIconUrl("");
        String result =
            stub.CreateSingularSensorType(createType).getCreateSingularSensorTypeResult();
        logger.info("Registering data type: " + pType + " , MSR's output: " + result);
        dataTypeCache.add(pType);
      }
    }

    gsn.msr.sensormap.userman.ServiceStub.AddGroup createGroup =
        new gsn.msr.sensormap.userman.ServiceStub.AddGroup();
    gsn.msr.sensormap.userman.ServiceStub login = new gsn.msr.sensormap.userman.ServiceStub();
    createGroup.setGrpName(conf.getName());
    if (groupName != null && groupName.trim().length() > 0) createGroup.setParentGroup(groupName);
    createGroup.setAdmin(username);
    String call_output = login.AddGroup(createGroup).getAddGroupResult();
    logger.info(
        "Creating a group called : "
            + conf.getName()
            + " With Parent: "
            + groupName
            + " MSR: "
            + call_output);

    gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor deleteVSensorParam =
        new gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor();
    deleteVSensorParam.setOriginalPublisherName(username);
    deleteVSensorParam.setPublisherName(username);
    deleteVSensorParam.setPassCode(passGUID);
    deleteVSensorParam.setSensorName(conf.getName());
    deleteVSensorParam.setSensorType("GSN-" + conf.getName());

    call_output = stub.DeleteVectorSensor(deleteVSensorParam).getDeleteVectorSensorResult();
    logger.info("Unregister: " + conf.getName() + " - MSR: " + call_output);

    gsn.msr.sensormap.sensorman.ServiceStub.RegisterCompositeSensor registerVectorSensorParams =
        new gsn.msr.sensormap.sensorman.ServiceStub.RegisterCompositeSensor();

    registerVectorSensorParams.setPublisherName(username);
    registerVectorSensorParams.setPassCode(passGUID);
    registerVectorSensorParams.setVectorSensorName(conf.getName());
    registerVectorSensorParams.setWsURL(gsnURI + "services/Service?wsdl");
    registerVectorSensorParams.setAlt(conf.getAltitude().toString());
    registerVectorSensorParams.setLat(conf.getLatitude().toString());
    registerVectorSensorParams.setLon(conf.getLongitude().toString());
    registerVectorSensorParams.setDesc(conf.getDescription());
    registerVectorSensorParams.setVectorSensorType("GSN-" + conf.getName());
    registerVectorSensorParams.setParamTypes(pTypes.toString());
    registerVectorSensorParams.setParamComments(pComments.toString());
    registerVectorSensorParams.setParamMetaData(pMetadata.toString());
    registerVectorSensorParams.setParamNames(pNames.toString());
    registerVectorSensorParams.setAccessControl("protected");
    registerVectorSensorParams.setDataType("vector");
    registerVectorSensorParams.setIcon("image/CImg/weather_tower.gif");
    registerVectorSensorParams.setGroupName(conf.getName());

    call_output =
        stub.RegisterCompositeSensor(registerVectorSensorParams).getRegisterCompositeSensorResult();

    if (call_output.indexOf("OK") >= 0) {
      logger.warn(
          "Sensor " + conf.getName() + " registered correctly. SensorMap says: " + call_output);
      return REGISTER_SENSOR_OK_CREATED_NEW;
    }

    if (call_output.indexOf(
            "Error: Sensor with the same publisher name and sensor name already exists")
        >= 0) {
      logger.warn(
          "Sensor "
              + conf.getName()
              + " not registered (already exists). SensorMap says: "
              + call_output);
      return REGISTER_SENSOR_ERROR_ALREADY_EXISTS;
    }

    logger.warn("Sensor " + conf.getName() + " not registered. SensorMap says: " + call_output);
    return REGISTER_SENSOR_ERROR_NOT_CREATED;
  }