Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97872686
Reader.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jan 7, 00:54
Size
5 KB
Mime Type
text/x-java
Expires
Thu, Jan 9, 00:54 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23424815
Attached To
R3229 Genome Privacy - SHCS App
Reader.java
View Options
package
io.clinicalfactor
;
import
java.awt.Color
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.math.BigInteger
;
import
java.sql.SQLException
;
import
java.util.Date
;
import
java.util.HashMap
;
import
javax.swing.JTextPane
;
import
javax.swing.text.BadLocationException
;
import
javax.swing.text.SimpleAttributeSet
;
import
javax.swing.text.StyleConstants
;
import
javax.swing.text.StyledDocument
;
import
crypto.CryptoException
;
import
crypto.paillier.PaillierScheme
;
import
database.DBconnector_client
;
import
database.DBconnector_server
;
public
class
Reader
implements
Runnable
{
private
String
path
;
private
DBconnector_client
conn_mu
;
private
DBconnector_server
conn_s
;
private
File
input_f
;
private
BufferedReader
br
;
private
BigInteger
[]
pbk
;
private
int
id_p
;
private
PaillierScheme
cryptoScheme
;
private
JTextPane
tp
;
private
StyledDocument
doc
;
private
String
[]
tokens
;
private
String
line
;
private
HashMap
<
String
,
Integer
>
attributes
;
private
String
test
;
private
BigInteger
plain
;
private
BigInteger
[]
cipher
;
public
Reader
(
String
csv_file_path
,
JTextPane
txp
,
String
tst
){
path
=
csv_file_path
;
conn_mu
=
new
DBconnector_client
();
conn_s
=
new
DBconnector_server
();
tp
=
txp
;
doc
=
tp
.
getStyledDocument
();
attributes
=
new
HashMap
<>();
test
=
tst
;
}
@Override
public
void
run
()
{
try
{
//check extension file
String
[]
pathCheck
=
path
.
split
(
"\\."
);
if
(!
pathCheck
[
pathCheck
.
length
-
1
].
equalsIgnoreCase
(
"csv"
))
{
throw
new
IOException
(
"Wrong Format for CSV File!"
);
}
input_f
=
new
File
(
path
);
br
=
new
BufferedReader
(
new
FileReader
(
input_f
));
conn_s
.
openConnection
();
conn_mu
.
openConnection
();
SimpleAttributeSet
attribute
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
attribute
,
Color
.
BLACK
);
long
start
=
System
.
currentTimeMillis
();
switch
(
test
){
case
"Coronary Artery Disease"
:
int
i
=
0
;
while
((
line
=
br
.
readLine
())
!=
null
){
i
++;
tokens
=
line
.
split
(
";"
);
if
(
i
==
1
){
for
(
int
j
=
0
;
j
<
tokens
.
length
;
j
++){
attributes
.
put
(
tokens
[
j
],
j
);
}
}
else
{
id_p
=
Integer
.
parseInt
(
tokens
[
0
]);
try
{
doc
.
insertString
(
doc
.
getLength
(),
"Encrypting clinical factors for patient "
+
id_p
+
"\n"
,
attribute
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
pbk
=
conn_s
.
getPublicKey
(
id_p
);
cryptoScheme
=
new
PaillierScheme
(
pbk
[
0
],
pbk
[
1
],
pbk
[
2
]);
//Current Smoking
plain
=
new
BigInteger
(
tokens
[
attributes
.
get
(
"SMOKE"
)]);
cipher
=
cryptoScheme
.
encrypt
(
plain
);
conn_s
.
insertEncryptedCF
(
id_p
,
conn_mu
.
getCF
(
"Current smoking"
),
cipher
[
0
],
cipher
[
1
],
null
,
null
);
//Age
String
birthdate
=
tokens
[
attributes
.
get
(
"BIRTHDATE"
)];
String
[]
date
=
birthdate
.
split
(
"/"
);
Date
today
=
new
Date
();
plain
=
BigInteger
.
valueOf
(
1900
+
today
.
getYear
()
-
Integer
.
parseInt
(
date
[
2
]));
cipher
=
cryptoScheme
.
encrypt
(
plain
);
conn_s
.
insertEncryptedCF
(
id_p
,
conn_mu
.
getCF
(
"Age"
),
cipher
[
0
],
cipher
[
1
],
null
,
null
);
//Family history of CAD
String
value
=
tokens
[
attributes
.
get
(
"CV_POS_FAMILY"
)];
if
(
Integer
.
parseInt
(
value
)
==
0
)
plain
=
BigInteger
.
ZERO
;
else
plain
=
BigInteger
.
ONE
;
cipher
=
cryptoScheme
.
encrypt
(
plain
);
conn_s
.
insertEncryptedCF
(
id_p
,
conn_mu
.
getCF
(
"Family history of CAD"
),
cipher
[
0
],
cipher
[
1
],
null
,
null
);
//Past Smoking
if
(
tokens
[
attributes
.
get
(
"PAST_SMOKE"
)].
equals
(
"1"
))
plain
=
BigInteger
.
ONE
;
else
plain
=
BigInteger
.
ZERO
;
cipher
=
cryptoScheme
.
encrypt
(
plain
);
conn_s
.
insertEncryptedCF
(
id_p
,
conn_mu
.
getCF
(
"Past smoking"
),
cipher
[
0
],
cipher
[
1
],
null
,
null
);
//Hyper-cholesterolemia
double
chol
=
Double
.
parseDouble
(
tokens
[
attributes
.
get
(
"CHOL"
)]);
if
(
chol
>
6.2d
)
plain
=
BigInteger
.
ONE
;
else
plain
=
BigInteger
.
ZERO
;
cipher
=
cryptoScheme
.
encrypt
(
plain
);
conn_s
.
insertEncryptedCF
(
id_p
,
conn_mu
.
getCF
(
"Hyper-cholesterolemia"
),
cipher
[
0
],
cipher
[
1
],
null
,
null
);
//Hypertension
int
diastolic
=
Integer
.
parseInt
(
tokens
[
attributes
.
get
(
"DIASTOLIC"
)]);
int
systolic
=
Integer
.
parseInt
(
tokens
[
attributes
.
get
(
"SYSTOLIC"
)]);
if
(
diastolic
>=
90
||
systolic
>=
140
||
!
tokens
[
attributes
.
get
(
"CURRENT_ART"
)].
equals
(
""
))
plain
=
BigInteger
.
ONE
;
else
plain
=
BigInteger
.
ZERO
;
cipher
=
cryptoScheme
.
encrypt
(
plain
);
conn_s
.
insertEncryptedCF
(
id_p
,
conn_mu
.
getCF
(
"Hypertension"
),
cipher
[
0
],
cipher
[
1
],
null
,
null
);
}
}
break
;
}
long
end
=
System
.
currentTimeMillis
();
try
{
doc
.
insertString
(
doc
.
getLength
(),
"Parsing CSV File and encryption, completed!"
+
"\n"
,
attribute
);
doc
.
insertString
(
doc
.
getLength
(),
(
end
-
start
)
+
" ms\n"
,
attribute
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
}
catch
(
IOException
|
CryptoException
|
NullPointerException
e
){
e
.
printStackTrace
();
SimpleAttributeSet
error
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
error
,
Color
.
RED
);
try
{
doc
.
insertString
(
doc
.
getLength
(),
e
.
getMessage
()
+
"\n"
,
error
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
SimpleAttributeSet
error
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
error
,
Color
.
RED
);
try
{
doc
.
insertString
(
doc
.
getLength
(),
"No Connection with the Server"
+
"\n"
,
error
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
Event Timeline
Log In to Comment