Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bolmsten committed Sep 15, 2021
1 parent 360525d commit 6762e38
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions dmp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { v4 as uuidv4 } from "uuid";
export function getToken() {
return axios
.post(`${process.env.DMP_HOST}/tokens`, {
email: "albert.einstein@example.com",
password: "password",
email: process.env.INGESTOR_EMAIL,
password: process.env.INGESTOR_PASSWORD,
})
.then(function (response) {
axios.defaults.headers.common[
Expand Down Expand Up @@ -103,7 +103,7 @@ export function createQuestionnarie(proposalId: string) {
name: `${proposalId}-DMP`,
packageId: `${process.env.PACKAGE_ID}`,
sharing: "RestrictedQuestionnaire",
tagUuids: ["302b1584-a7a2-4d9c-9770-eee990b002ec"],
tagUuids: [process.env.DMP_TAG], // Here I am using the Horizon 2020 template tag
templateId: null,
visibility: "PrivateQuestionnaire",
})
Expand All @@ -127,7 +127,7 @@ export function createUser(
lastName,
firstName,
role: "researcher",
password: "password",
password: "password", // this should be connected to your identity access solution instead of hardcoded
affiliation,
})
.then(function (response) {
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ services:
image: "middleware"
environment:
DMP_HOST: "http://dsw-server:3000"
DMP_TAG: "302b1584-a7a2-4d9c-9770-eee990b002ec"
RABBITMQ_HOST: "rabbitmq"
RABBITMQ_USER: "guest"
RABBITMQ_PASSWORD: "guest"
PACKAGE_ID: "myorg:panosc-expands:2.0.6"
INGESTOR_EMAIL: "albert.einstein@example.com"
INGESTOR_PASSWORD: "password"
depends_on:
- rabbitmq
- dsw-server
Expand Down
23 changes: 16 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ async function start() {

rabbitMq.listenOnBroadcast(async (type, message: unknown) => {
console.log(type, message);
let userUuid = "";
let questionnaireUuid = "";

if (type === "PROPOSAL_CREATED") {
let acceptMessage = message as ProposalAcceptedMessage;

userUuid = await addUser(acceptMessage);
questionnaireUuid = await addDMP(acceptMessage, userUuid);
let userUuid = await addUser(acceptMessage);
await addDMP(acceptMessage, userUuid);
} else if (type === "PROPOSAL_UPDATED") {
await new Promise((resolve) => setTimeout(resolve, 5000, [])); // This is hacky but for the moment needed as a search right after a create will not find the DMP
let acceptMessage = message as ProposalAcceptedMessage;
Expand All @@ -57,16 +55,27 @@ async function start() {
}
// Here is the place we can fetch and add calculations for instruments
if (answer.questionId === "selection_from_options_instrument") {
console.log(answer.answer);
// @ts-ignore: Unreachable code error
console.log(instrumentInformation[answer.answer[0]].static);
await changeQuestionAnswers(
questionnaireUuid,
instrumentInformation.NMX
questionnaireUuid, // @ts-ignore: Unreachable code error
instrumentInformation[answer.answer[0]].static
);

//Here we could do a simple lookup based on instrument and time allocated for a proposal
const days = parseInt(
answers.find((ans) => ans.questionId === "days_at_instrument")!
.answer
);
await changeQuestionAnswer(
questionnaireUuid,
mapping.data_size,
"20 Gigabytes"
`${
// @ts-ignore: Unreachable code error
instrumentInformation[answer.answer[0]].dailyGigabyteIndex *
days
} Gigabytes`
);
}
});
Expand Down
8 changes: 6 additions & 2 deletions instrumentInformation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"NMX": [
"NMX":{
"static" : [
{
"_comment": "File Formats",
"path": "a3e9d35d-1835-4117-9ea8-13bf29a48241.f1a1e194-72db-46d4-b979-fb47527279ee",
Expand Down Expand Up @@ -40,5 +41,8 @@
},
"type": "SetReplyEvent"
}
]
],
"dailyGigabyteIndex": 5
}

}

0 comments on commit 6762e38

Please sign in to comment.