Example usage for com.liferay.portal.kernel.util Constants RENAME

List of usage examples for com.liferay.portal.kernel.util Constants RENAME

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Constants RENAME.

Prototype

String RENAME

To view the source code for com.liferay.portal.kernel.util Constants RENAME.

Click Source Link

Usage

From source file:com.liferay.message.boards.web.internal.portlet.action.EditMessageAttachmentsMVCActionCommand.java

License:Open Source License

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

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*from  w ww  .ja  va2s . c o  m*/
        if (cmd.equals(Constants.CHECK)) {
            JSONObject jsonObject = RestoreEntryUtil.checkEntry(actionRequest);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

            return;
        } else if (cmd.equals(Constants.DELETE)) {
            deleteAttachment(actionRequest);
        } else if (cmd.equals(Constants.EMPTY_TRASH)) {
            emptyTrash(actionRequest);
        } else if (cmd.equals(Constants.RENAME)) {
            restoreRename(actionRequest);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreEntries(actionRequest);
        } else if (cmd.equals(Constants.OVERRIDE)) {
            restoreOverride(actionRequest);
        }

        if (Validator.isNotNull(cmd)) {
            String redirect = ParamUtil.getString(actionRequest, "redirect");

            sendRedirect(actionRequest, actionResponse, redirect);
        }
    } catch (PrincipalException pe) {
        SessionErrors.add(actionRequest, pe.getClass());

        actionResponse.setRenderParameter("mvcPath", "/message_boards/error.jsp");
    }
}

From source file:com.liferay.trash.web.internal.portlet.TrashPortlet.java

License:Open Source License

public void restoreEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (cmd.equals(Constants.RENAME)) {
        checkEntry(actionRequest, actionResponse);

        restoreRename(actionRequest, actionResponse);
    } else if (cmd.equals(Constants.OVERRIDE)) {
        restoreOverride(actionRequest, actionResponse);
    }/* w w  w  .ja v a 2 s . com*/
}

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

@Override
public void renamePage(long userId, long nodeId, String title, String newTitle, boolean strict,
        ServiceContext serviceContext) throws PortalException {

    wikiPageTitleValidator.validate(newTitle);

    if (StringUtil.equalsIgnoreCase(title, newTitle)) {
        throw new DuplicatePageException(newTitle);
    }//from  w w  w  .ja v  a2s.  co  m

    if (isUsedTitle(nodeId, newTitle)) {

        // Support moving back to a previously moved title

        WikiPage page = getPage(nodeId, newTitle);

        if (((page.getVersion() == WikiPageConstants.VERSION_DEFAULT) && (page.getContent().length() < 200))
                || !strict) {

            deletePage(nodeId, newTitle);
        } else {
            throw new DuplicatePageException(newTitle);
        }
    }

    WikiPage page = getPage(nodeId, title);

    String summary = page.getSummary();

    if (Validator.isNotNull(page.getRedirectTitle())) {
        page.setRedirectTitle(StringPool.BLANK);

        summary = StringPool.BLANK;
    }

    serviceContext.setCommand(Constants.RENAME);

    updatePage(userId, page, 0, newTitle, page.getContent(), summary, page.getMinorEdit(), page.getFormat(),
            page.getParentTitle(), page.getRedirectTitle(), serviceContext);
}

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

