Skip to content

Commit 8387ff8

Browse files
committed
code q
1 parent 59e06ee commit 8387ff8

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/main/java/com/redhat/labs/lodestar/model/GetListOptions.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@ public Sort getQuerySort(Sort defaultSort) {
4646
return defaultSort;
4747
}
4848
String[] sortAll = sort.split(",");
49-
Sort sort = null;
49+
Sort querySort = null;
5050
String direction;
5151

5252
for (String s : sortAll) {
5353
String[] sortFields = s.split("\\|");
5454
direction = sortFields.length == 2 ? sortFields[1] : "";
55-
if (sort == null) {
56-
sort = Sort.by(sortFields[0], getDirection(direction));
55+
if (querySort == null) {
56+
querySort = Sort.by(sortFields[0], getDirection(direction));
5757
} else {
58-
sort.and(sortFields[0], getDirection(direction));
58+
querySort.and(sortFields[0], getDirection(direction));
5959
}
6060
}
6161

62-
sort.and("uuid");
62+
if(querySort != null) {
63+
querySort.and("uuid");
64+
}
6365

64-
return sort;
66+
return querySort;
6567
}
6668

6769
private Sort.Direction getDirection(String dir) {

src/main/java/com/redhat/labs/lodestar/model/GetOptions.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public class GetOptions {
2727

2828
@Parameter(name = "region", required = false, description = "return only artifacts for the given region. Do not use with engagementUuid")
2929
@QueryParam("region")
30-
31-
private List<String> region = new ArrayList<String>();
30+
private List<String> region = new ArrayList<>();
3231

3332
public Optional<String> getEngagementUuid() {
3433
return Optional.ofNullable(engagementUuid);
@@ -39,11 +38,7 @@ public Optional<String> getType() {
3938
}
4039

4140
public List<String> getRegion() {
42-
if(region == null) {
43-
region = new ArrayList<String>();
44-
}
45-
46-
return region;
41+
return region == null ? new ArrayList<>() : region;
4742
}
4843

4944
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ public void updateArtifacts(String engagementUuid, String region, List<Artifact>
158158
}
159159

160160
}
161-
162161

163162
/**
164163
* Returns a {@link List} of {@link Artifact}s matching the specified
@@ -170,7 +169,7 @@ public void updateArtifacts(String engagementUuid, String region, List<Artifact>
170169
public List<Artifact> getArtifacts(GetListOptions options) {
171170

172171
if(!options.getRegion().isEmpty() && options.getType().isPresent()) { //by region and type
173-
return Artifact.pagedArtifactsByRegionAndType(options.getType().get(), options.getRegion(), options.getPage(),
172+
return Artifact.pagedArtifactsByRegionAndType(options.getType().orElse(""), options.getRegion(), options.getPage(),
174173
options.getPageSize(), options.getQuerySort());
175174
}
176175

@@ -180,7 +179,7 @@ public List<Artifact> getArtifacts(GetListOptions options) {
180179

181180
if(options.getType().isPresent()) { //by type
182181
checkEngagementUuid(options.getEngagementUuid());
183-
return Artifact.pagedArtifactsByType(options.getType().get(), options.getPage(), options.getPageSize(), options.getQuerySort());
182+
return Artifact.pagedArtifactsByType(options.getType().orElse(""), options.getPage(), options.getPageSize(), options.getQuerySort());
184183
}
185184

186185
Optional<String> engagementUuid = options.getEngagementUuid();
@@ -211,17 +210,18 @@ private void checkEngagementUuid(Optional<String> engagementUuid) {
211210
* @return
212211
*/
213212
public ArtifactCount countArtifacts(GetOptions options) {
213+
String type = options.getType().orElse("");
214214

215215
Optional<String> engagementUuid = options.getEngagementUuid();
216216

217217
ArtifactCount count;
218218

219219
if(!options.getRegion().isEmpty() && options.getType().isPresent()) {
220-
count = Artifact.countArtifactsByRegionAndType(options.getType().get(), options.getRegion());
220+
count = Artifact.countArtifactsByRegionAndType(type, options.getRegion());
221221
} else if(!options.getRegion().isEmpty()) {
222222
count = Artifact.countArtifactsByRegion(options.getRegion());
223223
} else if(options.getType().isPresent()) {
224-
count = Artifact.countArtifactsByType(options.getType().get());
224+
count = Artifact.countArtifactsByType(type);
225225
} else if(engagementUuid.isPresent()) {
226226
count = Artifact.countArtifactsByEngagementUuid(engagementUuid.get());
227227
} else {

0 commit comments

Comments
 (0)