示例#1
0
  @Override
  public Object parseString(String stringValue) {
    if (encoding == Encoding.string) return stringValue;

    if (sizeInBits > 32) {
      return Long.decode(stringValue);
    } else {
      return Long.decode(stringValue).intValue();
    }
  }
示例#2
0
  /** @param args */
  public static void main(String[] args) throws Exception {
    //    System.out.println(args[0]+" "+args[1]+" "+args[2]+" "+args[3]);
    String hex = args[0];
    InetAddress a = InetAddress.getByName(args[1]);
    int startPort = Integer.decode(args[2]).intValue();
    int bootPort = Integer.decode(args[3]).intValue();
    InetSocketAddress addr = new InetSocketAddress(a, startPort);
    InetSocketAddress bootaddress = new InetSocketAddress(a, bootPort);
    long startTime = Long.decode(args[4]).longValue();
    long randSeed = Long.decode(args[5]).longValue();

    replayNode(Id.build(hex), addr, bootaddress, startTime, randSeed);
  }
示例#3
0
 Term createIntegerOrLong(String x) throws ParseException {
   try {
     Term retval = null;
     if (x.endsWith("L") || x.endsWith("l")) {
       try {
         retval =
             TermWare.getInstance()
                 .getTermFactory()
                 .createLong(Long.decode(x.substring(0, x.length() - 1)));
       } catch (NumberFormatException ex) {
         // it can be just too big, becouse literals can be unsigned, while decode does not handle
         // unsogned,
         //  bigger then MAX
         // Here we will handle one case, which exists in JDK sources. (java/lang/Long.java)
         if (x.length() > 2) {
           char last = x.charAt(x.length() - 2);
           long l = Long.decode(x.substring(0, x.length() - 2));
           char x0 = x.charAt(0);
           char x1 = x.charAt(1);
           if (x0 == '0') {
             if (x1 == 'x' || x1 == 'X') {
               // hex
               int l1 = Character.digit(last, 16);
               l = ((l << 8) + l1);
             } else {
               // oct
               int l1 = Character.digit(last, 8);
               l = ((l << 4) + l1);
             }
           }
           retval = TermWare.getInstance().getTermFactory().createLong(l);
         } else {
           throw ex;
         }
       }
     } else {
       long l = Long.decode(x);
       retval = TermWare.getInstance().getTermFactory().createInt((int) l);
     }
     return retval;
   } catch (NumberFormatException ex) {
     throw new ParseException(
         "Can't read IntegerLiteral "
             + ex.getMessage()
             + "(s="
             + x
             + ") "
             + " in file "
             + inFname);
   }
 }
 public static Long getLong(MetricsKeys key, StringMap map) {
   Long value = 0L;
   if (map.containsKey(key.name()) && !map.get(key.name()).equals("")) {
     value = Long.decode(map.get(key.name()));
   }
   return value;
 }
  @Nullable
  public static Number parseNumber(@NotNull String text, @NotNull Class targetClass) {
    try {
      String trimmed = text.trim();

      if (targetClass.equals(Byte.class) || targetClass.equals(byte.class)) {
        return Byte.decode(trimmed);
      } else if (targetClass.equals(Short.class) || targetClass.equals(short.class)) {
        return Short.decode(trimmed);
      } else if (targetClass.equals(Integer.class) || targetClass.equals(int.class)) {
        return Integer.decode(trimmed);
      } else if (targetClass.equals(Long.class) || targetClass.equals(long.class)) {
        return Long.decode(trimmed);
      } else if (targetClass.equals(BigInteger.class)) {
        return decodeBigInteger(trimmed);
      } else if (targetClass.equals(Float.class) || targetClass.equals(float.class)) {
        return Float.valueOf(trimmed);
      } else if (targetClass.equals(Double.class) || targetClass.equals(double.class)) {
        return Double.valueOf(trimmed);
      } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
        return new BigDecimal(trimmed);
      }
    } catch (NumberFormatException ex) {
      return null;
    }
    return null;
  }
