Search in sources :

Example 1 with ServiceContext

use of com.liferay.portal.kernel.service.ServiceContext in project liferay-ide by liferay.

the class RosterPersistenceImpl method updateImpl.

@Override
public Roster updateImpl(Roster roster) {
    roster = toUnwrappedModel(roster);
    boolean isNew = roster.isNew();
    RosterModelImpl rosterModelImpl = (RosterModelImpl) roster;
    if (Validator.isNull(roster.getUuid())) {
        String uuid = PortalUUIDUtil.generate();
        roster.setUuid(uuid);
    }
    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
    Date now = new Date();
    if (isNew && (roster.getCreateDate() == null)) {
        if (serviceContext == null) {
            roster.setCreateDate(now);
        } else {
            roster.setCreateDate(serviceContext.getCreateDate(now));
        }
    }
    if (!rosterModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            roster.setModifiedDate(now);
        } else {
            roster.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }
    Session session = null;
    try {
        session = openSession();
        if (roster.isNew()) {
            session.save(roster);
            roster.setNew(false);
        } else {
            roster = (Roster) session.merge(roster);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    if (isNew || !RosterModelImpl.COLUMN_BITMASK_ENABLED) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else {
        if ((rosterModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { rosterModelImpl.getOriginalUuid() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
            args = new Object[] { rosterModelImpl.getUuid() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
        }
        if ((rosterModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLUBID.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { rosterModelImpl.getOriginalClubId() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_CLUBID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLUBID, args);
            args = new Object[] { rosterModelImpl.getClubId() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_CLUBID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLUBID, args);
        }
    }
    entityCache.putResult(RosterModelImpl.ENTITY_CACHE_ENABLED, RosterImpl.class, roster.getPrimaryKey(), roster, false);
    roster.resetOriginalValues();
    return roster;
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) Date(java.util.Date) NoSuchRosterException(com.liferay.roster.exception.NoSuchRosterException) RosterModelImpl(com.liferay.roster.model.impl.RosterModelImpl) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 2 with ServiceContext

use of com.liferay.portal.kernel.service.ServiceContext in project liferay-blade-samples by liferay.

the class FooPersistenceImpl method updateImpl.

@Override
public Foo updateImpl(Foo foo) {
    foo = toUnwrappedModel(foo);
    boolean isNew = foo.isNew();
    FooModelImpl fooModelImpl = (FooModelImpl) foo;
    if (Validator.isNull(foo.getUuid())) {
        String uuid = PortalUUIDUtil.generate();
        foo.setUuid(uuid);
    }
    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
    Date now = new Date();
    if (isNew && (foo.getCreateDate() == null)) {
        if (serviceContext == null) {
            foo.setCreateDate(now);
        } else {
            foo.setCreateDate(serviceContext.getCreateDate(now));
        }
    }
    if (!fooModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            foo.setModifiedDate(now);
        } else {
            foo.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }
    Session session = null;
    try {
        session = openSession();
        if (foo.isNew()) {
            session.save(foo);
            foo.setNew(false);
        } else {
            foo = (Foo) session.merge(foo);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    if (isNew || !FooModelImpl.COLUMN_BITMASK_ENABLED) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else {
        if ((fooModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { fooModelImpl.getOriginalUuid() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
            args = new Object[] { fooModelImpl.getUuid() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
        }
        if ((fooModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { fooModelImpl.getOriginalUuid(), fooModelImpl.getOriginalCompanyId() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);
            args = new Object[] { fooModelImpl.getUuid(), fooModelImpl.getCompanyId() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);
        }
        if ((fooModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FIELD2.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { fooModelImpl.getOriginalField2() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_FIELD2, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FIELD2, args);
            args = new Object[] { fooModelImpl.getField2() };
            finderCache.removeResult(FINDER_PATH_COUNT_BY_FIELD2, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FIELD2, args);
        }
    }
    entityCache.putResult(FooModelImpl.ENTITY_CACHE_ENABLED, FooImpl.class, foo.getPrimaryKey(), foo, false);
    clearUniqueFindersCache(fooModelImpl);
    cacheUniqueFindersCache(fooModelImpl, isNew);
    foo.resetOriginalValues();
    return foo;
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) FooModelImpl(com.liferay.blade.samples.servicebuilder.model.impl.FooModelImpl) Date(java.util.Date) NoSuchFooException(com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 3 with ServiceContext

use of com.liferay.portal.kernel.service.ServiceContext in project com-liferay-apio-architect by liferay.

the class BlogPostingNestedCollectionResource method _updateBlogsEntry.

private BlogsEntry _updateBlogsEntry(Long entryId, BlogPostingForm blogPostingForm) throws PortalException {
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    BlogsEntry blogsEntry = _blogsService.getEntry(entryId);
    serviceContext.setScopeGroupId(blogsEntry.getGroupId());
    return _blogsService.updateEntry(entryId, blogPostingForm.getHeadline(), blogPostingForm.getAlternativeHeadline(), blogPostingForm.getDescription(), blogPostingForm.getArticleBody(), blogPostingForm.getDisplayDateMonth(), blogPostingForm.getDisplayDateDay(), blogPostingForm.getDisplayDateYear(), blogPostingForm.getDisplayDateHour(), blogPostingForm.getDisplayDateMinute(), false, false, null, null, null, null, serviceContext);
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) BlogsEntry(com.liferay.blogs.kernel.model.BlogsEntry)

Example 4 with ServiceContext

use of com.liferay.portal.kernel.service.ServiceContext in project com-liferay-apio-architect by liferay.

the class MediaObjectNestedCollectionResource method _addFileEntry.

private FileEntry _addFileEntry(Long folderId, MediaObjectCreatorForm mediaObjectCreatorForm) throws PortalException {
    Folder folder = _dlAppService.getFolder(folderId);
    BinaryFile binaryFile = mediaObjectCreatorForm.getBinaryFile();
    return _dlAppService.addFileEntry(folder.getGroupId(), folderId, mediaObjectCreatorForm.getName(), binaryFile.getMimeType(), mediaObjectCreatorForm.getTitle(), mediaObjectCreatorForm.getDescription(), null, binaryFile.getInputStream(), binaryFile.getSize(), new ServiceContext());
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) Folder(com.liferay.portal.kernel.repository.model.Folder) BinaryFile(com.liferay.apio.architect.file.BinaryFile)

Example 5 with ServiceContext

use of com.liferay.portal.kernel.service.ServiceContext in project com-liferay-apio-architect by liferay.

the class BlogPostingNestedCollectionResource method _addBlogsEntry.

private BlogsEntry _addBlogsEntry(Long groupId, BlogPostingForm blogPostingForm) throws PortalException {
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(groupId);
    return _blogsService.addEntry(blogPostingForm.getHeadline(), blogPostingForm.getAlternativeHeadline(), blogPostingForm.getDescription(), blogPostingForm.getArticleBody(), blogPostingForm.getDisplayDateMonth(), blogPostingForm.getDisplayDateDay(), blogPostingForm.getDisplayDateYear(), blogPostingForm.getDisplayDateHour(), blogPostingForm.getDisplayDateMinute(), false, false, null, null, null, null, serviceContext);
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext)

Aggregations

ServiceContext (com.liferay.portal.kernel.service.ServiceContext)9 Session (com.liferay.portal.kernel.dao.orm.Session)4 Date (java.util.Date)4 Folder (com.liferay.portal.kernel.repository.model.Folder)2 BinaryFile (com.liferay.apio.architect.file.BinaryFile)1 NoSuchFooException (com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException)1 FooModelImpl (com.liferay.blade.samples.servicebuilder.model.impl.FooModelImpl)1 BlogsEntry (com.liferay.blogs.kernel.model.BlogsEntry)1 NoSuchClubException (com.liferay.roster.exception.NoSuchClubException)1 NoSuchRosterException (com.liferay.roster.exception.NoSuchRosterException)1 NoSuchRosterMemberException (com.liferay.roster.exception.NoSuchRosterMemberException)1 Roster (com.liferay.roster.model.Roster)1 ClubModelImpl (com.liferay.roster.model.impl.ClubModelImpl)1 RosterMemberModelImpl (com.liferay.roster.model.impl.RosterMemberModelImpl)1 RosterModelImpl (com.liferay.roster.model.impl.RosterModelImpl)1 BadRequestException (javax.ws.rs.BadRequestException)1