/* * 너무 복잡하면 힘들다. * 여기서 하던 filtering은 밖으로 뺀다. * 그리고 여기서 처리하던 limit, ioexception, 그외 exception도 밖으로 뺀다. * db insertion도 밖으로 뺀다. * 즉, 여기서는 무조건 값만 받고, 자연스럽게 또는 exception에 의해 return한다. * 2차 exception은 애초에 여기서 바로 다시 시도하는 것이 아니기 때문에 고려할 필요 없다. * * result, exception 정리를 위해 result exception throw로 return 단일화한다. */ public Result getListFromTag(String tag, Range<Long> range) { Result.Status status = Result.Status.Empty; // default는 not exception으로서 entire range travelled를 뜻한다. List<MediaFeedData> result = new ArrayList<MediaFeedData>(); // 값 유지를 위해 공간은 만들어두어야 한다. TODO: 다시 확인. // TODO: RANGE NULL CHECK 일단 뺐는데, 필요할지 확인. long from = range.getMinimum(); long to = range.getMaximum(); try { // library가 object 구조를 좀 애매하게 해놓아서, 바로 loop 하기보다, 1 cycle은 직접 작성해주는 구조가 되었다. TagMediaFeed list = instagram.getRecentMediaTags(tag, null, String.valueOf(to)); Pagination page = list.getPagination(); List<MediaFeedData> data = list.getData(); if (!addFilteredData(result, data, from, to)) { // filter가 안되어야만 다음으로 넘어가고, 아니면 그냥 그대로 끝이다. if (page.hasNextPage()) { MediaFeed nextList = instagram.getRecentMediaNextPage(page); Pagination nextPage = nextList.getPagination(); List<MediaFeedData> nextData = nextList.getData(); while (true) { if (!addFilteredData( result, nextData, from, to)) { // filter가 안되어야만 다음으로 넘어가고, 아니면 그냥 그대로 끝이다. if (result != null && result.size() > BATCH) { throw new Exception(); // TODO: 밑으로 내려가는지 확인. } if (nextPage.hasNextPage()) { nextList = instagram.getRecentMediaNextPage(nextPage); nextPage = nextList.getPagination(); nextData = nextList.getData(); } else { break; } } else { // if 자체가 while 안에서 실행되어야 되기 때문에 이렇게 else에서 break 걸어줘야 한다. break; } } } } } catch (Exception e) { // 아래의 단계를 거치게 해야 task loop에서의 처리가 깔끔해진다. status = Result.Status.Normal; // 기본적으로 normal. if (e instanceof InstagramException) { // 만약 insta exception이라면 exceed로 간주. status = Result.Status.Exceed; } if (result != null && !result.isEmpty()) { // 그런데 만약 full travel이라면 empty로 간주. long id = extractId(result.get(result.size() - 1).getId()); if (id == range.getMinimum()) { status = Result.Status.Empty; } } } return new Result(status, result); }
/** * Get the next page of tagged media objects from a previously executed request * * @param pagination * @throws InstagramException */ public TagMediaFeed getTagMediaInfoNextPage(Pagination pagination) throws InstagramException { return createInstagramObject( Verbs.GET, TagMediaFeed.class, StringUtils.removeStart(pagination.getNextUrl(), config.getApiURL()), null); }
/** * Get the next page of user feed objects from a previously executed request * * @param pagination * @throws InstagramException */ public UserFeed getUserFeedInfoNextPage(Pagination pagination) throws InstagramException { return createInstagramObject( Verbs.GET, UserFeed.class, StringUtils.removeStart(pagination.getNextUrl(), Constants.API_URL), null); }
public static String getPagination(TagMediaFeed mediaFeed) { Pagination pa = mediaFeed.getPagination(); if (pa != null) { Logger.info(" Pagination.getMinTagId : " + pa.getMinTagId()); Logger.info(" Pagination.getNextMinId : " + pa.getNextMinId()); Logger.info(" Pagination.getNextMaxId : " + pa.getNextMaxId()); Logger.info(" Pagination.getNextMaxTagId : " + pa.getNextMaxTagId()); Logger.info(" Pagination.getNextUrl : " + pa.getNextUrl()); Logger.info(" ----------------------------------------------"); } // if return pa.getNextMaxId(); } // getPagination