Example usage for com.mongodb BasicDBObject get

List of usage examples for com.mongodb BasicDBObject get

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject get.

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value from this object

Usage

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

protected String readId(BasicDBObject dbObject, String fieldName) {
    Object value = dbObject.get(fieldName);
    return value != null ? value.toString() : null;
}

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

@SuppressWarnings("unchecked")
protected Map<String, Object> readObjectMap(BasicDBObject dbObject, String fieldName) {
    return (Map<String, Object>) dbObject.get(fieldName);
}

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

protected String readString(BasicDBObject dbObject, String fieldName) {
    return (String) dbObject.get(fieldName);
}

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

protected Long readLong(BasicDBObject dbObject, String fieldName) {
    Object object = dbObject.get(fieldName);
    if (object == null) {
        return null;
    }/*from  w w w . j  av  a 2s. co  m*/
    if (object instanceof Long) {
        return (Long) object;
    }
    return ((Number) object).longValue();
}

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

protected Boolean readBoolean(BasicDBObject dbObject, String fieldName) {
    return (Boolean) dbObject.get(fieldName);
}

From source file:com.heisenberg.mongo.MongoCollection.java

License:Apache License

protected LocalDateTime readTime(BasicDBObject dbObject, String fieldName) {
    Date date = (Date) dbObject.get(fieldName);
    return (date != null ? new LocalDateTime(date) : null);
}

From source file:com.heisenberg.mongo.MongoWorkflowInstanceStore.java

License:Apache License

public WorkflowInstanceImpl readProcessInstance(BasicDBObject dbWorkflowInstance) {
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.workflowEngine = processEngine;
    workflowInstance.workflowInstance = workflowInstance;
    workflowInstance.id = readId(dbWorkflowInstance, fields._id);
    workflowInstance.organizationId = readString(dbWorkflowInstance, fields.organizationId);
    workflowInstance.callerWorkflowInstanceId = readId(dbWorkflowInstance, fields.callerWorkflowInstanceId);
    workflowInstance.callerActivityInstanceId = readId(dbWorkflowInstance, fields.callerActivityInstanceId);
    workflowInstance.start = readTime(dbWorkflowInstance, fields.start);
    workflowInstance.end = readTime(dbWorkflowInstance, fields.end);
    workflowInstance.duration = readLong(dbWorkflowInstance, fields.duration);
    workflowInstance.lock = readLock((BasicDBObject) dbWorkflowInstance.get(fields.lock));
    workflowInstance.workflowId = readId(dbWorkflowInstance, fields.workflowId);
    WorkflowImpl workflow = processEngine.newWorkflowQuery().representation(Representation.EXECUTABLE)
            .id(workflowInstance.workflowId).get();
    if (workflow != null) {
        workflowInstance.workflow = workflow;
        workflowInstance.workflowId = workflow != null ? workflow.id : null;
        workflowInstance.scopeDefinition = workflowInstance.workflow;
    } else {/*from ww w  .j a  va  2 s . c o m*/
        throw new RuntimeException("No workflow for instance " + workflowInstance.id);
    }

    Map<Object, ActivityInstanceImpl> allActivityInstances = new LinkedHashMap<>();
    Map<Object, Object> parentIds = new HashMap<>();
    List<BasicDBObject> dbActivityInstances = readList(dbWorkflowInstance, fields.activityInstances);
    if (dbActivityInstances != null) {
        for (BasicDBObject dbActivityInstance : dbActivityInstances) {
            ActivityInstanceImpl activityInstance = readActivityInstance(workflowInstance, dbActivityInstance);
            allActivityInstances.put(activityInstance.id, activityInstance);
            parentIds.put(activityInstance.id, dbActivityInstance.get(fields.parent));
        }
    }

    for (ActivityInstanceImpl activityInstance : allActivityInstances.values()) {
        Object parentId = parentIds.get(activityInstance.id);
        activityInstance.parent = (parentId != null ? allActivityInstances.get(parentId.toString())
                : workflowInstance);
        activityInstance.parent.addActivityInstance(activityInstance);
    }

    workflowInstance.variableInstances = readVariableInstances(dbWorkflowInstance, workflowInstance);
    workflowInstance.work = readWork(dbWorkflowInstance, fields.work, workflowInstance);
    workflowInstance.workAsync = readWork(dbWorkflowInstance, fields.workAsync, workflowInstance);

    return workflowInstance;
}

From source file:com.heisenberg.mongo.MongoWorkflowInstanceStore.java

License:Apache License

@SuppressWarnings("unchecked")
protected Queue<ActivityInstanceImpl> readWork(BasicDBObject dbWorkflowInstance, String fieldName,
        WorkflowInstanceImpl workflowInstance) {
    Queue<ActivityInstanceImpl> workQueue = null;
    List<ObjectId> workActivityInstanceIds = (List<ObjectId>) dbWorkflowInstance.get(fieldName);
    if (workActivityInstanceIds != null) {
        workQueue = new LinkedList<>();
        for (ObjectId workActivityInstanceId : workActivityInstanceIds) {
            ActivityInstanceImpl workActivityInstance = workflowInstance
                    .findActivityInstance(workActivityInstanceId.toString());
            workQueue.add(workActivityInstance);
        }//w  w w .  ja v  a 2 s  .  co m
    }
    return workQueue;
}

From source file:com.heisenberg.mongo.MongoWorkflowInstanceStore.java

License:Apache License

private List<VariableInstanceImpl> readVariableInstances(BasicDBObject dbWorkflowInstance,
        ScopeInstanceImpl parent) {/*from   w  w w .  j  a v a 2 s . c  om*/
    List<BasicDBObject> dbVariableInstances = readList(dbWorkflowInstance, fields.variableInstances);
    if (dbVariableInstances != null) {
        for (BasicDBObject dbVariableInstance : dbVariableInstances) {
            VariableInstanceImpl variableInstance = new VariableInstanceImpl();
            variableInstance.processEngine = processEngine;
            variableInstance.processInstance = parent.workflowInstance;
            variableInstance.id = readId(dbVariableInstance, fields._id);
            variableInstance.variableDefinitionId = readString(dbVariableInstance, fields.variableId);
            WorkflowImpl workflow = parent.workflowInstance.workflow;
            if (workflow != null) {
                variableInstance.variableDefinition = workflow
                        .findVariable(variableInstance.variableDefinitionId);
                variableInstance.variableDefinitionId = variableInstance.variableDefinition.id;
                variableInstance.dataType = variableInstance.variableDefinition.dataType;
                variableInstance.value = variableInstance.dataType
                        .convertJsonToInternalValue(dbVariableInstance.get(fields.value));
            }
            parent.addVariableInstance(variableInstance);
        }
    }

    return null;
}

From source file:com.heisenberg.mongo.MongoWorkflowStore.java

License:Apache License

protected void readVariables(ScopeImpl scope, BasicDBObject dbScope) {
    List<BasicDBObject> dbVariables = readList(dbScope, fields.variables);
    if (dbVariables != null) {
        scope.variableDefinitions = new ArrayList<>();
        for (BasicDBObject dbVariable : dbVariables) {
            VariableImpl variable = new VariableImpl();
            variable.id = readString(dbVariable, fields._id);

            Map<String, Object> dataTypeJson = readObjectMap(dbVariable, fields.dataType);
            variable.dataType = jsonService.jsonMapToObject(dataTypeJson, DataType.class);

            Object dbInitialValue = dbVariable.get(fields.initialValue);
            variable.initialValue = variable.dataType.convertJsonToInternalValue(dbInitialValue);

            scope.variableDefinitions.add(variable);
        }//w  w  w.j a  v  a2  s  .c  o  m
    }
}