-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(web): Convert web module to Java #841
Conversation
return serviceAccountDAO.all(); | ||
} | ||
|
||
ServiceAccount createServiceAccount(ServiceAccount serviceAccount) { | ||
public ServiceAccount createServiceAccount(ServiceAccount serviceAccount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two methods were being accessed despite being out of scope.
@@ -36,6 +36,7 @@ dependencies { | |||
implementation "org.springframework.boot:spring-boot-starter-actuator" | |||
implementation "com.netflix.spinnaker.fiat:fiat-api:$fiatVersion" | |||
implementation "com.netflix.spinnaker.fiat:fiat-core:$fiatVersion" | |||
implementation "com.netflix.spinnaker.kork:kork-artifacts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Groovy was referencing artifacts it didn't have access to.
UntypedUtils.setProperty(notification, it, UntypedUtils.getProperty(global, it)); | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajordens Here's the global notifications. Maybe we can delete?
(a, b) -> | ||
SearchUtils.score(b, normalizedAttributes) | ||
- SearchUtils.score(a, normalizedAttributes)) | ||
.collect(Collectors.toCollection(LinkedHashSet::new)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I broke this monstrosity up into a few blocks and methods. I'm happy to break it up further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes... but yeah it looks like you captured the original essencé d'groovy - nice job
if (!UntypedUtils.hasProperty(notification, it)) { | ||
UntypedUtils.setProperty(notification, it, new ArrayList<>()); | ||
} | ||
UntypedUtils.setProperty(notification, it, UntypedUtils.getProperty(global, it)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be:
UntypedUtils.setProperty(notification, it, UntypedUtils.getProperty(global, it)); | |
((List<?>) UntypedUtils.getProperty(notification, it)).addAll((List<?>) UntypedUtils.getProperty(global, it))); |
Otherwise it will replace the list instead of adding to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Right you are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! 💯 🏅 🏆 ☕
|
||
Set<Application> results = | ||
new HashSet<>( | ||
pageSize == null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ternary looks inverted
@RequestParam(value = "prefix", required = false) final String prefix, | ||
@RequestParam(value = "ids", required = false) Collection<String> ids, | ||
@RequestParam(value = "refresh", required = false) Boolean refresh) { | ||
if (prefix == null && (ids != null && !ids.isEmpty())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be incorrect; we'll throw an exception here if prefix == null
but ids
is a non-empty collection. Should this be prefix == null && ( ids == null || ids.isEmpty())
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we do the same check on ids
later too, maybe we should just do an Optional.ofNullable(ids).orElseGet(ArrayList::new)
at the beginning to simplify 🤷
@RequestParam(value = "pageSize", required = false) Integer pageSize, | ||
@RequestParam Map<String, String> params) { | ||
params.remove("pageSize"); | ||
Set<Project> projects = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cast safe? Seems like we should either have the interface .all()
return a Set
or convert the result of projectDao.all()
to a Set
instead of just casting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntelliJ didn't complain about it so I figured it would be OK, but I've wrapped projectDAO.all()
into new HashSet<>(projectDAO.all())
to be safe. Since all()
is defined by ItemDAO<T>
, I'm not comfortable in changing the signature of the method without affecting other places.
COMMA_SPLITTER.splitToList(normalizedAttributes.get("applications")); | ||
// TODO(rz): LOL converting Groovy with elvis operators everywhere. :grimacing: | ||
// Do you know what's going on here? I certainly don't. Good thing there's tests? | ||
items = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😭
new FuzzySearch(project, it.getKey(), it.getValue())))) | ||
.collect(Collectors.toSet())); | ||
|
||
return new TreeSet<>(items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to make a TreeSet
here instead of just doing items.stream()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature was a Set
, although I don't know why. The code was doing sorting on it, so I needed some implementation of SortedSet
, which landed me on TreeSet
- maybe this is the wrong implementation.
Alternatively I could change all of this to a List
and just distinct
on the stream before doing the sort? Kinda like this instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I totally understand the result being a LinkedHashSet
as we do seem to need it sorted...though I kind of like your idea better of making it a List
with distinct
.
I meant more that I think the following would be equivalent:
items.stream().sort()
new TreeSet<>(items).stream().sort()
so I wasn't sure it was wrapped right before calling .stream()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh boy, yeah ok, now I see what you're saying I missed the LinkedHashSet
🤦 .
This is now a List.
if (p1.getIndex() == null && p2.getIndex() != null) { | ||
return 1; | ||
} | ||
if (!p1.getIndex().equals(p2.getIndex())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this introduces a new NPE if both indexes are null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha. Right you are. I guess this NPE has existed since... 2014. Will fix, good catch.
@PathVariable(value = "application") String application, | ||
@RequestParam(required = false, value = "refresh", defaultValue = "true") boolean refresh) { | ||
List<Pipeline> pipelines = | ||
(List<Pipeline>) pipelineDAO.getPipelinesByApplication(application, refresh); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cast safe? If all implementations really do return this as a List
should we change the type on the interface? If not should we create a list from the collection here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to changing the interface to a list, but I think I'll try evaluating / taking that on as part of a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had one comment that I think is different behavior but otherwise LGTM, thanks again for doing this
can we update any of the gradle builds to disable the compileGroovy task for the modules that have been cut over at this point?
@cfieber Taking a pass to remove |
06f7863
to
4a4fe18
Compare
Thank you for the fix in Application create to actually check if fiat is enabled before attempting to make the role/sync call! Yet another reason to upgrade to 1.21! |
When you're on a roll, you're on a roll.
This is the entire module.