Пример #1
0
  @Override
  @Transactional(readOnly = true)
  public FetcherRequestDTO prepareFetcherRequest(Collection dbCollection) {
    FetcherRequestDTO dto = new FetcherRequestDTO();

    UserConnection userconnection =
        userConnectionService.fetchByCombinedUserName(dbCollection.getOwner().getUserName());
    dto.setAccessToken(userconnection.getAccessToken());
    dto.setAccessTokenSecret(userconnection.getSecret());
    dto.setCollectionName(dbCollection.getName());
    dto.setCollectionCode(dbCollection.getCode());
    if (dbCollection.getProvider() == CollectionType.Facebook) {
      dto.setToFollow(dbCollection.getFollow());
    } else {
      dto.setToFollow(
          getFollowTwitterIDs(dbCollection.getFollow(), dbCollection.getOwner().getUserName()));
    }
    dto.setToTrack(dbCollection.getTrack());
    dto.setGeoLocation(dbCollection.getGeo());
    dto.setGeoR(dbCollection.getGeoR());
    dto.setLanguageFilter(dbCollection.getLangFilters());
    dto.setSaveMediaEnabled(dbCollection.isSaveMediaEnabled());
    dto.setFetchInterval(dbCollection.getFetchInterval());
    dto.setProvider(dbCollection.getProvider().toString());
    dto.setFetchInterval(dbCollection.getFetchInterval());
    dto.setFetchFrom(dbCollection.getFetchFrom());
    dto.setLastExecutionTime(dbCollection.getLastExecutionTime());
    // Added by koushik
    accessTokenStr = dto.getAccessToken();
    accessTokenSecretStr = dto.getAccessTokenSecret();

    return dto;
  }
Пример #2
0
  @Override
  @Transactional(readOnly = true)
  public String getFollowTwitterScreenNames(String followList, String userName) {
    if (followList != null && !followList.isEmpty()) {
      List<String> userList = Arrays.asList(followList.split(","));

      if (null == accessTokenStr || null == accessTokenSecretStr) {
        UserConnection userConnection = userConnectionService.fetchByCombinedUserName(userName);
        accessTokenStr = userConnection.getAccessToken();
        accessTokenSecretStr = userConnection.getSecret();
      }

      long[] userIdList = null;
      if (userList != null) {
        try {
          userIdList = new long[userList.size()];
          int j = 0;
          logger.info("Received string: " + followList + ", Split follow string: " + userList);
          for (String user : userList) {
            // logger.info("Looking at follow data: " + user);
            if (StringUtils.isNumeric(user.trim())) {
              try {
                userIdList[j] = Long.parseLong(user.trim());
                // logger.info("Going to fetch twitter userData for the following twitterID: " +
                // userIdList[j]);
                ++j;
              } catch (Exception ex) {
                logger.error("Exception in parsing string to number: ", ex);
              }
            }
          }
          userIdList = ArrayUtils.subarray(userIdList, 0, j);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      List<User> dataList = new ArrayList<User>();
      if (userIdList != null && userIdList.length > 0) {
        dataList.addAll(getUserDataFromTwitterID(userIdList, userName));
      }

      if (!dataList.isEmpty()) {
        StringBuffer followScreenNames = new StringBuffer();
        for (User user : dataList) {
          followScreenNames.append(user.getScreenName()).append(",");
        }
        followScreenNames.deleteCharAt(followScreenNames.lastIndexOf(","));
        // logger.info("Created follow twitterID list: " + followScreenNames.toString());
        return followScreenNames.toString();
      } else {
        return null;
      }
    }
    return null;
  }
Пример #3
0
  @Override
  public JSONArray searchFacebookProfiles(
      String keyword, Integer offset, Integer limit, UserAccount userEntity) {
    UserConnection userConnection =
        userConnectionService.fetchByCombinedUserName(userEntity.getUserName());
    userConnection.getAccessToken();
    try {
      Client client = ClientBuilder.newBuilder().register(JacksonFeature.class).build();
      WebTarget webResource =
          client.target(
              fetchMainUrl
                  + "/"
                  + SocialSignInProvider.FACEBOOK
                  + "/searchProfiles"
                  + "?offset="
                  + offset
                  + "&limit="
                  + limit
                  + "&keyword="
                  + URLEncoder.encode(keyword, "UTF-8"));

      ObjectMapper objectMapper = JacksonWrapper.getObjectMapper();

      Response clientResponse =
          webResource
              .request(MediaType.APPLICATION_JSON)
              .post(Entity.json(userConnection.getAccessToken()), Response.class);

      String jsonString = clientResponse.readEntity(String.class);
      JSONParser parser = new JSONParser();
      JSONObject jsonResponse = (JSONObject) parser.parse(jsonString);
      JSONArray response =
          objectMapper.readValue(jsonResponse.get("entity").toString(), JSONArray.class);
      return response;
    } catch (Exception e) {
      logger.error("Exception while searching facebok profiles", e);
    }
    return null;
  }