-
Notifications
You must be signed in to change notification settings - Fork 0
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 #74 from companieshouse/lp-457-handle-jurisdiction
LP-457 Handle the new Jurisdiction field
- Loading branch information
Showing
14 changed files
with
260 additions
and
50 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
33 changes: 33 additions & 0 deletions
33
src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/model/Jurisdiction.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,33 @@ | ||
package uk.gov.companieshouse.limitedpartnershipsapi.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; | ||
|
||
public enum Jurisdiction { | ||
ENGLAND_AND_WALES("England and Wales"), | ||
NORTHERN_IRELAND("Northern Ireland"), | ||
SCOTLAND("Scotland"), | ||
@JsonEnumDefaultValue | ||
UNKNOWN("Unknown"); | ||
|
||
private final String description; | ||
|
||
Jurisdiction(String description) { | ||
this.description = description; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@JsonCreator | ||
public static Jurisdiction fromDescription(String description) { | ||
for (Jurisdiction jurisdiction : Jurisdiction.values()) { | ||
if (jurisdiction.getDescription().equalsIgnoreCase(description)) { | ||
return jurisdiction; | ||
} | ||
} | ||
|
||
return Jurisdiction.UNKNOWN; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
.../gov/companieshouse/limitedpartnershipsapi/model/dto/validator/JurisdictionValidator.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,17 @@ | ||
package uk.gov.companieshouse.limitedpartnershipsapi.model.dto.validator; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import uk.gov.companieshouse.limitedpartnershipsapi.model.Jurisdiction; | ||
|
||
import static uk.gov.companieshouse.limitedpartnershipsapi.model.Jurisdiction.UNKNOWN; | ||
|
||
public class JurisdictionValidator implements ConstraintValidator<ValidJurisdiction, Jurisdiction> { | ||
public boolean isValid(Jurisdiction jurisdiction, ConstraintValidatorContext context) { | ||
if (jurisdiction == null) { | ||
return true; | ||
} | ||
|
||
return !UNKNOWN.equals(jurisdiction); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...a/uk/gov/companieshouse/limitedpartnershipsapi/model/dto/validator/ValidJurisdiction.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 uk.gov.companieshouse.limitedpartnershipsapi.model.dto.validator; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Constraint(validatedBy = JurisdictionValidator.class) | ||
@Target({ElementType.FIELD, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ValidJurisdiction { | ||
String message() default "Jurisdiction must be valid"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
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
Oops, something went wrong.