Exemplo n.º 1
1
  private void mergeUpdate(JsonObject update, JsonObject master) {
    for (Map.Entry<String, JsonElement> attr : update.entrySet()) {
      if ((null == attr.getValue()) || attr.getValue().isJsonNull()) {
        // TODO use singleton to reduce memory footprint
        master.add(attr.getKey(), new JsonNull());
      }

      assertCompatibility(master.get(attr.getKey()), attr.getValue());
      if (attr.getValue() instanceof JsonPrimitive) {
        if (!master.has(attr.getKey()) || !master.get(attr.getKey()).equals(attr.getValue())) {
          master.add(attr.getKey(), attr.getValue());
        }
      } else if (attr.getValue() instanceof JsonObject) {
        if (!master.has(attr.getKey()) || master.get(attr.getKey()).isJsonNull()) {
          // copy whole subtree
          master.add(attr.getKey(), attr.getValue());
        } else {
          // recurse to merge attribute updates
          mergeUpdate(
              attr.getValue().getAsJsonObject(), master.get(attr.getKey()).getAsJsonObject());
        }
      } else if (attr.getValue() instanceof JsonArray) {
        // TODO any way to correlate elements between arrays? will need concept of
        // element identity to merge elements
        master.add(attr.getKey(), attr.getValue());
      }
    }
  }
 @Override
 public PluginManifest deserialize(
     final JsonElement json, final Type typeOfT, final JsonDeserializationContext context)
     throws JsonParseException {
   final PluginManifest pluginManifest = new PluginManifest();
   final JsonObject result = json.getAsJsonObject();
   if (!result.has("name")) {
     throw new IllegalArgumentException("No name present in manifest.");
   }
   if (!result.has("main")) {
     throw new IllegalArgumentException("No main present in manifest.");
   }
   if (result.has("disabled")) {
     final boolean disabled = result.get("disabled").getAsBoolean();
     pluginManifest.setDisabled(disabled);
   }
   if (result.has("author")) {
     final String author = result.get("author").getAsString();
     pluginManifest.setAuthor(author);
   }
   if (result.has("description")) {
     final String description = result.get("description").getAsString();
     pluginManifest.setDescription(description);
   }
   final String name = result.get("name").getAsString();
   final String mainClass = result.get("main").getAsString();
   pluginManifest.setName(name);
   pluginManifest.setMainClass(mainClass);
   return pluginManifest;
 }
Exemplo n.º 3
1
    private SegmentItem deserializeItem(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }

      SegmentItem segment = new SegmentItem();

      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<ItemType>() {},
              new TypeToken<List<ItemType>>() {}.getType()));
      json.remove("actions");

      if (json.has("isAdjacent")) {
        segment.isAdjacent = json.get("isAdjacent").getAsBoolean();
        json.remove("isAdjacent");
      }

      if (json.has("clientUpdate")) {
        JsonObject jsonClientUpdate = json.get("clientUpdate").getAsJsonObject();
        segment.clientUpdate =
            new ClientBlockUpdate(
                (Volume) context.deserialize(jsonClientUpdate.get("coords"), Volume.class));
        if (jsonClientUpdate.has("directional")) {
          segment.directionalClientUpdate = jsonClientUpdate.get("directional").getAsBoolean();
        }
        json.remove("clientUpdate");
      }

      return segment;
    }
Exemplo n.º 4
0
  public List<StatusActivity> fetchActivities() {
    List<StatusActivity> statuses = new ArrayList<StatusActivity>();

    StringBuilder url =
        new StringBuilder("https://www.googleapis.com/plus/v1/people/")
            .append(this.googleId)
            .append("/activities/public?key=AIzaSyC4xOkQsEPJcUKUvQGL6T7RZkrIIxSuZAg");
    JsonElement response = fetchJson(url.toString());
    if (response != null) {
      JsonArray activities = response.getAsJsonObject().get("items").getAsJsonArray();
      DateFormat googleFormatter = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
      for (JsonElement element : activities) {
        JsonObject activity = element.getAsJsonObject();
        try {
          String content = activity.get("object").getAsJsonObject().get("content").getAsString();
          Date date = googleFormatter.parse(activity.get("published").getAsString());
          String statusId = activity.get("id").getAsString();
          String statusUrl = activity.get("url").getAsString();
          statuses.add(
              new StatusActivity(this.member, date, this.provider, content, statusUrl, statusId));
        } catch (ParseException pe) {
          Logger.error("ouch! parse exception " + pe.getMessage());
        }
      }
    }
    return statuses;
  }
  public static HashMap<String, Integer> getAnimeSearchedMAL(
      String username, String password, String anime) {
    HashMap<String, Integer> map = new HashMap<String, Integer>();

    JSONObject xmlJSONObj;
    String json = "";
    String xml = "";
    try {
      xml = searchAnimeMAL(username, password, anime);
      xmlJSONObj = XML.toJSONObject(xml);
      json = xmlJSONObj.toString(4);
    } catch (Exception e) {
      MAMUtil.writeLog(e);
      e.printStackTrace();
    }
    JsonParser parser = new JsonParser();
    JsonObject root = parser.parse(json).getAsJsonObject();
    if (root.has("anime") && root.get("anime").getAsJsonObject().get("entry").isJsonArray()) {
      JsonArray searchedAnime = root.get("anime").getAsJsonObject().get("entry").getAsJsonArray();
      for (JsonElement obj : searchedAnime) {
        String name = obj.getAsJsonObject().get("title").getAsString();
        int id = obj.getAsJsonObject().get("id").getAsInt();
        map.put(name, id);
      }
    } else if (root.has("anime")) {
      JsonObject obj = root.get("anime").getAsJsonObject().get("entry").getAsJsonObject();
      int id = obj.getAsJsonObject().get("id").getAsInt();
      map.put(anime, id);
    }
    return map;
  }
  /**
   * Creates a User based on a Microsoft Azure Mobile Service JSON object containing a UserId and
   * Authentication Token
   *
   * @param json JSON object used to create the User
   * @return The created user if it is a valid JSON object. Null otherwise
   * @throws MobileServiceException
   */
  private MobileServiceUser createUserFromJSON(JsonObject json) throws MobileServiceException {
    if (json == null) {
      throw new IllegalArgumentException("json can not be null");
    }

    // If the JSON object is valid, create a MobileServiceUser object
    if (json.has(USER_JSON_PROPERTY)) {
      JsonObject jsonUser = json.getAsJsonObject(USER_JSON_PROPERTY);

      if (!jsonUser.has(USERID_JSON_PROPERTY)) {
        throw new JsonParseException(USERID_JSON_PROPERTY + " property expected");
      }
      String userId = jsonUser.get(USERID_JSON_PROPERTY).getAsString();

      MobileServiceUser user = new MobileServiceUser(userId);

      if (!json.has(TOKEN_JSON_PARAMETER)) {
        throw new JsonParseException(TOKEN_JSON_PARAMETER + " property expected");
      }

      user.setAuthenticationToken(json.get(TOKEN_JSON_PARAMETER).getAsString());
      return user;
    } else {
      // If the JSON contains an error property show it, otherwise raise
      // an error with JSON content
      if (json.has("error")) {
        throw new MobileServiceException(json.get("error").getAsString());
      } else {
        throw new JsonParseException(json.toString());
      }
    }
  }
    @Override
    protected Person doInBackground(String... params) {
      try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(WebStuff.USER_URL + "?email=" + params[0]);

        HttpResponse response = httpClient.execute(httpGet);
        Log.i("Cheerspal", response.getStatusLine().toString());

        HttpEntity httpEntity = response.getEntity();
        String result = EntityUtils.toString(httpEntity);

        if (result != null) {
          Log.i("Cheerspal", "result: " + result);

          JsonObject responseObject = new JsonParser().parse(result).getAsJsonObject();

          String firstName = responseObject.get("firstname").getAsString();
          String lastName = responseObject.get("lastname").getAsString();

          return new Person(firstName, lastName, params[0]);
        } else {
          Log.i("Cheerspal", "result: null");
        }
      } catch (Exception e) {
      }

      return null;
    }
 private String[] getErrorInfo(JsonObject responseBody) {
   String[] errorInfo = new String[2];
   JsonObject error = responseBody.get("data").getAsJsonObject().get("error").getAsJsonObject();
   errorInfo[0] = error.get("code").getAsString();
   errorInfo[1] = error.get("message").getAsString();
   return errorInfo;
 }
