Skip to content
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

Issue/3167 filter app datapoints (Connect #3167) #3196

Merged
merged 10 commits into from
Oct 1, 2019

Conversation

stellanl
Copy link
Contributor

@stellanl stellanl commented Sep 23, 2019

Before the PR (what is the issue or what needed to be done)

No way for app to get only assigned data points.

The solution

Add a new endpoint with modern names.
Moved most of the old endpoint (SurveyedLocaleServlet) methods to the new service (DataPointServlet) and share them.

Screenshots (if appropriate)

Checklist

  • Connect the issue
  • Test plan
  • Copyright header
  • Code formatting
  • Documentation

@stellanl stellanl requested a review from muloem September 23, 2019 12:58
return resp;
}

private List<SurveyedLocaleDto> getSurveyedLocaleDtosList(List<SurveyedLocale> slList,
Long surveyGroupId) {
protected static List<SurveyedLocaleDto> getSurveyedLocaleDtosList(List<SurveyedLocale> slList, Long surveyId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why is this method static?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I understood why, see my comment below why I may suggest to do it differently.


package org.akvo.flow.api.app;

import java.util.Date;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be unused

resp.setCode(String.valueOf(HttpServletResponse.SC_OK));
resp.setResultCount(slList.size());

List<SurveyedLocaleDto> dtoList = DataPointServlet.getSurveyedLocaleDtosList(slList, surveyId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, there should be another class/classes containing methods used by both servlets. This will help have smaller classes and avoid static methods which are harder to test.

Copy link
Contributor Author

@stellanl stellanl Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Just expected the old servlet would be removed soon. Why are these methods harder to test when static? They don't have any side effects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing tests one usually initialize to class to test with a constructor but of course there are tools like powermock and then static classes methods can also be tested. So there could be a static utility class with utility methods but it seems unusual to me that a servlet calls another one. If you decide to remove the other servlet, then the methods would not need to be static any more. Also what disturbs me a bit is that DataPointServlet is used both with static methods and instantiated via constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to sum up: if they are only utility methods -> we can move them to a static utility class, I guess in this case this would require less rework and makes sense. I still think they are not exactly utility classes since they access the database and read data and in this case if we wanted to mock some responses for them, they should be made into an object with constructor but it would require a change in architecture so maybe not needed right now.

@stellanl stellanl merged commit 699fe60 into develop Oct 1, 2019
@stellanl stellanl deleted the issue/3167-filter-app-datapoints branch October 1, 2019 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants