Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ASE_Y2S1_CP_G4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joshua Gill
ASE_Y2S1_CP_G4
Merge requests
!110
Created and implemented remove redundant files class, fixed some templating issues on settings page
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Created and implemented remove redundant files class, fixed some templating issues on settings page
issueThirtySeven
into
develop
Overview
0
Commits
1
Pipelines
0
Changes
44
Merged
Seb Barnard
requested to merge
issueThirtySeven
into
develop
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
44
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
e9a31065
1 commit,
3 years ago
44 files
+
97
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
44
Search (e.g. *.vue) (Ctrl+P)
src/main/java/com/example/clientproject/service/Utils/RemoveRedundantFiles.java
0 → 100644
+
58
−
0
Options
package
com.example.clientproject.service.Utils
;
import
com.example.clientproject.data.shops.ShopsRepo
;
import
com.example.clientproject.data.users.UsersRepo
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
@Component
public
class
RemoveRedundantFiles
{
@Autowired
private
ShopsRepo
shopRepo
;
@Autowired
private
UsersRepo
userRepo
;
private
final
String
dir
=
"./src/main/resources/static/imgs/uploaded/"
;
private
Set
<
String
>
getFilesInDir
(){
return
Stream
.
of
(
new
File
(
dir
).
listFiles
())
.
filter
(
file
->
!
file
.
isDirectory
())
.
map
(
File:
:
getName
)
.
collect
(
Collectors
.
toSet
());
}
private
Set
<
String
>
getFilesInDb
(){
Set
<
String
>
curFiles
=
new
HashSet
<>();
shopRepo
.
findAll
().
forEach
(
x
->
{
curFiles
.
add
(
x
.
getShopImage
());
curFiles
.
add
(
x
.
getShopBanner
());});
userRepo
.
findAll
().
forEach
(
x
->
curFiles
.
add
(
x
.
getUserProfilePicture
()));
return
curFiles
;
}
private
Set
<
String
>
getDeletableFiles
(){
Set
<
String
>
deletableFiles
=
getFilesInDir
();
deletableFiles
.
removeAll
(
getFilesInDb
());
return
deletableFiles
;
}
public
void
deleteFiles
(){
for
(
String
fileName:
getDeletableFiles
())
{
File
file
=
new
File
(
dir
+
fileName
);
if
(
file
.
delete
()){
System
.
out
.
println
(
"Deleted file "
+
fileName
);
}
else
{
System
.
out
.
println
(
"Failed to delete "
+
fileName
);
}
}
}
}
Loading