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

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

Introduction

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

Prototype

public long getGuestOrUserId() throws PortalException 

Source Link

Document

Returns this service context's user ID or guest ID if no user ID is available.

Usage

From source file:com.bemis.portal.customer.service.impl.CustomerLocationLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//w w w.  java2 s. c o m
public CustomerLocation addCustomerLocation(String bemisCustomerId, String bemisParentId, String customerName,
        String customerAddress1, String customerAddress2, String customerAddress3, String customerCity,
        String customerState, String customerPostalCde, String customerCountry, String customerPhoneNbr,
        String customerPoBox, String customerPoCity, String customerPoState, String customerPoPostalCde,
        String customerActiveStatusCde, ServiceContext serviceContext) throws PortalException {

    CustomerLocation customerLocation = customerLocationPersistence.fetchByBemisCustomerId(bemisCustomerId);

    if (customerLocation != null) {
        throw new DuplicateCustomerLocationException(bemisCustomerId);
    }

    User user = userLocalService.getUser(serviceContext.getGuestOrUserId());
    Date now = new Date();

    long customerLocationId = counterLocalService.increment();

    customerLocation = customerLocationPersistence.create(customerLocationId);

    customerLocation.setCompanyId(user.getCompanyId());
    customerLocation.setUserId(user.getUserId());
    customerLocation.setUserName(user.getFullName());
    customerLocation.setCreateDate(serviceContext.getCreateDate(now));
    customerLocation.setModifiedDate(serviceContext.getModifiedDate(now));

    customerLocation.setBemisCustomerId(bemisCustomerId);
    customerLocation.setBemisParentId(bemisParentId);

    customerLocation.setCustomerName(customerName);
    customerLocation.setCustomerAddress1(customerAddress1);
    customerLocation.setCustomerAddress2(customerAddress2);
    customerLocation.setCustomerAddress3(customerAddress3);
    customerLocation.setCustomerCity(customerCity);
    customerLocation.setCustomerState(customerState);
    customerLocation.setCustomerPostalCde(customerPostalCde);
    customerLocation.setCustomerCountry(customerCountry);
    customerLocation.setCustomerPhoneNbr(customerPhoneNbr);
    customerLocation.setCustomerPoBox(customerPoBox);
    customerLocation.setCustomerPoCity(customerPoCity);
    customerLocation.setCustomerPoState(customerPoState);
    customerLocation.setCustomerPoPostalCde(customerPoPostalCde);

    customerLocation.setCustomerActiveStatusCde(customerActiveStatusCde);

    customerLocation.setExpandoBridgeAttributes(serviceContext);

    customerLocationPersistence.update(customerLocation);

    return customerLocation;
}

From source file:com.bemis.portal.customer.service.impl.CustomerLocationLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//from w ww.  ja  va  2s .c om
public CustomerLocation updateCustomerLocation(long customerLocationId, String bemisParentId,
        String customerName, String customerAddress1, String customerAddress2, String customerAddress3,
        String customerCity, String customerState, String customerPostalCde, String customerCountry,
        String customerPhoneNbr, String customerPoBox, String customerPoCity, String customerPoState,
        String customerPoPostalCde, String customerActiveStatusCde, ServiceContext serviceContext)
        throws PortalException {

    CustomerLocation customerLocation = customerLocationPersistence.findByPrimaryKey(customerLocationId);

    User user = userLocalService.getUser(serviceContext.getGuestOrUserId());
    Date now = new Date();

    customerLocation.setUserId(user.getUserId());
    customerLocation.setUserName(user.getFullName());
    customerLocation.setModifiedDate(serviceContext.getModifiedDate(now));

    customerLocation.setBemisParentId(bemisParentId);

    customerLocation.setCustomerName(customerName);
    customerLocation.setCustomerAddress1(customerAddress1);
    customerLocation.setCustomerAddress2(customerAddress2);
    customerLocation.setCustomerAddress3(customerAddress3);
    customerLocation.setCustomerCity(customerCity);
    customerLocation.setCustomerState(customerState);
    customerLocation.setCustomerPostalCde(customerPostalCde);
    customerLocation.setCustomerCountry(customerCountry);
    customerLocation.setCustomerPhoneNbr(customerPhoneNbr);
    customerLocation.setCustomerPoBox(customerPoBox);
    customerLocation.setCustomerPoCity(customerPoCity);
    customerLocation.setCustomerPoState(customerPoState);
    customerLocation.setCustomerPoPostalCde(customerPoPostalCde);

    customerLocation.setCustomerActiveStatusCde(customerActiveStatusCde);

    customerLocation.setExpandoBridgeAttributes(serviceContext);

    customerLocationPersistence.update(customerLocation);

    return customerLocation;
}