示例#6
0
  public PacketInfo(
      String id, String name, boolean key, boolean serverList, Class<PacketReader> reader) {
    _id = id.toUpperCase();

    String[] sl = hexArray();
    _opcode = new Map.Entry[sl.length];
    for (int i = 0; i < _opcode.length; i++) {
      Type t = getType(sl[i]);
      long v = Long.decode("0x" + sl[i]);

      _opcode[i] = new AbstractMap.SimpleEntry<Type, Long>(t, v);
    }

    _name = name;
    _isKey = key;
    _serverList = serverList;

    if (reader != null) {
      try {
        _packetReader = reader.newInstance();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    _format = new Format(this);
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    Long feedbackId = Long.decode(BeanUtils.getProperty(form, "id"));
    String commentedited = BeanUtils.getProperty(form, "commentedited");
    String makepublic = BeanUtils.getProperty(form, "makepublic");
    boolean makepublicBool = "true".equals(makepublic);

    Feedback feedback = LegacySpringUtils.getFeedbackManager().get(feedbackId);

    feedback.setCommentedited(commentedited);
    feedback.setMakepublic(makepublicBool);

    LegacySpringUtils.getFeedbackManager().save(feedback);

    List feedbacks = LegacySpringUtils.getFeedbackManager().get(feedback.getUnitcode());

    request.setAttribute("feedbacks", feedbacks);

    return LogonUtils.logonChecks(mapping, request);
  }
 private long safeParse(String hex) {
   try {
     return Long.decode("0x" + hex);
   } catch (NumberFormatException notNumber) {
     return 0;
   }
 }
  /**
   * test the data against a long
   *
   * @param data the data we are testing
   * @return if we have a match
   */
  private boolean testLong(final ByteBuffer data) {

    long val = 0;
    final String test = new String(this.match.getTest().array());
    final char comparator = this.match.getComparator();
    final long bitmask = this.match.getBitmask();

    val = byteArrayToLong(data);

    // apply bitmask before the comparison
    val = val & bitmask;

    final long tst = Long.decode(test).longValue();

    switch (comparator) {
      case '=':
        return val == tst;

      case '!':
        return val != tst;

      case '>':
        return val > tst;

      case '<':
        return val < tst;

      default:
        return false;
    }
  }
示例#10
0
  /**
   * Creates a <tt>UUID</tt> from the string standard representation as described in the {@link
   * #toString} method.
   *
   * @param name a string that specifies a <tt>UUID</tt>.
   * @return a <tt>UUID</tt> with the specified value.
   * @throws IllegalArgumentException if name does not conform to the string representation as
   *     described in {@link #toString}.
   */
  public static UUID fromString(String name) {
    String[] components = name.split("-");
    if (components.length != 5) throw new IllegalArgumentException("Invalid UUID string: " + name);
    for (int i = 0; i < 5; i++) components[i] = "0x" + components[i];

    long mostSigBits = Long.decode(components[0]).longValue();
    mostSigBits <<= 16;
    mostSigBits |= Long.decode(components[1]).longValue();
    mostSigBits <<= 16;
    mostSigBits |= Long.decode(components[2]).longValue();

    long leastSigBits = Long.decode(components[3]).longValue();
    leastSigBits <<= 48;
    leastSigBits |= Long.decode(components[4]).longValue();

    return new UUID(mostSigBits, leastSigBits);
  }
示例#11
0
 public static boolean isGestureActive(int gesture) {
   try {
     return (Long.decode(Utils.readFile(GESTURE_CRTL)) & GESTURE_HEX_VALUES[gesture]) > 0;
   } catch (NumberFormatException e) {
     e.printStackTrace();
     return false;
   }
 }
  /**
   * Convert a string to a certain type, parsing the string if required
   *
   * @param context If creating a URL, use this as the URL's context
   * @param string String to convert
   * @param type Type to convert to
   * @return Converted string, or null if failed
   */
  protected static Object convertStringToType(URL context, String string, Class<?> type) {
    try {
      if (type.isAssignableFrom(String.class)) {
        return string;
      } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) {
        return Double.valueOf(string);
      } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) {
        return Integer.decode(string);
      } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) {
        return Float.valueOf(string);
      } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) {
        return Long.decode(string);
      } else if (type.isAssignableFrom(Character.class) || type.isAssignableFrom(char.class)) {
        return string.charAt(0);
      } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) {
        return Byte.decode(string);
      } else if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
        return Boolean.valueOf(string);
      } else if (type.isAssignableFrom(URL.class)) {
        try {
          return new URL(context, string);
        } catch (MalformedURLException e) {
        }
      } else if (type.isAssignableFrom(File.class)) {
        return new File(string);
      } else if (type.isAssignableFrom(Color.class)) {
        int[] ints = splitInts(string);
        if (ints.length == 1) return new Color(ints[0]);
        else if (ints.length == 3) return new Color(ints[0], ints[1], ints[2]);
        else if (ints.length == 4) return new Color(ints[0], ints[1], ints[2], ints[3]);
      } else if (type.isAssignableFrom(Dimension.class)) {
        int[] ints = splitInts(string);
        if (ints.length == 1) return new Dimension(ints[0], ints[0]);
        else if (ints.length == 2) return new Dimension(ints[0], ints[1]);
      } else if (type.isAssignableFrom(Point.class)) {
        int[] ints = splitInts(string);
        if (ints.length == 1) return new Point(ints[0], ints[0]);
        else if (ints.length == 2) return new Point(ints[0], ints[1]);
      } else if (type.isAssignableFrom(Font.class)) {
        return Font.decode(string);
      } else if (type.isAssignableFrom(Material.class)) {
        Color color = null;
        int[] ints = splitInts(string);
        if (ints.length == 1) color = new Color(ints[0]);
        else if (ints.length == 3) color = new Color(ints[0], ints[1], ints[2]);
        else if (ints.length == 4) color = new Color(ints[0], ints[1], ints[2], ints[3]);

        if (color != null) return new Material(color);
      } else if (type.isAssignableFrom(Insets.class)) {
        int[] ints = splitInts(string);
        if (ints.length == 4) return new Insets(ints[0], ints[1], ints[2], ints[3]);
      }
    } catch (Exception e) {

    }
    return null;
  }
示例#13
0
  public static void main(String[] args) throws IOException {
    final GenericOptionsParser parser;
    try {
      parser = new GenericOptionsParser(args);

      // This should be IOException but Hadoop 0.20.2 doesn't throw it...
    } catch (Exception e) {
      System.err.printf("Error in Hadoop arguments: %s\n", e.getMessage());
      System.exit(1);

      // Hooray for javac
      return;
    }

    args = parser.getRemainingArgs();
    // final Configuration conf = ContextUtil.getConfiguration(parser);
    final Configuration conf = parser.getConfiguration();

    long beg = 0;

    if (args.length < 2 || args.length > 3) {
      System.err.println("Usage: BAMSplitGuesser path-or-uri header-path-or-uri [beg]");
      System.exit(2);
    }

    try {
      if (args.length > 2) beg = Long.decode(args[2]);
    } catch (NumberFormatException e) {
      System.err.println("Invalid beg offset.");
      if (e.getMessage() != null) System.err.println(e.getMessage());
      System.exit(2);
    }

    SeekableStream ss = WrapSeekable.openPath(conf, new Path(args[0]));
    SeekableStream hs = WrapSeekable.openPath(conf, new Path(args[1]));

    final long end = beg + MAX_BYTES_READ;

    System.out.printf(
        "Will look for a BGZF block within: [%1$#x,%2$#x) = [%1$d,%2$d)\n"
            + "Will then verify BAM data within:  [%1$#x,%3$#x) = [%1$d,%3$d)\n",
        beg, beg + 0xffff, end);

    final long g = new BAMSplitGuesser(ss, hs, conf).guessNextBAMRecordStart(beg, end);

    ss.close();

    if (g == end) {
      System.out.println("Didn't find any acceptable BAM record in any BGZF block.");
      System.exit(1);
    }

    System.out.printf(
        "Accepted BGZF block at offset %1$#x (%1$d).\n"
            + "Accepted BAM record at offset %2$#x (%2$d) therein.\n",
        g >> 16, g & 0xffff);
  }
 /**
  * checks if an entity is shared with a user
  *
  * @param user the user to check
  * @param eid id of the entity
  * @return true if entity is shared with the user, false otherwise
  * @throws WebApiException exception thrown by social engine
  */
 public boolean checkPermission(User user, String eid) throws WebApiException {
   if (eid != null) {
     return SemanticHelper.isEntitySharedWithUser(
         socialClient, Long.decode(eid), Long.valueOf(user.getSocialId()));
   } else {
     logger.info("Try to check permission of null entity resource");
     return false;
   }
 }
  @Override
  public boolean setOperations(String[] lineRay, long currentLineNumber) {
    this.lineRay = lineRay;
    this.currentLineNumber = currentLineNumber;

    if (validate()) {
      // extract all the required fields from the row/line
      String clientAccountId =
          FieldExtractor.getFieldValue(lineRay, FieldExtractor.ClientAccountId);
      String campaignId = FieldExtractor.getFieldValue(lineRay, FieldExtractor.CampaignId);
      String advertisingChannelType =
          FieldExtractor.getFieldValue(lineRay, FieldExtractor.ChannelType);
      String googleSearch = FieldExtractor.getFieldValue(lineRay, FieldExtractor.GoogleSearch);
      String searchNetwork = FieldExtractor.getFieldValue(lineRay, FieldExtractor.SearchNetwork);
      String contentNetwork = FieldExtractor.getFieldValue(lineRay, FieldExtractor.ContentNetwork);
      String partnerSearchNetwork =
          FieldExtractor.getFieldValue(lineRay, FieldExtractor.PartnerSearchNetwork);
      String displaySelect = FieldExtractor.getFieldValue(lineRay, FieldExtractor.DisplaySelect);

      try {

        lineProcessor.awapi.addSession(clientAccountId);
        Campaign campaign = new Campaign();
        campaign.setId(Long.decode(campaignId));
        campaign.setAdvertisingChannelType(
            AdvertisingChannelType.fromString(advertisingChannelType));
        // Set the campaign network options to Search and Search Network.
        NetworkSetting networkSetting = new NetworkSetting();
        networkSetting.setTargetGoogleSearch(Boolean.valueOf(googleSearch));
        networkSetting.setTargetSearchNetwork(Boolean.valueOf(searchNetwork));
        networkSetting.setTargetContentNetwork(Boolean.valueOf(contentNetwork));
        networkSetting.setTargetPartnerSearchNetwork(Boolean.valueOf(partnerSearchNetwork));
        campaign.setNetworkSetting(networkSetting);
        if (displaySelect.equalsIgnoreCase("TRUE")) {
          campaign.setDisplaySelect(true);
        } else if (displaySelect.equalsIgnoreCase("FALSE")) {
          campaign.setDisplaySelect(false);
        }

        // Create operations.
        CampaignOperation operation = new CampaignOperation();
        operation.setOperand(campaign);
        operation.setOperator(Operator.SET);

        operations[operationsIterator++] = operation;

        return true;

      } catch (Exception generalException) {
        // catch general failures...
        reportError(campaignId, generalException);
        return false;
      }
    } else {
      return false;
    }
  }
示例#16
0
  @Test
  public void testToStringArray() {
    SearchResult res = new SearchResult(Long.decode("0x0F0F0F0F"), 12);
    String[] resToString = res.toStringArray();

    System.out.println("Address: " + resToString[0] + ";\tValue: " + resToString[1]);

    Assert.assertEquals(resToString[0], "F0F0F0F");
    Assert.assertEquals(resToString[1], "12");
  }
示例#17
0
  /**
   * Convert address and data to an Avalon-ST packet
   *
   * @param transaction Transaction code
   * @param address Avalon-ST address
   * @param data Avalon-ST data
   * @param byteSize read/write data byte size
   * @return Avalon-ST packet
   * @throws Exception
   */
  public byte[] createPacket(byte transaction, String address, String data, int byteSize)
      throws Exception {

    ///////////////////////////////////////////////////
    // Converts int Address to byte array Address
    ///////////////////////////////////////////////////
    byte[] bAddress = new byte[4];
    long lAddress;
    lAddress = Long.decode("0x" + address).longValue();

    bAddress[0] = (byte) ((byte) 0xff & (lAddress >> 8 * 3));
    bAddress[1] = (byte) ((byte) 0xff & (lAddress >> 8 * 2));
    bAddress[2] = (byte) ((byte) 0xff & (lAddress >> 8 * 1));
    bAddress[3] = (byte) ((byte) 0xff & (lAddress));
    ///////////////////////////////////////////////////

    ///////////////////////////////////////////////////
    // Converts int Data to byte Data
    ///////////////////////////////////////////////////
    if (transaction == TRAN_WRITE || transaction == TRAN_WRITE_INC_ADDR) {
      if (data.length() == 0) {
        byte[] noData = new byte[1];
        noData[0] = 0;
        return noData;
      }

      int byteLength = (data.length() + 1) / 2;
      byte[] bData = new byte[byteLength];
      long lData;
      lData = Long.decode("0x" + data).longValue();
      for (int i = 0; i < byteLength; i++) {
        bData[i] = (byte) ((byte) 0xff & (lData >> 8 * i));
      }
      return createPacket(transaction, bAddress, bData, bData.length);
    } else {
      byte[] bData = new byte[1];
      bData[0] = 0;
      return createPacket(transaction, bAddress, bData, byteSize);
    }
    ///////////////////////////////////////////////////

  }
