コード例 #1
0
ファイル: Elezioni.js プロジェクト: paulodiff/formapp
        return new Promise(function (resolve, reject) {

            var ws = require('ws.js');
            var fs = require('fs');
            var sec = ws.Security;
            var X509BinarySecurityToken = ws.X509BinarySecurityToken;
            var FileKeyInfo = require('xml-crypto').FileKeyInfo;
            var x509 = new X509BinarySecurityToken({ "key": fs.readFileSync(keyFile).toString() });
            var signature = new ws.Signature(x509);
            signature.addReference("//*[local-name(.)='Body']");
            signature.addReference("//*[local-name(.)='Timestamp']");
            signature.addReference("//*[local-name(.)='BinarySecurityToken']");

            var sec = new ws.Security({}, [x509, signature]);
            var handlers = [sec, new ws.Http()];
            var ctx = {
                request: request,
                url: endpoint,
                action: operationId,
                contentType: "text/xml"
            };

            ws.send(handlers, ctx, function (ctx) {
                logConsole.info("SENDSOAP: status " + ctx.statusCode);

                if (ctx.statusCode != 200) {
                    logConsole.error(ctx);
                }

                // console.log("messagse " + ctx.response);
                // console.log(ctx.request);
                // return ctx;
                resolve(ctx);
            });

        });
コード例 #2
0
ファイル: services.js プロジェクト: oletsaca/incoming
loadResource_setWorkzones = function (req, res, ctx, resources) {
	// set user object
	var user = {
		now: req.body.browserMenu.userConfigurations.now,

		login: req.body.browserMenu.userConfigurations.login,

		company: req.body.browserMenu.userConfigurations.company,

		auth_string: req.body.browserMenu.userConfigurations.authString
	};

  	// empty the web service context objects
	context = [];
	
	// set customer event listener for issuing a response
	var eventEmitter = new events.EventEmitter();

	eventEmitter.on('end', loadResource_end);


	// for each of the named resources 
	for (i in resources) {
		// set the request object
		request = {
			user: user,

			zones: {zone: []}
		};

		for (j in resources[i].zone) {
			request.zones.zone.push({
				properties: [{property:[
					{name:'resource_id', value: resources[i].name}, 

					{name:'zone', value: j}, 
					
					{name:'ratio', value: 100}, 
					
					{name:'duration', value: 365}, 
					
					{name:'date', value:req.body.browserMenu.dataConfigurations.date}
			]}]});
		};
		
		// set the soap envelope
  		envelope =	
			'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:ResourceManagement:1.0">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:set_resources_zones", request) +
			'</soapenv:Body>' +
			'</soapenv:Envelope>';

		// set the web service context object
		context.push({
			data: req.body,
		
			request: envelope, 
               	
   			url: req.body.browserMenu.userConfigurations.endpoint + "/soap/resource-management/",
               	
			action: "ResourceManagementService/set_resources_zones",
               	
      		contentType: "text/xml",
               
    		response: null
   		});
	}

   	// set the web service handlers
    var handlers =  [new Http()];

   	// send all the web service soap requests
	for (i in context) {
    	ws.send(handlers, context[i], function(context) {ctx.push(context); console.log(context)});
	};

	setTimeout(function(){eventEmitter.emit('end', req, res, ctx);}, 2000);
}
コード例 #3
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.request = function(req, res){

console.log(req.body.browserMenu.dataConfigurations.resources);

	// get resources
	var resources = {};
	
	for (i in req.body.browserMenu.dataConfigurations.resources) {
		if (resources[req.body.browserMenu.dataConfigurations.resources[i].name]) {
			// add next skill if not in the list
			resources[req.body.browserMenu.dataConfigurations.resources[i].name].skill[req.body.browserMenu.dataConfigurations.resources[i].skill] = 1;

			// add next zone if not in the list
			resources[req.body.browserMenu.dataConfigurations.resources[i].name].zone[req.body.browserMenu.dataConfigurations.resources[i].zone] = 1;

			// add next schedule if not in the list
			resources[req.body.browserMenu.dataConfigurations.resources[i].name].schedule[req.body.browserMenu.dataConfigurations.resources[i].schedule] = 1;

		} else {
			// create the object
			resources[req.body.browserMenu.dataConfigurations.resources[i].name] = {
				name: req.body.browserMenu.dataConfigurations.resources[i].name,

				skill: {}, 

				zone: {}, 

				schedule: {}, 

				type: req.body.browserMenu.dataConfigurations.resources[i].type, 

				timezone: req.body.browserMenu.dataConfigurations.resources[i].timezone, 

				language: req.body.browserMenu.dataConfigurations.resources[i].language, 

				status: req.body.browserMenu.dataConfigurations.resources[i].status, 

				resourcetype: req.body.browserMenu.dataConfigurations.resources[i].resourcetype
			};

			// add first skill found
			resources[req.body.browserMenu.dataConfigurations.resources[i].name].skill[req.body.browserMenu.dataConfigurations.resources[i].skill] = 1;

			// add first zone found
			resources[req.body.browserMenu.dataConfigurations.resources[i].name].zone[req.body.browserMenu.dataConfigurations.resources[i].zone] = 1;

			// add first schedule found
			resources[req.body.browserMenu.dataConfigurations.resources[i].name].schedule[req.body.browserMenu.dataConfigurations.resources[i].schedule] = 1;
		};
	};

	// set user object
	var user = {
		now: req.body.browserMenu.userConfigurations.now,

		login: req.body.browserMenu.userConfigurations.login,

		company: req.body.browserMenu.userConfigurations.company,

		auth_string: req.body.browserMenu.userConfigurations.authString
	};

	// set the web service context object
	var context = [];

	// set customer event listener for issuing a response
	var eventEmitter = new events.EventEmitter();

	eventEmitter.on('setSkills', loadResource_setSkills);

	eventEmitter.on('end', loadResource_end);


	// for each of the named resources 
	for (i in resources) {

		// set insert resource request object
		var request = {
			user: user,

			properties: {
				property: []
			}
		};

		// get a random resource id
		request.id = "r." + Math.floor(Math.random() * 1000000);

		// add a new resource name
		request.properties.property.push(
			{name: 'parent_id', value: req.body.browserMenu.dataConfigurations.externalid},

			{name: 'name', value: resources[i].name},
			
			{name: 'type', value: resources[i].type},
			
			{name: 'time_zone', value: resources[i].timezone},
			
			{name: 'language', value: resources[i].language},
			
			{name: 'status', value: resources[i].status},
			
			{name: 'Resource Type', value: resources[i].resourcetype}
		);

		// set soap envelope
		var envelope =
			'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:ResourceManagement:1.0">' +
				'<soapenv:Header/>' +
				'<soapenv:Body>' + 
					json2xml.toXml("urn:update_resource", request) +
				'</soapenv:Body>' +
			'</soapenv:Envelope>';

		// set the web service context object
		context.push({
			data: req.body,
		
			request: envelope, 
               	
			url: req.body.browserMenu.userConfigurations.endpoint + "/soap/resource-management/",
               	
			action: "ResourceManagementService/update_resource",
               	
      		contentType: "text/xml",
               
    		response: null
   		});

		// change the name by the resource id for later use
		resources[i].name = request.id;
	};

   	// set the web service handlers
    var handlers =  [new Http()];

   	// send all web service soap requests
	for (i in context) {
		// call web service
    	ws.send(handlers, context[i], function(ctx) {context.push(ctx); console.log(context)});
	};

	setTimeout(function(){eventEmitter.emit('setSkills', req, res, context, resources);}, 2000);
};
コード例 #4
0
ファイル: clientDummy_ws.js プロジェクト: reyesdiego/AGP
//					</LineasMercaderia>
//					<Contenedores>
//						<IZPContenedor xsi:nil="true" />
//						<IZPContenedor xsi:nil="true" />
//					</Contenedores>
//				</Carga>
//			</argwdepIngresos>
//		</WdepIngresos>
//	</soap:Body>
//	</soap:Envelope>"

var etree = et.parse(request);

console.log("response: " + etree.find('.//Dummy'));


var ctx =  { request: request
	, url: "https://testdia.afip.gov.ar/dia/ws/wdepMovimientos/wdepMovimientos.asmx"
	, action: "ar.gov.afip.dia.serviciosweb.wdepMovimientos.wdepMovimientos/Dummy"
	, contentType: "text/xml"
}


var handlers =  [ new ws.Addr("https://testdia.afip.gov.ar")
	, new ws.Http()
]

ws.send(handlers, ctx, function(ctx) {
	console.log("response: " + ctx.response);
})
コード例 #5
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.update = function(req, res){
	// responses
	req.body.response = [];

	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set insert resource request object
	var request = {
		user: user,

		activity_id: req.body.id,

		position_in_route: 'unchanged',

		properties:[]
	};

	// set properties
	if (req.body.phone)	request.properties.push({name: 'phone', value: req.body.phone});

	if (req.body.cell)	request.properties.push({name: 'cell', value: req.body.cell});

	if (req.body.email)	request.properties.push({name: 'email', value: req.body.email});

	if (req.body.reminder_time)	request.properties.push({name: 'reminder_time', value: req.body.reminder_time});

	if (req.body.PAS1) request.properties.push({name: 'PAS1', value: req.body.PAS1});

	if (req.body.PAS2) request.properties.push({name: 'PAS2', value: req.body.PAS2});

	if (req.body.PAS3a) request.properties.push({name: 'PAS3a', value: req.body.PAS3a});

	if (req.body.PAS3b) request.properties.push({name: 'PAS3b', value: req.body.PAS3b});

	if (req.body.PAS4) request.properties.push({name: 'PAS4', value: req.body.PAS4});

	if (req.body.PAS5) request.properties.push({name: 'PAS5', value: req.body.PAS5});

	if (req.body.PAS6) request.properties.push({name: 'PAS6', value: req.body.PAS6});

	// set customer event listener for issuing a response
	var eventEmitter = new events.EventEmitter();

	eventEmitter.on('end', end);

	// get resource id 
	var envelope =
		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toa:activity">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:update_activity", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';

	// set the web service context object
	context = {
		data: req.body,
		
		request: envelope, 
               	
   		url: req.body.endpoint+'/soap/activity/',
               	
   		action: "activity/update_activity",
               	
       	contentType: "text/xml",
               
   	   	response: null
    };

   	// set the web service handlers
    var handlers =  [new Http()];

    // invoke web service and emit event when done
    ws.send(handlers, context, function(ctx) {
	    	req.body.response.push(ctx.response);

	    	eventEmitter.emit('end', req, res, ctx);
    });
};
コード例 #6
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.request = function(req, res){
	// responses
	req.body.response = [];

	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set insert resource request object
	var request = {
		user: user,

//		search_in: 'cphone',

		search_in: 'appt_number',

		search_for: req.body.wonumber,

		date_from: null, // req.body.now.substr(0, 8)+'01', // workaround the data sync issues

		date_to: null, //req.body.now.substr(0, 10),

		select_from: 1,

		select_count: 1, 

		property_filter: ['appt_number', 'id', 'resource_id', 'customer_number', 'name', 'address', 'city', 'zip', 'state', 'coordx', 'coordy', 'phone', 'email', 'cell', 'worktype', 'WO_TYPE', 'date', 'time_slot', 'service_window_start', 'service_window_end', 'delivery_window_start', 'delivery_window_end', 'sla_window_start', 'sla_window_end', 'duration', 'status', 'reminder_time',  ] 
	};

	// set customer event listener for issuing a response
	var eventEmitter = new events.EventEmitter();

	eventEmitter.on('getresource', getResource);

	eventEmitter.on('end', end);

	// get resource id 
	var envelope =
		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toa:activity">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:search_activities", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';

	// set the web service context object
	context = {
		data: req.body,
		
		request: envelope, 
               	
   		url: req.body.endpoint+'/soap/activity/',
               	
   		action: "activity/search_activities",
               	
       	contentType: "text/xml",
               
   	   	response: null
    };

   	// set the web service handlers
    var handlers =  [new Http()];

	console.log(context);
    // invoke web service and emit event when done
    ws.send(handlers, context, function(ctx) {
    	console.log(ctx);

    	// if no response
		if (!ctx.response) {
	    	eventEmitter.emit('end', req, res, ctx);

		} else { // if response

	    	req.body.response.push(ctx.response);

    		ctx.data.resource_id = 0;

    		// find the resource id, 0 otherwise
			var parseString = require('xml2js').parseString;

			// parse the response
			parseString(ctx.response, function (err, result) {
				// if good endpoint
				if (result) {
					// if no  soap fault
					if (!result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['SOAP-ENV:Fault']) {

						// if result ok
						if (result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['ns1:search_activities_response'][0].result_code[0] == 0) { 

							// if activities found
							if (result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['ns1:search_activities_response'][0].activity_list[0].total[0] > 0){
								props = result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['ns1:search_activities_response'][0].activity_list[0].activities[0].activity[0].properties;
							
								// get resource id
								for (i = 0; i < props.length; i++) {
				   					if (props[i].name[0] == 'resource_id') {
			   			 				ctx.data.resource_id = props[i].value[0];
	   				 					break;
		   							}
		   						} 

	   							// get resource
				    			eventEmitter.emit('getresource', req, res, ctx);

		   					} else { // if activities not found
 			    				eventEmitter.emit('end', req, res, ctx);
		   					};
		   				} else { // if result not ok
 			    			eventEmitter.emit('end', req, res, ctx);
		   				}
					} else { // if soap fault
 				    	eventEmitter.emit('end', req, res, ctx);
					}
				} else { // if wrong endpoint (returns 301)
					 eventEmitter.emit('end', req, res, ctx);
				}
			});
		};
    });
};
コード例 #7
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.create = function(req, res){

	console.log(req.body);

	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set head object
	var head = {		
		processing_mode: "appointment_only",

		upload_type: "incremental",

		id: req.body.now,

		date: "",

		allow_change_date: "yes",

		appointment: {
			keys: { 
				field: ["appt_number", "customer_number"]
			}
		},

		inventory: {
			keys: {
				field: "invsn"
			}
		},

		properties_mode: "update",
	};

	// set data object
	var data = {		
		commands: null
	};

	// set request object
	var request = {		
		user: user,

		head: head, 

		data: data
	};

	// set command
	var command = [];

	command.push({
		date: (new Date(req.body.selectedstart)).toISOString().substr(0,10),

		type: "update_appointment",

		external_id: req.body.resource_id,

		appointment: {		
			// set appt number
			appt_number: req.body.appt_number,

			// set customer number
			customer_number: req.body.customer_number,

			// set worktype label
			worktype_label: req.body.worktype,

			// set time slot
			time_slot: req.body.selectedslot,

			// set customer name
			name: req.body.name,

			message_methods: 0,

			// set phone number
			phone: req.body.phone,

			// set email address
			email: req.body.email,

			// set cell number
			cell: req.body.cell,

			address: req.body.address,

			city: req.body.city,

			state: req.body.state,

			zip: req.body.zip,

			language: 1,

			reminder_time: 0,

			// set longitude coord
			coordx: req.body.coordx,

			// set latitude  coord
			coordy: req.body.coordy
		}
    });

    // set request commands
    request.data.commands = {command: command};

    // set soap envelope
    var envelope =	
    			'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:InboundInterface:1.0">' +

					'<soapenv:Header/>' +

					'<soapenv:Body>' + 

						json2xml.toXml("urn:inbound_interface_request", request) +

					'</soapenv:Body>' +

				'</soapenv:Envelope>';

	// set ws context
	var context = {
		request: envelope, 
               	
       	url: req.body.endpoint + "/soap/inbound/",
               	
      	action: "InboundInterfaceService/inbound_interface",
               	
        contentType: "text/xml",
               
        response: null
    };

    // set ws handlers
    var handlers =  [new Http()];

    // send request, get response
    console.log(context);

    ws.send(handlers, context, function(context) {
    	console.log(context);

		res.send(context.error?500:context.statusCode, context); 
	});
};
コード例 #8
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.cancel = function(req, res){
	// responses
	req.body.response = [];

	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set insert resource request object
	var request = {
		user: user,

		activity_id: req.body.id,

		properties:[{name: 'cancel_reason', value: 14}]
	};

	// set customer event listener for issuing a response
	var eventEmitter = new events.EventEmitter();

	eventEmitter.on('end', end);

	// get resource id 
	var envelope =
		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toa:activity">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:cancel_activity", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';

	// set the web service context object
	context = {
		data: req.body,
		
		request: envelope, 
               	
   		url: req.body.endpoint+'/soap/activity/',
               	
   		action: "activity/cancel_activity",
               	
       	contentType: "text/xml",
               
   	   	response: null
    };

   	// set the web service handlers
    var handlers =  [new Http()];

    // invoke web service and emit event when done
    ws.send(handlers, context, function(ctx) {
	    	req.body.response.push(ctx.response);

	    	eventEmitter.emit('end', req, res, ctx);
    });
};
コード例 #9
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.capacity = function(req, res){

	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set request object
	var request = {
		user: user,

		date: req.body.dates,

		location: req.body.location,

		calculate_duration: (req.body.calculateduration == 1),

		calculate_travel_time: (req.body.calculatetraveltime == 1),

		calculate_work_skill: (req.body.calculateworkskill == 1),

	};

	// set request time slot, if found
	if (req.body.timeslot !== undefined) request.time_slot = req.body.timeslot;

	// set request work skill, if found
	if (req.body.workskill !== undefined) request.work_skill = req.body.workskill;


/*
	// set activity fields, if found
	try {
		var activity_field = [];
				
		for (var l = 0; l < req.body.property.properties.propertieslist.length; l++) {
			
			activity_field.push({
				
				name: req.body.property.properties.propertieslist[l][0],
				
				value: req.body.property.properties.propertieslist[l][1]
				
			});				
		};

		if (activity_field.length) {
				
			request.activity_field = activity_field;
				
		};
	} catch (e) {
		// do nothing
	}
*/

	if (req.body.activity_field !== undefined) {
				
		request.activity_field = req.body.activity_field;
				
	};


   // set soap envelope
    var envelope =	
		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toa:capacity">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:get_capacity", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';

	// set ws context
	var context = {
		data: req.body,
		
		request: envelope, 
               	
       	url: req.body.endpoint + "/soap/capacity/",
               	
      	action: "toa_capacity_interface/get_capacity",
               	
        contentType: "text/xml",
               
        response: null
    };

    // set ws handlers
    var handlers =  [new Http()];

    // send request, get response
    console.log(context);

    ws.send(handlers, context, function(context) {
    	console.log(context);

		res.send(context.error?500:context.statusCode, context);
    });
};
コード例 #10
0
ファイル: services.js プロジェクト: oletsaca/incoming
getResource = function (req, res, context) {
	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set insert resource request object
	var request = {
		user: user,

		id: context.data.resource_id 
	};

	// set customer event listener for issuing a response
	var eventEmitter = new events.EventEmitter();

	eventEmitter.on('end', end);

	// get resource id 
	var envelope =
		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:ResourceManagement:1.0">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:get_resource", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';

	// set the web service context object
	context = {
		data: req.body,
		
		request: envelope, 
               	
   		url: req.body.endpoint+'/soap/resource-management/',
               	
   		action: "ResourceManagementService/get_resource",
               	
       	contentType: "text/xml",
               
   	   	response: null
    };

   	// set the web service handlers
    var handlers =  [new Http()];

    console.log(context);
    // invoke web service and emit event when done
    ws.send(handlers, context, function(ctx) {
    	console.log(ctx);

    	req.body.response.push(ctx.response);

    	eventEmitter.emit('end', req, res, ctx);
    });
}
コード例 #11
0
ファイル: services.js プロジェクト: oletsaca/incoming
createDOMActivities = function(req, res){
	// set user object
	var user = {

		now: req.body.browserMenu.userConfigurations.now,

		login: req.body.browserMenu.userConfigurations.login,

		company: req.body.browserMenu.userConfigurations.company,

		auth_string: req.body.browserMenu.userConfigurations.authString
	};

	// set head object
	var head = {
		
		processing_mode: "appointment_only",

		upload_type: "incremental",

		id: req.body.browserMenu.userConfigurations.now,

//		date: req.body.browserMenu.dataConfigurations.date+"-01",

		allow_change_date: "yes",

		appointment: {
		
			keys: { 
		
				field: req.body.browserMenu.headConfigurations.appointmentkeys.replace(/\s/g,"").split(",")
			}
		},

		inventory: {

			keys: {

				field: "invsn"

			}
		},

		properties_mode: "update",

		default_appointment_pool: req.body.browserMenu.headConfigurations.defaultappointmentpool
	};


	// set data object
	var data = {
		
		commands: null
	};


	// set request object
	var request = {
		
		user: user,

		head: head, 

		data: data
	};


	// get total requests weight
	var requests = 0;

    for (var i = req.body.homepage.chart.chart.series.length - 1; i >= 0; i--) {

    	for (var j = req.body.homepage.chart.chart.series[i].data.length - 1; j >= 0; j--) {

    		req.body.homepage.chart.chart.series[i].data[j][1] = Math.floor(req.body.homepage.chart.chart.series[i].data[j][1]);

	  		requests += req.body.homepage.chart.chart.series[i].data[j][1];

    	};

    };

    // set appointments numbers
    var appointments = 0;

    for (var i = req.body.homepage.chart.chart.series.length - 1; i >= 0; i--) {

    	for (var j = req.body.homepage.chart.chart.series[i].data.length - 1; j >= 0; j--) {

    		req.body.homepage.chart.chart.series[i].data[j][1] = Math.round(req.body.homepage.chart.chart.series[i].data[j][1] / requests * req.body.browserMenu.appointmentDetails.appointments);

	  		appointments += req.body.homepage.chart.chart.series[i].data[j][1];

    	};

    };


    // get top left coords
	var topleft = req.body.browserMenu.appointmentDetails.topleft.split(",");

	// get bottom right coords
	var bottomright = req.body.browserMenu.appointmentDetails.bottomright.split(",");
   
    // get top to bottom delta
    var toptobottom = Math.floor((topleft[0] - bottomright[0]) * 1000000);

    // get left to right delta
  	var righttoleft = Math.floor((bottomright[1] - topleft[1]) * 1000000);


    // set command objects
    var c = 0;

    var command = [];

	for (var i = 0; i < req.body.homepage.chart.chart.series.length; i++) {
		for (var j = 0; j < req.body.homepage.chart.chart.series[i].data.length; j++) {
			for (var k = 0; k < req.body.homepage.chart.chart.series[i].data[j][1]; k++) {

				// set random customer number
				var customer_number = Math.floor(Math.random() * 1000000);

				// set random latitude coords
				var latitude = Math.floor(Math.random() * toptobottom) / 1000000 + Number(bottomright[0]);

				// set random longitude coord
				var longitude = Math.floor(Math.random() * righttoleft) / 1000000 + Number(topleft[1]);

				// set command
    			command[c] = {
   					date: req.body.browserMenu.dataConfigurations.date+"-"+req.body.homepage.chart.chart.series[i].data[j][0].toString().lpad('0',2),

					type: "update_appointment",

					external_id: req.body.browserMenu.dataConfigurations.externalid,

					fallback_external_id: req.body.browserMenu.dataConfigurations.fallbackexternalid,

					appointment: {
		
						// set random appt number
						appt_number: Math.floor(Math.random() * 1000000), 

						// set random customer number
						customer_number: customer_number,

						// set worktype label
						worktype_label: req.body.browserMenu.appointmentDetails.worktypeslist[i],

//						sla_window_start: null,

//						sla_window_end: null,

//						duration: 60,

						// set random customer name
						name: "Customer." + customer_number,

						message_methods: 0,

						// set random phone number
						phone: "555760" + customer_number,

						// set random email address
						email: "555760." + customer_number + "@whatever.com",

						// set random cell number
						cell: "555760" + customer_number,

						address: null,

						city: null,

						state: null,

						zip: null,

						language: 1,

						reminder_time: 0,

						// set random longitude coord
						coordx: longitude,

						// set random latitude  coord
						coordy: latitude,

						//properties: null
    				}
		    	};

				// set all-day timeslot, if found
				if (req.body.browserMenu.appointmentDetails.alldaytimeslot != null && req.body.browserMenu.appointmentDetails.alldaytimeslot.length != 0)  {
					command[c].appointment.time_slot = req.body.browserMenu.appointmentDetails.alldaytimeslot
				};
				
				// set command properties, if found
				var property = [];
				
				for (var l = 0; l < req.body.property.properties.propertieslist.length; l++) {
								
					if (req.body.property.properties.propertieslist[l][0] == req.body.browserMenu.appointmentDetails.worktypeslist[i]) {
				
						if (req.body.property.properties.propertieslist[l][1] == 'length') {
							command[c].appointment.duration = req.body.property.properties.propertieslist[l][2];

						} else {
							property.push({
								label: req.body.property.properties.propertieslist[l][1],
				
								value: req.body.property.properties.propertieslist[l][2]
				
							});
						}				
					};			
				};

				if (property.length) {
				
					command[c].appointment.properties = {property: property};
				
				};


				// set names 
				if (req.body.browserMenu.dataConfigurations.names.length) { 
					command[c].appointment.name = names[0];

					names.shift();
				}


				// if reverse geocoding checked
				if (req.body.browserMenu.appointmentDetails.reversegeocoding) {

		    		// set default details
					var street_number = null,

						route = null,

						locality = null,

						administrative_area_level_1 = null,

						country = null,

						postal_code = null;

		    		// get reverse geocode 
					var xhr = new XMLHttpRequest;

					xhr.open("GET", "https://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=false", false);

					xhr.send();
					
					try {
						// get response json object
						var obj = eval("(" + xhr.responseText + ")");
						
						// iterate thru 1st results
						for (var l = obj.results[0].address_components.length - 1; l >= 0; l--) {
							switch (obj.results[0].address_components[l].types[0]) {	

								// set street number
								case "street_number":

									street_number = obj.results[0].address_components[l].short_name;

									break;

								// set route
								case "route":

									route = obj.results[0].address_components[l].short_name;

									break;

								// set locality
								case "locality":

									locality = obj.results[0].address_components[l].short_name;

									break;

								// set administrative area
								case "administrative_area_level_1":

									administrative_area_level_1 = obj.results[0].address_components[l].short_name;

									break;

								//set country
								case "country":

									country = obj.results[0].address_components[l].short_name;

									break;

								// set postal code
								case "postal_code":

									postal_code = obj.results[0].address_components[l].short_name;

									break;
							};
						};

						// set command address
						(street_number==null)?command[c].appointment.address = route: command[c].appointment.address = street_number+" "+route;

						// set command city
						command[c].appointment.city = locality;

						// set command state
						command[c].appointment.state = administrative_area_level_1;

						// set command zip
						command[c].appointment.zip = postal_code;
				
					} catch (e) {
						console.log("ERROR: " + e.message + "[Wrong XHR.responseText. Unknown reason. latlng="+latitude+","+longitude+" not reverse geocoded.]");
					}
				};

				c++;

			};

		};

	};


    // set request commands
    request.data.commands = {command: command};


    // set soap envelope
    var envelope =	
    			'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:InboundInterface:1.0">' +

					'<soapenv:Header/>' +

					'<soapenv:Body>' + 

						json2xml.toXml("urn:inbound_interface_request", request) +

					'</soapenv:Body>' +

				'</soapenv:Envelope>';


	// set ws context
	var context = {

		request: envelope, 
               	
       	url: req.body.browserMenu.userConfigurations.endpoint + "/soap/inbound/",
               	
      	action: "InboundInterfaceService/inbound_interface",
               	
        contentType: "text/xml",
               
        response: null

    };


    // set ws handlers
    var handlers =  [new Http()];


    // send request, get response
    console.log(context);

    ws.send(handlers, context, function(context) {
    	console.log(context);

		res.send(context.error?500:context.statusCode, context);
    });
};
コード例 #12
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.request = function(req, res){
	// set user object
	var user = {
		now: req.body.browserMenu.userConfigurations.now,

		login: req.body.browserMenu.userConfigurations.login,

		company: req.body.browserMenu.userConfigurations.company,

		auth_string: req.body.browserMenu.userConfigurations.authString
	};

	// set request object
	var request = {
		user: user,

		resources: [{
			resource:{
				resource_id: req.body.browserMenu.dataConfigurations.externalid, 
				include_children: 'all' //req.body.browserMenu.dataConfigurations.children
			}
		}],

		date_range: {
			date_from: req.body.homepage.dates[0], 
			date_to: req.body.homepage.dates[1], 
			include_unscheduled: 'false' //req.body.browserMenu.dataConfigurations.unscheduled
		},

		select_from: 1, //req.body.browserMenu.dataConfigurations.from
		
		select_count: 500, //req.body.browserMenu.dataConfigurations.count

		filter_expression: {
			field: 'projectid', //req.body.browserMenu.dataConfigurations.field
			operator: 'equals', //req.body.browserMenu.dataConfigurations.operator
			value: req.body.browserMenu.dataConfigurations.projectid
		},

		required_properties: {label:[]},
	};


	// default
	if (req.body.property.properties.propertieslist.indexOf("date") < 0) req.body.property.properties.propertieslist.push("date");

	if (req.body.property.properties.propertieslist.indexOf("appt_number") < 0) req.body.property.properties.propertieslist.push("appt_number");

	if (req.body.property.properties.propertieslist.indexOf("name") < 0) req.body.property.properties.propertieslist.push("name");

	if (req.body.property.properties.propertieslist.indexOf("address") < 0) req.body.property.properties.propertieslist.push("address");

	if (req.body.property.properties.propertieslist.indexOf("city") < 0) req.body.property.properties.propertieslist.push("city");

	if (req.body.property.properties.propertieslist.indexOf("zip") < 0) req.body.property.properties.propertieslist.push("zip");

	if (req.body.property.properties.propertieslist.indexOf("state") < 0) req.body.property.properties.propertieslist.push("state");

	if (req.body.property.properties.propertieslist.indexOf("coordx") < 0) req.body.property.properties.propertieslist.push("coordx");

	if (req.body.property.properties.propertieslist.indexOf("coordy") < 0) req.body.property.properties.propertieslist.push("coordy");

	if (req.body.property.properties.propertieslist.indexOf("workzone") < 0) req.body.property.properties.propertieslist.push("workzone");

	if (req.body.property.properties.propertieslist.indexOf("worktype") < 0) req.body.property.properties.propertieslist.push("worktype");

	if (req.body.property.properties.propertieslist.indexOf("service_window_start") < 0) req.body.property.properties.propertieslist.push("service_window_start");

	if (req.body.property.properties.propertieslist.indexOf("service_window_end") < 0) req.body.property.properties.propertieslist.push("service_window_end");

	if (req.body.property.properties.propertieslist.indexOf("delivery_window_start") < 0) req.body.property.properties.propertieslist.push("delivery_window_start");

	if (req.body.property.properties.propertieslist.indexOf("delivery_window_end") < 0) req.body.property.properties.propertieslist.push("delivery_window_end");

	if (req.body.property.properties.propertieslist.indexOf("start_time") < 0) req.body.property.properties.propertieslist.push("start_time");

	if (req.body.property.properties.propertieslist.indexOf("end_time") < 0) req.body.property.properties.propertieslist.push("end_time");

	if (req.body.property.properties.propertieslist.indexOf("duration") < 0) req.body.property.properties.propertieslist.push("duration");

	if (req.body.property.properties.propertieslist.indexOf("traveling_time") < 0) req.body.property.properties.propertieslist.push("traveling_time");

	if (req.body.property.properties.propertieslist.indexOf("status") < 0) req.body.property.properties.propertieslist.push("status");

	if (req.body.property.properties.propertieslist.indexOf("resource_id") < 0) req.body.property.properties.propertieslist.push("resource_id");

	if (req.body.property.properties.propertieslist.indexOf("unordered") < 0) req.body.property.properties.propertieslist.push("unordered");

	for (var i=0; i<req.body.property.properties.propertieslist.length; i++){
		request.required_properties.label.push(req.body.property.properties.propertieslist[i]);
	}


   	// set soap envelope
   	var envelope =	
		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toa:activity">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:get_activities", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';

	// set ws context
	var context = {
		data: req.body,
		
		request: envelope, 
               	
   	   	url: req.body.browserMenu.userConfigurations.endpoint + "/soap/activity/v2/",
               	
   		action: "activity/get_activities",
               	
        contentType: "text/xml",
               
   	    response: null
    };

   	// set ws handlers
    var handlers =  [new Http()];

    // send request, get response
   	console.log(context);

    ws.send(handlers, context, function(context) {
    	console.log(context);
    	
		res.send(context.error?500:context.statusCode, context);
    });
};
コード例 #13
0
ファイル: services.js プロジェクト: oletsaca/incoming
exports.request = function(req, res){
	// responses
	var responses = [];

	// set user object
	var user = {
		now: req.body.now,

		login: req.body.login,

		company: req.body.company,

		auth_string: req.body.authString
	};

	// set head object
	var head = {
		upload_type: "incremental",

		appointment: {		
			keys: { 
				field: ["appt_number", "customer_number"],
			}
		},

		inventory: {
			keys: {
				field: ["invtype_label", "invsn"]
			},

            upload_type: "incremental"
		},

		properties_mode: "update"
	};

	// set data object
	var data = {
		commands: {command:[]}
	};

	// set request object
	var request = {
		user: user,

		head: head,

		data: data
	};


	// foreach resource
	for (i in req.body.resources) {
		// set inventories
		var inventories = {inventory:[]};

		for (j in req.body.inventory) {
			// add inventories
			var inventory = {
				properties: {property: [
					{
						label: "invtype_label", value: req.body.inventory[j].type
					},
					{
						label: "inventory_model", value: req.body.inventory[j].model
					},
					{
						label: "quantity", value: req.body.inventory[j].quantity
					},
					{
						label: "invsn", value: Math.floor(Math.random() * 1000000000) //req.body.inventory[j].serialnumber
					},
				]}
			}

			inventories.inventory.push(inventory);
		};


		// add commands
		var command = {
			type: req.body.command, //"update_inventory",
			external_id: req.body.resources[i],
			inventories: inventories
		}

		request.data.commands.command.push(command);

/*
                  <inventories>              
                        <inventory>
                           <properties>
                        		<property>
                                 <label>invsn</label>
                                 <value>3303501</value>
                              </property>
                        		<property>
                                 <label>invtype_label</label>
                                 <value>NT</value>
                              </property>
                           </properties>
                        </inventory>
                        <inventory>
                           <properties>
                        		<property>
                                 <label>inventory_model</label>
                                 <value>EC3303501</value>
                              </property>
                        		<property>
                                 <label>invtype_label</label>
                                 <value>EC</value>
                              </property>
                        		<property>
                                 <label>quantity</label>
                                 <value>20</value>
                              </property>
                           </properties>
                        </inventory>
                  </inventories>
               </command>
            </commands>
*/


	};

	// set soap envelope
    var envelope =	
   		'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:InboundInterface:1.0">' +
			'<soapenv:Header/>' +
			'<soapenv:Body>' + 
				json2xml.toXml("urn:inbound_interface_request", request) +
			'</soapenv:Body>' +
		'</soapenv:Envelope>';


	// set ws context
	var context = {
		request: envelope, 
               	
   		url: req.body.endpoint + "/soap/inbound/",
               	
  		action: "InboundInterfaceService/inbound_interface",
               	
      	contentType: "text/xml",
               
       	response: null
   	};

    // set ws handlers
	var handlers =  [new Http()];

	console.log(context);

	// send ws requests
    ws.send(handlers, context, function(context) {
    	console.log(context);

    	res.send(context.error?500:context.statusCode, context);

	});
};
コード例 #14
0
ファイル: signature.js プロジェクト: Frost/ws.js
  ])

//only required if you specified validateResponseSignature as true
sec.options.responseKeyInfoProvider = new FileKeyInfo("server_public.pem")

var handlers =  
  [ new ws.Addr("http://www.w3.org/2005/08/addressing")
  , sec
  , new ws.Http()
  ]

request = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" +
          "<Header />" +
            "<Body>" +
              "<GetData xmlns='http://tempuri.org/'>" +
                "<value>123</value>" +
              "</GetData>" +
            "</Body>" +
          "</Envelope>"

var ctx =   { request: request
  , url: "http://localhost:7171/Service/sign_body_timestamp_wsa"
  , action: "http://tempuri.org/IService/GetData"
  , contentType: "text/xml"
}

ws.send(handlers, ctx, function(ctx) {                    
  console.log("status " + ctx.statusCode)
  console.log("messagse " + ctx.response)
})