Skip to content

Commit 9ca6fa1

Browse files
committed
fix list projects endpoints
1 parent 7ac6d1c commit 9ca6fa1

File tree

7 files changed

+33
-25
lines changed

7 files changed

+33
-25
lines changed

tc-online-review-api/src/main/java/com/topcoder/onlinereview/component/or/dataaccess/BaseDataAccess.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ public class BaseDataAccess {
3737
/** A <code>long</code> providing the ID of project status <code>Draft</code>. */
3838
protected static final long PROJECT_STATUS_DRAFT_ID = 2;
3939

40-
@Value("{data-access.entity-manager-name}")
40+
@Value("${data-access.entity-manager-name}")
4141
private String entityManagerName;
4242

43-
@Autowired @Qualifier("entityManagerMap")private Map<String, EntityManager> entityManagerMap;
43+
@Autowired
44+
@Qualifier("entityManagerMap")
45+
private Map<String, EntityManager> entityManagerMap;
46+
4447
private EntityManager entityManager;
4548

4649
@PostConstruct

tc-online-review-api/src/main/java/com/topcoder/onlinereview/component/shared/dataaccess/DataAccess.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.topcoder.onlinereview.component.shared.dataaccess;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
5-
63
import javax.persistence.EntityManager;
74
import java.util.List;
85
import java.util.Map;
@@ -15,7 +12,6 @@
1512
* @see RequestInt
1613
*/
1714
public class DataAccess {
18-
private static Logger log = LoggerFactory.getLogger(DataAccess.class);
1915
private EntityManager entityManager;
2016

2117
/**

tc-online-review-api/src/main/java/com/topcoder/onlinereview/component/shared/dataaccess/DataRetriever.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public Map<String, List<Map<String, Object>>> executeCommand(Map inputMap) throw
381381
String input = (String) inputs.get(inputCode);
382382

383383
if (input == null) {
384-
if (!optional.equals("Y")) {
384+
if (!"Y".equals(optional)) {
385385
throw new Exception("Missing required query input: " + inputCode);
386386
}
387387

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.topcoder.onlinereview.controller;
22

3-
import com.topcoder.onlinereview.dto.ProjectDto;
4-
import com.topcoder.onlinereview.service.ProjectService;
3+
import com.topcoder.onlinereview.component.exception.BaseException;
4+
import com.topcoder.onlinereview.dto.ListProjectResponse;
5+
import com.topcoder.onlinereview.service.ListProjectService;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.web.bind.annotation.GetMapping;
78
import org.springframework.web.bind.annotation.RequestParam;
89
import org.springframework.web.bind.annotation.RestController;
910

10-
import java.util.List;
11-
1211
@RestController
1312
public class ProjectController {
14-
@Autowired private ProjectService projectService;
13+
@Autowired private ListProjectService listProjectService;
1514

1615
@GetMapping("projects")
17-
public List<ProjectDto> listProjects(
18-
@RequestParam(required = false, defaultValue = "1") String stid) {
19-
return projectService.getProjects(stid);
16+
public ListProjectResponse listProjects(
17+
@RequestParam(required = false, defaultValue = "1") String stid) throws BaseException {
18+
return listProjectService.listProjects(1, "my", 132456L, "Global Manager");
2019
}
2120
}

tc-online-review-api/src/main/java/com/topcoder/onlinereview/service/ListProjectService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class ListProjectService {
4747
@Autowired private PhaseManager phaseManager;
4848
@Autowired private ContestEligibilityService contestEligibilityService;
4949
@Autowired private LookupHelper lookupHelper;
50+
@Autowired private ProjectDataAccess projectDataAccess;
51+
@Autowired private ProjectPhaseDataAccess phasesDataAccess;
52+
@Autowired private DeliverableDataAccess deliverableDataAccess;
5053

5154
public ListProjectResponse listProjects(Integer activeTab, String scope, long userId, String role)
5255
throws BaseException {
@@ -86,7 +89,6 @@ public ListProjectResponse listProjects(Integer activeTab, String scope, long us
8689
ProjectStatus draftStatus = lookupHelper.getProjectStatus("Draft");
8790
ProjectStatus activeStatus = lookupHelper.getProjectStatus("Active");
8891
Project[] ungroupedProjects;
89-
ProjectDataAccess projectDataAccess = new ProjectDataAccess();
9092
ProjectStatus[] projectStatuses = projectManager.getAllProjectStatuses();
9193

9294
if (activeTab != 1) {
@@ -142,7 +144,6 @@ public ListProjectResponse listProjects(Integer activeTab, String scope, long us
142144

143145
PhaseType[] phaseTypes = phaseManager.getAllPhaseTypes();
144146

145-
ProjectPhaseDataAccess phasesDataAccess = new ProjectPhaseDataAccess();
146147
Map<Long, com.topcoder.onlinereview.component.project.phase.Project> phProjects;
147148

148149
if (activeTab != 1) {
@@ -338,7 +339,7 @@ private Project[] filterUsingEligibilityConstraints(
338339
private Deliverable[] getDeliverables(
339340
Project[][] projects, Phase[][][] phases, Resource[][][] resources)
340341
throws DeliverablePersistenceException, DeliverableCheckingException, SearchBuilderException {
341-
DeliverableDataAccess deliverableDataAccess = new DeliverableDataAccess();
342+
342343
Map<Long, Map<Long, Long>> deliverableTypes = deliverableDataAccess.getDeliverablesList();
343344

344345
// Validate parameters

tc-online-review-api/src/main/java/com/topcoder/onlinereview/util/CommonUtils.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,47 @@
88
import java.util.Date;
99
import java.util.List;
1010
import java.util.Map;
11+
import java.util.function.Function;
1112

1213
public class CommonUtils {
1314
public static <T, R> R copyProperties(T t, R r) {
1415
BeanUtils.copyProperties(t, r);
1516
return r;
1617
}
1718

19+
private static <T> T getT(Map<String, Object> map, String key, Function<Object, T> function) {
20+
if (map.get(key) == null) {
21+
return null;
22+
}
23+
return function.apply(map.get(key));
24+
}
25+
1826
public static Long getLong(Map<String, Object> map, String key) {
19-
return Long.parseLong(map.get(key).toString());
27+
return getT(map, key, v -> Long.parseLong(v.toString()));
2028
}
2129

2230
public static Integer getInt(Map<String, Object> map, String key) {
23-
return Integer.parseInt(map.get(key).toString());
31+
return getT(map, key, v -> Integer.parseInt(v.toString()));
2432
}
2533

2634
public static Double getDouble(Map<String, Object> map, String key) {
27-
return Double.parseDouble(map.get(key).toString());
35+
return getT(map, key, v -> Double.parseDouble(v.toString()));
2836
}
2937

3038
public static Float getFloat(Map<String, Object> map, String key) {
31-
return Float.parseFloat(map.get(key).toString());
39+
return getT(map, key, v -> Float.parseFloat(v.toString()));
3240
}
3341

3442
public static Boolean getBoolean(Map<String, Object> map, String key) {
35-
return (Boolean) map.get(key);
43+
return getT(map, key, v -> (Boolean) v);
3644
}
3745

3846
public static String getString(Map<String, Object> map, String key) {
39-
return map.get(key).toString();
47+
return getT(map, key, v -> v.toString());
4048
}
4149

4250
public static Date getDate(Map<String, Object> map, String key) {
43-
return (Date) map.get(key);
51+
return getT(map, key, v -> (Date) v);
4452
}
4553

4654
public static List<Map<String, Object>> executeSql(EntityManager entityManager, String sql) {

tc-online-review-api/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ spring.jpa.hibernate.ddl-auto=update
2121
logging.level.org.hibernate.SQL=DEBUG
2222
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
2323

24+
data-access.entity-manager-name=idsEntityManager
2425
resource.persistence.entity-manager-name=idsEntityManager
2526
phase.persistence.entity-manager-name=idsEntityManager
2627
project.persistence.entity-manager-name=idsEntityManager

0 commit comments

Comments
 (0)