Skip to content

Commit

Permalink
Document usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulsom committed Jun 28, 2017
1 parent 631ab85 commit e18c7a4
Show file tree
Hide file tree
Showing 45 changed files with 1,019 additions and 266 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ language: java
jdk:
- oraclejdk8
install: "./gradlew assemble --scan --build-cache --configure-on-demand"
script: "./travis.sh"
after_success: bash <(curl -s https://codecov.io/bash)
script: ""
after_success:
- bash <(curl -s https://codecov.io/bash)
- ./gradlew --init-script bds_init.gradle :grooves-types:buildBom :grooves-api:buildBom :grooves-groovy:buildBom :grooves-gorm:buildBom -DbdsPluginVersion=5.0.0 --scan --build-cache --configure-on-demand
- curl -s https://copilot.blackducksoftware.com/bash/travis > blackduck.sh
- chmod u+x blackduck.sh
- ./blackduck.sh ./build/blackduck/grooves-api_bdio.jsonld
- ./blackduck.sh ./build/blackduck/grooves-types_bdio.jsonld
- ./blackduck.sh ./build/blackduck/grooves-groovy_bdio.jsonld
- ./blackduck.sh ./build/blackduck/grooves-gorm_bdio.jsonld
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand All @@ -20,5 +28,3 @@ env:
- secure: SoiURI/HxcdYh4rHTixuQKhzIHk360joevJkAwK9k9FZeYE9rTKRvkSbYcE7kUyNv4Z/NyqfC9ofKwgXqqOR5kY31smTAsO2A3tHauE7VhQtRd/VDTifVi95X0UXkxsPiRMrpCv4iW5kflYkwBT/k7oU2RIGlDF1cxsF87gtmCTIZ99pMZseEYPllIugiWoEyOiwndEavsVv0r080a0HcvLU48ZOp7HWjbM8Ba6ZGAbu5LPnXbaSuRSQjuI5L9g1ZkNVrYQ1Ds351l+Qz9zO0O/LxB0TXBjz3XPldmpnatq5KoJuezHIC1wy5QXKTcHPK/q6eDVfjwdaSF4z4EmLnS/WAS8QoeQAyTTLrErKUg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ayv6c1X/DGZxbOti4gMqY09FnQ439nsLqzFSn83MR3EKMJEp6RHKTo3dL4VPs7OWLSMOuv3kI1jCH163uiX1AhnC8TS8tCrQbIMslCQUjWjXoCqllZ9lnwYwj1a/dd0X+miM0PRnLsgd2ozGmugVdpPafZ3wJpDb29+i0g7guqE3ApppvluSdUPy/+gcmCWMF+/8f10sBizGOAHJfVF/LYUuItoOuq7QP4InWF1Tp8iNp4sfq6LffeJan1xZUfZrHJbzS3GXfAXXomlURGece/BDWDmjwJ0ZMNLJHVPtJUFgo72aes1vGJ+ttLCk99dGChq72rNnGIpEFrtaC4kRCuC8hTF+o8QRfia41197cnPAm3LOcDOWWNav3JwVUf7P+rgQisq1FvkYD/9ZU6bss9g1kICqXZXa0l50BA5k5pZvCvsDCBVOlj+EM/eCk5JVuEjcl5Nxq43Ngu8myDvGu8lGsrvP1+Pf40XsiDf4GShIHHoTr9BO0OnQa0OWdNJGOZTCc4wPEkm5KsxxfKo9W+Z87akan75y3aWPCLJyCw3kjGj8zNAfrWhPwohA6C6V2v5mewOIL5QlYubEUn8MzAz0R+9vMrKyhHtP0=
addons:
srcclr: true
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Joins are now reactive too.
This removes the need for reattach methods.
* Examples now contains `rx-mongo`.
* Documentation now points to examples.

== 0.1.1
* Improve RX support for `rx-gorm-rest`.
Expand Down
15 changes: 15 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
https://semaphoreci.com/rahulsom/grooves[image:https://semaphoreci.com/api/v1/rahulsom/grooves/branches/0-1-x/shields_badge.svg[Build
Status]]
https://opensource.org/licenses/Apache-2.0[image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[License]]

