Search in sources :

Example 6 with ServiceContext

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

the class FolderNestedCollectionResource method _addFolder.

private Folder _addFolder(Long groupId, FolderForm folderForm) throws PortalException {
    long parentFolderId = 0;
    Try<Folder> folderTry = Try.fromFallible(() -> _dlAppService.getFolder(groupId, parentFolderId, folderForm.getName()));
    if (folderTry.isSuccess()) {
        throw new BadRequestException("A folder with that name already exists");
    }
    return _dlAppService.addFolder(groupId, parentFolderId, folderForm.getName(), folderForm.getDescription(), new ServiceContext());
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) BadRequestException(javax.ws.rs.BadRequestException) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 7 with ServiceContext

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

the class ClubPersistenceImpl method updateImpl.

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

Example 8 with ServiceContext

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

the class RosterMemberPersistenceImpl method updateImpl.

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

Example 9 with ServiceContext

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

the class RosterPortlet method updateRoster.

protected void updateRoster(ActionRequest actionRequest) throws Exception {
    long rosterId = ParamUtil.getLong(actionRequest, "rosterId");
    long clubId = ParamUtil.getLong(actionRequest, "clubId");
    String name = ParamUtil.getString(actionRequest, "name");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Roster.class.getName(), actionRequest);
    if (rosterId <= 0) {
        RosterLocalServiceUtil.addRoster(clubId, name, serviceContext);
    } else {
        RosterLocalServiceUtil.updateRoster(rosterId, clubId, name, serviceContext);
    }
}
Also used : Roster(com.liferay.roster.model.Roster) 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