diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/CreateMissionRequestEventObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/CreateMissionRequestEventObserver.java
index 232e76f..4acdfb8 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/CreateMissionRequestEventObserver.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/CreateMissionRequestEventObserver.java
@@ -12,31 +12,27 @@ import org.slf4j.Logger;
 
 import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.masterdata.reference.SiteReference;
-import eu.reply.lea.services.process.task.entities.TaskStatus;
 import eu.reply.lea.services.process.task.entities.exceptions.TaskConfigurationNotFoundException;
-import eu.reply.lea.services.yard.client.DefaultYardService;
 import eu.reply.lea.services.yard.events.loadingUnit.sending.CreateMissionRequestCreatedEvent;
 import eu.reply.lea.services.yard.events.loadingUnit.sending.CreateMissionRequestRetryEvent;
 import eu.reply.lea.services.yard.model.LoadingUnitActivity;
 import eu.reply.lea.services.yard.pojo.CreateMissionRequestPojo;
 import eu.reply.lea.services.yard.pojo.LoadingUnitActivityPojo;
 import eu.reply.lea.services.yms.boundary.YardService;
-import eu.reply.lea.services.yms.task.TaskType;
 import eu.reply.lea.services.yms.task.dockaware.loading.LoadingTask;
 import eu.reply.lea.services.yms.task.dockaware.unloading.UnloadingTask;
 import eu.reply.lea.services.yms.task.event.InternalTasksSequenceCreatedEvent;
 import eu.reply.lea.services.yms.task.factory.InternalTaskBuilderDirector;
 import eu.reply.lea.services.yms.task.factory.TaskDetailInfo;
 import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask;
-import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTaskRepository;
 import eu.reply.lea.services.yms.task.sequence.InternalTasksSequence;
 import eu.reply.lea.services.yms.task.sequence.InternalTasksSequenceHandler;
+import eu.reply.lea.services.yms.task.sequence.TaskSequenceAdvancementService;
 import eu.reply.lea.services.yms.task.sequence.repository.InternalTasksSequenceRepository;
 import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
 import eu.reply.sce.backend.core.event.ModuleEvent;
 import eu.reply.sce.backend.core.event.Observer;
 import eu.reply.sce.backend.core.jee.configuration.ModuleConfiguration;
