public MissionTask hook(@Nonnull final MissionTask task) throws YardServiceException, LoadUnitTaskActionException {
freeSwitcher(task);
yardService.callLoadingUnitMovementStartAction(task);
task.setActionStatus(ActionStatus.HOOKED);
return task;
}
code
@Condition({
@Attribute(name = "status", values = { "IN_PROGRESS" }),
@Attribute(name = "actionStatus", values = { "HOOKED" })
})
public MissionTask unhook(@Nonnull final MissionTask task) {
yardService.callLoadingUnitMovementEndAction(task);
return closeTask(task);
}
public LoadingUnitMovement callLoadingUnitMovementStartAction(final MissionTask mission) {
SwitcherReference switcher = mission.getVehicle() != null ? SwitcherReference.from(mission.getVehicle()) : null;
return callActionOnLoadingUnitMovement(mission.getLoadingUnitMovementRef(), "start", new LoadingUnitMovementStartAction(switcher));
}
public LoadingUnitMovement callLoadingUnitMovementEndAction(final MissionTask mission) {
return callActionOnLoadingUnitMovement(mission.getLoadingUnitMovementRef(), "end", new LoadingUnitMovementEndAction());
}
/**
* Change the status of the LoadingUnitMovement to EXECUTING. <br>
* The following events are triggered:
* <ol>
* <li>LoadingUnitMovementStatusChangedEvent
* </ol>
*
* @throws LoadingUnitMovementActionException
* @throws LoadingUnitActionException
* @throws MasterdataServiceException
* @throws EntityNotFoundException
*/
@Condition({@Attribute(name = "status", values = {"TO_DO", "WAITING"})})
public LoadingUnitMovement action(final LoadingUnitMovement entity, final LoadingUnitMovementStartAction action)
throws LoadingUnitMovementActionException, LoadingUnitActionException, EntityNotFoundException,
MasterdataServiceException {
return this.start(entity, action);
}
private LoadingUnitMovement start(final LoadingUnitMovement entity, final LoadingUnitMovementStartAction action)
throws LoadingUnitMovementActionException, LoadingUnitActionException, EntityNotFoundException,
MasterdataServiceException {
checkLoadingUnitMovementIsNotStarted(entity);
LoadingUnitResource loadingUnitResource = getEm().find(LoadingUnitResource.class, Long.parseLong(entity.getLoadingUnitRef().getEntityId()));
if (!action.isHookingVehicleDataMissing()) {
loadingUnitResourceHandler.hookLoadingUnit(loadingUnitResource, action, switcherProviderProxy);
}
loadingUnitMovementApplicationService.createNewMovement(entity);
return entity;
}
Assistant
This part of code doesn't make much sense:
the hook( on yms module calls a http sincronous call to the yard called start but this start does not only start a movement but also hooks the switcher to the loading unit.
I want to change this, so we don't call hook on the yms but directly on the yard, and it does only perform the hook and not the moving
It looks like you want to refactor your code so that the hook() method in your YMS (Yard Management System) module directly calls a hook action on the Yard module, and that this action only performs the hook operation without starting the movement. Currently, the hook() method in your YMS module calls callLoadingUnitMovementStartAction(), which not only hooks the switcher to the loading unit but also starts the movement.
Here's how you can achieve the desired behavior:
Create a Separate Hook Action in the Yard Module
First, you need to define a new action in the Yard module that handles only the hook operation without starting the movement. This means creating a new action class and corresponding handler method.
java
// New action class for hooking
public class LoadingUnitMovementHookAction {
private SwitcherReference switcher;
public LoadingUnitMovementHookAction(SwitcherReference switcher) {
this.switcher = switcher;
}
public boolean isHookingVehicleDataMissing() {
return this.switcher == null;
}
public SwitcherReference getSwitcher() {
return switcher;
}
}
Then, in your Yard service, add a new handler method for the hook action:
java
@Condition({ @Attribute(name = "status", values = { "TO_DO", "WAITING" }) })
public LoadingUnitMovement action(final LoadingUnitMovement entity, final LoadingUnitMovementHookAction action)
throws LoadingUnitMovementActionException, LoadingUnitActionException, EntityNotFoundException,
MasterdataServiceException {
return this.hook(entity, action);
}
private LoadingUnitMovement hook(final LoadingUnitMovement entity, final LoadingUnitMovementHookAction action)
throws LoadingUnitMovementActionException, LoadingUnitActionException, EntityNotFoundException,
MasterdataServiceException {
// Perform only the hook operation
checkLoadingUnitMovementIsNotStarted(entity);
LoadingUnitResource loadingUnitResource = getEm().find(LoadingUnitResource.class,
Long.parseLong(entity.getLoadingUnitRef().getEntityId()));
if (!action.isHookingVehicleDataMissing()) {
loadingUnitResourceHandler.hookLoadingUnit(loadingUnitResource, action, switcherProviderProxy);
}
// Do not start movement here
return entity;
}
This hook() method only performs the hook operation and does not start the movement.
Update the YMS Module to Call the New Hook Action
In your YMS module, modify the hook() method to call the new callLoadingUnitMovementHookAction() method instead of callLoadingUnitMovementStartAction().
java
public MissionTask hook(@Nonnull final MissionTask task) throws YardServiceException, LoadUnitTaskActionException {
freeSwitcher(task);
yardService.callLoadingUnitMovementHookAction(task);
task.setActionStatus(ActionStatus.HOOKED);
return task;
}
Then, implement the callLoadingUnitMovementHookAction() method in your YardService:
Make sure that the action method in the Yard module is annotated with the correct @Condition to reflect the statuses during which the hook operation is valid. For example:
If there are any frontend applications or other services that consume these APIs, make sure to update them to use the new methods accordingly.
Test Thoroughly
After making these changes, it's crucial to test the entire flow to ensure that:
The hook operation successfully attaches the switcher to the loading unit without starting the movement.
The start movement operation only starts the movement when the loading unit is already hooked.
The unhook operation detaches the switcher from the loading unit at the appropriate time.
State transitions and statuses are updated correctly throughout the process.
Summary
By introducing separate actions for hook, start, and unhook, you decouple the hooking operation from starting the movement. This provides clearer separation of concerns and allows for more granular control over each step in the Yard Management process.
Note: Ensure that the method names, class names, and statuses used in the annotations (@Condition, @Attribute) match those in your existing codebase or any established conventions in your project.