Exemplo n.º 9
0
    private SegmentBlock deserializeBlock(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }
      SegmentBlock segment = new SegmentBlock();
      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<BlockType>() {},
              new TypeToken<List<BlockType>>() {}.getType()));
      json.remove("actions");

      if (json.has("meta")) {
        segment.meta = json.get("meta").getAsInt();
        json.remove("meta");
      }

      if (json.has("clientUpdate")) {
        segment.clientUpdate =
            new ClientBlockUpdate(
                (Volume)
                    context.deserialize(
                        json.get("clientUpdate").getAsJsonObject().get("coords"), Volume.class));
        json.remove("clientUpdate");
      }

      return segment;
    }
Exemplo n.º 10
0
    @Override
    public HanabiraBoard deserialize(
        JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
      JsonObject boardsJsonObject = json.getAsJsonObject().get("boards").getAsJsonObject();
      Set<Map.Entry<String, JsonElement>> boardsSet = boardsJsonObject.entrySet();
      if (boardsSet.size() > 1) {
        throw new IllegalArgumentException("Few board entries received for a request");
      }
      Map.Entry<String, JsonElement> boardEntry = boardsSet.iterator().next();
      boardKey = boardEntry.getKey();
      JsonObject boardObject = boardEntry.getValue().getAsJsonObject();
      int pages = boardObject.get("pages").getAsInt();

      HanabiraBoard cachedBoard = Hanabira.getStem().findBoardByKey(boardKey);
      if (cachedBoard == null) {
        cachedBoard = new HanabiraBoard(boardKey, pages, null);
        Hanabira.getStem().saveBoard(cachedBoard);
      } else {
        cachedBoard.update(pages, null);
      }

      JsonElement pageElement = boardObject.get("page");
      int page = (pageElement == null) ? 0 : pageElement.getAsInt();

      List<Integer> threadsOnPageIds = new ArrayList<>();
      for (JsonElement threadElement : boardObject.getAsJsonArray("threads")) {
        threadsOnPageIds.add(
            createThreadWithPosts(threadElement.getAsJsonObject(), boardKey).getThreadId());
      }
      cachedBoard.updatePage(page, threadsOnPageIds);

      return cachedBoard;
    }
Exemplo n.º 11
0
  public static ITheme create(JsonObject json) {

    ITheme theme;
    BlockSet primary = null;
    BlockSet secondary = null;

    // primary blocks
    if (json.has("primary")) {
      JsonObject data = json.get("primary").getAsJsonObject();
      primary = new BlockSet(data);
    }

    // secondary blocks
    if (json.has("secondary")) {
      JsonObject data = json.get("secondary").getAsJsonObject();
      secondary = new BlockSet(data);
    }

    if (json.has("base")) {
      theme = Theme.getTheme(Theme.valueOf(json.get("base").getAsString()));
      return new ThemeBase((ThemeBase) theme, primary, secondary);
    } else {
      theme = Theme.getTheme(Theme.OAK);
      return new ThemeBase((ThemeBase) theme, primary, secondary);
    }
  }
  @Override
  public JsonRpcResponse deserialize(
      JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();

    String id = jsonObject.get(ResponseProperty.ID.key()).getAsString();
    if (jsonObject.has(ResponseProperty.ERROR.key())) {
      JsonElement errorObject = jsonObject.get(ResponseProperty.ERROR.key());
      String errorMessage = errorObject.getAsJsonObject().get("message").getAsString();
      return JsonRpcResponse.error(id, errorMessage);
    }

    // Deserialize the data.
    Map<ParamsProperty, Object> properties = new HashMap<ParamsProperty, Object>();
    JsonElement data = jsonObject.get(ResponseProperty.DATA.key());
    if (data != null && data.isJsonObject()) {
      for (Entry<String, JsonElement> parameter : data.getAsJsonObject().entrySet()) {
        ParamsProperty parameterType = ParamsProperty.fromKey(parameter.getKey());
        if (parameterType == null) {
          // Skip this unknown parameter.
          continue;
        }
        Object object = null;
        if (parameterType == ParamsProperty.BLIPS) {
          Type blipMapType = new TypeToken<Map<String, BlipData>>() {}.getType();
          object = context.deserialize(parameter.getValue(), blipMapType);
        } else {
          object = context.deserialize(parameter.getValue(), parameterType.clazz());
        }
        properties.put(parameterType, object);
      }
    }

    return JsonRpcResponse.result(id, properties);
  }
