Skip to content

Commit 76e13ba

Browse files
committed
formatting
1 parent 61fb2c5 commit 76e13ba

File tree

1 file changed

+51
-57
lines changed

1 file changed

+51
-57
lines changed

src/main/java/com/redhat/labs/lodestar/service/EngagementService.java

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class EngagementService {
3737
private static final String DEFAULT_BRANCH = "master";
3838
private static final String ENGAGEMENT_FILE = "engagement.json";
3939
private static final String STATUS_FILE = "status.json";
40-
40+
4141
private String engagementPathPrefix;
4242

4343
@ConfigProperty(name = "engagements.repository.id")
@@ -54,7 +54,7 @@ public class EngagementService {
5454

5555
@Inject
5656
FileService fileService;
57-
57+
5858
@Inject
5959
HookService hookService;
6060

@@ -63,15 +63,15 @@ public class EngagementService {
6363

6464
@Inject
6565
JsonMarshaller json;
66-
66+
6767
@Inject
6868
ConfigService configService;
69-
69+
7070
@PostConstruct
7171
public void setPathPrefix() {
7272
Optional<Group> groupOption = groupService.getGitLabGroupByById(engagementRepositoryId);
73-
74-
if(groupOption.isPresent()) {
73+
74+
if (groupOption.isPresent()) {
7575
engagementPathPrefix = groupOption.get().getFullPath();
7676
LOGGER.info("Engagement repo set- to {}", engagementPathPrefix);
7777
} else {
@@ -94,8 +94,8 @@ public Project createEngagement(Engagement engagement, String author, String aut
9494
repoFiles.add(createEngagmentFile(engagement));
9595

9696
// create actions for multiple commit
97-
CommitMultiple commit = createCommitMultiple(repoFiles, project.getId(), DEFAULT_BRANCH, author,
98-
authorEmail, project.isFirst(), commitMessageOptional);
97+
CommitMultiple commit = createCommitMultiple(repoFiles, project.getId(), DEFAULT_BRANCH, author, authorEmail,
98+
project.isFirst(), commitMessageOptional);
9999

100100
if (LOGGER.isDebugEnabled()) {
101101
commit.getActions().stream().forEach(file -> LOGGER.debug("Action File path :: {}", file.getFilePath()));
@@ -105,12 +105,12 @@ public Project createEngagement(Engagement engagement, String author, String aut
105105
if (!fileService.createFiles(project.getId(), commit)) {
106106
throw new UnexpectedGitLabResponseException("failed to commit files for engagement creation.");
107107
}
108-
108+
109109
List<HookConfig> hookConfigs = configService.getHookConfig();
110110
hookConfigs.stream().forEach(hookC -> {
111-
Hook hook = Hook.builder().projectId(engagement.getProjectId()).pushEvents(true)
112-
.url(hookC.getBaseUrl()).token(hookC.getToken()).build();
113-
if(project.isFirst()) { //No need to check for existing hooks first time
111+
Hook hook = Hook.builder().projectId(engagement.getProjectId()).pushEvents(true).url(hookC.getBaseUrl())
112+
.token(hookC.getToken()).build();
113+
if (project.isFirst()) { // No need to check for existing hooks first time
114114
hookService.createProjectHook(engagement.getProjectId(), hook);
115115
} else {
116116
hookService.createOrUpdateProjectHook(engagement.getProjectId(), hook);
@@ -120,54 +120,55 @@ public Project createEngagement(Engagement engagement, String author, String aut
120120
return project;
121121

122122
}
123-
123+
124124
public List<Commit> getCommitLog(String customerName, String engagementName) {
125125
String projectPath = GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName);
126126
return projectService.getCommitLog(projectPath);
127127
}
128-
128+
129129
public List<Hook> getHooks(String customer, String engagment) {
130130
Optional<Project> project = getProject(customer, engagment);
131-
132-
if(project.isPresent()) {
131+
132+
if (project.isPresent()) {
133133
return hookService.getProjectHooks(project.get().getId());
134134
}
135-
135+
136136
return new ArrayList<>();
137137
}
138-
138+
139139
public Response createHook(String customerName, String engagementName, Hook hook) {
140-
Response created = Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).entity("project doesn't exist").build();
140+
Response created = Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).entity("project doesn't exist")
141+
.build();
141142
Optional<Project> optional = getProject(customerName, engagementName);
142-
143-
if(optional.isPresent()) {
143+
144+
if (optional.isPresent()) {
144145
List<Hook> hooks = hookService.getProjectHooks(optional.get().getId());
145146
boolean hookExists = hooks.stream().anyMatch(h -> h.getUrl().equals(hook.getUrl()));
146-
if(!hookExists) {
147+
if (!hookExists) {
147148
created = hookService.createProjectHook(optional.get().getId(), hook);
148149
}
149150
}
150-
151+
151152
return created;
152153
}
153-
154+
154155
public Status getProjectStatus(String customerName, String engagementName) {
155156
Status status = null;
156-
Optional<File> file = fileService.getFile(GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName), STATUS_FILE);
157-
if(file.isPresent()) {
157+
Optional<File> file = fileService
158+
.getFile(GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName), STATUS_FILE);
159+
if (file.isPresent()) {
158160
status = json.fromJson(file.get().getContent(), Status.class);
159161
}
160-
162+
161163
return status;
162164
}
163-
165+
164166
public Optional<Project> getProject(String customerName, String engagementName) {
165167
String fullPath = GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName);
166-
168+
167169
LOGGER.debug("Full path {}", fullPath);
168170
return projectService.getProjectByIdOrPath(fullPath);
169171
}
170-
171172

172173
/**
173174
* Gets all engagements from the base group Structure is BaseGroup - customer
@@ -181,17 +182,11 @@ public List<Engagement> getAllEngagements() {
181182

182183
List<Project> projects = projectService.getProjectsByGroup(engagementRepositoryId, true);
183184

184-
return
185-
projects
186-
.parallelStream()
187-
.map(project -> {
188-
return getEngagement(project, true);
189-
})
190-
.filter(optional -> optional.isPresent())
191-
.map(optional -> {
192-
return optional.get();
193-
})
194-
.collect(Collectors.toList());
185+
return projects.parallelStream().map(project -> {
186+
return getEngagement(project, true);
187+
}).filter(optional -> optional.isPresent()).map(optional -> {
188+
return optional.get();
189+
}).collect(Collectors.toList());
195190

196191
}
197192

@@ -200,49 +195,48 @@ public Engagement getEngagement(String namespaceOrId, boolean includeStatus) {
200195

201196
Optional<Project> project = projectService.getProjectByIdOrPath(namespaceOrId);
202197

203-
if(project.isPresent()) {
198+
if (project.isPresent()) {
204199
engagement = getEngagement(project.get(), includeStatus).orElse(null);
205200
}
206201

207202
return engagement;
208203
}
209-
204+
210205
public Engagement getEngagement(String customerName, String engagementName, boolean includeStatus) {
211206
Engagement engagement = null;
212-
207+
213208
Optional<Project> project = getProject(customerName, engagementName);
214-
215-
if(project.isPresent()) {
209+
210+
if (project.isPresent()) {
216211
engagement = getEngagement(project.get(), includeStatus).orElse(null);
217212
}
218-
213+
219214
return engagement;
220215
}
221216

222-
223217
private Optional<Engagement> getEngagement(Project project, boolean includeStatus) {
224218
Engagement engagement = null;
225-
219+
226220
Optional<File> engagementFile = fileService.getFileAllow404(project.getId(), ENGAGEMENT_FILE);
227221
if (engagementFile.isPresent()) {
228222
engagement = json.fromJson(engagementFile.get().getContent(), Engagement.class);
229-
223+
230224
List<Commit> commits = projectService.getCommitLog(String.valueOf(engagement.getProjectId()));
231225
engagement.setCommits(commits);
232226
}
233-
234-
if(includeStatus && engagement != null) {
227+
228+
if (includeStatus && engagement != null) {
235229
Optional<File> statusFile = fileService.getFileAllow404(project.getId(), STATUS_FILE);
236-
if(statusFile.isPresent()) {
230+
if (statusFile.isPresent()) {
237231
engagement.setStatus(json.fromJson(statusFile.get().getContent(), Status.class));
238232
}
239233
}
240-
234+
241235
return Optional.ofNullable(engagement);
242236
}
243237

244238
private File createEngagmentFile(Engagement engagement) {
245-
//Git api is read only here.
239+
// Git api is read only here.
246240
engagement.setCommits(null);
247241
engagement.setStatus(null);
248242
engagement.setCommitMessage(null);
@@ -260,7 +254,7 @@ private CommitMultiple createCommitMultiple(List<File> filesToCommit, Integer pr
260254
// results
261255
filesToCommit.stream().forEach(file -> actions.add(createAction(file, isNew)));
262256

263-
// use message if provided. otherwise, defaults
257+
// use message if provided. otherwise, defaults
264258
String commitMessage = commitMessageOptional
265259
.orElse(isNew ? commitMessage("Engagement created") : commitMessage("Engagement updated"));
266260

@@ -282,7 +276,7 @@ private String stripPrefix(String in) {
282276
}
283277
return in;
284278
}
285-
279+
286280
private String commitMessage(String message) {
287281
return String.format("%s %s %s", message, getEmoji(), getEmoji());
288282
}

0 commit comments

Comments
 (0)