Skip to content

Commit

Permalink
Merge pull request #7 from DiSSCo/IntegrateAPI
Browse files Browse the repository at this point in the history
Integrate api
  • Loading branch information
TomDijkema authored Jun 11, 2024
2 parents 1d16158 + 2fa527a commit e16408e
Show file tree
Hide file tree
Showing 22 changed files with 766 additions and 231 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.dockerignore
Dockerfile
Dockerfile.prod
Dockerfile.prod

deployment/
35 changes: 35 additions & 0 deletions deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.8'

services:
cordra:
container_name: cordra
restart: always
image: public.ecr.aws/dissco/cordra:latest
env_file:
- ./cordra/variables.env
volumes:
- ./data:/opt/cordra/data
tettris_marketplace:
container_name: tettris_marketplace
restart: always
image: public.ecr.aws/dissco/tettris-marketplace:latest
nginx:
container_name: nginx
restart: unless-stopped
image: nginx:1.26
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/conf:/etc/nginx:ro
- ./certbot/www:/var/www/certbot
- ./certbot/conf:/etc/letsencrypt
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
image: certbot/certbot
container_name: certbot
restart: unless-stopped
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
51 changes: 51 additions & 0 deletions deployment/nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
events {}
http {
server {
listen 80 default_server;
listen [::]:80 default_server;

location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;

ssl_certificate /etc/letsencrypt/live/blue.bicikl-project.eu-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blue.bicikl-project.eu-0001/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;

ssl_dhparam /etc/letsencrypt/dhparam;

# intermediate configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA>
ssl_prefer_server_ciphers off;

# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security "max-age=63072000" always;

# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;

# verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /etc/letsencrypt/live/blue.bicikl-project.eu-0001/fullchain.pem;

location / {
proxy_pass http://tettris_marketplace:3000;
}

location /cordra {
proxy_pass https://cordra:8443;
}

location ~ /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
}
5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--grey: #D9D9DF;
--greyMedium: #B4B4BF;
--greyDark: #868696;
--error: #E74C3C;
}

/* Import Montserrat Font */
Expand Down Expand Up @@ -151,6 +152,10 @@ p {
color: var(--greyDark);
}

.tc-error {
color: var(--error);
}

/* Font weight */
.fw-lightBold {
font-weight: 500;
Expand Down
56 changes: 23 additions & 33 deletions src/api/taxonomicService/GetTaxonomicService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* Import Types */
import { TaxonomicService, JSONResult } from 'app/Types';
/* Import Dependencies */
import axios from 'axios';
import moment from 'moment';

/* Import Mock Data */
import AcceptedTaxonomicService from 'sources/mock/TaxonomicServiceAccepted.json';
import SuggestedTaxonomicService from 'sources/mock/TaxonomicServiceSuggested.json';
import ReferenceCollection from 'sources/mock/ReferenceCollection.json';
/* Import Types */
import { TaxonomicService, CordraResult } from 'app/Types';


/**
Expand All @@ -19,41 +18,32 @@ const GetTaxonomicService = async ({ handle }: { handle?: string }) => {
const taxonomicServiceID: string = handle.replace(process.env.REACT_APP_HANDLE_URL as string, '');

try {
let result: { data: JSONResult };
let mockData;

switch (taxonomicServiceID) {
case 'TEST/SEMKDJE98D7':
mockData = AcceptedTaxonomicService;

result = { data: { ...mockData } };

break;
case 'TEST/LOFKDJE98D7':
result = { data: { ...SuggestedTaxonomicService } };

break;
case 'TEST/POTKDJE98D7':
mockData = ReferenceCollection;

result = { data: { ...mockData } };

break;
default:
throw (new Error('No mock data found'));
}
const result = await axios({
method: 'get',
url: '/Op.Retrieve',
params: {
targetId: taxonomicServiceID
},
responseType: 'json'
});

/* Get result data from JSON */
const data: JSONResult = result.data;
const data: CordraResult = result.data;

/* Set Taxonomic Service */
taxonomicService = data.data.attributes as TaxonomicService;
taxonomicService = data.attributes.content as TaxonomicService;

/* Set created and modified */
taxonomicService.taxonomicService['ods:created'] = moment(new Date(data.attributes.metadata.createdOn)).format('YYYY-MM-DDTHH:mm:ss.sssZ');
taxonomicService.taxonomicService['dcterms:modified'] = moment(new Date(data.attributes.metadata.modifiedOn)).format('YYYY-MM-DDTHH:mm:ss.sssZ');
} catch (error) {
console.warn(error);

throw(error);
}
}
};

return taxonomicService
return taxonomicService;
}

