From fd08d91cc977bd70dae0c88a4dd398386e6a35c2 Mon Sep 17 00:00:00 2001 From: Ghost141 Date: Sat, 22 Mar 2014 02:06:21 +0800 Subject: [PATCH] Module Assembly - TopCoder NodeJS Apply Develop Review Opportunity API --- actions/challengeRegistration.js | 2 + actions/challenges.js | 1 + actions/reviewOpportunities.js | 339 +++++++++++++- apiary.apib | 159 +++++++ initializers/challengeHelper.js | 12 +- initializers/helper.js | 26 +- queries/check_challenge_is_copilot_posting | 10 +- .../check_challenge_is_copilot_posting.json | 8 +- queries/check_reviewer | 6 + queries/check_reviewer.json | 5 + queries/get_assigned_review_resource_role | 11 + .../get_assigned_review_resource_role.json | 5 + queries/get_next_sequence_tcs_catalog | 1 + queries/get_next_sequence_tcs_catalog.json | 5 + queries/get_user_review_applications | 12 + queries/get_user_review_applications.json | 5 + queries/insert_resource | 36 +- queries/insert_review_application | 2 + queries/insert_review_application.json | 5 + queries/review_opportunity_detail | 87 ++++ queries/review_opportunity_detail.json | 5 + queries/update_review_application | 1 + queries/update_review_application.json | 5 + routes.js | 7 +- .../common_oltp__clean | 2 + .../common_oltp__insert_test_data | 5 + .../tcs_catalog__clean | 9 + .../tcs_catalog__insert_test_data | 187 ++++++++ .../challengeRegistration/tcs_catalog__clean | 38 +- .../tcs_catalog__insert_test_data | 110 ++--- test/test.applyDevelopReviewOpportunity.js | 419 ++++++++++++++++++ ...review_opportunities_response_message.json | 26 ++ 32 files changed, 1436 insertions(+), 115 deletions(-) create mode 100644 queries/check_reviewer create mode 100644 queries/check_reviewer.json create mode 100644 queries/get_assigned_review_resource_role create mode 100644 queries/get_assigned_review_resource_role.json create mode 100644 queries/get_next_sequence_tcs_catalog create mode 100644 queries/get_next_sequence_tcs_catalog.json create mode 100644 queries/get_user_review_applications create mode 100644 queries/get_user_review_applications.json create mode 100644 queries/insert_review_application create mode 100644 queries/insert_review_application.json create mode 100644 queries/review_opportunity_detail create mode 100644 queries/review_opportunity_detail.json create mode 100644 queries/update_review_application create mode 100644 queries/update_review_application.json create mode 100644 test/sqls/applyDevelopReviewOpportunity/common_oltp__clean create mode 100644 test/sqls/applyDevelopReviewOpportunity/common_oltp__insert_test_data create mode 100644 test/sqls/applyDevelopReviewOpportunity/tcs_catalog__clean create mode 100644 test/sqls/applyDevelopReviewOpportunity/tcs_catalog__insert_test_data create mode 100644 test/test.applyDevelopReviewOpportunity.js create mode 100644 test/test_files/expected_apply_software_review_opportunities_response_message.json diff --git a/actions/challengeRegistration.js b/actions/challengeRegistration.js index d6225c96f..7091d50de 100644 --- a/actions/challengeRegistration.js +++ b/actions/challengeRegistration.js @@ -594,6 +594,7 @@ var registerSoftwareChallengeAction = function (api, connection, next) { connection, challengeId, "Submitter", //optional value. Here we don't need to provide such value. + true, connection.dbConnectionMap, cb ); @@ -644,6 +645,7 @@ var registerStudioChallengeAction = function (api, connection, next) { connection, challengeId, "Submitter", + true, connection.dbConnectionMap, cb ); diff --git a/actions/challenges.js b/actions/challenges.js index 777306c48..e49f3620f 100755 --- a/actions/challenges.js +++ b/actions/challenges.js @@ -1256,6 +1256,7 @@ exports.getChallengeTerms = { connection, challengeId, role, + true, connection.dbConnectionMap, cb ); diff --git a/actions/reviewOpportunities.js b/actions/reviewOpportunities.js index ecd43518e..1e80b1c8d 100644 --- a/actions/reviewOpportunities.js +++ b/actions/reviewOpportunities.js @@ -1,8 +1,8 @@ /* * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. * - * @version 1.3 - * @author Sky_, Ghost_141 + * @version 1.4 + * @author Sky_, Ghost_141, TCSASSEMBLER * changes in 1.1 * - Implement the studio review opportunities. * changes in 1.2 @@ -10,12 +10,17 @@ * - remove getStudioReviewOpportunities method. * changes in 1.3: * - Implement the getSoftwareReviewOpportunity api. + * Changes in 1.4: + * - Implement the applyDevelopReviewOpportunity API. + * - add VALID_REVIEW_APPLICATION_ROLE_ID and REVIEW_APPLICATION_STATUS. */ 'use strict'; var async = require('async'); var _ = require('underscore'); +var moment = require('moment'); var NotFoundError = require('../errors/NotFoundError'); var IllegalArgumentError = require('../errors/IllegalArgumentError'); +var BadRequestError = require('../errors/BadRequestError'); var ForbiddenError = require('../errors/ForbiddenError'); /** @@ -68,6 +73,37 @@ var STUDIO_ALLOWABLE_QUERY_PARAMETER = ['round1ScheduledStartDate.type', 'round1 */ var SOFTWARE_REVIEW_TYPE = ['Iterative Review', 'Spec Review', 'Contest Review']; +/** + * Valid value for review application role id. + * + * @since 1.4 + */ +var VALID_REVIEW_APPLICATION_ROLE_ID = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + +/** + * The review application status object. + * + * @since 1.4 + */ +var REVIEW_APPLICATION_STATUS = { + pending: { + name: 'Pending', + id: 1 + }, + cancelled: { + name: 'Cancelled', + id: 2 + }, + approved: { + name: 'Approved', + id: 3 + }, + rejected: { + name: 'Rejected', + id: 4 + } +}; + /** * Format the date value to a specific pattern. * @param dateValue {String} the date value. @@ -650,6 +686,278 @@ var getSoftwareReviewOpportunity = function (api, connection, next) { }); }; +/** + * Handle the apply develop review opportunities api. + * @param {Object} api - the api object. + * @param {Object} connection - the connection object. + * @param {Function} next - the callback function. + * @since 1.4 + */ +var applyDevelopReviewOpportunity = function (api, connection, next) { + var helper = api.helper, + caller = connection.caller, + resourceRoleNames = [], + dbConnectionMap = connection.dbConnectionMap, + challengeId = Number(connection.params.challengeId), + reviewApplicationRoleId = connection.params.reviewApplicationRoleId, + reviewAuctionId, + message, + reviewAssignmentDate, + currentUserApplications; + + // The reviewApplicationRoleId is undefined. Initialize it. + if (!_.isDefined(reviewApplicationRoleId)) { + reviewApplicationRoleId = []; + } + + // Only have one review application role id. + if (!_.isArray(reviewApplicationRoleId)) { + reviewApplicationRoleId = [reviewApplicationRoleId]; + } + // Unique the array and transfer the value to number. + reviewApplicationRoleId = _(reviewApplicationRoleId) + .chain() + .uniq() + .map(function (item) { return Number(item); }) + .value(); + + async.waterfall([ + function (cb) { + var error = helper.checkPositiveInteger(challengeId, 'challengeId') || + helper.checkMaxInt(challengeId, 'challengeId') || + helper.checkMember(connection, 'Anonymous user don\'t have permission to access this api.'); + + reviewApplicationRoleId.forEach(function (item) { + error = error || helper.checkContains(VALID_REVIEW_APPLICATION_ROLE_ID, item, 'reviewApplicationRoleId'); + }); + + if (error) { + cb(error); + return; + } + async.parallel({ + detail: function (cbx) { + api.dataAccess.executeQuery('review_opportunity_detail', { challenge_id: challengeId }, dbConnectionMap, cbx); + }, + applications: function (cbx) { + api.dataAccess.executeQuery('get_user_review_applications', { challenge_id: challengeId, user_id: caller.userId }, dbConnectionMap, cbx); + }, + resourceRoles: function (cbx) { + api.dataAccess.executeQuery('get_assigned_review_resource_role', { challenge_id: challengeId }, dbConnectionMap, cbx); + }, + reviewerCheck: function (cbx) { + api.dataAccess.executeQuery('check_reviewer', { challenge_id: challengeId, user_id: caller.userId }, dbConnectionMap, cbx); + }, + privateCheck: function (cbx) { + api.dataAccess.executeQuery('check_user_challenge_accessibility', { challengeId: challengeId, user_id: caller.userId }, dbConnectionMap, cbx); + } + }, cb); + }, + function (res, cb) { + var details = res.detail, + reviewerCheck = res.reviewerCheck, + availableApplicationIds = _.chain(details) + .map(function (item) { return item.review_application_role_id; }) + .uniq() + .value(), + privateCheck = res.privateCheck[0], + positionsLeft, + reviewersCount, + assignedResourceRoles = res.resourceRoles, + currentUserResourceRole = _.filter(assignedResourceRoles, function (item) { return item.user_id === caller.userId; }); + + currentUserApplications = res.applications; + + // The challenge not existed or don't have review opportunity. + if (details.length === 0) { + cb(new BadRequestError('The challenge is not existed or don\'t have any review opportunities or review registration is not open.')); + return; + } + // Initialize it after the definition check. + // The total review positions left for this challenge. + positionsLeft = details[0].positions_left; + // The needed reviewer count. + reviewersCount = details[0].reviewers_count; + // The reviewer assignment date. + reviewAssignmentDate = details[0].assignment_date; + // The review auction id. This will bed used when insert new review application. + reviewAuctionId = details[0].review_auction_id; + + // If the request review application role is not belong to this challenge. + if (_.difference(reviewApplicationRoleId, availableApplicationIds).length > 0) { + cb(new BadRequestError('You can\'t apply the review application role that do not belong to this challenge.')); + return; + } + + // Check if it's a reviewer of this kind of challenge. + // We only check this when caller is trying to apply review opportunity not cancel them. + if (reviewApplicationRoleId.length > 0 && reviewerCheck.length === 0) { + cb(new ForbiddenError('You are not a Review Board member.')); + return; + } + + // The caller can't access this private challenge. + if (privateCheck.is_private && !privateCheck.has_access) { + cb(new ForbiddenError('The user is not allowed to register this challenge review.')); + return; + } + + // We only check this when caller is trying to apply review opportunity not cancel them. + // Get the review resource role that belong to the caller. If the length > 0 then the user is a reviewer already. + if (reviewApplicationRoleId.length > 0 && currentUserResourceRole.length > 0) { + cb(new BadRequestError('You are already assigned as reviewer for the contest.')); + return; + } + + // Do not need reviewer anymore. + if (positionsLeft <= 0) { + cb(new BadRequestError('There are no open positions for this challenge.')); + return; + } + + // iterative the available review application role ids for this challenge. + // The results of this function will be a array of resource role names(The role that caller applied). So we can check the terms of use later. + async.eachSeries(availableApplicationIds, function (roleId, cbx) { + var reviewApplicationRole = _.filter(details, function (item) { return item.review_application_role_id === roleId; }), + positionsNeeds = Math.min(positionsLeft, reviewApplicationRole[0].positions), + isClosed = false, + assignedRoles = _.map(assignedResourceRoles, function (item) { return item.resource_role_id; }), + i; + + if (reviewApplicationRoleId.indexOf(roleId) < 0) { + // The caller not apply this role. + // Update the reviewers count before callback. + positionsLeft -= positionsNeeds; + cbx(); + return; + } + + for (i = 0; i < reviewApplicationRole.length; i += 1) { + if (reviewApplicationRole[i].is_unique && assignedRoles.indexOf(reviewApplicationRole[i].resource_role_id) >= 0) { + isClosed = true; + } + } + console.log('isClosed: ' + isClosed); + + if (isClosed) { + cb(new BadRequestError('There is no open positions for selected review application role: ' + reviewApplicationRole[0].role_name + '.')); + return; + } + + if (positionsLeft === 0) { + cbx(new BadRequestError('There is no open positions for selected review application role: ' + reviewApplicationRole[0].role_name + '.')); + return; + } + + // Has the positions apply the role. + // Store the resource role for later terms of use check. + resourceRoleNames = _.union(resourceRoleNames, + _.chain(details) + .filter(function (item) { return item.review_application_role_id === roleId; }) + .map(function (item) { return item.resource_role_name; }) + .value()); + positionsLeft -= positionsNeeds; + cbx(); + }, function (err) { + cb(err); + }); + }, + function (cb) { + // Check the terms of use for each resource role here. + async.eachSeries(resourceRoleNames, function (role, cbx) { + api.challengeHelper.getChallengeTerms(connection, challengeId, role, false, dbConnectionMap, function (err, terms) { + if (err) { + cbx(err); + return; + } + // If the terms has not been all agreed. + // We don't allow people who has agree all terms. So simply return an error. + if (helper.allTermsAgreed(terms) !== true) { + cb(new ForbiddenError('You should agree with all terms of use.')); + return; + } + cbx(); + }); + }, function (err) { + cb(err); + }); + }, + function (cb) { + // Update or insert the review application. + var currentPendingAppliedApplication = _.filter(currentUserApplications, function (item) { return item.status === REVIEW_APPLICATION_STATUS.pending.name; }), + // The current pending applied application role id for the caller. + currentPendingApplied = _.map(currentPendingAppliedApplication, function (item) { return item.role_id; }), + // The review application role id to remove. + roleToRemove = _.difference(currentPendingApplied, reviewApplicationRoleId), + // The review application role id to add. + roleToAdd = _.difference(reviewApplicationRoleId, currentPendingApplied); + + async.parallel({ + update: function (cbx) { + // Update the role to cancelled status. + async.each(roleToRemove, function (roleId, callback) { + var reviewApplicationId = _.find(currentPendingAppliedApplication, function (item) { return item.role_id === roleId; }).review_application_id; + api.dataAccess.executeQuery('update_review_application', + { review_application_id: reviewApplicationId, status: REVIEW_APPLICATION_STATUS.cancelled.id }, + dbConnectionMap, callback); + }, function (err) { + cbx(err); + }); + }, + add: function (cbx) { + // Add the new application. + async.each(roleToAdd, function (roleId, callback) { + api.idGenerator.getNextIDFromDb('REVIEW_APPLICATION_SEQ', 'tcs_catalog', dbConnectionMap, function (err, id) { + if (err) { + callback(err); + return; + } + api.dataAccess.executeQuery('insert_review_application', + { + review_application_id: id, + review_auction_id: reviewAuctionId, + role_id: roleId, + user_id: caller.userId, + status: REVIEW_APPLICATION_STATUS.pending.id + }, dbConnectionMap, callback); + }); + }, function (err) { + cbx(err); + }); + } + }, function (err) { + cb(err); + }); + }, + function (cb) { + // Register succeed. Prepare the message. + if (reviewApplicationRoleId.length === 0) { + // The user is intend to remove all reigstered review applications. + message = 'Your review application for this contest has been cancelled.'; + } else if (moment(reviewAssignmentDate).isAfter()) { + // The assignment date is not arrived yet. + message = 'You have successfully applied to review this contest. The system will automatically select ' + + 'reviewers that best match the review positions for this contest on ' + + helper.formatDate(reviewAssignmentDate, 'MM.DD.YYYY HH:mm z') + '. You will be notified by email ' + + 'what review role you were assigned to.'; + } else { + // The assignment date is passed. + message = 'You have successfully applied to review this contest. The system will automatically decide ' + + 'whether you match the reviewer requirements for this contest now. You will be notified by email ' + + 'shortly.'; + } + cb(); + } + ], function (err) { + if (err) { + helper.handleError(api, connection, err); + } else { + connection.response = { message: message }; + } + next(connection, true); + }); +}; + /** * The API for searching review opportunities */ @@ -700,6 +1008,33 @@ exports.getSoftwareReviewOpportunity = { } }; +/** + * Apply Develop Review Opportunity API. + * @since 1.4 + */ +exports.applyDevelopReviewOpportunity = { + name: 'applyDevelopReviewOpportunity', + description: 'applyDevelopReviewOpportunity', + inputs: { + required: ['challengeId'], + optional: ['reviewApplicationRoleId'] + }, + blockedConnectionTypes: [], + outputExample: {}, + cacheEnabled: false, + version: 'v2', + transaction: 'write', + databases: ['tcs_catalog', 'common_oltp'], + run: function (api, connection, next) { + if (connection.dbConnectionMap) { + api.log('Execute applyDevelopReviewOpportunity#run', 'debug'); + applyDevelopReviewOpportunity(api, connection, next); + } else { + api.helper.handleNoConnection(api, connection, next); + } + } +}; + /** * The API for getting review opportunities for studio */ diff --git a/apiary.apib b/apiary.apib index 57d0873f4..4ebe75aca 100644 --- a/apiary.apib +++ b/apiary.apib @@ -1338,6 +1338,165 @@ Register a new user. "description":"Servers are up but overloaded. Try again later." } + +## Apply Develop Review Opportunity Detail [/develop/reviewOpportunities/{challengeId}/apply] +### Apply Develop Review Opportunity Information [POST] + ++ Request + + Authorization : Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZHwxMzI0NTYiLCJleHAiOjEzOTQwODA3MTEsImF1ZCI6InRvcGNvZGVyIiwiaWF0IjoxMzk0MDIwNzExfQ.xaaaElykyAq3woRRkcFQSUK0gvKnRCOhCD57x070GJ4 + ++ Parameters + + + challengeId (required, number, `30000000`) ... The challenge id. + + reviewApplicationRoleId (optional, number, `1`) ... The review application role id to apply. + ++ Response 200 (application/json) + + { + "message": "Your review application for this contest has been cancelled." + } + ++ Response 200 (application/json) + + { + "message": "You have successfully applied to review this contest. The system will automatically select reviewers that best match the review positions for this contest on 03.26.2014 08:00. You will be notified by email what review role you were assigned to." + } + ++ Response 200 (application/json) + + { + "message": "You have successfully applied to review this contest. The system will automatically decide whether you match the reviewer requirements for this contest now. You will be notified by email shortly." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be number." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be positive." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be Integer." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"challengeId should be less or equal to 2147483647." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"reviewApplicationRoleId should be an element of 1,2,3,4,5,6,7,8,9." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"The challenge is not existed or don't have any review opportunities or review registration is not open." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"You can't apply the review application role that do not belong to this challenge." + } + ++ Response 403 (application/json) + + { + "name":"Forbidden", + "value":"403", + "description":"You are not a Review Board member." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"You are already assigned as reviewer for the contest." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"There are no open positions for this challenge." + } + ++ Response 400 (application/json) + + { + "name":"Bad Request", + "value":"400", + "description":"There is no open positions for selected review application role: Primary Reviewer." + } + ++ Response 403 (application/json) + + { + "name":"Forbidden", + "value":"403", + "description":"You should agree with all terms of use." + } + ++ Response 401 (application/json) + + { + "name":"Unauthorized", + "value":"401", + "description":"Anonymous user don't have permission to access this api." + } + ++ Response 403 (application/json) + + { + "name":"Forbidden", + "value":"403", + "description":"The user is not allowed to register this challenge review." + } + ++ Response 500 (application/json) + + { + "name":"Internal Server Error", + "value":"500", + "description":"Unknown server error. Please contact support." + } + ++ Response 503 (application/json) + + { + "name":"Service Unavailable", + "value":"503", + "description":"Servers are up but overloaded. Try again later." + } + ## Challenge Reviewers Collection [/develop/reviewers/{contestType}] ### List reviewers of current challenge type [GET] diff --git a/initializers/challengeHelper.js b/initializers/challengeHelper.js index 95d2767d3..b6806dbc5 100644 --- a/initializers/challengeHelper.js +++ b/initializers/challengeHelper.js @@ -1,9 +1,11 @@ /* * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. * - * @version 1.0 - * @author ecnu_haozi + * @version 1.1 + * @author ecnu_haozi, Ghost_141 * Refactor common code out from challenge.js. + * Changes in 1.1 + * - Add new parameter in getChallengeTerms. */ "use strict"; @@ -35,10 +37,11 @@ exports.challengeHelper = function (api, next) { * @param {Object} connection The connection object for the current request * @param {Number} challengeId The challenge id. * @param {String} role The user's role name, this is optional. + * @param {Boolean} requireRegOpen - the flag that indicate need the challenge has open registration phase or not. * @param {Object} dbConnectionMap The database connection map for the current request * @param {Function} next The callback to be called after this function is done */ - getChallengeTerms : function (connection, challengeId, role, dbConnectionMap, next) { + getChallengeTerms : function (connection, challengeId, role, requireRegOpen, dbConnectionMap, next) { //Check if the user is logged-in if (_.isUndefined(connection.caller) || _.isNull(connection.caller) || @@ -80,7 +83,8 @@ exports.challengeHelper = function (api, next) { return; } - if (!rows[0].reg_open) { + // Update check to use flag. + if (requireRegOpen && !rows[0].reg_open) { cb(new ForbiddenError('Registration Phase of this challenge is not open.')); return; } diff --git a/initializers/helper.js b/initializers/helper.js index 3a176ed28..dc504cec3 100644 --- a/initializers/helper.js +++ b/initializers/helper.js @@ -5,9 +5,9 @@ /** * This module contains helper functions. - * @author Sky_, Ghost_141, muzehyun, kurtrips, isv - * @version 1.13 - * changes in 1.15 + * @author Sky_, Ghost_141, muzehyun, kurtrips, isv, TCSASSEMBLER + * @version 1.16 + * changes in 1.1 * - add mapProperties * changes in 1.2: * - add getPercent to underscore mixin @@ -48,6 +48,8 @@ * - add method checkMember to check if the caller have at least member access leve. * changes in 1.15 * - added checkUserExists function + * Changes in 1.16: + * - add allTermsAgreed method. */ "use strict"; @@ -928,9 +930,9 @@ helper.getPhaseId = function (phaseName) { */ helper.getColorStyle = function (rating) { - if (rating === null) { - return "color: #000000"; - } + if (rating === null) { + return "color: #000000"; + } if (rating < 0) { return "color: #FF9900"; // orange @@ -1132,6 +1134,18 @@ helper.checkUserExists = function (handle, api, dbConnectionMap, callback) { }); }; +/** + * check if the every terms has been agreed + * + * @param {Array} terms - The terms. + * @returns {Boolean} true if all terms agreed otherwise false. + * @since 1.16 + */ +helper.allTermsAgreed = function (terms) { + return _.every(terms, function (term) { + return term.agreed; + }); +}; /** * Expose the "helper" utility. diff --git a/queries/check_challenge_is_copilot_posting b/queries/check_challenge_is_copilot_posting index daf047dd7..af486b8e2 100644 --- a/queries/check_challenge_is_copilot_posting +++ b/queries/check_challenge_is_copilot_posting @@ -1,5 +1,5 @@ -SELECT - (project_id IS NOT NULL) as challenge_is_copilot -FROM project p -WHERE p.project_id = @challengeId@ -AND p.project_category_id = 29 +SELECT + (project_id IS NOT NULL) as challenge_is_copilot +FROM project p +WHERE p.project_id = @challengeId@ +AND p.project_category_id = 29 diff --git a/queries/check_challenge_is_copilot_posting.json b/queries/check_challenge_is_copilot_posting.json index aafaac038..523bbf195 100644 --- a/queries/check_challenge_is_copilot_posting.json +++ b/queries/check_challenge_is_copilot_posting.json @@ -1,5 +1,5 @@ -{ - "name" : "check_challenge_is_copilot_posting", - "db" : "tcs_catalog", - "sqlfile" : "check_challenge_is_copilot_posting" +{ + "name" : "check_challenge_is_copilot_posting", + "db" : "tcs_catalog", + "sqlfile" : "check_challenge_is_copilot_posting" } \ No newline at end of file diff --git a/queries/check_reviewer b/queries/check_reviewer new file mode 100644 index 000000000..224b50774 --- /dev/null +++ b/queries/check_reviewer @@ -0,0 +1,6 @@ +SELECT 1 +FROM rboard_user ru +INNER JOIN project p ON ru.project_type_id = p.project_category_id +WHERE ru.user_id = @user_id@ +AND ru.status_id = 100 +AND p.project_id = @challenge_id@ diff --git a/queries/check_reviewer.json b/queries/check_reviewer.json new file mode 100644 index 000000000..a623c3f00 --- /dev/null +++ b/queries/check_reviewer.json @@ -0,0 +1,5 @@ +{ + "name" : "check_reviewer", + "db" : "tcs_catalog", + "sqlfile" : "check_reviewer" +} diff --git a/queries/get_assigned_review_resource_role b/queries/get_assigned_review_resource_role new file mode 100644 index 000000000..cf9d64f6a --- /dev/null +++ b/queries/get_assigned_review_resource_role @@ -0,0 +1,11 @@ +SELECT + DISTINCT + r.resource_role_id +, u.user_id +FROM resource r +INNER JOIN resource_info ri ON r.resource_id = ri.resource_id AND ri.resource_info_type_id = 1 +INNER JOIN user u ON u.user_id = ri.value +INNER JOIN review_auction ra ON ra.project_id = r.project_id +INNER JOIN review_application_role_lu rarl ON rarl.review_auction_type_id = ra.review_auction_type_id +INNER JOIN review_application_role_resource_role_xref rarrrx ON rarrrx.review_application_role_id = rarl.review_application_role_id AND rarrrx.resource_role_id = r.resource_role_id +WHERE r.project_id = @challenge_id@ diff --git a/queries/get_assigned_review_resource_role.json b/queries/get_assigned_review_resource_role.json new file mode 100644 index 000000000..f2539983e --- /dev/null +++ b/queries/get_assigned_review_resource_role.json @@ -0,0 +1,5 @@ +{ + "name" : "get_assigned_review_resource_role", + "db" : "tcs_catalog", + "sqlfile" : "get_assigned_review_resource_role" +} diff --git a/queries/get_next_sequence_tcs_catalog b/queries/get_next_sequence_tcs_catalog new file mode 100644 index 000000000..edfd2117f --- /dev/null +++ b/queries/get_next_sequence_tcs_catalog @@ -0,0 +1 @@ +select SEQUENCE_@seq_name@.NEXTVAL as next_id from table(set{1}) diff --git a/queries/get_next_sequence_tcs_catalog.json b/queries/get_next_sequence_tcs_catalog.json new file mode 100644 index 000000000..9f4a0a275 --- /dev/null +++ b/queries/get_next_sequence_tcs_catalog.json @@ -0,0 +1,5 @@ +{ + "name" : "get_next_sequence_tcs_catalog", + "db" : "tcs_catalog", + "sqlfile" : "get_next_sequence_tcs_catalog" +} diff --git a/queries/get_user_review_applications b/queries/get_user_review_applications new file mode 100644 index 000000000..bc43ec19a --- /dev/null +++ b/queries/get_user_review_applications @@ -0,0 +1,12 @@ +SELECT + rarl.name AS role +, rarl.review_application_role_id AS role_id +, ra.review_application_id +, rasl.name AS status +FROM review_application ra +INNER JOIN user u ON u.user_id = ra.user_id +INNER JOIN review_auction rauc ON rauc.review_auction_id = ra.review_auction_id AND rauc.project_id = @challenge_id@ +INNER JOIN review_application_role_lu rarl ON rarl.review_application_role_id = ra.review_application_role_id +INNER JOIN review_application_status_lu rasl ON rasl.review_application_status_id = ra.review_application_status_id +WHERE u.user_id = @user_id@ +ORDER BY ra.create_date ASC diff --git a/queries/get_user_review_applications.json b/queries/get_user_review_applications.json new file mode 100644 index 000000000..b20108687 --- /dev/null +++ b/queries/get_user_review_applications.json @@ -0,0 +1,5 @@ +{ + "name" : "get_user_review_applications", + "db" : "tcs_catalog", + "sqlfile" : "get_user_review_applications" +} diff --git a/queries/insert_resource b/queries/insert_resource index 16c175bb8..8b1fea59e 100644 --- a/queries/insert_resource +++ b/queries/insert_resource @@ -1,19 +1,19 @@ -INSERT INTO resource - ( resource_id, - resource_role_id, - project_id, - user_id, - create_user, - create_date, - modify_user, - modify_date) -VALUES - ( @resourceId@, - 1, - @projectId@, - @userId@, - @createUser@, - CURRENT, - @modifyUser@, - CURRENT +INSERT INTO resource + ( resource_id, + resource_role_id, + project_id, + user_id, + create_user, + create_date, + modify_user, + modify_date) +VALUES + ( @resourceId@, + 1, + @projectId@, + @userId@, + @createUser@, + CURRENT, + @modifyUser@, + CURRENT ) \ No newline at end of file diff --git a/queries/insert_review_application b/queries/insert_review_application new file mode 100644 index 000000000..f7917bf63 --- /dev/null +++ b/queries/insert_review_application @@ -0,0 +1,2 @@ +INSERT INTO review_application(review_application_id, user_id, review_auction_id, review_application_role_id, review_application_status_id, create_date, modify_date) +VALUES(@review_application_id@, @user_id@, @review_auction_id@, @role_id@, @status@, current, current) diff --git a/queries/insert_review_application.json b/queries/insert_review_application.json new file mode 100644 index 000000000..31fc756ee --- /dev/null +++ b/queries/insert_review_application.json @@ -0,0 +1,5 @@ +{ + "name" : "insert_review_application", + "db" : "tcs_catalog", + "sqlfile" : "insert_review_application" +} diff --git a/queries/review_opportunity_detail b/queries/review_opportunity_detail new file mode 100644 index 000000000..e4c68f5a2 --- /dev/null +++ b/queries/review_opportunity_detail @@ -0,0 +1,87 @@ +-- spec +SELECT + ra.review_auction_id +, 1 - (SELECT COUNT(r.resource_id) FROM resource r WHERE r.project_id=p.project_id AND r.resource_role_id = 18) AS positions_left +, 1 AS reviewers_count +, rarl.name AS role_name +, rarl.review_application_role_id +, rarl.positions +, rarl.order_index +, rrl.name AS resource_role_name +, rrl.resource_role_id +, nvl(pp13.actual_start_time,pp13.scheduled_start_time) + 1 units hour AS assignment_date +, rarrrx.unique_role AS is_unique +FROM review_auction ra +INNER JOIN review_auction_type_lu ratl ON ratl.review_auction_type_id=ra.review_auction_type_id AND ratl.review_auction_category_id=2 +INNER JOIN review_application_role_lu rarl ON rarl.review_auction_type_id = ra.review_auction_type_id +INNER JOIN review_application_role_resource_role_xref rarrrx ON rarrrx.review_application_role_id = rarl.review_application_role_id +INNER JOIN resource_role_lu rrl ON rrl.resource_role_id = rarrrx.resource_role_id +INNER JOIN project p ON p.project_id=ra.project_id +INNER JOIN project_phase pp13 ON pp13.project_id=p.project_id AND pp13.phase_type_id=13 AND not exists (SELECT 1 FROM phase_dependency WHERE dependent_phase_id=pp13.project_phase_id) +INNER JOIN phase_dependency pd ON pd.dependency_phase_id=pp13.project_phase_id +INNER JOIN project_phase pp14 ON pp14.project_id=p.project_id AND pp14.phase_type_id=14 AND pp14.project_phase_id=pd.dependent_phase_id +WHERE p.project_id = @challenge_id@ +AND p.project_status_id = 1 +AND pp13.phase_status_id IN (2, 3) +AND pp14.phase_status_id IN (1, 2) + +UNION ALL + +-- contest +SELECT + ra.review_auction_id +, pc.parameter::int - (SELECT COUNT(r.resource_id) FROM resource r WHERE r.project_id=p.project_id AND r.resource_role_id IN (4,5,6,7)) AS positions_left +, pc.parameter::int AS reviewers_count +, rarl.name AS role_name +, rarl.review_application_role_id +, rarl.positions +, rarl.order_index +, rrl.name AS resource_role_name +, rrl.resource_role_id +, nvl(pp2.actual_end_time,pp2.scheduled_end_time) - 24 units hour AS assignment_date +, rarrrx.unique_role AS is_unique +FROM review_auction ra +INNER JOIN review_auction_type_lu ratl ON ratl.review_auction_type_id=ra.review_auction_type_id AND ratl.review_auction_category_id=1 +INNER JOIN review_application_role_lu rarl ON rarl.review_auction_type_id = ra.review_auction_type_id +INNER JOIN review_application_role_resource_role_xref rarrrx ON rarrrx.review_application_role_id = rarl.review_application_role_id +INNER JOIN resource_role_lu rrl ON rrl.resource_role_id = rarrrx.resource_role_id +INNER JOIN project p ON p.project_id=ra.project_id +INNER JOIN project_phase pp2 ON pp2.project_id=p.project_id AND pp2.phase_type_id=2 +INNER JOIN project_phase pp4 ON pp4.project_id=p.project_id AND pp4.phase_type_id=4 +INNER JOIN phase_criteria pc ON pc.project_phase_id=pp4.project_phase_id AND pc.phase_criteria_type_id=6 +WHERE p.project_id = @challenge_id@ +AND p.project_status_id = 1 +AND pp2.phase_status_id IN (2, 3) +AND pp4.phase_status_id IN (1, 2) +AND not exists (SELECT 1 FROM project_phase pp12 WHERE pp12.project_id=p.project_id AND pp12.phase_type_id=12) + +UNION ALL + +-- iterative +SELECT + ra.review_auction_id +, pc.parameter::int - (SELECT COUNT(r.resource_id) FROM resource r WHERE r.project_id=p.project_id AND r.resource_role_id = 21) AS positions_left +, pc.parameter::int AS reviewers_count +, rarl.name AS role_name +, rarl.review_application_role_id +, rarl.positions +, rarl.order_index +, rrl.name AS resource_role_name +, rrl.resource_role_id +, nvl(pp2.actual_start_time,pp2.scheduled_start_time) + 24 units hour AS assignment_date +, rarrrx.unique_role AS is_unique +FROM review_auction ra +INNER JOIN review_auction_type_lu ratl ON ratl.review_auction_type_id=ra.review_auction_type_id AND ratl.review_auction_category_id=3 +INNER JOIN review_application_role_lu rarl ON rarl.review_auction_type_id = ra.review_auction_type_id +INNER JOIN review_application_role_resource_role_xref rarrrx ON rarrrx.review_application_role_id = rarl.review_application_role_id +INNER JOIN resource_role_lu rrl ON rrl.resource_role_id = rarrrx.resource_role_id +INNER JOIN project p ON p.project_id=ra.project_id +INNER JOIN project_phase pp2 ON pp2.project_id=p.project_id AND pp2.phase_type_id=2 +INNER JOIN project_phase pp18 ON pp18.project_id=p.project_id AND pp18.phase_type_id=18 +INNER JOIN phase_dependency pd ON pd.dependent_phase_id=pp18.project_phase_id AND pd.dependent_start=1 AND pd.dependency_phase_id=pp2.project_phase_id AND pd.dependency_start=1 +INNER JOIN phase_criteria pc ON pc.project_phase_id=pp18.project_phase_id AND pc.phase_criteria_type_id=6 +WHERE p.project_id = @challenge_id@ +AND p.project_status_id = 1 +AND pp2.phase_status_id IN (2, 3) +AND pp18.phase_status_id IN (1, 2) +AND not exists (SELECT 1 FROM project_phase pp12 WHERE pp12.project_id=p.project_id AND pp12.phase_type_id=12) diff --git a/queries/review_opportunity_detail.json b/queries/review_opportunity_detail.json new file mode 100644 index 000000000..447184819 --- /dev/null +++ b/queries/review_opportunity_detail.json @@ -0,0 +1,5 @@ +{ + "name" : "review_opportunity_detail", + "db" : "tcs_catalog", + "sqlfile" : "review_opportunity_detail" +} diff --git a/queries/update_review_application b/queries/update_review_application new file mode 100644 index 000000000..ee1c6bbd6 --- /dev/null +++ b/queries/update_review_application @@ -0,0 +1 @@ +UPDATE review_application SET review_application_status_id = @status@, modify_date = current WHERE review_application_id = @review_application_id@ diff --git a/queries/update_review_application.json b/queries/update_review_application.json new file mode 100644 index 000000000..f541718df --- /dev/null +++ b/queries/update_review_application.json @@ -0,0 +1,5 @@ +{ + "name" : "update_review_application", + "db" : "tcs_catalog", + "sqlfile" : "update_review_application" +} diff --git a/routes.js b/routes.js index 2fc569c04..7caad7724 100755 --- a/routes.js +++ b/routes.js @@ -1,8 +1,8 @@ /* * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. * - * @version 1.24 - * @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild + * @version 1.25 + * @author vangavroche, Sky_, muzehyun, kurtrips, Ghost_141, ecnu_haozi, hesibo, LazyChild, TCSASSEMBLER * Changes in 1.1: * - add routes for search challenges * Changes in 1.2: @@ -59,6 +59,8 @@ * - added route for check email availability api * changes in 1.24 * - added stub api for reset token and reset password + * Changes in 1.25: + * - add route for apply develop review opportunities api. */ /* --------------------- @@ -204,6 +206,7 @@ exports.routes = { // Stub API { path: "/:apiVersion/users/resetPassword/:handle", action: "resetPassword" }, + { path: "/:apiVersion/develop/reviewOpportunities/:challengeId/apply", action: "applyDevelopReviewOpportunity" }, { path: "/:apiVersion/terms/:termsOfUseId/agree", action: "agreeTermsOfUse" }, { path: "/:apiVersion/users", action: "memberRegister" }, { path: "/:apiVersion/develop/challenges/:challengeId/submit", action: "submitForDevelopChallenge" }, diff --git a/test/sqls/applyDevelopReviewOpportunity/common_oltp__clean b/test/sqls/applyDevelopReviewOpportunity/common_oltp__clean new file mode 100644 index 000000000..503a77539 --- /dev/null +++ b/test/sqls/applyDevelopReviewOpportunity/common_oltp__clean @@ -0,0 +1,2 @@ +DELETE FROM user_terms_of_use_xref WHERE user_id = 132457; +DELETE FROM project_role_terms_of_use_xref WHERE project_id = 2001; diff --git a/test/sqls/applyDevelopReviewOpportunity/common_oltp__insert_test_data b/test/sqls/applyDevelopReviewOpportunity/common_oltp__insert_test_data new file mode 100644 index 000000000..2861cd1cf --- /dev/null +++ b/test/sqls/applyDevelopReviewOpportunity/common_oltp__insert_test_data @@ -0,0 +1,5 @@ +INSERT INTO project_role_terms_of_use_xref(project_id, resource_role_id, terms_of_use_id, create_date, modify_date, sort_order, group_ind) +VALUES(2001, 4, 20704, current, current, 0, 1); + +INSERT INTO user_terms_of_use_xref(user_id, terms_of_use_id, create_date, modify_date) +VALUES(132457, 20704, current, current); diff --git a/test/sqls/applyDevelopReviewOpportunity/tcs_catalog__clean b/test/sqls/applyDevelopReviewOpportunity/tcs_catalog__clean new file mode 100644 index 000000000..6d9d635ab --- /dev/null +++ b/test/sqls/applyDevelopReviewOpportunity/tcs_catalog__clean @@ -0,0 +1,9 @@ +DELETE FROM resource_info WHERE resource_id >= 2001; +DELETE FROM resource WHERE project_id >= 2001; +DELETE FROM group_contest_eligibility WHERE contest_eligibility_id = 2001; +DELETE FROM contest_eligibility WHERE contest_id >= 2001; +DELETE FROM phase_criteria WHERE project_phase_id >= 2001; +DELETE FROM project_phase WHERE project_id >= 2001; +DELETE FROM review_application WHERE review_auction_id >= 2001; +DELETE FROM review_auction WHERE project_id >= 2001; +DELETE FROM project WHERE project_id >= 2001; diff --git a/test/sqls/applyDevelopReviewOpportunity/tcs_catalog__insert_test_data b/test/sqls/applyDevelopReviewOpportunity/tcs_catalog__insert_test_data new file mode 100644 index 000000000..77887ea0e --- /dev/null +++ b/test/sqls/applyDevelopReviewOpportunity/tcs_catalog__insert_test_data @@ -0,0 +1,187 @@ +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2001, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2001, 2001, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2001, 2001, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2002, 2001, 2, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2003, 2001, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2004, 2001, 4, 1, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2004, 6, 3, 132456, current, 132456, current); + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2002, 1, 14, 132456, current, 132456, current); + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2003, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2003, 2003, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2005, 2003, 1, 3, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2006, 2003, 2, 3, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2007, 2003, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2008, 2003, 4, 3, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2008, 6, 3, 132456, current, 132456, current); + + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2004, 1, 13, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2004, 2004, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2009, 2004, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2010, 2004, 2, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2011, 2004, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2012, 2004, 4, 2, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2012, 6, 3, 132456, current, 132456, current); + + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2005, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2005, 2005, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2013, 2005, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2014, 2005, 2, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2015, 2005, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2016, 2005, 4, 1, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2016, 6, 3, 132456, current, 132456, current); + +INSERT INTO contest_eligibility(contest_eligibility_id, contest_id, is_studio) VALUES(2001, 2005, 0); +INSERT INTO group_contest_eligibility(contest_eligibility_id, group_id) VALUES(2001, 208); + + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2006, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2006, 2006, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2017, 2006, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2018, 2006, 2, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2019, 2006, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2020, 2006, 4, 1, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2020, 6, 3, 132456, current, 132456, current); + +INSERT INTO resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) +VALUES(2001, 4, 2006, 2020, 132456, 132456, current, 132456, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) +VALUES(2002, 4, 2006, 2020, 132458, 132456, current, 132456, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) +VALUES(2003, 4, 2006, 2020, 124764, 132456, current, 132456, current); + + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2007, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2007, 2007, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2021, 2007, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2022, 2007, 2, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2023, 2007, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2024, 2007, 4, 1, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2024, 6, 3, 132456, current, 132456, current); + +INSERT INTO review_application(review_application_id, user_id, review_auction_id, review_application_role_id, review_application_status_id, create_date, modify_date) +VALUES(2002, 132456, 2007, 1, 3, current, current); + +INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) +VALUES(2004, 2, 2007, 132456, current, 132456, current); +INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) +VALUES(2004, 1, '132456', 132456, current, 132456, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) +VALUES(2005, 4, 2007, 132456, current, 132456, current); +INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) +VALUES(2005, 1, '132456', 132456, current, 132456, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) +VALUES(2006, 8, 2007, 132456, current, 132456, current); +INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) +VALUES(2006, 1, '132456', 132456, current, 132456, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) +VALUES(2007, 9, 2007, 132456, current, 132456, current); +INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) +VALUES(2007, 1, '132456', 132456, current, 132456, current); + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2008, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2008, 2008, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2025, 2008, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2026, 2008, 2, 2, current, current + 3 units month, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2027, 2008, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2028, 2008, 4, 1, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2028, 6, 3, 132456, current, 132456, current); + + +INSERT INTO project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date) +VALUES(2009, 1, 14, 132456, current, 132456, current); + +INSERT INTO review_auction(review_auction_id, project_id, review_auction_type_id) VALUES(2009, 2009, 1); + +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2029, 2009, 1, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2030, 2009, 2, 2, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2031, 2009, 3, 1, current, current, 86400000, 132456, current, 132456, current); +INSERT INTO project_phase(project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) +VALUES(2032, 2009, 4, 1, current, current, 86400000, 132456, current, 132456, current); + +INSERT INTO phase_criteria(project_phase_id, phase_criteria_type_id, parameter, create_user, create_date, modify_user, modify_date) +VALUES(2032, 6, 3, 132456, current, 132456, current); + +INSERT INTO review_application(review_application_id, user_id, review_auction_id, review_application_role_id, review_application_status_id, create_date, modify_date) +VALUES(2003, 124766, 2009, 2, 3, current, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) +VALUES(2008, 4, 2009, 132456, current, 132456, current); +INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) +VALUES(2008, 1, '124766', 132456, current, 132456, current); + +INSERT INTO review_application(review_application_id, user_id, review_auction_id, review_application_role_id, review_application_status_id, create_date, modify_date) +VALUES(2004, 124764, 2009, 2, 3, current, current); +INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) +VALUES(2009, 4, 2009, 132456, current, 132456, current); +INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) +VALUES(2009, 1, '124764', 132456, current, 132456, current); diff --git a/test/sqls/challengeRegistration/tcs_catalog__clean b/test/sqls/challengeRegistration/tcs_catalog__clean index 926452e78..4b38e98ca 100644 --- a/test/sqls/challengeRegistration/tcs_catalog__clean +++ b/test/sqls/challengeRegistration/tcs_catalog__clean @@ -1,20 +1,20 @@ -delete from resource_info; -delete from notification; -delete from resource where project_id > 40000000 and project_id < 40000020; -delete from project_result where project_id > 40000000 and project_id < 40000020; -delete from project_user_audit where project_id > 40000000 and project_id < 40000020; -delete from component_inquiry where project_id > 40000000 and project_id < 40000020; - -delete from project_info where project_id > 40000000 and project_id < 40000020; -delete from project_phase where project_id > 40000000 and project_id < 40000020; -delete from component_inquiry where project_id > 40000000 and project_id < 40000020; -delete from project where project_id > 40000000 and project_id < 40000020; -delete from comp_version_dates_history where comp_vers_id > 40000000 and comp_vers_id < 40000020; -delete from comp_versions where component_id > 40000000 and component_id < 40000020; -delete from comp_versions where comp_vers_id > 40000000 and comp_vers_id < 40000020; -delete from comp_catalog where component_id > 40000000 and component_id < 40000020; -delete from user_rating where user_id = 400011; -delete from user_reliability where user_id = 400011; -delete from project_studio_specification where project_studio_spec_id = 1; - +delete from resource_info; +delete from notification; +delete from resource where project_id > 40000000 and project_id < 40000020; +delete from project_result where project_id > 40000000 and project_id < 40000020; +delete from project_user_audit where project_id > 40000000 and project_id < 40000020; +delete from component_inquiry where project_id > 40000000 and project_id < 40000020; + +delete from project_info where project_id > 40000000 and project_id < 40000020; +delete from project_phase where project_id > 40000000 and project_id < 40000020; +delete from component_inquiry where project_id > 40000000 and project_id < 40000020; +delete from project where project_id > 40000000 and project_id < 40000020; +delete from comp_version_dates_history where comp_vers_id > 40000000 and comp_vers_id < 40000020; +delete from comp_versions where component_id > 40000000 and component_id < 40000020; +delete from comp_versions where comp_vers_id > 40000000 and comp_vers_id < 40000020; +delete from comp_catalog where component_id > 40000000 and component_id < 40000020; +delete from user_rating where user_id = 400011; +delete from user_reliability where user_id = 400011; +delete from project_studio_specification where project_studio_spec_id = 1; + delete from copilot_profile where copilot_profile_id = 400011; \ No newline at end of file diff --git a/test/sqls/challengeRegistration/tcs_catalog__insert_test_data b/test/sqls/challengeRegistration/tcs_catalog__insert_test_data index 41ea9a949..eb585ff0f 100644 --- a/test/sqls/challengeRegistration/tcs_catalog__insert_test_data +++ b/test/sqls/challengeRegistration/tcs_catalog__insert_test_data @@ -1,55 +1,55 @@ -INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000001, 1, 2, 132456, CURRENT, 132456, CURRENT, 40000011, null); - -INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); - -INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 2, '40000001', 132456, CURRENT, 132456, CURRENT); - -INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000001', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); - -INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000001', '40000001', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); - -INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000001, 40000001, 113, CURRENT); - - -INSERT INTO project_studio_specification(project_studio_spec_id,contest_description,create_user,create_date,modify_user,modify_date) VALUES (1,'Description of Studio Contest 40000002.','132456',CURRENT,'132456',CURRENT); - -INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000001, 40000001, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); - -INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000002, 1, 20, 132456, CURRENT, 132456, CURRENT, 40000012, 1); - -INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 6, 'Hestia Business Information', 132456, CURRENT, 132456, CURRENT); - - -INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 2, '40000002', 132456, CURRENT, 132456, CURRENT); - -INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000002', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); - -INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000002', '40000002', '1', '1.0', CURRENT, '131', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); - - -INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000002, 40000002, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); - -INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 0, 113, null); - -INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, null, 113); - -INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 3000, 131, 40000003); - -INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, 1.00, 131); - -INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000003, 1, 29, 132456, CURRENT, 132456, CURRENT, 40000011, null); - -INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); - -INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 2, '40000003', 132456, CURRENT, 132456, CURRENT); - -INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000003', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); - -INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000003', '40000003', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); - -INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000003, 40000003, 113, CURRENT); - -INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000003, 40000003, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); - -INSERT INTO copilot_profile(copilot_profile_id, user_id, copilot_profile_status_id, suspension_count, reliability, create_user, create_date, update_user, update_date) -VALUES(400011, 400011, 1, 1, 50, 132456, CURRENT, 132456, CURRENT); +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000001, 1, 2, 132456, CURRENT, 132456, CURRENT, 40000011, null); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 2, '40000001', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000001', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000001', '40000001', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000001, 40000001, 113, CURRENT); + + +INSERT INTO project_studio_specification(project_studio_spec_id,contest_description,create_user,create_date,modify_user,modify_date) VALUES (1,'Description of Studio Contest 40000002.','132456',CURRENT,'132456',CURRENT); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000001, 40000001, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000002, 1, 20, 132456, CURRENT, 132456, CURRENT, 40000012, 1); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 6, 'Hestia Business Information', 132456, CURRENT, 132456, CURRENT); + + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 2, '40000002', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000002', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000002', '40000002', '1', '1.0', CURRENT, '131', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000002, 40000002, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 0, 113, null); + +INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, null, 113); + +INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 3000, 131, 40000003); + +INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, 1.00, 131); + +INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000003, 1, 29, 132456, CURRENT, 132456, CURRENT, 40000011, null); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 2, '40000003', 132456, CURRENT, 132456, CURRENT); + +INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000003', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0'); + +INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000003', '40000003', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0'); + +INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000003, 40000003, 113, CURRENT); + +INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000003, 40000003, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT); + +INSERT INTO copilot_profile(copilot_profile_id, user_id, copilot_profile_status_id, suspension_count, reliability, create_user, create_date, update_user, update_date) +VALUES(400011, 400011, 1, 1, 50, 132456, CURRENT, 132456, CURRENT); diff --git a/test/test.applyDevelopReviewOpportunity.js b/test/test.applyDevelopReviewOpportunity.js new file mode 100644 index 000000000..960ab1ffb --- /dev/null +++ b/test/test.applyDevelopReviewOpportunity.js @@ -0,0 +1,419 @@ +/* + * Copyright (C) 2014 TopCoder Inc., All Rights Reserved. + * + * @version 1.0 + * @author TCSASSEMBLER + */ +'use strict'; +/*global describe, it, before, beforeEach, after, afterEach */ +/*jslint node: true, stupid: true, unparam: true */ + +/** + * Module dependencies. + */ +var _ = require('underscore'); +var request = require('supertest'); +var assert = require('chai').assert; +var async = require('async'); +var S = require('string'); + +var testHelper = require('./helpers/testHelper'); +var SQL_DIR = __dirname + '/sqls/applyDevelopReviewOpportunity/'; +var API_ENDPOINT = process.env.API_ENDPOINT || 'http://localhost:8080'; + +describe('Get Software Review Opportunity Details API', function () { + this.timeout(180000); // The api with testing remote db could be quit slow + + var msgObj = require('../test/test_files/expected_apply_software_review_opportunities_response_message'), + member1 = testHelper.generateAuthHeader({ sub: 'ad|132457' }), + member2 = testHelper.generateAuthHeader({ sub: 'ad|132458' }); + + /** + * Clear database + * @param {Function} done the callback + */ + function clearDb(done) { + async.waterfall([ + function (cb) { + testHelper.runSqlFile(SQL_DIR + 'common_oltp__clean', 'common_oltp', cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + 'tcs_catalog__clean', 'tcs_catalog', cb); + } + ], done); + } + + /** + * This function is run before all tests. + * Generate tests data. + * @param {Function} done the callback + */ + before(function (done) { + async.waterfall([ + clearDb, + function (cb) { + testHelper.runSqlFile(SQL_DIR + 'tcs_catalog__insert_test_data', 'tcs_catalog', cb); + }, + function (cb) { + testHelper.runSqlFile(SQL_DIR + 'common_oltp__insert_test_data', 'common_oltp', cb); + } + ], done); + }); + + /** + * This function is run after all tests. + * Clean up all data. + * @param {Function} done the callback + */ + after(function (done) { + clearDb(done); + }); + + /** + * create a http request and test it. + * @param {String} url - the request url. + * @param {Number} expectStatus - the expected response status code. + * @param {Object} authHeader - the auth header. + * @param {Object} postData - the data post to api. + * @param {Function} cb - the call back function. + */ + function createGetRequest(url, expectStatus, authHeader, postData, cb) { + var req = request(API_ENDPOINT) + .post('/v2/develop/reviewOpportunities/' + url + '/apply') + .set('Accept', 'application/json') + .expect('Content-Type', /json/); + if (authHeader) { + req.set('Authorization', authHeader); + } + req.expect(expectStatus) + .send(postData) + .end(cb); + } + + /** + * assert the bad response. + * @param {String} url - the request url + * @param {Number} expectStatus - the expect status. + * @param {String} errorMessage - the expected error message. + * @param {Object} authHeader - the request auth header. + * @param {Object} postData - the data post to api. + * @param {Function} cb - the callback function. + */ + function assertBadResponse(url, expectStatus, errorMessage, authHeader, postData, cb) { + createGetRequest(url, expectStatus, authHeader, postData, function (err, result) { + if (!err) { + assert.equal(result.body.error.details, errorMessage, 'invalid error message'); + } else { + cb(err); + return; + } + cb(); + }); + } + + /** + * Test when caller is anonymous. + */ + it('should return unauthorized Error. The caller is anonymous.', function (done) { + assertBadResponse('2001', 401, msgObj.unauthorized, null, null, done); + }); + + + /** + * Test when challengeId is not number. + */ + it('should return bad request. The challengeId is not number.', function (done) { + assertBadResponse('abc', 400, msgObj.challengeId.notNumber, + member1, null, done); + }); + + /** + * Test when challengeId is not integer. + */ + it('should return bad request. The challengeId is not integer.', function (done) { + assertBadResponse('1.2345', 400, msgObj.challengeId.notInteger, + member1, null, done); + }); + + /** + * Test when challengeId is not positive. + */ + it('should return bad request. The challengeId is not positive.', function (done) { + assertBadResponse('-1', 400, msgObj.challengeId.notPositive, + member1, null, done); + }); + + /** + * Test when challengeId is zero. + */ + it('should return bad request. The challengeId is zero.', function (done) { + assertBadResponse('0', 400, msgObj.challengeId.notPositive, + member1, null, done); + }); + + /** + * Test when challengeId is too big. + */ + it('should return bad request. The challengeId is too big.', function (done) { + assertBadResponse('2147483648', 400, msgObj.challengeId.tooBig, + member1, null, done); + }); + + /** + * Test when reviewApplicationRoleId is invalid. + */ + it('should return bad Request. The reviewApplicationRoleId is invalid', function (done) { + assertBadResponse('2001', 400, msgObj.invalidReviewApplicationRole, member1, { + reviewApplicationRoleId: 10 + }, done); + }); + + /** + * Test when challenge is not existed. + */ + it('should return bad Request. The challenge is not existed.', function (done) { + assertBadResponse('8001', 400, msgObj.invalidChallenge, member1, null, done); + }); + + /** + * Test when challenge is existed but don't have any review opportunities. + */ + it('should return bad Request. The challenge don\'t have any review opportunities.', function (done) { + assertBadResponse('2002', 400, msgObj.invalidChallenge, member1, null, done); + }); + + /** + * Test when challenge review registration is not open. + */ + it('should return bad Request. The challenge review registration is not open.', function (done) { + assertBadResponse('2003', 400, msgObj.invalidChallenge, member1, null, done); + }); + + /** + * Test when requested review application role id is not belong to this challenge. + */ + it('should return bad Request. The requested review application role id is not belong to this challenge.', function (done) { + assertBadResponse('2001', 400, msgObj.invalidReviewApplicationId, member1, { reviewApplicationRoleId: 3 }, done); + }); + + /** + * Test the caller is not a reviewer for this kind of challenge. + */ + it('should return bad Request. The caller is not reviewer for this kind of challenge.', function (done) { + assertBadResponse('2004', 403, msgObj.notReviewer, member2, { reviewApplicationRoleId: 1 }, done); + }); + + /** + * Test when caller is not allowed to access this challenge. + */ + it('should return bad Request. The caller is not allowed to access this challenge.', function (done) { + assertBadResponse('2005', 403, msgObj.forbidden, member1, null, done); + }); + + /** + * Test when caller has already been as a reviewer. + */ + it('should return bad Request. The caller has already been assigned as a reviewer.', function (done) { + async.waterfall([ + function (cb) { + testHelper.runSqlQuery('INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES(2015, 2, 2001, 132456, current, 132456, current); ' + + 'INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date)VALUES(2015, 1, "132457", 132456, current, 132456, current); ' + + 'INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES(2016, 4, 2001, 132456, current, 132456, current); ' + + 'INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date)VALUES(2016, 1, "132457", 132456, current, 132456, current); ' + + 'INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES(2017, 8, 2001, 132456, current, 132456, current); ' + + 'INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date)VALUES(2017, 1, "132457", 132456, current, 132456, current); ' + + 'INSERT INTO resource(resource_id, resource_role_id, project_id, create_user, create_date, modify_user, modify_date) VALUES(2018, 9, 2001, 132456, current, 132456, current); ' + + 'INSERT INTO resource_info(resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date)VALUES(2018, 1, "132457", 132456, current, 132456, current);', 'tcs_catalog', cb); + }, + function (cb) { + assertBadResponse('2001', 400, msgObj.alreadyAReviewer, member1, { reviewApplicationRoleId: 1 }, cb); + }, + function (cb) { + testHelper.runSqlQueries(['DELETE FROM resource_info WHERE resource_id >= 2015;', 'DELETE FROM resource WHERE resource_id >= 2015'], 'tcs_catalog', cb); + } + ], done); + }); + + /** + * Test when challenge don't have open positions. + */ + it('should return bad Request. The challenge don\'t have any open positions.', function (done) { + assertBadResponse('2006', 400, msgObj.noOpenPositions, member1, { reviewApplicationRoleId: 1 }, done); + }); + + /** + * Test when there is no positions for applying primary reviewer. + */ + it('should return bad Request. There is no open positions for applying role.', function (done) { + assertBadResponse('2007', 400, msgObj.noPositionsForPrimaryReviewer, member2, { reviewApplicationRoleId: 1 }, done); + }); + + /** + * Test when challenge don't have open positions for applying secondary reviewer. + */ + it('should return bad Request. The challenge don\'t have open secondary reviewer positions.', function (done) { + assertBadResponse('2009', 400, msgObj.noPositionsForSecondaryReviewer, member1, { reviewApplicationRoleId: 2 }, done); + }); + + /** + * Test when there is still terms of use not agreed. + */ + it('should return bad Request. The terms of use are not all agreed.', function (done) { + assertBadResponse('2001', 403, msgObj.notAgreedTerms, member2, { reviewApplicationRoleId: 2 }, done); + }); + + /** + * Test when the register is success and the assignment date is passed. + */ + it('should return success results. The review application is created. The assignment date is passed.', function (done) { + async.waterfall([ + function (cb) { + createGetRequest('2001', 200, member1, { reviewApplicationRoleId: 1 }, function (err, result) { + cb(err, result); + }); + }, + function (result, cb) { + assert.equal(result.body.message, msgObj.success.afterAssignment, 'invalid response'); + + testHelper.runSqlSelectQuery('* FROM review_application WHERE review_auction_id = 2001;', 'tcs_catalog', cb); + }, + function (result, cb) { + assert.isTrue(result[0].review_application_id >= 3000000, 'invalid review application id'); + assert.isTrue(result[0].review_application_role_id === 1, 'invalid review application role id'); + assert.isTrue(result[0].review_application_status_id === 1, 'invalid review application status id'); + cb(); + } + ], done); + }); + + /** + * Test when register is success and the assignment is not passed. + */ + it('should return success results. The review application is created. The assignment is not passed.', function (done) { + async.waterfall([ + function (cb) { + createGetRequest('2008', 200, member1, { reviewApplicationRoleId: 1 }, function (err, result) { + cb(err, result); + }); + }, + function (result, cb) { + assert.isTrue(new S(result.body.message).startsWith(msgObj.success.beforeAssignmentPrefix), 'invalid prefix'); + assert.isTrue(new S(result.body.message).endsWith(msgObj.success.beforeAssignmentSuffix), 'invalid suffix'); + + testHelper.runSqlSelectQuery('* FROM review_application WHERE review_auction_id = 2008;', 'tcs_catalog', cb); + }, + function (result, cb) { + assert.isTrue(result[0].review_application_id >= 3000000, 'invalid review application id'); + assert.isTrue(result[0].review_application_role_id === 1, 'invalid review application role id'); + assert.isTrue(result[0].review_application_status_id === 1, 'invalid review application status id'); + cb(); + } + ], done); + }); + + /** + * Test when register cancelled all his registration. + */ + it('should return success results. The review application is cancelled.', function (done) { + async.waterfall([ + function (cb) { + createGetRequest('2001', 200, member1, null, function (err, result) { + cb(err, result); + }); + }, + function (result, cb) { + assert.equal(result.body.message, msgObj.success.cancelled, 'invalid response'); + + testHelper.runSqlSelectQuery(' * FROM review_application WHERE review_auction_id = 2001;', 'tcs_catalog', cb); + }, + function (result, cb) { + assert.isTrue(result[0].review_application_role_id === 1, 'invalid review application role id ' + result[0].review_application_role_id); + assert.isTrue(result[0].review_application_status_id === 2, 'invalid review application status id ' + result[0].review_application_status_id); + cb(); + } + ], done); + }); + + /** + * Test when caller apply the primary reviewer first and then cancel it and apply the secondary reviewer. + */ + it('should return success results. The caller apply the primary reviewer before and cancel it and apply secondary reviewer.', function (done) { + async.waterfall([ + function (cb) { + createGetRequest('2001', 200, member1, { reviewApplicationRoleId: 1 }, function (err) { + cb(err); + }); + }, + function (cb) { + testHelper.runSqlSelectQuery(' * FROM review_application WHERE review_auction_id = 2001 AND review_application_status_id = 1;', 'tcs_catalog', cb); + }, + function (result, cb) { + assert.isTrue(result[0].review_application_id >= 3000000); + assert.isTrue(result[0].review_application_role_id === 1); + cb(); + }, + function (cb) { + createGetRequest('2001', 200, member1, { reviewApplicationRoleId: 2 }, function (err) { + cb(err); + }); + }, + function (cb) { + testHelper.runSqlSelectQuery(' * FROM review_application WHERE review_auction_id = 2001 AND ' + + 'review_application_role_id = 1;', 'tcs_catalog', cb); + }, + function (result, cb) { + result.forEach(function (item) { + assert.isTrue(item.review_application_status_id === 2); + }); + cb(); + }, + function (cb) { + testHelper.runSqlSelectQuery(' * FROM review_application WHERE review_auction_id = 2001 AND ' + + 'review_application_role_id = 2;', 'tcs_catalog', cb); + }, + function (result, cb) { + result.forEach(function (item) { + assert.isTrue(item.review_application_status_id === 1); + }); + cb(); + } + ], done); + }); + + /** + * Test when caller apply the primary reviewer first and apply the primary reviewer and secondary reviewer + */ + it('should return success results. The caller apply the primary reviewer first and apply the primary reviewer and secondary reviewer.', function (done) { + async.waterfall([ + function (cb) { + testHelper.runSqlQueries(['DELETE FROM resource_info WHERE resource_id >= 2001;', 'DELETE FROM resource WHERE resource_id >= 2001;'], 'tcs_catalog', + function (err) { + cb(err); + }); + }, + function (cb) { + createGetRequest('2001', 200, member1, { reviewApplicationRoleId: 1 }, function (err) { + cb(err); + }); + }, + function (cb) { + createGetRequest('2001', 200, member1, { reviewApplicationRoleId: [1, 2] }, function (err) { + cb(err); + }); + }, + function (cb) { + testHelper.runSqlSelectQuery(' * FROM review_application WHERE review_auction_id = 2001 AND ' + + 'review_application_status_id = 1 AND user_id = 132457 ORDER BY review_application_role_id ASC;', 'tcs_catalog', cb); + }, + function (result, cb) { + assert.equal(result.length, 2, 'invalid results length'); + assert.equal(result[0].review_application_role_id, 1, 'invalid response'); + assert.equal(result[1].review_application_role_id, 2, 'invalid response'); + cb(); + } + ], done); + }); + + + +}); diff --git a/test/test_files/expected_apply_software_review_opportunities_response_message.json b/test/test_files/expected_apply_software_review_opportunities_response_message.json new file mode 100644 index 000000000..b1dc73519 --- /dev/null +++ b/test/test_files/expected_apply_software_review_opportunities_response_message.json @@ -0,0 +1,26 @@ +{ + "challengeId" : { + "notNumber": "challengeId should be number.", + "notPositive": "challengeId should be positive.", + "notInteger": "challengeId should be Integer.", + "tooBig": "challengeId should be less or equal to 2147483647." + }, + "unauthorized": "Anonymous user don't have permission to access this api.", + "invalidReviewApplicationRole": "reviewApplicationRoleId should be an element of 1,2,3,4,5,6,7,8,9.", + "invalidReviewApplicationId": "You can't apply the review application role that do not belong to this challenge.", + "notSupportedReviewApplicationRoleId": "You can't apply the review application role that do not belong to this challenge.", + "notReviewer": "You are not a Review Board member.", + "forbidden": "The user is not allowed to register this challenge review.", + "alreadyAReviewer": "You are already assigned as reviewer for the contest.", + "noOpenPositions": "There are no open positions for this challenge.", + "noPositionsForPrimaryReviewer": "There is no open positions for selected review application role: Primary Reviewer.", + "noPositionsForSecondaryReviewer": "There is no open positions for selected review application role: Secondary Reviewer.", + "invalidChallenge": "The challenge is not existed or don't have any review opportunities or review registration is not open.", + "notAgreedTerms": "You should agree with all terms of use.", + "success": { + "afterAssignment": "You have successfully applied to review this contest. The system will automatically decide whether you match the reviewer requirements for this contest now. You will be notified by email shortly.", + "beforeAssignmentPrefix": "You have successfully applied to review this contest. The system will automatically select reviewers that best match the review positions for this contest on ", + "beforeAssignmentSuffix": ". You will be notified by email what review role you were assigned to.", + "cancelled": "Your review application for this contest has been cancelled." + } +}