Skip to content

Commit 4c60026

Browse files
committed
moved the infering of the file type into its own function
1 parent 0148aaa commit 4c60026

8 files changed

Lines changed: 58 additions & 12 deletions

File tree

convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,39 @@ export default function InputFilesPond(props) {
120120
}
121121
}, [files]);
122122

123+
const inferPotentialFileType = (file) => {
124+
/*
125+
inferPotentialFileType function
126+
127+
Props:
128+
- filename (string): name of the file that was uploaded
129+
130+
Functionality:
131+
- tries to infer based on the file name and extension the file type
132+
(input file, dictionary, mapping file)
133+
134+
Purpose:
135+
- To update the state uploadedFiles with the file that was uploaded
136+
*/
137+
const { filename, fileExtension } = file;
138+
139+
if (
140+
filename.includes("dictionary") &&
141+
["csv", "tsv", "txt"].includes(fileExtension)
142+
) {
143+
return "redcap-dictionary";
144+
}
145+
146+
if (
147+
filename.includes("mapping") &&
148+
["yaml", "yml", "json"].includes(fileExtension)
149+
) {
150+
return "mapping-file";
151+
}
152+
153+
return "input-file";
154+
};
155+
123156
const handleFileUploadFinished = (_, file) => {
124157
/*
125158
handleFileUploadFinished function
@@ -131,25 +164,20 @@ export default function InputFilesPond(props) {
131164
- tries to infer based on the file name and extension the file type
132165
(input file, dictionary, mapping file)
133166
134-
Purpose:
135-
- To update the state uploadedFiles with the file that was uploaded
167+
Purpose:
168+
- To update the state uploadedFiles with the file that was uploaded
136169
*/
137170

138171
const returnedFileName = JSON.parse(file.serverId).tempFilename;
139-
const { filename, fileExtension } = file;
172+
const { filename } = file;
140173

141174
if (filename in uploadedFiles) {
142175
toast.error("File already uploaded");
143176
file.setMetadata("processingAborted", true);
144177
file.abortProcessing();
145178
return;
146179
}
147-
148-
const fileType = filename.includes("dictionary") && fileExtension === "csv"
149-
? "redcap-dictionary"
150-
: filename.includes("mapping") && ["yaml", "yml", "json"].includes(fileExtension)
151-
? "mapping-file"
152-
: "input-file"
180+
const fileType = inferPotentialFileType(file);
153181

154182
setUploadedFiles((prev) => {
155183
return {

convertPheno_server/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ services:
4747
convert-pheno:
4848
user: ${UID}
4949
image: manuelrueda/convert-pheno:0.15
50-
container_name: convert-pheno
50+
container_name: convert-pheno-container
5151
restart: unless-stopped
5252
tty: true
5353
volumes:

convertPheno_server/example.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ API_SECURITY=true
1414
# you can get the public Keycloak key in the admin view or by running
1515
# bash get_public_kc_key.sh https://<yourDomain>/auth/ <yourRealm>
1616
KC_PUBLIC_KEY=MII..
17+
18+
CP_CONTAINER_NAME=convert-pheno-container

convertPheno_server/server/config/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
db_name = environ.get("API_DB_NAME")
2020
security = environ.get("API_SECURITY")
2121
vscode_debugger = environ.get("DEBUGGER")
22+
cp_container_name = environ.get("CP_CONTAINER_NAME")
23+
24+
# check if all environment variables are set
25+
if None in [db_user, db_pw, db_host, db_port, db_name, security, cp_container_name]:
26+
raise ValueError(
27+
"Please set the environment variables:"
28+
"API_DB_USER, API_DB_PW, API_DB_HOST, API_DB_PORT, API_DB_NAME"
29+
"API_SECURITY, CP_CONTAINER_NAME"
30+
)
2231

2332
# throw an error if security is not "true" or "false"
2433
if security not in ["true", "false"]:
@@ -44,3 +53,5 @@ class Config:
4453
FLASK_UPLOAD_DIR = Path("../data/uploads/")
4554
FLASK_EXAMPLE_DIR = Path("../data/example_in/").resolve()
4655
FLASK_OUT_DIR = Path("../data/output/").resolve()
56+
57+
CP_CONTAINER_NAME = cp_container_name

convertPheno_server/server/utils/convert_pheno.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def get_docker_container():
2626
"""
2727
# TODO: add error handling
2828
client = docker.from_env()
29+
container_name = cfg["CP_CONTAINER_NAME"]
2930
try:
30-
container_obj = client.containers.get("convert-pheno")
31+
container_obj = client.containers.get(container_name)
3132
except docker.errors.NotFound:
32-
raise ValueError("Docker container convert-pheno not found")
33+
raise ValueError(f"Docker container {container_name} not found")
3334

3435
return container_obj
3536

docker-compose.prod.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ services:
2929
UID: ${UID}
3030
GID: ${GID}
3131
API_SECURITY: true
32+
CP_CONTAINER_NAME: convert-pheno
3233
restart: unless-stopped
3334
healthcheck:
3435
test: curl -f http://0.0.0.0:5000/api/curltest

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
UID: ${UID}
2727
GID: ${GID}
2828
API_SECURITY: ${API_SECURITY}
29+
CP_CONTAINER_NAME: convert-pheno
2930
restart: unless-stopped
3031
healthcheck:
3132
test: curl -f http://0.0.0.0:5000/api/curltest

example.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ API_DB_NAME=postgres
2323
# API configuration
2424
## enable/disable keycloak security
2525
API_SECURITY=true
26+
27+
CONVERT_PHENO_CONTAINER_NAME=convert-pheno

0 commit comments

Comments
 (0)