Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/AbstractTasksSequence.java	(date 1727425925450)
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.persistence.AttributeOverride;
@@ -22,6 +23,7 @@
 import lombok.Getter;
 import lombok.Setter;
 
+import eu.reply.lea.services.masterdata.reference.LocationReference;
 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;
@@ -114,10 +116,65 @@
             .collect(Collectors.toList());
     }
 
+    @Override
     @JsonIgnore
     public List<LocationAwareTask<?, ?, ?>> getQueueableTasks() {
         List<LocationAwareTask<?, ?, ?>> sortedSequence = getSortedSequence();
         return getQueueableTasks(sortedSequence, 0, true);
     }
 
-}
+    @Override
+    public boolean areAllTasksToBeExecutedContiguouslyClosed(final LocationAwareTask<?, ?, ?> task) {
+        return getTasksToBeExecutedContiguously(task).stream().allMatch(t -> t.getStatus().isClosed());
+    }
+
+    @Override
+    @JsonIgnore
+    public List<LocationAwareTask<?, ?, ?>> getTasksToBeExecutedContiguously(final LocationAwareTask<?, ?, ?> task) {
+        LocationReference location = task.getLocation();
+        List<LocationAwareTask<?, ?, ?>> tasksSameLocation = sortTasks(getTasksInLocation(location));
+        List<LocationAwareTask<?, ?, ?>> result = new ArrayList<>();
+        if (tasksSameLocation.isEmpty()) {
+            throw new IllegalStateException(String.format("There are no tasks in the location %s", location));
+        }
+        if (tasksSameLocation.stream().noneMatch(t->t.equals(task))) {
+            throw new IllegalStateException(String.format("It was not possible to find the tasks among"
+                                                          + "the ones of the sequence for the specified"
+                                                          + "location %s", location));
+        }
+        Integer taskSequenceNumber = task.getSequenceNumber();
+        boolean foundTask = false;
+        int previousSequenceNumber = tasksSameLocation.get(0).getSequenceNumber();
+        for (LocationAwareTask<?, ?, ?> taskSameLocation : tasksSameLocation) {
+            if (taskSameLocation.getSequenceNumber().equals(taskSequenceNumber)) {
+                foundTask = true;
+            }
+            if (taskSameLocation.getSequenceNumber() > previousSequenceNumber+1) {
+                if (foundTask) {
+                    return result;
+                }else{
+                    result.clear();
+                }
+            }
+            previousSequenceNumber = taskSameLocation.getSequenceNumber();
+            result.add(taskSameLocation);
+        }
+        if (foundTask){
+            return result;
+        }
+        throw new IllegalStateException(String.format("No tasks were found for location %s and task %s", location, task));
+    }
+
+
+    @JsonIgnore
+    public List<LocationAwareTask<?, ?, ?>> getTasksInLocation(final LocationReference location) {
+        return this.getTasks().stream()
+            .filter(task -> location.equals(task.getLocation()))
+            .collect(Collectors.toList());
+    }
+
+    @Override
+    public List<LocationAwareTask<?, ?, ?>> sortTasks(final List<LocationAwareTask<?, ?, ?>> tasks) {
+        return tasks.stream().sorted(Comparator.comparing(LocationAwareTask::getSequenceNumber)).collect(Collectors.toList());
+    }
+    }
Index: lea-yms-application/src/test/java/eu/reply/lea/services/yms/test/unitTests/TransitTaskTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/test/java/eu/reply/lea/services/yms/test/unitTests/TransitTaskTest.java b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/test/unitTests/TransitTaskTest.java
--- a/lea-yms-application/src/test/java/eu/reply/lea/services/yms/test/unitTests/TransitTaskTest.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/test/unitTests/TransitTaskTest.java	(date 1727425925451)
@@ -66,10 +66,6 @@
 import eu.reply.lea.services.yms.task.event.TaskCompletedEvent;
 import eu.reply.lea.services.yms.task.event.LocationAwareTaskStatusChangedEventInfo;
 import eu.reply.lea.services.yms.task.factory.TaskDetailInfo;
-import eu.reply.lea.services.yms.task.locationaware.boundary.CheckOutTaskProcessor;
-import eu.reply.lea.services.yms.task.locationaware.boundary.ReceivingTaskProcessor;
-import eu.reply.lea.services.yms.task.locationaware.boundary.ShippingTaskProcessor;
-import eu.reply.lea.services.yms.task.locationaware.boundary.WeighingTaskProcessor;
 import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.checkin.CheckInTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.checkin.CheckInTaskConfiguration;
@@ -79,9 +75,11 @@
 import eu.reply.lea.services.yms.task.locationaware.domain.checkout.CheckOutTaskConfiguration;
 import eu.reply.lea.services.yms.task.locationaware.domain.checkout.CheckOutTaskDetail;
 import eu.reply.lea.services.yms.task.locationaware.domain.checkout.CheckOutTaskHeader;
+import eu.reply.lea.services.yms.task.locationaware.boundary.CheckOutTaskProcessor;
 import eu.reply.lea.services.yms.task.locationaware.domain.receiving.ReceivingTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.receiving.ReceivingTaskConfiguration;
 import eu.reply.lea.services.yms.task.locationaware.domain.receiving.ReceivingTaskHeader;
+import eu.reply.lea.services.yms.task.locationaware.boundary.ReceivingTaskProcessor;
 import eu.reply.lea.services.yms.task.locationaware.domain.registration.RegistrationTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.registration.RegistrationTaskConfiguration;
 import eu.reply.lea.services.yms.task.locationaware.domain.registration.RegistrationTaskDetail;
@@ -89,13 +87,15 @@
 import eu.reply.lea.services.yms.task.locationaware.domain.shipping.ShippingTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.shipping.ShippingTaskConfiguration;
 import eu.reply.lea.services.yms.task.locationaware.domain.shipping.ShippingTaskHeader;
+import eu.reply.lea.services.yms.task.locationaware.boundary.ShippingTaskProcessor;
 import eu.reply.lea.services.yms.task.locationaware.domain.template.LocationAwareTaskTemplate;
 import eu.reply.lea.services.yms.task.locationaware.domain.unsealing.UnsealingTaskConfiguration;
 import eu.reply.lea.services.yms.task.locationaware.domain.unsealing.UnsealingTaskHeader;
 import eu.reply.lea.services.yms.task.locationaware.domain.weighing.WeighingTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.weighing.WeighingTaskConfiguration;
 import eu.reply.lea.services.yms.task.locationaware.domain.weighing.WeighingTaskHeader;
-import eu.reply.lea.services.yms.task.observer.QueueObserver;
+import eu.reply.lea.services.yms.task.locationaware.boundary.WeighingTaskProcessor;
+import eu.reply.lea.services.yms.task.locationaware.observer.TaskClosureObserver;
 import eu.reply.lea.services.yms.task.queue.QueueHandler;
 import eu.reply.lea.services.yms.task.sequence.TasksSequence;
 import eu.reply.lea.services.yms.task.sequence.TransitTasksSequence;
