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

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

Introduction

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

Prototype

public long getUserId() 

Source Link

Document

Returns the ID of this service context's current user.

Usage

From source file:com.bemis.portal.carriers.service.impl.CarrierLocalServiceImpl.java

License:Open Source License

protected AssetEntry updateAsset(Carrier carrier, ServiceContext serviceContext) throws PortalException {

    String className = Carrier.class.getName();
    long carrierId = carrier.getCarrierId();
    double priority = serviceContext.getAssetPriority();
    long userId = serviceContext.getUserId();
    String uuid = carrier.getUuid();
    Date createDate = carrier.getCreateDate();
    Date modifiedDate = carrier.getModifiedDate();
    String mimeType = ContentTypes.TEXT_HTML;
    String title = carrier.getName();
    String description = null;//from w w w. ja va  2 s .  c o m
    String summary = null;
    String url = carrier.getUrl();
    String layoutUuid = null;
    int height = 0;
    int width = 0;
    long groupId = carrier.getGroupId();

    // Create asset entry

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, groupId, createDate, modifiedDate,
            className, carrierId, uuid, 0, null, null, true, true, null, null, null, null, mimeType, title,
            description, summary, url, layoutUuid, height, width, priority);

    // Create asset link

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), null, AssetLinkConstants.TYPE_RELATED);

    return assetEntry;
}

From source file:com.bemis.portal.carriers.service.impl.CarrierLocalServiceImpl.java

License:Open Source License

protected Carrier updateCarrier(String carrierName, String carrierURL, String carrierPhone,
        ServiceContext serviceContext, Carrier carrier) throws PortalException {

    long companyId = serviceContext.getCompanyId();
    long groupId = serviceContext.getScopeGroupId();
    long userId = serviceContext.getUserId();

    User user = userLocalService.getUser(userId);

    // Set properties

    carrier.setName(carrierName);/*from w  ww.  jav a2 s .  c o m*/
    carrier.setUrl(carrierURL);
    carrier.setPhone(carrierPhone);

    carrier.setCompanyId(companyId);
    carrier.setGroupId(groupId);
    carrier.setModifiedDate(new Date());
    carrier.setUserId(userId);
    carrier.setUserName(user.getFullName());

    carrier = carrierPersistence.update(carrier);

    // Update asset

    updateAsset(carrier, serviceContext);

    return carrier;
}

From source file:com.bemis.portal.fileuploader.service.impl.FileUploaderLocalServiceImpl.java

License:Open Source License

/**
 * Uploads the file into the destination folder
 * If the file does not exist, adds the file. If exists, updates the existing file
 * Adds tags and categories to documents
 *
 * @param file/*from  w w  w  .  j a va 2s. c  om*/
 * @param fileDescription
 * @param fileName
 * @param changeLog
 * @param serviceContext
 * @return FileEntry
 * @throws PortalException
 */
public FileEntry uploadFile(File file, String fileDescription, String fileName, String changeLog,
        ServiceContext serviceContext) throws PortalException {

    if (_log.isDebugEnabled()) {
        _log.debug("Invoking uploadFile....");
    }

    long companyId = serviceContext.getCompanyId();
    long groupId = serviceContext.getScopeGroupId();
    long userId = serviceContext.getUserId();

    // see https://issues.liferay.com/browse/LPS-66607

    User user = userLocalService.getUser(userId);

    // Check permissions

    _fileUploadHelper.checkPermission(companyId, groupId, userId);

    String title = FilenameUtils.removeExtension(fileName);

    long folderId = GetterUtil.getLong(serviceContext.getAttribute(DESTINATION_FOLDER_ID));

    fileName = file.getName();

    String mimeType = MimeTypesUtil.getContentType(fileName);

    boolean majorVersion = true;

    DLFileEntry dlFileEntry = _dlFileEntryLocalService.fetchFileEntry(groupId, folderId, title);

    FileEntry fileEntry = null;

    if (Validator.isNull(dlFileEntry)) {
        fileEntry = addFileEntry(userId, groupId, folderId, fileName, mimeType, title, fileDescription,
                changeLog, file, serviceContext);
    } else {
        fileEntry = updateFileEntry(userId, dlFileEntry, fileName, mimeType, title, fileDescription, changeLog,
                majorVersion, file, serviceContext);
    }

    FileVersion fileVersion = fileEntry.getFileVersion();

    long[] assetCategoryIds = _fileUploadHelper.getAssetCategoryIds(groupId, title, serviceContext);

    String[] assetTagNames = serviceContext.getAssetTagNames();

    if (_log.isDebugEnabled()) {
        _log.debug(">>> Updating FileEntry with tags and categories");
    }

    _dlAppLocalService.updateAsset(userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames, null);

    // Post processing uploaded file

    _fileUploadHelper.postProcessUpload(file, fileEntry.getFileEntryId(), serviceContext);

    return fileEntry;
}

From source file:com.liferay.adaptive.media.journal.internal.exportimport.data.handler.test.AMJournalArticleStagedModelDataHandlerTest.java

License:Open Source License

private JournalArticle _addJournalArticle(String content, ServiceContext serviceContext) throws Exception {

    DDMForm ddmForm = DDMStructureTestUtil.getSampleDDMForm("content", "string", "text", true, "text_area",
            new Locale[] { LocaleUtil.getSiteDefault() }, LocaleUtil.getSiteDefault());

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(stagingGroup.getGroupId(),
            JournalArticle.class.getName(), "0", ddmForm, LocaleUtil.getSiteDefault(),
            ServiceContextTestUtil.getServiceContext());

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(stagingGroup.getGroupId(),
            PortalUtil.getClassNameId(com.liferay.dynamic.data.mapping.model.DDMStructure.class),
            ddmStructure.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class));

    JournalFolder journalFolder = _journalFolderLocalService.addFolder(serviceContext.getUserId(),
            serviceContext.getScopeGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(), "This is a test folder.", serviceContext);

    Map<Locale, String> titleMap = new HashMap<>();

    titleMap.put(LocaleUtil.getSiteDefault(), "Test Article");

    return _journalArticleLocalService.addArticle(serviceContext.getUserId(), serviceContext.getScopeGroupId(),
            journalFolder.getFolderId(), JournalArticleConstants.CLASSNAME_ID_DEFAULT, 0, StringPool.BLANK,
            true, 0, titleMap, null, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(),
            null, 1, 1, 1965, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, null, null, null,
            null, serviceContext);/*from   ww w.j av a  2 s .c  o  m*/
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

protected DLFileEntryType addDLFileEntryType(long groupId, long ddmStructureId, ServiceContext serviceContext)
        throws Exception {

    return DLFileEntryTypeLocalServiceUtil.addFileEntryType(serviceContext.getUserId(), groupId,
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), new long[] { ddmStructureId },
            serviceContext);//w  ww. jav a 2s .  c  o m
}

From source file:com.liferay.blogs.search.test.BlogsEntrySearchTest.java

License:Open Source License

@Override
protected BaseModel<?> updateBaseModel(BaseModel<?> baseModel, String keywords, ServiceContext serviceContext)
        throws Exception {

    BlogsEntry entry = (BlogsEntry) baseModel;

    return BlogsEntryLocalServiceUtil.updateEntry(serviceContext.getUserId(), entry.getEntryId(), keywords,
            entry.getContent(), serviceContext);
}

From source file:com.liferay.book.service.impl.BookLocalServiceImpl.java

License:Open Source License

public Book addBook(String name, String author, String description, double price, ServiceContext serviceContext)
        throws SystemException, PortalException {
    long bookId = counterLocalService.increment();

    Book book = bookPersistence.create(bookId);

    book.setGroupId(serviceContext.getScopeGroupId());
    book.setCompanyId(serviceContext.getCompanyId());
    book.setUserId(serviceContext.getUserId());
    book.setUserName(userLocalService.getUser(serviceContext.getUserId()).getFullName());

    book.setName(name);/*w  w  w.j  a  va  2  s  .  c o  m*/
    book.setAuthor(author);
    book.setDescription(description);
    book.setPrice(price);
    book.setCreateDate(serviceContext.getCreateDate(null));

    bookPersistence.update(book);

    resourceLocalService.addModelResources(book, serviceContext);

    return book;
}

From source file:com.liferay.book.service.impl.BookLocalServiceImpl.java

License:Open Source License

public Book updateBook(long bookId, String name, String author, String description, double price,
        ServiceContext serviceContext) throws SystemException, PortalException {
    Book book = bookPersistence.fetchByPrimaryKey(bookId);

    book.setUserId(serviceContext.getUserId());
    book.setUserName(userLocalService.getUser(serviceContext.getUserId()).getFullName());

    book.setName(name);//ww  w.  jav  a  2 s . co m
    book.setAuthor(author);
    book.setDescription(description);
    book.setPrice(price);

    bookPersistence.update(book);

    return book;
}

From source file:com.liferay.calendar.search.test.CalendarFixture.java

License:Open Source License

public Calendar addCalendar(LocalizedValuesMap nameLocalizedValuesMap,
        LocalizedValuesMap descriptionLocalizedValuesMap, ServiceContext serviceContext)
        throws PortalException {

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);//from   www.j ava  2  s  . c  o m

    Calendar calendar = _calendarLocalService.addCalendar(serviceContext.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameLocalizedValuesMap.getValues(),
            descriptionLocalizedValuesMap.getValues(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
            false, false, serviceContext);

    _calendars.add(calendar);

    return calendar;
}

From source file:com.liferay.calendar.search.test.CalendarFixture.java

License:Open Source License

public CalendarBooking addCalendarBooking(LocalizedValuesMap titleLocalizedValuesMap, Calendar calendar,
        ServiceContext serviceContext) throws PortalException {

    long startTime = DateUtil.newTime() + RandomTestUtil.randomInt();

    long endTime = startTime + Time.HOUR;

    CalendarBooking calendarBooking = _calendarBookingLocalService.addCalendarBooking(
            serviceContext.getUserId(), calendar.getCalendarId(), new long[0],
            CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, 0, titleLocalizedValuesMap.getValues(),
            Collections.emptyMap(), null, startTime, endTime, false, null, 0, "email", 0, "email",
            serviceContext);/* www  .  jav a  2 s  .  c  o  m*/

    _calendarBookings.add(calendarBooking);

    return calendarBooking;
}