-import eu.reply.sce.backend.core.jee.configuration.entity.EntityReferenceHandler;
 
 @Observer
 public class CreateMissionRequestEventObserver {
@@ -51,20 +47,13 @@ public class CreateMissionRequestEventObserver {
     private InternalTasksSequenceRepository internalTasksSequenceRepository;
 
     @Inject
-    private EntityReferenceHandler entityReferenceHandler;
-
-    @Inject
-    private DefaultYardService defaultYardService;
-
-    @Inject
     private YardService yardService;
 
     @Inject
-    private ConfigurableEventProducer<InternalTasksSequenceCreatedEvent> internalTasksSequenceCreatedEventProducer;
-
+    private TaskSequenceAdvancementService taskSequenceAdvancementService;
 
     @Inject
-    private MissionTaskRepository missionTaskRepository;
+    private ConfigurableEventProducer<InternalTasksSequenceCreatedEvent> internalTasksSequenceCreatedEventProducer;
 
     @Inject
     @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
@@ -112,18 +101,6 @@ public class CreateMissionRequestEventObserver {
     private void createMission(final CreateMissionRequestPojo payload) throws Exception {
         Exception exceptionErrorDuringCreation = null;
         try {
-
-            MissionTask missionTaskAlreadyPresent = missionTaskRepository.findByLoadingUnit(payload.getLoadingUnitRef())
-                    .stream().filter(task -> task.getStatus().isActive()
-                            && task.getTaskType().equals(TaskType.MISSION)
-                            && (task.getStatus().equals(TaskStatus.BLOCKED)
-                            || task.getStatus().equals(TaskStatus.TODO)
-                            || task.getStatus().equals(TaskStatus.IN_PROGRESS)
-                            || task.getStatus().equals(TaskStatus.PENDING)))
-                    .findFirst()
-                    .orElse(null);
-
-            if (missionTaskAlreadyPresent == null) {
             SiteReference siteRef = payload.getSiteReference();
             InternalTasksSequence
                 sequence = internalTasksSequenceRepository.findByLogisticUnitReference(payload.getLoadingUnitRef().toEntityReference());
@@ -159,10 +136,9 @@ public class CreateMissionRequestEventObserver {
                 internalTasksSequenceHandler.addTask(sequence, loadingTask);
             }
 
-                //sendTaskUnlockRequest(new LoadingUnitReference(payload.getLoadingUnit()));
             this.yardService.createMissionRequestCompleted(payload);
             internalTasksSequenceCreatedEventProducer.fire(new InternalTasksSequenceCreatedEvent(sequence.getLogisticUnitRef()));
-            }
+
 
 
         } catch (Exception exception) {
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java
index c45bb62..4061434 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java
@@ -120,6 +120,9 @@ public class TransitEventObserver {
     private TaskDequeueService taskDequeueService;
 
     @Inject
+    private TaskSequenceAdvancementService taskSequenceAdvancementService;
+
+    @Inject
     private YardService yardService;
 
     @Inject
@@ -346,7 +349,7 @@ public class TransitEventObserver {
                 new ResetTaskInfoForAdviseMessageEvent(
                     new LocationAwareTaskEventInfo(null, null, null, transitRef.toEntityReference(), Calendar.getInstance())));
         TransitTasksSequence transitTasksSequence= transitTasksSequenceRepository.findByTransitRef(transitRef);
-        transitTasksSequenceHandler.unlockNextTask(transitTasksSequence);
+        taskSequenceAdvancementService.advanceTaskInSequence(transitTasksSequence);
     }
 
 
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskHookedEvent.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskHookedEvent.java
new file mode 100644
index 0000000..124bd81
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskHookedEvent.java
@@ -0,0 +1,16 @@
+package eu.reply.lea.services.yms.task.event;
+
+import eu.reply.sce.backend.core.event.ConfigurableEvent;
+
+public class MissionTaskHookedEvent extends ConfigurableEvent<MissionTaskHookedEventInfo> {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 251519363051684676L;
+
+    public MissionTaskHookedEvent(final MissionTaskHookedEventInfo payload) {
+        super(payload);
+    }
+
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskHookedEventInfo.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskHookedEventInfo.java
new file mode 100644
index 0000000..5474cc4
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskHookedEventInfo.java
@@ -0,0 +1,27 @@
+package eu.reply.lea.services.yms.task.event;
+
+import java.time.Instant;
+
+import eu.reply.lea.services.yard.events.DomainEventInfo;
+import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask;
+
+public class MissionTaskHookedEventInfo implements DomainEventInfo {
+
+    private final MissionTask missionTask;
+    private final Instant occurredOn;
+
+    public MissionTaskHookedEventInfo(MissionTask missionTask) {
+        super();
+        this.missionTask = missionTask;
+        this.occurredOn = Instant.now();
+    }
+
+    public MissionTask getMissionTask() {
+        return missionTask;
+    }
+
+    @Override
+    public Instant getOccurredOn() {
+        return occurredOn;
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskUnhookedEvent.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskUnhookedEvent.java
new file mode 100644
index 0000000..f969ee1
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskUnhookedEvent.java
@@ -0,0 +1,16 @@
+package eu.reply.lea.services.yms.task.event;
+
+import eu.reply.sce.backend.core.event.ConfigurableEvent;
+
+public class MissionTaskUnhookedEvent extends ConfigurableEvent<MissionTaskUnhookedEventInfo> {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 251519363051684676L;
+
+    public MissionTaskUnhookedEvent(final MissionTaskUnhookedEventInfo payload) {
+        super(payload);
+    }
+
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskUnhookedEventInfo.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskUnhookedEventInfo.java
new file mode 100644
index 0000000..18bc2c8
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/event/MissionTaskUnhookedEventInfo.java
@@ -0,0 +1,27 @@
+package eu.reply.lea.services.yms.task.event;
+
+import java.time.Instant;
+
+import eu.reply.lea.services.yard.events.DomainEventInfo;
+import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask;
+
+public class MissionTaskUnhookedEventInfo implements DomainEventInfo {
+
+    private final MissionTask missionTask;
+    private final Instant occurredOn;
+
+    public MissionTaskUnhookedEventInfo(MissionTask missionTask) {
+        super();
+        this.missionTask = missionTask;
+        this.occurredOn = Instant.now();
+    }
+
+    public MissionTask getMissionTask() {
+        return missionTask;
+    }
+
+    @Override
+    public Instant getOccurredOn() {
+        return occurredOn;
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/factory/InternalTaskBuilderDirector.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/factory/InternalTaskBuilderDirector.java
index e6abde1..d72d9f3 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/factory/InternalTaskBuilderDirector.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/factory/InternalTaskBuilderDirector.java
@@ -71,7 +71,7 @@ public class InternalTaskBuilderDirector {
         throws TaskConfigurationNotFoundException {
         MissionTaskBuilder taskBuilder = (MissionTaskBuilder)
             taskBuilderFactory.getTaskBuilder(TaskType.MISSION)
-                .initBuilder(logisticUnitReference, siteReference, null, locationTo)
+                .initBuilder(logisticUnitReference, siteReference, null, locationFrom)
                 .setScheduled(scheduled).setUrgent(isUrgent)
                 .addTaskParameter("locationFrom", locationFrom)
                 .addTaskParameter("locationTo", locationTo);
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/application/LocationAwareTaskApplicationService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/application/LocationAwareTaskApplicationService.java
new file mode 100644
index 0000000..0262597
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/application/LocationAwareTaskApplicationService.java
@@ -0,0 +1,38 @@
+package eu.reply.lea.services.yms.task.locationaware.application;
+
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+
+import eu.reply.lea.services.yms.ModuleConfiguration;
+import eu.reply.lea.services.yms.task.TaskReference;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskClosureDomainService;
+import eu.reply.sce.backend.core.jee.configuration.entity.EntityReferenceHandler;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@Logged
+@ApplicationScoped
+@Named("LocationAwareTaskApplicationService")
+public class LocationAwareTaskApplicationService {
+
+    @Inject
+    private TaskClosureDomainService taskClosureDomainService;
+
+    @Inject
+    @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
+    private EntityManager em;
+
+    @Inject
+    private EntityReferenceHandler entityReferenceHandler;
+
+    @TransactionAttribute(TransactionAttributeType.REQUIRED)
+    public void handleTaskClosure(final TaskReference taskReference) {
+        final LocationAwareTask<?,?,?>
+            task =  entityReferenceHandler.getEntity(taskReference.toEntityReference(), em);
+        taskClosureDomainService.handleTaskClosure(task);
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/application/MissionTaskApplicationService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/application/MissionTaskApplicationService.java
new file mode 100644
index 0000000..77b3dfd
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/application/MissionTaskApplicationService.java
@@ -0,0 +1,62 @@
+package eu.reply.lea.services.yms.task.locationaware.application;
+
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import eu.reply.lea.services.yard.reference.LoadingUnitReference;
+import eu.reply.lea.services.yard.reference.SwitcherReference;
+import eu.reply.lea.services.yms.boundary.YardService;
+import eu.reply.lea.services.yms.task.TaskReference;
+import eu.reply.lea.services.yms.task.event.MissionTaskHookedEvent;
+import eu.reply.lea.services.yms.task.event.MissionTaskHookedEventInfo;
+import eu.reply.lea.services.yms.task.event.MissionTaskUnhookedEvent;
+import eu.reply.lea.services.yms.task.event.MissionTaskUnhookedEventInfo;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskDequeueService;
+import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask;
+import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTaskRepository;
+import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@Logged
+@ApplicationScoped
+@Named("MissionTaskApplicationService")
+public class MissionTaskApplicationService extends LocationAwareTaskApplicationService{
+
+    @Inject
+    private YardService yardService;
+
+    @Inject
+    private TaskDequeueService taskDequeueService;
+
+    @Inject
+    private MissionTaskRepository missionTaskRepository;
+
+    @Inject
+    private ConfigurableEventProducer<MissionTaskHookedEvent> missionTaskHookedProducer;
+
+    @Inject
+    private ConfigurableEventProducer<MissionTaskUnhookedEvent> missionTaskUnhookedProducer;
+
+    public MissionTask hookLoadingUnit(final TaskReference taskReference, final LoadingUnitReference loadingUnitReference, final SwitcherReference switcherReference){
+        MissionTask missionTask = missionTaskRepository.findByTaskReference(taskReference);
+        if (missionTask != null) {
+            yardService.callLoadingUnitHookAction(loadingUnitReference, switcherReference);
+            missionTask.setActionStatus(MissionTask.ActionStatus.HOOKED);
+            taskDequeueService.dequeueTasks(missionTask.getSequence().getAllTasksContiguousInTheLocationClosed(missionTask, true));
+            missionTaskHookedProducer.fire(new MissionTaskHookedEvent(new MissionTaskHookedEventInfo(missionTask)));
+        }
+        return missionTask;
+    }
+
+    public MissionTask unhookLoadingUnit(final TaskReference taskReference, final LoadingUnitReference loadingUnitReference, final SwitcherReference switcherReference){
+        MissionTask missionTask = missionTaskRepository.findByTaskReference(taskReference);
+        if (missionTask != null) {
+            yardService.callLoadingUnitReleaseAction(loadingUnitReference);
+            missionTask.setActionStatus(MissionTask.ActionStatus.UNHOOKED);
+            missionTaskUnhookedProducer.fire(new MissionTaskUnhookedEvent(new MissionTaskUnhookedEventInfo(missionTask)));
+        }
+        return missionTask;
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/MissionTaskProcessor.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/MissionTaskProcessor.java
index 98edacd..f1765ed 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/MissionTaskProcessor.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/MissionTaskProcessor.java
@@ -17,8 +17,10 @@ import eu.reply.lea.services.yard.pojo.SwitcherPojo;
 import eu.reply.lea.services.yard.reference.LoadingUnitReference;
 import eu.reply.lea.services.yard.reference.SwitcherReference;
 import eu.reply.lea.services.yms.boundary.YardService;
+import eu.reply.lea.services.yms.task.TaskReference;
 import eu.reply.lea.services.yms.task.exception.LoadUnitTaskActionException;
 import eu.reply.lea.services.yms.task.exception.LoadUnitTaskActionException.Codes;
+import eu.reply.lea.services.yms.task.locationaware.application.MissionTaskApplicationService;
 import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask.ActionStatus;
 import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTaskAssociateVehicleAction;
@@ -37,9 +39,14 @@ public class MissionTaskProcessor extends AbstractLocationAwareTaskProcessor<Mis
 	@Inject
 	private YardService yardService;
 
+
+    @Inject
+    private MissionTaskApplicationService missionTaskApplicationService;
+
 	@Inject
 	private DefaultYardService defaultYardService;
 
+
 	@Override
 	@Condition({ @Attribute(name = "status", values = { "TODO", "IN_PROGRESS", "PENDING" }) })
 	public MissionTask enter(final MissionTask task) {
@@ -94,10 +101,10 @@ public class MissionTaskProcessor extends AbstractLocationAwareTaskProcessor<Mis
         @Attribute(name = "actionStatus", values = {"READY"}),
         @Attribute(name = "vehicle", values = {"<> null"})
     })
-	public MissionTask hook(@Nonnull final MissionTask task) throws YardServiceException, LoadUnitTaskActionException {
-        yardService.callLoadingUnitHookAction(new LoadingUnitReference(task.getLogisticUnitReference()), SwitcherReference.from(task.getVehicle()));
-		task.setActionStatus(ActionStatus.HOOKED);
-		return task;
+    public MissionTask hook(@Nonnull final MissionTask task) {
+        return missionTaskApplicationService.hookLoadingUnit(new TaskReference(task),
+                                                             new LoadingUnitReference(task.getLogisticUnitReference()),
+                                                             SwitcherReference.from(task.getVehicle()));
     }
 
     @Condition({
@@ -105,15 +112,15 @@ public class MissionTaskProcessor extends AbstractLocationAwareTaskProcessor<Mis
         @Attribute(name = "actionStatus", values = {"HOOKED"})
     })
     public MissionTask unhook(@Nonnull final MissionTask task) {
-		yardService.callLoadingUnitReleaseAction(new LoadingUnitReference(task.getLogisticUnitReference()));
-        task.setActionStatus(ActionStatus.UNHOOKED);
-		return task;
+        return missionTaskApplicationService.unhookLoadingUnit(new TaskReference(task),
+                                                               new LoadingUnitReference(task.getLogisticUnitReference()),
+                                                               SwitcherReference.from(task.getVehicle()));
     }
 
     @Condition({
 		@Attribute(name = "status", values = { "IN_PROGRESS" })
 	})
-	public MissionTask complete(@Nonnull final MissionTask task) throws YardServiceException, LoadUnitTaskActionException {
+	public MissionTask complete(@Nonnull final MissionTask task) throws LoadUnitTaskActionException {
         if(!task.getActionStatus().equals(ActionStatus.UNHOOKED)){
             throw new LoadUnitTaskActionException(Codes.LOADING_UNIT_NEVER_UNHOOKED, task);
         }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskApplicationService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskApplicationService.java
deleted file mode 100644
index 62dd7b1..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskApplicationService.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package eu.reply.lea.services.yms.task.locationaware.domain;
-
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-
-import eu.reply.lea.services.masterdata.reference.LocationReference;
-import eu.reply.lea.services.yms.ModuleConfiguration;
-import eu.reply.lea.services.yms.task.TaskReference;
-import eu.reply.lea.services.yms.task.locationaware.integration.yms.queue.TaskDequeueAdapter;
-import eu.reply.lea.services.yms.task.sequence.LocationAwareTasksSequence;
-import eu.reply.sce.backend.core.jee.configuration.entity.EntityReferenceHandler;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-@Logged
-@ApplicationScoped
-public class LocationAwareTaskApplicationService {
-
-    @Inject
-    private TaskDequeueAdapter taskDequeueAdapter;
-
-    @Inject
-    @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
-    private EntityManager em;
-
-    @Inject
-    private EntityReferenceHandler entityReferenceHandler;
-
-    @TransactionAttribute(TransactionAttributeType.REQUIRED)
-    public void handleTaskClosure(final TaskReference taskReference) {
-        final LocationAwareTask<?,?,?>
-            task =  entityReferenceHandler.getEntity(taskReference.toEntityReference(), em);
-        LocationAwareTasksSequence<LocationAwareTask<?, ?, ?>> sequence =
-            task.getSequence();
-
-        if (sequence != null && sequence.areAllTasksContiguousInTheLocationClosed(task)) {
-            // Delegate external service call to adapter
-            taskDequeueAdapter.notifyDequeueForTask(sequence.getTasksSameLocationContiguously(task, true));
-        }
-    }
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskHandler.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskHandler.java
index dd99a42..dafff3a 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskHandler.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskHandler.java
@@ -201,7 +201,7 @@ public class LocationAwareTaskHandler {
         LocationAwareTask<?,?,?> task) throws MasterdataServiceException, LoadingUnitActionException {
         TaskStatus previousStatus = task.getStatus();
 
-        Boolean canUnlock = checkCanUnlock(task) && task.activate();
+        Boolean canUnlock = task.checkCanActivate() && task.activate();
 
         if (canUnlock) {
             this.debug("[unlockTask] Unlocked Task with Name:[{}] and TaskType:[{}]!", task.getName(), task.getTaskType());
@@ -238,56 +238,6 @@ public class LocationAwareTaskHandler {
     }
 
 
-    /**
-     * Checks all the conditions that are necessary to unlock a task
-     * It returns true if the conditions are respected.
-     *
-     * @param task
-     * @return Boolean, true if I can unlock a task
-     * @throws MasterdataServiceException
-     */
-    public Boolean checkCanUnlock(final LocationAwareTask<?,?,?> task) throws MasterdataServiceException {
-        Boolean canActivateTask = task.checkCanActivate();
-        this.debug("Task with Name:[{}] and TaskType:[{}] => [{}] activated!", task.getName(), task.getTaskType(), canActivateTask ? "CAN BE" : "CANNOT BE");
-
-        if (canActivateTask) {
-            this.debug("Task with Name:[{}] and TaskType:[{}]!",
-                    task.getName(),
-                    task.getTaskType());
-
-            if (task instanceof RegistrationTask) {//If the task is a registration task we can always unlock it
-                return true;
-            }
-            if ( task.getHeaders().isEnableQueue()) {
-
-                if (checkTaskConditions(task) && !task.getSequence().isBlocked()) {
-                        return true;
-                }
-            } else {//if we can activate and it's not a location aware task return true
-                return true;
-            }
-        }
-        return false; //can't activate
-    }
-
-
-    private boolean checkTaskConditions(LocationAwareTask<?,?,?> locTask)
-        throws MasterdataServiceException {
-        QueueProcessTracker //TODO move this
-            transitQueueProcessTracker = queueProcessTrackerRepository.findByLogisticUnitRef(locTask.getLogisticUnitReference());
-        if(transitQueueProcessTracker == null || !transitQueueProcessTracker.isTaskQueued(new TaskReference(locTask))){
-            this.debug("No process tracker for transit [{}]", locTask.getLogisticUnitReference());
-            return false;
-        }
-        if (sequenceHandler.isTransitBusy(locTask.getSequence())) {
-            this.debug("Transit is busy for task [{}]", locTask.getName());
-            return false;
-        }
-
-        return true;
-    }
-
-
 
     /**
      * The first unloading dock is computed as the first
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LogisticUnitService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LogisticUnitService.java
new file mode 100644
index 0000000..073fb7b
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LogisticUnitService.java
@@ -0,0 +1,8 @@
+package eu.reply.lea.services.yms.task.locationaware.domain;
+
+import eu.reply.sce.backend.core.entity.EntityReference;
+
+public interface LogisticUnitService {
+
+    public boolean canMoveAutonomously(EntityReference entityReference);
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskClosureDomainService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskClosureDomainService.java
new file mode 100644
index 0000000..db6bafe
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskClosureDomainService.java
@@ -0,0 +1,29 @@
+package eu.reply.lea.services.yms.task.locationaware.domain;
+
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.sequence.LocationAwareTasksSequence;
+import eu.reply.lea.services.yms.task.sequence.TaskSequenceAdvancementService;
+
+public class TaskClosureDomainService {
+
+    @Inject
+    private TaskDequeueService taskDequeueService;
+
+    @Inject
+    private LogisticUnitService logisticUnitService;
+
+    @Inject
+    private TaskSequenceAdvancementService taskSequenceAdvancementService;
+
+    public void handleTaskClosure(LocationAwareTask<?, ?, ?> task) {
+        LocationAwareTasksSequence<LocationAwareTask<?, ?, ?>> sequence = task.getSequence();
+
+        if (task.getLocation() != null && logisticUnitService.canMoveAutonomously(task.getLogisticUnitReference()) && sequence.areAllTasksContiguousInTheLocationClosed(task)) {
+            // Dequeue From location
+            taskDequeueService.dequeueTasks(sequence.getAllTasksContiguousInTheLocationClosed(task, true));
+        }
+        // unlock the next task
+        taskSequenceAdvancementService.advanceTaskInSequence(sequence);
+    }
+}
\ No newline at end of file
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskQueueService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskQueueService.java
new file mode 100644
index 0000000..5169896
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskQueueService.java
@@ -0,0 +1,9 @@
+package eu.reply.lea.services.yms.task.locationaware.domain;
+
+import eu.reply.sce.backend.core.entity.EntityReference;
+
+public interface TaskQueueService {
+
+    boolean isTaskQueued(LocationAwareTask<?, ?, ?> task);
+    void queueTasks(EntityReference logisticUnitReference);
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTask.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTask.java
index c326370..15768a6 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTask.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTask.java
@@ -41,17 +41,23 @@ import eu.reply.sce.backend.core.sequence.businesskey.BusinessKeySequence;
 @BusinessKeySequence(prefix = "MISSION", length = 10)
 @NamedQueries({
     @NamedQuery(name=MissionTask.Q_FIND_BY_VEHICLE_REF,query="select m from MissionTask m where m.vehicle = :vehicle"),
-    @NamedQuery(name = MissionTask.Q_FIND_BY_LOADING_UNIT_REFERENCE,
-        query = "select DISTINCT m from MissionTask m JOIN m.details md "
-                + "where md.loadingUnitReference.entityId = :entityId "
-                + "and md.loadingUnitReference.entityName = :entityName and md.loadingUnitReference.module = :module")
+    @NamedQuery(name = MissionTask.Q_FIND_BY_LOGISTIC_UNIT_REFERENCE,
+        query = "select DISTINCT m from MissionTask m  "
+                + "where m.logisticUnitReference.entityId = :entityId "
+                + "and m.logisticUnitReference.entityName = :entityName and m.logisticUnitReference.module = :module"),
+    @NamedQuery(name = MissionTask.Q_FIND_BY_LOGISTIC_UNIT_REFERENCE_AND_ACTION_STATUS,
+        query = "select DISTINCT m from MissionTask m  "
+                + "where m.logisticUnitReference.entityId = :entityId "
+                + "and m.logisticUnitReference.entityName = :entityName and m.logisticUnitReference.module = :module "
+                + "and m.status = :taskStatus")
 })
 public class MissionTask extends LocationAwareTask<MissionTaskConfiguration, MissionTaskHeader, MissionTaskDetail>{
 
     private static final long serialVersionUID = 6266394206640176004L;
 
     public static final String Q_FIND_BY_VEHICLE_REF = "MissionTask.Q_FIND_BY_VEHICLE_REF";
-    public static final String Q_FIND_BY_LOADING_UNIT_REFERENCE = "MissionTask.Q_FIND_BY_LOADING_UNIT_REFERENCE";
+    public static final String Q_FIND_BY_LOGISTIC_UNIT_REFERENCE = "MissionTask.Q_FIND_BY_LOADING_UNIT_REFERENCE";
+    public static final String Q_FIND_BY_LOGISTIC_UNIT_REFERENCE_AND_ACTION_STATUS = "MissionTask.Q_FIND_BY_LOADING_UNIT_REFERENCE_AND_ACTION_STATUS";
 
     public static final String P_VEHICLE = "vehicle";
     
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTaskRepository.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTaskRepository.java
index 244c11e..44796fc 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTaskRepository.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/mission/MissionTaskRepository.java
@@ -5,9 +5,13 @@ import java.util.List;
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
 
+import eu.reply.lea.services.process.task.entities.TaskStatus;
 import eu.reply.lea.services.yard.reference.LoadingUnitReference;
+import eu.reply.lea.services.yms.task.TaskReference;
 import eu.reply.sce.backend.core.jee.configuration.ModuleConfiguration;
+import eu.reply.sce.backend.core.jee.configuration.entity.EntityReferenceHandler;
 import eu.reply.sce.backend.core.jee.log.Logged;
 
 @ApplicationScoped
@@ -18,10 +22,16 @@ public class MissionTaskRepository {
     @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
     private EntityManager em;
 
+    @Inject
+    private EntityReferenceHandler entityReferenceHandler;
+
+    public MissionTask findByTaskReference(final TaskReference taskReference) {
+        return entityReferenceHandler.getEntity(taskReference.toEntityReference(), MissionTask.class, em);
 
+    }
 
     public List<MissionTask> findByLoadingUnit(final LoadingUnitReference loadingUnitReference) {
-        return em.createNamedQuery(MissionTask.Q_FIND_BY_LOADING_UNIT_REFERENCE, MissionTask.class)
+        return em.createNamedQuery(MissionTask.Q_FIND_BY_LOGISTIC_UNIT_REFERENCE, MissionTask.class)
             .setParameter("module", loadingUnitReference.getModule())
             .setParameter("entityName", loadingUnitReference.getEntityName())
             .setParameter("entityId", loadingUnitReference.getEntityId())
@@ -29,5 +39,18 @@ public class MissionTaskRepository {
 
     }
 
+    public MissionTask findByLoadingUnitAndStatus(final LoadingUnitReference loadingUnitReference, TaskStatus taskStatus) {
+        try {
+            return em.createNamedQuery(MissionTask.Q_FIND_BY_LOGISTIC_UNIT_REFERENCE_AND_ACTION_STATUS, MissionTask.class)
+                .setParameter("module", loadingUnitReference.getModule())
+                .setParameter("entityName", loadingUnitReference.getEntityName())
+                .setParameter("entityId", loadingUnitReference.getEntityId())
+                .setParameter("taskStatus", taskStatus)
+                .getSingleResult();
+        } catch (NoResultException e) {
+            return null;
+        }
+    }
+
 
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yard/LogisticUnitPolicy.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yard/LogisticUnitPolicy.java
new file mode 100644
index 0000000..1f6ba5a
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yard/LogisticUnitPolicy.java
@@ -0,0 +1,19 @@
+package eu.reply.lea.services.yms.task.locationaware.integration.yard;
+
+import java.util.Set;
+import javax.enterprise.context.ApplicationScoped;
+
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class LogisticUnitPolicy {
+
+    private static final Set<String> NON_AUTONOMOUS_LOGISTIC_UNIT_NAMES = Set.of("ContainerResource", "TrailerResource");
+    
+    public boolean canMoveAutonomously(EntityReference logisticUnitRef) {
+        String entityName = logisticUnitRef.getEntityName();
+        return !NON_AUTONOMOUS_LOGISTIC_UNIT_NAMES.contains(entityName);
+    }
+}
\ No newline at end of file
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yard/LogisticUnitServiceImpl.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yard/LogisticUnitServiceImpl.java
new file mode 100644
index 0000000..2238b2e
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yard/LogisticUnitServiceImpl.java
@@ -0,0 +1,21 @@
+package eu.reply.lea.services.yms.task.locationaware.integration.yard;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LogisticUnitService;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class LogisticUnitServiceImpl implements LogisticUnitService {
+
+    @Inject
+    private LogisticUnitPolicy logisticUnitPolicy;
+
+    @Override
+    public boolean canMoveAutonomously(final EntityReference entityReference) {
+        return logisticUnitPolicy.canMoveAutonomously(entityReference);
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskQueueServiceImpl.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskQueueServiceImpl.java
new file mode 100644
index 0000000..aa8c69a
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskQueueServiceImpl.java
@@ -0,0 +1,43 @@
+package eu.reply.lea.services.yms.task.locationaware.integration.yms.queue;
+
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+
+import eu.reply.lea.services.yms.task.TaskReference;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskQueueService;
+import eu.reply.lea.services.yms.task.queue.QueueProcessTracker;
+import eu.reply.lea.services.yms.task.queue.event.TaskQueueCommand;
+import eu.reply.lea.services.yms.task.queue.event.TaskQueueCommandInfo;
+import eu.reply.lea.services.yms.task.queue.repository.QueueProcessTrackerRepository;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
+
+public class TaskQueueServiceImpl implements TaskQueueService {
+
+    @Inject
+    private Logger logger;
+
+    @Inject
+    private QueueProcessTrackerRepository queueProcessTrackerRepository;
+
+    @Inject
+    private ConfigurableEventProducer<TaskQueueCommand> taskQueueCommandProducer;
+
+    public boolean isTaskQueued(LocationAwareTask<?, ?, ?> task){
+        QueueProcessTracker
+            transitQueueProcessTracker = queueProcessTrackerRepository.findByLogisticUnitRef(task.getLogisticUnitReference());
+        if(transitQueueProcessTracker == null || !transitQueueProcessTracker.isTaskQueued(new TaskReference(task))){
+            logger.info("No process tracker for logisticUnit [{}]", task.getLogisticUnitReference());
+            return false;
+        }
+        return true;
+    }
+
+    public void queueTasks(EntityReference logisticUnitReference){
+        taskQueueCommandProducer.fire(new TaskQueueCommand(new TaskQueueCommandInfo(logisticUnitReference)));
+    }
+
+
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/observer/TaskClosureObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/observer/TaskClosureObserver.java
index f04ca36..6cc6a44 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/observer/TaskClosureObserver.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/observer/TaskClosureObserver.java
@@ -4,15 +4,14 @@ import java.io.Serializable;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
 import javax.inject.Inject;
+import javax.inject.Named;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 
-import eu.reply.lea.services.masterdata.client.MasterdataServiceException;
-import eu.reply.lea.services.yard.exceptions.LoadingUnitActionException;
 import eu.reply.lea.services.yms.task.TaskReference;
 import eu.reply.lea.services.yms.task.event.LocationAwareTaskStatusChangedEventInfo;
-import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTaskApplicationService;
+import eu.reply.lea.services.yms.task.locationaware.application.LocationAwareTaskApplicationService;
 import eu.reply.lea.services.yms.util.ObjectMapperUtility;
 import eu.reply.sce.backend.core.event.ModuleEvent;
 import eu.reply.sce.backend.core.event.Observer;
@@ -29,12 +28,12 @@ public class TaskClosureObserver implements Serializable {
 
 
     @Inject
+    @Named("LocationAwareTaskApplicationService")
     private LocationAwareTaskApplicationService locationAwareTaskApplicationService;
 
 
-    public void dequeueTask(
-        @Observes @ModuleEvent("externalTaskClosedEvent") final JsonNode taskClosedEvent)
-        throws MasterdataServiceException, LoadingUnitActionException, JsonProcessingException {
+    public void onTaskClosure(
+        @Observes @ModuleEvent("externalTaskClosedEvent") final JsonNode taskClosedEvent) throws JsonProcessingException {
         LocationAwareTaskStatusChangedEventInfo payload =
             ObjectMapperUtility.getMapper().treeToValue(taskClosedEvent, LocationAwareTaskStatusChangedEventInfo.class);
         locationAwareTaskApplicationService.handleTaskClosure(new TaskReference(payload.getTaskRef()));
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/QueueProcessTracker.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/QueueProcessTracker.java
index 298b7c9..6cc1083 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/QueueProcessTracker.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/QueueProcessTracker.java
@@ -256,10 +256,6 @@ public class QueueProcessTracker extends StandardEntity {
         if (this.isEnqueueProcessPending()) {
             throw new EnqueueProcessPendingException();
         }
-
-        if (this.isDequeueProcessPending()) {
-            throw new DequeueProcessPendingException();
-        }
         ElementEnqueueProcess elementEnqueueProcess = new ElementEnqueueProcess(logisticUnitReference);
         boolean taskAdded = false;
         for (QueueRequestInfo queueRequestInfo : queueRequest.getTaskInfos()){
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/application/ExecutionAreaService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/application/ExecutionAreaService.java
index 3f59323..bcac34c 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/application/ExecutionAreaService.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/application/ExecutionAreaService.java
@@ -10,6 +10,7 @@ import javax.persistence.EntityManager;
 import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yms.task.queue.ExecutionArea;
 import eu.reply.lea.services.yms.task.queue.event.ExecutionAreaUnblockedEvent;
+import eu.reply.lea.services.yms.task.queue.repository.ExecutionAreaRepository;
 import eu.reply.sce.backend.core.entity.EntityReference;
 import eu.reply.sce.backend.core.jee.configuration.ModuleConfiguration;
 import eu.reply.sce.backend.core.jee.event.Producer;
@@ -19,9 +20,9 @@ import eu.reply.sce.backend.core.jee.log.Logged;
 @Logged
 public class ExecutionAreaService {
 
-    @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
+
     @Inject
-    private EntityManager em;
+    private ExecutionAreaRepository executionAreaRepository;
 
     @Inject
     private Producer<ExecutionAreaUnblockedEvent> executionAreaUnblockedEventProducer;
@@ -29,27 +30,19 @@ public class ExecutionAreaService {
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void createExecutionArea(final LocationReference entityReference, final int capacity) {
         ExecutionArea executionArea = new ExecutionArea(entityReference,capacity);
-        em.persist(executionArea);
+        executionAreaRepository.save(executionArea);
     }
 
 
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
-    public void unblockExecutionArea(final EntityReference entityReference){
-        ExecutionArea executionArea = em.createNamedQuery(ExecutionArea.Q_FIND_BY_LOCATION_REFERENCE, ExecutionArea.class)
-            .setParameter("locationReferenceId", entityReference.getEntityId())
-            .setParameter("locationReferenceEntityName", entityReference.getEntityName())
-            .setParameter("locationReferenceModule", entityReference.getModule())
-            .getSingleResult();
+    public void unblockExecutionArea(final LocationReference locationReference){
+        ExecutionArea executionArea = executionAreaRepository.findByLocationReference(locationReference);
         executionArea.unblock(executionAreaUnblockedEventProducer);
     }
 
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
-    public void blockExecutionArea(final EntityReference entityReference){
-        ExecutionArea executionArea = em.createNamedQuery(ExecutionArea.Q_FIND_BY_LOCATION_REFERENCE, ExecutionArea.class)
-            .setParameter("locationReferenceId", entityReference.getEntityId())
-            .setParameter("locationReferenceEntityName", entityReference.getEntityName())
-            .setParameter("locationReferenceModule", entityReference.getModule())
-            .getSingleResult();
+    public void blockExecutionArea(final LocationReference locationReference){
+        ExecutionArea executionArea = executionAreaRepository.findByLocationReference(locationReference);
         executionArea.block();
     }
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskQueueCommand.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskQueueCommand.java
new file mode 100644
index 0000000..ed9e718
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskQueueCommand.java
@@ -0,0 +1,18 @@
+package eu.reply.lea.services.yms.task.queue.event;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import eu.reply.sce.backend.core.event.ConfigurableEvent;
+
+@Getter
+@Setter
+public class TaskQueueCommand extends ConfigurableEvent<TaskQueueCommandInfo> {
+
+    private static final long serialVersionUID = 597245578267284022L;
+
+
+    public TaskQueueCommand(final TaskQueueCommandInfo payload) {
+        super(payload);
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskQueueCommandInfo.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskQueueCommandInfo.java
new file mode 100644
index 0000000..3d03a8f
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskQueueCommandInfo.java
@@ -0,0 +1,35 @@
+package eu.reply.lea.services.yms.task.queue.event;
+
+import java.io.Serializable;
+import java.time.Instant;
+import java.util.List;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import eu.reply.lea.services.masterdata.reference.LocationReference;
+import eu.reply.lea.services.yms.DomainEventInfo;
+import eu.reply.lea.services.yms.task.TaskReference;
+import eu.reply.sce.backend.core.entity.EntityReference;
+
+@NoArgsConstructor
+@Getter
+@Setter
+public class TaskQueueCommandInfo implements DomainEventInfo {
+
+    private static final long serialVersionUID = 597245578267284022L;
+
+    private EntityReference logisticUnitRef;
+    private Instant occurredOn;
+
+    public TaskQueueCommandInfo(final EntityReference logisticUnitRef) {
+        this.logisticUnitRef = logisticUnitRef;
+        this.occurredOn = Instant.now();
+    }
+
+    @Override
+    public Instant getOccurredOn() {
+        return occurredOn;
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ElementEnqueueProcessCompletenessObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ElementEnqueueProcessCompletenessObserver.java
index 90d1c45..b24fc41 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ElementEnqueueProcessCompletenessObserver.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ElementEnqueueProcessCompletenessObserver.java
@@ -30,7 +30,7 @@ public class ElementEnqueueProcessCompletenessObserver {
         LocationReference
             areaLocationReference = ObjectMapperUtility.getMapper().treeToValue(event.path("currentLocationReference"), LocationReference.class);
         elementEnqueueProcessService.confirmProcess(elementReference, areaLocationReference);
-    }
+    } //TODO guarda che no nha rollbackato!!!!
 
     public void abortProcess(@Observes @ModuleEvent("queueProcessUpdateForDequeuedEvent") final JsonNode event) throws JsonProcessingException {
         LocationReference
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaBlockedObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaBlockedObserver.java
index b085dbb..8861a64 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaBlockedObserver.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaBlockedObserver.java
@@ -8,6 +8,7 @@ import javax.inject.Inject;
 import eu.reply.lea.services.masterdata.events.map.DockBlockedEvent;
 import eu.reply.lea.services.masterdata.pojo.map.DockPojo;
 import eu.reply.lea.services.masterdata.reference.DockReference;
+import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yms.task.queue.application.ExecutionAreaService;
 import eu.reply.sce.backend.core.event.ModuleEvent;
 import eu.reply.sce.backend.core.event.Observer;
@@ -29,6 +30,6 @@ public class ExecutionAreaBlockedObserver implements Serializable {
      */
     public void onDockBlocked(@Observes @ModuleEvent(DockBlockedEvent.NAME) DockPojo dockPojo) {
         DockReference dockReference = new DockReference(dockPojo);
-        executionAreaService.blockExecutionArea(dockReference.toEntityReference());
+        executionAreaService.blockExecutionArea(new LocationReference ( dockReference.toEntityReference()));
     }
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaUnblockedObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaUnblockedObserver.java
index a4ed408..a5dbe3a 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaUnblockedObserver.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/ExecutionAreaUnblockedObserver.java
@@ -9,6 +9,7 @@ import javax.inject.Inject;
 import eu.reply.lea.services.masterdata.events.map.DockUnBlockedEvent;
 import eu.reply.lea.services.masterdata.pojo.map.DockPojo;
 import eu.reply.lea.services.masterdata.reference.DockReference;
+import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yms.task.queue.application.ExecutionAreaService;
 import eu.reply.sce.backend.core.event.ModuleEvent;
 import eu.reply.sce.backend.core.event.Observer;
@@ -31,6 +32,6 @@ public class ExecutionAreaUnblockedObserver implements Serializable {
      */
     public void onDockUnBlocked(@Observes @ModuleEvent(DockUnBlockedEvent.NAME) DockPojo dockPojo) {
         DockReference dockReference = new DockReference(dockPojo);
-        executionAreaService.unblockExecutionArea(dockReference.toEntityReference());
+        executionAreaService.unblockExecutionArea(new LocationReference(dockReference));
     }
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/InternalTasksSequenceQueueStartObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/InternalTasksSequenceQueueStartObserver.java
deleted file mode 100644
index 45e4735..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/InternalTasksSequenceQueueStartObserver.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package eu.reply.lea.services.yms.task.queue.observer;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import org.slf4j.Logger;
-
-import eu.reply.lea.services.yms.task.queue.application.QueueProcessTrackerService;
-import eu.reply.lea.services.yms.task.queue.exception.DequeueProcessPendingException;
-import eu.reply.lea.services.yms.task.queue.exception.EmptyQueueRequestException;
-import eu.reply.lea.services.yms.task.queue.exception.EnqueueProcessPendingException;
-import eu.reply.lea.services.yms.util.ObjectMapperUtility;
-import eu.reply.sce.backend.core.entity.EntityReference;
-import eu.reply.sce.backend.core.event.ModuleEvent;
-import eu.reply.sce.backend.core.event.Observer;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-
-@Observer
-@ApplicationScoped
-@Logged
-public class InternalTasksSequenceQueueStartObserver {
-
-    @Inject
-    private QueueProcessTrackerService queueProcessTrackerService;
-
-    @Inject
-    private Logger logger;
-
-
-    public void handleTransitSequenceCreatedEvent(@Observes @ModuleEvent("internalTasksSequenceCreatedEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            logisticUnitRef = ObjectMapperUtility.getMapper().treeToValue(event.path("logisticUnitRef"), EntityReference.class);
-        try{
-            queueProcessTrackerService.startNextQueueProcess(logisticUnitRef);
-        } catch (EnqueueProcessPendingException | DequeueProcessPendingException | EmptyQueueRequestException e) {
-            logger.warn(e.getMessage());
-        }
-    }
-
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/RemoveFromQueuedTasksObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/RemoveFromQueuedTasksObserver.java
deleted file mode 100644
index 8d627c2..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/RemoveFromQueuedTasksObserver.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package eu.reply.lea.services.yms.task.queue.observer;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-
-import eu.reply.lea.services.yms.task.queue.application.QueueProcessTrackerService;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
-import eu.reply.sce.backend.core.event.ModuleEvent;
-import eu.reply.sce.backend.core.event.Observer;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-
-@Observer
-@ApplicationScoped
-@Logged
-public class RemoveFromQueuedTasksObserver {
-
-    @Inject
-    private QueueProcessTrackerService queueProcessTrackerService;
-
-    public void handleTransitSequenceCreatedEvent(
-        @Observes @ModuleEvent("taskDequeueCommand") final TaskDequeueCommandInfo event) {
-        queueProcessTrackerService.startNewDequeueProcess(event.getTasks(), event
-            .getLocationReferences(), event.getLogisticUnitRef());
-    }
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/StartNewDequeueProcessObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/StartNewDequeueProcessObserver.java
new file mode 100644
index 0000000..85526ee
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/StartNewDequeueProcessObserver.java
@@ -0,0 +1,27 @@
+package eu.reply.lea.services.yms.task.queue.observer;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.queue.application.QueueProcessTrackerService;
+import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
+import eu.reply.sce.backend.core.event.ModuleEvent;
+import eu.reply.sce.backend.core.event.Observer;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+
+@Observer
+@ApplicationScoped
+@Logged
+public class StartNewDequeueProcessObserver {
+
+    @Inject
+    private QueueProcessTrackerService queueProcessTrackerService;
+
+    public void handleTransitSequenceCreatedEvent(
+        @Observes @ModuleEvent("taskDequeueCommand") final TaskDequeueCommandInfo event) {
+        queueProcessTrackerService.startNewDequeueProcess(event.getTasks(), event
+            .getLocationReferences(), event.getLogisticUnitRef());
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/StartNewQueueProcessObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/StartNewQueueProcessObserver.java
new file mode 100644
index 0000000..8088d1f
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/StartNewQueueProcessObserver.java
@@ -0,0 +1,26 @@
+package eu.reply.lea.services.yms.task.queue.observer;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.queue.application.QueueProcessTrackerService;
+import eu.reply.lea.services.yms.task.queue.event.TaskQueueCommandInfo;
+import eu.reply.sce.backend.core.event.ModuleEvent;
+import eu.reply.sce.backend.core.event.Observer;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+
+@Observer
+@ApplicationScoped
+@Logged
+public class StartNewQueueProcessObserver {
+
+    @Inject
+    private QueueProcessTrackerService queueProcessTrackerService;
+
+    public void handleTransitSequenceCreatedEvent(
+        @Observes @ModuleEvent("taskQueueCommand") final TaskQueueCommandInfo event) {
+        queueProcessTrackerService.startNextQueueProcess(event.getLogisticUnitRef());
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/TransitQueueStartObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/TransitQueueStartObserver.java
deleted file mode 100644
index c9c635e..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/TransitQueueStartObserver.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package eu.reply.lea.services.yms.task.queue.observer;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import org.slf4j.Logger;
-
-import eu.reply.lea.services.yard.reference.TransitReference;
-import eu.reply.lea.services.yms.task.event.LocationAwareTaskStatusChangedEventInfo;
-import eu.reply.lea.services.yms.task.queue.application.QueueProcessTrackerService;
-import eu.reply.lea.services.yms.task.queue.exception.DequeueProcessPendingException;
-import eu.reply.lea.services.yms.task.queue.exception.EmptyQueueRequestException;
-import eu.reply.lea.services.yms.task.queue.exception.EnqueueProcessPendingException;
-import eu.reply.lea.services.yms.util.ObjectMapperUtility;
-import eu.reply.sce.backend.core.entity.EntityReference;
-import eu.reply.sce.backend.core.event.ModuleEvent;
-import eu.reply.sce.backend.core.event.Observer;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-
-@Observer
-@ApplicationScoped
-@Logged
-public class TransitQueueStartObserver {
-
-    @Inject
-    private QueueProcessTrackerService queueProcessTrackerService;
-
-    @Inject
-    private Logger logger;
-
-
-    public void handleTransitSequenceCreatedEvent(@Observes @ModuleEvent("transitSequenceCreatedEvent") final JsonNode event)
-        throws JsonProcessingException {
-        TransitReference
-            transitReference = ObjectMapperUtility.getMapper().treeToValue(event.path("transitReference"), TransitReference.class);
-        try{
-            queueProcessTrackerService.startNextQueueProcess(transitReference.toEntityReference());
-        } catch (EnqueueProcessPendingException | DequeueProcessPendingException | EmptyQueueRequestException e) {
-            logger.warn(e.getMessage());
-        }
-    }
-
-
-    public void startNewQueueProcessAfterDequeueCompleted(
-        @Observes @ModuleEvent("elementDequeueProcessCompletedNormallyEvent") final JsonNode event) throws JsonProcessingException {
-        EntityReference
-            externalEntityReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
-        try {
-            queueProcessTrackerService.startNextQueueProcess(externalEntityReference);
-        } catch (EnqueueProcessPendingException | DequeueProcessPendingException | EmptyQueueRequestException e) {
-            logger.warn(e.getMessage());
-        }
-    }
-
-    public void handle(@Observes @ModuleEvent("checkInTaskCreatedBeforeAddressingEvent") final JsonNode event)
-        throws JsonProcessingException {
-        LocationAwareTaskStatusChangedEventInfo payload =
-            ObjectMapperUtility.getMapper().treeToValue(event, LocationAwareTaskStatusChangedEventInfo.class);
-        try{
-            queueProcessTrackerService.startNextQueueProcess(payload.getLogisticUnitRef());
-        } catch (EnqueueProcessPendingException | DequeueProcessPendingException | EmptyQueueRequestException e) {
-            logger.warn(e.getMessage());
-        }
-    }
-
-
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/repository/ExecutionAreaRepository.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/repository/ExecutionAreaRepository.java
index 325696b..1bb1930 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/repository/ExecutionAreaRepository.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/repository/ExecutionAreaRepository.java
@@ -2,10 +2,13 @@ package eu.reply.lea.services.yms.task.queue.repository;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
+import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
 
+import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yms.task.queue.ExecutionArea;
 import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.jee.configuration.ModuleConfiguration;
 import eu.reply.sce.backend.core.jee.configuration.entity.EntityReferenceHandler;
 import eu.reply.sce.backend.core.jee.log.Logged;
 
@@ -17,6 +20,10 @@ public class ExecutionAreaRepository {
     @Inject
     private EntityReferenceHandler entityReferenceHandler;
 
+    @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
+    @Inject
+    private EntityManager em;
+
 
     public ExecutionArea findByEntityReference(final EntityReference entityReference) {
         try {
@@ -25,4 +32,20 @@ public class ExecutionAreaRepository {
             return null;
         }
     }
+
+    public ExecutionArea findByLocationReference(final LocationReference locationReference) {
+        try {
+            return em.createNamedQuery(ExecutionArea.Q_FIND_BY_LOCATION_REFERENCE, ExecutionArea.class)
+                .setParameter("locationReferenceId", locationReference.getEntityId())
+                .setParameter("locationReferenceEntityName", locationReference.getEntityName())
+                .setParameter("locationReferenceModule", locationReference.getModule())
+                .getSingleResult();
+        } catch (NoResultException noResultException) {
+            return null;
+        }
+    }
+
+    public void save(ExecutionArea executionArea) {
+        em.persist(executionArea);
+    }
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java
index 78c7c31..d497b07 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java
@@ -4,6 +4,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import javax.persistence.AttributeOverride;
 import javax.persistence.AttributeOverrides;
@@ -24,6 +26,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import eu.reply.lea.services.masterdata.reference.LocationReference;
+import eu.reply.lea.services.process.task.entities.TaskStatus;
 import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
 import eu.reply.sce.backend.core.entity.EntityReference;
 import eu.reply.sce.backend.core.entity.StringCustomizableEntity;
@@ -118,7 +121,7 @@ public abstract class AbstractTasksSequence extends StringCustomizableEntity
 
     @Override
     @JsonIgnore
-    public List<LocationAwareTask<?, ?, ?>> getQueueableTasks() {
+    public List<LocationAwareTask<?, ?, ?>> getToBeQueuedTasks() {
         List<LocationAwareTask<?, ?, ?>> sortedSequence = getSortedSequence();
         return getQueueableTasks(sortedSequence, 0, true);
     }
@@ -131,13 +134,22 @@ public abstract class AbstractTasksSequence extends StringCustomizableEntity
 
     @Override
     @JsonIgnore
+    public List<LocationAwareTask<?, ?, ?>> getAllTasksContiguousInTheLocationClosed(final LocationAwareTask<?, ?, ?> task, final boolean enableQueue) {
+        //The input has to be the tasks
+        return getTasksSameLocationContiguously(task, false).stream().filter(t -> t.getHeaders().isEnableQueue()).collect(
+            Collectors.toList());
+    }
+
+    @Override
+    @JsonIgnore
     public List<LocationAwareTask<?, ?, ?>> getTasksSameLocationContiguously(final LocationAwareTask<?, ?, ?> task,
-                                                                             final boolean queueable) {
+                                                                             final boolean toBeQueued) {
         LocationReference location = task.getLocation();
-        List<LocationAwareTask<?, ?, ?>> tasksSameLocation = sortTasks(getTasksInLocation(location, queueable));
+        Objects.requireNonNull(location);
+        List<LocationAwareTask<?, ?, ?>> tasksSameLocation = sortTasks(getTasksInLocation(location, toBeQueued));
         List<LocationAwareTask<?, ?, ?>> result = new ArrayList<>();
         if (tasksSameLocation.isEmpty()) {
-            throw new IllegalStateException(String.format("There are no tasks in the location %s", location));
+            throw new IllegalStateException(String.format("There are no tasks toBeQueued: %b in the location %s", toBeQueued, location));
         }
         if (tasksSameLocation.stream().noneMatch(t->t.equals(task))) {
             throw new IllegalStateException(String.format("It was not possible to find the tasks among"
@@ -169,19 +181,39 @@ public abstract class AbstractTasksSequence extends StringCustomizableEntity
 
 
     @JsonIgnore
-    public List<LocationAwareTask<?, ?, ?>> getTasksInLocation(final LocationReference location, final boolean queueable) {
+    public List<LocationAwareTask<?, ?, ?>> getTasksInLocation(final LocationReference location, final boolean toBeQueued) {
+        Objects.requireNonNull(location);
         List<LocationAwareTask<?, ?, ?>> tasksToFilter;
-        if (queueable){
-            tasksToFilter = this.getQueueableTasks();
+        if (toBeQueued){
+            tasksToFilter = this.getToBeQueuedTasks();
         }else{
             tasksToFilter = this.getTasks();
         }
         return tasksToFilter.stream()
-            .filter(task -> location.equals(task.getLocation()))
+            .filter(task -> task.getLocation() != null && location.equals(task.getLocation()))
+            .collect(Collectors.toList());
+    }
+
+    @Override
+    @JsonIgnore
+    public LocationAwareTask<?,?,?> getNextBlockedTask() {
+        return getOrderedTasksThatMatch( t -> (t.getStatus() == TaskStatus.BLOCKED)).stream().findFirst().orElse(null);
+    }
+
+    protected List<LocationAwareTask<?,?,?>>  getOrderedTasksThatMatch(final Predicate<LocationAwareTask<?,?,?>> taskPredicate) {
+
+        final List<LocationAwareTask<?,?,?>> sortedList = getSortedSequence();
+        return sortedList.stream()
+            .filter(taskPredicate)
             .collect(Collectors.toList());
     }
 
     @Override
+    public boolean areThereTasksInExecution(){
+        return this.getTasks().stream().anyMatch(t -> t.isInExecutingArea());
+    }
+
+    @Override
     public List<LocationAwareTask<?, ?, ?>> sortTasks(final List<LocationAwareTask<?, ?, ?>> tasks) {
         return tasks.stream().sorted(Comparator.comparing(LocationAwareTask::getSequenceNumber)).collect(Collectors.toList());
     }
@@ -189,4 +221,26 @@ public abstract class AbstractTasksSequence extends StringCustomizableEntity
     boolean isSequenceNumberContiguous(int previousSequenceNumber, int currentSequenceNumber) {
         return currentSequenceNumber == previousSequenceNumber || currentSequenceNumber == previousSequenceNumber + 1;
     }
+
+    public LocationAwareTask<?,?,?> getNextTask(final LocationAwareTask<?,?,?> task,final Predicate<LocationAwareTask<?,?,?>> taskPredicate) {
+
+        List<LocationAwareTask<?,?,?>> nextTasks = getNextTasks(task, taskPredicate);
+        return (nextTasks.isEmpty()?null:nextTasks.get(0));
+    }
+
+
+    public List<LocationAwareTask<?,?,?>> getNextTasks(final LocationAwareTask<?,?,?> task,final Predicate<LocationAwareTask<?,?,?>> taskPredicate) {
+
+        final List<LocationAwareTask<?,?,?>> sortedList = getSortedSequence();
+
+        final int startIndex = task.getSequenceNumber();
+        if (startIndex >= 0 && startIndex < sortedList.size() - 1 && sortedList.contains(task)) {
+            return sortedList.subList(startIndex + 1, sortedList.size()).stream()
+                .filter(taskPredicate)
+                .collect(Collectors.toList());
+        } else {
+            return new ArrayList<>();
+        }
+    }
+
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/DefaultTaskInSequenceAdvancementStrategy.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/DefaultTaskInSequenceAdvancementStrategy.java
new file mode 100644
index 0000000..e3aaf22
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/DefaultTaskInSequenceAdvancementStrategy.java
@@ -0,0 +1,31 @@
+package eu.reply.lea.services.yms.task.sequence;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTaskHandler;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskQueueService;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class DefaultTaskInSequenceAdvancementStrategy implements TaskInSequenceAdvancementStrategy {
+
+    @Inject
+    private LocationAwareTaskHandler taskHandler;
+
+    @Inject
+    private TaskQueueService taskQueueService;
+
+    @Override
+    public boolean advanceTaskInSequence(LocationAwareTask<?, ?, ?> task) {
+        if (task.getHeaders().isEnableQueue() && !taskQueueService.isTaskQueued(task)){
+            taskQueueService.queueTasks(task.getLogisticUnitReference());
+        }else{
+            return taskHandler.unlockTask(task);
+        }
+        return false;
+    }
+
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequence.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequence.java
index 1cebae3..846bf45 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequence.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequence.java
@@ -39,7 +39,7 @@ public class InternalTasksSequence extends AbstractTasksSequence {
     @JsonIgnore
     @Override
     public List<LocationAwareTask<?, ?, ?>> getTasksToBeEnqueuedNext() {
-        List<LocationAwareTask<?, ?, ?>> queueableTasks = getQueueableTasks();
+        List<LocationAwareTask<?, ?, ?>> queueableTasks = getToBeQueuedTasks();
         if (queueableTasks.isEmpty()) {
             return Collections.emptyList();
         }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceService.java
index 6655554..6874ee0 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceService.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceService.java
@@ -18,7 +18,7 @@ public class InternalTasksSequenceService {
     private InternalTasksSequenceRepository internalTasksSequenceRepository;
 
     @Inject
-    private InternalTasksSequenceHandler internalTasksSequenceHandler;
+    private TaskSequenceAdvancementService taskSequenceAdvancementService;
 
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void lockSequence(final EntityReference logisticUnitReference) {
@@ -38,7 +38,7 @@ public class InternalTasksSequenceService {
     public void unlockNextTask(final EntityReference logisticUnitReference) {
         InternalTasksSequence
             internalTasksSequence = internalTasksSequenceRepository.findByLogisticUnitReference(logisticUnitReference);
-        internalTasksSequenceHandler.unlockNextTask(internalTasksSequence);
+        taskSequenceAdvancementService.advanceTaskInSequence(internalTasksSequence);
     }
 
 
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceTaskUnlockObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceTaskUnlockObserver.java
deleted file mode 100644
index 84a8ac6..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/InternalTasksSequenceTaskUnlockObserver.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package eu.reply.lea.services.yms.task.sequence;
-
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-
-import eu.reply.lea.services.yard.model.Transit;
-import eu.reply.lea.services.yms.util.ObjectMapperUtility;
-import eu.reply.sce.backend.core.entity.EntityReference;
-import eu.reply.sce.backend.core.event.ModuleEvent;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-@ApplicationScoped
-@Logged
-public class InternalTasksSequenceTaskUnlockObserver {
-
-
-    @Inject
-    private InternalTasksSequenceService internalTasksSequenceService;
-
-    public void handleUnlockOfTaskAfterEnqueueCompleted(
-        @Observes @ModuleEvent("elementEnqueueProcessCompletedNormallyEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            externalEntityReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
-        if(!externalEntityReference.getEntityName().equals(Transit.RESOURCE_NAME)){
-            internalTasksSequenceService.unlockNextTask(externalEntityReference);
-        }
-    }
-
-    public void handleUnlockOfTaskAfterDequeueCompleted(
-        @Observes @ModuleEvent("elementDequeueProcessCompletedNormallyEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            externalEntityReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
-        if(!externalEntityReference.getEntityName().equals(Transit.RESOURCE_NAME)){
-            internalTasksSequenceService.unlockNextTask(externalEntityReference);
-        }
-    }
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java
index 1614d76..fb0bd06 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java
@@ -1,6 +1,9 @@
 package eu.reply.lea.services.yms.task.sequence;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
@@ -51,23 +54,26 @@ public interface LocationAwareTasksSequence<I extends SequencedLocationAwareTask
      *
      * @return list of queueable tasks
      */
-    List<I> getQueueableTasks();
+    List<I> getToBeQueuedTasks();
 
     /**
      * Determines if all tasks to be executed contiguously starting from the given task are closed.
      *
      * @param task@return true if all contiguous tasks are closed; false otherwise
      */
-    boolean areAllTasksContiguousInTheLocationClosed(final LocationAwareTask<?, ?, ?> task);
+    boolean areAllTasksContiguousInTheLocationClosed(final I task);
+
+    List<I> getAllTasksContiguousInTheLocationClosed(I task,
+                                                                              boolean enableQueue);
 
     /**
      * Retrieves the list of tasks to be executed contiguously starting from the given task.
      *
      * @param task       the starting task
-     * @param queuable
+     * @param toBeQueued
      * @return list of contiguous tasks
      */
-    List<I> getTasksSameLocationContiguously(I task, final boolean queuable);
+    List<I> getTasksSameLocationContiguously(I task, final boolean toBeQueued);
 
     /**
      * Retrieves the tasks associated with the specified location.
@@ -78,11 +84,19 @@ public interface LocationAwareTasksSequence<I extends SequencedLocationAwareTask
      */
     List<I> getTasksInLocation(final LocationReference location, final boolean queueable);
 
+    I getNextBlockedTask();
+
+    boolean areThereTasksInExecution();
+
     /**
      * Sorts the given list of tasks by their sequence number.
      *
      * @param tasks the list of tasks to sort
      * @return sorted list of tasks
      */
-    List<LocationAwareTask<?, ?, ?>> sortTasks(List<LocationAwareTask<?, ?, ?>> tasks);
+    List<I> sortTasks(List<I> tasks);
+
+    public I getNextTask(final I task, final Predicate<I> taskPredicate);
+
+    public List<I> getNextTasks(final I task,final Predicate<I> taskPredicate);
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java
index 5a37680..b60a647 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java
@@ -40,17 +40,6 @@ public abstract class LocationAwareTasksSequenceHandler extends AbstractTasksSeq
     }
 
     
-    public Boolean unlockNextTask(LocationAwareTasksSequence<LocationAwareTask<?,?,?>> tasksSequence) {
-        if (tasksSequence.isBlocked()){
-            return false;
-        }
-        LocationAwareTask<?,?,?> task = getNextBlockedTask(tasksSequence);
-        if (task == null) {
-            return false;
-        }
-        return locationAwareTaskHandler.unlockTask(task);
-    }
-    
     /**
      * Returns the last Task that was closed.
      *
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/MissionTaskInSequenceAdvancementStrategy.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/MissionTaskInSequenceAdvancementStrategy.java
new file mode 100644
index 0000000..ec985d1
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/MissionTaskInSequenceAdvancementStrategy.java
@@ -0,0 +1,46 @@
+package eu.reply.lea.services.yms.task.sequence;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTaskHandler;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskQueueService;
+import eu.reply.lea.services.yms.task.locationaware.domain.mission.MissionTask;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class MissionTaskInSequenceAdvancementStrategy implements TaskInSequenceAdvancementStrategy {
+
+    @Inject
+    private LocationAwareTaskHandler taskHandler;
+
+    @Inject
+    private TaskQueueService taskQueueService;
+
+    @Override
+    public boolean advanceTaskInSequence(LocationAwareTask<?, ?, ?> task) {
+        if (!(task instanceof MissionTask)) {
+            throw new IllegalArgumentException("Expected MissionTask");
+        }
+        MissionTask missionTask = (MissionTask) task;
+
+        if (missionTask.getHeaders() != null
+                && missionTask.getHeaders().isEnableQueue()
+                && !taskQueueService.isTaskQueued(task)) {
+            taskQueueService.queueTasks(task.getLogisticUnitReference());
+            return false;
+        }//TODO else{
+
+        LocationAwareTasksSequence<LocationAwareTask<?,?,?>> sequence = missionTask.getSequence();
+        LocationAwareTask<?,?,?> nextQueueTask = sequence.getNextTask(missionTask, t ->  t.getHeaders().isEnableQueue());
+        if (nextQueueTask!=null
+           && !taskQueueService.isTaskQueued(nextQueueTask)) {
+            taskQueueService.queueTasks(task.getLogisticUnitReference());
+            return false;
+        }else{
+            return taskHandler.unlockTask(task);
+        }
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TaskInSequenceAdvancementStrategy.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TaskInSequenceAdvancementStrategy.java
new file mode 100644
index 0000000..f78c9f8
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TaskInSequenceAdvancementStrategy.java
@@ -0,0 +1,7 @@
+package eu.reply.lea.services.yms.task.sequence;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+
+public interface TaskInSequenceAdvancementStrategy {
+    boolean advanceTaskInSequence(LocationAwareTask<?, ?, ?> task);
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TaskSequenceAdvancementService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TaskSequenceAdvancementService.java
new file mode 100644
index 0000000..e0267dd
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TaskSequenceAdvancementService.java
@@ -0,0 +1,70 @@
+package eu.reply.lea.services.yms.task.sequence;
+
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+
+import eu.reply.lea.services.yms.task.TaskType;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class TaskSequenceAdvancementService {
+
+    @Inject
+    private MissionTaskInSequenceAdvancementStrategy missionTaskUnlockStrategy;
+
+    @Inject
+    private DefaultTaskInSequenceAdvancementStrategy defaultTaskUnlockStrategy;
+
+
+    private Map<TaskType, TaskInSequenceAdvancementStrategy> strategyMap;
+
+    @Inject
+    private Logger log;
+
+    @PostConstruct
+    public void init() {
+        strategyMap = new HashMap<>();
+        strategyMap.put(TaskType.MISSION, missionTaskUnlockStrategy);
+        // Add other task types if needed, or use default for all others
+    }
+
+
+    public Boolean advanceTaskInSequence(LocationAwareTasksSequence<LocationAwareTask<?,?,?>> tasksSequence) {
+        if (tasksSequence.isBlocked()){
+            log.info("unlock next task: Task sequence is blocked {}", tasksSequence);
+            return false;
+        }
+        if (tasksSequence.areThereTasksInExecution()){
+            log.info("unlock next task: There are tasks in execution {}", tasksSequence);
+            return false;
+        }
+        LocationAwareTask<?,?,?> task = tasksSequence.getNextBlockedTask();
+        if (task == null) {
+            log.info("No Blocked Tasks found: {}", task);
+            return false;
+        }
+
+        TaskInSequenceAdvancementStrategy strategy = strategyMap.getOrDefault(task.getTaskType(), defaultTaskUnlockStrategy);
+        boolean result = strategy.advanceTaskInSequence(task);
+
+        if (result) {
+            log.info("Task processed successfully: {}", task);
+        } else {
+            log.info("Task could not be processed: {}", task);
+        }
+
+        return result;
+    }
+
+
+
+
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TasksSequenceHandlerFactory.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TasksSequenceHandlerFactory.java
new file mode 100644
index 0000000..215a560
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TasksSequenceHandlerFactory.java
@@ -0,0 +1,7 @@
+package eu.reply.lea.services.yms.task.sequence;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+
+public interface TasksSequenceHandlerFactory {
+    LocationAwareTasksSequenceHandler createHandler(LocationAwareTasksSequence<LocationAwareTask<?,?,?>> tasksSequence);
+}
\ No newline at end of file
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TasksSequenceHandlerFactoryImpl.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TasksSequenceHandlerFactoryImpl.java
new file mode 100644
index 0000000..77f6b3b
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TasksSequenceHandlerFactoryImpl.java
@@ -0,0 +1,26 @@
+package eu.reply.lea.services.yms.task.sequence;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+
+@ApplicationScoped
+public class TasksSequenceHandlerFactoryImpl implements TasksSequenceHandlerFactory {
+
+    @Inject
+    private Instance<InternalTasksSequenceHandler> internalHandler;
+
+    @Inject
+    private Instance<TransitTasksSequenceHandler> transitHandler;
+
+    public LocationAwareTasksSequenceHandler createHandler(LocationAwareTasksSequence<LocationAwareTask<?,?,?>> tasksSequence) {
+        if (tasksSequence instanceof InternalTasksSequence) {
+            return internalHandler.get();
+        } else if (tasksSequence instanceof TransitTasksSequence) {
+            return transitHandler.get();
+        }
+        throw new IllegalArgumentException("Unsupported task sequence: " + tasksSequence);
+    }
+}
\ No newline at end of file
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequence.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequence.java
index 4dd2d12..3dfe567 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequence.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequence.java
@@ -172,7 +172,7 @@ public class TransitTasksSequence extends AbstractTasksSequence  {
     @JsonIgnore
     @Override
     public List<LocationAwareTask<?,?,?>> getTasksToBeEnqueuedNext(){
-        List<LocationAwareTask<?,?,?>> taskList = getQueueableTasks();
+        List<LocationAwareTask<?,?,?>> taskList = getToBeQueuedTasks();
         ArrayList<LocationAwareTask<?, ?, ?>> taskToBeEnqueuedNext = new ArrayList<>();
         if (taskList.isEmpty()){
             return taskToBeEnqueuedNext;
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceHandler.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceHandler.java
index cfc7937..6ac49a3 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceHandler.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceHandler.java
@@ -66,17 +66,6 @@ public class TransitTasksSequenceHandler extends LocationAwareTasksSequenceHandl
 
 
     /**
-     * Check if the transit is busy in a task.
-     *
-     * @param transitTasksSequence
-     * @return true if it is busy in a task, false otherwise
-     */
-    public Boolean isTransitBusy(TasksSequence<LocationAwareTask<?,?,?>> transitTasksSequence) {
-        return !transitTasksSequence.getTasks().stream().filter(t -> t.isInExecutingArea()).collect(Collectors.toList()).isEmpty();
-    }
-
-
-    /**
      * Get RegistrationTask from a sequence of specific transitReference.
      *
      * @param transitReference Reference of a Transit.
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceService.java
index e4079f3..9d435c2 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceService.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceService.java
@@ -18,7 +18,7 @@ public class TransitTasksSequenceService {
     private TransitTasksSequenceRepository transitTasksSequenceRepository;
 
     @Inject
-    private TransitTasksSequenceHandler transitTasksSequenceHandler;
+    private TaskSequenceAdvancementService taskSequenceAdvancementService;
 
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void lockSequence(final TransitReference transitReference) {
@@ -39,7 +39,7 @@ public class TransitTasksSequenceService {
     public void unlockNextTask(final TransitReference transitReference) {
         TransitTasksSequence
             transitTasksSequence = transitTasksSequenceRepository.findByTransitRef(transitReference);
-        transitTasksSequenceHandler.unlockNextTask(transitTasksSequence);
+        taskSequenceAdvancementService.advanceTaskInSequence(transitTasksSequence);
     }
 
 }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceTaskUnlockObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceTaskUnlockObserver.java
deleted file mode 100644
index d446bd7..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/TransitTasksSequenceTaskUnlockObserver.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package eu.reply.lea.services.yms.task.sequence;
-
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-
-import eu.reply.lea.services.yard.model.Transit;
-import eu.reply.lea.services.yard.reference.TransitReference;
-import eu.reply.lea.services.yms.util.ObjectMapperUtility;
-import eu.reply.sce.backend.core.entity.EntityReference;
-import eu.reply.sce.backend.core.event.ModuleEvent;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-@ApplicationScoped
-@Logged
-public class TransitTasksSequenceTaskUnlockObserver {
-
-
-    @Inject
-    private TransitTasksSequenceService transitTasksSequenceService;
-
-    public void handleUnlockOfTaskAfterEnqueueCompleted(
-        @Observes @ModuleEvent("elementEnqueueProcessCompletedNormallyEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            transitReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
-        if(transitReference.getEntityName().equals(Transit.RESOURCE_NAME)){
-            transitTasksSequenceService.unlockNextTask(new TransitReference(transitReference));
-        }
-    }
-
-    public void handleUnlockOfTaskAfterDequeueCompleted(
-        @Observes @ModuleEvent("elementDequeueProcessCompletedNormallyEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            transitReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
-        if(transitReference.getEntityName().equals(Transit.RESOURCE_NAME)){
-            transitTasksSequenceService.unlockNextTask(new TransitReference(transitReference));
-        }
-    }
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/observer/InternalTasksSequenceTaskUnlockObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/observer/InternalTasksSequenceTaskUnlockObserver.java
new file mode 100644
index 0000000..b34d20d
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/observer/InternalTasksSequenceTaskUnlockObserver.java
@@ -0,0 +1,49 @@
+package eu.reply.lea.services.yms.task.sequence.observer;
+
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import eu.reply.lea.services.masterdata.reference.LocationReference;
+import eu.reply.lea.services.yard.model.Transit;
+import eu.reply.lea.services.yard.reference.LoadingUnitReference;
+import eu.reply.lea.services.yms.task.event.MissionTaskHookedEventInfo;
+import eu.reply.lea.services.yms.task.sequence.InternalTasksSequenceService;
+import eu.reply.lea.services.yms.util.ObjectMapperUtility;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.entity.JsonNodeUtils;
+import eu.reply.sce.backend.core.event.ModuleEvent;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class InternalTasksSequenceTaskUnlockObserver {
+
+
+    @Inject
+    private InternalTasksSequenceService internalTasksSequenceService;
+
+    public void handleUnlockOfTaskAfterEnqueueCompleted(
+        @Observes @ModuleEvent("elementEnqueueProcessCompletedNormallyEvent") final JsonNode event)
+        throws JsonProcessingException {
+        EntityReference
+            externalEntityReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
+        if(!externalEntityReference.getEntityName().equals(Transit.RESOURCE_NAME)){
+            internalTasksSequenceService.unlockNextTask(externalEntityReference);
+        }
+    }
+
+
+    public void handleInternalTaskSequenceCreatedEvent(@Observes @ModuleEvent("internalTasksSequenceCreatedEvent") final JsonNode event)
+        throws JsonProcessingException {
+        EntityReference
+            logisticUnitRef = ObjectMapperUtility.getMapper().treeToValue(event.path("logisticUnitRef"), EntityReference.class);
+        if(!logisticUnitRef.getEntityName().equals(Transit.RESOURCE_NAME)){
+            internalTasksSequenceService.unlockNextTask(logisticUnitRef);
+        }
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/observer/TransitTasksSequenceTaskUnlockObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/observer/TransitTasksSequenceTaskUnlockObserver.java
new file mode 100644
index 0000000..a8e10d2
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/observer/TransitTasksSequenceTaskUnlockObserver.java
@@ -0,0 +1,54 @@
+package eu.reply.lea.services.yms.task.sequence.observer;
+
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import eu.reply.lea.services.yard.model.Transit;
+import eu.reply.lea.services.yard.reference.TransitReference;
+import eu.reply.lea.services.yms.task.event.LocationAwareTaskStatusChangedEventInfo;
+import eu.reply.lea.services.yms.task.queue.exception.DequeueProcessPendingException;
+import eu.reply.lea.services.yms.task.queue.exception.EmptyQueueRequestException;
+import eu.reply.lea.services.yms.task.queue.exception.EnqueueProcessPendingException;
+import eu.reply.lea.services.yms.task.sequence.TransitTasksSequenceService;
+import eu.reply.lea.services.yms.util.ObjectMapperUtility;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.event.ModuleEvent;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class TransitTasksSequenceTaskUnlockObserver {
+
+
+    @Inject
+    private TransitTasksSequenceService transitTasksSequenceService;
+
+    public void handleUnlockOfTaskAfterEnqueueCompleted(
+        @Observes @ModuleEvent("elementEnqueueProcessCompletedNormallyEvent") final JsonNode event)
+        throws JsonProcessingException {
+        EntityReference
+            transitReference = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
+        if(transitReference.getEntityName().equals(Transit.RESOURCE_NAME)){
+            transitTasksSequenceService.unlockNextTask(new TransitReference(transitReference));
+        }
+    }
+
+    public void handleTransitSequenceCreatedEvent(@Observes @ModuleEvent("transitSequenceCreatedEvent") final JsonNode event)
+        throws JsonProcessingException {
+        TransitReference
+            transitReference = ObjectMapperUtility.getMapper().treeToValue(event.path("transitReference"), TransitReference.class);
+        transitTasksSequenceService.unlockNextTask(transitReference);
+    }
+
+    public void handle(@Observes @ModuleEvent("checkInTaskCreatedBeforeAddressingEvent") final JsonNode event)
+        throws JsonProcessingException {
+        LocationAwareTaskStatusChangedEventInfo payload =
+            ObjectMapperUtility.getMapper().treeToValue(event, LocationAwareTaskStatusChangedEventInfo.class);
+        transitTasksSequenceService.unlockNextTask(new TransitReference(payload.getLogisticUnitRef()));
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitLocationTrackerService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitLocationTrackerService.java
index 53d35dc..50f265d 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitLocationTrackerService.java
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitLocationTrackerService.java
@@ -5,8 +5,11 @@ import javax.ejb.TransactionAttribute;
 import javax.ejb.TransactionAttributeType;
 import javax.inject.Inject;
 
+import org.slf4j.Logger;
+
 import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yms.task.tracking.event.LogisticUnitLocationUpdateCommand;
+import eu.reply.lea.services.yms.task.tracking.integration.yms.queue.QueueingStatusDTO;
 import eu.reply.sce.backend.core.entity.EntityReference;
 import eu.reply.sce.backend.core.jee.event.Producer;
 
@@ -24,6 +27,12 @@ public class LogisticUnitLocationTrackerService {
     @Inject
     private NextTaskProvider nextTaskProvider;
 
+    @Inject
+    private LogisticUnitService logisticUnitService;
+
+    @Inject
+    private Logger log;
+
     /**
      * Updates the location of a logistic unit with the provided queueing status.
      *
@@ -33,6 +42,10 @@ public class LogisticUnitLocationTrackerService {
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void updateLocation(final EntityReference logisticUnitRef,
                                final QueueingStatusDTO queueingStatusDTO) {
+        if ( !logisticUnitService.canMoveAutonomously(logisticUnitRef)) {
+            log.info("Returning from updateLocation because can't move autonomously {}", logisticUnitRef);
+            return;
+        }
         LogisticsUnitLocationTracker
             logisticsUnitLocationTracker = logisticUnitLocationTrackerRepository.getOrCreateLogisticUnitLocationTracker(logisticUnitRef);
         Optional<LocationReference> optionalNextLocation = nextTaskProvider.getNextLocation(logisticUnitRef);
@@ -57,12 +70,16 @@ public class LogisticUnitLocationTrackerService {
 
 
     /**
-     * Commands a transit operation to update the loading unit's position to its next execution location.
+     * Commands a logistic unit operation to update the loading unit's position to its next execution location.
      *
      * @param logisticUnitRef the reference of the logistic unit
      */
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
-    public void commandTransitToUpdateLoadingUnitPosition(final EntityReference logisticUnitRef) {
+    public void commandToUpdateLoadingUnitPosition(final EntityReference logisticUnitRef) {
+        if ( !logisticUnitService.canMoveAutonomously(logisticUnitRef)) {
+            log.info("Returning from commandToUpdateLoadingUnitPosition because can't move autonomously {}", logisticUnitRef);
+            return;
+        }
         Optional<LocationReference> optionalNextLocation = nextTaskProvider.getNextLocation(logisticUnitRef);
 
         if (optionalNextLocation.isEmpty()) {
@@ -70,14 +87,12 @@ public class LogisticUnitLocationTrackerService {
         }
         LocationReference nextLocation = optionalNextLocation.get();
 
-        // Get the TransitLocationTracker
         LogisticsUnitLocationTracker
             logisticsUnitLocationTracker = logisticUnitLocationTrackerRepository.findByLogisticUnitReference(logisticUnitRef);
 
         // Update the next execution location
         logisticsUnitLocationTracker.updateNextExecutionLocation(nextLocation);
 
-        // Command transit to update location
         Optional<LogisticUnitLocationUpdateCommand> updateCommand = logisticsUnitLocationTracker.generateCommandToUpdateLocation();
         updateCommand.ifPresent(logisticUnitLocationUpdateCommandProducer::fire);
     }
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitService.java
new file mode 100644
index 0000000..59accd8
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/LogisticUnitService.java
@@ -0,0 +1,8 @@
+package eu.reply.lea.services.yms.task.tracking;
+
+import eu.reply.sce.backend.core.entity.EntityReference;
+
+public interface LogisticUnitService {
+
+    public boolean canMoveAutonomously(EntityReference entityReference);
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/QueueingStatusDTO.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/QueueingStatusDTO.java
deleted file mode 100644
index a97ad24..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/QueueingStatusDTO.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package eu.reply.lea.services.yms.task.tracking;
-
-import java.time.Instant;
-
-import lombok.Getter;
-
-import eu.reply.lea.services.masterdata.reference.LocationReference;
-
-@Getter
-public class QueueingStatusDTO {
-
-    private final LocationReference currentLocationRef;
-    private final AreaType currentLocationAreaType;
-    private final LocationReference executionLocationRef;
-    private final Instant eventInstant;
-
-    public QueueingStatusDTO(final LocationReference executionLocationRef, final LocationReference currentLocationRef,
-                             final AreaType currentLocationAreaType,
-                             final Instant eventInstant) {
-        this.currentLocationRef = currentLocationRef;
-        this.executionLocationRef = executionLocationRef;
-        this.currentLocationAreaType = currentLocationAreaType;
-        this.eventInstant = eventInstant;
-    }
-}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yard/LogisticUnitPolicy.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yard/LogisticUnitPolicy.java
new file mode 100644
index 0000000..fcf59e0
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yard/LogisticUnitPolicy.java
@@ -0,0 +1,19 @@
+package eu.reply.lea.services.yms.task.tracking.integration.yard;
+
+import javax.enterprise.context.ApplicationScoped;
+import java.util.Set;
+
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class LogisticUnitPolicy {
+
+    private static final Set<String> NON_AUTONOMOUS_LOGISTIC_UNIT_NAMES = Set.of("ContainerResource", "TrailerResource");
+    
+    public boolean canMoveAutonomously(EntityReference logisticUnitRef) {
+        String entityName = logisticUnitRef.getEntityName();
+        return !NON_AUTONOMOUS_LOGISTIC_UNIT_NAMES.contains(entityName);
+    }
+}
\ No newline at end of file
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yard/LogisticUnitServiceImpl.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yard/LogisticUnitServiceImpl.java
new file mode 100644
index 0000000..db19a7c
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yard/LogisticUnitServiceImpl.java
@@ -0,0 +1,21 @@
+package eu.reply.lea.services.yms.task.tracking.integration.yard;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.yms.task.tracking.LogisticUnitService;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@ApplicationScoped
+@Logged
+public class LogisticUnitServiceImpl implements LogisticUnitService {
+
+    @Inject
+    private LogisticUnitPolicy logisticUnitPolicy;
+
+    @Override
+    public boolean canMoveAutonomously(final EntityReference entityReference) {
+        return logisticUnitPolicy.canMoveAutonomously(entityReference);
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yms/queue/QueueingStatusDTO.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yms/queue/QueueingStatusDTO.java
new file mode 100644
index 0000000..35c724c
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yms/queue/QueueingStatusDTO.java
@@ -0,0 +1,26 @@
+package eu.reply.lea.services.yms.task.tracking.integration.yms.queue;
+
+import java.time.Instant;
+
+import lombok.Getter;
+
+import eu.reply.lea.services.masterdata.reference.LocationReference;
+import eu.reply.lea.services.yms.task.tracking.AreaType;
+
+@Getter
+public class QueueingStatusDTO {
+
+    private final LocationReference currentLocationRef;
+    private final AreaType currentLocationAreaType;
+    private final LocationReference executionLocationRef;
+    private final Instant eventInstant;
+
+    public QueueingStatusDTO(final LocationReference executionLocationRef, final LocationReference currentLocationRef,
+                             final AreaType currentLocationAreaType,
+                             final Instant eventInstant) {
+        this.currentLocationRef = currentLocationRef;
+        this.executionLocationRef = executionLocationRef;
+        this.currentLocationAreaType = currentLocationAreaType;
+        this.eventInstant = eventInstant;
+    }
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yms/queue/observer/QueueChangesObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yms/queue/observer/QueueChangesObserver.java
new file mode 100644
index 0000000..a3e2a19
--- /dev/null
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/integration/yms/queue/observer/QueueChangesObserver.java
@@ -0,0 +1,62 @@
+package eu.reply.lea.services.yms.task.tracking.integration.yms.queue.observer;
+
+import java.time.Instant;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import eu.reply.lea.services.masterdata.reference.LocationReference;
+import eu.reply.lea.services.yms.task.tracking.AreaType;
+import eu.reply.lea.services.yms.task.tracking.LogisticUnitLocationTrackerService;
+import eu.reply.lea.services.yms.task.tracking.integration.yms.queue.QueueingStatusDTO;
+import eu.reply.lea.services.yms.util.ObjectMapperUtility;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.event.ModuleEvent;
+import eu.reply.sce.backend.core.event.Observer;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+
+@Observer
+@ApplicationScoped
+@Logged
+public class QueueChangesObserver {
+
+    @Inject
+    private LogisticUnitLocationTrackerService logisticUnitLocationTrackerService;
+
+
+    public void handleUpdateLocationTrackingInfo(
+        @Observes @ModuleEvent("elementChangedAreaEvent") final JsonNode event)
+        throws JsonProcessingException {
+        EntityReference
+            logisticUnitRef = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
+        Instant
+            eventInstant = Instant.parse(ObjectMapperUtility.getMapper().treeToValue(event.path("eventInstant"), String.class));
+        String
+            areaType = ObjectMapperUtility.getMapper().treeToValue(event.path("areaType"), String.class);
+        LocationReference
+            currentLocationReference = ObjectMapperUtility.getMapper().treeToValue(event.path("currentLocationReference"), LocationReference.class);
+        LocationReference
+            executionLocationReference = ObjectMapperUtility.getMapper().treeToValue(event.path("executionLocationReference"), LocationReference.class);
+        QueueingStatusDTO queueingStatus =
+            new QueueingStatusDTO(executionLocationReference, currentLocationReference, areaTypeConverter(areaType), eventInstant);
+        logisticUnitLocationTrackerService.updateLocation(logisticUnitRef, queueingStatus);
+
+    }
+
+    public void updatePositionAfterDequeuedEvent(@Observes @ModuleEvent("updatePositionAfterDequeuedEvent") final JsonNode event)
+        throws JsonProcessingException {
+        EntityReference
+            logisticUnitRef = ObjectMapperUtility.getMapper().treeToValue(event.path("queuedExternalEntityRef"), EntityReference.class);
+        logisticUnitLocationTrackerService.commandToUpdateLoadingUnitPosition(logisticUnitRef);
+    }
+
+    private AreaType areaTypeConverter(String areaType){
+        return AreaType.valueOf(areaType);
+    }
+
+
+}
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/observer/LogisticUnitLocationTrackerObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/observer/LogisticUnitLocationTrackerObserver.java
deleted file mode 100644
index 8d37fbd..0000000
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/tracking/observer/LogisticUnitLocationTrackerObserver.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package eu.reply.lea.services.yms.task.tracking.observer;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-
-import java.time.Instant;
-
-import eu.reply.lea.services.masterdata.reference.LocationReference;
-import eu.reply.lea.services.yms.task.tracking.AreaType;
-import eu.reply.lea.services.yms.task.tracking.QueueingStatusDTO;
-import eu.reply.lea.services.yms.task.tracking.LogisticUnitLocationTrackerService;
-import eu.reply.lea.services.yms.util.ObjectMapperUtility;
-import eu.reply.sce.backend.core.entity.EntityReference;
-import eu.reply.sce.backend.core.event.ModuleEvent;
-import eu.reply.sce.backend.core.event.Observer;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-
-
-@Observer
-@ApplicationScoped
-@Logged
-public class LogisticUnitLocationTrackerObserver {
-
-
-    @Inject
-    private LogisticUnitLocationTrackerService logisticUnitLocationTrackerService;
-
-
-    public void handleUpdateLocationTrackingInfo(
-        @Observes @ModuleEvent("elementChangedAreaEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            logisticUnitRef = ObjectMapperUtility.getMapper().treeToValue(event.path("externalEntityReference"), EntityReference.class);
-        Instant
-            eventInstant = Instant.parse(ObjectMapperUtility.getMapper().treeToValue(event.path("eventInstant"), String.class));
-        String
-            areaType = ObjectMapperUtility.getMapper().treeToValue(event.path("areaType"), String.class);
-        LocationReference
-            currentLocationReference = ObjectMapperUtility.getMapper().treeToValue(event.path("currentLocationReference"), LocationReference.class);
-        LocationReference
-            executionLocationReference = ObjectMapperUtility.getMapper().treeToValue(event.path("executionLocationReference"), LocationReference.class);
-        QueueingStatusDTO queueingStatus =
-            new QueueingStatusDTO(executionLocationReference, currentLocationReference, areaTypeConverter(areaType), eventInstant);
-        logisticUnitLocationTrackerService.updateLocation(logisticUnitRef, queueingStatus);
-
-    }
-
-    public void updatePositionAfterDequeuedEvent(@Observes @ModuleEvent("updatePositionAfterDequeuedEvent") final JsonNode event)
-        throws JsonProcessingException {
-        EntityReference
-            logisticUnitRef = ObjectMapperUtility.getMapper().treeToValue(event.path("queuedExternalEntityRef"), EntityReference.class);
-        logisticUnitLocationTrackerService.commandTransitToUpdateLoadingUnitPosition(logisticUnitRef);
-    }
-
-    private AreaType areaTypeConverter(String areaType){
-        return AreaType.valueOf(areaType);
-    }
-
-
-}
diff --git a/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceTest.java b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceTest.java
index 925119e..056237f 100644
--- a/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceTest.java
+++ b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceTest.java
@@ -28,7 +28,7 @@ public class LocationAwareTasksSequenceTest {
     private static class TestTasksSequence extends AbstractTasksSequence {
         @Override
         public List<LocationAwareTask<?, ?, ?>> getTasksToBeEnqueuedNext() {
-            return this.getQueueableTasks();
+            return this.getToBeQueuedTasks();
         }
     }
 
@@ -312,7 +312,7 @@ public class LocationAwareTasksSequenceTest {
         sequence.addTask(task3);
 
         // Act
-        List<LocationAwareTask<?, ?, ?>> queueableTasks = sequence.getQueueableTasks();
+        List<LocationAwareTask<?, ?, ?>> queueableTasks = sequence.getToBeQueuedTasks();
 
         // Assert
         assertEquals(queueableTasks, List.of(task1));

package eu.reply.lea.services.yms.task.sequence;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.MockitoAnnotations;

import eu.reply.lea.services.masterdata.reference.LocationReference;
import eu.reply.lea.services.process.task.entities.TaskStatus;
import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
import eu.reply.sce.backend.core.entity.EntityReference;

public class InternalTasksSequenceTest {


    @BeforeEach
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    private LocationAwareTask<?, ?, ?> createMockTask(long id, int sequenceNumber, LocationReference location, TaskStatus status) {
        LocationAwareTask<?, ?, ?> task = mock(LocationAwareTask.class);
        when(task.getId()).thenReturn(id);
        when(task.getName()).thenReturn(String.valueOf(id));        when(task.getSequenceNumber()).thenReturn(sequenceNumber);
        when(task.getLocation()).thenReturn(location);
        when(task.getStatus()).thenReturn(status);
        when(task.isQueueable()).thenReturn(status == TaskStatus.TODO);
        return task;
    }


    @Test
    public void testGetTasksToBeEnqueuedNext_DifferentLocations() {
        // Arrange
        LocationReference location1 = new LocationReference(new EntityReference("module", "entity", "id1"));
        LocationReference location2 = new LocationReference(new EntityReference("module", "entity", "id2"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location1, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location2, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location1, TaskStatus.TODO);

        InternalTasksSequence sequence = new InternalTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksToEnqueue = sequence.getTasksToBeEnqueuedNext();

        // Assert
        assertEquals(tasksToEnqueue, List.of(task1));

    }

    @Test
    public void testGetTasksToBeEnqueuedNext_EmptyTaskList() {
        // Arrange
        InternalTasksSequence sequence = new InternalTasksSequence();

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksToEnqueue = sequence.getTasksToBeEnqueuedNext();

        // Assert
        assertTrue(tasksToEnqueue.isEmpty());
    }
}
package eu.reply.lea.services.yms.task.sequence;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import eu.reply.lea.services.masterdata.reference.LocationReference;
import eu.reply.lea.services.process.task.entities.TaskStatus;
import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
import eu.reply.sce.backend.core.entity.EntityReference;


/**
 * Unit tests for the {@link AbstractTasksSequence} methods.
 */
public class LocationAwareTasksSequenceTest {

    /**
     * Concrete subclass of {@link AbstractTasksSequence} for testing purposes.
     */
    private static class TestTasksSequence extends AbstractTasksSequence {
        @Override
        public List<LocationAwareTask<?, ?, ?>> getTasksToBeEnqueuedNext() {
            return this.getToBeQueuedTasks();
        }
    }

    private LocationAwareTask<?, ?, ?> createMockTask(long id, int sequenceNumber, LocationReference location, TaskStatus status) {
        LocationAwareTask<?, ?, ?> task = mock(LocationAwareTask.class);
        when(task.getId()).thenReturn(id);
        when(task.getName()).thenReturn(String.valueOf(id));
        when(task.getSequenceNumber()).thenReturn(sequenceNumber);
        when(task.getLocation()).thenReturn(location);
        when(task.getStatus()).thenReturn(status);
        when(task.isQueueable()).thenReturn(status == TaskStatus.TODO);
        return task;
    }

    @Test
    public void testAreAllTasksInTheLocationClosed_AllClosedContiguous() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationReference location1 = new LocationReference(new EntityReference("masterdata", "dock", "1323"));

        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location1, TaskStatus.TODO);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        boolean result = sequence.areAllTasksContiguousInTheLocationClosed(task1);
        // Assert
        assertTrue(result);
    }


    @Test
    public void testAreAllTasksInTheLocationClosed_AllClosedContiguous_JumpingSequenceNumber() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationReference location1 = new LocationReference(new EntityReference("masterdata", "dock", "1323"));

        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,5, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location1, TaskStatus.TODO);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        boolean result = sequence.areAllTasksContiguousInTheLocationClosed(task1);
        // Assert
        assertTrue(result);
    }


    @Test
    public void testAreAllTasksInTheLocationClosed_AllClosedContiguous_TaskAfterJumpingSequenceNumberNotClosed() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationReference location1 = new LocationReference(new EntityReference("masterdata", "dock", "1323"));

        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,5, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location1, TaskStatus.TODO);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        boolean result = sequence.areAllTasksContiguousInTheLocationClosed(task1);
        // Assert
        assertTrue(result);
    }


    @Test
    public void testAreAllTasksInTheLocationClosed_NotAllClosedContiguous() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationReference location1 = new LocationReference(new EntityReference("masterdata", "dock", "1323"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location1, TaskStatus.DONE);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        boolean result = sequence.areAllTasksContiguousInTheLocationClosed(task1);
        // Assert
        assertFalse(result);
    }


    @Test(expected = IllegalStateException.class)
    public void testGetTasksToBeQueuedContiguously_NoTasksInLocation() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "456"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.TODO);

        AbstractTasksSequence sequence = new TestTasksSequence();
        // No tasks added to the sequence

        // Act
        sequence.getTasksSameLocationContiguously(task1, true);
    }

    @Test(expected = IllegalStateException.class)
    public void testGetTasksToBeQueuedContiguously_With_TaskNotFound() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location, TaskStatus.TODO);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);

        // Act
        sequence.getTasksSameLocationContiguously(task2, true);
    }


    @Test
    public void testGetTasksToBeEnqueuedNext_MultipleContiguousTasksSameLocation() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.IN_PROGRESS); // Not queueable
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location, TaskStatus.TODO); // Should not be included

        AbstractTasksSequence sequence = new InternalTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksToEnqueueNext = sequence.getTasksSameLocationContiguously(task1, true);

        // Assert
        assertEquals(tasksToEnqueueNext, List.of(task1, task2));
    }

    @Test
    public void testGetTasksToBeEnqueuedNext_MultipleNonContiguousTasksSameLocation_TaskBeforeSequenceNumberJump() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,5, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.IN_PROGRESS); // Not queueable
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location, TaskStatus.TODO); // Should not be included

        AbstractTasksSequence sequence = new InternalTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksToEnqueueNext = sequence.getTasksSameLocationContiguously(task1, true);

        // Assert
        assertEquals(tasksToEnqueueNext, List.of(task1));
    }


    @Test
    public void testGetTasksToBeEnqueuedNext_MultipleNonContiguousTasksSameLocation_TaskAfterSequenceNumberJump() {
        // Arrange
        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(5L,6, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task5 = createMockTask(2L,7, location, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location, TaskStatus.IN_PROGRESS); // Not queueable
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,4, location, TaskStatus.TODO); // Should not be included

        AbstractTasksSequence sequence = new InternalTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);
        sequence.addTask(task5);

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksToEnqueueNext = sequence.getTasksSameLocationContiguously(task5, true);

        // Assert
        assertEquals(tasksToEnqueueNext, List.of(task2,task5));
    }

    @Test
    public void testGetTasksInLocationQueueable() {
        // Arrange
        LocationReference location1 = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationReference location2 = new LocationReference(new EntityReference("masterdata", "dock", "456"));

        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location1, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location2, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, location1, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task4 = createMockTask(4L,5, location1, TaskStatus.TODO);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);
        sequence.addTask(task4);

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksInLocation1 = sequence.getTasksInLocation(location1,true );

        // Assert
        assertEquals(tasksInLocation1, List.of(task1,task3, task4));
    }

    @Test
    public void testGetTasksInLocationNotQueueable() {
        // Arrange
        LocationReference location1 = new LocationReference(new EntityReference("masterdata", "dock", "123"));
        LocationReference location2 = new LocationReference(new EntityReference("masterdata", "dock", "456"));

        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, location1, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, location2, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(1L,3, location1, TaskStatus.DONE);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);

        // Act
        List<LocationAwareTask<?, ?, ?>> tasksInLocation1 = sequence.getTasksInLocation(location1,false );

        // Assert
        assertEquals(tasksInLocation1, List.of(task1));
    }

    @Test
    public void testSortTasks() {
        // Arrange
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,3, null, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,1, null, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,2, null, TaskStatus.TODO);

        List<LocationAwareTask<?, ?, ?>> unsortedTasks = Arrays.asList(task1, task2, task3);

        AbstractTasksSequence sequence = new TestTasksSequence();

        // Act
        List<LocationAwareTask<?, ?, ?>> sortedTasks = sequence.sortTasks(unsortedTasks);

        // Assert
        assertEquals(sortedTasks, List.of(task2, task3,task1));
    }

    @Test
    public void testGetQueueableTasks() {
        // Arrange
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, null, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, null, TaskStatus.IN_PROGRESS);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, null, TaskStatus.BLOCKED);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);

        // Act
        List<LocationAwareTask<?, ?, ?>> queueableTasks = sequence.getToBeQueuedTasks();

        // Assert
        assertEquals(queueableTasks, List.of(task1));
    }

    @Test
    public void testGetActiveTasks() {
        // Arrange
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, null, TaskStatus.TODO);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, null, TaskStatus.IN_PROGRESS);
        LocationAwareTask<?, ?, ?> task3 = createMockTask(3L,3, null, TaskStatus.DONE);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);
        sequence.addTask(task3);

        // Act
        List<LocationAwareTask<?, ?, ?>> activeTasks = sequence.getActiveTasks();

        // Assert
        assertEquals(activeTasks, List.of(task1, task2));
    }

    @Test
    public void testIsAllTasksClosed_True() {
        // Arrange
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, null, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, null, TaskStatus.DONE);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);

        // Act
        boolean allClosed = sequence.isAllTasksClosed();

        // Assert
        assertTrue(allClosed);
    }

    @Test
    public void testIsAllTasksClosed_False() {
        // Arrange
        LocationAwareTask<?, ?, ?> task1 = createMockTask(1L,1, null, TaskStatus.DONE);
        LocationAwareTask<?, ?, ?> task2 = createMockTask(2L,2, null, TaskStatus.IN_PROGRESS);

        AbstractTasksSequence sequence = new TestTasksSequence();
        sequence.addTask(task1);
        sequence.addTask(task2);

        // Act
        boolean allClosed = sequence.isAllTasksClosed();

        // Assert
        assertFalse(allClosed);
    }
}
Add new tests