export default GetTaxonomicService;
82 changes: 50 additions & 32 deletions src/api/taxonomicService/GetTaxonomicServices.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* Import Dependencies */
import axios from 'axios';
import moment from 'moment';
import { isEmpty } from 'lodash';

/* Import Types */
import { TaxonomicService, JSONResultArray, Dict } from 'app/Types';
import { TaxonomicService, CordraResultArray, Dict } from 'app/Types';

/* Import Mock Data */
import AcceptedTaxonomicService from 'sources/mock/TaxonomicServiceAccepted.json';
import ReferenceCollection from 'sources/mock/ReferenceCollection.json';
/* Import Sources */
import TaxonomicServiceFilters from 'sources/searchFilters/TaxonomicServiceFilters.json';


/**
Expand All @@ -14,49 +18,63 @@ import ReferenceCollection from 'sources/mock/ReferenceCollection.json';
const GetTaxonomicServices = async ({ pageNumber, pageSize, searchFilters }: { pageNumber: number, pageSize: number, searchFilters: { [searchFilter: string]: string } }) => {
/* Base variables */
let taxonomicServices: TaxonomicService[] = [];
let links: Dict = {};
let metadata: Dict = {};

/* Destructure search filters into string */
let filters: string = '';

filters = filters.concat('/taxonomicService/ods\\:type:taxonomicService');

if (!isEmpty(searchFilters)) {
Object.entries(searchFilters).map(([key, value]) => {
/* Get field alias from taxonomic service filters source */
const alias: string | undefined = TaxonomicServiceFilters.taxonomicServiceFilters.find(taxonomicSearchFilter => taxonomicSearchFilter.name === key)?.alias;

filters = filters.concat(` AND ` + `/taxonomicService/${(alias ?? key).replace(':', '\\:')}:` + `${value}`);
});
};

try {
let result: { data: JSONResultArray } = {
data: {
data: [
...searchFilters?.taxonomicServiceType !== 'referenceCollection' ? [{ ...AcceptedTaxonomicService.data }] : [],
{ ...ReferenceCollection.data }
],
links: {
self: `https://marketplace.cetaf.org/api/v1/taxonomicServices?pageSize=${pageSize}&pageNumber=${pageNumber}`,
first: `https://marketplace.cetaf.org/api/v1/taxonomicServices?pageSize=${pageSize}&pageNumber=1`,
next: `https://marketplace.cetaf.org/api/v1/taxonomicServices?pageSize=${pageSize}&pageNumber=${pageNumber + 1}`,
...(pageNumber > 1 && { previous: `https://marketplace.cetaf.org/api/v1/taxonomicServices?pageSize=${pageSize}&pageNumber=${pageNumber - 1}` })
}
}
};
const result = await axios({
method: 'get',
url: `/Op.Search`,
params: {
pageSize,
pageNum: (pageNumber - 1 >= 0) ? pageNumber - 1 : 0,
targetId: 'service',
query: filters
},
responseType: 'json'
});

/* Get result data from JSON */
const data: JSONResultArray = result.data;
const data: CordraResultArray = result.data;

/* Set Taxonomic Services */
data.data.forEach((dataFragment) => {
const taxonomicService = dataFragment.attributes as TaxonomicService;

let counter = 0;
data.results.forEach((dataFragment) => {
const taxonomicService = dataFragment.attributes.content as TaxonomicService;

while (counter < 6) {
taxonomicServices.push(taxonomicService);
/* Set created and modified */
taxonomicService.taxonomicService['ods:created'] = moment(new Date(dataFragment.attributes.metadata.createdOn)).format('YYYY-MM-DDTHH:mm:ss.sssZ');
taxonomicService.taxonomicService['dcterms:modified'] = moment(new Date(dataFragment.attributes.metadata.modifiedOn)).format('YYYY-MM-DDTHH:mm:ss.sssZ');

counter++;
}
/* Push to taxonomic services array */
taxonomicServices.push(taxonomicService);
});

/* Set Links */
links = result.data.links;
/* Set metadata */
metadata = {
totalRecords: data.size
};
} catch (error) {
console.warn(error);
}

throw(error);
};

return {
taxonomicServices,
links
metadata
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/GenerateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { resolve } from 'path';

/* Taxonomic Service */
const TaxonomicService = async () => {
writeFileSync('src/app/types/TaxonomicService.d.ts', await compileFromFile(resolve(__dirname, '../sources/dataModel', 'taxonomic_service.json'), {}));
writeFileSync('src/app/types/TaxonomicService.d.ts', await compileFromFile(resolve(__dirname, '../sources/dataModel', 'taxonomic-service.json'), {}));
}


Expand Down
Loading

0 comments on commit e16408e

Please sign in to comment.