From source file:com.bemis.portal.report.service.impl.ReportDefinitionLocalServiceImpl.java

License:Open Source License

@Override
public ReportDefinition addReportDefinition(String name, String category, Map<Locale, String> titleMap,
        Map<Locale, String> descriptionMap, String urlPath, Set<String> availableFields,
        Set<String> defaultSelectedFields, Set<String> sortFields, Set<ReportParameter> reportParameters,
        ServiceContext serviceContext) throws PortalException {

    if (reportDefinitionPersistence.fetchByURLPath(urlPath) != null) {
        throw new DuplicateReportDefinitionException(urlPath);
    }/*www . java 2 s.  c o  m*/

    User user = userLocalService.getUser(serviceContext.getGuestOrUserId());
    Date now = new Date();

    long reportDefintionId = counterLocalService.increment();

    ReportDefinition reportDefinition = reportDefinitionPersistence.create(reportDefintionId);

    reportDefinition.setCompanyId(user.getCompanyId());
    reportDefinition.setGroupId(serviceContext.getScopeGroupId());
    reportDefinition.setUserId(user.getUserId());
    reportDefinition.setUserName(user.getFullName());
    reportDefinition.setCreateDate(serviceContext.getCreateDate(now));
    reportDefinition.setModifiedDate(serviceContext.getModifiedDate(now));

    reportDefinition.setName(name);
    reportDefinition.setCategory(category);
    reportDefinition.setDescriptionMap(descriptionMap);
    reportDefinition.setTitleMap(titleMap, Locale.US);
    reportDefinition.setUrlPath(urlPath);
    reportDefinition.setAvailableFields(StringUtils.join(availableFields, StringPool.COMMA));
    reportDefinition.setDefaultSelectedFields(StringUtils.join(defaultSelectedFields, StringPool.COMMA));
    reportDefinition.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

    String reportParametersString = reportParameterSetSerializer.serialize(reportParameters);

    reportDefinition.setParameters(reportParametersString);

    reportDefinition.setExpandoBridgeAttributes(serviceContext);

    reportDefinitionPersistence.update(reportDefinition);

    /*
          // Resources
            
          resourceLocalService.addModelResources(
             reportDefinition, serviceContext);
    */

    return reportDefinition;
}

From source file:com.bemis.portal.report.service.impl.ReportDefinitionLocalServiceImpl.java

License:Open Source License

@Override
public ReportDefinition updateReportDefinition(long reportDefinitionId, Set<String> availableFields,
        Set<String> defaultSelectedFields, Set<String> sortFields, Set<ReportParameter> reportParameters,
        ServiceContext serviceContext) throws PortalException {

    ReportDefinition reportDefinition = reportDefinitionPersistence.fetchByPrimaryKey(reportDefinitionId);

    User user = userLocalService.getUser(serviceContext.getGuestOrUserId());
    Date now = new Date();

    reportDefinition.setUserId(user.getUserId());
    reportDefinition.setUserName(user.getFullName());
    reportDefinition.setModifiedDate(serviceContext.getModifiedDate(now));

    reportDefinition.setAvailableFields(StringUtils.join(availableFields, StringPool.COMMA));
    reportDefinition.setDefaultSelectedFields(StringUtils.join(defaultSelectedFields, StringPool.COMMA));
    reportDefinition.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

    String reportParametersString = reportParameterSetSerializer.serialize(reportParameters);

    reportDefinition.setParameters(reportParametersString);

    reportDefinitionPersistence.update(reportDefinition);

    return reportDefinition;
}

