-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP
- Loading branch information
Showing
9 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/ca/gc/aafc/agent/api/entities/AgentIdentifierType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ca.gc.aafc.agent.api.entities; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import org.hibernate.annotations.Generated; | ||
import org.hibernate.annotations.GenerationTime; | ||
import org.hibernate.annotations.NaturalId; | ||
import org.hibernate.annotations.Type; | ||
|
||
import ca.gc.aafc.dina.entity.IdentifierType; | ||
import ca.gc.aafc.dina.i18n.MultilingualTitle; | ||
|
||
@Entity(name = "identifier_type") | ||
@Getter | ||
@Setter | ||
@SuperBuilder | ||
public class AgentIdentifierType implements IdentifierType { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@NaturalId | ||
@NotNull | ||
@Column(name = "uuid", unique = true) | ||
private UUID uuid; | ||
|
||
@Column(name = "created_by") | ||
private String createdBy; | ||
|
||
@Column(name = "created_on", insertable = false, updatable = false) | ||
@Generated(value = GenerationTime.INSERT) | ||
private OffsetDateTime createdOn; | ||
|
||
@Column(name = "key") | ||
private String key; | ||
|
||
private String name; | ||
|
||
@Type(type = "list-array") | ||
private List<String> dinaComponents; | ||
|
||
private String uriTemplate; | ||
|
||
private String term; | ||
|
||
@Type(type = "jsonb") | ||
private MultilingualTitle multilingualTitle; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/ca/gc/aafc/agent/api/service/AgentIdentifierTypeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ca.gc.aafc.agent.api.service; | ||
|
||
import lombok.NonNull; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.validation.SmartValidator; | ||
|
||
import ca.gc.aafc.agent.api.entities.AgentIdentifierType; | ||
import ca.gc.aafc.dina.jpa.BaseDAO; | ||
import ca.gc.aafc.dina.service.IdentifierTypeService; | ||
import ca.gc.aafc.dina.validation.IdentifierTypeValidator; | ||
|
||
@Service | ||
public class AgentIdentifierTypeService extends IdentifierTypeService<AgentIdentifierType> { | ||
|
||
public AgentIdentifierTypeService(@NonNull BaseDAO baseDAO, | ||
@NonNull SmartValidator validator, | ||
IdentifierTypeValidator identifierTypeValidator) { | ||
super(baseDAO, validator, identifierTypeValidator); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/ca/gc/aafc/agent/api/validation/AgentIdentifierTypeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ca.gc.aafc.agent.api.validation; | ||
|
||
|
||
import javax.inject.Named; | ||
|
||
import org.springframework.context.MessageSource; | ||
import org.springframework.stereotype.Component; | ||
|
||
import ca.gc.aafc.dina.validation.IdentifierTypeValidator; | ||
|
||
@Component | ||
public class AgentIdentifierTypeValidator extends IdentifierTypeValidator { | ||
public AgentIdentifierTypeValidator(@Named("validationMessageSource") MessageSource messageSource) { | ||
super(messageSource); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/resources/db/changelog/migrations/22-Add_identifier_type_table.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.1" encoding="UTF-8" standalone="no" ?> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://local.xsd/dbchangelog-4.4.xsd" | ||
context="schema-change"> | ||
|
||
<changeSet id="22-Add_identifier_type_table" context="schema-change" author="cgendreau"> | ||
<createTable tableName="identifier_type"> | ||
<column autoIncrement="true" name="id" type="SERIAL"> | ||
<constraints primaryKey="true" primaryKeyName="pk_identifier_type_id"/> | ||
</column> | ||
<column name="uuid" type="uuid"> | ||
<constraints nullable="false" unique="true"/> | ||
</column> | ||
|
||
<column name="key" type="VARCHAR(50)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
|
||
<column name="name" type="VARCHAR(50)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="term" type="VARCHAR(100)"/> | ||
<column name="dina_components" type="text[]"/> | ||
<column name="uri_template" type="varchar(100)"/> | ||
<column name="multilingual_title" type="jsonb"/> | ||
<column name="created_by" type="varchar(255)"/> | ||
<column name="created_on" type="timestamptz" defaultValueComputed="current_timestamp"/> | ||
</createTable> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/test/java/ca/gc/aafc/agent/api/service/AgentIdentifierTypeServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ca.gc.aafc.agent.api.service; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import ca.gc.aafc.agent.api.BaseIntegrationTest; | ||
import ca.gc.aafc.agent.api.testsupport.factories.AgentIdentifierTypeFactory; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class AgentIdentifierTypeServiceIT extends BaseIntegrationTest { | ||
|
||
@Inject | ||
private AgentIdentifierTypeService agentIdentifierTypeService; | ||
|
||
@Test | ||
public void createAgentIdentifierType() { | ||
var identifierType = AgentIdentifierTypeFactory.newAgentIdentifierType(); | ||
agentIdentifierTypeService.create(identifierType.build()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/java/ca/gc/aafc/agent/api/testsupport/factories/AgentIdentifierTypeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ca.gc.aafc.agent.api.testsupport.factories; | ||
|
||
import java.util.UUID; | ||
|
||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
import ca.gc.aafc.agent.api.entities.AgentIdentifierType; | ||
|
||
|
||
public class AgentIdentifierTypeFactory { | ||
|
||
public static AgentIdentifierType.AgentIdentifierTypeBuilder<?,?> newAgentIdentifierType() { | ||
return AgentIdentifierType | ||
.builder() | ||
.uuid(UUID.randomUUID()) | ||
.name(RandomStringUtils.randomAlphabetic(10)); | ||
} | ||
} |