@@ -80,21 +80,7 @@ public void purge() {
80
80
* and inserts into the database.
81
81
*/
82
82
public void refresh () {
83
-
84
- engagementRestClient .getAllEngagementProjects ().stream ().map (Engagement ::getProjectId )
85
- .map (this ::getArtifactsFromGitlabByProjectId ).flatMap (Collection ::stream )
86
- .forEach (a -> {
87
-
88
- // set uuid if missing
89
- if (null == a .getUuid ()) {
90
- a .setUuid (UUID .randomUUID ().toString ());
91
- }
92
-
93
- // persist the artifact
94
- createOrUpdateArtifact (a );
95
-
96
- });
97
-
83
+ engagementRestClient .getAllEngagementProjects ().parallelStream ().forEach (this ::reloadFromGitlabByEngagement );
98
84
}
99
85
100
86
/**
@@ -105,22 +91,38 @@ public void refresh() {
105
91
* @param projectId
106
92
* @return
107
93
*/
108
- List <Artifact > getArtifactsFromGitlabByProjectId (long projectId ) {
94
+ void reloadFromGitlabByEngagement (Engagement engagement ) {
95
+ if (engagement .getUuid () == null ) {
96
+ LOGGER .error ("Engagement found with no uuid. Check description of project {}" , engagement .getProjectId ());
97
+ return ;
98
+ }
99
+
109
100
try {
110
- File file = gitlabRestClient .getFile (projectId , artifactsFile , defaultBranch );
101
+ File file = gitlabRestClient .getFile (engagement . getProjectId () , artifactsFile , defaultBranch );
111
102
if (null == file .getContent () || file .getContent ().isBlank ()) {
112
- LOGGER .error ("NO FILE DATA FROM GITLAB FOR PROJECT {}. THIS SHALL NOT STAND" , projectId );
113
- return Collections . emptyList () ;
103
+ LOGGER .error ("IMPOSSIBLE. NO FILE DATA FROM GITLAB FOR PROJECT {}. THIS SHALL NOT STAND" , engagement . getProjectId () );
104
+ return ;
114
105
}
115
106
116
107
file .decodeFileAttributes ();
117
- return Arrays .asList (jsonb .fromJson (file .getContent (), Artifact [].class ));
108
+ List <Artifact > artifacts = Arrays .asList (jsonb .fromJson (file .getContent (), Artifact [].class ));
109
+
110
+ artifacts .forEach (a -> {
111
+ a .setEngagementUuid (engagement .getUuid ());
112
+ // set uuid if missing
113
+ if (null == a .getUuid ()) {
114
+ a .setUuid (UUID .randomUUID ().toString ());
115
+ }
116
+
117
+ // persist the artifact
118
+ createOrUpdateArtifact (a );
119
+ });
118
120
119
121
} catch (WebApplicationException wae ) {
120
122
if (wae .getResponse ().getStatus () != 404 ) {
121
123
throw wae ;
122
124
}
123
- return Collections . emptyList ( );
125
+ LOGGER . error ( "NO FILE DATA FROM GITLAB FOR PROJECT {}. THIS SHALL NOT STAND" , engagement . getProjectId () );
124
126
}
125
127
}
126
128
0 commit comments