use of org.apache.wiki.workflow.Step in project jspwiki by apache.
the class DefaultPageManager method saveText.
@Override
public void saveText(final Context context, final String text) throws WikiException {
// Check if page data actually changed; bail if not
final Page page = context.getPage();
final String oldText = getPureText(page);
final String proposedText = TextUtil.normalizePostData(text);
if (oldText != null && oldText.equals(proposedText)) {
return;
}
// Check if creation of empty pages is allowed; bail if not
final boolean allowEmpty = TextUtil.getBooleanProperty(m_engine.getWikiProperties(), Engine.PROP_ALLOW_CREATION_OF_EMPTY_PAGES, false);
if (!allowEmpty && !wikiPageExists(page) && text.trim().equals("")) {
return;
}
// Create approval workflow for page save; add the diffed, proposed and old text versions as
// Facts for the approver (if approval is required). If submitter is authenticated, any reject
// messages will appear in his/her workflow inbox.
final WorkflowBuilder builder = WorkflowBuilder.getBuilder(m_engine);
final Principal submitter = context.getCurrentUser();
final Step prepTask = m_engine.getManager(TasksManager.class).buildPreSaveWikiPageTask(proposedText);
final Step completionTask = m_engine.getManager(TasksManager.class).buildSaveWikiPageTask();
final String diffText = m_engine.getManager(DifferenceManager.class).makeDiff(context, oldText, proposedText);
final boolean isAuthenticated = context.getWikiSession().isAuthenticated();
final Fact[] facts = new Fact[5];
facts[0] = new Fact(WorkflowManager.WF_WP_SAVE_FACT_PAGE_NAME, page.getName());
facts[1] = new Fact(WorkflowManager.WF_WP_SAVE_FACT_DIFF_TEXT, diffText);
facts[2] = new Fact(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, proposedText);
facts[3] = new Fact(WorkflowManager.WF_WP_SAVE_FACT_CURRENT_TEXT, oldText);
facts[4] = new Fact(WorkflowManager.WF_WP_SAVE_FACT_IS_AUTHENTICATED, isAuthenticated);
final String rejectKey = isAuthenticated ? WorkflowManager.WF_WP_SAVE_REJECT_MESSAGE_KEY : null;
final Workflow workflow = builder.buildApprovalWorkflow(submitter, WorkflowManager.WF_WP_SAVE_APPROVER, prepTask, WorkflowManager.WF_WP_SAVE_DECISION_MESSAGE_KEY, facts, completionTask, rejectKey);
workflow.start(context);
// Let callers know if the page-save requires approval
if (workflow.getCurrentStep() instanceof Decision) {
throw new DecisionRequiredException("The page contents must be approved before they become active.");
}
}
use of org.apache.wiki.workflow.Step in project jspwiki by apache.
the class DefaultUserManager method startUserProfileCreationWorkflow.
/**
* {@inheritDoc}
*/
@Override
public void startUserProfileCreationWorkflow(final Context context, final UserProfile profile) throws WikiException {
final WorkflowBuilder builder = WorkflowBuilder.getBuilder(m_engine);
final Principal submitter = context.getWikiSession().getUserPrincipal();
final Step completionTask = m_engine.getManager(TasksManager.class).buildSaveUserProfileTask(context.getWikiSession().getLocale());
// Add user profile attribute as Facts for the approver (if required)
final boolean hasEmail = profile.getEmail() != null;
final Fact[] facts = new Fact[hasEmail ? 4 : 3];
facts[0] = new Fact(WorkflowManager.WF_UP_CREATE_SAVE_FACT_PREFS_FULL_NAME, profile.getFullname());
facts[1] = new Fact(WorkflowManager.WF_UP_CREATE_SAVE_FACT_PREFS_LOGIN_NAME, profile.getLoginName());
facts[2] = new Fact(WorkflowManager.WF_UP_CREATE_SAVE_FACT_SUBMITTER, submitter.getName());
if (hasEmail) {
facts[3] = new Fact(WorkflowManager.WF_UP_CREATE_SAVE_FACT_PREFS_EMAIL, profile.getEmail());
}
final Workflow workflow = builder.buildApprovalWorkflow(submitter, WorkflowManager.WF_UP_CREATE_SAVE_APPROVER, null, WorkflowManager.WF_UP_CREATE_SAVE_DECISION_MESSAGE_KEY, facts, completionTask, null);
workflow.setAttribute(WorkflowManager.WF_UP_CREATE_SAVE_ATTR_SAVED_PROFILE, profile);
workflow.start(context);
final boolean approvalRequired = workflow.getCurrentStep() instanceof Decision;
// If the profile requires approval, redirect user to message page
if (approvalRequired) {
throw new DecisionRequiredException("This profile must be approved before it becomes active");
}
}
Aggregations