Skip to content
GitLab
Explore
Sign in
xtof
JOSAST
Compare revisions
9fd844f07591041a4bc7aeffd5ad1674e1be6942 to 200ac5b77ae3ac1837dfceccd7ccc0050fad3be6
Commits on Source (2)
feat : add json library
· 53230656
xtof
authored
Jan 16, 2021
53230656
feat : add transfert to latmos
· 200ac5b7
xtof
authored
Jan 16, 2021
200ac5b7
Hide whitespace changes
Inline
Side-by-side
ApplicationDatabaseSynchronisation/pom.xml
View file @
200ac5b7
...
...
@@ -53,8 +53,15 @@
<groupId>
com.jcraft
</groupId>
<artifactId>
jsch
</artifactId>
<version>
0.1.55
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.6
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
@@ -90,4 +97,4 @@
</plugins>
</build>
</project>
</project>
\ No newline at end of file
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/AmsatToUvsqsatSyncConfig.java
0 → 100644
View file @
200ac5b7
package
org.josast.databaseSync
;
public
class
AmsatToUvsqsatSyncConfig
{
public
String
login
;
public
String
password
;
public
String
sftpUrl
;
public
String
amsatDatabaseUrl
;
public
String
sshUrl
;
public
String
deltaTime
;
public
String
satelliteNasaId
;
/**
* @return the login
*/
public
String
getLogin
()
{
return
login
;
}
/**
* @param login the login to set
*/
public
void
setLogin
(
String
login
)
{
this
.
login
=
login
;
}
/**
* @return the password
*/
public
String
getPassword
()
{
return
password
;
}
/**
* @param password the password to set
*/
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
/**
* @return the sftpUrl
*/
public
String
getSftpUrl
()
{
return
sftpUrl
;
}
/**
* @param sftpUrl the sftpUrl to set
*/
public
void
setSftpUrl
(
String
sftpUrl
)
{
this
.
sftpUrl
=
sftpUrl
;
}
/**
* @return the amsatDatabaseUrl
*/
public
String
getAmsatDatabaseUrl
()
{
return
amsatDatabaseUrl
;
}
/**
* @param amsatDatabaseUrl the amsatDatabaseUrl to set
*/
public
void
setAmsatDatabaseUrl
(
String
amsatDatabaseUrl
)
{
this
.
amsatDatabaseUrl
=
amsatDatabaseUrl
;
}
/**
* @return the sshUrl
*/
public
String
getSshUrl
()
{
return
sshUrl
;
}
/**
* @param sshUrl the sshUrl to set
*/
public
void
setSshUrl
(
String
sshUrl
)
{
this
.
sshUrl
=
sshUrl
;
}
/**
* @return the deltaTime
*/
public
String
getDeltaTime
()
{
return
deltaTime
;
}
/**
* @param deltaTime the deltaTime to set
*/
public
void
setDeltaTime
(
String
deltaTime
)
{
this
.
deltaTime
=
deltaTime
;
}
/**
* @return the satelliteNasaId
*/
public
String
getSatelliteNasaId
()
{
return
satelliteNasaId
;
}
/**
* @param satelliteNasaId the satelliteNasaId to set
*/
public
void
setSatelliteNasaId
(
String
satelliteNasaId
)
{
this
.
satelliteNasaId
=
satelliteNasaId
;
}
@Override
public
String
toString
()
{
return
"AmsatToUvsqsatSyncConfig [login="
+
login
+
", password="
+
password
+
", sftpUrl="
+
sftpUrl
+
", amsatDatabaseUrl="
+
amsatDatabaseUrl
+
", sshUrl="
+
sshUrl
+
", deltaTime="
+
deltaTime
+
", satelliteNasaId="
+
satelliteNasaId
+
"]"
;
}
}
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/AppSynchroAmsatToUvsqsat.java
0 → 100644
View file @
200ac5b7
package
org.josast.databaseSync
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardOpenOption
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.TimeZone
;
import
java.util.logging.Logger
;
import
org.josast.databaseSync.config.ManageJSonConfigFile
;
import
org.json.JSONObject
;
public
class
AppSynchroAmsatToUvsqsat
{
private
static
Logger
appLogger
=
Logger
.
getLogger
(
"AmsatLogger"
);
private
static
long
MN
=
1000
*
60
;
private
Path
filepath
;
private
String
RepositoryPath
=
"config"
;
private
AmsatToUvsqsatSyncConfig
config
=
new
AmsatToUvsqsatSyncConfig
();
private
String
fileIn
=
null
;
SimpleDateFormat
formater
=
new
SimpleDateFormat
(
"yyyy-MM-dd-HH-mm-ss.SSS"
);
public
void
execute
()
{
formater
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
// lecture de la configuration
ManageJSonConfigFile
mjcf
=
new
ManageJSonConfigFile
();
config
=
(
AmsatToUvsqsatSyncConfig
)
mjcf
.
readJson
(
new
AmsatToUvsqsatSyncConfig
());
// Récupération des données
GetDataFromAmsatDatabase
dataAmsatDb
=
new
GetDataFromAmsatDatabase
(
config
.
getAmsatDatabaseUrl
());
Date
endDate
=
new
Date
();
long
temp
=
endDate
.
getTime
()
-
MN
*
Integer
.
parseInt
(
config
.
getDeltaTime
());
Date
startDate
=
new
Date
(
temp
);
DataToExchange
[]
results
=
dataAmsatDb
.
getTelemetrydata
(
startDate
,
endDate
,
Integer
.
parseInt
(
config
.
getSatelliteNasaId
()));
// et écriture dans un fichier
if
(
results
!=
null
)
{
// file format 2020-12-21-17-42-19.409-Data.json
String
creationdate
=
formater
.
format
(
startDate
);
fileIn
=
creationdate
+
"-Data.json"
;
DataToUVSQsatControlCenter
dtc
=
new
DataToUVSQsatControlCenter
(
results
,
fileIn
);
dtc
.
save
();
// Envoie du fichier vers Latmos
SendSftp
sfp
=
new
SendSftp
(
config
.
getSftpUrl
(),
config
.
getLogin
(),
config
.
getPassword
());
String
remotefile
=
"/toLATMOS/json/"
+
fileIn
;
String
localfile
=
fileIn
;
sfp
.
upload
(
localfile
,
remotefile
);
System
.
out
.
println
(
"Upload"
);
// efface fichier local.
try
{
Files
.
delete
(
Paths
.
get
(
fileIn
));
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
System
.
exit
(
0
);
}
}
public
int
SaveConfigFile
(
AmsatToUvsqsatSyncConfig
tlmData
)
{
int
erreur
=
0
;
SimpleDateFormat
formater
=
new
SimpleDateFormat
(
"yyyy-MM-dd-HH-mm-ss.SSS"
);
Date
aujourdhui
=
new
Date
();
JSONObject
jasonObject
=
new
JSONObject
(
tlmData
);
String
creationdate
=
formater
.
format
(
aujourdhui
);
// AmsatToUvsqsatSyncConfig jasonObject2 = (AmsatToUvsqsatSyncConfig) toBean(jasonObject, new AmsatToUvsqsatSyncConfig());
filepath
=
Paths
.
get
(
this
.
RepositoryPath
+
"\\Data.json"
);
try
{
if
(!
Files
.
exists
(
filepath
))
{
Files
.
createFile
(
filepath
);
Files
.
writeString
(
filepath
,
" "
+
"\r\n"
,
StandardOpenOption
.
CREATE
);
}
Files
.
writeString
(
filepath
,
jasonObject
.
toString
()
+
"\r\n"
,
StandardOpenOption
.
CREATE
);
if
(
Files
.
size
(
filepath
)<
10
)
{
appLogger
.
severe
(
"file not created "
);
erreur
=-
1
;
}
}
catch
(
IOException
e
)
{
appLogger
.
severe
(
e
.
toString
());
erreur
=-
1
;
}
return
erreur
;
}
public
static
void
main
(
String
[]
args
)
{
AppSynchroAmsatToUvsqsat
app
=
new
AppSynchroAmsatToUvsqsat
();
app
.
execute
();
// app.initDirectory();
// AmsatToUvsqsatSyncConfig config = new AmsatToUvsqsatSyncConfig();
// config.setAmsatDatabaseUrl("AMSATDataBase");
// config.setDeltaTimeLong(10);
// config.setDeltaTime("10");
// config.setLogin("login");
// config.setPassword("password");
// config.setSftpUrl("URL SFTP");
// config.setSshUrl("SSH file");
////
// app.readJson( );
// app.saveTlmData(config);
}
}
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/DataToUVSQsatControlCenter.java
View file @
200ac5b7
...
...
@@ -5,52 +5,40 @@ import java.nio.charset.StandardCharsets;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.logging.Logger
;
import
org.josast.SIDS.SIDSData
;
import
org.json.JSONArray
;
public
class
DataToUVSQsatControlCenter
implements
Commande
{
public
class
DataToUVSQsatControlCenter
implements
Commande
{
private
SIDSData
[]
sidsdata
;
private
static
Logger
appLogger
=
Logger
.
getLogger
(
"AmsatLogger"
);
private
DataToExchange
[]
data
;
private
String
file
=
null
;
public
DataToUVSQsatControlCenter
(
SIDSData
[]
sidsdataIn
,
String
fileIn
)
{
sidsdata
=
sidsdataIn
.
clone
();
public
DataToUVSQsatControlCenter
(
DataToExchange
[]
sidsdataIn
,
String
fileIn
)
{
data
=
sidsdataIn
.
clone
();
file
=
fileIn
;
}
@Override
public
void
excecute
()
{
// ObjectMapper mapper = new ObjectMapper();
DataToExchange
dte
[]
=
new
DataToExchange
[
sidsdata
.
length
];
for
(
int
i
=
0
;
i
<
sidsdata
.
length
;
i
++
)
{
dte
[
i
]
=
new
DataToExchange
(
sidsdata
[
i
].
getSource
(),
sidsdata
[
i
].
getTimestamp
()
,
sidsdata
[
i
].
getFrame
(),
sidsdata
[
i
].
getLongitude
(),
sidsdata
[
i
].
getLatitude
());
}
JSONArray
ja
=
new
JSONArray
(
dte
);
Path
path
=
Paths
.
get
(
file
);
save
();
}
public
void
save
()
{
JSONArray
ja
=
new
JSONArray
(
data
);
Path
path
=
Paths
.
get
(
file
);
try
{
Files
.
writeString
(
path
,
ja
.
toString
(),
StandardCharsets
.
UTF_8
);
Files
.
writeString
(
path
,
ja
.
toString
(),
StandardCharsets
.
UTF_8
);
}
catch
(
IOException
ex
)
{
// Handle exception
appLogger
.
severe
(
"can not write "
+
file
+
" "
+
ex
.
getMessage
());
}
}
}
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/GetDataFromAmsatDatabase.java
0 → 100644
View file @
200ac5b7
package
org.josast.databaseSync
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.Iterator
;
import
java.util.TimeZone
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
public
class
GetDataFromAmsatDatabase
implements
Commande
{
private
String
file
=
null
;
private
String
urlDatabase
=
null
;
final
private
SimpleDateFormat
ISO8601DATEFORMAT
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
public
GetDataFromAmsatDatabase
(
String
urlIn
)
{
urlDatabase
=
urlIn
;
ISO8601DATEFORMAT
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
}
public
DataToExchange
[]
getTelemetrydata
(
Date
startdate
,
Date
endate
,
int
noradid
)
{
String
startDate
=
ISO8601DATEFORMAT
.
format
(
startdate
);
String
endDate
=
ISO8601DATEFORMAT
.
format
(
endate
);
DataToExchange
dte
[]
=
null
;
// ?endTimeStamp=2021-10-08T15:00:00Z&noradID=1000&startTimeStamp=2021-09-08T13:00:00Z
String
url
=
urlDatabase
+
"?startTimeStamp="
+
startDate
+
"&endTimeStamp="
+
endDate
+
"&noradID="
+
noradid
;
HttpGetDatabasse
httpget
=
new
HttpGetDatabasse
();
String
results
=
httpget
.
sendGET
(
url
);
JSONArray
json
=
new
JSONArray
(
results
);
if
(
json
.
length
()
!=
0
)
{
JSONObject
jsonObject
=
(
JSONObject
)
json
.
get
(
0
);
dte
=
new
DataToExchange
[
json
.
length
()];
for
(
int
i
=
0
;
i
<
json
.
length
();
i
++)
{
jsonObject
=
(
JSONObject
)
json
.
get
(
i
);
dte
[
i
]
=
new
DataToExchange
(
jsonObject
.
getString
(
"source"
),
jsonObject
.
getString
(
"timestamp"
),
jsonObject
.
getString
(
"frame"
),
jsonObject
.
getString
(
"latitude"
),
jsonObject
.
getString
(
"longitude"
));
}
}
return
dte
;
}
@Override
public
void
excecute
()
{
}
}
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/SendSftp.java
0 → 100644
View file @
200ac5b7
package
org.josast.databaseSync
;
import
java.util.logging.Logger
;
import
com.jcraft.jsch.ChannelSftp
;
import
com.jcraft.jsch.JSch
;
import
com.jcraft.jsch.JSchException
;
import
com.jcraft.jsch.Session
;
import
com.jcraft.jsch.SftpException
;
public
class
SendSftp
{
private
static
Logger
appLogger
=
Logger
.
getLogger
(
"AmsatLogger"
);
private
String
remoteHost
=
null
;
private
String
username
=
null
;
private
String
password
=
null
;
private
String
KnownHosts
=
"LATMOS_SSH"
;
private
ChannelSftp
channelSftp
=
null
;
public
SendSftp
(
String
remoteHost
,
String
username
,
String
password
)
{
super
();
this
.
remoteHost
=
remoteHost
;
this
.
username
=
username
;
this
.
password
=
password
;
channelSftp
=
setupJsch
();
}
public
ChannelSftp
setupJsch
()
{
Session
jschSession
=
null
;
ChannelSftp
channel
=
null
;
try
{
JSch
jsch
=
new
JSch
();
jsch
.
setKnownHosts
(
KnownHosts
);
jschSession
=
jsch
.
getSession
(
username
,
remoteHost
);
jschSession
.
setPassword
(
password
);
jschSession
.
connect
();
}
catch
(
Exception
e
)
{
appLogger
.
severe
(
"error connection to "
+
remoteHost
+
" "
+
e
.
getMessage
());
}
try
{
channel
=
(
ChannelSftp
)
jschSession
.
openChannel
(
"sftp"
);
}
catch
(
JSchException
e
)
{
appLogger
.
severe
(
"error to open channel sftp "
+
e
.
getMessage
());
}
return
channel
;
}
public
void
upload
(
String
filein
,
String
fileout
)
{
try
{
channelSftp
.
connect
();
}
catch
(
JSchException
e
)
{
appLogger
.
severe
(
"error to connect channel "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
try
{
channelSftp
.
put
(
filein
,
fileout
);
}
catch
(
SftpException
e
)
{
appLogger
.
severe
(
"error to send file "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
System
.
out
.
println
(
"sentn"
);
channelSftp
.
exit
();
}
}
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/config/ManageFolder.java
0 → 100644
View file @
200ac5b7
package
org.josast.databaseSync.config
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
ManageFolder
{
private
static
Logger
appLogger
=
Logger
.
getLogger
(
"AmsatLogger"
);
private
String
RepositoryPath
=
null
;
private
String
defaultrepository
=
"data"
;
public
ManageFolder
()
{
RepositoryPath
=
System
.
getProperty
(
"user.dir"
)
+
"\\"
+
defaultrepository
;
}
public
ManageFolder
(
String
path
)
{
if
(
path
==
null
)
{
RepositoryPath
=
System
.
getProperty
(
"user.dir"
)
+
"\\"
+
defaultrepository
;
}
else
if
(
path
.
length
()
==
0
)
{
RepositoryPath
=
System
.
getProperty
(
"user.dir"
)
+
"\\+defaultrepository"
;
}
else
{
RepositoryPath
=
System
.
getProperty
(
"user.dir"
)
+
"\\"
+
path
;
}
}
/**
* @return the repositoryPath
*/
public
String
getRepositoryPath
()
{
return
RepositoryPath
;
}
/**
* @param repositoryPath the repositoryPath to set
*/
public
void
setRepositoryPath
(
String
repositoryPath
)
{
RepositoryPath
=
repositoryPath
;
}
public
void
createdDirectories
()
{
Path
path
=
Paths
.
get
(
RepositoryPath
);
// if directory exists?
if
(!
Files
.
exists
(
path
))
{
try
{
Files
.
createDirectories
(
path
);
appLogger
.
info
(
"directory created : "
+
RepositoryPath
);
}
catch
(
IOException
e
)
{
appLogger
.
log
(
Level
.
SEVERE
,
"cannot create outpout directorie "
+
e
.
toString
());
}
}
else
{
appLogger
.
info
(
"directory already exist : "
+
RepositoryPath
);
}
}
}
ApplicationDatabaseSynchronisation/src/main/java/org/josast/databaseSync/config/ManageJSonConfigFile.java
0 → 100644
View file @
200ac5b7
package
org.josast.databaseSync.config
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.Field
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardOpenOption
;
import
java.util.logging.Logger
;
import
org.apache.commons.io.IOUtils
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
ManageJSonConfigFile
{
private
static
Logger
appLogger
=
Logger
.
getLogger
(
"AmsatLogger"
);
private
String
configRepository
=
"config"
;
private
String
configName
=
"Data.json"
;
public
int
SaveConfigFile
(
Object
bean
)
{
ManageFolder
mn
=
new
ManageFolder
(
configRepository
);
mn
.
createdDirectories
();
Path
filepath
=
Paths
.
get
(
mn
.
getRepositoryPath
()
+
"\\"
+
configName
);
int
erreur
=
0
;
JSONObject
jasonObject
=
new
JSONObject
(
bean
);
try
{
if
(!
Files
.
exists
(
filepath
))
{
Files
.
createFile
(
filepath
);
Files
.
writeString
(
filepath
,
" "
+
"\r\n"
,
StandardOpenOption
.
CREATE
);
}
Files
.
writeString
(
filepath
,
jasonObject
.
toString
()
+
"\r\n"
,
StandardOpenOption
.
CREATE
);
if
(
Files
.
size
(
filepath
)
<
10
)
{
appLogger
.
severe
(
"file not created "
);
erreur
=
-
1
;
}
}
catch
(
IOException
e
)
{
appLogger
.
severe
(
e
.
toString
());
erreur
=
-
1
;
}
return
erreur
;
}
public
Object
readJson
(
Object
object
)
{
Object
tempobject
=
null
;
String
RepositoryPath
=
System
.
getProperty
(
"user.dir"
)
+
"\\"
+
configRepository
;
System
.
out
.
println
(
RepositoryPath
);
Path
filepath
=
Paths
.
get
(
RepositoryPath
+
"\\"
+
configName
);
try
{
InputStream
is
=
Files
.
newInputStream
(
filepath
);
String
text
=
IOUtils
.
toString
(
is
,
"UTF-8"
);
JSONObject
myJsonObject
=
new
JSONObject
(
text
);
tempobject
=
toBean
(
myJsonObject
,
object
);
}
catch
(
IOException
|
JSONException
e
)
{
e
.
printStackTrace
();
appLogger
.
severe
(
"Erreor reading json file"
+
filepath
.
getFileName
());
}
return
tempobject
;
}
public
static
Object
toBean
(
JSONObject
jobject
,
Object
object
)
{
for
(
Field
field
:
object
.
getClass
().
getDeclaredFields
())
{
try
{
field
.
set
(
object
,
jobject
.
getString
(
field
.
getName
()));
}
catch
(
IllegalArgumentException
|
IllegalAccessException
|
JSONException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
return
object
;
}
}