Skip to content

Commit 7734f82

Browse files
AS-3092: Implement BenchmarkPerUnitEndpointsImpl.
1 parent 33e2b57 commit 7734f82

File tree

8 files changed

+61
-24
lines changed

8 files changed

+61
-24
lines changed

farms-api/farms-api-rest-endpoints/src/main/java/ca/bc/gov/farms/api/rest/v1/endpoints/BenchmarkPerUnitEndpoints.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.ws.rs.Path;
99
import javax.ws.rs.PathParam;
1010
import javax.ws.rs.Produces;
11+
import javax.ws.rs.QueryParam;
1112
import javax.ws.rs.core.MediaType;
1213
import javax.ws.rs.core.Response;
1314

@@ -30,6 +31,25 @@
3031
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
3132
public interface BenchmarkPerUnitEndpoints {
3233

34+
@Operation(operationId = "Get Benchmark Per Unit resource by Program Year.", summary = "Get Benchmark Per Unit resource by Program Year.", extensions = {
35+
@Extension(properties = {
36+
@ExtensionProperty(name = "auth-type", value = "#{wso2.x-auth-type.app_and_app_user}"),
37+
@ExtensionProperty(name = "throttling-tier", value = "Unlimited") }) })
38+
@Parameters({
39+
@Parameter(name = HeaderConstants.REQUEST_ID_HEADER, description = HeaderConstants.REQUEST_ID_HEADER_DESCRIPTION, required = false, schema = @Schema(implementation = String.class), in = ParameterIn.HEADER),
40+
@Parameter(name = HeaderConstants.VERSION_HEADER, description = HeaderConstants.VERSION_HEADER_DESCRIPTION, required = false, schema = @Schema(implementation = Integer.class), in = ParameterIn.HEADER),
41+
@Parameter(name = HeaderConstants.CACHE_CONTROL_HEADER, description = HeaderConstants.CACHE_CONTROL_DESCRIPTION, required = false, schema = @Schema(implementation = String.class), in = ParameterIn.HEADER),
42+
@Parameter(name = HeaderConstants.PRAGMA_HEADER, description = HeaderConstants.PRAGMA_HEADER_DESCRIPTION, required = false, schema = @Schema(implementation = String.class), in = ParameterIn.HEADER),
43+
@Parameter(name = HeaderConstants.AUTHORIZATION_HEADER, description = HeaderConstants.AUTHORIZATION_HEADER_DESCRIPTION, required = false, schema = @Schema(implementation = String.class), in = ParameterIn.HEADER)
44+
})
45+
@ApiResponses(value = {
46+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = BenchmarkPerUnitRsrc.class)), headers = @Header(name = HeaderConstants.ETAG_HEADER, schema = @Schema(implementation = String.class), description = HeaderConstants.ETAG_DESCRIPTION)),
47+
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = MessageListRsrc.class))) })
48+
@GET
49+
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
50+
public Response getBenchmarkPerUnitsByProgramYear(
51+
@Parameter(description = "The identifier of the Benchmark Per Unit resource.") @QueryParam("programYear") Integer programYear);
52+
3353
@Operation(operationId = "Get Benchmark Per Unit resource by Benchmark Per Unit Id.", summary = "Get Benchmark Per Unit resource by Benchmark Per Unit Id.", extensions = {
3454
@Extension(properties = {
3555
@ExtensionProperty(name = "auth-type", value = "#{wso2.x-auth-type.app_and_app_user}"),

farms-api/farms-api-rest-endpoints/src/main/java/ca/bc/gov/farms/api/rest/v1/endpoints/impl/BenchmarkPerUnitEndpointsImpl.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ public class BenchmarkPerUnitEndpointsImpl extends BaseEndpointsImpl implements
2020
@Autowired
2121
private BenchmarkPerUnitService service;
2222

23+
@Override
24+
public Response getBenchmarkPerUnitsByProgramYear(Integer programYear) {
25+
logger.debug("<getBenchmarkPerUnitsByProgramYear");
26+
27+
Response response = null;
28+
29+
logRequest();
30+
31+
try {
32+
BenchmarkPerUnitListRsrc result = (BenchmarkPerUnitListRsrc) service
33+
.getBenchmarkPerUnitsByProgramYear(programYear, getFactoryContext());
34+
response = Response.ok(result).tag(result.getUnquotedETag()).build();
35+
} catch (Throwable t) {
36+
response = getInternalServerErrorResponse(t);
37+
}
38+
39+
logResponse(response);
40+
41+
logger.debug(">getBenchmarkPerUnitsByProgramYear " + response);
42+
return response;
43+
}
44+
2345
@Override
2446
public Response getBenchmarkPerUnit(Long benchmarkPerUnitId) {
2547
logger.debug("<getBenchmarkPerUnit");
@@ -28,15 +50,9 @@ public Response getBenchmarkPerUnit(Long benchmarkPerUnitId) {
2850
logRequest();
2951

3052
try {
31-
if (benchmarkPerUnitId == null) {
32-
BenchmarkPerUnitListRsrc result = (BenchmarkPerUnitListRsrc) service
33-
.getBenchmarkPerUnitList(getFactoryContext());
34-
response = Response.ok(result).tag(result.getUnquotedETag()).build();
35-
} else {
36-
BenchmarkPerUnitRsrc result = (BenchmarkPerUnitRsrc) service.getBenchmarkPerUnit(benchmarkPerUnitId,
37-
getFactoryContext());
38-
response = Response.ok(result).tag(result.getUnquotedETag()).build();
39-
}
53+
BenchmarkPerUnitRsrc result = (BenchmarkPerUnitRsrc) service.getBenchmarkPerUnit(benchmarkPerUnitId,
54+
getFactoryContext());
55+
response = Response.ok(result).tag(result.getUnquotedETag()).build();
4056
} catch (NotFoundException e) {
4157
response = Response.status(Response.Status.NOT_FOUND).build();
4258
} catch (Throwable t) {

farms-api/farms-persistence/src/main/java/ca/bc/gov/farms/persistence/v1/dao/BenchmarkPerUnitDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface BenchmarkPerUnitDao extends Serializable {
1111

1212
BenchmarkPerUnitDto fetch(Long benchmarkPerUnitId) throws DaoException;
1313

14-
List<BenchmarkPerUnitDto> fetchAll() throws DaoException;
14+
List<BenchmarkPerUnitDto> fetchByProgramYear(Integer programYear) throws DaoException;
1515

1616
void insert(BenchmarkPerUnitDto dto, String userId) throws DaoException;
1717

farms-api/farms-persistence/src/main/java/ca/bc/gov/farms/persistence/v1/dao/mybatis/BenchmarkPerUnitDaoImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,20 @@ public BenchmarkPerUnitDto fetch(Long benchmarkPerUnitId) throws DaoException {
4747
}
4848

4949
@Override
50-
public List<BenchmarkPerUnitDto> fetchAll() throws DaoException {
51-
logger.debug("<fetchAll");
50+
public List<BenchmarkPerUnitDto> fetchByProgramYear(Integer programYear) throws DaoException {
51+
logger.debug("<fetchByProgramYear");
5252

5353
List<BenchmarkPerUnitDto> dtos = null;
5454

5555
try {
5656
Map<String, Object> parameters = new HashMap<>();
57-
dtos = this.mapper.fetchAll(parameters);
57+
parameters.put("programYear", programYear);
58+
dtos = this.mapper.fetchBy(parameters);
5859
} catch (RuntimeException e) {
5960
handleException(e);
6061
}
6162

62-
logger.debug(">fetchAll " + dtos);
63+
logger.debug(">fetchByProgramYear " + dtos);
6364
return dtos;
6465
}
6566

farms-api/farms-persistence/src/main/java/ca/bc/gov/farms/persistence/v1/dao/mybatis/mapper/BenchmarkPerUnitMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface BenchmarkPerUnitMapper {
99

1010
BenchmarkPerUnitDto fetch(Map<String, Object> parameters);
1111

12-
List<BenchmarkPerUnitDto> fetchAll(Map<String, Object> parameters);
12+
List<BenchmarkPerUnitDto> fetchBy(Map<String, Object> parameters);
1313

1414
int insert(Map<String, Object> parameters);
1515

farms-api/farms-persistence/src/main/resources/ca/bc/gov/farms/persistence/v1/dao/mybatis/mapper/BenchmarkPerUnitMapper.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
where bpu.benchmark_per_unit_id = #{benchmarkPerUnitId}
4242
</select>
4343

44-
<select id="fetchAll" resultMap="BenchmarkPerUnitDtoMap">
44+
<select id="fetchBy" resultMap="BenchmarkPerUnitDtoMap">
4545
<include refid="selectColumns"/>
4646
from benchmark_per_unit bpu
47-
order by bpu.program_year, bpu.unit_comment
47+
where bpu.program_year = #{programYear}
48+
order by bpu.unit_comment
4849
</select>
4950

5051
<insert id="insert">

farms-api/farms-service-api/src/main/java/ca/bc/gov/farms/service/api/v1/BenchmarkPerUnitService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public interface BenchmarkPerUnitService {
1313

1414
@Transactional(readOnly = true, rollbackFor = Exception.class)
15-
BenchmarkPerUnitList<? extends BenchmarkPerUnit> getBenchmarkPerUnitList(FactoryContext factoryContext)
15+
BenchmarkPerUnitList<? extends BenchmarkPerUnit> getBenchmarkPerUnitsByProgramYear(Integer programYear, FactoryContext factoryContext)
1616
throws ServiceException;
1717

1818
@Transactional(readOnly = true, rollbackFor = Exception.class)

farms-api/farms-service-api/src/main/java/ca/bc/gov/farms/service/api/v1/impl/BenchmarkPerUnitServiceImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ca.bc.gov.farms.service.api.v1.impl;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54
import java.util.Properties;
65

@@ -52,21 +51,21 @@ public void setBenchmarkPerUnitDao(BenchmarkPerUnitDao benchmarkPerUnitDao) {
5251
}
5352

5453
@Override
55-
public BenchmarkPerUnitList<? extends BenchmarkPerUnit> getBenchmarkPerUnitList(FactoryContext factoryContext)
56-
throws ServiceException {
57-
logger.debug("<getBenchmarkPerUnitList");
54+
public BenchmarkPerUnitList<? extends BenchmarkPerUnit> getBenchmarkPerUnitsByProgramYear(Integer programYear,
55+
FactoryContext factoryContext) throws ServiceException {
56+
logger.debug("<getBenchmarkPerUnitsByProgramYear");
5857

5958
BenchmarkPerUnitList<? extends BenchmarkPerUnit> result = null;
6059

6160
try {
62-
List<BenchmarkPerUnitDto> dtos = benchmarkPerUnitDao.fetchAll();
61+
List<BenchmarkPerUnitDto> dtos = benchmarkPerUnitDao.fetchByProgramYear(programYear);
6362

6463
result = benchmarkPerUnitFactory.getBenchmarkPerUnitList(dtos, factoryContext);
6564
} catch (DaoException e) {
6665
throw new ServiceException("DAO threw an exception", e);
6766
}
6867

69-
logger.debug(">getBenchmarkPerUnitList");
68+
logger.debug(">getBenchmarkPerUnitsByProgramYear");
7069
return result;
7170
}
7271

0 commit comments

Comments
 (0)