@@ -120,7 +120,7 @@
     @Spy @InjectMocks private TransitTasksSequenceHandler transitTasksSequenceHandler;
 
 
-    @InjectMocks private QueueObserver queueObserver;
+    @InjectMocks private TaskClosureObserver taskClosureObserver;
 
     @InjectMocks private WeighingTaskProcessor weighingTaskProcessor;
 
@@ -171,11 +171,9 @@
 
         CheckOutTaskHeader coHeader = createCheckOutHeader(true, true);
 
-        final CheckInTaskConfiguration
-            checkInConfig = new CheckInTaskConfiguration("CONFIF_CHECK_IN", new SiteReference(sitePojo), "DESC", ciHeader);
+        final CheckInTaskConfiguration checkInConfig = new CheckInTaskConfiguration("CONFIF_CHECK_IN",new SiteReference(sitePojo), "DESC", ciHeader);
         em.persist(checkInConfig);
-        final CheckOutTaskConfiguration
-            checkOutConfig = new CheckOutTaskConfiguration("CONFIF_CHECK_OUT", new SiteReference(sitePojo), "DESC", coHeader);
+        final CheckOutTaskConfiguration checkOutConfig = new CheckOutTaskConfiguration("CONFIF_CHECK_OUT", new SiteReference(sitePojo),"DESC", coHeader);
         em.persist(checkOutConfig);
 
         for (int j = 0; j < 500; j++) {
@@ -231,8 +229,7 @@
 
         final CheckInTaskConfiguration checkInConfig = new CheckInTaskConfiguration("CONFIG_CHECK_IN",new SiteReference(sitePojo), "DESC", ciHeader);
         em.persist(checkInConfig);
-        final RegistrationTaskConfiguration
-            regConfig = new RegistrationTaskConfiguration("CONFIG_REG", new SiteReference(sitePojo), "desc", regHeader);
+        final RegistrationTaskConfiguration regConfig = new RegistrationTaskConfiguration("CONFIG_REG", new SiteReference(sitePojo),"desc", regHeader);
         em.persist(regConfig);
         final CheckOutTaskConfiguration checkOutConfig = new CheckOutTaskConfiguration("CONFIG_CHECK_OUT",new SiteReference(sitePojo), "DESC", coHeader);
         em.persist(checkOutConfig);
@@ -749,10 +746,8 @@
         final RegistrationTaskConfiguration regConfig = new RegistrationTaskConfiguration("CONFIG_REG",new SiteReference(sitePojo), "desc", regHeader);
         final CheckInTaskConfiguration checkInConfig = new CheckInTaskConfiguration("CONFIG_CHECK_IN",new SiteReference(sitePojo), "DESC", ciHeader);
         final CheckOutTaskConfiguration checkOutConfig = new CheckOutTaskConfiguration("CONFIG_CHECK_OUT",new SiteReference(sitePojo), "DESC", coHeader);
-        final ShippingTaskConfiguration
-            shippingConfig = new ShippingTaskConfiguration("CONFIG_SHIPPING", new SiteReference(sitePojo), "DESC", shippingHeader);
-        final ReceivingTaskConfiguration
-            receivingConfig = new ReceivingTaskConfiguration("CONFIG_RECEIVING", new SiteReference(sitePojo), "DESC", receivingHeader);
+        final ShippingTaskConfiguration shippingConfig = new ShippingTaskConfiguration("CONFIG_SHIPPING", new SiteReference(sitePojo),"DESC", shippingHeader);
+        final ReceivingTaskConfiguration receivingConfig = new ReceivingTaskConfiguration("CONFIG_RECEIVING",new SiteReference(sitePojo), "DESC", receivingHeader);
 
         em.persist(regConfig);
         em.persist(checkInConfig);
@@ -764,8 +759,7 @@
         final CheckInTask checkInTask = createCheckInTask(sitePojo, "checkInName", "checInDescription", Calendar.getInstance(), tm, checkInConfig);
         final CheckOutTask checkOutTask = createCheckOutTask(sitePojo, "checkOutName", "checOutDescription", Calendar.getInstance(), Calendar.getInstance(), tm, checkOutConfig);
         final ShippingTask shippingTask = createShippingTask(sitePojo, "shippingName", "shippingDescription", tm, shippingConfig);
-        final ReceivingTask
-            receivingTask = createReceivingTask(sitePojo, "receivingName", "receivingDescription", tm, receivingConfig);
+        final ReceivingTask receivingTask = createReceivingTask(sitePojo, "receivingName", "receivingDescription", tm, receivingConfig);
 
         regTask.addDetail(new RegistrationTaskDetail(regTask, "plate1", "plateCountry1", true, false, false, false));
         regTask.addDetail(new RegistrationTaskDetail(regTask, "plate2", "plateCountry2", false, true, false, false));
@@ -999,8 +993,7 @@
         TransitTaskTemplate unsealingtaskTemplate = tasksSequenceTemplate.getTasks().stream()
             .filter(t -> t.getTaskType().equals(TaskType.UNSEALING)).findFirst().get();
         unsealingtaskTemplate.setSplitByTrailer(true);
-        UnsealingTaskConfiguration
-            config = new UnsealingTaskConfiguration(new SiteReference(sitePojo).getBusinessKey(), new SiteReference(sitePojo), "description", new UnsealingTaskHeader());
+        UnsealingTaskConfiguration config = new UnsealingTaskConfiguration(new SiteReference(sitePojo).getBusinessKey(), new SiteReference(sitePojo),"description", new UnsealingTaskHeader());
         em.persist(config);
 
         observer.onTransitCreated(pojo);
@@ -1360,8 +1353,7 @@
         WeighingTaskHeader header = new WeighingTaskHeader();
         ZonePojoTest zone = new ZonePojoTest(1l, "001", Zone.Type.WEIGHTING, sitePojo);
         header.setPreferredLocation(new ZoneReference(zone));
-        WeighingTaskConfiguration
-            configuration = new WeighingTaskConfiguration(new SiteReference(sitePojo).getBusinessKey(), new SiteReference(sitePojo) , "description", header );
+        WeighingTaskConfiguration configuration = new WeighingTaskConfiguration(new SiteReference(sitePojo).getBusinessKey(),new SiteReference(sitePojo) ,"description",header );
         em.merge(configuration);
 
         TransitPojo tr = createTransitPojo();
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/observer/QueueObserver.java
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/observer/QueueObserver.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/observer/QueueObserver.java
deleted file mode 100644
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/observer/QueueObserver.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ /dev/null	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
@@ -1,89 +0,0 @@
-package eu.reply.lea.services.yms.task.observer;
-
-import java.io.Serializable;
-import java.util.Collections;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import org.slf4j.Logger;
-
-import eu.reply.lea.services.masterdata.client.MasterdataServiceException;
-import eu.reply.lea.services.yard.exceptions.LoadingUnitActionException;
-import eu.reply.lea.services.yard.reference.TransitReference;
-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.LocationAwareTask;
-import eu.reply.lea.services.yms.task.queue.QueueHandler;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommand;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
-import eu.reply.lea.services.yms.util.ObjectMapperUtility;
-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;
-import eu.reply.sce.backend.core.jee.log.Logged;
-
-
-@Observer
-@Logged
-@ApplicationScoped
-public class QueueObserver implements Serializable {
-
-    @Inject
-    private Logger logger;
-
-    @Inject
-    @ModuleConfiguration.Module(ModuleConfiguration.Module.CURRENT)
-    private EntityManager em;
-
-
-    @Inject
-    private QueueHandler queueHandler;
-
-    @Inject
-    private EntityReferenceHandler entityReferenceHandler;
-
-    @Inject
-    private ConfigurableEventProducer<TaskDequeueCommand> taskDequeueCommandProducer;
-
-
-    /**
-     * Trace message
-     *
-     * @param format format message to be traced.
-     * @param args   value of the format message
-     */
-    public void debug(String format, Object... args) {
-        if (this.logger != null) {
-            this.logger.debug(format, args);
-        }
-    }
-
-
-    @TransactionAttribute(TransactionAttributeType.REQUIRED)
-    public void dequeueTask(
-        @Observes @ModuleEvent("externalTaskClosedEvent") final JsonNode taskClosedEvent)
-        throws MasterdataServiceException, LoadingUnitActionException, JsonProcessingException {
-        LocationAwareTaskStatusChangedEventInfo payload =
-            ObjectMapperUtility.getMapper().treeToValue(taskClosedEvent, LocationAwareTaskStatusChangedEventInfo.class);
-        final LocationAwareTask<?,?,?>
-            task =  entityReferenceHandler.getEntity(payload.getTaskRef(), em);
-        if (task.getLocation()!=null) {
-            taskDequeueCommandProducer.fire(new TaskDequeueCommand(
-                new TaskDequeueCommandInfo(Collections.singletonList(new TaskReference(task)),
-                                           Collections.singletonList(task.getLocation()),
-                                           new TransitReference(task.getLogisticUnitReference()))));
-        }
-    }
-
-
-
-
-}
Index: lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/locationaware/domain/integration/yms/queue/TaskDequeueServiceImplTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/locationaware/domain/integration/yms/queue/TaskDequeueServiceImplTest.java b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/locationaware/domain/integration/yms/queue/TaskDequeueServiceImplTest.java
new file mode 100644
--- /dev/null	(date 1727426990864)
+++ b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/locationaware/domain/integration/yms/queue/TaskDequeueServiceImplTest.java	(date 1727426990864)
@@ -0,0 +1,65 @@
+package eu.reply.lea.services.yms.task.locationaware.domain.integration.yms.queue;
+
+
+import static org.mockito.Mockito.anyList;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.lea.services.yms.task.locationaware.integration.yms.queue.TaskDequeueAdapter;
+import eu.reply.lea.services.yms.task.locationaware.integration.yms.queue.TaskDequeueServiceImpl;
+
+public class TaskDequeueServiceImplTest {
+
+    @InjectMocks
+    private TaskDequeueServiceImpl taskDequeueService;
+
+    @Mock
+    private TaskDequeueAdapter taskDequeueAdapter;
+
+    @BeforeEach
+    void setUp()  {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testDequeueTasks_Success() {
+        // Arrange
+        LocationAwareTask<?, ?, ?> task = mock(LocationAwareTask.class);
+        when(task.getLocation()).thenReturn(mock(eu.reply.lea.services.masterdata.reference.LocationReference.class));
+
+        List<LocationAwareTask<?, ?, ?>> tasks = Collections.singletonList(task);
+
+        // Act
+        taskDequeueService.dequeueTasks(tasks);
+
+        // Assert
+        verify(taskDequeueAdapter, times(1)).notifyDequeueForTask(anyList());
+    }
+
+    @Test
+    public void testDequeueTasks_NoTasksToDequeue() {
+        // Arrange
+        List<LocationAwareTask<?, ?, ?>> tasks = Collections.emptyList();
+
+        // Act
+        taskDequeueService.dequeueTasks(tasks);
+
+        // Assert
+        verify(taskDequeueAdapter, never()).notifyDequeueForTask(anyList());
+    }
+
+}
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskApplicationService.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
new file mode 100644
--- /dev/null	(date 1727425925449)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/LocationAwareTaskApplicationService.java	(date 1727425925449)
@@ -0,0 +1,44 @@
+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);
+        LocationReference location = task.getLocation();
+        LocationAwareTasksSequence<LocationAwareTask<?, ?, ?>> sequence =
+            task.getSequence();
+
+        if (sequence != null && sequence.areAllTasksToBeExecutedContiguouslyClosed(task)) {
+            // Delegate external service call to adapter
+            taskDequeueAdapter.notifyDequeueForTask(sequence.getTasksInLocation(location));
+        }
+    }
+}
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/observer/TransitEventObserver.java	(date 1727425925447)
@@ -50,8 +50,9 @@
 import eu.reply.lea.services.yard.reference.TransitReference;
 import eu.reply.lea.services.yms.boundary.YardService;
 import eu.reply.lea.services.yms.task.TaskReference;
