The 3D Web Coder

FireRatingCloud Query Retrieving Updated Docs

Yesterday, I added a timestamp to my FireRatingCloud mongodb documents with the intention of retrieving only documents modified after a specific moment.

Today, let's look at filtering for and retrieving just those.

Here are the steps to achieve that:

Modern JavaScript Bundling Tools

Before getting to that, here is a quick pointer to a thorough and interesting article on consolidating modern JavaScript tooling from Philippe Leefsma, who says:

Here is a worthy read to help understanding JavaScript modules, bundling and transpiling.

The gist of the article is providing an overview of and a solution for the current complex situation:

Personally, I don’t care for building asset pipelines any longer, what I’m looking for is minimal config tools that allow me to use modern tooling as needed: Things like Sass, Autoprefixer, Babel and Coffeescript, a proper module system and loader without having to worry about the implementation, configuration and ongoing maintenance. In essence, every developer has been investing time into creating asset pipelines over the last few years, that’s a lot of wheel re-invention going on and a lot of wasted hours.

It wraps up saying:

If you just want to use modules, then Browserify, jspm or Webpack with the default options will do the job.

Keep the tooling simple and the configuration light. Happy Bundling.

A MongoDB Query and Express Route Using $gt

I can very easily retrieve all documents from a mongo db for a specific BIM project with a modified timestamp greater than the one specified in the REST API query like this:

  findAllForProjectModifiedAfter : function(req, res){
    var pid = req.params.pid;
    var mod = req.params.mod;
    Door.find({'project_id':pid, modified:{$gt:mod}},
      function(err, results) {
        return res.send(results);
      }
    );
  }

I added that new method to controller/doors_v1.js.

Here is the new REST API route definition to populate the mod parameter and access this method in routes.js:

  app.get( '/api/v1/doors/project/:pid/newer/:mod',
    DoorService.findAllForProjectModifiedAfter );

C# REST API client accessing the new route

The interesting part will be to implement the C# client to use the new access point in an intelligent manner.

Just making the individual call is no problem, but implementing a continuous real-time BIM update will require more than that, e.g., an external event.

That in turn will require some rethinking and re-architecturing of the Revit external application to manage the external event subscription and handling.

Just for testing purposes, however, I can simply add the timestamp and the new REST API route to the existing retrieval of all records for the current project like this, using the static Boolean variable _test_newer to turn on the test code when needed:

  // Determine custom project identifier.
 
  string project_id = Util.GetProjectIdentifier( doc );
 
  // Get all doors referencing this project.
 
  string query = "doors/project/" + project_id;
 
  if( _test_newer )
  {
    // Add timestamp to query.
 
    int timestamp = Util.UnixTimestamp();
 
    timestamp -= 30; // go back half a minute
 
    Debug.Print(
      "Retrieving door documents modified after {0}",
      timestamp );
 
    query += "/newer/" + timestamp.ToString();
  }
 
  List<FireRating.DoorData> doors = Util.Get( query );
 
  if( null != doors && 0 < doors.Count )
  {
    // Process the door documents and update the BIM...

I leave _test_newer turned off by default; I can turn it on at will in the debugger:

  /// <summary>
  /// Test retrieving only recently modified records.
  /// </summary>
  static bool _test_newer = false;

Download and Diff

The current versions of FireRatingCloud and fireratingdb discussed above are release 2016.0.0.25 and release 0.0.21, respectively.

You can examine the changes required to implement the findAllForProjectModifiedAfter and the REST API route project/:pid/newer/:mod by comparing the last two fireratingdb releases, and analogously for the C# test code.