use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class KBArticleLocalServiceImpl method addKBArticle.
@Override
public KBArticle addKBArticle(long userId, long parentResourceClassNameId, long parentResourcePrimKey, String title, String urlTitle, String content, String description, String sourceURL, String[] sections, String[] selectedFileNames, ServiceContext serviceContext) throws PortalException, SystemException {
// KB article
User user = userPersistence.findByPrimaryKey(userId);
long groupId = serviceContext.getScopeGroupId();
double priority = getPriority(groupId, parentResourcePrimKey);
Date now = new Date();
validate(title, content, sourceURL);
validateParent(parentResourceClassNameId, parentResourcePrimKey);
long kbFolderId = KnowledgeBaseUtil.getKBFolderId(parentResourceClassNameId, parentResourcePrimKey);
validateUrlTitle(groupId, kbFolderId, urlTitle);
long kbArticleId = counterLocalService.increment();
long resourcePrimKey = counterLocalService.increment();
long rootResourcePrimKey = getRootResourcePrimKey(resourcePrimKey, parentResourceClassNameId, parentResourcePrimKey);
KBArticle kbArticle = kbArticlePersistence.create(kbArticleId);
kbArticle.setUuid(serviceContext.getUuid());
kbArticle.setResourcePrimKey(resourcePrimKey);
kbArticle.setGroupId(groupId);
kbArticle.setCompanyId(user.getCompanyId());
kbArticle.setUserId(user.getUserId());
kbArticle.setUserName(user.getFullName());
kbArticle.setCreateDate(serviceContext.getCreateDate(now));
kbArticle.setModifiedDate(serviceContext.getModifiedDate(now));
kbArticle.setRootResourcePrimKey(rootResourcePrimKey);
kbArticle.setParentResourceClassNameId(parentResourceClassNameId);
kbArticle.setParentResourcePrimKey(parentResourcePrimKey);
kbArticle.setKbFolderId(kbFolderId);
kbArticle.setVersion(KBArticleConstants.DEFAULT_VERSION);
kbArticle.setTitle(title);
kbArticle.setUrlTitle(getUniqueUrlTitle(groupId, kbFolderId, kbArticleId, title, urlTitle));
kbArticle.setContent(content);
kbArticle.setDescription(description);
kbArticle.setPriority(priority);
kbArticle.setSections(StringUtil.merge(AdminUtil.escapeSections(sections)));
kbArticle.setViewCount(0);
kbArticle.setLatest(true);
kbArticle.setMain(false);
kbArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
kbArticle.setSourceURL(sourceURL);
kbArticlePersistence.update(kbArticle);
if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
addKBArticleResources(kbArticle, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
} else {
addKBArticleResources(kbArticle, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
}
// Asset
updateKBArticleAsset(userId, kbArticle, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
// Attachments
addKBArticleAttachments(userId, kbArticle, selectedFileNames);
// Workflow
WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId, KBArticle.class.getName(), resourcePrimKey, kbArticle, serviceContext);
return kbArticle;
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class KBCommentLocalServiceImpl method addKBComment.
@Override
public KBComment addKBComment(long userId, long classNameId, long classPK, String content, int userRating, ServiceContext serviceContext) throws PortalException, SystemException {
// KB comment
User user = userPersistence.findByPrimaryKey(userId);
long groupId = serviceContext.getScopeGroupId();
Date now = new Date();
validate(content);
long kbCommentId = counterLocalService.increment();
KBComment kbComment = kbCommentPersistence.create(kbCommentId);
kbComment.setUuid(serviceContext.getUuid());
kbComment.setGroupId(groupId);
kbComment.setCompanyId(user.getCompanyId());
kbComment.setUserId(user.getUserId());
kbComment.setUserName(user.getFullName());
kbComment.setCreateDate(serviceContext.getCreateDate(now));
kbComment.setModifiedDate(serviceContext.getModifiedDate(now));
kbComment.setClassNameId(classNameId);
kbComment.setClassPK(classPK);
kbComment.setContent(content);
kbComment.setUserRating(userRating);
kbComment.setStatus(KBCommentConstants.STATUS_NEW);
kbCommentPersistence.update(kbComment);
// Social
JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
putTitle(extraDataJSONObject, kbComment);
socialActivityLocalService.addActivity(userId, kbComment.getGroupId(), KBComment.class.getName(), kbCommentId, AdminActivityKeys.ADD_KB_COMMENT, extraDataJSONObject.toString(), 0);
// Subscriptions
notifySubscribers(kbComment, serviceContext);
return kbComment;
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class KBTemplateLocalServiceImpl method addKBTemplate.
@Override
public KBTemplate addKBTemplate(long userId, String title, String content, ServiceContext serviceContext) throws PortalException, SystemException {
// KB template
User user = userPersistence.findByPrimaryKey(userId);
long groupId = serviceContext.getScopeGroupId();
Date now = new Date();
validate(title, content);
long kbTemplateId = counterLocalService.increment();
KBTemplate kbTemplate = kbTemplatePersistence.create(kbTemplateId);
kbTemplate.setUuid(serviceContext.getUuid());
kbTemplate.setGroupId(groupId);
kbTemplate.setCompanyId(user.getCompanyId());
kbTemplate.setUserId(user.getUserId());
kbTemplate.setUserName(user.getFullName());
kbTemplate.setCreateDate(serviceContext.getCreateDate(now));
kbTemplate.setModifiedDate(serviceContext.getModifiedDate(now));
kbTemplate.setTitle(title);
kbTemplate.setContent(content);
kbTemplatePersistence.update(kbTemplate);
// Resources
resourceLocalService.addModelResources(kbTemplate, serviceContext);
// Social
JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
extraDataJSONObject.put("title", kbTemplate.getTitle());
socialActivityLocalService.addActivity(userId, groupId, KBTemplate.class.getName(), kbTemplateId, AdminActivityKeys.ADD_KB_TEMPLATE, extraDataJSONObject.toString(), 0);
return kbTemplate;
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class LiferayOAuthStore method setTokenInfo.
public void setTokenInfo(SecurityToken securityToken, ConsumerInfo consumerInfo, String serviceName, String tokenName, TokenInfo tokenInfo) throws GadgetException {
long userId = GetterUtil.getLong(securityToken.getViewerId());
User user = null;
try {
user = UserLocalServiceUtil.getUser(userId);
} catch (Exception e) {
throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
}
Gadget gadget = null;
try {
gadget = GadgetLocalServiceUtil.fetchGadget(user.getCompanyId(), securityToken.getAppUrl());
} catch (SystemException se) {
throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, se);
}
String gadgetKey = StringPool.BLANK;
if (gadget == null) {
gadgetKey = GadgetConstants.toAdhocGadgetKey(securityToken.getModuleId());
} else {
gadgetKey = GadgetConstants.toPublishedGadgetKey(gadget.getGadgetId());
}
try {
OAuthTokenLocalServiceUtil.addOAuthToken(userId, gadgetKey, serviceName, securityToken.getModuleId(), tokenInfo.getAccessToken(), tokenName, tokenInfo.getTokenSecret(), tokenInfo.getSessionHandle(), tokenInfo.getTokenExpireMillis());
} catch (Exception e) {
throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
}
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class LiferayActivityService method getThemeDisplay.
protected ThemeDisplay getThemeDisplay(SecurityToken securityToken) throws Exception {
long userIdLong = GetterUtil.getLong(securityToken.getViewerId());
User user = UserLocalServiceUtil.getUserById(userIdLong);
Company company = CompanyLocalServiceUtil.getCompanyById(user.getCompanyId());
ThemeDisplay themeDisplay = new ThemeDisplay();
themeDisplay.setCompany(company);
themeDisplay.setLocale(user.getLocale());
themeDisplay.setUser(user);
return themeDisplay;
}
Aggregations