+import eu.reply.lea.services.yms.task.TransitTaskFactoryException;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTaskHandler;
 import eu.reply.lea.services.yms.task.TaskType;
-import eu.reply.lea.services.yms.task.TransitTaskFactoryException;
 import eu.reply.lea.services.yms.task.event.CheckInCountdownEndedEvent;
 import eu.reply.lea.services.yms.task.event.LocationAwareTaskEventInfo;
 import eu.reply.lea.services.yms.task.event.TransitTaskSequenceCreationCommand;
@@ -62,13 +63,13 @@
 import eu.reply.lea.services.yms.task.event.task.ResetTaskInfoForAdviseMessageEvent;
 import eu.reply.lea.services.yms.task.factory.TransitTaskBuilderDirector;
 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.TaskDequeueService;
 import eu.reply.lea.services.yms.task.locationaware.domain.registration.RegistrationTask;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommand;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
 import eu.reply.lea.services.yms.task.sequence.TransitTasksSequence;
 import eu.reply.lea.services.yms.task.sequence.TransitTasksSequenceHandler;
 import eu.reply.lea.services.yms.task.sequence.repository.TransitTasksSequenceRepository;
+import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommand;
+import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
 import eu.reply.sce.backend.core.entity.EntityReference;
 import eu.reply.sce.backend.core.entity.exception.EntityNotFoundException;
 import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
