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();
}
}
Aggregations