Giter Site home page Giter Site logo

Comments (4)

kcoleman-marklogic avatar kcoleman-marklogic commented on June 12, 2024
// Sample code demonstrating the bug. You'll need to tinker with the auth settings
package examples;
import java.io.File;

import com.marklogic.client.io.*;
import com.marklogic.client.io.DocumentMetadataHandle.DocumentCollections;
import com.marklogic.client.query.MatchDocumentSummary;
import com.marklogic.client.query.QueryManager;
import com.marklogic.client.query.StructuredQueryBuilder;
import com.marklogic.client.document.GenericDocumentManager;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.DocumentWriteSet;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClient;


public class Example {
    // replace with your MarkLogic Server connection information
    static String HOST = "localhost";
    static int PORT = 8003;
    static String USER = "user";
    static String PASSWORD = "password";
    static  DatabaseClient client = DatabaseClientFactory.newClient(
            HOST, PORT, 
            USER, PASSWORD, 
            DatabaseClientFactory.Authentication.DIGEST);

    /// An example of mixing various metadata sources in a bulk write,
    /// using document quality and collections.
    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);
        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()
                );
    }


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

from java-client-api.

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

Joe pointed out there's no status on this, which messes with the bugtrack integration, so I have set it to Fix.

from java-client-api.

sammefford avatar sammefford commented on June 12, 2024

Thanks, Kim. I added your code as a unit test and made a small fix so it works as expected: 00b604d

from java-client-api.

sravanr avatar sravanr commented on June 12, 2024

I have a test added to functional test suite.

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.