Example usage for com.liferay.portal.kernel.service ServiceContext getPortletId

List of usage examples for com.liferay.portal.kernel.service ServiceContext getPortletId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ServiceContext getPortletId.

Prototype

public String getPortletId() 

Source Link

Document

Returns the ID of the current portlet if this service context is being passed as a parameter to a portlet.

Usage

From source file:org.sidate.qanda.service.impl.AnswerLocalServiceImpl.java

License:Open Source License

public Answer addAnswer(String text, long questionId, ServiceContext serviceContext) {

    String portletId = serviceContext.getPortletId();
    long groupId = serviceContext.getScopeGroupId();
    long answerId = counterLocalService.increment();
    Date createDate = serviceContext.getCreateDate();
    Date modifiedDate = serviceContext.getModifiedDate();
    String uuid = serviceContext.getUuid();
    long userId = serviceContext.getUserId();
    Answer answer = answerPersistence.create(answerId);

    answer.setUuid(uuid);/*www.  j  a v a 2 s .  c  o m*/
    answer.setCreateDate(createDate);
    answer.setModifiedDate(modifiedDate);
    answer.setUserId(userId);
    answer.setGroupId(groupId);
    answer.setExpandoBridgeAttributes(serviceContext);
    answer.setPortletId(portletId);

    answer.setQuestionId(questionId);

    answerPersistence.update(answer);

    try {
        resourceLocalService.addModelResources(answer, serviceContext);
        assetEntryLocalService.updateEntry(userId, answer.getGroupId(), answer.getCreateDate(),
                answer.getModifiedDate(), Answer.class.getName(), answer.getPrimaryKey(), answer.getUuid(), 0,
                serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), true, true, null, null,
                null, null, ContentTypes.TEXT_HTML, QuestionLocalServiceUtil.getQuestion(questionId).getTitle(),
                text, null, null, null, 0, 0, 0D);

        // Indexing
        Indexer<Answer> indexer = IndexerRegistryUtil.nullSafeGetIndexer(Answer.class);
        indexer.reindex(answer);

        socialActivityLocalService.addActivity(userId, groupId, Question.class.getName(), questionId, 2, "",
                QuestionLocalServiceUtil.getQuestion(questionId).getUserId());

    } catch (PortalException e) {
        e.printStackTrace();
    }

    return answer;
}

From source file:org.sidate.qanda.service.impl.QuestionLocalServiceImpl.java

License:Open Source License

public Question addQuestion(String title, String text, boolean isQuestionToProcedure, long ProcedureId,
        ServiceContext serviceContext) throws PortalException {

    String portletId = serviceContext.getPortletId();
    long groupId = serviceContext.getScopeGroupId();
    long questionId = counterLocalService.increment();
    Date createDate = serviceContext.getCreateDate();
    Date modifiedDate = serviceContext.getModifiedDate();
    String uuid = serviceContext.getUuid();
    Question question = questionPersistence.create(questionId);
    long userId = serviceContext.getUserId();

    question.setUserName(UserLocalServiceUtil.fetchUser(userId).getFullName());
    question.setUuid(uuid);//w  w w.j  a  va 2  s.  com
    question.setCreateDate(createDate);
    question.setModifiedDate(modifiedDate);
    question.setUserId(userId);
    question.setGroupId(groupId);
    question.setExpandoBridgeAttributes(serviceContext);
    question.setIsAnswered(false);
    question.setPortletId(portletId);
    question.setIsQuestionToProcedure(isQuestionToProcedure);
    question.setProcedureId(ProcedureId);

    questionPersistence.update(question);

    resourceLocalService.addModelResources(question, serviceContext);

    assetEntryLocalService.updateEntry(serviceContext.getUserId(), question.getGroupId(),
            question.getCreateDate(), question.getModifiedDate(), Question.class.getName(),
            question.getPrimaryKey(), question.getUuid(), 0, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), true, true, null, null, null, null, ContentTypes.TEXT_HTML,
            title, text, "", null, null, 0, 0, 0D);

    Indexer<Question> indexer = IndexerRegistryUtil.nullSafeGetIndexer(Question.class);
    indexer.reindex(question);

    socialActivityLocalService.addActivity(userId, groupId, Question.class.getName(), questionId, 1, "", 0);

    log.info("Question " + questionId + " has been added and indexed.");

    return question;
}