Prerequisite - RESTful Consumer Exercise 2

Prerequisites for Excercise 2

This exercise will simulate an ERP response to retrieve multiple production orders.  We will retrieve the production orders and save them as Work Order objects in the MES software.

  • This provider assumes you have the OEE and Production modules installed with an MES database. If that is not the case, investigate the Getting Set Up section of the Practical Tutorial.
  • This provider assumes you have OEE Materials assigned to Production Lines.  If that is not the case, investigate the OEE Practical Tutorial.
  • Exercise 2 will consume an example endpoint on your local server.  Ensure you have the following RESTful Provider on your system:

Navigate to Providers → RESTful Endpoints → Instructor Tools → getProductionOrders

  • If this exists, nothing further is needed. Skip to the next page.

  • If this does not exist, create a new structure with the endpoint to match:

  • Open the endpoint getProductionOrders and match the following settings:


  • Paste the following into the do_GET(request) script function:

do_GET body

Python
	
	req_path = request['path']
	req_query = request['query']
	req_headers = request['headers']
	req_metadata = request['remote']
	req_body = request['body']
	res_headers = {}
	
	eqPath =  str(request['query']['path'])
	line = eqPath.split('\')[3:][0]
	
	opsList =  system.mes.getAvailableOperations(eqPath, '', False, False)
	if opsList.size() == 0:
		res_code = 400
		res_content = {'error': "No Operations Configured on Line"}
		return {'code': res_code, 'headers': res_headers, 'content': res_content}
	
	matList = []
	for item in opsList:
		matList.append(item.getName().split('-')[0])
		
	import random
	
	firstStart = system.date.addHours(system.date.now(), 4)
	firstEnd = system.date.addHours(firstStart, 1)
	secondStart = system.date.addMinutes(firstEnd, 5)
	secondEnd = system.date.addHours(secondStart, 2)
	
	#generating wo numbers
	firstId = system.date.toMillis(system.date.now())
	secondId = firstId + 1
	
	res_content = {"Data": 
	  {  
	    "lines": [
	      {
	        "line": line,
	              "scheduled_items": [
	                {
	                  "duration": 2.1171843383,
	                  "end_dtm": firstEnd,
	                  "id": system.date.toMillis(firstStart),
	                  "item_type": "WORK_ORDER",
	                  "newDuration": 0.0,
	                  "overflow": False,
	                  "related_data": [{
	                    "ct_units": 0,
	                    "id": firstId,
	                    "item_code": random.choice(matList),
	                    "item_desc1": "Product Description",
	                    "item_desc2": "",
	                    "item_net_weight": 0.0,
	                    "item_size": random.random(),
	                    "order_qty": 1200.0,
	                    "remarks": "",
	                    "routing_code": "Y901C721F8",
	                    "site": "11",
	                    "status_code": "C",
	                    "type_code": "S"
	                  }],
	                  "sequence": 2,
	                  "start_dtm": firstStart
	                },
	                {
	                  "duration": 2.1171843383,
	                  "end_dtm": secondEnd,
	                  "id": system.date.toMillis(secondStart),
	                  "item_type": "WORK_ORDER",
	                  "newDuration": 0.0,
	                  "overflow": False,
	                  "related_data": [{
	                    "ct_units": 0,
	                    "id": secondId,
	                    "item_code": random.choice(matList),
	                    "item_desc1": "Great Product",
	                    "item_desc2": "",
	                    "item_net_weight": 0.0,
	                    "item_size": 0.0,
	                    "order_qty": 3600,
	                    "remarks": "",
	                    "routing_code": "Y901C721F8",
	                    "site": "11",
	                    "status_code": "C",
	                    "type_code": "S"
	                  }],
	                  "sequence": 2,
	                  "start_dtm": secondStart
	                }
	              ]
	       }
	    ]
	  }
	}
	
	res_code = 200
	
	return {'code': res_code, 'headers': res_headers, 'content': res_content}