/** * 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.setContent(soapModel.getContent()); model.setType(soapModel.getType()); model.setReceiverUserId(soapModel.getReceiverUserId()); model.setReceiverMicroblogsEntryId(soapModel.getReceiverMicroblogsEntryId()); model.setSocialRelationType(soapModel.getSocialRelationType()); return model; }
public MicroblogsEntry addMicroblogsEntry( long userId, String content, int type, long receiverUserId, long receiverMicroblogsEntryId, int socialRelationType, ServiceContext serviceContext) throws PortalException, SystemException { // Microblogs entry User user = userPersistence.findByPrimaryKey(userId); if (receiverUserId == 0) { receiverUserId = userId; } Date now = new Date(); validate(type, receiverMicroblogsEntryId); long microblogsEntryId = counterLocalService.increment(); MicroblogsEntry microblogsEntry = microblogsEntryPersistence.create(microblogsEntryId); microblogsEntry.setCompanyId(user.getCompanyId()); microblogsEntry.setUserId(user.getUserId()); microblogsEntry.setUserName(user.getFullName()); microblogsEntry.setCreateDate(now); microblogsEntry.setModifiedDate(now); microblogsEntry.setContent(content); microblogsEntry.setType(type); microblogsEntry.setReceiverUserId(receiverUserId); microblogsEntry.setReceiverMicroblogsEntryId(receiverMicroblogsEntryId); 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("receiverMicroblogsEntryId", receiverMicroblogsEntryId); SocialActivityLocalServiceUtil.addActivity( userId, 0, MicroblogsEntry.class.getName(), microblogsEntryId, activityKey, extraDataJSONObject.toString(), receiverUserId); // Notification if (type == MicroblogsEntryConstants.TYPE_REPLY) { sendNotificationEvent(microblogsEntry); } return microblogsEntry; }