/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.wiki.util.test;
import com.liferay.portal.kernel.model.BaseModel;
import com.liferay.portal.kernel.model.ClassedModel;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.test.util.RandomTestUtil;
import com.liferay.portal.kernel.test.util.TestPropsValues;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.wiki.model.WikiPage;
import com.liferay.wiki.service.WikiNodeLocalServiceUtil;
import com.liferay.wiki.service.WikiPageLocalServiceUtil;
/**
* @author Roberto Díaz
*/
public class WikiPageTrashHandlerTestUtil {
public static BaseModel<?> addBaseModelWithWorkflow(
BaseModel<?> parentBaseModel, boolean approved,
ServiceContext serviceContext)
throws Exception {
serviceContext = (ServiceContext)serviceContext.clone();
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
return WikiTestUtil.addPage(
TestPropsValues.getUserId(), serviceContext.getScopeGroupId(),
(Long)parentBaseModel.getPrimaryKeyObj(), getSearchKeywords(),
approved);
}
public static BaseModel<?> getBaseModel(long primaryKey) throws Exception {
return WikiPageLocalServiceUtil.getPageByPageId(primaryKey);
}
public static Class<?> getBaseModelClass() {
return WikiPage.class;
}
public static String getBaseModelName(ClassedModel classedModel) {
WikiPage page = (WikiPage)classedModel;
return page.getTitle();
}
public static int getNotInTrashBaseModelsCount(BaseModel<?> parentBaseModel)
throws Exception {
return WikiPageLocalServiceUtil.getPagesCount(
(Long)parentBaseModel.getPrimaryKeyObj(), true,
WorkflowConstants.STATUS_ANY);
}
public static BaseModel<?> getParentBaseModel(
Group group, ServiceContext serviceContext)
throws Exception {
serviceContext = (ServiceContext)serviceContext.clone();
serviceContext.setWorkflowAction(WorkflowConstants.STATUS_APPROVED);
return WikiNodeLocalServiceUtil.addNode(
TestPropsValues.getUserId(),
RandomTestUtil.randomString(_NODE_NAME_MAX_LENGTH),
RandomTestUtil.randomString(), serviceContext);
}
public static String getSearchKeywords() {
return _PAGE_TITLE;
}
public static long getTrashEntryClassPK(ClassedModel classedModel) {
WikiPage page = (WikiPage)classedModel;
return page.getResourcePrimKey();
}
public static void moveBaseModelToTrash(long primaryKey) throws Exception {
WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(primaryKey);
WikiPageLocalServiceUtil.movePageToTrash(
TestPropsValues.getUserId(), page.getNodeId(), page.getTitle());
}
public static void moveParentBaseModelToTrash(long primaryKey)
throws Exception {
WikiNodeLocalServiceUtil.moveNodeToTrash(
TestPropsValues.getUserId(), primaryKey);
}
public static BaseModel<?> updateBaseModel(
long primaryKey, ServiceContext serviceContext)
throws Exception {
WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(primaryKey);
serviceContext = (ServiceContext)serviceContext.clone();
return WikiPageLocalServiceUtil.updatePage(
TestPropsValues.getUserId(), page.getNodeId(), page.getTitle(),
page.getVersion(), RandomTestUtil.randomString(),
RandomTestUtil.randomString(), false, page.getFormat(),
page.getParentTitle(), page.getRedirectTitle(), serviceContext);
}
private static final int _NODE_NAME_MAX_LENGTH = 75;
private static final String _PAGE_TITLE = RandomTestUtil.randomString(255);
}