Search in sources :

Example 61 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class KBCommentLocalServiceImpl method notifySubscribers.

protected void notifySubscribers(KBComment kbComment, ServiceContext serviceContext) throws PortalException, SystemException {
    PortletPreferences preferences = portletPreferencesLocalService.getPreferences(kbComment.getCompanyId(), kbComment.getGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, PortletKeys.KNOWLEDGE_BASE_ADMIN, null);
    if (!AdminUtil.isSuggestionStatusChangeNotificationEnabled(kbComment.getStatus(), preferences)) {
        return;
    }
    String fromName = AdminUtil.getEmailFromName(preferences, serviceContext.getCompanyId());
    String fromAddress = AdminUtil.getEmailFromAddress(preferences, kbComment.getCompanyId());
    String subject = AdminUtil.getEmailKBArticleSuggestionNotificationSubject(kbComment.getStatus(), preferences);
    String body = AdminUtil.getEmailKBArticleSuggestionNotificationBody(kbComment.getStatus(), preferences);
    KBArticle kbArticle = kbArticleLocalService.getLatestKBArticle(kbComment.getClassPK(), WorkflowConstants.STATUS_APPROVED);
    String kbArticleContent = StringUtil.replace(kbArticle.getContent(), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + serviceContext.getPortalURL() + "/", "src=\"" + serviceContext.getPortalURL() + "/" });
    SubscriptionSender subscriptionSender = new AdminSubscriptionSender(kbArticle, serviceContext);
    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(kbArticle.getCompanyId());
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", kbArticleContent, false);
    subscriptionSender.setContextAttribute("[$COMMENT_CONTENT$]", kbComment.getContent(), false);
    subscriptionSender.setContextAttribute("[$COMMENT_CREATE_DATE$]", getFormattedKBCommentCreateDate(kbComment, serviceContext), false);
    subscriptionSender.setContextUserPrefix("ARTICLE");
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("kb_article", kbArticle.getKbArticleId());
    subscriptionSender.setPortletId(serviceContext.getPortletId());
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(kbArticle.getGroupId());
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(kbArticle.getUserId());
    User user = userLocalService.getUser(kbComment.getUserId());
    subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());
    subscriptionSender.flushNotificationsAsync();
}
Also used : User(com.liferay.portal.model.User) KBArticle(com.liferay.knowledgebase.model.KBArticle) AdminSubscriptionSender(com.liferay.knowledgebase.admin.util.AdminSubscriptionSender) PortletPreferences(javax.portlet.PortletPreferences) AdminSubscriptionSender(com.liferay.knowledgebase.admin.util.AdminSubscriptionSender) SubscriptionSender(com.liferay.portal.util.SubscriptionSender)

Example 62 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class KBFolderLocalServiceImpl method addKBFolder.

@Override
public KBFolder addKBFolder(long userId, long groupId, long parentResourceClassNameId, long parentResourcePrimKey, String name, String description, ServiceContext serviceContext) throws PortalException, SystemException {
    // KB folder
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    validateName(groupId, parentResourcePrimKey, name);
    validateParent(parentResourceClassNameId, parentResourcePrimKey);
    long kbFolderId = counterLocalService.increment();
    KBFolder kbFolder = kbFolderPersistence.create(kbFolderId);
    kbFolder.setUuid(serviceContext.getUuid());
    kbFolder.setGroupId(groupId);
    kbFolder.setCompanyId(user.getCompanyId());
    kbFolder.setUserId(userId);
    kbFolder.setUserName(user.getFullName());
    kbFolder.setCreateDate(now);
    kbFolder.setModifiedDate(now);
    kbFolder.setParentKBFolderId(parentResourcePrimKey);
    kbFolder.setName(name);
    kbFolder.setUrlTitle(getUniqueUrlTitle(groupId, parentResourcePrimKey, kbFolderId, name));
    kbFolder.setDescription(description);
    kbFolderPersistence.update(kbFolder);
    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
        addKBFolderResources(kbFolder, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addKBFolderResources(kbFolder, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }
    return kbFolder;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) User(com.liferay.portal.model.User) Date(java.util.Date)

Example 63 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class KBArticleLocalServiceImpl method updateKBArticle.

@Override
public KBArticle updateKBArticle(long userId, long resourcePrimKey, String title, String content, String description, String sourceURL, String[] sections, String[] selectedFileNames, long[] removeFileEntryIds, ServiceContext serviceContext) throws PortalException, SystemException {
    // KB article
    User user = userPersistence.findByPrimaryKey(userId);
    validate(title, content, sourceURL);
    KBArticle oldKBArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
    int oldVersion = oldKBArticle.getVersion();
    KBArticle kbArticle = null;
    if (oldKBArticle.isApproved()) {
        long kbArticleId = counterLocalService.increment();
        kbArticle = kbArticlePersistence.create(kbArticleId);
        kbArticle.setUuid(serviceContext.getUuid());
        kbArticle.setResourcePrimKey(oldKBArticle.getResourcePrimKey());
        kbArticle.setGroupId(oldKBArticle.getGroupId());
        kbArticle.setCompanyId(user.getCompanyId());
        kbArticle.setUserId(user.getUserId());
        kbArticle.setUserName(user.getFullName());
        kbArticle.setCreateDate(oldKBArticle.getCreateDate());
        kbArticle.setRootResourcePrimKey(oldKBArticle.getRootResourcePrimKey());
        kbArticle.setParentResourceClassNameId(oldKBArticle.getParentResourceClassNameId());
        kbArticle.setParentResourcePrimKey(oldKBArticle.getParentResourcePrimKey());
        kbArticle.setKbFolderId(oldKBArticle.getKbFolderId());
        kbArticle.setVersion(oldVersion + 1);
        kbArticle.setUrlTitle(oldKBArticle.getUrlTitle());
        kbArticle.setPriority(oldKBArticle.getPriority());
        kbArticle.setViewCount(oldKBArticle.getViewCount());
    } else {
        kbArticle = oldKBArticle;
    }
    if (oldKBArticle.isPending()) {
        kbArticle.setStatus(WorkflowConstants.STATUS_PENDING);
    } else {
        kbArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
    }
    kbArticle.setModifiedDate(serviceContext.getModifiedDate(null));
    kbArticle.setTitle(title);
    kbArticle.setContent(content);
    kbArticle.setDescription(description);
    kbArticle.setSourceURL(sourceURL);
    kbArticle.setSections(StringUtil.merge(AdminUtil.escapeSections(sections)));
    kbArticle.setLatest(true);
    kbArticle.setMain(false);
    kbArticlePersistence.update(kbArticle);
    if (oldKBArticle.isApproved()) {
        oldKBArticle.setLatest(false);
        kbArticlePersistence.update(oldKBArticle);
    }
    if ((serviceContext.getGroupPermissions() != null) || (serviceContext.getGuestPermissions() != null)) {
        updateKBArticleResources(kbArticle, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }
    // Asset
    updateKBArticleAsset(userId, kbArticle, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    // Attachments
    addKBArticleAttachments(userId, kbArticle, selectedFileNames);
    removeKBArticleAttachments(removeFileEntryIds);
    // Workflow
    WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), kbArticle.getGroupId(), userId, KBArticle.class.getName(), resourcePrimKey, kbArticle, serviceContext);
    return kbArticle;
}
Also used : User(com.liferay.portal.model.User) KBArticle(com.liferay.knowledgebase.model.KBArticle)

Example 64 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class UserLocalServiceImpl method updateLastLogin.

/**
 * Updates the user's last login with the current time and the IP address.
 *
 * @param  userId the primary key of the user
 * @param  loginIP the IP address the user logged in from
 * @return the user
 * @throws PortalException if a user with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public User updateLastLogin(long userId, String loginIP) throws PortalException, SystemException {
    User user = userPersistence.findByPrimaryKey(userId);
    Date lastLoginDate = user.getLoginDate();
    if (lastLoginDate == null) {
        lastLoginDate = new Date();
    }
    user.setLoginDate(new Date());
    user.setLoginIP(loginIP);
    user.setLastLoginDate(lastLoginDate);
    user.setLastLoginIP(user.getLoginIP());
    user.setFailedLoginAttempts(0);
    userPersistence.update(user);
    return user;
}
Also used : User(com.liferay.portal.model.User) Date(java.util.Date)

Example 65 with User

use of com.liferay.portal.model.User in project liferay-ide by liferay.

the class UserLocalServiceImpl method updateReminderQuery.

/**
 * Updates the user's password reset question and answer.
 *
 * @param  userId the primary key of the user
 * @param  question the user's new password reset question
 * @param  answer the user's new password reset answer
 * @return the user
 * @throws PortalException if a user with the primary key could not be found
 *         or if the new question or answer were invalid
 * @throws SystemException if a system exception occurred
 */
@Override
public User updateReminderQuery(long userId, String question, String answer) throws PortalException, SystemException {
    validateReminderQuery(question, answer);
    User user = userPersistence.findByPrimaryKey(userId);
    user.setReminderQueryQuestion(question);
    user.setReminderQueryAnswer(answer);
    userPersistence.update(user);
    return user;
}
Also used : User(com.liferay.portal.model.User)

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