= Grooves

Event Sourcing Library for Java.
Expand All @@ -13,17 +17,28 @@ https://oss.sonatype.org/#nexus-search;quick~grooves-gorm[grooves-gorm]::
This is for you if you're using GORM for persistence.
It has interfaces that need to know the domain object used, and build flexible queries without forcing you to write the code to read domain objects from the database.

image::https://api.bintray.com/packages/bintray/jcenter/com.github.rahulsom%3Agrooves-gorm/images/download.svg[link="https://bintray.com/bintray/jcenter/com.github.rahulsom%3Agrooves-gorm/_latestVersion"]


https://oss.sonatype.org/#nexus-search;quick~grooves-groovy[grooves-groovy]::
This is for you if you want to write your queries in groovy, but are not using GORM.
You will have to implement your own data access, but will get support for checking completeness of queries based on groovy AST Transformations.

image::https://api.bintray.com/packages/bintray/jcenter/com.github.rahulsom%3Agrooves-groovy/images/download.svg[link="https://bintray.com/bintray/jcenter/com.github.rahulsom%3Agrooves-groovy/_latestVersion"]


https://oss.sonatype.org/#nexus-search;quick~grooves-api[grooves-api]::
This is for you if you are not using groovy, or don't care about verifying completeness of queries.

image::https://api.bintray.com/packages/bintray/jcenter/com.github.rahulsom%3Agrooves-api/images/download.svg[link="https://bintray.com/bintray/jcenter/com.github.rahulsom%3Agrooves-api/_latestVersion"]


https://oss.sonatype.org/#nexus-search;quick~grooves-types[grooves-types]::
This contains types that are used in `grooves-api`.
It is very unlikely you'll be using this directly.

image::https://api.bintray.com/packages/bintray/jcenter/com.github.rahulsom%3Agrooves-types/images/download.svg[link="https://bintray.com/bintray/jcenter/com.github.rahulsom%3Agrooves-types/_latestVersion"]

== Examples

link:examples/grails/rdbms[examples/grails/rdbms]::
Expand Down
14 changes: 14 additions & 0 deletions bds_init.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
initscript {
repositories { mavenCentral() }
dependencies {
classpath group:'com.blackducksoftware.integration', name: 'hub-gradle-plugin', version: System.properties['bdsPluginVersion']
}
}

