Skip to content

Commit

Permalink
Merge pull request #171 from citrusframework/feature/#166-auditted-en…
Browse files Browse the repository at this point in the history
…tities

feat(#166): auditted entities
  • Loading branch information
bbortt authored Oct 16, 2023
2 parents 211d5ab + 3d16c0e commit 09ab5c6
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
import org.citrusframework.simulator.model.ScenarioExecutionFilter;
import org.citrusframework.simulator.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;
import java.util.Collection;
import java.util.Date;

@RestController
@RequestMapping("api/activity")
Expand All @@ -33,8 +39,8 @@ public class ActivityController {

@RequestMapping(method = RequestMethod.GET)
public Collection<ScenarioExecution> getScenarioExecutions(
@RequestParam(value = "fromDate", required = false) Date fromDate,
@RequestParam(value = "toDate", required = false) Date toDate,
@RequestParam(value = "fromDate", required = false) Instant fromDate,
@RequestParam(value = "toDate", required = false) Instant toDate,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.citrusframework.simulator.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.time.Instant;

/**
* Base abstract class for entities which will hold definitions for created and last modified by attributes.
*/
@MappedSuperclass
@EntityListeners({ AuditingEntityListener.class })
@JsonIgnoreProperties(value = { "createdDate", "lastModifiedDate" }, allowGetters = true)
public abstract class AbstractAuditingEntity<T, I> implements Serializable {

private static final long serialVersionUID = 1L;

@CreatedDate
@Column(name = "created_date", nullable = false, updatable = false)
private Instant createdDate = Instant.now();

@LastModifiedDate
@Column(name = "last_modified_date")
private Instant lastModifiedDate = Instant.now();

public Instant getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Instant createdDate) {
this.createdDate = createdDate;
}

public T createdDate(Instant createdDate) {
setCreatedDate(createdDate);
return (T) this;
}

public Instant getLastModifiedDate() {
return lastModifiedDate;
}

public void setLastModifiedDate(Instant lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}

public T lastModifiedDate(Instant lastModifiedDate) {
setLastModifiedDate(lastModifiedDate);
return (T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@

package org.citrusframework.simulator.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import jakarta.persistence.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

/**
* JPA entity for representing inbound and outbound messages
*/
@Entity
public class Message implements Serializable {
private static final long serialVersionUID = -4858126051234255084L;
public class Message extends AbstractAuditingEntity<Message, Long> implements Serializable {

@Serial
private static final long serialVersionUID = 2L;

public enum Direction {
INBOUND,
Expand All @@ -38,31 +49,26 @@ public enum Direction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MESSAGE_ID")
private Long messageId;

@JsonIgnore
@ManyToOne
private ScenarioExecution scenarioExecution;

@Column(nullable = false)
private Direction direction;

@Column(nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date date;

@Column(columnDefinition = "CLOB")
@Lob
@Column(columnDefinition = "CLOB")
private String payload;

@Column(unique = true)
private String citrusMessageId;

@OneToMany(mappedBy = "message", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("name ASC")
@OneToMany(mappedBy = "message", cascade = CascadeType.ALL, orphanRemoval = true)
private Collection<MessageHeader> headers = new ArrayList<>();

@ManyToOne
@JsonIgnoreProperties(value = { "scenarioParameters", "scenarioActions", "scenarioMessages" }, allowSetters = true)
private ScenarioExecution scenarioExecution;

public Long getMessageId() {
return messageId;
}
Expand All @@ -75,32 +81,6 @@ public ScenarioExecution getScenarioExecution() {
return scenarioExecution;
}

public void setScenarioExecution(ScenarioExecution scenarioExecution) {
this.scenarioExecution = scenarioExecution;
}

public Long getScenarioExecutionId() {
if (scenarioExecution != null) {
return scenarioExecution.getExecutionId();
}
return null;
}

public String getScenarioName() {
if (scenarioExecution != null) {
return scenarioExecution.getScenarioName();
}
return null;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public Direction getDirection() {
return direction;
}
Expand Down Expand Up @@ -139,18 +119,35 @@ public Collection<MessageHeader> getHeaders() {
return headers;
}

public void setScenarioExecution(ScenarioExecution scenarioExecution) {
this.scenarioExecution = scenarioExecution;
}

public Long getScenarioExecutionId() {
if (scenarioExecution != null) {
return scenarioExecution.getExecutionId();
}
return null;
}

public String getScenarioName() {
if (scenarioExecution != null) {
return scenarioExecution.getScenarioName();
}
return null;
}


@Override
public String toString() {
return "Message{" +
"date=" + date +
", messageId=" + messageId +
", direction=" + direction +
", payload='" + payload + '\'' +
", citrusMessageId=" + citrusMessageId +
", scenarioExecutionId=" + getScenarioExecutionId() +
", scenarioName=" + getScenarioName() +
", headers=" + headers +
"messageId='" + getMessageId() + "'" +
", createdDate='" + getCreatedDate() + "'" +
", direction='" + getDirection() + "'" +
", payload='" + getPayload() + "'" +
", citrusMessageId='" + getCitrusMessageId() + "'" +
", headers='" + getHeaders() + "'" +
", scenarioExecution='" + getScenarioExecution() + "'" +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

package org.citrusframework.simulator.model;

import java.util.Date;
import lombok.Data;

import java.time.Instant;

/**
* Filter for filtering {@link Message}s
*/
@Data
public class MessageFilter {
private Date fromDate;
private Date toDate;
private Instant fromDate;
private Instant toDate;
private Integer pageNumber;
private Integer pageSize;
private Boolean directionInbound;
Expand All @@ -42,5 +43,4 @@ public class MessageFilter {
* filter.
*/
private String headerFilter;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@
*/
package org.citrusframework.simulator.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import jakarta.persistence.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;

import java.io.Serial;
import java.io.Serializable;

/**
Expand All @@ -26,14 +34,13 @@
* @author Georgi Todorov
*/
@Entity
public class MessageHeader implements Serializable {
public class MessageHeader extends AbstractAuditingEntity<MessageHeader, Long> implements Serializable {

private static final long serialVersionUID = 6645135139541485915L;
@Serial
private static final long serialVersionUID = 2L;

@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "HEADER_ID")
private Long headerId;

@Column(nullable = false)
Expand All @@ -42,8 +49,10 @@ public class MessageHeader implements Serializable {
@Column(nullable = false, name = "`value`")
private String value;

@JsonIgnore
@ManyToOne
@NotNull
@ManyToOne(optional = false)
@JoinColumn(nullable = false)
@JsonIgnoreProperties(value = { "headers", "scenarioExecution" }, allowSetters = true)
private Message message;

public MessageHeader() {
Expand Down Expand Up @@ -89,10 +98,11 @@ public void setMessage(Message message) {
@Override
public String toString() {
return "MessageHeader{" +
"headerId=" + headerId +
", name='" + name + '\'' +
", value='" + value + '\'' +
"headerId='" + getHeaderId() + "'" +
", createdDate='" + getCreatedDate() + "'" +
", name='" + getName() + "'" +
", value='" + getValue() + "'" +
", message='" + getMessage() + "'" +
'}';
}

}
Loading

0 comments on commit 09ab5c6

Please sign in to comment.