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

Migrate to new group id - rebase #1214

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open

Conversation

Altonss
Copy link
Contributor

@Altonss Altonss commented Feb 7, 2023

This PR solves #1045

Altonss and others added 30 commits February 7, 2023 19:00
Add ID column to tmpDbGroups
Move to group.name in DatabaseTest.java
Migrate to group.name in DatabaseTest.java
@Altonss Altonss mentioned this pull request Feb 7, 2023
@Altonss
Copy link
Contributor Author

Altonss commented Feb 7, 2023

I must have done something wrong, but now the tests are failing :( ping @TheLastProject

@TheLastProject
Copy link
Member

I found the reason behind a few of the failing tests. Not all yet, there's some database constraint that are failing. Need to look at that still.

@Altonss
Copy link
Contributor Author

Altonss commented Feb 14, 2023

I found the reason behind a few of the failing tests. Not all yet, there's some database constraint that are failing. Need to look at that still.

Thanks a lot for the help! Now it only fails at ImportExport at 2 places...

List<Group> cardGroups = DBHelper.getLoyaltyCardGroups(database, cardId);

Integer groupId = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIdsGroups.groupID, record, false);
cardGroups.add(DBHelper.getGroup(database, groupId));
Copy link
Member

@TheLastProject TheLastProject Mar 8, 2023

Choose a reason for hiding this comment

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

Finally figuring out why one of the tests is failing.

For one of the unit tests, this adds an entry to cardGroups with value null, causing a NullPointerException in setLoyaltyCardGroups.

This is because DBHelper.getGroup() has 0 results for groupId 1.

I'm not quite sure yet why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for figuring this out! Hmm I don't know why either... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is maybe importCardGroupMappingV2 used instead of importCardGroupMappingV3, which defaults to null if no string found?

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like it, the failure happens in importCardGroupMappingV3. It's the multipleCardsExportImportWithGroups test failing.

E/Catima: Failed to import data
java.lang.NullPointerException
	at protect.card_locker.DBHelper.setLoyaltyCardGroups(DBHelper.java:641)
	at protect.card_locker.importexport.CatimaImporter.importCardGroupMappingV3(CatimaImporter.java:540)
	at protect.card_locker.importexport.CatimaImporter.parseV3CardGroups(CatimaImporter.java:361)
	at protect.card_locker.importexport.CatimaImporter.parseV3(CatimaImporter.java:211)
	at protect.card_locker.importexport.CatimaImporter.importCSV(CatimaImporter.java:88)
	at protect.card_locker.importexport.CatimaImporter.importData(CatimaImporter.java:59)
	at protect.card_locker.importexport.MultiFormatImporter.importData(MultiFormatImporter.java:47)
	at protect.card_locker.ImportExportTest.multipleCardsExportImportWithGroups(ImportExportTest.java:468)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:580)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$2(SandboxTestRunner.java:287)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:99)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

bundle.putString(LoyaltyCardEditActivity.BUNDLE_ADDGROUP, groupsTabLayout.getTabAt(selectedTab).getText().toString());
TabLayout.Tab tab = groupsTabLayout.getTabAt(selectedTab);
if (tab != null) {
Group group = (Group) groupsTabLayout.getTabAt(selectedTab).getTag();
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I missing something here or was this unnecessary duplication?

Suggested change
Group group = (Group) groupsTabLayout.getTabAt(selectedTab).getTag();
Group group = (Group) tab.getTag();


DBHelper.insertGroup(database, id);
/**
* Import a single group from the V3 scheme (database v16) into the database using the given
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that v17?

List<Group> cardGroups = DBHelper.getLoyaltyCardGroups(database, cardId);

Integer groupId = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIdsGroups.groupID, record, false);
cardGroups.add(DBHelper.getGroup(database, groupId));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not 100% sure this is correct, but it makes the tests pass.

Suggested change
cardGroups.add(DBHelper.getGroup(database, groupId));
cardGroups.add(DBHelper.getGroupByName(database, groupsTable.get(groupId)));

Copy link
Contributor

Choose a reason for hiding this comment

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

Also not sure how importing works. Does it keep existing cards and groups? If so does this handle conflicting IDs between existing data and the exported data?

Copy link
Contributor

@obfusk obfusk May 31, 2023

Choose a reason for hiding this comment

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

Might be better to have a DBHelper.insertGroup(database, id, name) to be used in importGroupV3() to insert a group with a specific ID.

@obfusk obfusk mentioned this pull request Jun 1, 2023
12 tasks
@obfusk
Copy link
Contributor

obfusk commented Jun 1, 2023

@Altonss @TheLastProject I opened #1333 based on this PR.

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.

3 participants