rtpmt.models.Vibration.java Source code

Java tutorial

Introduction

Here is the source code for rtpmt.models.Vibration.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package rtpmt.models;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.WriteConcern;
import rtpmt.database.access.DBConstants;
import rtpmt.database.access.IDataStore;
import rtpmt.network.packet.NetworkMessage;

/**
 *
 * @author Kumar
 */
public class Vibration extends BaseInfo implements IDataStore {
    /**
     *
     * @param packageInformation
     */
    public Vibration(NetworkMessage.PackageInformation packageInformation) {
        super(packageInformation);
        populateVibrationObject(packageInformation);
    }

    private void populateVibrationObject(NetworkMessage.PackageInformation packageInformation) {
        if (packageInformation.getMessageType() == NetworkMessage.PackageInformation.MessageType.SENSOR_INFO) {
            if (packageInformation.getSensorsCount() > 0) {
                for (NetworkMessage.PackageInformation.Sensor sensor : packageInformation.getSensorsList()) {
                    char charAt = sensor.getSensorType().toString()
                            .charAt(sensor.getSensorType().toString().length() - 1);
                    this.put(DBConstants.VALUE + DBConstants.DOT + Character.toString(charAt).toLowerCase(),
                            sensor.getSensorValue());
                }
            }
        }
    }

    public Object get() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void save() {
        DBCollection packageColl = db.getCollection(DBConstants.VIBRATION_COLLECTION);

        BasicDBObject query = new BasicDBObject();
        query.put(DBConstants.SENSOR_ID, this.get(DBConstants.SENSOR_ID));
        query.put(DBConstants.TRUCK_ID, this.get(DBConstants.TRUCK_ID));
        query.put(DBConstants.PACKAGE_ID, this.get(DBConstants.PACKAGE_ID));
        query.put(DBConstants.TIMESTAMP, this.get(DBConstants.TIMESTAMP));
        BasicDBObject set = new BasicDBObject();
        set.put("$set", this);
        packageColl.update(query, set, true, false);
        //packageColl.insert(this, WriteConcern.ACKNOWLEDGED);
    }
}