示例#18
0
  protected static Object convert(String typeName, String value) throws IllegalArgumentException {
    if ("null".equals(value)) {
      return null;
    }

    Class<?> type = toClass(typeName);

    if (type == null) {
      throw new IllegalArgumentException(
          String.format("Unsupported parameter %s", toParameter(null)));
    }

    if ((type.isAssignableFrom(Boolean.class)) || (type == Boolean.TYPE)) {
      return Boolean.valueOf(value);
    }

    if ((type.isAssignableFrom(Byte.class)) || (type == Boolean.TYPE)) {
      return Byte.decode(value);
    }

    if ((type.isAssignableFrom(Short.class)) || (type == Short.TYPE)) {
      return Short.decode(value);
    }

    if ((type.isAssignableFrom(Integer.class)) || (type == Integer.TYPE)) {
      return Integer.decode(value);
    }

    if ((type.isAssignableFrom(Long.class)) || (type == Long.TYPE)) {
      return Long.decode(value);
    }

    if ((type.isAssignableFrom(Float.class)) || (type == Float.TYPE)) {
      return Float.valueOf(value);
    }

    if ((type.isAssignableFrom(Double.class)) || (type == Double.TYPE)) {
      return Double.valueOf(value);
    }

    if ((type.isAssignableFrom(Character.class)) || (type == Character.TYPE)) {
      if (value.length() != 1) {
        throw new IllegalArgumentException(String.format("Invalid character: %s", value));
      }
      return new Character(value.charAt(0));
    }

    if (type.isAssignableFrom(String.class)) {
      return value;
    }

    throw new IllegalArgumentException(
        String.format("Unsupported parameter %s", toParameter(type)));
  }