@@ -118,6 +119,9 @@
     @Inject
     private DefaultYardService defaultYardService;
 
+    @Inject
+    private TaskDequeueService taskDequeueService;
+
     @Inject
     private YardService yardService;
 
@@ -525,8 +529,7 @@
             return;
         }
         List<LocationAwareTask<?,?,?>> tasksToCancel = tasksSequence != null ? tasksSequence.getTasks() : new ArrayList<>();
-        List<TaskReference> locationAwareTasksCancelled = new ArrayList<>();
-        List<LocationReference> taskLocationCancelled = new ArrayList<>();
+        List<LocationAwareTask<?,?,?>> locationAwareTasksCancelled = new ArrayList<>();
         for (LocationAwareTask<?,?,?> task : tasksToCancel) {
             if (task.getTaskType() == TaskType.REGISTRATION && !cancelRegistrationTask) {
                 continue;
@@ -537,16 +540,13 @@
                 }
             }
             locationAwareTaskHandler.cancelTask(task, "");
-            if (task.getLocation()!=null) {
-                taskLocationCancelled.add( task.getLocation());
-                locationAwareTasksCancelled.add(new TaskReference(task));
-            }
+            locationAwareTasksCancelled.add(task);
+
         }
         tasksSequence.cancelSequence(transitTaskSequenceStatusUpdateProducer);
 
