klehmann / domino-jna

Java project to access the IBM/HCL Domino C API using Java Native Access (JNA)
Apache License 2.0
66 stars 16 forks source link

Wrong results when getting entries in a category #64

Closed markleusink closed 3 years ago

markleusink commented 3 years ago

Hi Karsten,

I have a categorized view. One of the categories is named SKIBSVÆRFT B/C. So it has the Æ character and a slash in it.

When I use JNA to get the entries in that category I get the wrong results when using one of the getXXInCategory() functions. Tested it with v0.42:

The standard API also returns the correct results when I use createViewNavFromCategory()

Is this a bug? Or am I doing something wrong?

klehmann commented 3 years ago

Hi Mark! I cannot reproduce the issue here. I created a view with one category column and another sorted (also tried unsorted) column. This test case returns data:

    @Test
    public void testGetCatIds() {
        runWithSession(new IDominoCallable<Object>() {

            @Override
            public Object call(Session session) throws Exception {
                NotesDatabase db = new NotesDatabase("Server1/Mindoo", "test/categorylookuptest.nsf", "");
                NotesCollection col = db.openCollectionByName("view1");
                LinkedHashSet<Integer> ids = col.getAllIdsInCategory("SKIBSVÆRFT B/C", EnumSet.of(Navigate.NEXT_NONCATEGORY));
                assertTrue(!ids.isEmpty());
                System.out.println("IDs:\n");
                for (Integer currId : ids) {
                    System.out.println(currId);
                }

                List<NotesViewEntryData> entries = col.getAllEntriesInCategory("SKIBSVÆRFT B/C", 0, EnumSet.of(Navigate.NEXT_NONCATEGORY), Integer.MAX_VALUE,
                        EnumSet.of(ReadMask.NOTEID, ReadMask.SUMMARYVALUES), new NotesCollection.EntriesAsListCallback(Integer.MAX_VALUE));
                assertTrue(!entries.isEmpty());
                for (NotesViewEntryData currEntry : entries) {
                    System.out.println(currEntry.getNoteId() + " - " + currEntry.getColumnDataAsMap());
                }

                return null;
            }
        });

    }

What are your exact parameter values and can you send me a sample DB?

markleusink commented 3 years ago

Did some more testing too: created a new database and created some documents with that value as the category name. When I run the code against that database everything is fine.

So there must be something different with the original set of documents. I'll investigate more. Will let you know when I found the cause.

klehmann commented 3 years ago

Where does the string "SKIBSVÆRFT B/C" come from? Is it stored in class files as constant? I had issues with German Umlauts for strings stored in class files of my Eclipse plugins and then added

javacDefaultEncoding..=UTF-8

to my build.properties file so that the class files get created with the right encoding.

markleusink commented 3 years ago

The string was part of the HTTP request so that wasn't the problem here (well it was at first, because it wasn't encoded properly, but that was fixed already).

Looks like my debugging code was part of the issue. I added some code to check what the standard Java API was returning. But that code is called after the NotesDatabase / NotesCollection objects are set. Subsequent calls to getAllEntriesInCategory / getAllIdsInCategory calls will then return 0.

String category = "SKIBSVÆRFT B/C";

NotesDatabase db = new NotesDatabase(ExtLibUtil.getCurrentSession(), "", "why.nsf");
NotesCollection colCategoryData = db.openCollectionByName("vwProspects");

int a = ExtLibUtil.getCurrentSession().getDatabase("", "why.nsf").getView("vwProspects").createViewNavFromCategory(category).getCount();
data.put("createViewNavFromCategory", a);

List<Map<String, Object>> b = colCategoryData.getAllEntriesInCategory(
            category, 1, EnumSet.of(Navigate.NEXT),
            Integer.MAX_VALUE,
            EnumSet.of(ReadMask.SUMMARYVALUES),
            new ViewLookupCallback(Integer.MAX_VALUE)) ;
data.put("getAllEntriesInCategory", b.size());

Set<Integer> c = colCategoryData.getAllIdsInCategory(category,  EnumSet.of(Navigate.NEXT));
data.put("getAllIdsInCategory", c.size());

Set<Integer> d = colCategoryData.getAllIdsByKey(EnumSet.of(Find.EQUAL), category);
data.put("getAllIdsByKey", d.size());`

If I disable rows 4 & 5 everything works fine.

I think I'll quickly forget about this issue :-( Thanks for your help!

klehmann commented 3 years ago

That's weird. Those lines should not have any side effects because the C API objects have different handles and the collection/view is not reused.

markleusink commented 3 years ago

Just tested it again, but the result is the same. Environment: JNA 0.42, Domino 10.0.1FP3, Windows. ODA 10.0.1 is also installed.

This returns the correct entries:

NotesDatabase dbProspects = new NotesDatabase(ExtLibUtil.getCurrentSession(), "", dbPath);
NotesCollection colCategoryData = dbProspects.openCollectionByName(viewName);

List<Map<String, Object>> res = colCategoryData.getAllEntriesInCategory(
    category, 1, EnumSet.of(Navigate.NEXT),
    Integer.MAX_VALUE,
    EnumSet.of(ReadMask.SUMMARYVALUES),
    new ViewLookupCallback(Integer.MAX_VALUE));

And this returns 0 entries for the getAllEntriesInCategory call and the correct entries for the createViewNavFromCategory call:

NotesDatabase dbProspects = new NotesDatabase(ExtLibUtil.getCurrentSession(), "", dbPath);
NotesCollection colCategoryData = dbProspects.openCollectionByName(viewName);

lotus.domino.Database db = ExtLibUtil.getCurrentSession().getDatabase("", dbPath);
lotus.domino.View vw = db.getView(viewName);
lotus.domino.ViewNavigator nav = vw.createViewNavFromCategory(category);

NotesDatabase dbProspects = new NotesDatabase(ExtLibUtil.getCurrentSession(), "", dbPath);
NotesCollection colCategoryData = dbProspects.openCollectionByName(viewName);

List<Map<String, Object>> res = colCategoryData.getAllEntriesInCategory(
    category, 1, EnumSet.of(Navigate.NEXT),
    Integer.MAX_VALUE,
    EnumSet.of(ReadMask.SUMMARYVALUES),
    new ViewLookupCallback(Integer.MAX_VALUE));

(I used the lotus.domino package to make sure that ODA isn't interfering)

It's nog a big issue, as long as I'm aware of it.