/** * Will convert an {@code com.sola.instagram.model.User} model to our cassandra model, {@code * com.andrewzurn.instagram.analyzer.model.SourceUser}, by extrapulating and calculating * information based on the user's list of {@code * com.andrewzurn.instagram.analyzer.model.RawUserMedia}. An optional updateDate can be passed in, * for the case that we already have the User in our cassandra cluster, and need to merely update * it's values. * * @param user the user to convert * @param userRecentMedia the user's converted media * @return the converted {@code com.andrewzurn.instagram.analyzer.model.SourceUser} * @throws Exception if an error occures while accessing the {@code * come.sola.isntagram.model.User} object. */ private SourceUser convertToSourceUser(User user, List<RawUserMedia> userRecentMedia) throws Exception { // gather engagement ratings for user float averagedEngagementRating = 0; float mostRecentMediaEngagementRating = 0; try { averagedEngagementRating = analyticsUtils.averagedEngagementRating(userRecentMedia, user.getFollowerCount()); mostRecentMediaEngagementRating = analyticsUtils.averagedEngagementRating( userRecentMedia.subList(0, 1), user.getFollowerCount()); } catch (Exception e) { // this was more than likely caused by calling the getFollowerCount() method throw new InstagramApiException("ERROR while creating the engagement ratings.\n" + e); } // gather the impression and trending info for user float trendingRating = analyticsUtils.getTrendingRating(userRecentMedia); boolean trending = trendingRating > 0.0; // gather location information and recent media ids List<String> locations = this.mapLocations(userRecentMedia); List<String> recentMediaIds = this.mapRecentMediaIds(userRecentMedia); Date createdTime = new Date(); Date updatedTime = new Date(); return SourceUser.build( user, averagedEngagementRating, mostRecentMediaEngagementRating, trendingRating, trending, locations, recentMediaIds, createdTime, updatedTime, false, null); }
public SourceUser createSourceUser(User user, List<RawUserMedia> userMedias) throws DataModelConverterException { SourceUser sourceUser; try { sourceUser = this.convertToSourceUser(user, userMedias); } catch (Exception e) { throw new DataModelConverterException( String.format( "could not convert the user media to %s.", user.getClass().getCanonicalName().toString())); } return sourceUser; }