vicinityManager/server/services/items/registration.js
/*
Inserts or updates all oids in the request, depending on their previous existance
*/
Inserts or updates all oids in the request, depending on their previous existance
Inserts or updates all oids in the request depending on their previous existance
function saveDocuments(objects, otherParams, callback){
  var obj = {};
  var pwd = crypto.randomBytes(32).toString('base64'); 
  var infra_id = objects["infrastructure-id"];
  delete objects["infrastructure-id"]; 
  obj.typeOfItem = findType(objects.type, otherParams.types); 
  if(obj.typeOfItem === "unknown") {
    callback({oid: "NONE", password: "NONE", "infrastructure-id": "NONE"}, "Unknown type...");
  } else {
    obj.adid = {'id': otherParams.nodeId, 'extid': otherParams.adid};
    obj.name = objects.name; 
    obj.cid = otherParams.cid; 
    obj.accessLevel = 0; 
    obj.avatar = config.avatarItem; 
    obj.infrastructureId = infra_id; 
    obj.status = 'disabled';
    if(!objects.credentials && !objects.oid){ 
      oidExist(uuid()) 
      .then(function(response){
        obj.oid = response;
        objects.oid = response;
        return semanticRepo.callSemanticRepo(objects, "td/create", "POST"); }) 
      .then(function(response){
        var repoAnswer = JSON.parse(response);
        if(!(repoAnswer.data.hasOwnProperty('errors'))) {
          obj.info = JSON.parse(response).data.lifting; 
          createInstance(new itemOp(obj), pwd, infra_id, callback);
        } else { 
          callback({oid: obj.oid, password: "NONE", "infrastructure-id": "NONE"}, repoAnswer.data.errors);
        }
      })
      .catch(function(err){callback({oid: obj.oid, password: "NONE", "infrastructure-id": "NONE"}, err); });
    } else { 
      callback({oid: "NONE", password: "NONE", "infrastructure-id": "NONE"}, "Update service disabled, you cannot register TDs with OID");
    }
  }
}
function saveDocuments ( objects , otherParams , callback ) { var obj = { } ; var pwd = crypto . randomBytes ( 32 ) . toString ( 'base64' ) ; var infra_id = objects [ "infrastructure-id" ] ; delete objects [ "infrastructure-id" ] ; obj . typeOfItem = findType ( objects . type , otherParams . types ) ; if ( obj . typeOfItem === "unknown" ) { callback ( { oid : "NONE" , password : "NONE" , "infrastructure-id" : "NONE" } , "Unknown type..." ) ; } else { obj . adid = { 'id' : otherParams . nodeId , 'extid' : otherParams . adid } ; obj . name = objects . name ; obj . cid = otherParams . cid ; obj . accessLevel = 0 ; obj . avatar = config . avatarItem ; obj . infrastructureId = infra_id ; obj . status = 'disabled' ; if ( ! objects . credentials && ! objects . oid ) { oidExist ( uuid ( ) ) . then ( function ( response ) { obj . oid = response ; objects . oid = response ; return semanticRepo . callSemanticRepo ( objects , "td/create" , "POST" ) ; } ) . then ( function ( response ) { var repoAnswer = JSON . parse ( response ) ; if ( ! ( repoAnswer . data . hasOwnProperty ( 'errors' ) ) ) { obj . info = JSON . parse ( response ) . data . lifting ; createInstance ( new itemOp ( obj ) , pwd , infra_id , callback ) ; } else { callback ( { oid : obj . oid , password : "NONE" , "infrastructure-id" : "NONE" } , repoAnswer . data . errors ) ; } } ) . catch ( function ( err ) { callback ( { oid : obj . oid , password : "NONE" , "infrastructure-id" : "NONE" } , err ) ; } ) ; } else { callback ( { oid : "NONE" , password : "NONE" , "infrastructure-id" : "NONE" } , "Update service disabled, you cannot register TDs with OID" ) ; } } }
Inserts or updates all oids in the request, depending on their previous existance
Inserts or updates all oids in the request depending on their previous existance
// password for comm server credentials // remove infrastructure-id, no need to pass it further // Create one item document // Use collection of semanticTypes to find if service/device/unknown // Adding important fields for Vicinity // Name in commServer // CID, obtained from mongo // private by default // Default avatar provided by VCNT // Need to map with agent // Create a new instance in Mongo // Username in commServer & semanticRepo // Register TD in semantic repository //logger.debug(repoAnswer); // Thing description obj, stores response from semanticRepo // If lifting ends with error ... // if the TD contains an OID, then we need to update the instance in Mongo (not create a new one)