Skip to content

Commit

Permalink
MET-5961 add initial definition for debias processing state in db
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Jul 9, 2024
1 parent f8479c6 commit 663a245
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<version.postgresql.bucket4j>8.1.1</version.postgresql.bucket4j>
<version.guava>32.1.3-jre</version.guava>
<version.mockito-core>5.8.0</version.mockito-core>
<spring-statemachine.version>4.0.0</spring-statemachine.version>
</properties>
<dependencies>
<!-- Rate limiting dependencies-->
Expand Down Expand Up @@ -369,7 +370,12 @@
<artifactId>aws-java-sdk-s3</artifactId>
<version>${version.aws.s3}</version>
</dependency>

<!-- state machine for de-bias project -->
<dependency>
<groupId>org.springframework.statemachine</groupId>
<artifactId>spring-statemachine-starter</artifactId>
<version>${spring-statemachine.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/eu/europeana/metis/sandbox/common/debias/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package eu.europeana.metis.sandbox.common.debias;

/**
* Verbs Event
*/
public enum Event {
PROCESS,
SUCCEED,
FAIL
}
11 changes: 11 additions & 0 deletions src/main/java/eu/europeana/metis/sandbox/common/debias/State.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.europeana.metis.sandbox.common.debias;

/**
* Nouns/Adjectives State
*/
public enum State {
START,
PROCESSING,
COMPLETED,
ERROR
}
55 changes: 55 additions & 0 deletions src/main/java/eu/europeana/metis/sandbox/config/DebiasConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package eu.europeana.metis.sandbox.config;

import eu.europeana.metis.sandbox.common.debias.Event;
import eu.europeana.metis.sandbox.common.debias.State;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;

@Configuration
@EnableStateMachine
public class DebiasConfig extends StateMachineConfigurerAdapter<State, Event> {

@Override
public void configure(StateMachineStateConfigurer<State, Event> states) throws Exception {
states
.withStates()
.initial(State.START)
.state(State.PROCESSING)
.state(State.ERROR)
.end(State.COMPLETED);
}

@Override
public void configure(StateMachineTransitionConfigurer<State, Event> transitions) throws Exception {
transitions
.withExternal()
.source(State.START).target(State.PROCESSING)
.event(Event.PROCESS)
.and()
.withExternal()
.source(State.PROCESSING).target(State.ERROR)
.event(Event.FAIL)
.and()
.withExternal()
.source(State.ERROR).target(State.PROCESSING)
.event(Event.PROCESS)
.and()
.withExternal()
.source(State.PROCESSING).target(State.COMPLETED)
.event(Event.SUCCEED);
}

// @Bean
// public StateMachineRuntimePersister<State,Event,String> stringStateMachineRuntimePersister() {
// return new JpaPersistingStateMachineInterceptor<>(jpaStateMachineRepository);;
// }
// @Override
// public void configure(StateMachineConfigurationConfigurer<State, Event> config) throws Exception {
// config.withPersistence()
// .runtimePersister()
// }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package eu.europeana.metis.sandbox.entity.debias;

import eu.europeana.metis.sandbox.entity.DatasetEntity;
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.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import java.time.ZonedDateTime;

/**
* The type Detection entity.
*/
@Entity
@Table(name = "dataset_debias_detect")
public class DetectionEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "dataset_id", referencedColumnName = "datasetId")
private DatasetEntity datasetId;

private String state;

@Column(insertable = false, updatable = false)
private ZonedDateTime createdDate;


/**
* Instantiates a new Detection entity.
*/
public DetectionEntity() {
// provide explicit no-args constructor as it is required for Hibernate
}

/**
* Instantiates a new Detection entity.
*
* @param datasetId the dataset id
* @param state the state
*/
public DetectionEntity(DatasetEntity datasetId, String state) {
this.datasetId = datasetId;
this.state = state;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public DatasetEntity getDatasetId() {
return datasetId;
}

public void setDatasetId(DatasetEntity datasetId) {
this.datasetId = datasetId;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public ZonedDateTime getCreatedDate() {
return createdDate;
}

public void setCreatedDate(ZonedDateTime createdDate) {
this.createdDate = createdDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package eu.europeana.metis.sandbox.service.debias;

import org.springframework.stereotype.Service;

@Service
public class DebiasStateMachineService {

}
11 changes: 11 additions & 0 deletions src/main/resources/database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ CREATE TABLE IF NOT EXISTS harvesting_parameter
FOREIGN KEY (dataset_id) REFERENCES dataset (dataset_id)
);

CREATE TABLE IF NOT EXISTS dataset_debias_detect
(
id BIGSERIAL,
dataset_id BIGINT NOT NULL,
state VARCHAR(30) NOT NULL,
created_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
PRIMARY KEY (id),
FOREIGN KEY (dataset_id) REFERENCES dataset (dataset_id)
);

CREATE INDEX ON dataset_debias_detect (dataset_id);
CREATE INDEX ON harvesting_parameter (dataset_id);
CREATE INDEX ON dataset_log (dataset_id);
CREATE INDEX ON record_log (record_id);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/database/schema_drop.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BEGIN;
DROP TABLE IF EXISTS dataset_debias_detect;
DROP TABLE IF EXISTS dataset_log;
DROP TABLE IF EXISTS harvesting_parameter;
DROP TABLE IF EXISTS dataset;
Expand Down

0 comments on commit 663a245

Please sign in to comment.