Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flopbox-agent
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oualid Hassan
flopbox-agent
Commits
9b1ab729
Commit
9b1ab729
authored
3 years ago
by
Adrien Morel
Browse files
Options
Downloads
Patches
Plain Diff
readme update + video + uml
parent
9fe766ff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+98
-2
98 additions, 2 deletions
README.md
uml.png
+0
-0
0 additions, 0 deletions
uml.png
video.mp4
+0
-0
0 additions, 0 deletions
video.mp4
with
98 additions
and
2 deletions
README.md
+
98
−
2
View file @
9b1ab729
# Flop
b
ox
a
gent
#
SR2 -
Flop
B
ox
-A
gent
##
## Hassan Oualid - Morel Adrien
\ No newline at end of file
### 10 Avril 2022
## Introduction
Ce projet à pour but de permettre à un utilisateur une mise à jour automatique des fichiers de répertoires
associès avec un serveur FTP via l'api FlopBox. A la création ainsi qu'a la modification d'un fichier local celui-ci est envoyé sur le serveur FTP
associé a son répertoire. A la suppression celui-ci est déplacé vers un repertoire distant ".deleted" à la racine du serveur FTP.
## Démo

## Exécution
Pour générer un exécutable .jar utilisez la commande suivante:
```
bash
mvn clean package
```
Ensuite pour le lancer:
```
bash
java
-jar
./target/flopbox-agent-1.0-SNAPSHOT.jar
```
Pour générer la javadoc:
```
bash
mvn javadoc:javadoc
```
## Architechture
Deux Threads distinct sont présent dans ce programme, un est chragé de verifier si il y a création, modification, suppression des fichiers locaux.
(Via la librairie Apache.io Monitor)
L'autre est lui chargé de vérifier si il y a des modfications sur le serveur FTP distant.
De plus voici le diagram uml du projet:

## Code samples
Ici pour verifier la modification des fichiers locaux nous utilisons Apache.io Monitor qui permet une compréhension aisée du code:
```
java
public
void
run
()
{
File
directory
=
new
File
(
Configuration
.
instance
.
getDataDirectoryPath
());
FileAlterationObserver
observer
=
new
FileAlterationObserver
(
directory
);
observer
.
addListener
(
this
);
while
(
true
)
{
try
{
observer
.
checkAndNotify
();
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
```
Ici grace au "objectMapper" on peut transformer facilement en objet java les résultats d'une requête sur l'api:
```
java
public
static
FtpFileDto
[]
listFiles
(
String
alias
,
String
path
)
throws
IOException
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
LocalFtpServer
ftpServer
=
Configuration
.
getFtpServerFromAlias
(
alias
).
orElseThrow
();
OkHttpClient
okHttpClient
=
new
OkHttpClient
();
Request
request
=
new
Request
.
Builder
()
.
url
(
"http://localhost:8080/v1/ftps/"
+
alias
+
"/"
+
path
+
"?action=list&recursive=true"
)
.
header
(
"Authorization"
,
"Bearer "
+
JWT
)
.
header
(
"Ftp-Username"
,
ftpServer
.
getUsername
())
.
header
(
"Ftp-Password"
,
ftpServer
.
getPassword
())
.
build
();
try
(
Response
response
=
okHttpClient
.
newCall
(
request
).
execute
())
{
return
objectMapper
.
readValue
(
response
.
body
().
byteStream
(),
FtpFileDto
[].
class
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
```
Ici on récupere les séparateur présents dans le path des fichiers, cela permet l'intercompatibilité du code notament sous les systèmes windows:
```
java
public
class
FlopboxService
{
private
final
static
String
SEPARATOR
=
Pattern
.
quote
(
System
.
getProperty
(
"file.separator"
));
...
}
```
This diff is collapsed.
Click to expand it.
uml.png
0 → 100644
+
0
−
0
View file @
9b1ab729
486 KiB
This diff is collapsed.
Click to expand it.
video.mp4
0 → 100644
+
0
−
0
View file @
9b1ab729
File added
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment