Commit 9bc229b0 authored by Julien Topçu's avatar Julien Topçu
Browse files

Recommends talks given a topic and a format

parent 2c12b296
......@@ -223,6 +223,10 @@
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
......@@ -322,6 +326,11 @@
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
......@@ -29,6 +29,7 @@
<include>org.jetbrains.kotlin:*</include>
<include>org.jetbrains:annotations</include>
<include>org.apache.commons:commons-lang3</include>
<include>com.google.code.findbugs:jsr305</include>
<!-- and test dependencies-->
<include>*:*:*:*:test</include>
</includes>
......
......@@ -3,7 +3,10 @@ package org.craftsrecords.talkadvisor.recommendation.api;
import org.craftsrecords.talkadvisor.recommendation.Recommendation;
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria;
import javax.annotation.Nonnull;
@FunctionalInterface
public interface RecommendTalksForTopic {
Recommendation getRecommendation(Criteria criteria);
@Nonnull
Recommendation getRecommendation(@Nonnull Criteria criteria);
}
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.spi;
import org.craftsrecords.talkadvisor.recommendation.Recommendation;
import javax.annotation.Nonnull;
public interface Recommendations {
void save(@Nonnull Recommendation recommendation);
}
package org.craftsrecords.talkadvisor.recommendation.spi;
import org.craftsrecords.talkadvisor.recommendation.criteria.Topic;
import org.craftsrecords.talkadvisor.recommendation.talk.Talk;
import javax.annotation.Nonnull;
import java.util.Set;
@FunctionalInterface
public interface SearchTalks {
@Nonnull
Set<Talk> forTopic(@Nonnull Topic topic);
}
......@@ -2,10 +2,22 @@ package org.craftsrecords.talkadvisor.recommendation
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalksForTopic
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria
import org.craftsrecords.talkadvisor.recommendation.spi.Recommendations
import org.craftsrecords.talkadvisor.recommendation.spi.SearchTalks
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
class TalksAdvisor : RecommendTalksForTopic {
class TalksAdvisor(private val searchTalks: SearchTalks, private val recommendations: Recommendations) : RecommendTalksForTopic {
override fun getRecommendation(criteria: Criteria): Recommendation {
TODO("not implemented")
val talks = getTalksSatisfying(criteria)
val recommendation = Recommendation(talks = talks)
recommendations.save(recommendation)
return recommendation
}
private fun getTalksSatisfying(criteria: Criteria): Set<Talk> {
return searchTalks.forTopic(criteria.topic)
.filter { criteria.talksFormats.contains(it.format) }
.toSet()
}
}
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.talkadvisor.recommendation.criteria.Topic
import org.craftsrecords.talkadvisor.recommendation.spi.SearchTalks
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
import java.time.Duration
import kotlin.random.Random
class HardCodedTalksSearcher : SearchTalks {
override fun forTopic(topic: Topic): Set<Talk> {
return createTalks(topic)
}
private fun createTalks(topic: Topic): Set<Talk> {
return (1..20)
.map {
Talk.with {
id = it.toString()
title = "${randomText()} ${topic.name} ${randomText()}"
duration = Duration.ofMinutes(Random.nextLong(2, 100))
}.build()
}.toSet()
}
private fun randomText() = Random.nextBits(4).toString()
}
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.talkadvisor.recommendation.Recommendation
import org.craftsrecords.talkadvisor.recommendation.spi.Recommendations
import java.util.*
class InMemoryRecommendations(private val recommendations: MutableMap<UUID, Recommendation> = HashMap()) : Recommendations {
override fun save(recommendation: Recommendation) {
recommendations[recommendation.id] = recommendation
}
}
\ No newline at end of file
......@@ -2,11 +2,15 @@ package org.craftsrecords.talkadvisor
import cucumber.runtime.java.picocontainer.PicoFactory
import org.craftsrecords.talkadvisor.recommendation.TalksAdvisor
import org.craftsrecords.talkadvisor.recommendation.spi.stubs.HardCodedTalksSearcher
import org.craftsrecords.talkadvisor.recommendation.spi.stubs.InMemoryRecommendations
import org.craftsrecords.talkadvisor.recommendation.stepdefs.TestContext
class CustomPicoFactory : PicoFactory() {
init {
addClass(TestContext::class.java)
addClass(TalksAdvisor::class.java)
addClass(HardCodedTalksSearcher::class.java)
addClass(InMemoryRecommendations::class.java)
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment