Search in sources :

Example 26 with User

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;
}
Also used : User(com.liferay.portal.model.User) KBArticle(com.liferay.knowledgebase.model.KBArticle) Date(java.util.Date)

Example 27 with User

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;
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) User(com.liferay.portal.model.User) JSONObject(com.liferay.portal.kernel.json.JSONObject) Date(java.util.Date)

Example 28 with User

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;
}
Also used : User(com.liferay.portal.model.User) JSONObject(com.liferay.portal.kernel.json.JSONObject) KBTemplate(com.liferay.knowledgebase.model.KBTemplate) Date(java.util.Date)

Example 29 with User

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);
    }
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) User(com.liferay.portal.model.User) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetException(org.apache.shindig.gadgets.GadgetException) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetException(org.apache.shindig.gadgets.GadgetException)

Example 30 with User

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;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

User (com.liferay.portal.model.User)97 Date (java.util.Date)22 SystemException (com.liferay.portal.kernel.exception.SystemException)17 Group (com.liferay.portal.model.Group)15 PortalException (com.liferay.portal.kernel.exception.PortalException)13 Company (com.liferay.portal.model.Company)11 ServiceContext (com.liferay.portal.service.ServiceContext)11 Indexable (com.liferay.portal.kernel.search.Indexable)10 UserGroup (com.liferay.portal.model.UserGroup)10 IOException (java.io.IOException)9 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)8 EncryptorException (com.liferay.util.EncryptorException)7 Song (org.liferay.jukebox.model.Song)7 Contact (com.liferay.portal.model.Contact)6 PrincipalException (com.liferay.portal.security.auth.PrincipalException)6 Album (org.liferay.jukebox.model.Album)6 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)5 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)5 NoSuchImageException (com.liferay.portal.NoSuchImageException)5 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)5