-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: v2
Are you sure you want to change the base?
Conversation
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())) { |
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.
if (StringUtils.isNoneBlank(rapidProContact.getName())) { | |
if (StringUtils.isNotBlank(rapidProContact.getName())) { |
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.
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()); |
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.
Check for null on rapidProContact
.
DateTime now = DateTime.now(); | ||
event.setEventDate(now); | ||
event.setDateCreated(now); | ||
event.setBaseEntityId(rapidProContact.getUuid()); |
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.
Check for null rapidProContact
and event
... or use @nonnull
} | ||
|
||
protected String getVaccineSequence(ZeirVaccine vaccine) { | ||
String[] splitVaccine = vaccine.name().split("_"); |
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.
Check for null vaccine
... or use @nonnull
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.
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() |
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.
Check for null event
... or use @nonnull
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.
👍
} | ||
|
||
protected void addCommonClientProperties(Client client, RapidProContact rapidProContact) { | ||
RapidProFields fields = rapidProContact.getFields(); |
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.
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()); |
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 needed?
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.
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")) { |
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.
Move the string literal to constants.
} | ||
} | ||
catch (IOException exception) { | ||
logger.error(exception.getMessage(), exception.fillInStackTrace().toString()); |
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.
logger.error(exception.getMessage(), exception.fillInStackTrace().toString()); | |
logger.error(exception); |
} | ||
} | ||
catch (JSONException | IOException exception) { | ||
logger.error(exception.getMessage(), exception.fillInStackTrace().toString()); |
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.
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, |
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.
Move to string literal to constants.
Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
- Log RapidPro contacts with issues - Refactor code and loop through records for results which are limited to 25 records
@@ -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()) { |
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.
Revert this to an if to remove a possible l
Signed-off-by: Elly Kitoto <[email protected]>
…-core into rapidpro-refactor Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>
} | ||
} | ||
|
||
protected void addCriterion(String condition, Object value1, Object value2, String property) { |
Check notice
Code scanning / CodeQL
Useless parameter
} | ||
} | ||
|
||
protected void addCriterion(String condition, Object value, String property) { |
Check notice
Code scanning / CodeQL
Useless parameter
|
||
List<Event> convertContactToEvents(RapidProContact rapidProContact); | ||
|
||
RapidProContact convertEventToContact(Event event); |
Check notice
Code scanning / CodeQL
Useless parameter
} 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
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 |
87bf2a9
to
f431903
Compare
No description provided.