Example usage for com.mongodb BasicDBObject append

List of usage examples for com.mongodb BasicDBObject append

Introduction

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

Prototype

@Override
public BasicDBObject append(final String key, final Object val) 

Source Link

Document

Add a key/value pair to this object

Usage

From source file:com.sitewhere.mongodb.device.MongoDeviceAssignmentState.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /*from  w w w.j  a  v a2 s  .  c o m*/
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceAssignmentState source, BasicDBObject target) {
    if (source.getLastInteractionDate() != null) {
        target.append(PROP_LAST_INTERACTION_DATE, source.getLastInteractionDate());
    }

    if (source.getLastLocation() != null) {
        target.append(PROP_LAST_LOCATION, MongoDeviceLocation.toDBObject(source.getLastLocation(), true));
    }

    if (!source.getLatestMeasurements().isEmpty()) {
        List<BasicDBObject> measurements = new ArrayList<BasicDBObject>();
        for (IDeviceMeasurement sm : source.getLatestMeasurements()) {
            measurements.add(MongoDeviceMeasurement.toDBObject(sm, true));
        }
        target.append(PROP_LATEST_MEASUREMENTS, measurements);
    }

    if (!source.getLatestAlerts().isEmpty()) {
        List<BasicDBObject> alerts = new ArrayList<BasicDBObject>();
        for (IDeviceAlert sa : source.getLatestAlerts()) {
            alerts.add(MongoDeviceAlert.toDBObject(sa, true));
        }
        target.append(PROP_LATEST_ALERTS, alerts);
    }

    if (source.getLastReplyTo() != null) {
        target.append(PROP_LAST_REPLY_TO, source.getLastReplyTo());
    }
}

From source file:com.sitewhere.mongodb.device.MongoDeviceCommand.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * //from   www.j  ava 2s.c  om
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceCommand source, BasicDBObject target) {
    target.append(PROP_TOKEN, source.getToken());
    target.append(PROP_SPEC_TOKEN, source.getSpecificationToken());
    target.append(PROP_NAMESPACE, source.getNamespace());
    target.append(PROP_NAME, source.getName());
    target.append(PROP_DESCRIPTION, source.getDescription());

    // Create parameters list.
    List<DBObject> params = new ArrayList<DBObject>();
    for (ICommandParameter parameter : source.getParameters()) {
        BasicDBObject dbparam = new BasicDBObject();
        dbparam.append(PROP_PARAM_NAME, parameter.getName());
        dbparam.append(PROP_PARAM_TYPE, parameter.getType().name());
        dbparam.append(PROP_PARAM_REQUIRED, parameter.isRequired());
        params.add(dbparam);
    }
    target.append(PROP_PARAMETERS, params);

    MongoSiteWhereEntity.toDBObject(source, target);
    MongoMetadataProvider.toDBObject(source, target);
}

From source file:com.sitewhere.mongodb.device.MongoDeviceCommandInvocation.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /*from  w  w w  .j  a  v  a 2 s  . c  om*/
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceCommandInvocation source, BasicDBObject target) {
    MongoDeviceEvent.toDBObject(source, target, false);

    target.append(PROP_INITIATOR, source.getInitiator().name());
    target.append(PROP_INITIATOR_ID, source.getInitiatorId());
    target.append(PROP_TARGET, source.getTarget().name());
    target.append(PROP_TARGET_ID, source.getTargetId());
    target.append(PROP_COMMAND_TOKEN, source.getCommandToken());
    target.append(PROP_STATUS, source.getStatus().name());

    BasicDBObject params = new BasicDBObject();
    for (String key : source.getParameterValues().keySet()) {
        params.append(key, source.getParameterValues().get(key));
    }
    target.append(PROP_PARAMETER_VALUES, params);
}

From source file:com.sitewhere.mongodb.device.MongoDeviceCommandResponse.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /* w ww .  ja v a 2 s  .  c o  m*/
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceCommandResponse source, BasicDBObject target) {
    MongoDeviceEvent.toDBObject(source, target, false);

    target.append(PROP_ORIGINATING_EVENT_ID, source.getOriginatingEventId());
    target.append(PROP_RESPONSE_EVENT_ID, source.getResponseEventId());
    target.append(PROP_RESPONSE, source.getResponse());
}

