Exercise 8 PR #95
|
@ -68,6 +68,15 @@
|
||||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
<version>1.2.5</version>
|
<version>1.2.5</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
|
<version>3.2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package ch.unisg.executorpool.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ExecutorMapper {
|
||||||
|
|
||||||
|
ExecutorClass mapToDomainEntity(MongoExecutorDocument executorClass) {
|
||||||
|
try {
|
||||||
|
return new ExecutorClass(
|
||||||
|
new ExecutorClass.ExecutorUri(new URI(executorClass.executorUri)),
|
||||||
|
new ExecutorClass.ExecutorTaskType(executorClass.executorTaskType)
|
||||||
|
);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MongoExecutorDocument mapToMongoDocument(ExecutorClass executorClass) {
|
||||||
|
return new MongoExecutorDocument(executorClass.getExecutorUri().getValue().toString(),
|
||||||
|
executorClass.getExecutorTaskType().getValue()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package ch.unisg.executorpool.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import ch.unisg.executorpool.application.port.out.AddExecutorPort;
|
||||||
|
import ch.unisg.executorpool.application.port.out.LoadExecutorPort;
|
||||||
|
import ch.unisg.executorpool.application.port.out.RemoveExecutorPort;
|
||||||
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ExecutorPersistenceAdapter implements AddExecutorPort, RemoveExecutorPort, LoadExecutorPort {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final ExecutorRepository executorRepository;
|
||||||
|
|
||||||
|
private final ExecutorMapper executorMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addExecutor(ExecutorClass executorClass) {
|
||||||
|
MongoExecutorDocument mongoExecutorDocument = executorMapper.mapToMongoDocument(executorClass);
|
||||||
|
executorRepository.save(mongoExecutorDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeExecutor(ExecutorClass executorClass) {
|
||||||
|
MongoExecutorDocument mongoExecutorDocument = executorMapper.mapToMongoDocument(executorClass);
|
||||||
|
executorRepository.delete(mongoExecutorDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExecutorClass loadExecutor(ExecutorClass.ExecutorUri executorUri, ExecutorClass.ExecutorTaskType executorTaskType) {
|
||||||
|
MongoExecutorDocument mongoExecutorDocument = executorRepository.findByExecutorUri(executorUri.getValue().toString(), executorTaskType.getValue());
|
||||||
|
ExecutorClass executorClass = executorMapper.mapToDomainEntity(mongoExecutorDocument);
|
||||||
|
return executorClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package ch.unisg.executorpool.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ExecutorRepository extends MongoRepository<MongoExecutorDocument, String> {
|
||||||
|
|
||||||
|
public MongoExecutorDocument findByExecutorUri(String executorUri, String executorTaskType);
|
||||||
|
|
||||||
|
public List<MongoExecutorDocument> findByExecutorTaskType(String executorTaskType);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ch.unisg.executorpool.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MongoExecutorDocument {
|
||||||
|
|
||||||
|
public String executorUri;
|
||||||
|
public String executorTaskType;
|
||||||
|
|
||||||
|
public MongoExecutorDocument(String executorUri, String executorTaskType) {
|
||||||
|
|
||||||
|
this.executorUri = executorUri;
|
||||||
|
this.executorTaskType = executorTaskType;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ch.unisg.executorpool.application.port.out;
|
||||||
|
|
||||||
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
|
|
||||||
|
public interface AddExecutorPort {
|
||||||
|
|
||||||
|
void addExecutor(ExecutorClass executorClass);
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package ch.unisg.executorpool.application.port.out;
|
package ch.unisg.executorpool.application.port.out;
|
||||||
|
|
||||||
import ch.unisg.executorpool.domain.ExecutorAddedEvent;
|
import ch.unisg.executorpool.domain.ExecutorAddedEvent;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
||||||
|
|
||||||
public interface ExecutorAddedEventPort {
|
public interface ExecutorAddedEventPort {
|
||||||
void publishExecutorAddedEvent(ExecutorAddedEvent event);
|
void publishExecutorAddedEvent(ExecutorAddedEvent event);
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ch.unisg.executorpool.application.port.out;
|
||||||
|
|
||||||
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
|
|
||||||
|
public interface LoadExecutorPort {
|
||||||
|
|
||||||
|
ExecutorClass loadExecutor(ExecutorClass.ExecutorUri executorUri, ExecutorClass.ExecutorTaskType executorTaskType);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ch.unisg.executorpool.application.port.out;
|
||||||
|
|
||||||
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
|
|
||||||
|
public interface RemoveExecutorPort {
|
||||||
|
|
||||||
|
void removeExecutor(ExecutorClass executorClass);
|
||||||
|
|
||||||
|
}
|
|
@ -2,11 +2,11 @@ package ch.unisg.executorpool.application.service;
|
||||||
|
|
||||||
import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolUseCase;
|
import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolUseCase;
|
||||||
import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolCommand;
|
import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolCommand;
|
||||||
|
import ch.unisg.executorpool.application.port.out.AddExecutorPort;
|
||||||
import ch.unisg.executorpool.application.port.out.ExecutorAddedEventPort;
|
import ch.unisg.executorpool.application.port.out.ExecutorAddedEventPort;
|
||||||
import ch.unisg.executorpool.domain.ExecutorAddedEvent;
|
import ch.unisg.executorpool.domain.ExecutorAddedEvent;
|
||||||
import ch.unisg.executorpool.domain.ExecutorClass;
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
import ch.unisg.executorpool.domain.ExecutorPool;
|
import ch.unisg.executorpool.domain.ExecutorPool;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
@ -16,9 +16,11 @@ import javax.transaction.Transactional;
|
||||||
public class AddNewExecutorToExecutorPoolService implements AddNewExecutorToExecutorPoolUseCase {
|
public class AddNewExecutorToExecutorPoolService implements AddNewExecutorToExecutorPoolUseCase {
|
||||||
|
|
||||||
private final ExecutorAddedEventPort executorAddedEventPort;
|
private final ExecutorAddedEventPort executorAddedEventPort;
|
||||||
|
private final AddExecutorPort addExecutorToRepositoryPort;
|
||||||
|
|
||||||
public AddNewExecutorToExecutorPoolService(ExecutorAddedEventPort executorAddedEventPort){
|
public AddNewExecutorToExecutorPoolService(ExecutorAddedEventPort executorAddedEventPort, AddExecutorPort addExecutorToRepositoryPort){
|
||||||
this.executorAddedEventPort = executorAddedEventPort;
|
this.executorAddedEventPort = executorAddedEventPort;
|
||||||
|
this.addExecutorToRepositoryPort = addExecutorToRepositoryPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,6 +31,8 @@ public class AddNewExecutorToExecutorPoolService implements AddNewExecutorToExec
|
||||||
var executorAddedEvent = new ExecutorAddedEvent(newExecutor);
|
var executorAddedEvent = new ExecutorAddedEvent(newExecutor);
|
||||||
executorAddedEventPort.publishExecutorAddedEvent(executorAddedEvent);
|
executorAddedEventPort.publishExecutorAddedEvent(executorAddedEvent);
|
||||||
|
|
||||||
|
addExecutorToRepositoryPort.addExecutor(newExecutor);
|
||||||
|
|
||||||
return newExecutor;
|
return newExecutor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ package ch.unisg.executorpool.application.service;
|
||||||
import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolCommand;
|
import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolCommand;
|
||||||
import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolUseCase;
|
import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolUseCase;
|
||||||
import ch.unisg.executorpool.application.port.out.ExecutorRemovedEventPort;
|
import ch.unisg.executorpool.application.port.out.ExecutorRemovedEventPort;
|
||||||
|
import ch.unisg.executorpool.application.port.out.RemoveExecutorPort;
|
||||||
import ch.unisg.executorpool.domain.ExecutorClass;
|
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||||
import ch.unisg.executorpool.domain.ExecutorPool;
|
import ch.unisg.executorpool.domain.ExecutorPool;
|
||||||
import ch.unisg.executorpool.domain.ExecutorRemovedEvent;
|
import ch.unisg.executorpool.domain.ExecutorRemovedEvent;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
@ -17,9 +17,11 @@ import java.util.Optional;
|
||||||
public class RemoveExecutorFromExecutorPoolService implements RemoveExecutorFromExecutorPoolUseCase {
|
public class RemoveExecutorFromExecutorPoolService implements RemoveExecutorFromExecutorPoolUseCase {
|
||||||
|
|
||||||
private final ExecutorRemovedEventPort executorRemovedEventPort;
|
private final ExecutorRemovedEventPort executorRemovedEventPort;
|
||||||
|
private final RemoveExecutorPort removeExecutorFromRepositoryPort;
|
||||||
|
|
||||||
public RemoveExecutorFromExecutorPoolService(ExecutorRemovedEventPort executorRemovedEventPort){
|
public RemoveExecutorFromExecutorPoolService(ExecutorRemovedEventPort executorRemovedEventPort, RemoveExecutorPort removeExecutorFromRepositoryPort){
|
||||||
this.executorRemovedEventPort = executorRemovedEventPort;
|
this.executorRemovedEventPort = executorRemovedEventPort;
|
||||||
|
this.removeExecutorFromRepositoryPort = removeExecutorFromRepositoryPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,6 +34,8 @@ public class RemoveExecutorFromExecutorPoolService implements RemoveExecutorFrom
|
||||||
executorRemovedEventPort.publishExecutorRemovedEvent(executorRemovedEvent);
|
executorRemovedEventPort.publishExecutorRemovedEvent(executorRemovedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeExecutorFromRepositoryPort.removeExecutor(removedExecutor);
|
||||||
|
|
||||||
return removedExecutor;
|
return removedExecutor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package ch.unisg.executorpool.domain;
|
package ch.unisg.executorpool.domain;
|
||||||
|
|
||||||
import ch.unisg.executorpool.domain.ExecutorClass;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public class ExecutorRemovedEvent {
|
public class ExecutorRemovedEvent {
|
||||||
|
|
|
@ -73,6 +73,10 @@
|
||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package ch.unisg.roster;
|
package ch.unisg.roster;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.adapter.out.persistence.mongodb.RosterRepository;
|
||||||
|
import ch.unisg.roster.roster.application.port.in.LoadRosterItemPort;
|
||||||
|
import ch.unisg.roster.roster.domain.Roster;
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@ -11,19 +16,24 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import ch.unisg.roster.roster.adapter.common.clients.TapasMqttClient;
|
import ch.unisg.roster.roster.adapter.common.clients.TapasMqttClient;
|
||||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventMqttListener;
|
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventMqttListener;
|
||||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventsMqttDispatcher;
|
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventsMqttDispatcher;
|
||||||
|
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableMongoRepositories(basePackageClasses = RosterRepository.class)
|
||||||
public class RosterApplication {
|
public class RosterApplication {
|
||||||
|
|
||||||
static Logger logger = Logger.getLogger(RosterApplication.class.getName());
|
static Logger logger = Logger.getLogger(RosterApplication.class.getName());
|
||||||
|
|
||||||
private static ConfigurableEnvironment ENVIRONMENT;
|
private static ConfigurableEnvironment ENVIRONMENT;
|
||||||
|
|
||||||
|
private static final LoadRosterItemPort loadRosterItemPort;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SpringApplication rosterApp = new SpringApplication(RosterApplication.class);
|
SpringApplication rosterApp = new SpringApplication(RosterApplication.class);
|
||||||
ENVIRONMENT = rosterApp.run(args).getEnvironment();
|
ENVIRONMENT = rosterApp.run(args).getEnvironment();
|
||||||
bootstrapMarketplaceWithMqtt();
|
bootstrapMarketplaceWithMqtt();
|
||||||
|
initialiseRoster();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,4 +52,9 @@ public class RosterApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void initialiseRoster(){
|
||||||
|
List<RosterItem> rosterItemList = loadRosterItemPort.loadAllRosterItems();
|
||||||
|
Roster.getInstance().initialiseRoster(rosterItemList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package ch.unisg.roster.roster.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Document(collection="roster")
|
||||||
|
public class MongoRosterDocument {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
public String taskId;
|
||||||
|
public String taskType;
|
||||||
|
public String executorURI;
|
||||||
|
|
||||||
|
public MongoRosterDocument(String taskId, String taskType, String executorURI){
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.taskType = taskType;
|
||||||
|
this.executorURI = executorURI;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package ch.unisg.roster.roster.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.unisg.common.valueobject.ExecutorURI;
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RosterMapper {
|
||||||
|
|
||||||
|
RosterItem maptoDomainEntity(MongoRosterDocument rosterItem) {
|
||||||
|
return new RosterItem(rosterItem.taskId, rosterItem.taskType,
|
||||||
|
new ExecutorURI(rosterItem.executorURI));
|
||||||
|
}
|
||||||
|
|
||||||
|
MongoRosterDocument mapToMongoDocument(RosterItem rosterItem){
|
||||||
|
return new MongoRosterDocument(
|
||||||
|
rosterItem.getTaskID(),
|
||||||
|
rosterItem.getTaskType(),
|
||||||
|
rosterItem.getExecutorURI().getValue().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package ch.unisg.roster.roster.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.application.port.in.AddRosterItemPort;
|
||||||
|
import ch.unisg.roster.roster.application.port.in.DeleteRosterItem;
|
||||||
|
import ch.unisg.roster.roster.application.port.in.LoadRosterItemPort;
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class RosterPersistenceAdapter implements AddRosterItemPort, LoadRosterItemPort, DeleteRosterItem {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final RosterRepository rosterRepository;
|
||||||
|
private final RosterMapper rosterMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRosterItem(RosterItem rosterItem){
|
||||||
|
MongoRosterDocument mongoRosterDocument = rosterMapper.mapToMongoDocument(rosterItem);
|
||||||
|
rosterRepository.save(mongoRosterDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RosterItem loadRosterItem(String taskId){
|
||||||
|
MongoRosterDocument mongoRosterDocument = rosterRepository.findByTaskId(taskId);
|
||||||
|
RosterItem rosterItem = rosterMapper.maptoDomainEntity(mongoRosterDocument);
|
||||||
|
return rosterItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RosterItem> loadAllRosterItems(){
|
||||||
|
List<MongoRosterDocument> rosterList = rosterRepository.findAll();
|
||||||
|
List<RosterItem> rosterItemList = new ArrayList<>();
|
||||||
|
for(MongoRosterDocument rosterDocument : rosterList){
|
||||||
|
rosterItemList.add(rosterMapper.maptoDomainEntity(rosterDocument));
|
||||||
|
}
|
||||||
|
return rosterItemList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteRosterItem(String taskId){
|
||||||
|
rosterRepository.deleteById(taskId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ch.unisg.roster.roster.adapter.out.persistence.mongodb;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface RosterRepository extends MongoRepository<MongoRosterDocument,String>{
|
||||||
|
public MongoRosterDocument findByTaskId(String taskId);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ch.unisg.roster.roster.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
|
|
||||||
|
public interface AddRosterItemPort {
|
||||||
|
|
||||||
|
void addRosterItem(RosterItem rosterItem);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package ch.unisg.roster.roster.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
|
|
||||||
|
public interface DeleteRosterItem {
|
||||||
|
|
||||||
|
void deleteRosterItem(String taskId);
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package ch.unisg.roster.roster.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface LoadRosterItemPort {
|
||||||
|
|
||||||
|
RosterItem loadRosterItem(String taskId);
|
||||||
|
|
||||||
|
List<RosterItem> loadAllRosterItems();
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ package ch.unisg.roster.roster.application.service;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.application.port.in.AddRosterItemPort;
|
||||||
|
import ch.unisg.roster.roster.domain.RosterItem;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskCommand;
|
import ch.unisg.roster.roster.application.port.in.ApplyForTaskCommand;
|
||||||
|
@ -18,6 +20,7 @@ import lombok.RequiredArgsConstructor;
|
||||||
public class ApplyForTaskService implements ApplyForTaskUseCase {
|
public class ApplyForTaskService implements ApplyForTaskUseCase {
|
||||||
|
|
||||||
private final TaskAssignedEventPort taskAssignedEventPort;
|
private final TaskAssignedEventPort taskAssignedEventPort;
|
||||||
|
private final AddRosterItemPort addRosterItemPort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a task is available and assignes it to the executor. If task got assigned a task
|
* Checks if a task is available and assignes it to the executor. If task got assigned a task
|
||||||
|
@ -31,6 +34,7 @@ public class ApplyForTaskService implements ApplyForTaskUseCase {
|
||||||
|
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
taskAssignedEventPort.publishTaskAssignedEvent(new TaskAssignedEvent(task.getTaskID()));
|
taskAssignedEventPort.publishTaskAssignedEvent(new TaskAssignedEvent(task.getTaskID()));
|
||||||
|
addRosterItemPort.addRosterItem(new RosterItem(task.getTaskID(), task.getTaskType().getValue(), command.getExecutorURI()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ch.unisg.roster.roster.application.service;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import ch.unisg.roster.roster.application.port.in.DeleteRosterItem;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import ch.unisg.roster.roster.application.port.in.TaskCompletedCommand;
|
import ch.unisg.roster.roster.application.port.in.TaskCompletedCommand;
|
||||||
|
@ -17,6 +18,7 @@ import lombok.RequiredArgsConstructor;
|
||||||
public class TaskCompletedService implements TaskCompletedUseCase {
|
public class TaskCompletedService implements TaskCompletedUseCase {
|
||||||
|
|
||||||
private final TaskCompletedEventPort taskCompletedEventPort;
|
private final TaskCompletedEventPort taskCompletedEventPort;
|
||||||
|
private final DeleteRosterItem deleteRosterItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completes the task in the roster and publishes a task completed event.
|
* Completes the task in the roster and publishes a task completed event.
|
||||||
|
@ -26,6 +28,7 @@ public class TaskCompletedService implements TaskCompletedUseCase {
|
||||||
public void taskCompleted(TaskCompletedCommand command) {
|
public void taskCompleted(TaskCompletedCommand command) {
|
||||||
|
|
||||||
Roster.getInstance().taskCompleted(command.getTaskID());
|
Roster.getInstance().taskCompleted(command.getTaskID());
|
||||||
|
deleteRosterItem.deleteRosterItem(command.getTaskID());
|
||||||
|
|
||||||
taskCompletedEventPort.publishTaskCompleted(new TaskCompletedEvent(command.getTaskID(),
|
taskCompletedEventPort.publishTaskCompleted(new TaskCompletedEvent(command.getTaskID(),
|
||||||
command.getTaskStatus(), command.getTaskResult()));
|
command.getTaskStatus(), command.getTaskResult()));
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ch.unisg.roster.roster.domain;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -83,4 +84,10 @@ public class Roster {
|
||||||
return queues.get(taskType.getValue()).removeIf(task -> task.getTaskID().equalsIgnoreCase(taskID));
|
return queues.get(taskType.getValue()).removeIf(task -> task.getTaskID().equalsIgnoreCase(taskID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initialiseRoster(List<RosterItem> rosterItemList){
|
||||||
|
for(RosterItem rosterItem : rosterItemList){
|
||||||
|
rosterMap.put(rosterItem.getTaskID(), rosterItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,8 @@ public class RosterItem {
|
||||||
this.executorURI = executorURI;
|
this.executorURI = executorURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RosterItem withIDTypeExecutorURI(String taskId, String taskType,
|
||||||
|
ExecutorURI executorURI){
|
||||||
|
return new RosterItem(taskId, taskType, executorURI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user