From source file:com.bemis.portal.report.service.impl.ReportDefinitionLocalServiceImpl.java

License:Open Source License

@Override
public ReportDefinition updateReportDefinition(long reportDefinitionId, String category,
        Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String urlPath,
        Set<String> availableFields, Set<String> defaultSelectedFields, Set<String> sortFields,
        ServiceContext serviceContext) throws PortalException {

    ReportDefinition reportDefinition = reportDefinitionPersistence.fetchByPrimaryKey(reportDefinitionId);

    User user = userLocalService.getUser(serviceContext.getGuestOrUserId());
    Date now = new Date();

    reportDefinition.setUserId(user.getUserId());
    reportDefinition.setUserName(user.getFullName());
    reportDefinition.setModifiedDate(serviceContext.getModifiedDate(now));

    reportDefinition.setCategory(category);
    reportDefinition.setDescriptionMap(descriptionMap);
    reportDefinition.setTitleMap(titleMap);
    reportDefinition.setUrlPath(urlPath);
    reportDefinition.setAvailableFields(StringUtils.join(availableFields, StringPool.COMMA));
    reportDefinition.setDefaultSelectedFields(StringUtils.join(defaultSelectedFields, StringPool.COMMA));
    reportDefinition.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

    reportDefinition.setExpandoBridgeAttributes(serviceContext);

    reportDefinitionPersistence.update(reportDefinition);

    return reportDefinition;
}

From source file:com.bemis.portal.report.service.impl.ReportPreferencesLocalServiceImpl.java

License:Open Source License

@Override
public ReportPreferences addReportPreferences(long reportDefinitionId, Set<String> selectedFields,
        Set<String> sortFields, Map<ReportParameter, Serializable> reportParametersValues,
        ServiceContext serviceContext) throws PortalException {

    final User user = userLocalService.getUser(serviceContext.getGuestOrUserId());

    Date now = new Date();

    final long reportPreferencesId = counterLocalService.increment();

    ReportPreferences reportPreferences = reportPreferencesPersistence.create(reportPreferencesId);

    reportPreferences.setCompanyId(user.getCompanyId());
    reportPreferences.setUserId(user.getUserId());
    reportPreferences.setUserName(user.getFullName());
    reportPreferences.setCreateDate(serviceContext.getCreateDate(now));
    reportPreferences.setModifiedDate(serviceContext.getModifiedDate(now));

    reportPreferences.setReportDefinitionId(reportDefinitionId);
    reportPreferences.setSelectedFields(StringUtils.join(selectedFields, StringPool.COMMA));
    reportPreferences.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

    String reportParametersString = reportParametersValuesSerializer.serialize(reportParametersValues);

    reportPreferences.setParametersValues(reportParametersString);

    reportPreferences.setExpandoBridgeAttributes(serviceContext);

    reportPreferencesPersistence.update(reportPreferences);

    return reportPreferences;
}

From source file:com.bemis.portal.report.service.impl.ReportRequestLocalServiceImpl.java

License:Open Source License

