Search in sources :

Example 6 with ContentContext

use of org.alfresco.repo.content.ContentContext in project SearchServices by Alfresco.

the class SolrContentStoreTest method exampleUsage.

/**
 * A demonstration of how the store might be used.
 */
@Test
public void exampleUsage() {
    SolrContentStore store = new SolrContentStore(solrHome);
    String tenant = "alfresco.com";
    long dbId = 12345;
    String otherData = "sdfklsfdl";
    ContentContext ctxWrite = SolrContentUrlBuilder.start().add(SolrContentUrlBuilder.KEY_DB_ID, String.valueOf(dbId)).add(SolrContentUrlBuilder.KEY_TENANT, tenant).add("otherData", otherData).getContentContext();
    ContentWriter writer = store.getWriter(ctxWrite);
    writer.putContent("a document in plain text");
    // The URL can be reliably rebuilt in any order
    String urlRead = SolrContentUrlBuilder.start().add("otherData", otherData).add(SolrContentUrlBuilder.KEY_TENANT, tenant).add(SolrContentUrlBuilder.KEY_DB_ID, String.valueOf(dbId)).get();
    ContentReader reader = store.getReader(urlRead);
    String documentText = reader.getContentString();
    Assert.assertEquals("a document in plain text", documentText);
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentContext(org.alfresco.repo.content.ContentContext) Test(org.junit.Test)

Aggregations

ContentContext (org.alfresco.repo.content.ContentContext)6 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)6 Test (org.junit.Test)5 ContentReader (org.alfresco.service.cmr.repository.ContentReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)1 JavaBinCodec (org.apache.solr.common.util.JavaBinCodec)1