Skip to content

Commit

Permalink
Removed Record Builder annotations (#716) (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
grahampacker-ms authored Jan 27, 2025
1 parent a48cc91 commit f5694c2
Show file tree
Hide file tree
Showing 12 changed files with 515 additions and 320 deletions.
21 changes: 0 additions & 21 deletions calm-hub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-core</artifactId>
<version>44</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
Expand Down Expand Up @@ -215,21 +209,6 @@
</execution>
</executions>
</plugin>

<!-- Record Builder Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-processor</artifactId>
<version>44</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.finos.calm.domain.adr.Adr;
import org.finos.calm.domain.adr.AdrMeta;
import org.finos.calm.domain.adr.AdrMetaBuilder;
import org.finos.calm.domain.adr.Decision;
import org.finos.calm.domain.adr.DecisionBuilder;
import org.finos.calm.domain.adr.LinkBuilder;
import org.finos.calm.domain.adr.Link;
import org.finos.calm.domain.adr.NewAdrRequest;
import org.finos.calm.domain.adr.NewAdrRequestBuilder;
import org.finos.calm.domain.adr.Option;
import org.finos.calm.domain.adr.OptionBuilder;
import org.finos.calm.domain.adr.Status;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
Expand Down Expand Up @@ -50,27 +46,17 @@ public class MongoAdrIntegration {
private final String TITLE = "My ADR";
private final String PROBLEM_STATEMENT = "My problem is...";
private final List<String> DECISION_DRIVERS = List.of("a", "b", "c");
private final Option OPTION_A = OptionBuilder.builder().name("Option 1").description("optionDescription")
.positiveConsequences(List.of("a")).negativeConsequences(List.of("b")).build();
private final Option OPTION_B = OptionBuilder.builder().name("Option 2").description("optionDescription")
.positiveConsequences(List.of("c")).negativeConsequences(List.of("d")).build();
private final Option OPTION_A = new Option("Option A", "optionDescription", List.of("a"), List.of("b"));
private final Option OPTION_B = new Option("Option B", "optionDescription", List.of("c"), List.of("d"));
private final List<Option> CONSIDERED_OPTIONS = List.of(OPTION_A, OPTION_B);
private final String RATIONALE = "This is the best option";
private final Decision DECISION_OUTCOME = DecisionBuilder.builder()
.rationale(RATIONALE)
.chosenOption(OPTION_A)
.build();

private final NewAdrRequest newAdr = NewAdrRequestBuilder.builder()
.title(TITLE)
.contextAndProblemStatement(PROBLEM_STATEMENT)
.decisionDrivers(DECISION_DRIVERS)
.consideredOptions(CONSIDERED_OPTIONS)
.decisionOutcome(DECISION_OUTCOME)
.links(List.of(LinkBuilder.builder().rel("abc").href("http://abc.com").build()))
.build();

private final Adr adr = Adr.builderFromNewAdr(newAdr).status(Status.draft).build();
private final Decision DECISION_OUTCOME = new Decision(OPTION_A, RATIONALE);
private final List<Link> LINKS = List.of(new Link("abc", "http://abc.com"));

private final NewAdrRequest newAdr = new NewAdrRequest(TITLE, PROBLEM_STATEMENT, DECISION_DRIVERS,
CONSIDERED_OPTIONS, DECISION_OUTCOME, LINKS);

private final Adr adr = new Adr.AdrBuilder(newAdr).setStatus(Status.draft).build();

@BeforeEach
public void setupAdrs() {
Expand Down Expand Up @@ -123,12 +109,12 @@ void end_to_end_verify_create_an_adr() throws JsonProcessingException {

@Test
@Order(3)
void end_to_end_verify_get_adr_revision() throws JsonProcessingException {
AdrMeta expectedAdrMeta = AdrMetaBuilder.builder()
.namespace("finos")
.id(1)
.revision(1)
.adrContent(adr)
void end_to_end_verify_get_adr_revision() {
AdrMeta expectedAdrMeta = new AdrMeta.AdrMetaBuilder()
.setNamespace("finos")
.setId(1)
.setRevision(1)
.setAdr(adr)
.build();

AdrMeta actualAdrMeta = given()
Expand All @@ -152,11 +138,11 @@ void end_to_end_verify_get_adr() {
.body()
.as(AdrMeta.class);

AdrMeta expectedAdrMeta = AdrMetaBuilder.builder()
.namespace("finos")
.id(1)
.revision(1)
.adrContent(adr)
AdrMeta expectedAdrMeta = new AdrMeta.AdrMetaBuilder()
.setNamespace("finos")
.setId(1)
.setRevision(1)
.setAdr(adr)
.build();
assertEquals(expectedAdrMeta, actualAdrMeta);
}
Expand Down Expand Up @@ -204,7 +190,7 @@ void end_to_end_verify_status_changed() throws JsonProcessingException {
.when().get("/calm/namespaces/finos/adrs/1/revisions/3")
.then()
.statusCode(200)
.body("adrContent.status", equalTo("proposed"));
.body("adr.status", equalTo("proposed"));
}

}
209 changes: 181 additions & 28 deletions calm-hub/src/main/java/org/finos/calm/domain/adr/Adr.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,91 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.soabase.recordbuilder.core.RecordBuilder;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@RecordBuilder.Options(enableWither = false)
@RecordBuilder
public record Adr(
String title,
Status status,
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
LocalDateTime creationDateTime,
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
LocalDateTime updateDateTime,
String contextAndProblemStatement,
List<String> decisionDrivers,
List<Option> consideredOptions,
Decision decisionOutcome,
List<Link> links

) {

public static AdrBuilder builderFromNewAdr(NewAdrRequest newAdrRequest) {
return AdrBuilder.builder()
.title(newAdrRequest.title())
.contextAndProblemStatement(newAdrRequest.contextAndProblemStatement())
.decisionDrivers(newAdrRequest.decisionDrivers())
.consideredOptions(newAdrRequest.consideredOptions())
.decisionOutcome(newAdrRequest.decisionOutcome())
.links(newAdrRequest.links());
public class Adr {
private String title;
private Status status;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime creationDateTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime updateDateTime;
private String contextAndProblemStatement;
private List<String> decisionDrivers;
private List<Option> consideredOptions;
private Decision decisionOutcome;
private List<Link> links;

public Adr() {

}

public Adr(
String title,
Status status,
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
LocalDateTime creationDateTime,
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
LocalDateTime updateDateTime,
String contextAndProblemStatement,
List<String> decisionDrivers,
List<Option> consideredOptions,
Decision decisionOutcome,
List<Link> links

) {
this.title = title;
this.status = status;
this.creationDateTime = creationDateTime;
this.updateDateTime = updateDateTime;
this.contextAndProblemStatement = contextAndProblemStatement;
this.decisionDrivers = decisionDrivers;
this.consideredOptions = consideredOptions;
this.decisionOutcome = decisionOutcome;
this.links = links;
}

public String getTitle() {
return title;
}

public Status getStatus() {
return status;
}

public LocalDateTime getCreationDateTime() {
return creationDateTime;
}

public LocalDateTime getUpdateDateTime() {
return updateDateTime;
}

public String getContextAndProblemStatement() {
return contextAndProblemStatement;
}

public List<String> getDecisionDrivers() {
return decisionDrivers;
}

public List<Option> getConsideredOptions() {
return consideredOptions;
}

public Decision getDecisionOutcome() {
return decisionOutcome;
}

public List<Link> getLinks() {
return links;
}

// does not include datetimes in equals
Expand All @@ -58,4 +110,105 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(title, status, contextAndProblemStatement, decisionDrivers, consideredOptions, decisionOutcome, links);
}

@Override
public String toString() {
return "Adr[" +
"title=" + title + ", " +
"status=" + status + ", " +
"creationDateTime=" + creationDateTime + ", " +
"updateDateTime=" + updateDateTime + ", " +
"contextAndProblemStatement=" + contextAndProblemStatement + ", " +
"decisionDrivers=" + decisionDrivers + ", " +
"consideredOptions=" + consideredOptions + ", " +
"decisionOutcome=" + decisionOutcome + ", " +
"links=" + links + ']';
}

public static class AdrBuilder {
private String title;
private Status status;
private LocalDateTime creationDateTime;
private LocalDateTime updateDateTime;
private String contextAndProblemStatement;
private List<String> decisionDrivers;
private List<Option> consideredOptions;
private Decision decisionOutcome;
private List<Link> links;

public AdrBuilder() {

}

public AdrBuilder(Adr adr) {
this.title = adr.getTitle();
this.status = adr.getStatus();
this.creationDateTime = adr.getCreationDateTime();
this.updateDateTime = adr.getUpdateDateTime();
this.contextAndProblemStatement = adr.getContextAndProblemStatement();
this.decisionDrivers = adr.getDecisionDrivers();
this.consideredOptions = adr.getConsideredOptions();
this.decisionOutcome = adr.getDecisionOutcome();
this.links = adr.getLinks();
}

public AdrBuilder(NewAdrRequest newAdrRequest) {
this.title = newAdrRequest.title();
this.contextAndProblemStatement = newAdrRequest.contextAndProblemStatement();
this.decisionDrivers = newAdrRequest.decisionDrivers();
this.consideredOptions = newAdrRequest.consideredOptions();
this.decisionOutcome = newAdrRequest.decisionOutcome();
this.links = newAdrRequest.links();
}

public AdrBuilder setTitle(String title) {
this.title = title;
return this;
}

public AdrBuilder setStatus(Status status) {
this.status = status;
return this;
}

public AdrBuilder setCreationDateTime(LocalDateTime creationDateTime) {
this.creationDateTime = creationDateTime;
return this;
}

public AdrBuilder setUpdateDateTime(LocalDateTime updateDateTime) {
this.updateDateTime = updateDateTime;
return this;
}

public AdrBuilder setContextAndProblemStatement(String contextAndProblemStatement) {
this.contextAndProblemStatement = contextAndProblemStatement;
return this;
}

public AdrBuilder setDecisionDrivers(List<String> decisionDrivers) {
this.decisionDrivers = decisionDrivers;
return this;
}

public AdrBuilder setConsideredOptions(List<Option> consideredOptions) {
this.consideredOptions = consideredOptions;
return this;
}

public AdrBuilder setDecisionOutcome(Decision decisionOutcome) {
this.decisionOutcome = decisionOutcome;
return this;
}

public AdrBuilder setLinks(List<Link> links) {
this.links = links;
return this;
}

public Adr build() {
return new Adr(title, status, creationDateTime, updateDateTime, contextAndProblemStatement, decisionDrivers, consideredOptions, decisionOutcome, links);
}
}

}
Loading

0 comments on commit f5694c2

Please sign in to comment.