-        taskDequeueCommandProducer.fire(new TaskDequeueCommand(
-                new TaskDequeueCommandInfo(locationAwareTasksCancelled,
-                                           taskLocationCancelled, transitReference)));
+        taskDequeueService.dequeueTasks(locationAwareTasksCancelled);
+
     }
 
     private void updateTransit(final TransitReference transitReference) {
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueAdapter.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueAdapter.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueAdapter.java
new file mode 100644
--- /dev/null	(date 1727426529832)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueAdapter.java	(date 1727426529832)
@@ -0,0 +1,38 @@
+package eu.reply.lea.services.yms.task.locationaware.integration.yms.queue;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.inject.Inject;
+
+import eu.reply.lea.services.masterdata.reference.LocationReference;
+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.queue.event.TaskDequeueCommand;
+import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
+import eu.reply.sce.backend.core.entity.EntityReference;
+import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
+
+/**
+ * Adapter responsible for interacting with the infrastructure layer to notify about task dequeuing.
+ */
+public class TaskDequeueAdapter {
+
+    @Inject
+    private ConfigurableEventProducer<TaskDequeueCommand> taskDequeueCommandProducer;
+
+    public void notifyDequeueForTask(List<LocationAwareTask<?, ?, ?>> tasks) {
+        if (tasks.isEmpty()){
+            throw new IllegalStateException("No tasks to dequeue");
+        }
+        EntityReference logisticUnitRef = tasks.get(0).getLogisticUnitReference();
+        List<TaskReference> tasksToDequeue = tasks.stream().map(TaskReference::new).collect(Collectors.toList());
+        List<LocationReference> locationReferences = tasks.stream().map(LocationAwareTask::getLocation).collect(Collectors.toList());
+        taskDequeueCommandProducer.fire(new TaskDequeueCommand(
+            new TaskDequeueCommandInfo(
+                tasksToDequeue,
+                locationReferences,
+                logisticUnitRef)
+            )
+        );
+    }
+}
\ No newline at end of file
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceHandler.java	(date 1727425925450)
@@ -5,13 +5,9 @@
 import javax.inject.Inject;
 
 import eu.reply.lea.services.process.task.entities.TaskStatus;
-import eu.reply.lea.services.yard.reference.TransitReference;
-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.LocationAwareTaskHandler;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommand;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
-import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskDequeueService;
 import eu.reply.sce.backend.core.jee.log.Logged;
 
 @SuppressWarnings("rawtypes")
@@ -22,7 +18,7 @@
     private LocationAwareTaskHandler locationAwareTaskHandler;
 
     @Inject
-    private ConfigurableEventProducer<TaskDequeueCommand> taskDequeueCommandProducer;
+    private TaskDequeueService taskDequeueService;
 
     /**
      * Blocks and Dequeues all the task after transitTask
@@ -34,16 +30,13 @@
         LocationAwareTask<?,?,?> transitTask) {
         this.debug("[blockAndDequeueAllTasksAfter] Blocking Dequeing all the tasks after [{}]", transitTask);
         List<LocationAwareTask<?,?,?>> taskSequence = transitTask.getSequence().getTasks();
-        List<LocationAwareTask> locationAwareTasksAfterTask = taskSequence.stream()
+        List<LocationAwareTask<?,?,?>> locationAwareTasksAfterTask = taskSequence.stream()
                 .filter(t -> (t.getSequenceNumber() > transitTask.getSequenceNumber())).collect(Collectors.toList());
         for (LocationAwareTask locationAwareTask : locationAwareTasksAfterTask) {
             this.debug("[blockAndDequeueAllTasksAfter] Blocking Dequeing task [{}]", locationAwareTask);
             locationAwareTaskHandler.blockTask(locationAwareTask);
         }
-        taskDequeueCommandProducer.fire(new TaskDequeueCommand(
-            new TaskDequeueCommandInfo(locationAwareTasksAfterTask.stream().map(t->new TaskReference(t)).collect(Collectors.toList()),
-                                       locationAwareTasksAfterTask.stream().map(t->t.getLocation()).collect(Collectors.toList()),
-                                       new TransitReference(transitTask.getLogisticUnitReference()))));
+        taskDequeueService.dequeueTasks(locationAwareTasksAfterTask);
     }
 
 
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueServiceImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueServiceImpl.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueServiceImpl.java
new file mode 100644
--- /dev/null	(date 1727425925449)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/integration/yms/queue/TaskDequeueServiceImpl.java	(date 1727425925449)
@@ -0,0 +1,40 @@
+package eu.reply.lea.services.yms.task.locationaware.integration.yms.queue;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskDequeueService;
+import eu.reply.sce.backend.core.jee.log.Logged;
+
+@Logged
+@ApplicationScoped
+public class TaskDequeueServiceImpl implements TaskDequeueService {
+
+    @Inject
+    private TaskDequeueAdapter taskDequeueAdapter;
+
+    @Inject
+    private Logger logger;
+
+    @Override
+    public void dequeueTasks(List<LocationAwareTask<?, ?, ?>> tasks) {
+        List<LocationAwareTask<?,?,?>> tasksToDequeue = tasks.stream().filter(t->t.getLocation()!=null).collect(Collectors.toList());
+        if (tasksToDequeue.isEmpty()){
+            return;
+        }
+        try {
+            taskDequeueAdapter.notifyDequeueForTask(tasksToDequeue);
+            logger.info("Successfully dequeued tasks.");
+        } catch (Exception e) {
+            logger.error("Error during task dequeuing: {}", e.getMessage());
+            throw new RuntimeException("Failed to dequeue tasks.", e);
+        }
+    }
+
+}
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/observer/TaskClosureObserver.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
new file mode 100644
--- /dev/null	(date 1727426570392)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/observer/TaskClosureObserver.java	(date 1727426570392)
@@ -0,0 +1,47 @@
+package eu.reply.lea.services.yms.task.locationaware.observer;
+
+import java.io.Serializable;
+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.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.util.ObjectMapperUtility;
+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 that listens for task closure events and delegates the handling to the service.
+ */
+@Observer
+@Logged
+@ApplicationScoped
+public class TaskClosureObserver implements Serializable {
+
+
+    @Inject
+    private LocationAwareTaskApplicationService locationAwareTaskApplicationService;
+
+
+    public void dequeueTask(
+        @Observes @ModuleEvent("externalTaskClosedEvent") final JsonNode taskClosedEvent)
+        throws MasterdataServiceException, LoadingUnitActionException, JsonProcessingException {
+        LocationAwareTaskStatusChangedEventInfo payload =
+            ObjectMapperUtility.getMapper().treeToValue(taskClosedEvent, LocationAwareTaskStatusChangedEventInfo.class);
+        locationAwareTaskApplicationService.handleTaskClosure(new TaskReference(payload.getTaskRef()));
+
+    }
+
+
+
+
+}
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/LocationAwareTaskProcessor.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/LocationAwareTaskProcessor.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/LocationAwareTaskProcessor.java
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/LocationAwareTaskProcessor.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/LocationAwareTaskProcessor.java	(date 1727425925449)
@@ -9,7 +9,6 @@
 import eu.reply.lea.services.yms.task.sequence.exception.TransitTaskSequenceException;
 import eu.reply.sce.backend.core.entity.configuration.Condition;
 
-
 public class LocationAwareTaskProcessor extends
     AbstractLocationAwareTaskProcessor<LocationAwareTask<?,?,?>> {
 
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/AbstractLocationAwareTaskProcessor.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/AbstractLocationAwareTaskProcessor.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/AbstractLocationAwareTaskProcessor.java
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/AbstractLocationAwareTaskProcessor.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/boundary/AbstractLocationAwareTaskProcessor.java	(date 1727425925449)
@@ -17,7 +17,6 @@
 import eu.reply.lea.services.masterdata.model.carrier.Driver;
 import eu.reply.lea.services.masterdata.model.language.Language;
 import eu.reply.lea.services.masterdata.pojo.carrier.DriverPojo;
-import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.process.task.boundary.GenericTaskProcessor;
 import eu.reply.lea.services.process.task.entities.TaskStatus;
 import eu.reply.lea.services.process.task.exceptions.ActionNotAllowedException;
@@ -28,28 +27,26 @@
 import eu.reply.lea.services.yms.boundary.YardService;
 import eu.reply.lea.services.yms.task.AddTaskToSequenceService;
 import eu.reply.lea.services.yms.task.HaveLoadingUnitReference;
-import eu.reply.lea.services.yms.task.TaskReference;
 import eu.reply.lea.services.yms.task.TaskType;
 import eu.reply.lea.services.yms.task.dockaware.loading.ChangeLocationAction;
 import eu.reply.lea.services.yms.task.event.ChangedPriorityEvent;
-import eu.reply.lea.services.yms.task.event.TaskClosedEvent;
-import eu.reply.lea.services.yms.task.event.TaskCompletedEvent;
-import eu.reply.lea.services.yms.task.event.TaskRemovedFromSequenceEvent;
 import eu.reply.lea.services.yms.task.event.LocationAwareTaskEnterEvent;
 import eu.reply.lea.services.yms.task.event.LocationAwareTaskEventInfo;
 import eu.reply.lea.services.yms.task.event.LocationAwareTaskStatusChangedEventInfo;
+import eu.reply.lea.services.yms.task.event.TaskClosedEvent;
+import eu.reply.lea.services.yms.task.event.TaskCompletedEvent;
+import eu.reply.lea.services.yms.task.event.TaskRemovedFromSequenceEvent;
 import eu.reply.lea.services.yms.task.exception.ChangeLocationException;
 import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
 import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTaskDetail;
 import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTaskHandler;
+import eu.reply.lea.services.yms.task.locationaware.domain.TaskDequeueService;
 import eu.reply.lea.services.yms.task.locationaware.domain.registration.RegistrationTask;
 import eu.reply.lea.services.yms.task.sequence.AddTaskAction;
 import eu.reply.lea.services.yms.task.sequence.TasksSequence;
 import eu.reply.lea.services.yms.task.sequence.TransitTasksSequence;
 import eu.reply.lea.services.yms.task.sequence.TransitTasksSequenceHandler;
 import eu.reply.lea.services.yms.task.sequence.exception.TransitTaskSequenceException;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommand;
-import eu.reply.lea.services.yms.task.queue.event.TaskDequeueCommandInfo;
 import eu.reply.sce.backend.core.entity.configuration.Condition;
 import eu.reply.sce.backend.core.event.ConfigurableEventProducer;
 import eu.reply.sce.backend.core.jee.Context;
@@ -81,9 +78,6 @@
     @Inject
     private Context context;
 
-    @Inject
-    private ConfigurableEventProducer<TaskDequeueCommand> taskDequeueCommandProducer;
-
     @Getter
     @Inject
     private YardService yardService;
@@ -108,6 +102,9 @@
     @Inject
     private ConfigurableEventProducer<LocationAwareTaskEnterEvent> transitTaskEnterProducer;
 
+    @Inject
+    private TaskDequeueService taskDequeueService;
+
     /**
      * Trace message
      *
@@ -188,8 +185,7 @@
      */
     public T action(final T task, final ChangeLocationAction action)
         throws ChangeLocationException {
-        List<TaskReference> taskToDequeue = new ArrayList<>();
-        List<LocationReference> locationToDequeue = new ArrayList<>();
+        List<LocationAwareTask<?,?,?>> tasksToChangeLocation = new ArrayList<>();
         //Condition you can't have tasks that are dockpreparation or docking and the status is in progress and that are before the task
         //check child tasks not in status in progess.
         Boolean isThereAChildTaskStarted = task.getSequence().getTasks().stream().anyMatch(item -> item.getParentTaskId() != null && item.getParentTaskId().equals(task.getId())
@@ -201,16 +197,14 @@
         //for all the child task and the current task I dequeue them and then I change their location
         for (LocationAwareTask<?,?,?> transitTask : task.getSequence().getTasks()) {
             if ((transitTask.getParentTaskId() != null && transitTask.getParentTaskId().equals(task.getId())) || transitTask.getId().equals(task.getId())) {
-                taskToDequeue.add(new TaskReference(transitTask));
-                locationToDequeue.add(transitTask.getLocation());
-                transitTask.setLocation(action.getLocation());
-                locationAwareTaskHandler.blockTask(transitTask);
+                tasksToChangeLocation.add(transitTask);
             }
         }
-        taskDequeueCommandProducer.fire(new TaskDequeueCommand(
-            new TaskDequeueCommandInfo(taskToDequeue,
-                                       locationToDequeue,
-                                       new TransitReference(task.getLogisticUnitReference()))));
+        taskDequeueService.dequeueTasks(tasksToChangeLocation);
+        for (LocationAwareTask<?,?,?> taskToChangeLocation : tasksToChangeLocation){
+            taskToChangeLocation.setLocation(action.getLocation());
+            locationAwareTaskHandler.blockTask(taskToChangeLocation);
+        }
         return task;
     }
 
@@ -247,7 +241,7 @@
         removedTasks.addAll(removeChildrenTasks(task, sequence));
         removedTasks.add(task);
         sequenceHandler.removeTask(sequence, task);
-        fireDequeueCommand(removedTasks);
+        taskDequeueService.dequeueTasks(removedTasks);
         transitTaskRemovedFromSequenceEventProducer.fire(new TaskRemovedFromSequenceEvent(new LocationAwareTaskEventInfo(entityRefHandler.getEntityReference(getEm(), task),
                                                                                                                          task.getTaskType(), task.getStatus(),
                                                                                                                          task.getLogisticUnitReference(),
@@ -255,16 +249,6 @@
         return task;
     }
 
-    private void fireDequeueCommand(List<LocationAwareTask<?,?,?>> tasks) {
-        List<TaskReference> removedTasks = new ArrayList<>();
-        List<LocationReference> locationOfRemovedTask = new ArrayList<>();
-        for (LocationAwareTask<?,?,?> transitTask : tasks) {
-            removedTasks.add(new TaskReference(transitTask));
-            locationOfRemovedTask.add(transitTask.getLocation());
-        }
-        taskDequeueCommandProducer.fire(new TaskDequeueCommand(
-            new TaskDequeueCommandInfo(removedTasks, locationOfRemovedTask, new TransitReference(tasks.get(0).getLogisticUnitReference()))));
-    }
 
 
     private List<LocationAwareTask<?,?,?>> removeChildrenTasks(final T task, final TasksSequence<LocationAwareTask<?,?,?>>  sequence) throws TransitTaskSequenceException {
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/RemoveFromQueuedTasksObserver.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/RemoveFromQueuedTasksObserver.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/observer/RemoveFromQueuedTasksObserver.java	(date 1727425925450)
@@ -22,6 +22,6 @@
     public void handleTransitSequenceCreatedEvent(
         @Observes @ModuleEvent("taskDequeueCommand") final TaskDequeueCommandInfo event) {
         queueProcessTrackerService.startNewDequeueProcess(event.getTasks(), event
-            .getLocationReferences(), event.getTransitReference().toEntityReference());
+            .getLocationReferences(), event.getLogisticUnitRef());
     }
 }
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskDequeueCommandInfo.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskDequeueCommandInfo.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskDequeueCommandInfo.java
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskDequeueCommandInfo.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/queue/event/TaskDequeueCommandInfo.java	(date 1727425925450)
@@ -10,6 +10,7 @@
 import eu.reply.lea.services.masterdata.reference.LocationReference;
 import eu.reply.lea.services.yard.reference.TransitReference;
 import eu.reply.lea.services.yms.task.TaskReference;
+import eu.reply.sce.backend.core.entity.EntityReference;
 
 @NoArgsConstructor
 @Getter
@@ -20,14 +21,14 @@
 
     private List<TaskReference> tasks;
     private List<LocationReference> locationReferences;
-    private TransitReference transitReference;
+    private EntityReference logisticUnitRef;
 
     public TaskDequeueCommandInfo(final List<TaskReference> tasks,
                                   final List<LocationReference> locationReferences,
-                                  final TransitReference transitReference) {
+                                  final EntityReference logisticUnitRef) {
         this.tasks = tasks;
         this.locationReferences = locationReferences;
-        this.transitReference = transitReference;
+        this.logisticUnitRef = logisticUnitRef;
     }
 
 }
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskDequeueService.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskDequeueService.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskDequeueService.java
new file mode 100644
--- /dev/null	(date 1727426521097)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/locationaware/domain/TaskDequeueService.java	(date 1727426521097)
@@ -0,0 +1,17 @@
+package eu.reply.lea.services.yms.task.locationaware.domain;
+
+import java.util.List;
+
+/**
+ * Domain service responsible for handling the dequeuing of tasks.
+ */
+public interface TaskDequeueService {
+
+    /**
+     * Dequeues the given list of tasks.
+     *
+     * @param tasks the tasks to dequeue
+     */
+    void dequeueTasks(List<LocationAwareTask<?, ?, ?>> tasks);
+
+}
Index: lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
new file mode 100644
--- /dev/null	(date 1727427678838)
+++ b/lea-yms-application/src/test/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequenceTest.java	(date 1727427678838)
@@ -0,0 +1,169 @@
+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.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 LocationAwareTasksSequence} 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.getTasks();
+        }
+        // No additional implementation needed for testing
+    }
+
+    @Test
+    public void testAreAllTasksToBeExecutedContiguouslyClosed_AllClosed() {
+        // Arrange
+        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "5389423298"));
+
+        LocationAwareTask<?, ?, ?> task1 = mock(LocationAwareTask.class);
+        when(task1.getSequenceNumber()).thenReturn(1);
+        when(task1.getLocation()).thenReturn(location);
+        when(task1.getStatus()).thenReturn(TaskStatus.DONE);
+
+        LocationAwareTask<?, ?, ?> task2 = mock(LocationAwareTask.class);
+        when(task2.getSequenceNumber()).thenReturn(2);
+        when(task2.getLocation()).thenReturn(location);
+        when(task2.getStatus()).thenReturn(TaskStatus.DONE);
+
+        // Task in a different location
+        LocationAwareTask<?, ?, ?> task3 = mock(LocationAwareTask.class);
+        when(task3.getSequenceNumber()).thenReturn(3);
+        when(task3.getLocation()).thenReturn(new LocationReference(new EntityReference("masterdata", "dock", "53894527398")));
+        when(task3.getStatus()).thenReturn(TaskStatus.TODO);
+
+        // Create sequence and add tasks
+        AbstractTasksSequence sequence = new TestTasksSequence();
+        sequence.addTask(task1);
+        sequence.addTask(task2);
+        sequence.addTask(task3);
+
+        // Act
+        boolean result = sequence.areAllTasksToBeExecutedContiguouslyClosed(task1);
+
+        // Assert
+        assertTrue("All contiguous tasks in the same location are closed", result);
+    }
+
+    @Test
+    public void testAreAllTasksToBeExecutedContiguouslyClosed_NotAllClosed() {
+        // Arrange
+        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "53894527398"));
+
+        LocationAwareTask<?, ?, ?> task1 = mock(LocationAwareTask.class);
+        when(task1.getSequenceNumber()).thenReturn(1);
+        when(task1.getLocation()).thenReturn(location);
+        when(task1.getStatus()).thenReturn(TaskStatus.DONE);
+
+        LocationAwareTask<?, ?, ?> task2 = mock(LocationAwareTask.class);
+        when(task2.getSequenceNumber()).thenReturn(2);
+        when(task2.getLocation()).thenReturn(location);
+        when(task2.getStatus()).thenReturn(TaskStatus.TODO);
+
+        // Create sequence and add tasks
+        AbstractTasksSequence sequence = new TestTasksSequence();
+        sequence.addTask(task1);
+        sequence.addTask(task2);
+
+        // Act
+        boolean result = sequence.areAllTasksToBeExecutedContiguouslyClosed(task1);
+
+        // Assert
+        assertFalse("Not all contiguous tasks in the same location are closed", result);
+    }
+
+    @Test
+    public void testGetTasksToBeExecutedContiguously() {
+        // Arrange
+        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "53894527398"));
+
+        // Task sequence: [task1, task2, task3, task4]
+        LocationAwareTask<?, ?, ?> task1 = mock(LocationAwareTask.class);
+        when(task1.getSequenceNumber()).thenReturn(1);
+        when(task1.getLocation()).thenReturn(location);
+
+        LocationAwareTask<?, ?, ?> task2 = mock(LocationAwareTask.class);
+        when(task2.getSequenceNumber()).thenReturn(2);
+        when(task2.getLocation()).thenReturn(location);
+
+        // Gap in sequence numbers to simulate non-contiguous tasks
+        LocationAwareTask<?, ?, ?> task3 = mock(LocationAwareTask.class);
+        when(task3.getSequenceNumber()).thenReturn(4);
+        when(task3.getLocation()).thenReturn(location);
+
+        LocationAwareTask<?, ?, ?> task4 = mock(LocationAwareTask.class);
+        when(task4.getSequenceNumber()).thenReturn(5);
+        when(task4.getLocation()).thenReturn(location);
+
+        // Create sequence and add tasks
+        AbstractTasksSequence sequence = new TestTasksSequence();
+        sequence.addTask(task1);
+        sequence.addTask(task2);
+        sequence.addTask(task3);
+        sequence.addTask(task4);
+
+        // Act
+        List<LocationAwareTask<?, ?, ?>> contiguousTasks = sequence.getTasksToBeExecutedContiguously(task1);
+
+        // Assert
+        assertEquals("Contiguous tasks should include task1 and task2", 2, contiguousTasks.size());
+        assertTrue("Contiguous tasks should contain task1", contiguousTasks.contains(task1));
+        assertTrue("Contiguous tasks should contain task2", contiguousTasks.contains(task2));
+        assertFalse("Contiguous tasks should not contain task3", contiguousTasks.contains(task3));
+        assertFalse("Contiguous tasks should not contain task4", contiguousTasks.contains(task4));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testGetTasksToBeExecutedContiguously_NoTasksInLocation() {
+        // Arrange
+        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "53894527398"));
+
+        // No tasks in the sequence
+        AbstractTasksSequence sequence = new TestTasksSequence();
+
+        // Act
+        sequence.getTasksToBeExecutedContiguously(mock(LocationAwareTask.class));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testGetTasksToBeExecutedContiguously_TaskNotFound() {
+        // Arrange
+        LocationReference location = new LocationReference(new EntityReference("masterdata", "dock", "53894527398"));
+
+        LocationAwareTask<?, ?, ?> task1 = mock(LocationAwareTask.class);
+        when(task1.getSequenceNumber()).thenReturn(1);
+        when(task1.getLocation()).thenReturn(location);
+
+        AbstractTasksSequence sequence = new TestTasksSequence();
+        sequence.addTask(task1);
+
+        LocationAwareTask<?, ?, ?> taskNotInSequence = mock(LocationAwareTask.class);
+        when(taskNotInSequence.getSequenceNumber()).thenReturn(99);
+        when(taskNotInSequence.getLocation()).thenReturn(location);
+
+        // Act
+        sequence.getTasksToBeExecutedContiguously(taskNotInSequence);
+    }
+
+}
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
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
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/sequence/LocationAwareTasksSequence.java	(date 1727426618811)
@@ -2,6 +2,12 @@
 
 import java.util.List;
 
