@Override public MicroblogsEntry addMicroblogsEntry( long userId, long creatorClassNameId, long creatorClassPK, String content, int type, long parentMicroblogsEntryId, int socialRelationType, ServiceContext serviceContext) throws PortalException { // Microblogs entry User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); validate(type, parentMicroblogsEntryId); long microblogsEntryId = counterLocalService.increment(); if (parentMicroblogsEntryId == 0) { parentMicroblogsEntryId = microblogsEntryId; } MicroblogsEntry microblogsEntry = microblogsEntryPersistence.create(microblogsEntryId); microblogsEntry.setCompanyId(user.getCompanyId()); microblogsEntry.setUserId(user.getUserId()); microblogsEntry.setUserName(user.getFullName()); microblogsEntry.setCreateDate(now); microblogsEntry.setModifiedDate(now); microblogsEntry.setCreatorClassNameId(creatorClassNameId); microblogsEntry.setCreatorClassPK(creatorClassPK); microblogsEntry.setContent(content); microblogsEntry.setType(type); microblogsEntry.setParentMicroblogsEntryId(parentMicroblogsEntryId); microblogsEntry.setSocialRelationType(socialRelationType); microblogsEntryPersistence.update(microblogsEntry); // Resources resourceLocalService.addModelResources(microblogsEntry, serviceContext); // Asset updateAsset( microblogsEntry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames()); return microblogsEntry; }
/** * Converts the soap model instance into a normal model instance. * * @param soapModel the soap model instance to convert * @return the normal model instance */ public static MicroblogsEntry toModel(MicroblogsEntrySoap soapModel) { if (soapModel == null) { return null; } MicroblogsEntry model = new MicroblogsEntryImpl(); model.setMicroblogsEntryId(soapModel.getMicroblogsEntryId()); model.setCompanyId(soapModel.getCompanyId()); model.setUserId(soapModel.getUserId()); model.setUserName(soapModel.getUserName()); model.setCreateDate(soapModel.getCreateDate()); model.setModifiedDate(soapModel.getModifiedDate()); model.setCreatorClassNameId(soapModel.getCreatorClassNameId()); model.setCreatorClassPK(soapModel.getCreatorClassPK()); model.setContent(soapModel.getContent()); model.setType(soapModel.getType()); model.setParentMicroblogsEntryId(soapModel.getParentMicroblogsEntryId()); model.setSocialRelationType(soapModel.getSocialRelationType()); return model; }
@Override public MicroblogsEntry addMicroblogsEntry( long userId, String content, int type, long parentMicroblogsEntryId, int socialRelationType, ServiceContext serviceContext) throws PortalException { // Microblogs entry User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); validate(type, parentMicroblogsEntryId); long microblogsEntryId = counterLocalService.increment(); if (parentMicroblogsEntryId == 0) { parentMicroblogsEntryId = microblogsEntryId; } MicroblogsEntry microblogsEntry = microblogsEntryPersistence.create(microblogsEntryId); microblogsEntry.setCompanyId(user.getCompanyId()); microblogsEntry.setUserId(user.getUserId()); microblogsEntry.setUserName(user.getFullName()); microblogsEntry.setCreateDate(now); microblogsEntry.setModifiedDate(now); microblogsEntry.setCreatorClassNameId(classNameLocalService.getClassNameId(User.class)); microblogsEntry.setCreatorClassPK(user.getUserId()); microblogsEntry.setContent(content); microblogsEntry.setType(type); microblogsEntry.setParentMicroblogsEntryId(parentMicroblogsEntryId); microblogsEntry.setSocialRelationType(socialRelationType); microblogsEntryPersistence.update(microblogsEntry); // Resources resourceLocalService.addModelResources(microblogsEntry, serviceContext); // Asset updateAsset( microblogsEntry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames()); // Social int activityKey = MicroblogsActivityKeys.ADD_ENTRY; if (type == MicroblogsEntryConstants.TYPE_REPLY) { activityKey = MicroblogsActivityKeys.REPLY_ENTRY; } else if (type == MicroblogsEntryConstants.TYPE_REPOST) { activityKey = MicroblogsActivityKeys.REPOST_ENTRY; } JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("content", microblogsEntry.getContent()); extraDataJSONObject.put("parentMicroblogsEntryId", parentMicroblogsEntryId); socialActivityLocalService.addActivity( userId, 0, MicroblogsEntry.class.getName(), microblogsEntryId, activityKey, extraDataJSONObject.toString(), microblogsEntry.getParentMicroblogsEntryUserId()); // Notification subscribeUsers(microblogsEntry, serviceContext); sendNotificationEvent(microblogsEntry, serviceContext); return microblogsEntry; }