* @param activity
* @return
*/
public static ActivityModel putActivity(Activity activity, UserModel userModel) throws DataInvalidException {
ActivityModel model = new ActivityModel();
// -------------------------------------------------------
// 基本情報の設定
// -------------------------------------------------------
// key
model.setKey(createKey(activity.getId()));
// 公開フラグ
model.setPublicFlg(true);
// アクティビティタイプ(post or share)
if(!activity.getVerb().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_POST)
&& !activity.getVerb().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_SHARE)) {
throw new DataInvalidException();
}else {
model.setVerb(new Category(activity.getVerb()));
}
// タイトル
if(activity.getTitle() != null && !activity.getTitle().trim().isEmpty()) {
String title = activity.getTitle();
model.setTitle(new Text(title));
}
// 公開日
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(activity.getPublished().getValue());
calendar.add(Calendar.HOUR, 9);
model.setPublished(calendar.getTime());
// 更新日
model.setUpdated(new Date(activity.getUpdated().getValue()));
// URL
model.setUrl(new Text(activity.getUrl()));
// コンテントの設定
if(activity.getObject().getContent() != null
&& !activity.getObject().getContent().trim().isEmpty()) {
String content = activity.getObject().getContent();
model.setContent(new Text(content));
}
// -------------------------------------------------------
// 添付情報の設定
// -------------------------------------------------------
List<Attachments> attachmentsList = activity.getObject().getAttachments();
if(attachmentsList != null && attachmentsList.size() > 0) {
// 添付情報の一つ目のみを対象とする
Attachments attachment = attachmentsList.get(0);
if(attachment.getObjectType() == null) {
throw new DataInvalidException();
}
// 添付フラグをTrueに設定
model.setAttachmentsFlg(true);
// 添付情報のタイプ
if(attachment.getObjectType() != null) {
if(attachment.getObjectType().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_PHOTO)
|| attachment.getObjectType().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_VIDEO)
|| attachment.getObjectType().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_ARTICLE)
|| attachment.getObjectType().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_ALBUM)) {
model.setAttachmentsType(new Category(attachment.getObjectType()));
}else {
throw new DataInvalidException();
}
}else {
throw new DataInvalidException();
}
// 添付情報の表示名
if(attachment.getDisplayName() != null && !attachment.getDisplayName().isEmpty()) {
model.setAttachmentsDisplayName(new Text(attachment.getDisplayName()));
}
// 添付情報のコンテンツ
if(attachment.getContent() != null && !attachment.getContent().isEmpty()) {
String content = attachment.getContent();
model.setAttachmentsContent(new Text(content));
}
// 添付情報のURL
if(attachment.getUrl() != null) {
model.setAttachmentsUrl(new Text(attachment.getUrl()));
}
// 添付情報のイメージURL
if(attachment.getImage() != null && attachment.getImage().getUrl() != null) {
model.setAttachmentsImageUrl(new Text(attachment.getImage().getUrl()));
}
// 添付情報のFULLイメージURL
if(attachment.getFullImage() != null && attachment.getFullImage().getUrl() != null) {
model.setAttachmentsFullImageUrl(new Text(attachment.getFullImage().getUrl()));
}
// 動画情報(添付情報は動画の場合)
if(attachment.getEmbed() != null) {
if(attachment.getImage() != null && attachment.getImage().getUrl() != null) {
model.setAttachmentsImageUrl(new Text(attachment.getImage().getUrl()));
}
model.setEmbedType(attachment.getEmbed().getType());
model.setEmbedUrl(new Text(attachment.getEmbed().getUrl()));
}
// アルバムの場合(アクティビティに画像を設定 twtter POSTを簡単にするため)
if(attachment.getThumbnails() != null && attachment.getThumbnails().size() > 0) {
Thumbnails thumbnails = attachment.getThumbnails().get(0);
if(thumbnails != null && thumbnails.getImage() != null) {
model.setAttachmentsImageUrl(new Text(thumbnails.getImage().getUrl()));
}
}
}
// -------------------------------------------------------
// シェアの場合の元情報
// -------------------------------------------------------
if(activity.getVerb().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_SHARE)
&& activity.getObject().getActor() != null) {
model.setShareActorFlg(true);
model.setActorId(activity.getObject().getActor().getId());
model.setActorDisplayName(activity.getObject().getActor().getDisplayName());
model.setActorUrl(new Text(activity.getObject().getActor().getUrl()));
if(activity.getObject().getActor().getImage() != null && activity.getObject().getActor().getImage().getUrl() != null) {
model.setActorImageUrl(new Text(activity.getObject().getActor().getImage().getUrl()));
}
// 追加コメント
if(activity.getAnnotation() != null
&& !activity.getAnnotation().trim().isEmpty()) {
String content = activity.getAnnotation();
model.setAnnotation(new Text(content));
}
}
// -------------------------------------------------------
// 親の設定
// -------------------------------------------------------
// userModelの設定
model.getUserModelRef().setModel(userModel);
// DateModelの設定
DateModel dateModel = DateService.getOrNull(userModel, model.getPublished());
if(dateModel == null) {
dateModel = DateService.put(userModel, model.getPublished());
}
model.getDateModelRef().setModel(dateModel);
// アクティビティの更新チェック日時を更新
model.setUpdateCheckDate(new Date());
// アクティビティ
return putActivity(userModel, dateModel, model);
}