Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 15c600e

Browse files
author
ykohata
committed
Merge branch 'technology-2014-10-02'
2 parents 27c6dec + 81bb5a2 commit 15c600e

13 files changed

+225
-57
lines changed

actions/rss.js

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/*
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.0
4+
* @version 1.1
55
* @author Ghost_141
6+
* Changes in 1.1:
7+
* - Add technologies and platforms filter.
68
*/
79
"use strict";
810

911
var async = require('async');
1012
var _ = require('underscore');
13+
var fs = require('fs');
1114
var BadRequestError = require('../errors/BadRequestError');
1215
var UnauthorizedError = require('../errors/UnauthorizedError');
1316
var ForbiddenError = require('../errors/ForbiddenError');
@@ -17,6 +20,38 @@ var ForbiddenError = require('../errors/ForbiddenError');
1720
*/
1821
var VALID_CHALLENGE_TYPE = ['develop', 'design', 'data'];
1922

23+
/**
24+
* The technology filter for challenges api.
25+
* @since 1.1
26+
*/
27+
var TECHNOLOGY_FILTER = ' AND EXISTS (SELECT DISTINCT 1 FROM comp_technology ct WHERE ct.comp_vers_id = pi1.value ' +
28+
'AND ct.technology_type_id IN (@filter@))';
29+
30+
/**
31+
* The platform filter for challenges api.
32+
* @since 1.1
33+
*/
34+
var PLATFORM_FILTER = ' AND EXISTS (SELECT 1 FROM project_platform pp WHERE pp.project_platform_id IN (@filter@) ' +
35+
'AND p.project_id = pp.project_id)';
36+
37+
/**
38+
* Add tech filter and platform filter.
39+
* @param query
40+
* @param techId
41+
* @param platformId
42+
* @param helper
43+
* @returns {*}
44+
*/
45+
function addFilter(query, techId, platformId, helper) {
46+
if (_.isDefined(techId)) {
47+
query = helper.editSql(query, TECHNOLOGY_FILTER, techId.join(','));
48+
}
49+
if (_.isDefined(platformId)) {
50+
query = helper.editSql(query, PLATFORM_FILTER, platformId.join(','));
51+
}
52+
return query;
53+
}
54+
2055
/**
2156
* Get the challenges RSS information.
2257
*
@@ -30,6 +65,10 @@ function getChallengesRSS(api, connection, next) {
3065
RSSMaxLength = api.config.tcConfig.maxRSSLength,
3166
positionsRemain = RSSMaxLength,
3267
challengeType = connection.params.challengeType,
68+
technologies = connection.params.technologies,
69+
techId,
70+
platforms = connection.params.platforms,
71+
platformId,
3372
listType = (connection.params.listType || helper.ListType.OPEN).toUpperCase(),
3473
copyToResult = function (queryResults) {
3574
if (positionsRemain > 0) {
@@ -68,51 +107,78 @@ function getChallengesRSS(api, connection, next) {
68107
error = helper.checkContains(VALID_CHALLENGE_TYPE, challengeType.toLowerCase(), 'challengeType');
69108
}
70109
error = error || helper.checkContains(helper.VALID_LIST_TYPE, listType, 'listType');
71-
if (error) {
72-
cb(error);
73-
return;
74-
}
75110

76111
challengeType = (challengeType || 'all').toLowerCase();
77-
112+
cb(error);
113+
},
114+
function (cb) {
115+
if (!_.isUndefined(technologies)) {
116+
helper.getCatalogCachedValue(technologies.split(','), dbConnectionMap, 'technologies', cb);
117+
} else {
118+
cb(null, null);
119+
}
120+
},
121+
function (id, cb) {
122+
if (_.isDefined(techId)) {
123+
techId = id;
124+
}
125+
if (!_.isUndefined(platforms)) {
126+
helper.getCatalogCachedValue(platforms.split(','), dbConnectionMap, 'platforms', cb);
127+
} else {
128+
cb(null, null);
129+
}
130+
},
131+
function (id, cb) {
132+
if (_.isDefined(id)) {
133+
platformId = id;
134+
}
135+
helper.readQuery('get_software_studio_challenges_rss', cb);
136+
},
137+
function (q, cb) {
138+
q = addFilter(q, techId, platformId, helper);
139+
// edit the sql
78140
async.parallel({
79141
design: function (cbx) {
80142
if (challengeType === 'design' || challengeType === 'all') {
81-
api.dataAccess.executeQuery('get_software_studio_challenges_rss',
143+
api.dataAccess.executeSqlQuery(q,
82144
{
83145
page_size: RSSMaxLength,
84146
project_status_id: helper.LIST_TYPE_PROJECT_STATUS_MAP[listType],
85147
project_type_id: helper.studio.category,
86148
registration_phase_status: helper.LIST_TYPE_REGISTRATION_STATUS_MAP[listType]
87-
}, dbConnectionMap, cbx);
149+
}, 'tcs_catalog', dbConnectionMap, cbx);
88150
} else {
89151
cbx();
90152
}
91153
},
92154
develop: function (cbx) {
93155
if (challengeType === 'develop' || challengeType === 'all') {
94-
api.dataAccess.executeQuery('get_software_studio_challenges_rss',
156+
api.dataAccess.executeSqlQuery(q,
95157
{
96158
page_size: RSSMaxLength,
97159
project_status_id: helper.LIST_TYPE_PROJECT_STATUS_MAP[listType],
98160
project_type_id: helper.software.category,
99161
registration_phase_status: helper.LIST_TYPE_REGISTRATION_STATUS_MAP[listType]
100-
}, dbConnectionMap, cbx);
162+
}, 'tcs_catalog', dbConnectionMap, cbx);
101163
} else {
102164
cbx();
103165
}
104166
},
105167
data: function (cbx) {
106-
if (challengeType === 'data' || challengeType === 'all') {
107-
if (listType === helper.ListType.PAST) {
108-
api.dataAccess.executeQuery('get_past_data_challenges_rss', { page_size: RSSMaxLength }, dbConnectionMap, cbx);
109-
} else if (listType === helper.ListType.OPEN || listType === helper.ListType.ACTIVE) {
110-
api.dataAccess.executeQuery('get_open_data_challenges_rss', { page_size: RSSMaxLength }, dbConnectionMap, cbx);
168+
if (_.isDefined(techId) || _.isDefined(platformId)) {
169+
cbx();
170+
} else {
171+
if (challengeType === 'data' || challengeType === 'all') {
172+
if (listType === helper.ListType.PAST) {
173+
api.dataAccess.executeQuery('get_past_data_challenges_rss', { page_size: RSSMaxLength }, dbConnectionMap, cbx);
174+
} else if (listType === helper.ListType.OPEN || listType === helper.ListType.ACTIVE) {
175+
api.dataAccess.executeQuery('get_open_data_challenges_rss', { page_size: RSSMaxLength }, dbConnectionMap, cbx);
176+
} else {
177+
cbx();
178+
}
111179
} else {
112180
cbx();
113181
}
114-
} else {
115-
cbx();
116182
}
117183
}
118184
}, cb);

actions/srmChallenges.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.5
5-
* @author Sky_, freegod, panoptimum
4+
* @version 1.6
5+
* @author Sky_, freegod, panoptimum, Ghost_141
66
* changes in 1.1:
77
* - implement srm API
88
* changes in 1.2:
@@ -20,6 +20,8 @@
2020
* - load round access api
2121
* changes in 1.5
2222
* - added API for retrieving SRM schedule
23+
* Changes in 1.6:
24+
* - Update search srm challenges api to use informixoltp database.
2325
*/
2426
/*jslint node: true, nomen: true */
2527
"use strict";
@@ -177,17 +179,17 @@ exports.searchSRMChallenges = {
177179
description: "searchSRMChallenges",
178180
inputs: {
179181
required: [],
180-
optional: ["pageSize", "pageIndex", "sortColumn", "sortOrder"]
182+
optional: ["pageSize", "pageIndex", "sortColumn", "sortOrder", "listType"]
181183
},
182184
blockedConnectionTypes: [],
183185
outputExample: {},
184186
version: 'v2',
185187
transaction: 'read', // this action is read-only
186-
databases: ["topcoder_dw"],
188+
databases: ["informixoltp"],
187189
run: function (api, connection, next) {
188190
api.log("Execute searchSRMChallenges#run", 'debug');
189-
var helper = api.helper, params = connection.params, sqlParams,
190-
pageIndex, pageSize, sortColumn, sortOrder, error, result,
191+
var helper = api.helper, params = connection.params, sqlParams, listType,
192+
pageIndex, pageSize, sortColumn, sortOrder, error, result, status,
191193
dbConnectionMap = connection.dbConnectionMap;
192194
if (!dbConnectionMap) {
193195
helper.handleNoConnection(api, connection, next);
@@ -202,11 +204,18 @@ exports.searchSRMChallenges = {
202204
}
203205
pageIndex = Number(params.pageIndex || 1);
204206
pageSize = Number(params.pageSize || DEFAULT_PAGE_SIZE);
207+
listType = (params.listType || 'ACTIVE').toUpperCase();
205208

206209
if (!_.isDefined(params.sortOrder) && sortColumn === "roundid") {
207210
sortOrder = "desc";
208211
}
209212

213+
if (listType === helper.ListType.ACTIVE) {
214+
status = 'A';
215+
} else {
216+
status = 'F';
217+
}
218+
210219
async.waterfall([
211220
function (cb) {
212221
var allowedSort = helper.getLowerCaseList(ALLOWABLE_SORT_COLUMN);
@@ -219,6 +228,7 @@ exports.searchSRMChallenges = {
219228
helper.checkPageIndex(pageIndex, "pageIndex") ||
220229
helper.checkPositiveInteger(pageSize, "pageSize") ||
221230
helper.checkContains(["asc", "desc"], sortOrder, "sortOrder") ||
231+
helper.checkContains([helper.ListType.ACTIVE, helper.ListType.UPCOMING], listType, 'listType') ||
222232
helper.checkContains(allowedSort, sortColumn, "sortColumn");
223233
if (error) {
224234
cb(error);
@@ -233,7 +243,8 @@ exports.searchSRMChallenges = {
233243
firstRowIndex: (pageIndex - 1) * pageSize,
234244
pageSize: pageSize,
235245
sortColumn: helper.getSortColumnDBName(sortColumn),
236-
sortOrder: sortOrder
246+
sortOrder: sortOrder,
247+
status: status
237248
};
238249

239250
async.parallel({

apiary.apib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6341,7 +6341,7 @@ Request
63416341
### View Algorithm SRM Challenges [GET]
63426342
63436343
+ Parameters
6344-
+ listType (optional, string, `Active`) ... The type of challenges to search. It can only be 'ACTIVE', 'OPEN', 'PAST' or 'UPCOMING'. If it's null, 'Active' will be used.
6344+
+ listType (optional, string, `Active`) ... The type of challenges to search. It can only be 'ACTIVE' or 'UPCOMING'. If it's null, 'Active' will be used.
63456345
+ filter (optional, string, `type`) ... Key of the filter key-value pair
63466346
+ value (optional, string, `Development`) ... Value of the filter key-value pair
63476347
+ pageIndex (optional, number, `1`) ... The paging number, 1-based, -1 if no paging. It can be null.

config/servers/web.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ exports.default = {
5454
// When true, returnErrorCodes will modify the response header for http(s) clients if connection.error is not null.
5555
// You can also set connection.rawConnection.responseHttpCode to specify a code per request.
5656
returnErrorCodes: false
57+
,
58+
// http(s).Server#timeout
59+
timeout: 4 * 60 * 1000
5760
};
5861
}
5962
}

initializers/configurator.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
3+
*
4+
* @version 1.0
5+
* @author kohata
6+
*/
7+
"use strict";
8+
9+
exports.configurator = function(api, next){
10+
11+
api.configurator = {
12+
_start: function(api, next){
13+
this.configWeb(api);
14+
next();
15+
},
16+
configWeb: function(api){
17+
if(!api.servers || !api.servers.servers['web'] || !api.servers.servers['web'].server) {
18+
api.log('[configurator] web server has not been created.', 'warning');
19+
return;
20+
}
21+
22+
var timeout = api.config.servers.web.timeout || 10 * 60 * 1000;
23+
24+
api.servers.servers['web'].server.timeout = timeout;
25+
api.log('[configurator] web.server#timeout => '+timeout, 'info');
26+
}
27+
};
28+
29+
next();
30+
}

initializers/helper.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* This module contains helper functions.
88
* @author Sky_, Ghost_141, muzehyun, kurtrips, isv, LazyChild, hesibo, panoptimum, flytoj2ee
9-
* @version 1.37
9+
* @version 1.38
1010
* changes in 1.1:
1111
* - add mapProperties
1212
* changes in 1.2:
@@ -99,6 +99,8 @@
9999
* - Updated apiName2dbNameMap to add entries for registration_start_date and challenge_community columns
100100
* - Updated formatDateWithTimezone function to accept optional 'format' parameter.
101101
* - Updated checkDates function to accept optional 'errorMessage' parameter.
102+
* Changes in 1.38:
103+
* - Add method editSql, readQuery and constant QUERY_PATH.
102104
*/
103105
"use strict";
104106

@@ -1699,6 +1701,41 @@ helper.checkSortColumn = function (sortColumns, sortColumn) {
16991701
return null;
17001702
};
17011703

1704+
/**
1705+
* Add template into sql.
1706+
* @param {String} sql - the sql query.
1707+
* @param {String} template - the template that will insert into sql
1708+
* @param {String} content - the content that need in template.
1709+
* @since 1.38
1710+
*/
1711+
helper.editSql = function (sql, template, content) {
1712+
// For empty sql just return it.
1713+
if (sql.length === 0) {
1714+
return sql;
1715+
}
1716+
var index = sql.toLowerCase().indexOf('order by');
1717+
if (!_.isUndefined(template)) {
1718+
template = template.replace('@filter@', content);
1719+
}
1720+
return sql.slice(0, index) + template + sql.slice(index, sql.length);
1721+
};
1722+
1723+
/**
1724+
* The path that store all query files.
1725+
* @since 1.38
1726+
*/
1727+
helper.QUERY_PATH = './queries/';
1728+
1729+
/**
1730+
* Read the query from file name.
1731+
* @param {String} name - The file that store the query under queries folder.
1732+
* @param {Function} cb - The callback function.
1733+
* @since 1.38
1734+
*/
1735+
helper.readQuery = function (name, cb) {
1736+
fs.readFile(helper.QUERY_PATH + name, 'utf8', cb);
1737+
};
1738+
17021739
/*
17031740
* this is the random int generator class
17041741
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"bigdecimal": "0.6.x",
2727
"bignum": "0.6.x",
2828
"java": "0.3.x",
29-
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#33e1a9a1a8131b4a9580ca959f8b597ae22351d3",
29+
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#469300dbd4913c5d467b6957bc4610d95c3923ed",
3030
"forums-wrapper": "git://github.com/cloudspokes/forums-wrapper.git#12b57be495c2e10431173522bc9eff60e0575959",
3131
"asn1": "*",
3232
"crypto": "0.0.x",

queries/get_software_studio_challenges_rss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ FIRST @page_size@
1010
, pcl.project_type_id
1111
FROM project p
1212
INNER JOIN project_category_lu pcl ON pcl.project_category_id = p.project_category_id
13+
INNER JOIN project_info pi1 ON pi1.project_id = p.project_id AND pi1.project_info_type_id = 1
1314
INNER JOIN project_info pi ON pi.project_info_type_id = 6 AND p.project_id = pi.project_id
1415
INNER JOIN project_phase pp1 ON pp1.project_id = p.project_id AND pp1.phase_type_id = 1
1516
LEFT JOIN project_spec ps ON ps.project_id = p.project_id and ps.version = (select max(version) from project_spec where project_id = p.project_id)

0 commit comments

Comments
 (0)