Exemplo n.º 13
0
  public void getIssueAndPull() throws Exception {
    MongoClient mongoClient = new MongoClient(MongoInfo.getMongoServerIp(), 27017);
    MongoDatabase database = mongoClient.getDatabase("ghcrawlerV3");
    FindIterable<Document> issueIterable = database.getCollection("issueandpull").find();
    Connection connection = MysqlInfo.getMysqlConnection();
    connection.setAutoCommit(false);
    String sql =
        "update repotest set open_issues = ?,closed_issues = ?,open_pull=?,closed_pull=? where full_name = ?";
    PreparedStatement stmt = connection.prepareStatement(sql);
    JsonParser parser = new JsonParser();
    for (Document document : issueIterable) {
      String json = document.toJson();
      JsonObject repoIssue = parser.parse(json).getAsJsonObject();
      int openIssue = repoIssue.get("openissue").getAsInt();
      int closedIssue = repoIssue.get("closedissue").getAsInt();
      int openPull = repoIssue.get("openpull").getAsInt();
      int closedPull = repoIssue.get("closedpull").getAsInt();
      String repoName = repoIssue.get("fn").getAsString();
      System.out.println(repoName);
      stmt.setInt(1, openIssue);
      stmt.setInt(2, closedIssue);
      stmt.setInt(3, openPull);
      stmt.setInt(4, closedPull);
      stmt.setString(5, repoName);

      stmt.execute();
    }
    connection.commit();
    connection.close();
    mongoClient.close();
  }
Exemplo n.º 14
0
  public void getCommitCount() throws Exception {

    MongoClient mongoClient = new MongoClient(MongoInfo.getMongoServerIp(), 27017);
    MongoDatabase database = mongoClient.getDatabase("ghcrawlerV3");
    FindIterable<Document> issueIterable = database.getCollection("commitnumber").find();
    Connection connection = MysqlInfo.getMysqlConnection();
    connection.setAutoCommit(false);
    JsonParser parser = new JsonParser();
    for (Document document : issueIterable) {
      String json = document.toJson();
      JsonObject repoJsonObject = parser.parse(json).getAsJsonObject();
      int commit = repoJsonObject.get("commitnumber").getAsInt();
      String full_name = repoJsonObject.get("fn").getAsString();
      System.out.println(full_name);
      String sql = "update repotest set commit = ? where full_name = ?";
      PreparedStatement stmt = connection.prepareStatement(sql);
      stmt.setInt(1, commit);
      stmt.setString(2, full_name);
      stmt.execute();
    }

    connection.commit();
    connection.close();
    mongoClient.close();
  }
  @Override
  public CommandProcessingResult deleteAllLoanTaxMapId(JsonCommand command) {

    final JsonElement parsedJson = this.fromJsonHelper.parse(command.json());

    if (parsedJson.isJsonObject()) {

      final JsonObject topLevelJsonElement = parsedJson.getAsJsonObject();

      if (topLevelJsonElement.has("taxMapArray")
          && topLevelJsonElement.get("taxMapArray").isJsonArray()) {

        final JsonArray array = topLevelJsonElement.get("taxMapArray").getAsJsonArray();

        for (int i = 0; i < array.size(); i++) {
          final JsonObject loanChargeElement = array.get(i).getAsJsonObject();
          final Long taxMapId = this.fromJsonHelper.extractLongNamed("taxMapId", loanChargeElement);
          this.loanTaxMapRepository.delete(taxMapId);
        }
      }

      return new CommandProcessingResultBuilder().withEntityId(0L).build();
    }
    return null;
  }