@Override
public ReportRequest addReportRequest(final long reportDefinitionId, String reportFormat,
        final Set<String> reportFields, Set<String> sortFields,
        final Map<ReportParameter, Serializable> reportParametersValues, ServiceContext serviceContext)
        throws PortalException {

    final User user = userLocalService.getUser(serviceContext.getGuestOrUserId());

    Date now = new Date();

    final long reportRequestId = counterLocalService.increment();

    ReportRequest reportRequest = reportRequestPersistence.create(reportRequestId);

    reportRequest.setGroupId(user.getGroupId());
    reportRequest.setCompanyId(user.getCompanyId());
    reportRequest.setUserId(user.getUserId());
    reportRequest.setUserName(user.getFullName());
    reportRequest.setCreateDate(serviceContext.getCreateDate(now));
    reportRequest.setModifiedDate(serviceContext.getModifiedDate(now));

    final ReportDefinition reportDefinition = reportDefinitionLocalService
            .getReportDefinition(reportDefinitionId);

    reportRequest.setReportDefinitionCategory(reportDefinition.getCategory());

    reportRequest.setReportFormat(reportFormat);
    reportRequest.setReportDefinitionId(reportDefinitionId);
    reportRequest.setReportDefinitionName(reportDefinition.getTitle(serviceContext.getLocale()));
    reportRequest.setSelectedFields(StringUtils.join(reportFields, StringPool.COMMA));
    reportRequest.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

    String reportParametersString = reportParametersValuesSerializer.serialize(reportParametersValues);

    reportRequest.setParameters(reportParametersString);

    reportRequest.setExpandoBridgeAttributes(serviceContext);

    reportRequestPersistence.update(reportRequest);

    /*//from  w  ww . j av  a2 s  .c om
          // Resources
            
          resourceLocalService.addModelResources(reportRequest, serviceContext);
    */

    return reportRequest;
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, BookmarksEntry entry, ServiceContext serviceContext)
        throws PortalException {

    String layoutFullURL = serviceContext.getLayoutFullURL();

    if (!entry.isApproved() || Validator.isNull(layoutFullURL)) {
        return;/*from   www.j  av a2s  .  c o  m*/
    }

    BookmarksGroupServiceOverriddenConfiguration bookmarksGroupServiceOverriddenConfiguration = configurationProvider
            .getConfiguration(BookmarksGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(entry.getGroupId(), BookmarksConstants.SERVICE_NAME));

    if ((serviceContext.isCommandAdd()
            && !bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedEnabled())
            || (serviceContext.isCommandUpdate()
                    && !bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedEnabled())) {

        return;
    }

    String statusByUserName = StringPool.BLANK;

    try {
        User user = userLocalService.getUserById(serviceContext.getGuestOrUserId());

        statusByUserName = user.getFullName();
    } catch (Exception e) {
        _log.error(e, e);
    }

    String entryTitle = entry.getName();

    StringBundler sb = new StringBundler(7);

    sb.append(layoutFullURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("bookmarks");
    sb.append(StringPool.SLASH);
    sb.append("folder");
    sb.append(StringPool.SLASH);
    sb.append(entry.getFolderId());

    String entryURL = sb.toString();

    String fromName = bookmarksGroupServiceOverriddenConfiguration.emailFromName();
    String fromAddress = bookmarksGroupServiceOverriddenConfiguration.emailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedSubject();
        bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedSubject();
        bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedBody();
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            BookmarksResourcePermissionChecker.RESOURCE_NAME);

    subscriptionSender.setClassName(entry.getModelClassName());
    subscriptionSender.setClassPK(entry.getEntryId());
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttributes("[$BOOKMARKS_ENTRY_STATUS_BY_USER_NAME$]", statusByUserName,
            "[$BOOKMARKS_ENTRY_URL$]", entryURL);
    subscriptionSender.setContextCreatorUserPrefix("BOOKMARKS_ENTRY");
    subscriptionSender.setCreatorUserId(entry.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("bookmarks_entry", entry.getEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(BookmarksPortletKeys.BOOKMARKS);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    BookmarksFolder folder = entry.getFolder();

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), ancestorFolderId);
        }
    }

    subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), entry.getGroupId());

    subscriptionSender.addPersistedSubscribers(BookmarksEntry.class.getName(), entry.getEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:de.hofuniversity.iisys.liferay.workflows.LoggingTaskManager.java

License:Open Source License

private void logServiceContext(ServiceContext serviceContext, String indent) {
    if (serviceContext != null) {
        fLogger.println(indent + "command: " + serviceContext.getCommand());
        try {/*from  w w w  . ja va  2s  .  c om*/
            fLogger.println(indent + "guestOrUserId: " + serviceContext.getGuestOrUserId());
        } catch (PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        fLogger.println(indent + "workflowAction: " + serviceContext.getWorkflowAction());
        fLogger.println(indent + "attributes:");
        logMap(serviceContext.getAttributes(), indent + "\t");
    }
}