@Override
public WikiPage updateStatus(long userId, WikiPage page, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    // Page//from w  ww  . j a  va  2  s.c  o m

    User user = userPersistence.findByPrimaryKey(userId);

    int oldStatus = page.getStatus();

    page.setStatus(status);
    page.setStatusByUserId(userId);
    page.setStatusByUserName(user.getFullName());
    page.setStatusDate(new Date());

    wikiPagePersistence.update(page);

    if (status == WorkflowConstants.STATUS_APPROVED) {
        String cmd = GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_COMMAND));

        if (cmd.equals(Constants.RENAME)) {
            long resourcePrimKey = page.getResourcePrimKey();

            WikiPage oldPage = getPage(resourcePrimKey, true);

            page = doRenamePage(userId, page.getNodeId(), oldPage.getTitle(), page.getTitle(), serviceContext);
        }

        // Asset

        if ((oldStatus != WorkflowConstants.STATUS_APPROVED)
                && (page.getVersion() != WikiPageConstants.VERSION_DEFAULT)) {

            AssetEntry draftAssetEntry = assetEntryLocalService.fetchEntry(WikiPage.class.getName(),
                    page.getPrimaryKey());

            if (draftAssetEntry != null) {
                long[] assetCategoryIds = draftAssetEntry.getCategoryIds();
                String[] assetTagNames = draftAssetEntry.getTagNames();

                List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(draftAssetEntry.getEntryId(),
                        AssetLinkConstants.TYPE_RELATED, false);

                long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

                AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, page.getGroupId(),
                        page.getCreateDate(), page.getModifiedDate(), WikiPage.class.getName(),
                        page.getResourcePrimKey(), page.getUuid(), 0, assetCategoryIds, assetTagNames, true,
                        true, null, null, page.getCreateDate(), null, ContentTypes.TEXT_HTML, page.getTitle(),
                        null, null, null, null, 0, 0, null);

                // Asset Links

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

                SystemEventHierarchyEntryThreadLocal.push(WikiPage.class);

                try {
                    assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId());
                } finally {
                    SystemEventHierarchyEntryThreadLocal.pop(WikiPage.class);
                }
            }
        }

        assetEntryLocalService.updateVisible(WikiPage.class.getName(), page.getResourcePrimKey(), true);

        // Social

        WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = configurationProvider
                .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                        new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

        if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH) && (!page.isMinorEdit()
                || wikiGroupServiceOverriddenConfiguration.pageMinorEditAddSocialActivity())) {

            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

            extraDataJSONObject.put("title", page.getTitle());
            extraDataJSONObject.put("version", page.getVersion());

            int type = WikiActivityKeys.UPDATE_PAGE;

            if (serviceContext.isCommandAdd()) {
                type = WikiActivityKeys.ADD_PAGE;
            }

            SocialActivityManagerUtil.addActivity(userId, page, type, extraDataJSONObject.toString(), 0);
        }

        // Subscriptions

        if (NotificationThreadLocal.isEnabled()
                && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditSendEmail())) {

            notifySubscribers(userId, page, (String) workflowContext.get(WorkflowConstants.CONTEXT_URL),
                    serviceContext);
        }

        // Cache

        clearPageCache(page);
    }

    // Head

    if (status == WorkflowConstants.STATUS_APPROVED) {
        page.setHead(true);

        List<WikiPage> pages = wikiPagePersistence.findByN_T_H(page.getNodeId(), page.getTitle(), true);

        for (WikiPage curPage : pages) {
            if (!curPage.equals(page)) {
                curPage.setHead(false);

                wikiPagePersistence.update(curPage);
            }
        }
    } else if (status != WorkflowConstants.STATUS_IN_TRASH) {
        page.setHead(false);

        List<WikiPage> pages = wikiPagePersistence.findByN_T_S(page.getNodeId(), page.getTitle(),
                WorkflowConstants.STATUS_APPROVED);

        for (WikiPage curPage : pages) {
            if (!curPage.equals(page)) {
                curPage.setHead(true);

                wikiPagePersistence.update(curPage);

                break;
            }
        }
    }

    // Indexer

    Indexer<WikiPage> indexer = IndexerRegistryUtil.nullSafeGetIndexer(WikiPage.class);

    indexer.reindex(page);

    return wikiPagePersistence.update(page);
}

From source file:com.liferay.wiki.web.internal.portlet.action.EditPageAttachmentsMVCActionCommand.java

License:Open Source License

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

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    PortletConfig portletConfig = getPortletConfig(actionRequest);

    try {//  w  w w. j a va 2  s.  c om
        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            Throwable cause = uploadException.getCause();

            if (uploadException.isExceededFileSizeLimit()) {
                throw new FileSizeException(cause);
            }

            if (uploadException.isExceededLiferayFileItemSizeLimit()) {
                throw new LiferayFileItemException(cause);
            }

            if (uploadException.isExceededUploadRequestSizeLimit()) {
                throw new UploadRequestSizeException(cause);
            }

            throw new PortalException(cause);
        } else if (cmd.equals(Constants.ADD)) {
            _wikiAttachmentsHelper.addAttachments(actionRequest);
        } else if (cmd.equals(Constants.CHECK)) {
            JSONObject jsonObject = RestoreEntryUtil.checkEntry(actionRequest);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

            return;
        } else if (cmd.equals(Constants.DELETE)) {
            deleteAttachment(actionRequest, false);
        } else if (cmd.equals(Constants.EMPTY_TRASH)) {
            _wikiAttachmentsHelper.emptyTrash(actionRequest);
        } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
            deleteAttachment(actionRequest, true);
        } else if (cmd.equals(Constants.RENAME)) {
            _wikiAttachmentsHelper.restoreRename(actionRequest);
        } else if (cmd.equals(Constants.RESTORE)) {
            _wikiAttachmentsHelper.restoreEntries(actionRequest);

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

            if (Validator.isNotNull(redirect)) {
                actionResponse.sendRedirect(redirect);
            }
        } else if (cmd.equals(Constants.OVERRIDE)) {
            _wikiAttachmentsHelper.restoreOverride(actionRequest);
        }
    } catch (NoSuchNodeException | NoSuchPageException | PrincipalException e) {

        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcPath", "/wiki/error.jsp");
    } catch (Exception e) {
        handleUploadException(portletConfig, actionRequest, actionResponse, cmd, e);
    }
}

From source file:com.liferay.wiki.web.internal.portlet.action.MovePageMVCActionCommand.java

License:Open Source License

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

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/* ww w  . ja  v a2 s. c  o m*/
        if (cmd.equals(Constants.CHANGE_PARENT)) {
            changeParentPage(actionRequest);
        } else if (cmd.equals(Constants.RENAME)) {
            renamePage(actionRequest);
        }

        if (Validator.isNotNull(cmd)) {
            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchNodeException || e instanceof NoSuchPageException
                || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());
        } else if (e instanceof DuplicatePageException || e instanceof PageContentException
                || e instanceof PageTitleException) {

            SessionErrors.add(actionRequest, e.getClass());
        } else {
            throw e;
        }
    }
}