diff --git a/README.md b/README.md index c9efc4e7..a76aa653 100644 --- a/README.md +++ b/README.md @@ -42,32 +42,9 @@ Run `npm run sync:es` from the root of project to execute the script. **NOTE**: In production these dependencies / services are hosted & managed outside tc-projects-service. -#### Kafka -Kafka must be installed and configured prior starting the application. -Following topics must be created: -``` -notifications.connect.project.updated -notifications.connect.project.files.updated -notifications.connect.project.team.updated -notifications.connect.project.plan.updated -notifications.connect.project.topic.created -notifications.connect.project.topic.updated -notifications.connect.project.post.created -notifications.connect.project.post.edited -``` +### Import sample metadata -New Kafka related configuration options has been introduced: -``` -"kafkaConfig": { - "hosts": List of Kafka brokers. Default: localhost: 9092 - "clientCert": SSL certificate - "clientCertKey": Certificate key -} -``` -Environment variables: -- `KAFKA_HOSTS` - same as "hosts" -- `KAFKA_CLIENT_CERT` - same as "clientCert" -- `KAFKA_CLIENT_CERT_KEY` - same as "clientCertKey" +To create sample metadata entries (duplicate what is currently in development environment) run `node migrations/seedMetadata.js` ### Test @@ -103,4 +80,4 @@ You may replace 172.17.0.1 with your docker0 IP. You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** and **postman_environment.json** to verify endpoints. #### Deploying without docker -If you don't want to use docker to deploy to localhost. You can simply run `npm run start` from root of project. This should start the server on default port `3000`. +If you don't want to use docker to deploy to localhost. You can simply run `npm run start:dev` from root of project. This should start the server on default port `8001`. diff --git a/migrations/seedMetadata.js b/migrations/seedMetadata.js new file mode 100644 index 00000000..431daa8f --- /dev/null +++ b/migrations/seedMetadata.js @@ -0,0 +1,72 @@ +/* eslint-disable */ +const _ = require('lodash') +const axios = require('axios'); +const Promise = require('bluebird'); + + +var url = 'https://api.topcoder-dev.com/v4/projects/metadata'; +var targetUrl = 'http://localhost:8001/v4/'; +var destUrl = targetUrl + 'projects/'; +var destTimelines = targetUrl; + +axios.get(url) + .then(async function (response) { + let data = response.data; + + var headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw' + } + + + let promises = _(data.result.content.projectTypes).map(pt=>{ + return axios.post(destUrl+'metadata/projectTypes',{param:pt}, {headers:headers}) + }); + try{ + await Promise.all(promises); + }catch(ex){ + //ignore the error + } + + promises = _(data.result.content.projectTemplates).map(pt=>{ + return axios.post(destUrl+'metadata/projectTemplates',{param:pt}, {headers:headers}) + }); + try{ + await Promise.all(promises); + }catch(ex){ + //ignore the error + } + + promises = _(data.result.content.productCategories).map(pt=>{ + return axios.post(destUrl+'metadata/productCategories',{param:pt}, {headers:headers}) + }); + try{ + await Promise.all(promises); + }catch(ex){ + //ignore the error + } + + promises = _(data.result.content.productTemplates).map(pt=>{ + return axios.post(destUrl+'metadata/productTemplates',{param:pt}, {headers:headers}) + }); + try{ + await Promise.all(promises); + }catch(ex){ + //ignore the error + } + + await Promise.each(data.result.content.milestoneTemplates,pt=>{ + return new Promise((resolve,reject)=>{ + axios.post(destTimelines+'timelines/metadata/milestoneTemplates',{param:pt}, {headers:headers}) + .then(r=>resolve()) + .catch(e=>resolve()); //ignore the error + }) + }); + + + + // handle success + console.log('Done'); + }).catch(err=>{ + console.log(err); + });