Skip to content

Commit

Permalink
35474 Add IdentifyType support
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
cgendreau committed Dec 23, 2024
1 parent 40f7335 commit 57e9aa8
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@

<asciidoctor-maven-plugin.version>2.1.0</asciidoctor-maven-plugin.version>
<asciidoctorj.diagram.version>2.0.2</asciidoctorj.diagram.version>
<dina-base-api.version>0.133</dina-base-api.version>
<dina-base-api.version>0.134-SNAPSHOT</dina-base-api.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<spring-boot-maven-plugin.fork>false</spring-boot-maven-plugin.fork>

<!-- versions override-->
<spring-framework.version>5.3.38</spring-framework.version>
<postgresql.version>42.4.4</postgresql.version>
</properties>

<dependencies>
<dependency>
<groupId>io.github.aafc-bicoe</groupId>
Expand Down
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;
}
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);
}
}
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);
}


}
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<include file="db/changelog/migrations/19-Add_identifier_table.xml"/>
<include file="db/changelog/migrations/20-Add_pos_to_organization_rel.xml"/>
<include file="db/changelog/migrations/21-Remove_legacy_identifier_column.xml"/>
<include file="db/changelog/migrations/22-Add_identifier_type_table.xml"/>
</databaseChangeLog>
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>
2 changes: 2 additions & 0 deletions src/test/java/ca/gc/aafc/agent/api/BaseIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;

Expand All @@ -17,6 +18,7 @@
@TestPropertySource(properties = "spring.config.additional-location=classpath:application-test.yml")
@Transactional
@ContextConfiguration(initializers = { PostgresTestContainerInitializer.class })
@Import(BaseIntegrationTest.CollectionModuleTestConfiguration.class)
public abstract class BaseIntegrationTest {

@TestConfiguration
Expand Down
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());
}
}
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));
}
}

0 comments on commit 57e9aa8

Please sign in to comment.