Search in sources :

Example 6 with WorkflowDefinition

use of com.liferay.ide.kaleo.core.model.WorkflowDefinition in project liferay-ide by liferay.

the class UploadWorkflowFileJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        String errorMsgs = KaleoUtil.checkWorkflowDefinitionForErrors(_workflowFile);
        if (!CoreUtil.empty(errorMsgs)) {
            UIUtil.async(new Runnable() {

                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), "Upload Kaleo Workflow", "Unable to upload kaleo workflow:\n\n" + errorMsgs);
                }
            });
            return Status.OK_STATUS;
        }
        JSONObject def = _kaleoConnection.getKaleoDefinitions().getJSONObject(0);
        int companyId = def.getInt("companyId");
        long groupId = def.getLong("groupId");
        long userId = _kaleoConnection.getUserByEmailAddress().getLong("userId");
        RootXmlResource rootXmlResource = new RootXmlResource(new XmlResourceStore(_workflowFile.getContents()));
        WorkflowDefinition workflowDefinition = WorkflowDefinition.TYPE.instantiate(rootXmlResource).nearest(WorkflowDefinition.class);
        String portalLocale = "en_US";
        try {
            portalLocale = _kaleoConnection.getPortalLocale(userId);
        } catch (Exception e) {
        }
        String name = workflowDefinition.getName().content();
        String titleMap = KaleoUtil.createJSONTitleMap(name, portalLocale);
        String content = CoreUtil.readStreamToString(_workflowFile.getContents());
        JSONArray drafts = _kaleoConnection.getKaleoDraftWorkflowDefinitions();
        /*
			 * go through to see if the file that is being uploaded has any
			 * existing drafts
			 */
        JSONObject existingDraft = null;
        if ((drafts != null) && (drafts.length() > 0)) {
            for (int i = 0; i < drafts.length(); i++) {
                JSONObject draft = drafts.getJSONObject(i);
                String draftName = draft.getString("name");
                if ((name != null) && name.equals(draftName)) {
                    if (existingDraft == null) {
                        existingDraft = draft;
                    } else {
                        boolean draftVersion = false;
                        if (draft.getInt("draftVersion") > existingDraft.getInt("draftVersion")) {
                            draftVersion = true;
                        }
                        boolean version = false;
                        if (draft.getInt("version") > existingDraft.getInt("version")) {
                            version = true;
                        }
                        if (draftVersion || version) {
                            existingDraft = draft;
                        }
                    }
                }
            }
        }
        if (existingDraft != null) {
            _kaleoConnection.updateKaleoDraftDefinition(name, titleMap, content, existingDraft.getInt("version"), existingDraft.getInt("draftVersion"), companyId, userId);
        }
        _kaleoConnection.publishKaleoDraftDefinition(name, titleMap, content, companyId + "", userId + "", groupId + "");
    } catch (Exception e) {
        return KaleoUI.createErrorStatus("Error uploading new kaleo workflow file.", e);
    }
    if (_runnable != null) {
        _runnable.run();
    }
    return Status.OK_STATUS;
}
Also used : JSONObject(org.json.JSONObject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) JSONArray(org.json.JSONArray) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource)

Example 7 with WorkflowDefinition

use of com.liferay.ide.kaleo.core.model.WorkflowDefinition in project liferay-ide by liferay.

the class NewNodeOpWizard method performPostDiagramNodeAdded.