Exemplo n.º 16
0
 /*
  * 检查code是否核查不合法返回null
  */
 @Override
 public UserCode checkUserCode(String code) throws Exception {
   // 获取加密后的信息解密
   String msg = PurseSecurityUtils.decryption(code, CommonConstants.SecurityKey);
   // 解密后的json格式验证是否正确
   JsonParser jsonParser = new JsonParser();
   JsonObject jsonObject = jsonParser.parse(msg).getAsJsonObject();
   String createTime = jsonObject.get("createTime").getAsString();
   Long userId = jsonObject.get("userId").getAsLong();
   Long id = jsonObject.get("id").getAsLong();
   // 验证信息为空
   if (StringUtils.isEmpty(createTime) || ObjectUtils.isNull(userId) || ObjectUtils.isNull(id)) {
     return null;
   }
   UserCode userCode = userCodeDao.getUserCodeById(id);
   // 查询userCode 状态是否已经使用过
   if (ObjectUtils.isNotNull(userCode) && userCode.getStatus().longValue() == 0) {
     Calendar c = Calendar.getInstance();
     c.setTime(userCode.getCreateTime());
     c.add(Calendar.DAY_OF_MONTH, 3);
     if (new Date().getTime() > c.getTime().getTime()) { // 超过三天
       return null;
     }
     return userCode;
   }
   return null;
 }
  // AmbientColorAgents MetaConfig entries with pattern UNIT_(number)
  private void updateAmbientColorAgentMetaConfig(
      JsonArray metaConfigEntries, Map<File, DatabaseEntryDescriptor> dalUnitDB)
      throws CouldNotPerformException {
    JsonObject metaConfigEntry;
    String key, unitScope;
    for (JsonElement metaConfigEntryElem : metaConfigEntries) {
      metaConfigEntry = metaConfigEntryElem.getAsJsonObject();

      if (!metaConfigEntry.has(KEY_FIELD) || !metaConfigEntry.has(VALUE_FIELD)) {
        continue;
      }

      key = metaConfigEntry.get(KEY_FIELD).getAsString();
      if (key.matches("UNIT_[0123456789]+")) {
        unitScope = updateScopeToNewUnitTypes(metaConfigEntry.get(VALUE_FIELD).getAsString());
        if (!unitScopeIdMap.containsKey(unitScope)) {
          throw new CouldNotPerformException(
              "Could not replace scope ["
                  + unitScope
                  + "] with unit id in metaConfigEntry with key ["
                  + key
                  + "] of PowerStateSynchroniser");
        }
        metaConfigEntry.remove(VALUE_FIELD);
        metaConfigEntry.addProperty(VALUE_FIELD, unitScopeIdMap.get(unitScope));
      }
    }
  }
Exemplo n.º 18
0
  @Override
  public void parseJson(String json) throws JSONException {

    JsonElement element = JsonUtils.getJsonElement(json);
    if (element != null) {
      JsonObject object = element.getAsJsonObject();
      if (object.has("date")) {
        JsonElement item = object.get("date");
        if (!item.isJsonNull()) {
          data = item.getAsString();
        }
      }

      if (object.has("time")) {
        JsonElement item = object.get("time");
        if (!item.isJsonNull()) {
          ApiModelList<DeliveryTime> times = new ApiModelList<>(new DeliveryTime());
          times.parseJson(item.toString());
          deliveryTimes = new ArrayList<>();
          deliveryTimes.addAll(times.getList());
        }
      }
    }
    if (null != deliveryTimes) {
      for (DeliveryTime deliveryTime : deliveryTimes) {
        deliveryTime.setDate(this);
      }
    }
  }
  public PublicKey retrieveJwkKey(String jwkUrl) {
    RSAPublicKey pub = null;

    try {
      String jwkString = restTemplate.getForObject(jwkUrl, String.class);
      JsonObject json = (JsonObject) new JsonParser().parse(jwkString);
      JsonArray getArray = json.getAsJsonArray("keys");
      for (int i = 0; i < getArray.size(); i++) {
        JsonObject object = getArray.get(i).getAsJsonObject();
        String algorithm = object.get("alg").getAsString();

        if (algorithm.equals("RSA")) {
          byte[] modulusByte = Base64.decodeBase64(object.get("mod").getAsString());
          BigInteger modulus = new BigInteger(1, modulusByte);
          byte[] exponentByte = Base64.decodeBase64(object.get("exp").getAsString());
          BigInteger exponent = new BigInteger(1, exponentByte);

          RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
          KeyFactory factory = KeyFactory.getInstance("RSA");
          pub = (RSAPublicKey) factory.generatePublic(spec);
        }
      }

    } catch (HttpClientErrorException e) {
      logger.error("HttpClientErrorException in KeyFetcher.java: ", e);
    } catch (NoSuchAlgorithmException e) {
      logger.error("NoSuchAlgorithmException in KeyFetcher.java: ", e);
    } catch (InvalidKeySpecException e) {
      logger.error("InvalidKeySpecException in KeyFetcher.java: ", e);
    }
    return pub;
  }
 @Override
 public Versioning deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   if (!json.isJsonObject()) {
     throw new JsonParseException("Element was not an object");
   }
   JsonObject obj = json.getAsJsonObject();
   VersioningType type = context.deserialize(obj.get("type"), VersioningType.class);
   JsonElement params = obj.get("params");
   if (type == null) {
     type = VersioningType.NONE;
   }
   switch (type) {
     case EXTERNAL:
       return new VersioningExternal(
           type, context.deserialize(params, VersioningExternal.Params.class));
     case SIMPLE:
       return new VersioningSimple(
           type, context.deserialize(params, VersioningSimple.Params.class));
     case STAGGERED:
       return new VersioningStaggered(
           type, context.deserialize(params, VersioningStaggered.Params.class));
     case TRASHCAN:
       return new VersioningTrashCan(
           type, context.deserialize(params, VersioningTrashCan.Params.class));
     case NONE:
     default:
       return new VersioningNone(type);
   }
 }
  public void handleMessage(String pattern, String channel, String message) {
    if (channel.equalsIgnoreCase(TO_VOICE_CONF_SYSTEM_CHAN)) {
      JsonParser parser = new JsonParser();
      JsonObject obj = (JsonObject) parser.parse(message);

      if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");

        if (header.has("name")) {
          String messageName = header.get("name").getAsString();
          switch (messageName) {
            case EjectAllUsersFromVoiceConfRequestMessage.EJECT_ALL_VOICE_USERS_REQUEST:
              processEjectAllVoiceUsersRequestMessage(message);
              break;
            case EjectUserFromVoiceConfRequestMessage.EJECT_VOICE_USER_REQUEST:
              processEjectVoiceUserRequestMessage(message);
              break;
            case GetUsersFromVoiceConfRequestMessage.GET_VOICE_USERS_REQUEST:
              processGetVoiceUsersRequestMessage(message);
              break;
            case MuteUserInVoiceConfRequestMessage.MUTE_VOICE_USER_REQUEST:
              processMuteVoiceUserRequestMessage(message);
              break;
            case StartRecordingVoiceConfRequestMessage.START_RECORD_VOICE_CONF_REQUEST:
              processStartRecordingVoiceConfRequestMessage(message);
              break;
            case StopRecordingVoiceConfRequestMessage.STOP_RECORD_VOICE_CONF_REQUEST:
              processStopRecordingVoiceConfRequestMessage(message);
              break;
          }
        }
      }
    }
  }
  boolean skipRecord(GoogleURL urlObject, Reporter reporter) {

    if (_skipDomain) {
      reporter.incrCounter(Counters.SKIPPING_BAD_DOMAIN_URL, 1);
      return true;
    }

    if (!urlObject.isValid()) {
      reporter.incrCounter(Counters.SKIPPING_INVALID_URL, 1);
      return true;
    } else if (urlObject.has_query()) {
      reporter.incrCounter(Counters.HIT_QUERY_CHECK_CONDITION, 1);
      if ((_flags & (HAS_HOMEPAGE_URLDATA | HAS_FEED_URLDATA)) == 0) {
        reporter.incrCounter(Counters.SKIPPING_QUERY_URL, 1);
        return true;
      }
    } else {
      // if redirect ... skip
      if ((_flags & HAS_REDIRECT_DATA) != 0) {
        reporter.incrCounter(Counters.SKIPPING_REDIRECTED_URL, 1);
        return true;
      }

      if ((_flags & (HAS_HOMEPAGE_URLDATA | HAS_FEED_URLDATA)) != 0) {
        if (!_skipEverythingButHomepage || ((_flags & HAS_HOMEPAGE_URLDATA) != 0)) {
          reporter.incrCounter(Counters.ALLOWING_HOMEPAGE_OR_FEEDURL, 1);
          return false;
        }
      }

      if (_skipEverythingButHomepage) {
        reporter.incrCounter(Counters.SKIPPING_EVERYTHING_BUT_HOMEPAGE_URL, 1);
        return true;
      }

      if (_crawlStatus != null) {
        if (_crawlStatus.has("crawl_status")) {
          JsonObject realCrawlStatus = _crawlStatus.get("crawl_status").getAsJsonObject();
          if (realCrawlStatus.has("http_result")) {
            int httpResult = realCrawlStatus.get("http_result").getAsInt();
            if (httpResult == 200 || httpResult == 404) {
              if ((_flags & HAS_BLOGPROBE_URLDATA) != 0) {
                if (_blogURLSkipFlag.get()) {
                  reporter.incrCounter(Counters.SKIPPING_BLOGPROBE_URL, 1);
                  return true;
                } else {
                  reporter.incrCounter(Counters.RECRAWLING_BLOGPROBE_URL, 1);
                  return false;
                }
              } else {
                reporter.incrCounter(Counters.SKIPPING_ALREADY_FETCHED, 1);
                return true;
              }
            }
          }
        }
      }
    }
    return false;
  }
  public Project(JsonObject json) {
    this();

    this.projectId = json.get("project_id").getAsInt();
    this.wordCount = json.get("wordcount").getAsInt();
    this.credits = json.get("credits").getAsFloat();
  }
  private static boolean parseProperty(
      JsonElement propertyElement, IConfigPropertyHolder property, Gson gson) {
    if (!(propertyElement instanceof JsonObject)) return true;

    JsonObject propertyNode = propertyElement.getAsJsonObject();

    JsonElement value = propertyNode.get(VALUE_TAG);

    if (value == null) return true;

    try {
      Object parsedValue = gson.fromJson(value, property.getType());
      property.setValue(parsedValue);
    } catch (Exception e) {
      Log.warn(e, "Failed to parse value of field %s:%s", property.category(), property.name());
      return true;
    }

    JsonElement comment = propertyNode.get(COMMENT_TAG);

    final String expectedComment = property.comment();

    if (comment == null) {
      return !Strings.isNullOrEmpty(expectedComment);
    } else if (comment.isJsonPrimitive()) {
      String commentValue = comment.getAsString();
      return !expectedComment.equals(commentValue);
    }

    return true;
  }
