Skip to content

Commit

Permalink
Add mapper for new node comments. refs #6
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamarts committed Dec 17, 2020
1 parent 20e6cc8 commit 87971bf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
6 changes: 3 additions & 3 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"server": {
"host": "0.0.0.0",
"host": "localhost",
"port": 3005,
"baseDir": "/"
},
Expand All @@ -15,8 +15,8 @@
"renewTokenInMinute": 800,
"endpoints": {
"auth": "/auth/realms/agrows/protocol/openid-connect/token",
"publishMetrics": "/v1/owner/gitfeed/thing/:provider/node/:node",
"metrics": "/v1/owner/gitfeed/thing/:provider/node/:node",
"publishMetrics": "/v1/owner/gitfeedV9/thing/:provider/node/:node",
"metrics": "/v1/owner/gitfeedV9/thing/:provider/node/:node",
"jsonDataAPI": "/v1/files/upload/jsondata"
}
}
Expand Down
5 changes: 5 additions & 0 deletions controller/metrics.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const metrics = async (req, res) => {
return false;
}

if (starwsResp.status && starwsResp.status != 200) {
res.status(starwsResp.status).send({ message: 'Unknown error' });
return false;
}

const maker = nodeMapper[node];

if (!maker) {
Expand Down
10 changes: 6 additions & 4 deletions controller/publish.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const starws = require('../services/star-ws/controller');
const nodeMapper = require('../mapper/inbound.mapper');
const logger = require('../config/logger');
const utils = require('../utils');

const publish = async (req, res) => {
const sourceData = req.body;
Expand Down Expand Up @@ -43,7 +44,7 @@ const publish = async (req, res) => {
// TODO: Means that is not formatted, lets mapper it
let rawDataValues;
if (createRawData) {
// Save JSON Data
// Save JSON Data
const rawDataPromise = [];
sourceData.forEach((theData, index) => {
rawDataPromise[index] = starws.saveJSONData(theData);
Expand All @@ -64,15 +65,16 @@ const publish = async (req, res) => {
const data = [];
sourceData.forEach((item, index) => {
let d = item;
if (rawDataValues){
if (rawDataValues) {
d = {
...item,
rawData: rawDataValues[index].link
}
rawData: rawDataValues[index].link,
};
}
data.push(theMaker(d));
});

utils.dateCounter = 0;
const starwsResp = await starws.publishMetrics(provider, node, data);
if (starwsResp) {
res.status(starwsResp.status).send(starwsResp.data);
Expand Down
38 changes: 33 additions & 5 deletions mapper/inbound.mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ const issues = JM.makeConverter({
dateTime: input => Utils.dateFormat4StarWS(input.updatedAt),
fields: {
number: ['number', h.toString],
state: 'state',
state: 'state', //
createdAt: input => Utils.dateFormat4StarWS(input.createdAt),
closedAt: input => Utils.dateFormat4StarWS(input.closedAt),
updatedAt: input => Utils.dateFormat4StarWS(input.updatedAt),
closedAt: input => Utils.dateFormat4StarWS(input.closedAt), //
updatedAt: input => Utils.dateFormat4StarWS(input.updatedAt), //
author: input => Utils.prepareString4StarWS(`a:${input.author}`),
labels: input => Utils.concatArray4StarWS(input.labels),
participantsTotalCount: ['participants.totalCount', h.toString],
labels: input => Utils.concatArray4StarWS(input.labels), //
participantsTotalCount: ['participants.totalCount', h.toString], //
participants: input => {
const participants =
input.participants && input.participants.users
Expand Down Expand Up @@ -129,6 +129,33 @@ const commits = JM.makeConverter({
},
});

const comments = JM.makeConverter({
dateTime: input => Utils.dateFormat4StarWS(input.createdAt),
fields: {
url: 'url',
createdAt: data => Utils.dateFormat4StarWS(data.createdAt),
author: input => Utils.prepareString4StarWS(`a:${input.author}`),
number: ['number', h.toString],
url: 'url',
id: 'id',
rawData: input => {
if (input.rawData) {
return input.rawData;
}
return `https://datajson/empty`;
},
dono: input => {
return `o:${input.owner}`;
},
name: input => {
return `n:${input.name}`;
},
provider: 'provider',
type: JM.helpers.def('comments'),
},
tags: {},
});

const userStats = JM.makeConverter({
dateTime: input => {
if (input.dateTime) {
Expand Down Expand Up @@ -197,6 +224,7 @@ module.exports = {
pulls,
issues,
commits,
comments,
userStats,
repositoryStats,
};
19 changes: 19 additions & 0 deletions services/star-ws/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ const publishMetrics = async (provider, node, data) => {
endPoint = route.reverse({ provider, node });

try {
const dateTimes = data.map(val => val.dateTime);
const uniq = dateTimes
.map(d => {
return {
count: 1,
d: d,
};
})
.reduce((a, b) => {
a[b.d] = (a[b.d] || 0) + b.count;
return a;
}, {});

const duplicates = Object.keys(uniq).filter(a => uniq[a] > 1);
if (duplicates.length > 0) {
const dup = data.filter(val => duplicates.includes(val.dateTime));
console.log(dup);
}
console.log(duplicates);
const response = await httpClient.post(endPoint, data);
logger.info(`POST Request for path /publish successfully executed!`);
return response;
Expand Down
1 change: 1 addition & 0 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const logger = require('../config/logger');

const utils = (() => {
return {
dateCounter: 0,
dateFormat4StarWS: data => {
if (!data) {
logger.debug(`UTILS dateFormat4StarWS: Date content is invalid!`);
Expand Down

0 comments on commit 87971bf

Please sign in to comment.