protected void performPostDiagramNodeAdded() {
    NewNodeOp newNodeOp = element().nearest(NewNodeOp.class);
    CanTransition newNode = newNodeOp.adapt(CanTransition.class);
    CanTransition node = _diagramNodePart.getLocalModelElement().nearest(CanTransition.class);
    WorkflowDefinition workflowDefinition = node.nearest(WorkflowDefinition.class);
    if ((newNode != null) && (node != null)) {
        Value<String> newNodeName = newNode.getName();
        node.setName(newNodeName.content());
        if (newNodeOp.getConnectedNodes().size() > 0) {
            for (Node diagramNode : newNodeOp.getConnectedNodes()) {
                Value<String> nodeName = diagramNode.getName();
                String diagramNodeName = nodeName.content(true);
                if (diagramNode instanceof ConditionForOp) {
                    ElementList<Condition> conditions = workflowDefinition.getConditions();
                    Condition insertCondition = conditions.insert();
                    insertCondition.setName(diagramNodeName);
                } else if (diagramNode instanceof ForkForOp) {
                    ElementList<Fork> forks = workflowDefinition.getForks();
                    Fork insertFork = forks.insert();
                    insertFork.setName(diagramNodeName);
                } else if (diagramNode instanceof JoinForOp) {
                    ElementList<Join> joins = workflowDefinition.getJoins();
                    Join insertJoin = joins.insert();
                    insertJoin.setName(diagramNodeName);
                } else if (diagramNode instanceof JoinXorForOp) {
                    ElementList<JoinXor> joinXors = workflowDefinition.getJoinXors();
                    JoinXor insertJoinXor = joinXors.insert();
                    insertJoinXor.setName(diagramNodeName);
                } else if (diagramNode instanceof StateForOp) {
                    ElementList<State> states = workflowDefinition.getStates();
                    State insertState = states.insert();
                    insertState.setName(diagramNodeName);
                } else if (diagramNode instanceof TaskForOp) {
                    ElementList<Task> tasks = workflowDefinition.getTasks();
                    Task insertTask = tasks.insert();
                    insertTask.setName(diagramNodeName);
                }
                if (diagramNode instanceof ChooseDiagramNode || node instanceof Condition || node instanceof Fork || node instanceof State || node instanceof Task) {
                    Transition newTransition = node.getTransitions().insert();
                    newTransition.setName(diagramNodeName);
                    newTransition.setTarget(diagramNodeName);
                } else {
                    CanTransition canTransition = diagramNode.nearest(CanTransition.class);
                    ElementList<Transition> transition = canTransition.getTransitions();
                    Transition joinTransition = transition.insert();
                    joinTransition.setName(node.getName().content());
                    joinTransition.setTarget(node.getName().content());
                }
            }
        }
    }
    _actionHandler.postDiagramNodePartAdded(element(), newNode, node);
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) Fork(com.liferay.ide.kaleo.core.model.Fork) JoinXor(com.liferay.ide.kaleo.core.model.JoinXor) JoinXorForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.JoinXorForOp) ChooseDiagramNode(com.liferay.ide.kaleo.core.op.ChooseDiagramNode) Node(com.liferay.ide.kaleo.core.model.Node) StateForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.StateForOp) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) ElementList(org.eclipse.sapphire.ElementList) ForkForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.ForkForOp) ConditionForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.ConditionForOp) Condition(com.liferay.ide.kaleo.core.model.Condition) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Join(com.liferay.ide.kaleo.core.model.Join) ChooseDiagramNode(com.liferay.ide.kaleo.core.op.ChooseDiagramNode) State(com.liferay.ide.kaleo.core.model.State) NewNodeOp(com.liferay.ide.kaleo.core.op.NewNodeOp) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) JoinForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.JoinForOp) TaskForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.TaskForOp)

Example 8 with WorkflowDefinition

use of com.liferay.ide.kaleo.core.model.WorkflowDefinition in project liferay-ide by liferay.

the class JoinNodeAddActionHandler method postDiagramNodePartAdded.

@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
    NewJoinNodeOp newJoinNodeOp = op.nearest(NewJoinNodeOp.class);
    Join newJoin = newNode.nearest(Join.class);
    WorkflowDefinition workflowDefinition = newJoin.nearest(WorkflowDefinition.class);
    for (Node nodeName : newJoinNodeOp.getConnectedNodes()) {
        for (WorkflowNode diagramNode : workflowDefinition.getDiagramNodes()) {
            if (nodeName.getName().content() != null) {
                String name = nodeName.getName().content();
                if (name.equals(diagramNode.getName().content())) {
                    CanTransition canTransition = diagramNode.nearest(CanTransition.class);
                    Transition newTransition = canTransition.getTransitions().insert();
                    newTransition.setName(newJoin.getName().content());
                    newTransition.setTarget(newJoin.getName().content());
                }
            }
        }
    }
    if (newJoinNodeOp.getExitTransitionName().content() != null) {
        Transition newTransition = newJoin.getTransitions().insert();
        newTransition.setTarget(newJoinNodeOp.getExitTransitionName().content());
        newTransition.setName(newJoinNodeOp.getExitTransitionName().content());
    }
}
Also used : Node(com.liferay.ide.kaleo.core.model.Node) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) Join(com.liferay.ide.kaleo.core.model.Join) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) NewJoinNodeOp(com.liferay.ide.kaleo.core.op.NewJoinNodeOp) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Example 9 with WorkflowDefinition

