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

Refactor Rapidpro implementation on v2 #482

Open
wants to merge 150 commits into
base: v2
Choose a base branch
from
Open

Refactor Rapidpro implementation on v2 #482

wants to merge 150 commits into from

Conversation

ellykits
Copy link
Contributor

No description provided.

@ellykits ellykits changed the title Rapidpro service code refactor v2: Rapidpro service code refactor Jun 29, 2021
ellykits added 28 commits July 6, 2021 17:31
Implement project based service with callbacks
- Used Province, district and facility to obtain the actual location
id of the provider
Today's date is persisted in the app state token table for future
use.

When the listener will query contact it will use this date to
get all the contacts that were modified after the previous date.

In case an error occurs while saving the rapidpro contacts, the earliest
date modified will be used instead of today's date
- Use the facility location id to obtain the team information
The code will be used to uniquely identify the facility
client.addAttribute(RapidProConstants.IS_REGISTRATION_COMPLETE, false);
client.addAttribute(RapidProConstants.SYSTEM_OF_REGISTRATION, RapidProConstants.MVACC);
client.setDateCreated(DateTime.now());
if (StringUtils.isNoneBlank(rapidProContact.getName())) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (StringUtils.isNoneBlank(rapidProContact.getName())) {
if (StringUtils.isNotBlank(rapidProContact.getName())) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StringUtils.isNoneBlank is used also to exclude any white blank spaces

if (identifierSources != null && !identifierSources.isEmpty()) {
IdentifierSource identifierSource = identifierSources.get(0);
List<String> uniqueIds = uniqueIdentifierService
.generateIdentifiers(identifierSource, 1, rapidProContact.getFields().getSupervisorPhone());
Copy link
Member

Choose a reason for hiding this comment

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

Check for null on rapidProContact.

DateTime now = DateTime.now();
event.setEventDate(now);
event.setDateCreated(now);
event.setBaseEntityId(rapidProContact.getUuid());
Copy link
Member

Choose a reason for hiding this comment

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

Check for null rapidProContact and event ... or use @nonnull

}

protected String getVaccineSequence(ZeirVaccine vaccine) {
String[] splitVaccine = vaccine.name().split("_");
Copy link
Member

Choose a reason for hiding this comment

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

Check for null vaccine ... or use @nonnull

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ZeirVaccine is an enum so can never be null. But I have added extra check (@NonNull) annotation

}

public String readObsValue(Event event, String formSubmissionField) {
Optional<Obs> optionalObs = event.getObs().stream()
Copy link
Member

Choose a reason for hiding this comment

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

Check for null event ... or use @nonnull

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}

protected void addCommonClientProperties(Client client, RapidProContact rapidProContact) {
RapidProFields fields = rapidProContact.getFields();
Copy link
Member

Choose a reason for hiding this comment

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

Check for null rapidProContact and event ... or use @nonnull

}
}
}
logger.warn("Synced all {} record(s) of type {} from OpenSRP to RapidPro", unSyncedStates.size(), entity.name());
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's needed.

String group = entity == CHILD ? RapidProConstants.CHILDREN : RapidProConstants.CARETAKERS;
payload.put(RapidProConstants.GROUP, group);
try (CloseableHttpResponse httpResponse = postToRapidPro(payload.toString(),
RapidProUtils.getBaseUrl(rapidProUrl) + "/contact_actions.json")) {
Copy link
Member

Choose a reason for hiding this comment

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

Move the string literal to constants.

}
}
catch (IOException exception) {
logger.error(exception.getMessage(), exception.fillInStackTrace().toString());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.error(exception.getMessage(), exception.fillInStackTrace().toString());
logger.error(exception);

}
}
catch (JSONException | IOException exception) {
logger.error(exception.getMessage(), exception.fillInStackTrace().toString());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.error(exception.getMessage(), exception.fillInStackTrace().toString());
logger.error(exception);

}

public static HttpGet contactByPhoneRequest(String phone, String rapidProUrl, String rapidProToken) {
return (HttpGet) setupRapidproRequest(getBaseUrl(rapidProUrl) + "/contacts.json?urn=tel:" + phone,
Copy link
Member

Choose a reason for hiding this comment

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

Move to string literal to constants.

@@ -401,7 +400,7 @@ private void updateContactFields(ZeirRapidProEntity entity, ZeirRapidProEntityPr
.limit(RapidProUtils.RAPIDPRO_DATA_LIMIT).collect(Collectors.toList());
ZeirChildClientConverter childConverter = new ZeirChildClientConverter(this);
ZeirMotherClientConverter motherConverter = new ZeirMotherClientConverter();
if (!unSyncedStates.isEmpty()) {
while (!unSyncedStates.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this to an if to remove a possible l

@ellykits ellykits changed the title v2: Rapidpro service code refactor Refactor Rapidpro implementation on v2 Jan 19, 2023
}
}

protected void addCriterion(String condition, Object value1, Object value2, String property) {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'property' is never used.
}
}

protected void addCriterion(String condition, Object value, String property) {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'property' is never used.

List<Event> convertContactToEvents(RapidProContact rapidProContact);

RapidProContact convertEventToContact(Event event);

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'event' is never used.
} else {
String lastItem = splitVaccine[splitVaccine.length - 1];
if (StringUtils.isNumeric(lastItem)) {
return String.valueOf(Integer.parseInt(lastItem) + 1);

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException

Potential uncaught 'java.lang.NumberFormatException'.
@ndegwamartin
Copy link
Contributor

This fix might need to await a patch from Spring given there's LTS support for Spring 5.3 till late in 2024 https://endoflife.date/spring-framework.

@ndegwamartin
Copy link
Contributor

ndegwamartin commented Mar 9, 2023

This fix might need to await a patch from Spring given there's LTS support for Spring 5.3 till late in 2024 https://endoflife.date/spring-framework.

Tracked here #619

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.

8 participants