Example usage for com.liferay.portal.kernel.service ServiceContextFactory getInstance

List of usage examples for com.liferay.portal.kernel.service ServiceContextFactory getInstance

Introduction

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

Prototype

public static ServiceContext getInstance(PortletRequest portletRequest) throws PortalException 

Source Link

Usage

From source file:com.liferay.akismet.hook.action.AkismetEditDiscussionAction.java

License:Open Source License

protected void updateStatus(HttpServletRequest request, HttpServletResponse response) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long messageId = ParamUtil.getLong(request, "messageId");

    boolean spam = ParamUtil.getBoolean(request, "spam");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(request);

    if (spam) {/*from www  . j a v a  2  s  . c  om*/
        MBMessage message = MBMessageLocalServiceUtil.updateStatus(themeDisplay.getUserId(), messageId,
                WorkflowConstants.STATUS_DENIED, serviceContext);

        if (AkismetUtil.isMessageBoardsEnabled(message.getCompanyId())) {
            AkismetUtil.submitSpam(message);
        }
    } else {
        MBMessage message = MBMessageLocalServiceUtil.updateStatus(themeDisplay.getUserId(), messageId,
                WorkflowConstants.STATUS_APPROVED, serviceContext);

        if (AkismetUtil.isMessageBoardsEnabled(message.getCompanyId())) {
            AkismetUtil.submitHam(message);
        }
    }
}

From source file:com.liferay.asset.display.template.web.internal.portlet.action.EditAssetDisplayTemplateMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long assetDisplayTemplateId = ParamUtil.getLong(actionRequest, "assetDisplayTemplateId");

    String name = ParamUtil.getString(actionRequest, "name");
    long classNameId = ParamUtil.getLong(actionRequest, "classNameId");
    String language = ParamUtil.getString(actionRequest, "language");
    String scriptContent = ParamUtil.getString(actionRequest, "scriptContent");
    boolean main = ParamUtil.getBoolean(actionRequest, "main");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    if (assetDisplayTemplateId <= 0) {
        _assetDisplayTemplateService.addAssetDisplayTemplate(themeDisplay.getScopeGroupId(),
                themeDisplay.getUserId(), name, classNameId, language, scriptContent, main, serviceContext);
    } else {/*www  .  j av  a 2 s  .  c  o  m*/
        _assetDisplayTemplateService.updateAssetDisplayTemplate(assetDisplayTemplateId, name, classNameId,
                language, scriptContent, main, serviceContext);
    }
}

From source file:com.liferay.asset.publisher.web.portlet.AssetPublisherPortlet.java

License:Open Source License

public void getFieldValue(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    try {/*  ww w.  j a  v  a 2  s . c o  m*/
        ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);

        long structureId = ParamUtil.getLong(resourceRequest, "structureId");

        Fields fields = (Fields) serviceContext.getAttribute(Fields.class.getName() + structureId);

        if (fields == null) {
            String fieldsNamespace = ParamUtil.getString(resourceRequest, "fieldsNamespace");

            fields = DDMUtil.getFields(structureId, fieldsNamespace, serviceContext);
        }

        String fieldName = ParamUtil.getString(resourceRequest, "name");

        Field field = fields.get(fieldName);

        Serializable fieldValue = field.getValue(themeDisplay.getLocale(), 0);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        if (fieldValue != null) {
            jsonObject.put("success", true);
        } else {
            jsonObject.put("success", false);

            writeJSON(resourceRequest, resourceResponse, jsonObject);

            return;
        }

        DDMStructure ddmStructure = field.getDDMStructure();

        String type = ddmStructure.getFieldType(fieldName);

        Serializable displayValue = DDMUtil.getDisplayFieldValue(themeDisplay, fieldValue, type);

        jsonObject.put("displayValue", String.valueOf(displayValue));

        if (fieldValue instanceof Boolean) {
            jsonObject.put("value", (Boolean) fieldValue);
        } else if (fieldValue instanceof Date) {
            DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMM ddHHmmss");

            jsonObject.put("value", dateFormat.format(fieldValue));
        } else if (fieldValue instanceof Double) {
            jsonObject.put("value", (Double) fieldValue);
        } else if (fieldValue instanceof Float) {
            jsonObject.put("value", (Float) fieldValue);
        } else if (fieldValue instanceof Integer) {
            jsonObject.put("value", (Integer) fieldValue);
        } else if (fieldValue instanceof Number) {
            jsonObject.put("value", String.valueOf(fieldValue));
        } else {
            jsonObject.put("value", (String) fieldValue);
        }

        writeJSON(resourceRequest, resourceResponse, jsonObject);
    } catch (Exception e) {
        throw new PortletException(e);
    }
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

protected void checkInEntries(ActionRequest actionRequest) throws Exception {

    long[] fileEntryIds = ParamUtil.getLongValues(actionRequest, "rowIdsFileEntry");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    for (long fileEntryId : fileEntryIds) {
        _dlAppService.checkInFileEntry(fileEntryId, false, StringPool.BLANK, serviceContext);
    }/*www . ja  v a2s .c om*/
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

protected void checkOutEntries(ActionRequest actionRequest) throws Exception {

    long[] fileEntryIds = ParamUtil.getLongValues(actionRequest, "rowIdsFileEntry");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    for (long fileEntryId : fileEntryIds) {
        _dlAppService.checkOutFileEntry(fileEntryId, serviceContext);
    }//from  w  w  w .  ja  va2 s  .c om
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

protected void checkInFileEntries(ActionRequest actionRequest) throws Exception {

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    boolean majorVersion = ParamUtil.getBoolean(actionRequest, "majorVersion");
    String changeLog = ParamUtil.getString(actionRequest, "changeLog");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    if (fileEntryId > 0) {
        _dlAppService.checkInFileEntry(fileEntryId, majorVersion, changeLog, serviceContext);
    } else {/* w w w  .ja va2  s . c  o m*/
        long[] fileEntryIds = ParamUtil.getLongValues(actionRequest, "rowIdsFileEntry");

        for (int i = 0; i < fileEntryIds.length; i++) {
            _dlAppService.checkInFileEntry(fileEntryIds[i], majorVersion, changeLog, serviceContext);
        }
    }
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

protected void checkOutFileEntries(ActionRequest actionRequest) throws Exception {

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    if (fileEntryId > 0) {
        _dlAppService.checkOutFileEntry(fileEntryId, serviceContext);
    } else {/*from www .jav a  2s. c  om*/
        long[] fileEntryIds = ParamUtil.getLongValues(actionRequest, "rowIdsFileEntry");

        for (int i = 0; i < fileEntryIds.length; i++) {
            _dlAppService.checkOutFileEntry(fileEntryIds[i], serviceContext);
        }
    }
}

From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public int putResource(WebDAVRequest webDAVRequest) throws WebDAVException {
    File file = null;//ww  w. ja v  a  2  s  .  c  o m

    try {
        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

        String[] pathArray = webDAVRequest.getPathArray();

        long companyId = webDAVRequest.getCompanyId();
        long groupId = webDAVRequest.getGroupId();
        long parentFolderId = getParentFolderId(companyId, pathArray);
        String title = getTitle(pathArray);
        String description = StringPool.BLANK;
        String changeLog = StringPool.BLANK;

        ServiceContext serviceContext = ServiceContextFactory.getInstance(request);

        serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
        serviceContext.setAddGuestPermissions(true);

        String extension = FileUtil.getExtension(title);

        file = FileUtil.createTempFile(extension);

        FileUtil.write(file, request.getInputStream());

        String contentType = getContentType(request, file, title, extension);

        try {
            FileEntry fileEntry = _dlAppService.getFileEntry(groupId, parentFolderId, title);

            if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

                return WebDAVUtil.SC_LOCKED;
            }

            long fileEntryId = fileEntry.getFileEntryId();

            description = fileEntry.getDescription();

            populateServiceContext(serviceContext, fileEntry);

            serviceContext.setCommand(Constants.UPDATE_WEBDAV);

            _dlAppService.updateFileEntry(fileEntryId, title, contentType, title, description, changeLog, false,
                    file, serviceContext);
        } catch (NoSuchFileEntryException nsfee) {
            if (_log.isDebugEnabled()) {
                _log.debug(nsfee, nsfee);
            }

            serviceContext.setCommand(Constants.ADD_WEBDAV);

            _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description,
                    changeLog, file, serviceContext);
        }

        if (_log.isInfoEnabled()) {
            _log.info("Added " + StringUtil.merge(pathArray, StringPool.SLASH));
        }

        return HttpServletResponse.SC_CREATED;
    } catch (FileSizeException fse) {
        if (_log.isDebugEnabled()) {
            _log.debug(fse, fse);
        }

        return HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
    } catch (NoSuchFolderException nsfe) {
        if (_log.isDebugEnabled()) {
            _log.debug(nsfe, nsfe);
        }

        return HttpServletResponse.SC_CONFLICT;
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return HttpServletResponse.SC_FORBIDDEN;
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn(pe, pe);
        }

        return HttpServletResponse.SC_CONFLICT;
    } catch (Exception e) {
        throw new WebDAVException(e);
    } finally {
        FileUtil.delete(file);
    }
}