示例#19
0
 private static int convertInt(String rawValue) {
   try {
     // Decode into long, because there are some large hex values in the android resource files
     // (e.g. config_notificationsBatteryLowARGB = 0xFFFF0000 in sdk 14).
     // Integer.decode() does not support large, i.e. negative values in hex numbers.
     // try parsing decimal number
     return (int) Long.parseLong(rawValue);
   } catch (NumberFormatException nfe) {
     // try parsing hex number
     return Long.decode(rawValue).intValue();
   }
 }
示例#20
0
 /**
  * Gets a long from an attribute in a stream.
  *
  * @param attributeName The attribute name.
  * @param defaultValue The default value.
  * @return The long attribute value, or the default value if none found.
  */
 public long getAttribute(String attributeName, long defaultValue) {
   final String attrib = getParent().getAttributeValue(null, attributeName);
   long result = defaultValue;
   if (attrib != null) {
     try {
       result = Long.decode(attrib);
     } catch (NumberFormatException e) {
       logger.warning(attributeName + " is not a long: " + attrib);
     }
   }
   return result;
 }
示例#21
0
 public static ThreadInfo getThreadInfo(String idToken) {
   ThreadInfo tinfo = null;
   if (idToken.startsWith("t@")) {
     idToken = idToken.substring(2);
   }
   try {
     long threadId = Long.decode(idToken);
     tinfo = getThreadInfo(threadId);
   } catch (NumberFormatException e) {
     tinfo = null;
   }
   return tinfo;
 }
  /**
   * Publishes a message to qpid that describes what action a user has just performed on a task.
   * These actions may be either TaskTaken or TaskCompleted. This calls checkInitialized to see if
   * there is a valid connection to qpid.
   *
   * @param task the task that has been acted upon
   * @param exchangeName the exchange name for messaging
   * @param eventName the event that correlates with the action
   * @param taskId the id of the task that was acted upon
   */
  public void amqpTaskPublish(Task task, String exchangeName, String eventName, String taskId) {
    String info = "";
    if (checkInitialized()) {
      if (eventName.equals("TaskTaken")) {

        try {
          info =
              "eventType="
                  + eventName
                  + ";"
                  + "processID="
                  + task.getProcessInstanceId()
                  + ";"
                  + "taskID="
                  + task.getId()
                  + ";"
                  + "assignee="
                  + task.getAssignee()
                  + ";";
        } catch (Exception e) {
          log.debug(e.getMessage());
        }
      } else if (eventName.equals("TaskCompleted")) {
        try {
          org.jbpm.task.Task ht = taskRepo.findById(Long.decode(taskId));
          String processName = ht.getTaskData().getProcessId();
          String processId = Long.toString(ht.getTaskData().getProcessInstanceId());
          String assignee = ht.getTaskData().getActualOwner().getId();
          info =
              "eventType="
                  + eventName
                  + ";"
                  + "processID="
                  + processName
                  + "."
                  + processId
                  + ";"
                  + "taskID="
                  + taskId
                  + ";"
                  + "assignee="
                  + assignee
                  + ";";
        } catch (Exception e) {
          log.debug(e.getMessage());
        }
      }
      sendMessage(info, exchangeName);
    }
  }
 public String getNewSessionAlias(HttpServletRequest request) {
   Set<String> sessionAliases = getSessionIds(request).keySet();
   if (sessionAliases.isEmpty()) {
     return DEFAULT_ALIAS;
   }
   long lastAlias = Long.decode(DEFAULT_ALIAS);
   for (String alias : sessionAliases) {
     long selectedAlias = safeParse(alias);
     if (selectedAlias > lastAlias) {
       lastAlias = selectedAlias;
     }
   }
   return Long.toHexString(lastAlias + 1);
 }
  @RequestMapping(
      value = "/setPaymentStatus_TaskActiviti_Direct",
      method = RequestMethod.GET,
      headers = {"Accept=application/json"})
  public @ResponseBody String setPaymentStatus_TaskActiviti_Direct(
      @RequestParam String sID_Order,
      @RequestParam String sID_PaymentSystem,
      @RequestParam String sData,
      @RequestParam(value = "sPrefix", required = false) String sPrefix,

      // @RequestParam String snID_Task,
      @RequestParam String sID_Transaction,
      @RequestParam String sStatus_Payment)
      throws Exception {

    if (sPrefix == null) {
      sPrefix = "";
    }

    LOG.info("/setPaymentStatus_TaskActiviti_Direct");
    LOG.info("sID_Order=" + sID_Order);
    LOG.info("sID_PaymentSystem=" + sID_PaymentSystem);
    LOG.info("sData=" + sData);
    LOG.info("sPrefix=" + sPrefix);

    LOG.info("sID_Transaction=" + sID_Transaction);
    LOG.info("sStatus_Payment=" + sStatus_Payment);

    // String snID_Task=sID_Order;

    Long nID_Task = null;
    try {
      if (sID_Order.contains(TASK_MARK)) {
        nID_Task = Long.decode(sID_Order.replace(TASK_MARK, ""));
      }
    } catch (NumberFormatException e) {
      LOG.error("incorrect sID_Order! can't invoke task_id: " + sID_Order);
    }
    String snID_Task = "" + nID_Task;
    LOG.info("snID_Task=" + snID_Task);

    if ("Liqpay".equals(sID_PaymentSystem)) {
      setPaymentTransaction_ToActiviti(snID_Task, sID_Transaction, sStatus_Payment, sPrefix);
      sData = "Ok";
    } else {
      sData = "Fail";
    }
    // sID_Order=TaskActiviti_105123&sID_PaymentSystem=Liqpay&sData=&nID_Subject=25447
    return sData;
  }
