updated headers for nica order request Added reactor type support to nica checklists. Refactored flow logic to just use NICA_CHECKLISTS table. added feature flag support gated Feature Flags menu item to supervisors removed debug added auto comment for intr maint flows on reactor log, intr maint flow id to react servs form, and cancel order on unsign reactor log added exceptions for lamp and tc services, added control to edit flow id on react servs form, added auto-reactor log comment, added cancel order on unsign event removed debug modified NicaOrdersServices to use env variables for group resource name added logic to filter out service flow ids for servics with is_intrusive set to false, modified security group for feature flag menu, added ability to clear intr main flow id to react serv form removed unused equates
814 lines
35 KiB
Plaintext
814 lines
35 KiB
Plaintext
Compile function Nica_Orders_Services(@Service, @Params)
|
|
/***********************************************************************************************************************
|
|
|
|
This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
|
|
permission from Infineon Technologies.
|
|
|
|
Name : Nica_Orders_Services
|
|
|
|
Description : Handler program for all module related services.
|
|
|
|
Notes : The generic parameters should contain all the necessary information to process the services. Often
|
|
this will be information like the data Record and Key ID.
|
|
|
|
Parameters :
|
|
Service [in] -- Name of the service being requested
|
|
Param1-10 [in/out] -- Additional request parameter holders
|
|
Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
|
|
|
|
History : (Date, Initials, Notes)
|
|
12/05/24 djs Original programmer.
|
|
|
|
***********************************************************************************************************************/
|
|
#pragma precomp SRP_PreCompiler
|
|
|
|
$Insert APP_INSERTS
|
|
$Insert SERVICE_SETUP
|
|
$Insert REACTOR_EQUATES
|
|
$Insert REACTOR_LOG_EQUATES
|
|
$Insert NICA_ORDERS_EQUATES
|
|
$Insert NICA_ORDERS_CHECKLISTS_EQUATES
|
|
$Insert RLIST_EQUATES
|
|
|
|
Declare function Environment_Services, Database_Services, Error_Services, Logging_Services, Nica_Orders_Services
|
|
Declare function Httpclient_Services, SRP_JSON, Reactor_Services, Reactor_Log_Services, SRP_Array
|
|
Declare subroutine Error_Services, Btree.Extract, Database_Services, Logging_Services, Nica_Orders_Services, Delay
|
|
Declare subroutine Httpclient_Services, SRP_JSON, Mona_Services, Service_Services, Extract_SI_Keys
|
|
|
|
Machine = Environment_Services('GetServer')
|
|
LogDate = Oconv(Date(), 'D4/')
|
|
LogTime = Oconv(Time(), 'MTS')
|
|
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
|
|
|
|
GoToService
|
|
|
|
Return Response or ""
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Service Parameter Options
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
Options BOOLEAN = True$, False$
|
|
Options ENTITY_TYPES = 'REACTOR','REACTOR_LOG'
|
|
Options ORDER_TYPES = 'INTRUSIVE_MAINT','CHANGEOVER','INITIATE_IDLE','IDLE','ASM_HTR_TUBE_CHANGE','ASM_HTR_ANNUAL_PM','ASM_HTR_SEMIANNUAL_PM','ASM_HTR_FIVE_AND_TEN_YEAR_PM','IQS_HGCV_ALARM'
|
|
Options ORDER_STATUSES = 'new','creating','not-started','in-progress','cancelled','done'
|
|
Options REACTOR_TYPES = 'ASM','ASM+','HTR','EPP'
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// SERVICES
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Service GetOrderIds(EntityType=ENTITY_TYPES, EntityID, OrderTypes=ORDER_TYPES, OrderStatus=ORDER_STATUSES, IsComplete=BOOLEAN)
|
|
|
|
OrderKeys = ''
|
|
ErrorMsg = ''
|
|
If ( (EntityType NE '') or (EntityID NE '') or (OrderTypes NE '') or (OrderStatus NE '') or (IsComplete NE '') ) then
|
|
Open 'DICT.NICA_ORDERS' to hDict then
|
|
Query = ''
|
|
Table = 'NICA_ORDERS'
|
|
Option = 'E'
|
|
Flag = ''
|
|
If EntityType NE '' then Query := 'ENTITY_TYPE' : @VM : EntityType : @FM
|
|
If EntityID NE '' then Query := 'ENTITY_ID' : @VM : EntityID : @FM
|
|
If OrderTypes NE '' then
|
|
Query := 'ORDER_TYPE'
|
|
For each OrderType in OrderTypes using @VM
|
|
Query := @VM : OrderType
|
|
Next OrderType
|
|
Query := @FM
|
|
end
|
|
If OrderStatus NE '' then Query := 'ORDER_STATUS' : @VM : OrderStatus : @FM
|
|
If IsComplete NE '' then
|
|
Query := 'IS_COMPLETE'
|
|
For each Val in IsComplete using @VM
|
|
Query := @VM : Val
|
|
Next Val
|
|
end
|
|
Btree.Extract(Query, Table, hDict, OrderKeys, Option, Flag)
|
|
If Flag NE 0 then
|
|
ErrorMsg = 'Error in ':Service:' service. Btree.Extract call failed.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Failed to open DICT.NICA_ORDERS.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. At least one search parameter must be provided.'
|
|
end
|
|
|
|
If ErrorMsg EQ '' then
|
|
Response = OrderKeys
|
|
end else
|
|
Error_Services('Add', ErrorMsg)
|
|
end
|
|
|
|
End Service
|
|
|
|
|
|
Service GetOrderUpdates()
|
|
|
|
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
|
Lock hSysLists, ServiceKeyID then
|
|
ActiveOrderIds = Nica_Orders_Services('GetActiveOrders')
|
|
For each OrderId in ActiveOrderIds using @VM
|
|
Nica_Orders_Services('GetOrderStatusUpdate', OrderId)
|
|
Next OrderId
|
|
Unlock hSysLists, ServiceKeyID else Null
|
|
Nica_Orders_Services('UpdateNicaFlags')
|
|
end
|
|
|
|
end service
|
|
|
|
|
|
Service UpdateNicaFlags()
|
|
|
|
ErrCode = ''
|
|
ReactNos = Reactor_Services('GetReactorNumbers')
|
|
Open 'REACTOR' to hReactor then
|
|
Open 'REACTOR_LOG' to hReactorLog then
|
|
For each ReactNo in ReactNos using @FM
|
|
ProveInActive = Reactor_Services('GetProveInActive', ReactNo)
|
|
HgCVChecklistActive = (Nica_Orders_Services('GetActiveOrders', 'REACTOR', ReactNo, 'IQS_HGCV_ALARM') NE '')
|
|
IntrMaintChecklistActive = (Nica_Orders_Services('GetActiveOrders', 'REACTOR', ReactNo, 'INTRUSIVE_MAINT') NE '')
|
|
Open 'REACTOR' to hReactor then
|
|
ReadV CacheProveInActive from hReactor, ReactNo, REACTOR_PROVE_IN_ACTIVE$ then
|
|
If CacheProveInActive NE ProveInActive then
|
|
Lock hReactor, ReactNo then
|
|
WriteV ProveInActive on hReactor, ReactNo, REACTOR_PROVE_IN_ACTIVE$ else Null
|
|
Unlock hReactor, ReactNo else Null
|
|
end
|
|
end
|
|
end
|
|
ReadV CacheHgCVChecklistActive from hReactor, ReactNo, REACTOR_HGCV_CHECKLIST_ACTIVE$ then
|
|
If CacheHgCVChecklistActive NE HgCVChecklistActive then
|
|
Lock hReactor, ReactNo then
|
|
WriteV HgCVChecklistActive on hReactor, ReactNo, REACTOR_HGCV_CHECKLIST_ACTIVE$ else Null
|
|
Unlock hReactor, ReactNo else Null
|
|
end
|
|
end
|
|
end
|
|
ReadV CacheIntrMaintChecklistActive from hReactor, ReactNo, REACTOR_INTRUSIVE_MAINT_CHECKLIST_ACTIVE$ then
|
|
If CacheIntrMaintChecklistActive NE IntrMaintChecklistActive then
|
|
Lock hReactor, ReactNo then
|
|
WriteV IntrMaintChecklistActive on hReactor, ReactNo, REACTOR_INTRUSIVE_MAINT_CHECKLIST_ACTIVE$ else Null
|
|
Unlock hReactor, ReactNo else Null
|
|
end
|
|
end
|
|
end
|
|
end
|
|
CurrModeKey = Xlate('REACTOR_CHILD_KEY_IDS_NG', ReactNo, 'REACT_MODE_KEY_IDS', 'X')
|
|
CurrModeKey = CurrModeKey[-1, 'B':@VM]
|
|
CurrRLKey = Xlate('REACT_MODE_NG', CurrModeKey, 'START_RL_ID', 'X')
|
|
RLChecklistActive = Reactor_Log_Services('GetRlChecklistActive', CurrRlKey)
|
|
Open 'REACTOR_LOG' to hReactorLog then
|
|
ReadV CacheRlChecklistActive from hReactorLog, CurrRlKey, REACTOR_LOG_CHECKLIST_ACTIVE$ then
|
|
If CacheRlChecklistActive NE RLChecklistActive then
|
|
Lock hReactorLog, CurrRlKey then
|
|
WriteV RlChecklistActive on hReactorLog, CurrRlKey, REACTOR_LOG_CHECKLIST_ACTIVE$ else Null
|
|
Unlock hReactorLog, CurrRlKey else Null
|
|
end
|
|
end
|
|
end
|
|
end
|
|
Next ReactNo
|
|
end
|
|
end
|
|
|
|
end service
|
|
|
|
|
|
Service GetActiveOrders(EntityType=ENTITY_TYPES, EntityId, OrderTypes=ORDER_TYPES)
|
|
|
|
Response = Nica_Orders_Services('GetOrderIds', EntityType, EntityID, OrderTypes, '#cancelled', False$:@VM:'')
|
|
|
|
end service
|
|
|
|
|
|
Service CreateNewOrder(EntityType=ENTITY_TYPES, EntityID, OrderType=ORDER_TYPES, OrderFlows)
|
|
|
|
ErrorMsg = ''
|
|
EntityTypes = 'REACTOR,REACTOR_LOG'
|
|
OrderTypes = 'INTRUSIVE_MAINT,CHANGEOVER,INITIATE_IDLE,IDLE,ASM_HTR_TUBE_CHANGE,ASM_HTR_ANNUAL_PM,'
|
|
OrderTypes := 'ASM_HTR_SEMIANNUAL_PM,ASM_HTR_FIVE_AND_TEN_YEAR_PM,IQS_HGCV_ALARM'
|
|
|
|
Machine = Environment_Services('GetServer')
|
|
Headers = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
|
|
ColumnWidths = 20 : @FM : 15 : @FM : 300
|
|
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\NicaOrders'
|
|
makeDirSuccess = Utility("MAKEDIR", LogPath)
|
|
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_CreateNicaOrder.csv'
|
|
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
|
|
|
|
Prod = Environment_Services('IsProd')
|
|
IgnoreCertErrors = Not(Prod)
|
|
|
|
If ( (EntityType NE '') and (EntityID NE '') and (OrderType NE '') ) then
|
|
|
|
Begin Case
|
|
Case Not(InList(EntityTypes, EntityType, ','))
|
|
ErrorMsg = 'Error in ':Service:' service. Unsupported entity type'
|
|
Case Not(InList(OrderTypes, OrderType, ','))
|
|
ErrorMsg = 'Error in ':Service:' service. Unsupported order type'
|
|
End Case
|
|
|
|
If ErrorMsg EQ '' then
|
|
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Attempting to create NICA order for entity ':EntityType:' ' :EntityID:' of type ':OrderType
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
|
|
CurrActiveOrders = Nica_Orders_Services('GetActiveOrders', EntityType, EntityID, OrderType)
|
|
OrderTypeAlreadyActive = (CurrActiveOrders NE '')
|
|
|
|
If ( (OrderTypeAlreadyActive EQ False$) or (OrderType EQ 'INTRUSIVE_MAINT') ) then
|
|
|
|
Begin Case
|
|
Case EntityType EQ 'REACTOR'
|
|
ReactNo = EntityID
|
|
|
|
Case EntityType EQ 'REACTOR_LOG'
|
|
ReactNo = Xlate(EntityType, EntityID, REACTOR_LOG_REACTOR$, 'X')
|
|
End Case
|
|
|
|
// Build request
|
|
Body = ''
|
|
NewSortedChecklistIds = ''
|
|
If OrderType NE 'INTRUSIVE_MAINT' then
|
|
// Original API endpoint just uses query params, no body.
|
|
NicaURL = Environment_Services("GetProveInApiUrl"):'/checklists?'
|
|
NicaURL := 'checklistType=':OrderType
|
|
NicaURL := '&reactorNumber=':ReactNo
|
|
end else
|
|
// New API endpoint uses JSON body instead of query params.
|
|
NicaURL = Environment_Services("GetProveInApiUrl"):'/order'
|
|
If OrderFlows NE '' then
|
|
ReactorType = Xlate('REACTOR', ReactNo, REACTOR_REACT_TYPE$, 'X')
|
|
NewChecklistIds = Nica_Orders_Services('GetFlowChecklistIds', OrderFlows, OrderType, ReactorType)
|
|
// Get incomplete checklists and add them to the new order
|
|
If CurrActiveOrders NE '' then
|
|
IncompleteChecklistIds = ''
|
|
Open 'DICT.NICA_ORDERS_CHECKLISTS' to hDict then
|
|
For each ActiveNicaOrdersId in CurrActiveOrders using @VM
|
|
IncompleteOrderChecklistIds = ''
|
|
Flag = ''
|
|
Query = 'NICA_ORDERS_ID':@VM:ActiveNicaOrdersId:@FM
|
|
Query := 'IS_COMPLETE':@VM:False$:@FM
|
|
Btree.Extract(Query, 'NICA_ORDERS_CHECKLISTS', hDict, IncompleteOrderChecklistIds, 'E', Flag)
|
|
If Flag EQ 0 then
|
|
IncompleteOrderChecklistIdsRot = SRP_Array('Rotate', IncompleteOrderChecklistIds, @VM, '*')
|
|
PrevChecklistIds = IncompleteOrderChecklistIdsRot<0, 2>
|
|
Swap '*' with @VM in PrevChecklistIds
|
|
IncompleteChecklistIds<0, -1> = PrevChecklistIds
|
|
end
|
|
Next ActiveNicaOrdersId
|
|
end
|
|
NewChecklistIds<0, -1> = IncompleteChecklistIds
|
|
end
|
|
|
|
NewChecklistIds = SRP_Array('Clean', NewChecklistIds, 'TrimAndMakeUnique', @VM)
|
|
NewChecklistPriorities = Xlate('NICA_CHECKLISTS', NewChecklistIds, 'PRIORITY', 'X')
|
|
ChecklistArray = NewChecklistIds:@FM:NewChecklistPriorities
|
|
ChecklistArray = SRP_Array('SortRows', ChecklistArray, 'AR2', 'ARRAY', @FM, @VM)
|
|
NewSortedChecklistIds = ChecklistArray<1>
|
|
JsonRequest = ''
|
|
objJson = ''
|
|
If SRP_JSON(objJson, 'New', 'Object') then
|
|
SRP_JSON(objJson, 'SetValue', 'orderType', OrderType)
|
|
SRP_JSON(objJson, 'SetValue', 'reactorNumber', ReactNo)
|
|
NewChecklistInstIds = Xlate('NICA_CHECKLISTS', NewSortedChecklistIds, 'NICA_BASE_INSTRUCTION_ID', 'X')
|
|
SRP_JSON(objJson, 'SetValueArray', 'baseInstructionIds', NewChecklistInstIds, @VM)
|
|
Body = SRP_JSON(objJson, 'Stringify', 'Styled')
|
|
Convert @FM to '' in Body
|
|
SRP_JSON(objJson, 'Release')
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Failed to initialize JSON object for request body.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null Orderflows variable passed in.'
|
|
end
|
|
end
|
|
|
|
// Send the request
|
|
IsSuccessful = False$
|
|
If ErrorMsg EQ '' then
|
|
|
|
Retries = 3
|
|
BackoffSeconds = 1
|
|
OrderId = ''
|
|
|
|
Loop
|
|
while (IsSuccessful EQ False$ and Retries GT 0)
|
|
WaitSeconds = (3 - retries) * BackoffSeconds
|
|
Delay(WaitSeconds)
|
|
|
|
Retries = Retries - 1
|
|
If Body NE '' then
|
|
Headers = 'Content-Type':@VM:'application/json':@FM:'Accept':@VM:'*/*'
|
|
end else
|
|
Headers = 'Accept':@VM:'*/*'
|
|
end
|
|
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'POST', NicaURL, Headers, Body, '', '', False$, False$, '', IgnoreCertErrors)
|
|
If HttpResponseJson NE '' then
|
|
ObjResponseJson = ''
|
|
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then
|
|
OrderId = SRP_JSON(ObjResponseJson, 'GetValue', 'id')
|
|
If OrderId NE '' then
|
|
Convert @Lower.Case to @Upper.Case in OrderId
|
|
NicaOrderRec = ''
|
|
NicaOrderRec<NICA_ORDERS.ORDER_TYPE$> = OrderType
|
|
NicaOrderRec<NICA_ORDERS.ORDER_STATUS$> = SRP_JSON(ObjResponseJson, 'GetValue', 'state')
|
|
NicaOrderRec<NICA_ORDERS.ENTITY_TYPE$> = EntityType
|
|
NicaOrderRec<NICA_ORDERS.ENTITY_ID$> = EntityID
|
|
NicaOrderRec<NICA_ORDERS.IS_COMPLETE$> = SRP_JSON(ObjResponseJson, 'GetValue', 'isComplete')
|
|
If NicaOrderRec<NICA_ORDERS.IS_COMPLETE$> EQ False$ then
|
|
NicaOrderRec<NICA_ORDERS.PROGRESS_PERCENTAGE$> = SRP_JSON(ObjResponseJson, 'GetValue', 'progressPercentage')
|
|
end else
|
|
NicaOrderRec<NICA_ORDERS.PROGRESS_PERCENTAGE$> = 100
|
|
end
|
|
|
|
LogNicaOrderRec = NicaOrderRec
|
|
Swap @FM with ',' in LogNicaOrderRec
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Nica order record to write: ':LogNicaOrderRec
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
|
|
Database_Services('WriteDataRow', 'NICA_ORDERS', OrderId, NicaOrderRec, True$, False$, False$)
|
|
If Error_Services('NoError') then
|
|
If ( (OrderType _EQC 'INITIATE_IDLE') and (EntityType _EQC 'REACTOR') ) then
|
|
Open 'REACTOR' to hReactor then
|
|
WriteV True$ to hReactor, ReactNo, REACTOR_IDLE_STARTUP_REQUIRED$ else
|
|
ErrorMsg = 'Error in ':Service:' service. Error setting IDLE_STARTUP_REQUIRED flag in REACTOR record.'
|
|
end
|
|
end
|
|
end
|
|
If OrderType _EQC 'INTRUSIVE_MAINT' then
|
|
// Create NICA_ORDERS_CHECKLISTS child records for each checklist
|
|
If NewSortedChecklistIds NE '' then
|
|
For each ChecklistId in NewSortedChecklistIds using @VM
|
|
Key = OrderId:'*':ChecklistId
|
|
NicaOrdersChecklistsRec = ''
|
|
NicaOrdersChecklistsRec<NICA_ORDERS_CHECKLISTS.IS_COMPLETE$> = False$
|
|
Database_Services('WriteDataRow', 'NICA_ORDERS_CHECKLISTS', Key, NicaOrdersChecklistsRec, True$, False$, True$)
|
|
If Error_Services('HasError') then ErrorMsg = Error_Services('GetMessage')
|
|
Until (ErrorMsg NE '')
|
|
Next ChecklistId
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. failed to create NICA_ORDERS_CHECKLIST records due to empty checklist array.'
|
|
end
|
|
end
|
|
If ErrorMsg EQ '' then
|
|
For each OrderId in CurrActiveOrders using @VM
|
|
Nica_Orders_Services('CancelOrder', Orderid)
|
|
Next OrderId
|
|
IsSuccessful = True$
|
|
Response = OrderId
|
|
end
|
|
end else
|
|
ErrorMsg = Error_Services('GetMessage')
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null OrderId returned from MesaProveInAPI.'
|
|
end
|
|
SRP_JSON(ObjResponseJson, 'Release')
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Error parsing JSON response from MesaProveInAPI.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null JSON response returned from MesaProveInAPI.'
|
|
end
|
|
Repeat
|
|
end
|
|
|
|
// Send MonA status
|
|
MonaResource = Environment_Services('GetEnvironmentVariable', 'MonaNicaIntegrationServiceGroup')
|
|
StatusName = 'CreateNicaOrder'
|
|
If IsSuccessful then
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Successfully created Nica order for entity ':EntityType:' ':EntityID:' of type ':OrderType
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'Ok')
|
|
end else
|
|
ErrorMsg = 'Error encountered when attempting to create Nica in order for reactor ':ReactNo:' of type ':OrderType
|
|
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'Critical')
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error encountered when attempting to create Nica order for entity ':EntityType:' ' :EntityID:' of type ':OrderType:'. Active order already exists.'
|
|
end
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null EntityType, EntityID, or OrderType passed in.'
|
|
end
|
|
|
|
If ErrorMsg NE '' then
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = ErrorMsg
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
Error_Services('Add', ErrorMsg)
|
|
Response = 'error'
|
|
end
|
|
|
|
end service
|
|
|
|
|
|
Service CancelOrder(OrderId)
|
|
|
|
ErrorMsg = ''
|
|
Machine = Environment_Services('GetServer')
|
|
Headers = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
|
|
ColumnWidths = 20 : @FM : 15 : @FM : 300
|
|
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\NicaOrders'
|
|
makeDirSuccess = Utility("MAKEDIR", LogPath)
|
|
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_CancelNicaOrder.csv'
|
|
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
|
|
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Attempting to cancel Nica order ' : OrderId :'.'
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
|
|
Prod = Environment_Services('IsProd')
|
|
IgnoreCertErrors = Not(Prod)
|
|
|
|
If OrderId NE '' then
|
|
LockRetries = 3
|
|
LockBackoffSeconds = 1
|
|
HaveLock = False$
|
|
Loop
|
|
While (HaveLock EQ False$ and LockRetries GT 0)
|
|
WaitSeconds = (3 - LockRetries) * LockBackoffSeconds
|
|
Delay(WaitSeconds)
|
|
LockRetries = LockRetries - 1
|
|
HaveLock = Database_Services('GetKeyIDLock', 'NICA_ORDERS', OrderId, True$)
|
|
Repeat
|
|
|
|
If HaveLock then
|
|
NicaOrderRec = Database_Services('ReadDataRow', 'NICA_ORDERS', OrderId)
|
|
If Error_Services('NoError') then
|
|
EntityType = NicaOrderRec<NICA_ORDERS.ENTITY_TYPE$>
|
|
EntityId = NicaOrderRec<NICA_ORDERS.ENTITY_ID$>
|
|
Begin Case
|
|
Case EntityType EQ 'REACTOR'
|
|
ReactNo = EntityId
|
|
|
|
Case EntityType EQ 'REACTOR_LOG'
|
|
ReactNo = Xlate(EntityType, EntityId, REACTOR_LOG_REACTOR$, 'X')
|
|
|
|
Case Otherwise$
|
|
ErrorMsg = 'Error in ':Service:' service. Unsupported entity type.'
|
|
End Case
|
|
|
|
If ErrorMsg EQ '' then
|
|
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Sending cancel request for Nica order ' : OrderId : ' for reactor ' : ReactNo
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
|
|
Response = False$
|
|
BaseProveInUrl = Environment_Services("GetProveInApiUrl"):'/checklists?'
|
|
UrlOrderId = OrderId
|
|
Convert @Upper.Case to @Lower.Case in UrlOrderId
|
|
ProveInUrl = BaseProveInUrl:'checklistOrderId=':UrlOrderId
|
|
ProveInUrl = ProveInUrl:'&checklistState=cancelled'
|
|
|
|
Retries = 3
|
|
BackoffSeconds = 1
|
|
IsSuccessful = False$
|
|
|
|
Loop
|
|
while (IsSuccessful EQ False$ and Retries GT 0)
|
|
WaitSeconds = (3 - Retries) * BackoffSeconds
|
|
Delay(WaitSeconds)
|
|
Retries = Retries - 1
|
|
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'PUT', ProveInUrl, 'Accept':@VM:'*/*', '', '', '', False$, False$, '', IgnoreCertErrors)
|
|
If HttpResponseJson NE '' then
|
|
ObjResponseJson = ''
|
|
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then
|
|
IsComplete = SRP_JSON(ObjResponseJson, 'GetValue', 'pendingUpdate')
|
|
NicaOrderRec<NICA_ORDERS.ORDER_STATUS$> = SRP_JSON(ObjResponseJson, 'GetValue', 'state')
|
|
NicaOrderRec<NICA_ORDERS.IS_COMPLETE$> = SRP_JSON(ObjResponseJson, 'GetValue', 'isComplete')
|
|
If IsComplete EQ False$ then
|
|
NicaOrderRec<NICA_ORDERS.PROGRESS_PERCENTAGE$> = SRP_JSON(ObjResponseJson, 'GetValue', 'progressPercentage')
|
|
end else
|
|
NicaOrderRec<NICA_ORDERS.PROGRESS_PERCENTAGE$> = 100
|
|
end
|
|
Database_Services('WriteDataRow', 'NICA_ORDERS', OrderId, NicaOrderRec, True$, False$, False$)
|
|
If Error_Services('NoError') then
|
|
OrderType = NicaOrderRec<NICA_ORDERS.ORDER_TYPE$>
|
|
If ( (OrderType _EQC 'IDLE') and (EntityType EQ 'REACTOR') ) then
|
|
Open 'REACTOR' to hReactor then
|
|
WriteV False$ on hReactor, ReactNo, REACTOR_IDLE_STARTUP_REQUIRED$ else
|
|
ErrorMsg = 'Error in ':Service:' service. Error setting IDLE_STARTUP_REQUIRED flag in REACTOR record.'
|
|
end
|
|
end
|
|
end
|
|
If ( (Response EQ True$) or (Response EQ False$) ) then IsSuccessful = True$
|
|
end else
|
|
ErrorMsg = Error_Services('GetMessage')
|
|
end
|
|
If IsComplete EQ True$ then
|
|
Response = True$
|
|
end else
|
|
Response = False$
|
|
end
|
|
end
|
|
end
|
|
SRP_JSON(ObjResponseJson, 'Release')
|
|
Repeat
|
|
|
|
MonaResource = Environment_Services('GetEnvironmentVariable', 'MonaNicaIntegrationServiceGroup')
|
|
StatusName = 'CancelNicaOrder'
|
|
If ( (IsSuccessful EQ True$) and (Response NE 'error') and (ErrorMsg EQ '') ) then
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Successfully cancelled Nica order ' : OrderId : ' for reactor ' : ReactNo
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'Ok')
|
|
end else
|
|
ErrorMsg = 'Error encountered cancelling Nica order ' : OrderId : ' for reactor ' : ReactNo
|
|
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'Critical')
|
|
end
|
|
end else
|
|
ErrorMsg = Error_Services('GetMessage')
|
|
Database_Services('ReleaseKeyIDLock', 'NICA_ORDERS', OrderId)
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Failed to lock NICA_ORDERS ':OrderId:' for cancellation.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null OrderID passed in.'
|
|
end
|
|
end else
|
|
ErrorMsg = Error_Services('GetMessage')
|
|
end
|
|
|
|
If ErrorMsg NE '' then
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = ErrorMsg
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
Error_Services('Add', ErrorMsg)
|
|
Response = 'error'
|
|
end
|
|
|
|
end service
|
|
|
|
|
|
Service GetOrderStatus(OrderId)
|
|
|
|
If OrderId NE '' then
|
|
If RowExists('NICA_ORDERS', OrderId) then
|
|
Response = Xlate('NICA_ORDERS', OrderId, 'ORDER_STATUS', 'X')
|
|
end else
|
|
Error_Services('Add', 'Error in ':Service:' service. Nica order ':OrderId:' does not exist.')
|
|
end
|
|
end else
|
|
Error_Services('Add', 'Error in ':Service:' service. Null OrderId passed in.')
|
|
end
|
|
|
|
end service
|
|
|
|
|
|
Service GetOrderStatusUpdate(OrderId)
|
|
|
|
ErrorMsg = ''
|
|
Headers = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
|
|
ColumnWidths = 20 : @FM : 15 : @FM : 300
|
|
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\NicaOrders'
|
|
makeDirSuccess = Utility("MAKEDIR", LogPath)
|
|
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_GetOrderStatusUpdate.csv'
|
|
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
|
|
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Attempting to update Nica order ' : OrderId :'.'
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
|
|
Prod = Environment_Services('IsProd')
|
|
IgnoreCertErrors = Not(Prod)
|
|
|
|
If OrderId NE '' then
|
|
HaveLock = Database_Services('GetKeyIDLock', 'NICA_ORDERS', OrderId, True$)
|
|
If HaveLock then
|
|
NicaOrderRec = Database_Services('ReadDataRow', 'NICA_ORDERS', OrderId)
|
|
If Error_Services('NoError') then
|
|
EntityType = NicaOrderRec<NICA_ORDERS.ENTITY_TYPE$>
|
|
EntityId = NicaOrderRec<NICA_ORDERS.ENTITY_ID$>
|
|
Begin Case
|
|
Case EntityType EQ 'REACTOR'
|
|
ReactNo = EntityId
|
|
|
|
Case EntityType EQ 'REACTOR_LOG'
|
|
ReactNo = Xlate(EntityType, EntityId, REACTOR_LOG_REACTOR$, 'X')
|
|
|
|
Case Otherwise$
|
|
ErrorMsg = 'Error in ':Service:' service. Unsupported entity type.'
|
|
End Case
|
|
|
|
If ErrorMsg EQ '' then
|
|
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Attempting to fetch Nica order ':OrderId:' for reactor ':ReactNo
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
|
|
Response = True$
|
|
IsSuccessful = True$
|
|
BaseProveInUrl = Environment_Services("GetProveInApiUrl"):'/checklists?'
|
|
UrlOrderId = OrderId
|
|
Convert @Upper.Case to @Lower.Case in UrlOrderId
|
|
ProveInUrl = BaseProveInUrl:'checklistOrderId=':UrlOrderId
|
|
|
|
Retries = 3
|
|
BackoffSeconds = 1
|
|
IsSuccessful = False$
|
|
|
|
Loop
|
|
while (IsSuccessful EQ False$ and Retries GT 0)
|
|
WaitSeconds = (3 - Retries) * BackoffSeconds
|
|
Delay(WaitSeconds)
|
|
Retries = Retries - 1
|
|
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'GET', ProveInUrl, 'Accept':@VM:'*/*', '', '', '', False$, False$, '', IgnoreCertErrors)
|
|
|
|
If HttpResponseJson NE '' then
|
|
ObjResponseJson = ''
|
|
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then
|
|
IsComplete = SRP_JSON(ObjResponseJson, 'GetValue', 'isComplete')
|
|
NicaOrderRec<NICA_ORDERS.ORDER_STATUS$> = SRP_JSON(ObjResponseJson, 'GetValue', 'state')
|
|
NicaOrderRec<NICA_ORDERS.IS_COMPLETE$> = IsComplete
|
|
If IsComplete EQ False$ then
|
|
NicaOrderRec<NICA_ORDERS.PROGRESS_PERCENTAGE$> = SRP_JSON(ObjResponseJson, 'GetValue', 'progressPercentage')
|
|
end else
|
|
NicaOrderRec<NICA_ORDERS.PROGRESS_PERCENTAGE$> = 100
|
|
end
|
|
Database_Services('WriteDataRow', 'NICA_ORDERS', OrderId, NicaOrderRec, True$, False$, False$)
|
|
If Error_Services('NoError') then
|
|
OrderType = NicaOrderRec<NICA_ORDERS.ORDER_TYPE$>
|
|
If (OrderType _EQC 'INTRUSIVE_MAINT') then
|
|
// Update NICA_ORDERS_CHECKLISTS records (documents)
|
|
Open 'NICA_ORDERS_CHECKLISTS' to hNicaOrdersChecklists then
|
|
// Parse documents array for their isComplete flag
|
|
ObjDocumentArray = SRP_JSON(ObjResponseJson, 'get', 'progresses')
|
|
If ObjDocumentArray NE 0 then
|
|
NumDocs = SRP_JSON(objDocumentArray, 'GetCount')
|
|
For DocIndex = 1 to NumDocs
|
|
DocumentId = SRP_JSON(ObjDocumentArray, 'GetValue', '[':DocIndex:'].baseInstructionId', '')
|
|
If DocumentId NE '' then
|
|
State = SRP_JSON(ObjDocumentArray, 'GetValue', '[':DocIndex:'].state', False$)
|
|
IsComplete = (State _EQC 'done')
|
|
ChecklistId = ''
|
|
Extract_SI_Keys('NICA_CHECKLISTS', 'NICA_BASE_INSTRUCTION_ID', DocumentId, ChecklistId)
|
|
ErrorCode = ''
|
|
If Not(Get_Status(ErrorCode)) then
|
|
If ChecklistId NE '' then
|
|
NicaOrdersChecklistsKey = OrderId:'*':ChecklistId
|
|
HaveOrderChecklistLock = Database_Services('GetKeyIDLock', 'NICA_ORDERS_CHECKLISTS', NicaOrdersChecklistsKey)
|
|
If HaveOrderChecklistLock then
|
|
NicaOrdersChecklistsRec = Database_Services('ReadDataRow', 'NICA_ORDERS_CHECKLISTS', NicaOrdersChecklistsKey)
|
|
If Error_Services('NoError') then
|
|
NicaOrdersChecklistsRec<NICA_ORDERS_CHECKLISTS.IS_COMPLETE$> = IsComplete
|
|
NicaOrdersChecklistsRec<NICA_ORDERS_CHECKLISTS.STATE$> = State
|
|
Database_Services('WriteDataRow', 'NICA_ORDERS_CHECKLISTS', NicaOrdersChecklistsKey, NicaOrdersChecklistsRec, True$, False$, False$)
|
|
If Error_Services('HasError') then
|
|
Database_Services('ReleaseKeyIDLock', 'NICA_ORDERS_CHECKLISTS', NicaOrdersChecklistsKey)
|
|
end
|
|
end
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. No NICA_CHECKLISTS record found for documentId ':DocumentId:'.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Error calling Extract_SI_Keys on NICA_CHECKLISTS table. Error code: ':ErrorCode:'.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null documentId return from Json response.'
|
|
end
|
|
Next DocIndex
|
|
SRP_JSON(ObjDocumentArray, 'Release')
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Error retrieving documents array from Json response.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Error opening NICA_ORDERS_CHECKLISTS table.'
|
|
end
|
|
end
|
|
|
|
If IsComplete EQ True$ then
|
|
If ( (OrderType _EQC 'IDLE') and (EntityType _EQC 'REACTOR') ) then
|
|
Open 'REACTOR' to hReactor then
|
|
WriteV False$ on hReactor, ReactNo, REACTOR_IDLE_STARTUP_REQUIRED$ else
|
|
ErrorMsg = 'Error in ':Service:' service. Error setting IDLE_STARTUP_REQUIRED flag in REACTOR record.'
|
|
end
|
|
end
|
|
end
|
|
If ErrorMsg EQ '' then Response = True$
|
|
end else
|
|
Response = False$
|
|
end
|
|
If ( (Response EQ True$) or (Response EQ False$) ) then IsSuccessful = True$
|
|
end else
|
|
ErrorMsg = Error_Services('GetMessage')
|
|
end
|
|
end
|
|
SRP_JSON(ObjResponseJson, 'Release')
|
|
end
|
|
Repeat
|
|
|
|
MonaResource = Environment_Services('GetEnvironmentVariable', 'MonaNicaIntegrationServiceGroup')
|
|
StatusName = 'GetNicaOrderUpdate'
|
|
If IsSuccessful and Response NE 'error' then
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = 'Successfully updated Nica order ':OrderId:' for reactor ':ReactNo:'.'
|
|
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'Ok')
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
end else
|
|
Database_Services('ReleaseKeyIDLock', 'NICA_ORDERS', OrderId)
|
|
ErrorMsg = 'Error encountered updating Nica order ':OrderId:' for reactor ':ReactNo:'.'
|
|
Mona_Services('SendBufferedStatus', MonAResource, StatusName, 'Critical')
|
|
end
|
|
end
|
|
end else
|
|
ErrorMsg = Error_Services('GetMessage')
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Failed to lock NICA_ORDERS ':OrderId:'.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null OrderId passed in.'
|
|
end
|
|
|
|
If ErrorMsg NE '' then
|
|
LogData = ''
|
|
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
|
|
LogData<2> = Machine
|
|
LogData<3> = ErrorMsg
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
|
|
Error_Services('Add', ErrorMsg)
|
|
Response = 'error'
|
|
end
|
|
|
|
end service
|
|
|
|
|
|
Service GetFlowChecklistIds(NicaOrderFlowIds, NicaOrderFlowType=ORDER_TYPES, ReactorTypes=REACTOR_TYPES)
|
|
|
|
ErrorMsg = ''
|
|
FlowChecklistIds = ''
|
|
If ( (NicaOrderFlowIds NE '') and (NicaOrderFlowType NE '') and (ReactorTypes NE '') ) then
|
|
Query = 'SELECT NICA_CHECKLISTS '
|
|
For each NicaOrderFlowId in NicaOrderFlowIds using @VM setting vPos
|
|
If vPos GT 1 then Query := 'OR '
|
|
Query := 'WITH NICA_ORDER_FLOW_IDS EQ ':Quote(NicaOrderFlowId):' '
|
|
Next NicaOrderFlowId
|
|
Query := 'AND WITH NICA_ORDER_FLOW_TYPE EQ ':Quote(NicaOrderFlowType):' '
|
|
For each ReactorType in ReactorTypes using @VM setting vPos
|
|
If vPos EQ 1 then
|
|
Query := 'AND '
|
|
end else
|
|
Query := 'OR '
|
|
end
|
|
Query := 'WITH REACTOR_TYPES EQ ':Quote(ReactorType):' '
|
|
Next ReactorType
|
|
Query := 'BY PRIORITY'
|
|
RList(Query, TARGET_ACTIVELIST$, '', '', '')
|
|
ErrCode = ''
|
|
If Not(Get_Status(ErrCode)) then
|
|
EOF = False$
|
|
Loop
|
|
Readnext KeyId else EOF = True$
|
|
Until EOF
|
|
FlowChecklistIds<0, -1> = KeyId
|
|
Repeat
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Error calling RList. Error code: ':ErrCode:'.'
|
|
end
|
|
end else
|
|
ErrorMsg = 'Error in ':Service:' service. Null NicaOrderFlowIds, NicaOrderFlowType, or ReactorTypes Passed in.'
|
|
end
|
|
If ErrorMsg NE '' then
|
|
Error_Services('Add', ErrorMsg)
|
|
end else
|
|
Response = FlowChecklistIds
|
|
end
|
|
|
|
end service
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Internal GoSubs
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|