From source file:com.liferay.invitation.invite.members.web.internal.portlet.InviteMembersPortlet.java

License:Open Source License

protected void doSendInvite(ActionRequest actionRequest) throws Exception {
    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long[] receiverUserIds = getLongArray(actionRequest, "receiverUserIds");
    String[] receiverEmailAddresses = getStringArray(actionRequest, "receiverEmailAddresses");
    long invitedRoleId = ParamUtil.getLong(actionRequest, "invitedRoleId");
    long invitedTeamId = ParamUtil.getLong(actionRequest, "invitedTeamId");

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!_userLocalService.hasGroupUser(groupId, themeDisplay.getUserId())) {

        return;/*  www  .jav  a  2  s  .  c o  m*/
    }

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    Group group = _groupLocalService.getGroup(groupId);

    PortletURL portletURL = PortletProviderUtil.getPortletURL(actionRequest, group,
            UserNotificationEvent.class.getName(), PortletProvider.Action.VIEW);

    serviceContext.setAttribute("redirectURL", portletURL.toString());

    HttpServletRequest request = _portal.getHttpServletRequest(actionRequest);

    String createAccountURL = _portal.getCreateAccountURL(request, themeDisplay);

    serviceContext.setAttribute("createAccountURL", createAccountURL);

    serviceContext.setAttribute("loginURL", themeDisplay.getURLSignIn());

    _memberRequestLocalService.addMemberRequests(themeDisplay.getUserId(), groupId, receiverUserIds,
            invitedRoleId, invitedTeamId, serviceContext);

    _memberRequestLocalService.addMemberRequests(themeDisplay.getUserId(), groupId, receiverEmailAddresses,
            invitedRoleId, invitedTeamId, serviceContext);
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.AddLayoutPageTemplateEntryMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    long layoutPageTemplateCollectionId = ParamUtil.getLong(actionRequest, "layoutPageTemplateCollectionId");

    String name = ParamUtil.getString(actionRequest, "name");

    try {//w ww.j  ava 2  s  .  c o m
        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        LayoutPageTemplateEntry layoutPageTemplateEntry = _layoutPageTemplateEntryService
                .addLayoutPageTemplateEntry(serviceContext.getScopeGroupId(), layoutPageTemplateCollectionId,
                        name, Collections.<FragmentEntry>emptyList(), serviceContext);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("redirectURL", getRedirectURL(actionResponse, layoutPageTemplateEntry));

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } catch (PortalException pe) {
        hideDefaultSuccessMessage(actionRequest);

        _layoutPageTemplateEntryExceptionRequestHandler.handlePortalException(actionRequest, actionResponse,
                pe);
    }
}