Search in sources :

Example 6 with IKaleoConnection

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

the class WorkflowDefinitionsFolder method _scheduleCacheDefinitionsJob.

private void _scheduleCacheDefinitionsJob() {
    if (_cacheDefinitionsJob == null) {
        _cacheDefinitionsJob = new Job("Loading kaleo workflows...") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                _currentStatus = KaleoUI.createInfoStatus("Loading kaleo workflows...");
                _site.getService().update();
                IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(_getLiferayServer());
                List<WorkflowDefinitionEntry> definitionEntries = new ArrayList<>();
                IStatus errorStatus = null;
                try {
                    JSONArray kaleoDefinitions = kaleoConnection.getKaleoDefinitions();
                    JSONArray kaleoDraftDefinitions = kaleoConnection.getKaleoDraftWorkflowDefinitions();
                    for (int i = 0; i < kaleoDefinitions.length(); i++) {
                        JSONObject definition = (JSONObject) kaleoDefinitions.get(i);
                        /*
							 * if( definition.has( "active" ) &&
							 * !definition.getBoolean( "active" ) ) { continue;
							 * }
							 */
                        /*
							 * kaleoConnection.getLatestKaleoDraftDefinition(
							 * definition.getString( "name" ),
							 * definition.getString( "version" ) );
							 */
                        WorkflowDefinitionEntry definitionEntry = WorkflowDefinitionEntry.createFromJsObject(definition);
                        definitionEntry.setParent(WorkflowDefinitionsFolder.this);
                        if (kaleoDraftDefinitions != null) {
                            for (int j = 0; j < kaleoDraftDefinitions.length(); j++) {
                                JSONObject draftDefinition = kaleoDraftDefinitions.getJSONObject(j);
                                if (_same(definition, draftDefinition, "name") && _same(definition, draftDefinition, "version")) {
                                    int draftVersion = draftDefinition.getInt("draftVersion");
                                    if (definitionEntry.getDraftVersion() < draftVersion) {
                                        if (draftDefinition.has("title")) {
                                            definitionEntry.setTitle(draftDefinition.getString("title"));
                                        }
                                        if (draftDefinition.has("titleMap")) {
                                            definitionEntry.setTitleMap(draftDefinition.getString("titleMap"));
                                        } else {
                                            definitionEntry.setTitleMap(KaleoUtil.createJSONTitleMap(definitionEntry.getTitle()));
                                        }
                                        definitionEntry.setCompanyId(draftDefinition.getLong("companyId"));
                                        definitionEntry.setContent(draftDefinition.getString("content"));
                                        definitionEntry.setDraftVersion(draftDefinition.getInt("draftVersion"));
                                        String titleCurrentValue = draftDefinition.getString("titleCurrentValue");
                                        definitionEntry.setTitleCurrentValue(titleCurrentValue);
                                        definitionEntry.setUserId(draftDefinition.getLong("userId"));
                                        definitionEntry.setGroupId(draftDefinition.getLong("groupId"));
                                        definitionEntry.setLocation(kaleoConnection.getHost() + ":" + kaleoConnection.getHttpPort());
                                    }
                                }
                            }
                        }
                        definitionEntries.add(definitionEntry);
                    }
                    if (kaleoDraftDefinitions != null) {
                        for (int i = 0; i < kaleoDraftDefinitions.length(); i++) {
                            JSONObject draftDefinition = kaleoDraftDefinitions.getJSONObject(i);
                            WorkflowDefinitionEntry draftEntry = null;
                            for (WorkflowDefinitionEntry entry : definitionEntries) {
                                if (entry.getName().equals(draftDefinition.getString("name"))) {
                                    if (entry.getVersion() == draftDefinition.getInt("version")) {
                                        draftEntry = entry;
                                        if (entry.getDraftVersion() < draftDefinition.getInt("draftVersion")) {
                                            entry.setCompanyId(draftDefinition.getLong("companyId"));
                                            entry.setContent(draftDefinition.getString("content"));
                                            entry.setDraftVersion(draftDefinition.getInt("draftVersion"));
                                            entry.setTitleCurrentValue(draftDefinition.getString("titleCurrentValue"));
                                            entry.setUserId(draftDefinition.getLong("userId"));
                                            entry.setLocation(kaleoConnection.getHost() + ":" + kaleoConnection.getHttpPort());
                                        }
                                    }
                                }
                            }
                            if (draftEntry == null) {
                            /*
									 * draftEntry = WorkflowDefinitionEntry.
									 * createFromJSONObject( draftDefinition );
									 * draftEntry.setParent(
									 * WorkflowDefinitionsFolder.this );
									 * draftEntry.setDraftVersion(
									 * draftDefinition.getInt( "draftVersion" )
									 * ); definitionEntries.add( draftEntry );
									 */
                            }
                        }
                    }
                    _cachedDefinitions = definitionEntries.toArray(new WorkflowDefinitionEntry[0]);
                } catch (Exception e) {
                    errorStatus = KaleoUI.createErrorStatus(e);
                }
                if (errorStatus != null) {
                    _currentStatus = errorStatus;
                } else {
                    _currentStatus = null;
                }
                _site.getService().update();
                _cacheDefinitionsJob = null;
                return Status.OK_STATUS;
            }
        };
        _cacheDefinitionsJob.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) Job(org.eclipse.core.runtime.jobs.Job) JSONException(org.json.JSONException)

Aggregations

IKaleoConnection (com.liferay.ide.kaleo.core.IKaleoConnection)6 Job (org.eclipse.core.runtime.jobs.Job)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)3 CommonViewer (org.eclipse.ui.navigator.CommonViewer)3 WorkflowDefinitionEntry (com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry)2 WorkflowDefinitionsFolder (com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsFolder)2 UploadWorkflowFileJob (com.liferay.ide.kaleo.ui.util.UploadWorkflowFileJob)2 IFile (org.eclipse.core.resources.IFile)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 KaleoAPIException (com.liferay.ide.kaleo.core.KaleoAPIException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IDocument (org.eclipse.jface.text.IDocument)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TransferData (org.eclipse.swt.dnd.TransferData)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IViewPart (org.eclipse.ui.IViewPart)1 PartInitException (org.eclipse.ui.PartInitException)1