3245 Create project in Daisy at course start (from idea) instead of waiting on the daily sync
This commit is contained in:
parent
6b6c535e97
commit
9ede3a270d
core/src/main/java/se/su/dsv/scipro
daisy-integration/src/main/java/se/su/dsv/scipro/integration/daisy
view/src/test/java/se/su/dsv/scipro/workerthreads
@ -0,0 +1,8 @@
|
||||
package se.su.dsv.scipro.match;
|
||||
|
||||
class AllowAllIdeaCreationJudge implements IdeaCreationJudge {
|
||||
@Override
|
||||
public Decision ruling(Idea idea) {
|
||||
return Decision.allowed();
|
||||
}
|
||||
}
|
@ -3,19 +3,25 @@ package se.su.dsv.scipro.match;
|
||||
public final class Decision {
|
||||
private final boolean allowed;
|
||||
private final String reason;
|
||||
private final Integer identifier;
|
||||
|
||||
private Decision(final boolean allowed, final String reason) {
|
||||
private Decision(final boolean allowed, final String reason, Integer identifier) {
|
||||
|
||||
this.allowed = allowed;
|
||||
this.reason = reason;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public static Decision allowed() {
|
||||
return new Decision(true, "");
|
||||
return allowed(null);
|
||||
}
|
||||
|
||||
public static Decision allowed(Integer identifier) {
|
||||
return new Decision(true, "", identifier);
|
||||
}
|
||||
|
||||
public static Decision denied(String reason) {
|
||||
return new Decision(false, reason);
|
||||
return new Decision(false, reason, null);
|
||||
}
|
||||
|
||||
public boolean isAllowed() {
|
||||
@ -25,4 +31,8 @@ public final class Decision {
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public Integer getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package se.su.dsv.scipro.match;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.multibindings.Multibinder;
|
||||
import com.google.inject.multibindings.OptionalBinder;
|
||||
|
||||
public class MatchModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Multibinder.newSetBinder(binder(), IdeaCreationJudge.class);
|
||||
OptionalBinder.newOptionalBinder(binder(), IdeaCreationJudge.class)
|
||||
.setDefault().to(AllowAllIdeaCreationJudge.class);
|
||||
bind(ProjectStartNotifier.class).asEagerSingleton();
|
||||
bind(AddActivityPlanOnProjectStart.class).asEagerSingleton();
|
||||
bind(ApplicationPeriodService.class).to(ApplicationPeriodServiceImpl.class);
|
||||
|
@ -27,7 +27,7 @@ public class IdeaExportWorker extends AbstractWorker {
|
||||
private final IdeaService ideaService;
|
||||
private final MailEventService mailService;
|
||||
private final ProjectService projectService;
|
||||
private final Set<IdeaCreationJudge> ideaCreationJudges;
|
||||
private final IdeaCreationJudge ideaCreationJudge;
|
||||
private final EventBus eventBus;
|
||||
private final FirstMeetingService firstMeetingService;
|
||||
|
||||
@ -35,14 +35,14 @@ public class IdeaExportWorker extends AbstractWorker {
|
||||
public IdeaExportWorker(final IdeaService ideaService,
|
||||
final MailEventService mailService,
|
||||
final ProjectService projectService,
|
||||
final Set<IdeaCreationJudge> ideaCreationJudges,
|
||||
final IdeaCreationJudge ideaCreationJudge,
|
||||
final EventBus eventBus,
|
||||
final FirstMeetingService firstMeetingService)
|
||||
{
|
||||
this.ideaService = ideaService;
|
||||
this.mailService = mailService;
|
||||
this.projectService = projectService;
|
||||
this.ideaCreationJudges = ideaCreationJudges;
|
||||
this.ideaCreationJudge = ideaCreationJudge;
|
||||
this.eventBus = eventBus;
|
||||
this.firstMeetingService = firstMeetingService;
|
||||
}
|
||||
@ -55,7 +55,7 @@ public class IdeaExportWorker extends AbstractWorker {
|
||||
Decision decision = isAllowedToStart(idea);
|
||||
if (decision.isAllowed()) {
|
||||
allow(idea);
|
||||
createProject(idea);
|
||||
createProject(idea, decision.getIdentifier());
|
||||
eventBus.post(new ProjectStartedEvent(idea));
|
||||
} else {
|
||||
deny(idea, decision.getReason());
|
||||
@ -74,13 +74,7 @@ public class IdeaExportWorker extends AbstractWorker {
|
||||
}
|
||||
|
||||
private Decision isAllowedToStart(final Idea idea) {
|
||||
for (IdeaCreationJudge ideaCreationJudge : ideaCreationJudges) {
|
||||
Decision decision = ideaCreationJudge.ruling(idea);
|
||||
if (!decision.isAllowed()) {
|
||||
return decision;
|
||||
}
|
||||
}
|
||||
return Decision.allowed();
|
||||
return ideaCreationJudge.ruling(idea);
|
||||
}
|
||||
|
||||
|
||||
@ -101,7 +95,7 @@ public class IdeaExportWorker extends AbstractWorker {
|
||||
ideaService.save(idea);
|
||||
}
|
||||
|
||||
private void createProject(Idea idea) {
|
||||
private void createProject(Idea idea, Integer identifier) {
|
||||
beginTransaction();
|
||||
LOGGER.info("Exporting idea: {}", idea);
|
||||
Project project = Project.builder()
|
||||
@ -110,6 +104,7 @@ public class IdeaExportWorker extends AbstractWorker {
|
||||
.startDate(getCourseStartDate(idea))
|
||||
.headSupervisor(idea.getMatch().getSupervisor())
|
||||
.projectParticipants(getAuthors(idea))
|
||||
.identifier(identifier)
|
||||
.build();
|
||||
project.setExpectedEndDate(idea.getApplicationPeriod().getCourseEndDate());
|
||||
project.setResearchArea(idea.getResearchArea());
|
||||
|
@ -37,9 +37,7 @@ public class Daisy implements IdeaCreationJudge {
|
||||
|
||||
try {
|
||||
exporterFacade.exportProject(project, project.getHeadSupervisor().getUnit());
|
||||
externalExporter.deleteProject(project);
|
||||
project.setIdentifier(null);
|
||||
return Decision.allowed();
|
||||
return Decision.allowed(project.getIdentifier());
|
||||
} catch (ExternalExportException e) {
|
||||
return Decision.denied(e.getMessage());
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ public class DaisyModule extends ServletModule {
|
||||
bind(ExternalImporter.class).to(ExternalImporterDaisyImpl.class);
|
||||
bind(ImporterTransactions.class).to(ImporterTransactionsImpl.class);
|
||||
|
||||
Multibinder<IdeaCreationJudge> judges = Multibinder.newSetBinder(binder(), IdeaCreationJudge.class);
|
||||
judges.addBinding().to(Daisy.class);
|
||||
OptionalBinder.newOptionalBinder(binder(), IdeaCreationJudge.class)
|
||||
.setBinding().to(Daisy.class);
|
||||
|
||||
bind(ExternalExporter.class).to(ExternalExporterDaisyImpl.class);
|
||||
bind(UserImportWorker.class);
|
||||
|
@ -19,7 +19,6 @@ import se.su.dsv.scipro.test.DomainObjects;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
@ -46,7 +45,7 @@ public class IdeaExportWorkerTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
worker = new IdeaExportWorker(ideaService, mailService, projectService, Collections.singleton(ideaCreationJudge), eventBus, firstMeetingService) {
|
||||
worker = new IdeaExportWorker(ideaService, mailService, projectService, ideaCreationJudge, eventBus, firstMeetingService) {
|
||||
@Override
|
||||
protected void beginTransaction() {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user