-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from AAFC-BICoE/29608_Add_storage_unit_to_Seq…
…Batch 29608 add storage unit to seq batch
- Loading branch information
Showing
10 changed files
with
117 additions
and
75 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
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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/ca/gc/aafc/seqdb/api/validation/SeqBatchValidator.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,44 @@ | ||
package ca.gc.aafc.seqdb.api.validation; | ||
|
||
import ca.gc.aafc.seqdb.api.entities.SeqBatch; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.Validator; | ||
|
||
@Component | ||
public class SeqBatchValidator implements Validator { | ||
|
||
private static final String ERROR_MESSAGE_KEY = "validation.constraint.violation.storageUnitOrType"; | ||
|
||
private final MessageSource messageSource; | ||
|
||
public SeqBatchValidator(MessageSource messageSource) { | ||
this.messageSource = messageSource; | ||
} | ||
|
||
@Override | ||
public boolean supports(Class<?> clazz) { | ||
return SeqBatch.class.isAssignableFrom(clazz); | ||
} | ||
|
||
@Override | ||
public void validate(Object target, Errors errors) { | ||
if (!supports(target.getClass())) { | ||
throw new IllegalArgumentException("SeqBatchValidator not supported for class " + target.getClass()); | ||
} | ||
checkStorageOrTypeNotBoth(errors, (SeqBatch) target); | ||
} | ||
|
||
private void checkStorageOrTypeNotBoth(Errors errors, SeqBatch seqBatch) { | ||
if (seqBatch.getStorageUnit() != null && seqBatch.getStorageUnitType() != null) { | ||
String errorMessage = getMessage(ERROR_MESSAGE_KEY); | ||
errors.rejectValue("storageUnit", ERROR_MESSAGE_KEY, errorMessage); | ||
} | ||
} | ||
|
||
private String getMessage(String key) { | ||
return messageSource.getMessage(key, null, LocaleContextHolder.getLocale()); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/resources/db/changelog/migrations/34-Add_storage_SeqBatch.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,15 @@ | ||
<?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" | ||
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS"> | ||
|
||
<changeSet id="34-Add_storage_SeqBatch" context="schema-change" author="cgendreau"> | ||
<addColumn tableName="seq_batch"> | ||
<column name="storage_unit" type="uuid"/> | ||
<column name="storage_unit_type" type="uuid"/> | ||
<column name="storage_restriction" type="jsonb"/> | ||
</addColumn> | ||
</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
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
71 changes: 0 additions & 71 deletions
71
src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/DBBackedIntegrationTest.java
This file was deleted.
Oops, something went wrong.
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