/** * 短縮URLの取得 * * @return * @throws Exception */ public String getShortUrl(UserModel userModel, ActivityModel activityModel) throws Exception { // アプリ承認オブジェクトの生成 GoogleCredential credential = new GoogleCredential.Builder() .setJsonFactory(JSON_FACTORY) .setTransport(TRANSPORT) .setClientSecrets( Constants.GOOGLE_PROJECT_CLIENT_ID, Constants.GOOGLE_PROJECT_CLIENT_SECRET) .build() .setRefreshToken(userModel.getRefreshToken()); // Urlshortener オブジェクトの生成 Urlshortener.Builder builder = new Urlshortener.Builder(TRANSPORT, JSON_FACTORY, credential); builder.setApplicationName(Constants.GOOGLE_APPLICATION_NAME); Urlshortener urlshortener = builder.build(); // URLの設定 Url url = new Url(); url.setLongUrl( "http://plucial.com/u/" + userModel.getKey().getName() + "/a/" + activityModel.getKey().getName()); // 短縮URLの発行 url = urlshortener.url().insert(url).execute(); return url.getId(); }
@Override protected Navigation execute( UserModel acsessUserModel, UserModel loginUserModel, boolean isLogin, boolean isSmartPhone) throws Exception { String activityId = asString("activityId"); ActivityModel activityModel = ActivityService.getActivity(activityId); ArrayList<ActivityModel> activityList = new ArrayList<ActivityModel>(); if (activityModel != null) { activityList.add(activityModel); } // リクエストスコープの設定 requestScope("activityList", activityList); if (activityModel != null) { if (activityModel.getTitleString() != null) { requestScope( "pageTitle", activityModel.getTitleString() + " - " + acsessUserModel.getDisplayName()); } else if (activityModel.isAttachmentsFlg() && activityModel.getAttachmentsDisplayNameString() != null) { requestScope( "pageTitle", activityModel.getAttachmentsDisplayNameString() + " - " + acsessUserModel.getDisplayName()); } else { requestScope("pageTitle", "Google+での投稿 - " + acsessUserModel.getDisplayName()); } } return forward("/responsive/activity_only.jsp"); }
/** * Delete * * @param model * @return */ public static void delete(UserModel userModel) { // ユーザーのすべてのDateModelを取得 List<DateModel> dateModelList = userModel.getDateModelListRef().getModelList(); for (DateModel dateModel : dateModelList) { // DateModelに紐づくつべてのActivityModel を取得 List<ActivityModel> activityModelList = dateModel.getActivityModelListRef().getModelList(); for (ActivityModel activityModel : activityModelList) { // アクティビティの削除 ActivityService.delete(userModel, activityModel); } // DateModelの削除 DateService.delete(userModel, dateModel); } // URLリストの削除 UserUrlsService.deleteAll(userModel); userModelDao.delete(userModel.getKey()); // 自信のキャッシュをクリア Memcache.delete(userModel.getKey().toString()); // ユーザーカウントのキャッシュクリア clearUserCountAndListMemcache(); // グループのキャッシュをクリア clearGroupUserListMemcache(userModel.getGroup()); }
/** * 承認情報の生成 * * @param userModel * @param msg * @return */ private ConfigurationBuilder getConfigurationBuilder(UserModel userModel) throws Exception { // 承認情報の生成 ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(Constants.TWITTER_APP_API_KEY) .setOAuthConsumerSecret(Constants.TWITTER_APP_API_SECRET) .setOAuthAccessToken(userModel.getTwitterAccessToken()) .setOAuthAccessTokenSecret(userModel.getTwitterTokenSecret()); return cb; }
/** * ユーザーの取得 * * @param email * @return */ public static UserModel getOrNull(String userID) { Key key = createKey(userID); UserModel model = Memcache.get(key.toString()); if (model != null) return model; model = userModelDao.getOrNull(key); if (model != null) Memcache.put(model.getKey().toString(), model); return model; }
/** * PUT * * @param model * @return */ public static UserModel put(UserModel model) { // 永久化 userModelDao.put(model); // 自信のキャッシュをクリア Memcache.delete(model.getKey().toString()); // グループのキャッシュをクリア clearGroupUserListMemcache(model.getGroup()); return model; }
@Override protected Navigation run() throws Exception { UserModel acsessUserModel = null; UserModel loginUserModel = null; try { // アクセスしているページのユーザー情報を取得 acsessUserModel = getAccessUserModel(); S3QueryResultList<DateModel> dateModelList = DateService.getDateModelList(acsessUserModel, null); requestScope("date_cursor", dateModelList.getEncodedCursor()); requestScope("date_hasNext", String.valueOf(dateModelList.hasNext())); List<UserUrlsModel> profileUrlList = UserUrlsService.getUrlsListByType(acsessUserModel, Constants.USER_URLS_TYPE_PROFILE); List<UserUrlsModel> contributorUrlList = UserUrlsService.getUrlsListByType(acsessUserModel, Constants.USER_URLS_TYPE_CONTRIBUTOR); requestScope("acsessUserModel", acsessUserModel); requestScope("userId", acsessUserModel.getKey().getName()); requestScope("dateModelList", dateModelList); requestScope("profileUrlList", profileUrlList); requestScope("contributorUrlList", contributorUrlList); // ログインユーザー情報を取得 loginUserModel = getLoginUserModel(); requestScope("isLogin", String.valueOf(loginUserModel != null)); requestScope("loginUserModel", loginUserModel); // ログイン済みの場合 return execute(acsessUserModel, loginUserModel, true, isSmartPhone()); } catch (UserLoginException e) { // ログインしていない場合 return execute(acsessUserModel, loginUserModel, false, isSmartPhone()); } catch (NoContentsException e) { // アクセスページのユーザーが存在しない場合 return redirect("/error/404.html"); } }
/** * PUT * * @param email * @param userId * @param displayName * @param userImage * @param tagline * @param braggingRights * @param accessToken * @param refreshToken * @return */ public static UserModel put( String userId, String email, String url, String displayName, Image userImage, String tagline, String braggingRights, String aboutMe, Cover cover, String accessToken, String refreshToken) { UserModel userModel = new UserModel(); Key key = createKey(userId); userModel.setKey(key); // email if (email != null && !email.isEmpty()) { userModel.setEmail(email); } // url if (url != null && !url.isEmpty()) { userModel.setUrl(new Text(url)); } // 表示名 if (displayName != null && !displayName.isEmpty()) { userModel.setDisplayName(displayName); } // 写真 if (userImage != null && !userImage.isEmpty()) { userModel.setImageUrl(new Text(userImage.getUrl())); } // キャッチ if (tagline != null && !tagline.isEmpty()) { userModel.setTagline(new Text(tagline)); } // 特技 if (braggingRights != null && !braggingRights.isEmpty()) { userModel.setBraggingRights(new Text(braggingRights)); } // About Me if (aboutMe != null && !aboutMe.isEmpty()) { userModel.setAboutMe(new Text(aboutMe)); } // 背景画像url if (cover != null && cover.getCoverPhoto() != null && cover.getCoverPhoto().getUrl() != null && !cover.getCoverPhoto().getUrl().isEmpty()) { userModel.setCoverPhotoUrl(new Text(cover.getCoverPhoto().getUrl())); } // アクセストークン if (userImage != null && !accessToken.isEmpty()) { userModel.setAccessToken(accessToken); } // リフレッシュトークン if (refreshToken != null && !refreshToken.isEmpty()) { userModel.setRefreshToken(refreshToken); } // 新しいユーザーをまず(0〜9)グループに割り当てる Random rnd = new Random(); userModel.setGroup(rnd.nextInt(10)); // チェック日を設定 userModel.setUpdateCheckDate(new Date()); return put(userModel); }