示例#25
0
 /**
  * Creates a new <code>UUIDGenerator</code> instance.
  *
  * <p>Supported configuration parameters:
  *
  * <table>
  * <tr>
  * <th>Name</th>
  * <th>optional?</th>
  * <th>Usage</th>
  * </tr>
  * <tr>
  * <td>macAddress</td>
  * <td>yes</td>
  * <td>specify MAC address component of UUID</td>
  * </tr>
  * </table>
  *
  * @param params configuration parameters
  * @throws IdGenerationException
  */
 public UUIDGenerator(Properties params) throws IdGenerationException {
   super(params);
   String macAddress = params.getProperty("macAddress");
   if (macAddress != null) {
     long decoded;
     try {
       decoded = Long.decode(macAddress);
     } catch (NumberFormatException e) {
       throw new IdGenerationException(
           "Value for parameter 'macAddress': '" + macAddress + "' can not be decoded as Long.");
     }
     mac = decoded;
     macSet = true;
   }
 }
示例#26
0
 private void testParseSpecialValue(String x) throws SQLException {
   Object expected;
   expected = new BigDecimal(x);
   try {
     expected = Long.decode(x);
     expected = Integer.decode(x);
   } catch (Exception e) {
     // ignore
   }
   ResultSet rs = stat.executeQuery("call " + x);
   rs.next();
   Object o = rs.getObject(1);
   assertEquals(expected.getClass().getName(), o.getClass().getName());
   assertTrue(expected.equals(o));
 }
