diff --git a/docs/Implement Endpoint To Populate Elasticsearch For The Given Challenges.postman_collection.json b/docs/Implement Endpoint To Populate Elasticsearch For The Given Challenges.postman_collection.json new file mode 100644 index 0000000..b5df385 --- /dev/null +++ b/docs/Implement Endpoint To Populate Elasticsearch For The Given Challenges.postman_collection.json @@ -0,0 +1,99 @@ +{ + "variables": [], + "info": { + "name": "Implement Endpoint To Populate Elasticsearch For The Given Challenges", + "_postman_id": "7db581cc-9635-e7b3-b3ba-8f3e52254c1b", + "description": "", + "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" + }, + "item": [ + { + "name": "View challenge details via ElasticSearch", + "request": { + "url": "http://cockpit.cloud.topcoder.com:9200/challengesdetail/challenges/30005532", + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "description": "" + }, + "response": [ + { + "id": "5ea84ed3-bbac-42f2-b15f-e9c6e4e8fda9", + "name": "View challenge details via ElasticSearch", + "originalRequest": { + "url": "http://cockpit.cloud.topcoder.com:9200/challengesdetail/challenges/30005532", + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + } + }, + "status": "OK", + "code": 200, + "_postman_previewlanguage": "json", + "_postman_previewtype": "text", + "header": [ + { + "name": "content-length", + "key": "content-length", + "value": "1296", + "description": "The length of the response body in octets (8-bit bytes)" + }, + { + "name": "content-type", + "key": "content-type", + "value": "application/json; charset=UTF-8", + "description": "The mime type of this content" + } + ], + "cookie": [], + "responseTime": 50, + "body": "{\"_index\":\"challengesdetail\",\"_type\":\"challenges\",\"_id\":\"30005532\",\"_version\":6,\"found\":true,\"_source\":{\"track\":\"DEVELOP\",\"subTrack\":\"ARCHITECTURE\",\"detailRequirements\":\"test\",\"finalSubmissionGuidelines\":\"test\",\"terms\":[{\"termsOfUseId\":21193,\"role\":\"Submitter\",\"agreeabilityType\":\"Electronically-agreeable\",\"title\":\"Standard Terms for TopCoder Competitions v2.0\"},{\"termsOfUseId\":20704,\"role\":\"Primary Screener\",\"agreeabilityType\":\"Electronically-agreeable\",\"title\":\"Reviewer terms of use text 20704\"},{\"termsOfUseId\":20704,\"role\":\"Reviewer\",\"agreeabilityType\":\"Electronically-agreeable\",\"title\":\"Reviewer terms of use text 20704\"},{\"termsOfUseId\":20704,\"role\":\"Aggregator\",\"agreeabilityType\":\"Electronically-agreeable\",\"title\":\"Reviewer terms of use text 20704\"},{\"termsOfUseId\":20704,\"role\":\"Final Reviewer\",\"agreeabilityType\":\"Electronically-agreeable\",\"title\":\"Reviewer terms of use text 20704\"},{\"termsOfUseId\":20794,\"role\":\"Manager\",\"agreeabilityType\":\"Non-agreeable\",\"title\":\"Approved OR Managers - TopCoder Technical Team\"},{\"termsOfUseId\":20893,\"role\":\"Copilot\",\"agreeabilityType\":\"Non-electronically-agreeable\",\"title\":\"MSA\"},{\"termsOfUseId\":20704,\"role\":\"Specification Reviewer\",\"agreeabilityType\":\"Electronically-agreeable\",\"title\":\"Reviewer terms of use text 20704\"}],\"id\":30005532}}" + } + ] + }, + { + "name": "View challenge listing via ElasticSearch", + "request": { + "url": "http://cockpit.cloud.topcoder.com:9200/challengeslisting/challenges/30005532", + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "description": "" + }, + "response": [] + }, + { + "name": "Push challenges", + "request": { + "url": "http://localhost:8083/v3/esfeeder/challenges", + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "description": "" + }, + { + "key": "Authorization", + "value": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJhZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJoZWZmYW4iLCJleHAiOjE3NjYyODkyNDYsInVzZXJJZCI6IjEzMjQ1NiIsImlhdCI6MTQ1MDkyOTI0NiwiZW1haWwiOm51bGwsImp0aSI6IjEzNjljNjAwLWUwYTEtNDUyNS1hN2M3LTU2YmU3ZDgxM2Y1MSJ9.hp5peSoj-fh3KFkskvBpfUFIcJNtsv4zIMFV-D8F3JA", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{\r\n \"param\": {\r\n \"index\": \"challenges\",\r\n \"type\": \"challenges\",\r\n \"challengeIds\": [30005532]\r\n }\r\n}" + }, + "description": "" + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/docs/Verification_Implement Endpoint To Populate Elasticsearch For The Given Challenges.docx b/docs/Verification_Implement Endpoint To Populate Elasticsearch For The Given Challenges.docx new file mode 100644 index 0000000..dcb6b89 Binary files /dev/null and b/docs/Verification_Implement Endpoint To Populate Elasticsearch For The Given Challenges.docx differ diff --git a/src/main/java/com/appirio/service/challengefeeder/ChallengeFeederServiceApplication.java b/src/main/java/com/appirio/service/challengefeeder/ChallengeFeederServiceApplication.java index 58f7632..0f0569e 100644 --- a/src/main/java/com/appirio/service/challengefeeder/ChallengeFeederServiceApplication.java +++ b/src/main/java/com/appirio/service/challengefeeder/ChallengeFeederServiceApplication.java @@ -75,8 +75,13 @@ * Version 1.8 - Topcoder Elasticsearch Feeder Service - Jobs Cleanup And Improvement v1.0 * - remove the useless resources, jobs and logging of configuration values *

+ * + *

+ * Version 1.9 - Implement Endpoint To Populate Elasticsearch For The Given Challenges + * - Changes the challenge resource object creation logic/ + *

* @author TCSCODER - * @version 1.8 + * @version 1.9 */ public class ChallengeFeederServiceApplication extends BaseApplication { /** @@ -183,7 +188,7 @@ protected void registerResources(ChallengeFeederServiceConfiguration config, Env // Register resources here env.jersey().register(new HealthCheckResource()); - env.jersey().register(new ChallengeFeederFactory(jestClient).getResourceInstance()); + env.jersey().register(new ChallengeFeederFactory(jestClient,config).getResourceInstance()); env.jersey().register(new MmFeederResourceFactory(jestClient).getResourceInstance()); env.jersey().register(new MarathonMatchFeederFactory(jestClient).getResourceInstance()); env.jersey().register(new SRMFeederFactory(jestClient).getResourceInstance()); diff --git a/src/main/java/com/appirio/service/challengefeeder/resources/ChallengeFeederResource.java b/src/main/java/com/appirio/service/challengefeeder/resources/ChallengeFeederResource.java index 5c41b69..7beacc0 100644 --- a/src/main/java/com/appirio/service/challengefeeder/resources/ChallengeFeederResource.java +++ b/src/main/java/com/appirio/service/challengefeeder/resources/ChallengeFeederResource.java @@ -3,17 +3,9 @@ */ package com.appirio.service.challengefeeder.resources; -import com.appirio.service.challengefeeder.dto.ChallengeFeederParam; -import com.appirio.service.supply.resources.MetadataApiResponseFactory; -import com.appirio.supply.ErrorHandler; -import com.appirio.tech.core.api.v3.request.PostPutRequest; -import com.appirio.tech.core.api.v3.request.annotation.AllowAnonymous; -import com.appirio.tech.core.api.v3.response.ApiResponse; -import com.codahale.metrics.annotation.Timed; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Arrays; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.PUT; @@ -21,16 +13,33 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.appirio.service.challengefeeder.dto.ChallengeFeederParam; +import com.appirio.service.challengefeeder.manager.ChallengeDetailFeederManager; +import com.appirio.service.challengefeeder.manager.ChallengeListingFeederManager; +import com.appirio.service.supply.resources.MetadataApiResponseFactory; +import com.appirio.supply.ErrorHandler; +import com.appirio.supply.SupplyException; +import com.appirio.tech.core.api.v3.request.PostPutRequest; +import com.appirio.tech.core.api.v3.request.annotation.AllowAnonymous; +import com.appirio.tech.core.api.v3.response.ApiResponse; +import com.codahale.metrics.annotation.Timed; + /** * Resource to handle the challenge feeder * * Version 1.1 - Topcoder Elasticsearch Feeder Service - Jobs Cleanup And Improvement v1.0 * - make it dummy * - * + * + * Version 1.2 - Implement Endpoint To Populate Elasticsearch For The Given Challenges + * - Added method to call listing and detail feeder manager to populate challenge + * data into ES using API resource * * @author TCSCODER - * @version 1.1 + * @version 1.2 */ @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -41,11 +50,24 @@ public class ChallengeFeederResource { * Logger used to log the events */ private static final Logger logger = LoggerFactory.getLogger(ChallengeFeederResource.class); + + /** + * Manager to access the challenge feeder for listing. + */ + private final ChallengeListingFeederManager challengeListingFeederManager; + + /** + * Manager to access the challenge details feeder for listing. + */ + private final ChallengeDetailFeederManager challengeDetailFeederManager; + /** * Create ChallengeFeederResource */ - public ChallengeFeederResource() { + public ChallengeFeederResource(ChallengeDetailFeederManager challengeDetailFeederManager,ChallengeListingFeederManager challengeListingFeederManager) { + this.challengeDetailFeederManager = challengeDetailFeederManager; + this.challengeListingFeederManager = challengeListingFeederManager; } /** @@ -58,10 +80,15 @@ public ChallengeFeederResource() { @Timed @AllowAnonymous public ApiResponse pushChallengeFeeders(@Valid PostPutRequest request) { - try { - return MetadataApiResponseFactory.createResponse(null); - } catch (Exception e) { - return ErrorHandler.handle(e, logger); - } + try { + if (request == null || request.getParam() == null) { + throw new SupplyException("The request body should be provided", HttpServletResponse.SC_BAD_REQUEST); + } + challengeListingFeederManager.pushChallengeFeeder(request.getParam()); + challengeDetailFeederManager.pushChallengeFeeder(request.getParam()); + return MetadataApiResponseFactory.createResponse(null); + } catch (Exception e) { + return ErrorHandler.handle(e, logger); + } } } diff --git a/src/main/java/com/appirio/service/resourcefactory/ChallengeFeederFactory.java b/src/main/java/com/appirio/service/resourcefactory/ChallengeFeederFactory.java index 443de80..e61c387 100644 --- a/src/main/java/com/appirio/service/resourcefactory/ChallengeFeederFactory.java +++ b/src/main/java/com/appirio/service/resourcefactory/ChallengeFeederFactory.java @@ -1,7 +1,14 @@ package com.appirio.service.resourcefactory; +import com.appirio.service.challengefeeder.ChallengeFeederServiceConfiguration; +import com.appirio.service.challengefeeder.dao.ChallengeDetailFeederDAO; +import com.appirio.service.challengefeeder.dao.ChallengeListingFeederDAO; +import com.appirio.service.challengefeeder.manager.ChallengeDetailFeederManager; +import com.appirio.service.challengefeeder.manager.ChallengeListingFeederManager; import com.appirio.service.challengefeeder.resources.ChallengeFeederResource; +import com.appirio.service.challengefeeder.util.JestClientUtils; import com.appirio.service.supply.resources.ResourceFactory; +import com.appirio.supply.DAOFactory; import com.appirio.supply.SupplyException; import io.searchbox.client.JestClient; @@ -10,11 +17,12 @@ * * Version 1.1 - Topcoder Elasticsearch Feeder Service - Jobs Cleanup And Improvement v1.0 * - create dummy resource - * * + * Version 1.2 - Implement Endpoint To Populate Elasticsearch For The Given Challenges + * - Changes the challenge factory object creation logic * * @author TCSCODER - * @version 1.1 + * @version 1.2 */ public class ChallengeFeederFactory implements ResourceFactory { @@ -22,14 +30,17 @@ public class ChallengeFeederFactory implements ResourceFactory