+import eu.reply.lea.services.masterdata.reference.LocationReference;
+import eu.reply.lea.services.yms.task.locationaware.domain.LocationAwareTask;
+
+/**
+ * Interface representing a sequence of location-aware tasks.
+ */
 public interface LocationAwareTasksSequence<I extends SequencedLocationAwareTask> extends TasksSequence<I> {
 
     /**
@@ -39,4 +45,43 @@
      * Retrieves the list of tasks that should be enqueued next.
      */
     List<I> getTasksToBeEnqueuedNext();
+
+    /**
+     * Retrieves the list of queueable tasks.
+     *
+     * @return list of queueable tasks
+     */
+    List<I> getQueueableTasks();
+
+    /**
+     * Determines if all tasks to be executed contiguously starting from the given task are closed.
+     *
+     * @param task the starting task
+     * @return true if all contiguous tasks are closed; false otherwise
+     */
+    boolean areAllTasksToBeExecutedContiguouslyClosed(final I task);
+
+    /**
+     * Retrieves the list of tasks to be executed contiguously starting from the given task.
+     *
+     * @param task the starting task
+     * @return list of contiguous tasks
+     */
+    List<I> getTasksToBeExecutedContiguously(I task);
+
+    /**
+     * Retrieves the tasks associated with the specified location.
+     *
+     * @param location the location reference
+     * @return list of tasks in the given location
+     */
+    List<I> getTasksInLocation(final LocationReference location);
+
+    /**
+     * 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);
 }
Index: lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/TaskReference.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/TaskReference.java b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/TaskReference.java
--- a/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/TaskReference.java	(revision b02d2364bcee38ae3f32920f38c9bf2e1421f2c4)
+++ b/lea-yms-application/src/main/java/eu/reply/lea/services/yms/task/TaskReference.java	(date 1727425925448)
@@ -22,6 +22,10 @@
     public TaskReference(final String module, final String entityName, final String entityId, final String businessKey) {
         super(module, entityName, entityId, businessKey);
     }
+    public TaskReference(final EntityReference entityReference) {
+        super(entityReference.getModule(), entityReference.getEntityName(), entityReference.getEntityId(), entityReference.getBusinessKey());
+    }
+
 
     @Override
     public TypedEntityReference<Task> clone() {


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

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import eu.reply.lea.services.masterdata.reference.LocationReference;
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;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(indexes = {
    @Index(columnList = "logisticUnitRef_entityId,logisticUnitRef_module,logisticUnitRef_entityName"),
})
@NamedQuery(name = AbstractTasksSequence.Q_FIND_BY_LOGISTIC_UNIT_REF, query = "SELECT ats from AbstractTasksSequence ats where "
                                                                              + "logisticUnitRef.entityId = :logisticUnitEntityId "
                                                                              + "and logisticUnitRef.entityName = :logisticUnitRefEntityName "
                                                                              + "and logisticUnitRef.module = :logisticUnitRefModule")
@Getter
@Setter
public abstract class AbstractTasksSequence extends StringCustomizableEntity
    implements LocationAwareTasksSequence<LocationAwareTask<?, ?, ?>> {

    public static final String Q_FIND_BY_LOGISTIC_UNIT_REF = "AbstractTasksSequence.Q_FIND_BY_LOGISTIC_UNIT_REF";


    @OneToMany(fetch = FetchType.LAZY, mappedBy = "sequence")
    @OrderBy("sequenceNumber ASC")
    private final List<LocationAwareTask<?, ?, ?>> tasks = new ArrayList<>();



    @Embedded
    @AttributeOverrides({@AttributeOverride(name = "entityId", column = @Column(name = "logisticUnitRef_entityId", length = 50)),
        @AttributeOverride(name = "entityName", column = @Column(name = "logisticUnitRef_entityName")),
        @AttributeOverride(name = "module", column = @Column(name = "logisticUnitRef_module", length = 20)),
        @AttributeOverride(name = "businessKey", column = @Column(name = "logisticUnitRef_businessKey")),
        @AttributeOverride(name = "usageType", column = @Column(name = "logisticUnitRef_usageType"))
    })
    private EntityReference logisticUnitRef;

    private boolean blocked = false;

    public List<LocationAwareTask<?, ?, ?>> getTasks() {
        return Collections.unmodifiableList(tasks);
    }

    public boolean addTask(final LocationAwareTask<?, ?, ?> task) {

        if (this.addChild(task, tasks)) {
            task.setSequence(this);
            return true;
        }
        return false;
    }

    public boolean removeTask(final LocationAwareTask<?, ?, ?> task) {
        if (this.removeChild(task, tasks)) {
            task.setSequence(null);
            return true;
        }
        return false;
    }

    @JsonIgnore
    public boolean isAllTasksClosed() {
        return getTasks().stream().allMatch(task -> task.getStatus().isClosed());
    }

    @JsonIgnore
    public List<LocationAwareTask<?, ?, ?>> getSortedSequence() {
        final List<LocationAwareTask<?, ?, ?>> sortedList = this.getTasks().stream().sorted((t1, t2) -> {
            return t1.getSequenceNumber().compareTo(t2.getSequenceNumber());
        }).collect(Collectors.toList());
        return sortedList;
    }

    @JsonIgnore
    protected List<LocationAwareTask<?, ?, ?>> getQueueableTasks(List<LocationAwareTask<?, ?, ?>> sortedSequence, int sequenceNumber,
                                                        boolean inclusive) {
        List<LocationAwareTask<?, ?, ?>> nextTasksQueueable = sortedSequence.stream()
            .filter(t -> inclusive ? t.getSequenceNumber() >= sequenceNumber
                                   : t.getSequenceNumber() > sequenceNumber)
            .filter(LocationAwareTask::isQueueable)
            .collect(Collectors.toList());


        return nextTasksQueueable;
    }

    @JsonIgnore
    public List<LocationAwareTask<?, ?, ?>> getActiveTasks() {
        return this.getTasks().stream()
            .filter(t -> t.getStatus().isActive())
            .collect(Collectors.toList());
    }

    @Override
    @JsonIgnore
    public List<LocationAwareTask<?, ?, ?>> getQueueableTasks() {
        List<LocationAwareTask<?, ?, ?>> sortedSequence = getSortedSequence();
        return getQueueableTasks(sortedSequence, 0, true);
    }

    @Override
    public boolean areAllTasksToBeExecutedContiguouslyClosed(final LocationAwareTask<?, ?, ?> task) {
        return getTasksToBeExecutedContiguously(task).stream().allMatch(t -> t.getStatus().isClosed());
    }

    @Override
    @JsonIgnore
    public List<LocationAwareTask<?, ?, ?>> getTasksToBeExecutedContiguously(final LocationAwareTask<?, ?, ?> task) {
        LocationReference location = task.getLocation();
        List<LocationAwareTask<?, ?, ?>> tasksSameLocation = sortTasks(getTasksInLocation(location));
        List<LocationAwareTask<?, ?, ?>> result = new ArrayList<>();
        if (tasksSameLocation.isEmpty()) {
            throw new IllegalStateException(String.format("There are no tasks in the location %s", location));
        }
        if (tasksSameLocation.stream().noneMatch(t->t.equals(task))) {
            throw new IllegalStateException(String.format("It was not possible to find the tasks among"
                                                          + "the ones of the sequence for the specified"
                                                          + "location %s", location));
        }
        Integer taskSequenceNumber = task.getSequenceNumber();
        boolean foundTask = false;
        int previousSequenceNumber = tasksSameLocation.get(0).getSequenceNumber();
        for (LocationAwareTask<?, ?, ?> taskSameLocation : tasksSameLocation) {
            if (taskSameLocation.getSequenceNumber().equals(taskSequenceNumber)) {
                foundTask = true;
            }
            if (taskSameLocation.getSequenceNumber() > previousSequenceNumber+1) {
                if (foundTask) {
                    return result;
                }else{
                    result.clear();
                }
            }
            previousSequenceNumber = taskSameLocation.getSequenceNumber();
            result.add(taskSameLocation);
        }
        if (foundTask){
            return result;
        }
        throw new IllegalStateException(String.format("No tasks were found for location %s and task %s", location, task));
    }


    @JsonIgnore
    public List<LocationAwareTask<?, ?, ?>> getTasksInLocation(final LocationReference location) {
        return this.getTasks().stream()
            .filter(task -> location.equals(task.getLocation()))
            .collect(Collectors.toList());
    }

    @Override
    public List<LocationAwareTask<?, ?, ?>> sortTasks(final List<LocationAwareTask<?, ?, ?>> tasks) {
        return tasks.stream().sorted(Comparator.comparing(LocationAwareTask::getSequenceNumber)).collect(Collectors.toList());
    }
    }
Can you provide tests? or maybe improve the ones present, because not all work correcly.
also if you have suggestion on how to change to make it more DDD