use of com.liferay.ide.kaleo.core.model.WorkflowDefinition in project liferay-ide by liferay.

the class JoinXorNodeAddActionHandler method postDiagramNodePartAdded.

@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
    NewJoinXorNodeOp newJoinXorNodeOp = op.nearest(NewJoinXorNodeOp.class);
    JoinXor newJoinXor = newNode.nearest(JoinXor.class);
    WorkflowDefinition workflowDefinition = newJoinXor.nearest(WorkflowDefinition.class);
    for (Node nodeName : newJoinXorNodeOp.getConnectedNodes()) {
        for (WorkflowNode diagramNode : workflowDefinition.getDiagramNodes()) {
            if (nodeName.getName().content() != null) {
                String name = nodeName.getName().content();
                if (name.equals(diagramNode.getName().content())) {
                    CanTransition canTransition = diagramNode.nearest(CanTransition.class);
                    Transition newTransition = canTransition.getTransitions().insert();
                    newTransition.setName(newJoinXor.getName().content());
                    newTransition.setTarget(newJoinXor.getName().content());
                }
            }
        }
    }
    if (newJoinXorNodeOp.getExitTransitionName().content() != null) {
        Transition newTransition = newJoinXor.getTransitions().insert();
        newTransition.setTarget(newJoinXorNodeOp.getExitTransitionName().content());
        newTransition.setName(newJoinXorNodeOp.getExitTransitionName().content());
    }
}
Also used : JoinXor(com.liferay.ide.kaleo.core.model.JoinXor) NewJoinXorNodeOp(com.liferay.ide.kaleo.core.op.NewJoinXorNodeOp) Node(com.liferay.ide.kaleo.core.model.Node) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Example 10 with WorkflowDefinition

use of com.liferay.ide.kaleo.core.model.WorkflowDefinition in project liferay-ide by liferay.

the class NewNodeAddActionHandler method run.

@Override
public Object run(Presentation context) {
    Object retval = null;
    if (canRunWizard(context)) {
        NewNodeOp op = createOp(context);
        WorkflowDefinition oldWorkflowDefinition = (WorkflowDefinition) getModelElement();
        WorkflowDefinition newWorkflowDefinition = op.getWorkflowDefinition().content(true);
        newWorkflowDefinition.copy(oldWorkflowDefinition);
        // When WorkflowDefinition.getSchemaVersion(),
        // VersionedSchemaDefaultValueService.compute()
        // can't get the version, always returns the default value, directly
        // set the schema version here.
        newWorkflowDefinition.setSchemaVersion(oldWorkflowDefinition.getSchemaVersion().content());
        NewNodeOpWizard wizard = createNewNodeWizard(op, this, context);
        WorkflowDefinitionEditor definitionEditor = context.part().adapt(WorkflowDefinitionEditor.class);
        op.setUseNodeWizards(definitionEditor.isNodeWizardsEnabled());
        runWizard(context, wizard);
        definitionEditor.setNodeWizardsEnabled(op.isUseNodeWizards().content());
    } else {
        retval = insertDiagramPart(context, true);
    }
    return retval;
}
Also used : NewNodeOpWizard(com.liferay.ide.kaleo.ui.wizard.NewNodeOpWizard) NewNodeOp(com.liferay.ide.kaleo.core.op.NewNodeOp) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) WorkflowDefinitionEditor(com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditor)

Aggregations

WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)16 Transition (com.liferay.ide.kaleo.core.model.Transition)6 Node (com.liferay.ide.kaleo.core.model.Node)5 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)5 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)4 Join (com.liferay.ide.kaleo.core.model.Join)4 Fork (com.liferay.ide.kaleo.core.model.Fork)3 State (com.liferay.ide.kaleo.core.model.State)3 Task (com.liferay.ide.kaleo.core.model.Task)3 NewNodeOp (com.liferay.ide.kaleo.core.op.NewNodeOp)3 Value (org.eclipse.sapphire.Value)3 Version (org.eclipse.sapphire.Version)3 Condition (com.liferay.ide.kaleo.core.model.Condition)2 JoinXor (com.liferay.ide.kaleo.core.model.JoinXor)2 AssignableOp (com.liferay.ide.kaleo.core.op.AssignableOp)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 Element (org.eclipse.sapphire.Element)2 RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)2