示例#27
0
  /**
   * Convert the given value to specified type.
   *
   * @param value
   * @param type
   * @return
   */
  @SuppressWarnings("unchecked")
  public static <T> T valueOf(String value, Class type) {

    if (type == String.class) {
      return (T) value;
    } else if (type == Boolean.class || type == Boolean.TYPE) {
      return (T) Boolean.valueOf(value);
    } else if (type == Integer.class || type == Integer.TYPE) {
      return (T) Integer.decode(value);
    } else if (type == Float.class || type == Float.TYPE) {
      return (T) Float.valueOf(value);
    } else if (type == Double.class || type == Double.TYPE) {
      return (T) Double.valueOf(value);
    } else if (type == Long.class || type == Long.TYPE) {
      return (T) Long.decode(value);
    } else if (type == Short.class || type == Short.TYPE) {
      return (T) Short.decode(value);
    } else if (type.isAssignableFrom(List.class)) {
      return (T) new ArrayList<String>(Arrays.asList(value.split(","))); // $NON-NLS-1$
    } else if (type.isArray()) {
      String[] values = value.split(","); // $NON-NLS-1$
      Object array = Array.newInstance(type.getComponentType(), values.length);
      for (int i = 0; i < values.length; i++) {
        Array.set(array, i, valueOf(values[i], type.getComponentType()));
      }
      return (T) array;
    } else if (type == Void.class) {
      return null;
    } else if (type.isEnum()) {
      return (T) Enum.valueOf(type, value);
    } else if (type.isAssignableFrom(Map.class)) {
      List<String> l = Arrays.asList(value.split(",")); // $NON-NLS-1$
      Map m = new HashMap<String, String>();
      for (String key : l) {
        int index = key.indexOf('=');
        if (index != -1) {
          m.put(key.substring(0, index), key.substring(index + 1));
        }
      }
      return (T) m;
    }

    throw new IllegalArgumentException(
        "Conversion from String to "
            + type.getName()
            + " is not supported"); //$NON-NLS-1$ //$NON-NLS-2$
  }
 /**
  * checks if social entity is owned by the given user
  *
  * @param user user owner of entity
  * @param entityId social entity id
  * @return true if entity is owned by the user, false otherwise
  */
 public boolean isOwnedBy(User user, String entityId) {
   try {
     Entity entity = socialClient.readEntity(Long.decode(entityId), null);
     it.unitn.disi.sweb.webapi.model.smartcampus.social.User socialUser =
         socialClient.readUser(Long.valueOf(user.getSocialId()));
     return entity.getOwnerId().equals(socialUser.getEntityBaseId());
   } catch (NumberFormatException e) {
     logger.error(String.format("Exception converting in long entityId %s", entityId));
     return false;
   } catch (WebApiException e) {
     logger.error("Exception invoking socialEngineClient", e);
     return false;
   } catch (Exception e) {
     logger.error("A general exception is occurred", e);
     return false;
   }
 }
示例#29
0
 public Long count(List<String> searchFields, String keywords, String where) {
   String q = "select count(*) from " + clazz.getName() + " e";
   if (keywords != null && !keywords.equals("")) {
     String searchQuery = getSearchQuery(searchFields);
     if (!searchQuery.equals("")) {
       q += " where (" + searchQuery + ")";
     }
     q += (where != null ? " and " + where : "");
   } else {
     q += (where != null ? " where " + where : "");
   }
   Query query = getJPAContext().em().createQuery(q);
   if (keywords != null && !keywords.equals("") && q.indexOf("?1") != -1) {
     query.setParameter(1, "%" + keywords.toLowerCase() + "%");
   }
   return Long.decode(query.getSingleResult().toString());
 }
  @RequestMapping(value = "/persistenceGeo/getUsersByGroup/{idGroup}", method = RequestMethod.GET)
  public @ResponseBody Map<String, Object> getUsersByGroup(@PathVariable String idGroup) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<UserDto> users = null;

    try {
      // TODO: get user by authority group of user logged
      users = (List<UserDto>) userAdminService.getUsersByGroup(Long.decode(idGroup));
    } catch (Exception e) {
      // Nothing
    }

    result.put(RESULTS, users != null ? users.size() : 0);
    result.put(ROOT, users != null ? users : ListUtils.EMPTY_LIST);

    return result;
  }