-
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.
Options API Jurisdictions and Program Areas (#1519)
* jurisdiction api * Program Areas
- Loading branch information
1 parent
b5a18a6
commit 85965c1
Showing
16 changed files
with
596 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
apps/modernization-ui/src/generated/services/JurisdictionOptionsService.ts
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 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { Option } from '../models/Option'; | ||
import type { CancelablePromise } from '../core/CancelablePromise'; | ||
import { OpenAPI } from '../core/OpenAPI'; | ||
import { request as __request } from '../core/request'; | ||
export class JurisdictionOptionsService { | ||
/** | ||
* NBS Jurisdiction Option Autocomplete | ||
* Provides options from Facilities that have a name matching a criteria. | ||
* @returns Option OK | ||
* @throws ApiError | ||
*/ | ||
public static jurisdictionAutocomplete({ | ||
criteria, | ||
limit = 15, | ||
}: { | ||
criteria: string, | ||
limit?: number, | ||
}): CancelablePromise<Array<Option>> { | ||
return __request(OpenAPI, { | ||
method: 'GET', | ||
url: '/nbs/api/options/jurisdictions/search', | ||
query: { | ||
'criteria': criteria, | ||
'limit': limit, | ||
}, | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
apps/modernization-ui/src/generated/services/ProgramAreaOptionsService.ts
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 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { Option } from '../models/Option'; | ||
import type { CancelablePromise } from '../core/CancelablePromise'; | ||
import { OpenAPI } from '../core/OpenAPI'; | ||
import { request as __request } from '../core/request'; | ||
export class ProgramAreaOptionsService { | ||
/** | ||
* NBS Program Area Option Autocomplete | ||
* Provides options from Facilities that have a name matching a criteria. | ||
* @returns Option OK | ||
* @throws ApiError | ||
*/ | ||
public static programAreaAutocomplete({ | ||
criteria, | ||
limit = 15, | ||
}: { | ||
criteria: string, | ||
limit?: number, | ||
}): CancelablePromise<Array<Option>> { | ||
return __request(OpenAPI, { | ||
method: 'GET', | ||
url: '/nbs/api/options/program-areas/search', | ||
query: { | ||
'criteria': criteria, | ||
'limit': limit, | ||
}, | ||
}); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...v/cdc/nbs/option/jurisdictions/autocomplete/JurisdictionOptionAutocompleteController.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,36 @@ | ||
package gov.cdc.nbs.option.jurisdictions.autocomplete; | ||
|
||
import gov.cdc.nbs.option.Option; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Collection; | ||
|
||
@RestController | ||
@RequestMapping("nbs/api/options/jurisdictions/search") | ||
class JurisdictionOptionAutocompleteController { | ||
|
||
private final JurisdictionOptionResolver resolver; | ||
|
||
JurisdictionOptionAutocompleteController(final JurisdictionOptionResolver finder) { | ||
this.resolver = finder; | ||
} | ||
|
||
@Operation( | ||
operationId = "jurisdiction-autocomplete", | ||
summary = "NBS Jurisdiction Option Autocomplete", | ||
description = "Provides options from Facilities that have a name matching a criteria.", | ||
tags = "JurisdictionOptions" | ||
) | ||
@GetMapping | ||
Collection<Option> complete( | ||
@RequestParam final String criteria, | ||
@RequestParam(defaultValue = "15" | ||
) final int limit) { | ||
return this.resolver.resolve(criteria, limit); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...c/main/java/gov/cdc/nbs/option/jurisdictions/autocomplete/JurisdictionOptionResolver.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,27 @@ | ||
package gov.cdc.nbs.option.jurisdictions.autocomplete; | ||
|
||
import gov.cdc.nbs.option.jdbc.autocomplete.SQLBasedOptionResolver; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class JurisdictionOptionResolver extends SQLBasedOptionResolver { | ||
|
||
private static final String QUERY = """ | ||
select | ||
code as [value], | ||
code_short_desc_txt as [name], | ||
indent_level_nbr as [order] | ||
from [NBS_SRTE].[dbo].Jurisdiction_code | ||
where status_cd = 'A' | ||
and code_short_desc_txt like :criteria | ||
order by | ||
indent_level_nbr | ||
offset 0 rows | ||
fetch next :limit rows only | ||
"""; | ||
|
||
JurisdictionOptionResolver(final NamedParameterJdbcTemplate template) { | ||
super(QUERY, template); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...gov/cdc/nbs/option/program/area/autocomplete/ProgramAreaOptionAutocompleteController.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,36 @@ | ||
package gov.cdc.nbs.option.program.area.autocomplete; | ||
|
||
import gov.cdc.nbs.option.Option; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Collection; | ||
|
||
@RestController | ||
@RequestMapping("nbs/api/options/program-areas/search") | ||
class ProgramAreaOptionAutocompleteController { | ||
|
||
private final ProgramAreaOptionResolver resolver; | ||
|
||
ProgramAreaOptionAutocompleteController(final ProgramAreaOptionResolver finder) { | ||
this.resolver = finder; | ||
} | ||
|
||
@Operation( | ||
operationId = "program-area-autocomplete", | ||
summary = "NBS Program Area Option Autocomplete", | ||
description = "Provides options from Facilities that have a name matching a criteria.", | ||
tags = "ProgramAreaOptions" | ||
) | ||
@GetMapping | ||
Collection<Option> complete( | ||
@RequestParam final String criteria, | ||
@RequestParam(defaultValue = "15") final int limit | ||
) { | ||
return this.resolver.resolve(criteria, limit); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/gov/cdc/nbs/option/program/area/autocomplete/ProgramAreaOptionResolver.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,27 @@ | ||
package gov.cdc.nbs.option.program.area.autocomplete; | ||
|
||
import gov.cdc.nbs.option.jdbc.autocomplete.SQLBasedOptionResolver; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class ProgramAreaOptionResolver extends SQLBasedOptionResolver { | ||
|
||
private static final String QUERY = """ | ||
select | ||
prog_area_cd as [value], | ||
prog_area_desc_txt as [name], | ||
nbs_uid as [order] | ||
from [NBS_SRTE].[dbo].Program_area_code | ||
where status_cd = 'A' | ||
and prog_area_desc_txt like :criteria | ||
order by | ||
nbs_uid | ||
offset 0 rows | ||
fetch next :limit rows only | ||
"""; | ||
|
||
ProgramAreaOptionResolver(final NamedParameterJdbcTemplate template) { | ||
super(QUERY, template); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
libs/options-api/src/test/java/gov/cdc/nbs/option/AutocompleteRequester.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 gov.cdc.nbs.option; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
@Component | ||
public class AutocompleteRequester { | ||
|
||
private final MockMvc mvc; | ||
|
||
AutocompleteRequester(final MockMvc mvc) { | ||
this.mvc = mvc; | ||
} | ||
|
||
public ResultActions complete(final String name, final String criteria) throws Exception { | ||
return mvc.perform( | ||
get("/nbs/api/options/{name}/search", name) | ||
.param("criteria", criteria)) | ||
.andDo(print()); | ||
} | ||
|
||
public ResultActions complete(final String name, final String criteria, final int limit) throws Exception { | ||
return mvc.perform( | ||
get("/nbs/api/options/{name}/search", name) | ||
.param("criteria", criteria) | ||
.param("limit", String.valueOf(limit))) | ||
.andDo(print()); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
libs/options-api/src/test/java/gov/cdc/nbs/option/jurisdiction/JurisdictionMother.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,94 @@ | ||
package gov.cdc.nbs.option.jurisdiction; | ||
|
||
import gov.cdc.nbs.option.Option; | ||
import gov.cdc.nbs.testing.support.Available; | ||
import io.cucumber.spring.ScenarioScope; | ||
import jakarta.annotation.PreDestroy; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.Serializable; | ||
import java.sql.PreparedStatement; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Component | ||
@ScenarioScope | ||
class JurisdictionMother { | ||
|
||
private static final String DELETE_IN = """ | ||
delete | ||
from NBS_SRTE.[dbo].Jurisdiction_code | ||
where code in (:codes) | ||
"""; | ||
|
||
private static final String CREATE = """ | ||
insert into NBS_SRTE.[dbo].Jurisdiction_code( | ||
code, | ||
code_short_desc_txt, | ||
indent_level_nbr, | ||
status_cd, | ||
type_cd | ||
) | ||
values (:identifier, :name, :order, 'A', 'ALL') | ||
"""; | ||
|
||
private final NamedParameterJdbcTemplate template; | ||
private final Available<Option> availalbe; | ||
|
||
JurisdictionMother(final JdbcTemplate template) { | ||
this.template = new NamedParameterJdbcTemplate(template); | ||
this.availalbe = new Available<>(); | ||
} | ||
|
||
@PreDestroy | ||
void reset() { | ||
|
||
List<String> codes = this.availalbe.all() | ||
.map(Option::value) | ||
.toList(); | ||
|
||
if (!codes.isEmpty()) { | ||
|
||
Map<String, List<String>> parameters = Map.of("codes", codes); | ||
|
||
template.execute( | ||
DELETE_IN, | ||
new MapSqlParameterSource(parameters), | ||
PreparedStatement::executeUpdate); | ||
|
||
this.availalbe.reset(); | ||
} | ||
} | ||
|
||
void create(final String name) { | ||
|
||
String code = UUID.randomUUID().toString() | ||
.replace("-", "") | ||
.substring(0, 20); | ||
|
||
int order = this.availalbe.all() | ||
.map(Option::order) | ||
.max(Comparator.naturalOrder()) | ||
.orElse(1) + 1; | ||
|
||
Map<String, ? extends Serializable> parameters = Map.of( | ||
"identifier", code, | ||
"name", name, | ||
"order", order); | ||
|
||
template.execute( | ||
CREATE, | ||
new MapSqlParameterSource(parameters), | ||
PreparedStatement::executeUpdate | ||
); | ||
|
||
this.availalbe.available(new Option(code, name, name, order)); | ||
|
||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
libs/options-api/src/test/java/gov/cdc/nbs/option/jurisdiction/JurisdictionOptionSteps.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,19 @@ | ||
package gov.cdc.nbs.option.jurisdiction; | ||
|
||
import io.cucumber.java.en.Given; | ||
|
||
public class JurisdictionOptionSteps { | ||
|
||
private final JurisdictionMother mother; | ||
|
||
|
||
JurisdictionOptionSteps(final JurisdictionMother mother) { | ||
this.mother = mother; | ||
} | ||
|
||
@Given("there is a {string} jurisdiction") | ||
public void the_jurisdiction_exists_in_the_value_set(final String name) { | ||
mother.create(name); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...test/java/gov/cdc/nbs/option/jurisdiction/autocomplete/JurisdictionAutocompleteSteps.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,35 @@ | ||
package gov.cdc.nbs.option.jurisdiction.autocomplete; | ||
|
||
import gov.cdc.nbs.option.AutocompleteRequester; | ||
import gov.cdc.nbs.testing.support.Active; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
public class JurisdictionAutocompleteSteps { | ||
|
||
private static final String NAME = "jurisdictions"; | ||
private final AutocompleteRequester request; | ||
private final Active<ResultActions> response; | ||
|
||
JurisdictionAutocompleteSteps( | ||
final AutocompleteRequester request, | ||
final Active<ResultActions> response | ||
) { | ||
this.request = request; | ||
this.response = response; | ||
} | ||
|
||
@When("I am trying to find jurisdictions that start with {string}") | ||
public void i_am_trying_to_find_jurisdiction_that_start_with(final String criteria) throws Exception { | ||
response.active(request.complete(NAME, criteria)); | ||
} | ||
|
||
@When("I am trying to find at most {int} jurisdiction(s) that start with {string}") | ||
public void i_am_trying_to_find_n_jurisdiction_that_start_with( | ||
final int limit, | ||
final String criteria | ||
) throws Exception { | ||
response.active(request.complete("jurisdictions", criteria, limit)); | ||
} | ||
|
||
} |
Oops, something went wrong.