Search in sources :

Example 1 with Step

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.");
    }
}
Also used : DecisionRequiredException(org.apache.wiki.workflow.DecisionRequiredException) Workflow(org.apache.wiki.workflow.Workflow) Page(org.apache.wiki.api.core.Page) Step(org.apache.wiki.workflow.Step) TasksManager(org.apache.wiki.tasks.TasksManager) Fact(org.apache.wiki.workflow.Fact) Decision(org.apache.wiki.workflow.Decision) DifferenceManager(org.apache.wiki.diff.DifferenceManager) WorkflowBuilder(org.apache.wiki.workflow.WorkflowBuilder) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 2 with Step

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");
    }
}
Also used : DecisionRequiredException(org.apache.wiki.workflow.DecisionRequiredException) WorkflowBuilder(org.apache.wiki.workflow.WorkflowBuilder) Workflow(org.apache.wiki.workflow.Workflow) Step(org.apache.wiki.workflow.Step) TasksManager(org.apache.wiki.tasks.TasksManager) Fact(org.apache.wiki.workflow.Fact) Principal(java.security.Principal) Decision(org.apache.wiki.workflow.Decision)

Aggregations

Principal (java.security.Principal)2 TasksManager (org.apache.wiki.tasks.TasksManager)2 Decision (org.apache.wiki.workflow.Decision)2 DecisionRequiredException (org.apache.wiki.workflow.DecisionRequiredException)2 Fact (org.apache.wiki.workflow.Fact)2 Step (org.apache.wiki.workflow.Step)2 Workflow (org.apache.wiki.workflow.Workflow)2 WorkflowBuilder (org.apache.wiki.workflow.WorkflowBuilder)2 Page (org.apache.wiki.api.core.Page)1 WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)1 DifferenceManager (org.apache.wiki.diff.DifferenceManager)1