allprojects {
apply plugin: com.blackducksoftware.integration.gradle.HubGradlePlugin

buildBom{
deployHubBdio false
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ buildscript {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.gradle:build-scan-plugin:1.6'
classpath 'com.gradle:build-scan-plugin:1.7.4'
classpath 'me.champeau.gradle:buildscan-recipes-plugin:0.2.0'
classpath 'fr.jcgay:gradle-notifier:1.1.0'
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.3'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:+'
classpath 'com.netflix.nebula:nebula-release-plugin:4.2.0'
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories {
apply plugin: 'groovy'

dependencies {
compile 'org.asciidoctor:asciidoctorj:1.5.0'
compile 'org.asciidoctor:asciidoctorj:1.5.4.1'
compile 'com.github.sommeri:less4j:1.17.2'
compileOnly ('org.kordamp.gipsy:gipsy:0.4.0') {
exclude module: 'groovy-all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package grooves.grails.mongo

// tag::documented[]
import com.github.rahulsom.grooves.groovy.transformations.Aggregate
import com.github.rahulsom.grooves.api.AggregateType
import groovy.transform.EqualsAndHashCode

// end::documented[]
/**
* Represents a Patient
*
* @author Rahul Somasunderam
*/
@Aggregate
// tag::documented[]
@Aggregate // <1>
@EqualsAndHashCode(includes = ['uniqueId'])
class Patient implements AggregateType<Long> {
class Patient implements AggregateType<Long> { //<2>

// Long id // <3>
String uniqueId
static constraints = {
}

@Override String toString() { "Patient($id, $uniqueId)" }

}
// end::documented[]
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,29 @@ import static rx.Observable.*
*/
@SuppressWarnings(['DuplicateNumberLiteral', 'DuplicateStringLiteral',])
@EqualsAndHashCode(includes = ['aggregateId', 'lastEventPosition'])
class PatientAccount implements JavaSnapshot<Long, Patient, String, Long, PatientEvent> {
// tag::documented[]
class PatientAccount implements JavaSnapshot<Long, Patient, String, Long, PatientEvent> { // <1>

static mapWith = 'mongo'

String id
Long lastEventPosition
Date lastEventTimestamp
Long lastEventPosition // <2>
Date lastEventTimestamp // <3>
Set<String> processingErrors = []

Long aggregateId

Patient getAggregate() { Patient.get(aggregateId) }

@Override
Observable<Patient> getAggregateObservable() {
Observable<Patient> getAggregateObservable() { // <4>
aggregateId ? defer { just aggregate } : empty()
}

void setAggregate(Patient aggregate) { this.aggregateId = aggregate.id }

@Override
Observable<Patient> getDeprecatedByObservable() {
Observable<Patient> getDeprecatedByObservable() { // <5>
deprecatedBy ? just(deprecatedBy) : empty()
}
Long deprecatedById
Expand All @@ -44,7 +45,7 @@ class PatientAccount implements JavaSnapshot<Long, Patient, String, Long, Patien
void setDeprecatedBy(Patient aggregate) { deprecatedById = aggregate.id }

@Override
Observable<Patient> getDeprecatesObservable() {
Observable<Patient> getDeprecatesObservable() { // <6>
deprecatesIds ? from(deprecatesIds).flatMap { Patient.get it } : empty()
}
Set<Long> deprecatesIds
Expand Down Expand Up @@ -74,3 +75,4 @@ class PatientAccount implements JavaSnapshot<Long, Patient, String, Long, Patien
"B: $balance, M: $moneyMade)"
}
}
// end::documented[]
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,42 @@ import static rx.Observable.just
*/
@SuppressWarnings(['AbstractClassWithoutAbstractMethod', 'GrailsDomainReservedSqlKeywordName'])
@EqualsAndHashCode
abstract class PatientEvent implements BaseEvent<Long, Patient, Long, PatientEvent> {
// tag::abstract[]
abstract class PatientEvent implements BaseEvent<Long, Patient, Long, PatientEvent> { // <1>

RevertEvent<Long, Patient, Long, PatientEvent> revertedBy
RevertEvent<Long, Patient, Long, PatientEvent> revertedBy // <2>
String createdBy
Date timestamp
Long position
Date timestamp // <3>
Long position // <4>
Patient aggregate
Observable<Patient> getAggregateObservable() { just(aggregate) }
Observable<Patient> getAggregateObservable() { just(aggregate) } // <5>

static transients = ['revertedBy']
static transients = ['revertedBy'] // <6>

static constraints = {
}
// end::abstract[]

String getTs() { timestamp.format('yyyy-MM-dd') }

@Override String toString() { "PatientEvent($id, $aggregateId, $ts)" }
// tag::abstract[]
}
// end::abstract[]

@Event(Patient)
@EqualsAndHashCode
class PatientCreated extends PatientEvent {
//tag::created[]
@Event(Patient) // <1>
class PatientCreated extends PatientEvent { // <2>
String name

@Override String getAudit() { new JsonBuilder([name: name]).toString() }
@Override String getAudit() { new JsonBuilder([name: name]).toString() } // <3>
//end::created[]
@Override String toString() {
"<${aggregateId}.$id> $ts created as ${name}" }
//tag::created[]
}
//end::created[]

@EqualsAndHashCode
class PatientAddedToZipcode extends PatientEvent implements
Expand Down Expand Up @@ -90,15 +98,20 @@ class PaymentMade extends PatientEvent {
@Override String toString() { "<${aggregateId}.$id> $ts paid \$ $amount" }
}

//tag::reverted[]
@EqualsAndHashCode
class PatientEventReverted extends PatientEvent implements
RevertEvent<Long, Patient, Long, PatientEvent> {
Long revertedEventId
class PatientEventReverted
extends PatientEvent // <1>
implements RevertEvent<Long, Patient, Long, PatientEvent> { // <2>
Long revertedEventId // <3>

@Override String getAudit() { new JsonBuilder([revertedEvent: revertedEventId]).toString() }
//end::reverted[]
@Override String toString() {
"<${aggregateId}.$id> $ts reverted #$revertedEventId" }
//tag::reverted[]
}
//end::reverted[]

@EqualsAndHashCode
class PatientDeprecatedBy extends PatientEvent implements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ import static rx.Observable.just
/**
* Queries for the PatientAccount
*/
@Query(aggregate = Patient, snapshot = PatientAccount)
@GrailsCompileStatic
class PatientAccountQuery implements
GormQuerySupport<Long, Patient, Long, PatientEvent, String, PatientAccount,
PatientAccountQuery> {
//tag::documented[]
@Query(aggregate = Patient, snapshot = PatientAccount) // <5>
class PatientAccountQuery
implements GormQuerySupport<Long, Patient, Long, PatientEvent,
String, PatientAccount, PatientAccountQuery> { // <6>

final Class<PatientAccount> snapshotClass = PatientAccount
final Class<PatientEvent> eventClass = PatientEvent
final Class<PatientEvent> eventClass = PatientEvent // <7>
final Class<PatientAccount> snapshotClass = PatientAccount // <8>

@Override
PatientAccount createEmptySnapshot() { new PatientAccount(deprecates: []) }
PatientAccount createEmptySnapshot() { new PatientAccount(deprecates: []) } // <9>

@Override
boolean shouldEventsBeApplied(PatientAccount snapshot) {
boolean shouldEventsBeApplied(PatientAccount snapshot) { // <10>
true
}

Expand All @@ -35,18 +36,19 @@ class PatientAccountQuery implements
}

@Override
Observable<EventApplyOutcome> onException(
Observable<EventApplyOutcome> onException( // <11>
Exception e, PatientAccount snapshot, PatientEvent event) {
snapshot.processingErrors << e.message
just CONTINUE
}

Observable<EventApplyOutcome> applyPatientCreated(
Observable<EventApplyOutcome> applyPatientCreated( // <12>
PatientCreated event, PatientAccount snapshot) {
snapshot.name = snapshot.name ?: event.name
just CONTINUE
just CONTINUE // <13>
}

//end::documented[]
Observable<EventApplyOutcome> applyProcedurePerformed(
ProcedurePerformed event, PatientAccount snapshot) {
snapshot.balance += event.cost
Expand All @@ -60,12 +62,6 @@ class PatientAccountQuery implements
just CONTINUE
}

@SuppressWarnings(['DuplicateStringLiteral', 'UnusedMethodParameter',])
Observable<EventApplyOutcome> applyPatientAddedToZipcode(
PatientAddedToZipcode event, PatientAccount snapshot) {
just CONTINUE // Ignore zip change
}

@Override
PatientAccount detachSnapshot(PatientAccount snapshot) {
if (snapshot.isAttached()) {
Expand All @@ -74,5 +70,6 @@ class PatientAccountQuery implements
}
snapshot
}

//tag::documented[]
}
//end::documented[]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javax.ejb.Singleton;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -49,4 +50,12 @@ public void addEvent(PatientEvent event) {
public void addSnapshot(Object snapshot) {
snapshotList.add(snapshot);
}

public static boolean isTimestampInRange(
Date lowerBoundExclusive, Date timestamp, Date upperBoundInclusive) {
return (lowerBoundExclusive == null || timestamp.compareTo(lowerBoundExclusive) > 0)
&& timestamp.compareTo(upperBoundInclusive) <= 0;
}


}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package grooves.example.javaee.domain;

// tag::documented[]
import com.github.rahulsom.grooves.api.AggregateType;

import java.io.Serializable;

public class Patient implements AggregateType<Long>, Serializable {
private Long id;
public class Patient implements AggregateType<Long>, // <1>
Serializable {
private Long id; // <2>
private String uniqueId;
// end::documented[]

@Override
public String toString() {
Expand All @@ -29,4 +32,6 @@ public String getUniqueId() {
public Patient(String uniqueId) {
this.uniqueId = uniqueId;
}
// tag::documented[]
}
// end::documented[]
Loading

0 comments on commit e18c7a4

Please sign in to comment.