From source file:com.sitewhere.mongodb.device.MongoDeviceElementMapping.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * //from ww w .  j av a 2s . co  m
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceElementMapping source, BasicDBObject target) {
    target.append(PROP_DEVICE_ELEMENT_SCHEMA_PATH, source.getDeviceElementSchemaPath());
    target.append(PROP_HARDWARE_ID, source.getHardwareId());
}

From source file:com.sitewhere.mongodb.device.MongoDeviceEvent.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /* w ww . j  a  va2 s .c  o m*/
 * @param source
 * @param target
 * @param isNested
 */
public static void toDBObject(IDeviceEvent source, BasicDBObject target, boolean isNested) {
    if (isNested) {
        target.append(PROP_NESTED_ID, source.getId());
    }
    target.append(PROP_EVENT_TYPE, source.getEventType().name());
    target.append(PROP_SITE_TOKEN, source.getSiteToken());
    target.append(PROP_DEVICE_ASSIGNMENT_TOKEN, source.getDeviceAssignmentToken());
    target.append(PROP_DEVICE_ASSIGNMENT_TYPE, source.getAssignmentType().name());
    target.append(PROP_ASSET_MODULE_ID, source.getAssetModuleId());
    target.append(PROP_ASSET_ID, source.getAssetId());
    target.append(PROP_EVENT_DATE, source.getEventDate());
    target.append(PROP_RECEIVED_DATE, source.getReceivedDate());

    MongoMetadataProvider.toDBObject(source, target);
}

From source file:com.sitewhere.mongodb.device.MongoDeviceEventManagement.java

License:Open Source License

@Override
public SearchResults<IDeviceLocation> listDeviceLocations(List<String> assignmentTokens,
        IDateRangeSearchCriteria criteria) throws SiteWhereException {
    DBCollection events = getMongoClient().getEventsCollection(getTenant());
    BasicDBObject query = new BasicDBObject();
    query.put(MongoDeviceEvent.PROP_DEVICE_ASSIGNMENT_TOKEN, new BasicDBObject("$in", assignmentTokens));
    query.append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.Location.name());
    MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria);
    BasicDBObject sort = new BasicDBObject(MongoDeviceEvent.PROP_EVENT_DATE, -1)
            .append(MongoDeviceEvent.PROP_RECEIVED_DATE, -1);
    return MongoPersistence.search(IDeviceLocation.class, events, query, sort, criteria);
}

From source file:com.sitewhere.mongodb.device.MongoDeviceGroup.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /*from   w ww  .  jav a  2  s  . c o m*/
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceGroup source, BasicDBObject target) {
    target.append(PROP_TOKEN, source.getToken());
    target.append(PROP_NAME, source.getName());
    target.append(PROP_DESCRIPTION, source.getDescription());
    target.append(PROP_ROLES, source.getRoles());
    MongoSiteWhereEntity.toDBObject(source, target);
    MongoMetadataProvider.toDBObject(source, target);
}

From source file:com.sitewhere.mongodb.device.MongoDeviceGroupElement.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /*from www  .  jav  a2  s  .  c  o m*/
 * @param source
 * @param target
 */
public static void toDBObject(IDeviceGroupElement source, BasicDBObject target) {
    target.append(PROP_GROUP_TOKEN, source.getGroupToken());
    target.append(PROP_INDEX, source.getIndex());
    target.append(PROP_TYPE, source.getType().name());
    target.append(PROP_ELEMENT_ID, source.getElementId());
    target.append(PROP_ROLES, source.getRoles());
}

From source file:com.sitewhere.mongodb.device.MongoDeviceLocation.java

License:Open Source License

/**
 * Copy information from SPI into Mongo DBObject.
 * /*from   ww  w  .  j av a 2s . co  m*/
 * @param source
 * @param target
 * @param isNested
 */
public static void toDBObject(IDeviceLocation source, BasicDBObject target, boolean isNested) {
    MongoDeviceEvent.toDBObject(source, target, isNested);

    BasicDBObject locFields = new BasicDBObject();
    locFields.append(PROP_LONGITUDE, source.getLongitude());
    locFields.append(PROP_LATITUDE, source.getLatitude());
    target.append(PROP_LATLONG, locFields);
    if (source.getElevation() != null) {
        target.append(PROP_ELEVATION, source.getElevation());
    }
}