Giter Site home page Giter Site logo

Comments (5)

kcoleman-marklogic avatar kcoleman-marklogic commented on June 12, 2024
// Sample code that demonstrates the problem:
package examples;

import com.marklogic.client.io.*;
import com.marklogic.client.document.DocumentPage;
import com.marklogic.client.document.DocumentRecord;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.DocumentManager.Metadata;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClient;


public class standalone {
    // replace with your MarkLogic Server connection information
    static String HOST = "kim-3.marklogic.com";
    static int PORT = 8003;
    static String USER = "admin";
    static String PASSWORD = "adm1n";
    static  DatabaseClient client = DatabaseClientFactory.newClient(
            HOST, PORT, 
            USER, PASSWORD, 
            DatabaseClientFactory.Authentication.DIGEST);

    public static void example2() { 
        JSONDocumentManager jdm = client.newJSONDocumentManager();
        jdm.setMetadataCategories(Metadata.QUALITY);
        DocumentPage documents = jdm.read("doc1.json", "doc2.json", "doc3.json");
        while (documents.hasNext()) {
            DocumentRecord document = documents.next();
            System.out.print(document.getUri() + ": ");
//          StringHandle content = document.getContent(new StringHandle());
            DocumentMetadataHandle metadata = document.getMetadata(new DocumentMetadataHandle());
            System.out.println(document.getUri() + ": " + metadata.getQuality());
//          System.out.println(content.toString());
        }
    }   


    public static void main(String[] args) {
        example2();
    }
}

from java-client-api.

kcoleman-marklogic avatar kcoleman-marklogic commented on June 12, 2024

p.s. I forgot to say, it should be reproducible with any documents, but I had inserted mine with the following function, which you can probably drop into the same package and run, +/- an import or two.

    public static void exampleA() {
        // Synthesize input content
        StringHandle doc1 = new StringHandle(
                "{\"number\": 1}").withFormat(Format.JSON);
        StringHandle doc2 = new StringHandle(
                "{\"number\": 2}").withFormat(Format.JSON);
        StringHandle doc3 = new StringHandle(
                "{\"number\": 3}").withFormat(Format.JSON);
        StringHandle doc4 = new StringHandle(
                "{\"number\": 4}").withFormat(Format.JSON);
        StringHandle doc5 = new StringHandle(
                "{\"number\": 5}").withFormat(Format.JSON);

        // Synthesize input metadata
        DocumentMetadataHandle defaultMetadata1 = 
                new DocumentMetadataHandle().withQuality(1);
        DocumentMetadataHandle defaultMetadata2 = 
                new DocumentMetadataHandle().withQuality(2);
        DocumentMetadataHandle docSpecificMetadata = 
                new DocumentMetadataHandle().withCollections("myCollection");

        // Create and build up the batch
        JSONDocumentManager jdm = client.newJSONDocumentManager();
        DocumentWriteSet batch = jdm.newWriteSet();

        // use system default metadata
        batch.add("doc1.json", doc1);       // system default metadata

        // using batch default metadata
        batch.addDefault(defaultMetadata1);  // XXX this needs a name change
        batch.add("doc2.json", doc2);       // batch default metadata
        batch.add("doc3.json", docSpecificMetadata, doc3); // XXX add back when bug fixed
        batch.add("doc4.json", doc4);       // batch default metadata

        // replace batch default metadata with new metadata
        batch.addDefault(defaultMetadata2); // XXX this needs a name change
        batch.add("doc5.json", doc5);       // batch default 

        // Execute the write operation
        jdm.write(batch);

        // Check the results
        // Doc1 should have the system default quality of 0
        System.out.println("doc1 quality: Expected=0, Actual=" + 
                jdm.readMetadata("doc1.json", new DocumentMetadataHandle()).getQuality()
                );
        // Doc2 should use the first batch default metadata, with quality 1
        System.out.println("doc2 quality: Expected=" +
                defaultMetadata1.getQuality() + ", Actual=" + 
                jdm.readMetadata("doc2.json", new DocumentMetadataHandle()).getQuality()
                );

        // Doc3 should have the system default document quality (0) because quality
        // was not included in the document-specific metadata. It should be in the
        // collection "myCollection", from the document-specific metadata.
        DocumentMetadataHandle doc3Metadata =  
                jdm.readMetadata("doc3.json", new DocumentMetadataHandle());
        System.out.println("doc3 quality: Expected=0, Actual=" + doc3Metadata.getQuality());
        System.out.print("doc3 collections: Expected: myCollection, Actual=");
        for (String collection : doc3Metadata.getCollections()) {
            System.out.print(collection + " ");
        }
        System.out.println();

        // Doc 4 should also use the 1st batch default metadata, with quality 1
        System.out.println("doc4 quality: Expected=" +
                defaultMetadata1.getQuality() + ", Actual=" + 
                jdm.readMetadata("doc4.json", new DocumentMetadataHandle()).getQuality()
                );
        // Doc5 should use the 2nd batch default metadata, with quality 2
        System.out.println("doc5 quality: Expected=" + 
                defaultMetadata2.getQuality() + ", Actual=" + 
                jdm.readMetadata("doc5.json", new DocumentMetadataHandle()).getQuality()
                );
    }

from java-client-api.

kcoleman-marklogic avatar kcoleman-marklogic commented on June 12, 2024

Gah, lunchtime food coma. Sorry. THIS REST request:

curl --anyauth --user admin:adm1n -H "Accept: multipart/mixed; boundary=BOUNDARY" -X GET http://localhost:8003/v1/documents?uri=doc1.json&uri=doc2.json&uri=doc3.json&category=quality

(The one in the original problem description was missing Accept headers).

from java-client-api.

kcoleman-marklogic avatar kcoleman-marklogic commented on June 12, 2024

Set status to Fix on behalf of bugtrack integration.

Should this still be assigned to Charles now that Sam is back? For some reason, I actually thought this had been fixed, though I haven't tried it to confirm.

from java-client-api.

sravanr avatar sravanr commented on June 12, 2024

Verified

from java-client-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.