Ejemplo n.º 1
0
  private void checkStatusUpdate(
      Exchange exchange, List<Message> messageList, TelemetryObject incomingMessage) {
    // No reason to check polling, if nothing to poll
    if (PollStoreSetValues.getRequiredParameterValueDataStore().size() == 0) return;

    String dataStoreKey;
    if (commandsBidiMap.getKey(incomingMessage.getName()) == null) return;

    dataStoreKey = (String) commandsBidiMap.getKey(incomingMessage.getName());
    boolean statusUpdateParametersCorrect = true;
    /*
     * Int starts from 1 because first parameter is always name and doesnt
     * contain value.
     */
    for (int i = 1; i < incomingMessage.getParams().size() - 1; i++) {

      try {
        if (commandsThatReturnIntegrer.contains(incomingMessage.getName())) {
          statusUpdateParametersCorrect =
              checkIntegerParameterValue(
                  exchange,
                  messageList,
                  incomingMessage,
                  dataStoreKey,
                  statusUpdateParametersCorrect,
                  i);
        } else {
          statusUpdateParametersCorrect =
              checkBigDecimalParameterValue(
                  exchange,
                  messageList,
                  incomingMessage,
                  dataStoreKey,
                  statusUpdateParametersCorrect,
                  i);
        }
      } catch (NumberFormatException e) {
        statusUpdateParametersCorrect =
            checkStringParameterValue(
                exchange,
                messageList,
                incomingMessage,
                dataStoreKey,
                statusUpdateParametersCorrect,
                i);
      }
      if (statusUpdateParametersCorrect == false) {
        break;
      }
    }
    if (statusUpdateParametersCorrect == true) {
      PollStoreSetValues.getRequiredParameterValueDataStore().remove(dataStoreKey);
    }
  }
Ejemplo n.º 2
0
  private void checkPollingMessageType(
      Exchange exchange, List<Message> messageList, TelemetryObject incomingMessage) {

    if (exchange.getIn().getHeader(JMSConstants.HEADER_POLLING) != null) {
      if (exchange
          .getIn()
          .getHeader(JMSConstants.HEADER_POLLING)
          .equals(JMSConstants.POLL_SET_COMMAND)) {

        if (incomingMessage
            .getParameter(JMSConstants.GS_DEVICE_END_MESSAGE)
            .getValue()
            .equals("0")) {
          createPollingMessage(exchange, messageList, incomingMessage);
        } else {
          PollStoreSetValues.getRequiredParameterValueDataStore().remove(incomingMessage.getName());
        }
      }
      if (exchange
          .getIn()
          .getHeader(JMSConstants.HEADER_POLLING)
          .equals(JMSConstants.POLL_GET_COMMAND)) {
        if (incomingMessage
            .getParameter(JMSConstants.GS_DEVICE_END_MESSAGE)
            .getValue()
            .equals("0")) {
          checkStatusUpdate(exchange, messageList, incomingMessage);
        } else {
          PollStoreSetValues.getRequiredParameterValueDataStore()
              .remove(commandsBidiMap.getKey(incomingMessage.getName()));
        }
      }
    }
  }
Ejemplo n.º 3
0
 /** Get the object associated with the ID in the session */
 protected Object getSessionIdObject(String id) {
   HttpSession session = getSession();
   synchronized (session) {
     BidiMap map = (BidiMap) session.getAttribute(SESSION_KEY_OBJ_MAP);
     if (map == null) {
       return null;
     }
     return map.getKey(id);
   }
 }
Ejemplo n.º 4
0
  /**
   * Reads the prediction file (each line is a integer) and converts them into original outcome
   * labels using the mapping provided by the bi-directional map
   *
   * @param predictionsFile predictions from classifier
   * @param labelsToIntegersMapping mapping outcomeLabel:integer
   * @return list of outcome labels
   * @throws IOException
   */
  public static List<String> extractOutcomeLabelsFromPredictions(
      File predictionsFile, BidiMap labelsToIntegersMapping) throws IOException {
    List<String> result = new ArrayList<>();

    for (String line : FileUtils.readLines(predictionsFile)) {
      Integer intLabel = Integer.valueOf(line);

      String outcomeLabel = (String) labelsToIntegersMapping.getKey(intLabel);

      result.add(outcomeLabel);
    }

    return result;
  }
Ejemplo n.º 5
0
  /**
   * Saves the feature mapping to readable format, each line is a feature id and feature name,
   * sorted by feature id
   *
   * @param mapping mapping (name:id)
   * @param outputFile output file
   * @throws IOException
   */
  public static void saveMappingTextFormat(BidiMap mapping, File outputFile) throws IOException {
    PrintWriter pw = new PrintWriter(new FileOutputStream(outputFile));

    // sort values (feature indexes)
    @SuppressWarnings("unchecked")
    SortedSet<Object> featureIndexes = new TreeSet<Object>(mapping.values());

    for (Object featureIndex : featureIndexes) {
      pw.printf(
          Locale.ENGLISH, "%5d %s%n", (int) featureIndex, mapping.getKey(featureIndex).toString());
    }

    IOUtils.closeQuietly(pw);
  }
Ejemplo n.º 6
0
 public static int getErrorCode(String errorMsg) {
   return Integer.parseInt(error.getKey(errorMsg).toString());
 }
Ejemplo n.º 7
0
 /**
  * Retrieves equivalent wrapper class for the given primitive type.
  *
  * @param clazz primitive type
  * @return equivalent wrapper class
  */
 public static Class<?> getWrapperForPrimitive(Class<?> clazz) {
   return (Class<?>) PRIMITIVE_TYPE_MAP.getKey(clazz);
 }