Exemplo n.º 25
0
  private static double parseDirections(JsonElement jsonE) {
    JsonObject json = jsonE.getAsJsonObject();
    JsonArray jsonarray = json.get("routes").getAsJsonArray();
    json = jsonarray.get(0).getAsJsonObject();
    jsonarray = json.get("legs").getAsJsonArray();

    double time = 0;
    double minTime = 0;

    if (jsonarray.size() > 0)
      minTime =
          jsonarray
              .get(0)
              .getAsJsonObject()
              .get("duration")
              .getAsJsonObject()
              .get("value")
              .getAsInt();

    for (int i = 1; i < jsonarray.size(); i++) {
      time =
          jsonarray
              .get(i)
              .getAsJsonObject()
              .get("duration")
              .getAsJsonObject()
              .get("value")
              .getAsDouble();
      if (time < minTime) minTime = time;
    }
    System.out.println("minTime= " + minTime);
    return minTime;
  }
Exemplo n.º 26
0
 @Transactional
 public void getCallbackHunterCalls() throws ParseException, IOException {
   List<AccountSettings> accountSettingsList = accountSettingsManager.getAccountSettingsList();
   for (AccountSettings accountSettings : accountSettingsList) {
     if (accountSettings.getCbhId() != null
         && !accountSettings.getCbhId().isEmpty()
         && accountSettings.getCbhKey() != null
         && !accountSettings.getCbhKey().isEmpty()) {
       JsonArray arrayResponse =
           callBackHunterApi.getData(
               accountSettings.getCbhId(),
               accountSettings.getCbhKey(),
               Calendar.getInstance(TIME_ZONE).getTime());
       for (JsonElement call : arrayResponse) {
         JsonObject object = call.getAsJsonObject();
         String data = object.get("phone_client").getAsString();
         DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         format.setTimeZone(TIME_ZONE);
         Date date = format.parse(object.get("datecall").getAsString());
         if (leadManager
             .getLeadsByTypeAndDataAndDate(LeadType.CALLBACK, data, date)
             .isEmpty()) { // check duplicated leads for today
           leadProcessingService.pushLead(
               data, "", "", accountSettings.getHost(), LeadType.CALLBACK);
         }
       }
     }
   }
 }
