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

DDP-5826-filling the kit history from files #187

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

pegahtah
Copy link
Contributor

No description provided.

import static org.broadinstitute.dsm.TestHelper.setupDB;
import static org.broadinstitute.dsm.util.tools.TbosUPSKitTool.readFile;

public class UPSKitToolTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this class to test the methods I made in the migatioonTool

"left join ups_package pack on (ship.ups_shipment_id = pack.ups_shipment_id) " +
"where kit.dsm_kit_request_id = ? and pack.tracking_number = ?";

public static Map readFile(String fileName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

method to read the kits for the participant and build a HashMap

int kitCounter = 0;
for (; kitCounter < kits.size(); kitCounter++) {
Kit kit = kits.get(kitCounter);
Kit outboundKit = getDDBKitBasedOnKitLabel(SQL_SELECT_KIT_BY_KIT_LABEL + SQL_SELECT_OUTBOUND, kit.getKitLabel(), ddpInstance.getDdpInstanceId());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Find the kit info in the DB, so we can find the tracking numbers and also see if there is already activity info for the kit in db

}
}

public static String decideWhatToInsertForKit(Kit fileKit, Kit dbKit, boolean isRetrun) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method decides what activities from the file is missing in DSM database, if a kit doesn't have any any activity, it inserts all that it is in the file

String insertedShipmentId = null;
if (StringUtils.isBlank(dbKit.getLastActivityDesc())) {//insert everything if the kit doesn't have any shipments in bd
logger.info("Inserting Shipment, Package and all activities for kit " + fileKit.getKitLabel());
insertedShipmentId = insertKitInDB(fileKit, isRetrun);//most of the kits should end up here
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if a kit has no activity in ups_activity, then we must insert all

String firstActivityTime = isRetrun ? fileKit.getPickedUpAt() : fileKit.getShippedAt();
String lastActivityTime = isRetrun ? fileKit.getReceivedAt() : fileKit.getDeliveredAt();
if (StringUtils.isNotBlank(firstActivityTime)) {
if (shouldInsertBasedOnTimeForKit(dbKit, firstActivityTime)) {//last activity in DB is before the shipped at
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, it checks what is the latest activity in the db for the kit, and if the activity in the file is later than the one we have in the db, then we insert the one in the file. This is because when UPSJob was ran the first time, it inserted every available activity for the all of the valid and not delivered tracking numbers, so if the latest activity we have in db is older than the ones in file, activities before that should also be already in db

return insertedShipmentId;
}

public static boolean shouldInsertBasedOnTimeForKit(@NonNull Kit dbKit, String utcDateTimeString) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

converts the UTC time in the CSV file and compares it with the EST time in the DB

TbosUPSKitTool.littleMain(fileName);
}

private static void littleMain(String fileName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the method that we should call when we want to run this

@pegahtah pegahtah requested a review from SimoneMaiwald May 23, 2021 14:51
@pegahtah pegahtah changed the title DDP-5826 DDP-5826-filling the kit history from files May 25, 2021
@SimoneMaiwald
Copy link
Collaborator

can we close that one?

1 similar comment
@SimoneMaiwald
Copy link
Collaborator

can we close that one?

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