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

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

Introduction

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

Prototype

public Date getCreateDate() 

Source Link

Document

Returns the date when an entity was created if this service context is being passed as a parameter to a method which creates an entity.

Usage

From source file:com.liferay.message.boards.internal.service.MBDiscussionMBMessageLocalServiceWrapper.java

License:Open Source License

@Override
public MBMessage addDiscussionMessage(long userId, String userName, long groupId, String className,
        long classPK, long threadId, long parentMessageId, String subject, String body,
        ServiceContext serviceContext) throws PortalException {

    super.addDiscussionMessage(userId, userName, groupId, className, classPK, threadId, parentMessageId,
            subject, body, serviceContext);

    // Message/*from   www.  j a v  a  2s.c o  m*/

    validateDiscussionMaxComments(className, classPK);

    long categoryId = MBCategoryConstants.DISCUSSION_CATEGORY_ID;
    subject = getDiscussionMessageSubject(subject, body);
    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = Collections.emptyList();
    boolean anonymous = false;
    double priority = 0.0;
    boolean allowPingbacks = false;

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAttribute("className", className);
    serviceContext.setAttribute("classPK", String.valueOf(classPK));

    Date now = new Date();

    if (serviceContext.getCreateDate() == null) {
        serviceContext.setCreateDate(now);
    }

    if (serviceContext.getModifiedDate() == null) {
        serviceContext.setModifiedDate(now);
    }

    MBMessage message = addMessage(userId, userName, groupId, categoryId, threadId, parentMessageId, subject,
            body, PropsValues.DISCUSSION_COMMENTS_FORMAT, inputStreamOVPs, anonymous, priority, allowPingbacks,
            serviceContext);

    // Discussion

    if (parentMessageId == MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) {
        long classNameId = _classNameLocalService.getClassNameId(className);

        MBDiscussion discussion = _mbDiscussionLocalService.fetchDiscussion(classNameId, classPK);

        if (discussion == null) {
            _mbDiscussionLocalService.addDiscussion(userId, groupId, classNameId, classPK,
                    message.getThreadId(), serviceContext);
        }
    }

    return message;
}

From source file:com.liferay.pokedex.service.impl.PokemonLocalServiceImpl.java

License:Open Source License

@Override
public Pokemon addPokemon(String originalName, String customName, String description, String type, long order,
        String frontImageURL, String frontShinyImageURL, String backImageURL, String backShinyImageURL,
        ServiceContext serviceContext) throws PortalException {

    // Entry/*from  w  ww  .j  a  v a2  s. com*/

    User user = userPersistence.findByPrimaryKey(serviceContext.getUserId());

    long groupId = user.getGroupId();

    long id = counterLocalService.increment();

    Pokemon pokemon = pokemonPersistence.create(id);

    pokemon.setUuid(serviceContext.getUuid());
    pokemon.setGroupId(groupId);
    pokemon.setCompanyId(user.getCompanyId());
    pokemon.setUserId(user.getUserId());
    pokemon.setUserName(user.getFullName());
    pokemon.setOriginalName(originalName);
    pokemon.setCustomName(customName);
    pokemon.setDescription(description);
    pokemon.setType(type);
    pokemon.setOrder(order);
    pokemon.setCreateDate(serviceContext.getCreateDate());
    pokemon.setModifiedDate(serviceContext.getModifiedDate());
    pokemon.setFrontImageURL(frontImageURL);
    pokemon.setFrontShinyImageURL(frontShinyImageURL);
    pokemon.setBackImageURL(backImageURL);
    pokemon.setBackShinyImageURL(backShinyImageURL);

    return pokemonPersistence.update(pokemon);
}

From source file:com.liferay.roster.service.impl.RosterLocalServiceImpl.java

License:Open Source License

public Roster addRoster(long clubId, String name, ServiceContext serviceContext) {

    Roster roster = rosterLocalService.createRoster(counterLocalService.increment());

    roster.setClubId(clubId);//  www .j  a  v  a  2  s.c  o m
    roster.setName(name);
    roster.setCreateDate(serviceContext.getCreateDate());
    roster.setModifiedDate(serviceContext.getModifiedDate());

    return rosterLocalService.addRoster(roster);
}

From source file:com.liferay.roster.service.impl.RosterLocalServiceImpl.java

License:Open Source License

public Roster updateRoster(long rosterId, long clubId, String name, ServiceContext serviceContext)
        throws PortalException {

    Roster roster = rosterLocalService.getRoster(rosterId);

    roster.setClubId(clubId);//www. j ava 2  s. c o  m
    roster.setName(name);
    roster.setCreateDate(serviceContext.getCreateDate());
    roster.setModifiedDate(serviceContext.getModifiedDate());

    return rosterLocalService.updateRoster(roster);
}

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);//  w ww  . j  a  v  a 2  s. co 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 av a2  s  .c  o m*/
    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;
}