Exemplo n.º 27
0
 @Override
 public ServerPingServerData deserialize(
     final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) {
   final JsonObject jsonObject = jsonElement.getAsJsonObject();
   return new ServerPingServerData(
       jsonObject.get("name").getAsString(), jsonObject.get("protocol").getAsInt());
 }
Exemplo n.º 28
0
  @Override
  protected void runOneIteration() throws Exception {
    NodesInfo action = new NodesInfo.Builder().build();

    JestResult result = null;
    try {
      result = client.execute(action);
    } catch (Exception e) {
      logger.error("Error executing NodesInfo!", e);
      // do not elevate the exception since that will stop the scheduled calls.
      // throw new RuntimeException("Error executing NodesInfo!", e);
    }

    if (result != null) {
      LinkedHashSet<String> httpHosts = new LinkedHashSet<String>();

      JsonObject jsonMap = result.getJsonObject();
      JsonObject nodes = (JsonObject) jsonMap.get("nodes");
      if (nodes != null) {
        for (Entry<String, JsonElement> entry : nodes.entrySet()) {
          JsonObject host = (JsonObject) entry.getValue();
          String http_address = host.get("http_address").getAsString();
          if (null != http_address) {
            String cleanHttpAddress =
                "http://" + http_address.substring(6, http_address.length() - 1);
            httpHosts.add(cleanHttpAddress);
          }
        }
      }

      logger.info("Discovered Http Hosts: {}", httpHosts);
      client.setServers(httpHosts);
    }
  }
  @Test
  public void write_onPatchWithInnerObject_fullyWritesInnerObject() {
    TestData original = new TestData();
    TestData updated = new TestData();
    updated.setInnerData(new InnerTestData());

    Patch<TestData> patch =
        MakePatch.from(original).to(updated).with(new ReflectivePatchCalculator<>());
    JsonObject json = toJson(patch);

    assertTrue(json.has("innerData"));
    assertTrue(json.get("innerData").isJsonObject());

    JsonObject innerJson = json.get("innerData").getAsJsonObject();
    Collection<String[]> fields =
        Collections2.transform(
            innerJson.entrySet(),
            entry -> new String[] {entry.getKey(), entry.getValue().getAsString()});
    assertThat(
        fields,
        containsInAnyOrder(
            new String[] {"json-name-alias", "inner-named-value"},
            new String[] {"name1", "inner-value-1"},
            new String[] {"name2", "inner-value-2"}));
  }
  @Test
  public void testOpeningTimeTypeAdapter() {
    assertEquals(adapter.getAdaptedType(), OpeningTime.class);

    JsonObject openingTimeJson = new JsonObject();
    openingTimeJson.addProperty("day", "Monday");
    openingTimeJson.addProperty("timeStart", "12:00");
    openingTimeJson.addProperty("timeStop", "15:00");

    OpeningTime openingTime = adapter.deserialize(openingTimeJson, OpeningTime.class, null);

    assertEquals(openingTimeJson.get("day").getAsString(), openingTime.getDay().value());
    assertEquals(
        openingTimeJson.get("timeStart").getAsString(),
        String.format(
            "%02d:%02d",
            openingTime.getTimeStart().getHourOfDay(),
            openingTime.getTimeStart().getMinutesInHour()));
    assertEquals(
        openingTimeJson.get("timeStop").getAsString(),
        String.format(
            "%02d:%02d",
            openingTime.getTimeStop().getHourOfDay(),
            openingTime.getTimeStop().getMinutesInHour()));
  }