1616import static eu .europa .ec .fisheries .uvms .movement .model .exception .ErrorCode .MOVEMENT_DUPLICATE_ERROR ;
1717import static eu .europa .ec .fisheries .uvms .rules .service .config .BusinessObjectType .RECEIVING_MOVEMENT_MSG ;
1818import static eu .europa .ec .fisheries .uvms .rules .service .config .ExtraValueType .DATA_FLOW ;
19+ import static eu .europa .ec .fisheries .uvms .rules .service .config .ExtraValueType .MOVEMENT_VESSEL_MAP ;
1920import static eu .europa .ec .fisheries .uvms .rules .service .config .ExtraValueType .SENDER_RECEIVER ;
2021import static eu .europa .ec .fisheries .uvms .rules .service .config .ExtraValueType .XML ;
2122
@@ -270,9 +271,10 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
270271 String pluginType = request .getType ().name ();
271272 String userName = request .getUsername ();
272273 String registeredPluginClassName = request .getRegisteredClassName ();
274+ MovementVesselMappingContext ctx = new MovementVesselMappingContext ();
273275 try {
274276 fluxVesselPositionMessage = JAXBUtils .unMarshallMessage (request .getRequest (), FLUXVesselPositionMessage .class , null );
275- List <RawMovementType > movementReportsList = FLUXVesselPositionMapper .mapToRawMovementTypes (fluxVesselPositionMessage , registeredPluginClassName ,pluginType ,mapToMovementType );
277+ List <RawMovementType > movementReportsList = FLUXVesselPositionMapper .mapToRawMovementTypes (fluxVesselPositionMessage , ctx , registeredPluginClassName ,pluginType ,mapToMovementType );
276278 // If no movements were received then there is no sense to continue, so just going to update the exchange log status to FAILED!
277279 if (CollectionUtils .isEmpty (movementReportsList )) {
278280 log .warn ("The list of rawMovements is EMPTY! Not going to proceed neither validation not sending to Movement Module!" );
@@ -281,10 +283,14 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
281283 return ;
282284 }
283285
286+ // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists.
287+ EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets (movementReportsList , ctx );
288+
284289 Map <ExtraValueType , Object > extraValues = new EnumMap <>(ExtraValueType .class );
285290 extraValues .put (SENDER_RECEIVER , request .getSenderOrReceiver ());
286291 extraValues .put (XML , request .getRequest ());
287292 extraValues .put (DATA_FLOW , request .getFluxDataFlow ());
293+ extraValues .put (MOVEMENT_VESSEL_MAP , ctx );
288294 Collection <AbstractFact > factsResults = rulesEngine .evaluate (RECEIVING_MOVEMENT_MSG ,fluxVesselPositionMessage ,extraValues ,null );
289295
290296 final String reportId = fluxVesselPositionMessage .getFLUXReportDocument ().getIDS ().stream ()
@@ -300,14 +306,14 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
300306 }
301307 // Decomment this one and comment the other when validation is working! Still work needs to be done after this!
302308 // processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid());
303- enrichAndSenMovementsAsBatch (validationResult , movementReportsList , userName , request .getLogGuid (), request , request .getLogGuid ());
309+ enrichAndSenMovementsAsBatch (validationResult , movementReportsList , enrichedWrapper , userName , request .getLogGuid (), request , request .getLogGuid ());
304310 // Send some response to Movement, if it originated from there (manual movement)
305311 if (MovementSourceType .MANUAL .equals (movementReportsList .get (0 ).getSource ())) {// A person has created a position
306312 ProcessedMovementAck response = MovementModuleResponseMapper .mapProcessedMovementAck (eu .europa .ec .fisheries .schema .movement .common .v1 .AcknowledgeTypeType .OK ,
307313 messageGuid , "Movement successfully processed" );
308314 movOutQueueProducer .sendMessageWithSpecificIds (JAXBMarshaller .marshallJaxBObjectToString (response ), movOutQueueProducer .getDestination (), null , messageGuid , messageGuid );
309315 }
310- } catch (JAXBException | RulesModelMarshallException | MessageException | RulesValidationException e ) {
316+ } catch (JAXBException | RulesModelMarshallException | MessageException | RulesValidationException | JMSException | MobileTerminalUnmarshallException | AssetModelMapperException | MobileTerminalModelMapperException e ) {
311317 log .error ("Error while processing received movement" , e );
312318 }
313319 }
@@ -322,10 +328,8 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
322328 * @param exchangeLogGuid
323329 * @throws RulesServiceException
324330 */
325- private void enrichAndSenMovementsAsBatch (ValidationResult validationResult , List <RawMovementType > rawMovements , String username , String exchangeLogGuid , SetFLUXMovementReportRequest request , String reportId ) throws RulesServiceException {
331+ private void enrichAndSenMovementsAsBatch (ValidationResult validationResult , List <RawMovementType > rawMovements , EnrichedMovementWrapper enrichedWrapper , String username , String exchangeLogGuid , SetFLUXMovementReportRequest request , String reportId ) throws RulesServiceException {
326332 try {
327- // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists.
328- EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets (rawMovements );
329333 CreateMovementBatchResponse movementBatchResponse = sendBatchToMovement (enrichedWrapper .getAssetList (), rawMovements , username );
330334 ExchangeLogStatusTypeType status ;
331335 if (movementBatchResponse != null && SimpleResponse .OK .equals (movementBatchResponse .getPermitted ())) {
@@ -340,15 +344,15 @@ private void enrichAndSenMovementsAsBatch(ValidationResult validationResult, Lis
340344 }
341345 sendBatchBackToExchange (exchangeLogGuid , rawMovements , MovementRefTypeType .MOVEMENT , username );
342346 updateRequestMessageStatusInExchange (exchangeLogGuid , status );
343- } catch (MessageException | MobileTerminalModelMapperException | MobileTerminalUnmarshallException | JMSException | AssetModelMapperException | RulesModelException e ) {
347+ } catch (MessageException | RulesModelException e ) {
344348 throw new RulesServiceException (e .getMessage (), e );
345349 }
346350 }
347351
348352 private void processReceivedMovementsAsBatch (List <RawMovementType > rawMovements , String pluginType , String username , String exchangeLogGuid ) throws RulesServiceException {
349353 try {
350354 // Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists.
351- EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets (rawMovements );
355+ EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets (rawMovements , null );
352356 List <RawMovementFact > rawMovementFactList = RawMovementFactMapper .mapRawMovementFacts (rawMovements , enrichedWrapper .getMobileTerminalList (),
353357 enrichedWrapper .getAssetList (), pluginType );
354358 movementValidator .evaluateRawList (rawMovementFactList );
@@ -387,7 +391,7 @@ private void processReceivedMovementsAsBatch(List<RawMovementType> rawMovements,
387391 * @throws JMSException
388392 * @throws MobileTerminalModelMapperException
389393 */
390- private EnrichedMovementWrapper enrichBatchWithMobileTerminalAndAssets (List <RawMovementType > rawMovementList ) throws AssetModelMapperException , MessageException , MobileTerminalUnmarshallException , JMSException , MobileTerminalModelMapperException {
394+ private EnrichedMovementWrapper enrichBatchWithMobileTerminalAndAssets (List <RawMovementType > rawMovementList , MovementVesselMappingContext ctx ) throws AssetModelMapperException , MessageException , MobileTerminalUnmarshallException , JMSException , MobileTerminalModelMapperException {
391395 List <Asset > assetList = new ArrayList <>();
392396 // Get Mobile Terminal if it exists
393397 List <MobileTerminalType > mobileTerminalList ;
@@ -403,6 +407,7 @@ private EnrichedMovementWrapper enrichBatchWithMobileTerminalAndAssets(List<RawM
403407 for (RawMovementType rawMovementType : rawMovementList ) {
404408 Asset asset = getAssetByCfrIrcs (rawMovementType .getAssetId ());
405409 assetList .add (asset );
410+ ctx .put (rawMovementType , asset );
406411 if (isPluginTypeWithoutMobileTerminal (rawMovementType .getPluginType ()) && asset != null ) {
407412 MobileTerminalType mobileTerminal = findMobileTerminalByAsset (asset .getAssetId ().getGuid ());
408413 rawMovementType .setMobileTerminal (MobileTerminalMapper .mapMobileTerminal (mobileTerminal ));
0 commit comments