use of org.alfresco.repo.content.ContentContext in project SearchServices by Alfresco.
the class SolrContentStore method storeDocOnSolrContentStore.
/**
* Stores a {@link SolrInputDocument} into Alfresco solr content store.
* @param tenant
* @param dbId
* @param doc
* @throws IOException
*/
public void storeDocOnSolrContentStore(String tenant, long dbId, SolrInputDocument doc) throws IOException {
ContentContext contentContext = SolrContentUrlBuilder.start().add(SolrContentUrlBuilder.KEY_TENANT, tenant).add(SolrContentUrlBuilder.KEY_DB_ID, String.valueOf(dbId)).getContentContext();
this.delete(contentContext.getContentUrl());
ContentWriter writer = this.getWriter(contentContext);
if (log.isDebugEnabled()) {
log.debug("Writing doc to " + contentContext.getContentUrl());
}
try (OutputStream contentOutputStream = writer.getContentOutputStream();
// Compresses the document
GZIPOutputStream gzip = new GZIPOutputStream(contentOutputStream)) {
JavaBinCodec codec = new JavaBinCodec(resolver);
codec.marshal(doc, gzip);
} catch (Exception e) {
// A failure to write to the store is acceptable as long as it's logged
log.warn("Failed to write to store using URL: " + contentContext.getContentUrl(), e);
}
}
use of org.alfresco.repo.content.ContentContext in project SearchServices by Alfresco.
the class SolrContentStoreTest method contentByString.
@Test
public void contentByString() {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
ContentWriter writer = store.getWriter(ctx);
File file = new File(store.getRootLocation() + "/" + writer.getContentUrl().replace("solr://", ""));
Assert.assertFalse("File was created before anything was written", file.exists());
String content = "Quick brown fox jumps over the lazy dog.";
writer.putContent(content);
Assert.assertTrue("File was not created.", file.exists());
try {
writer.putContent("Should not work");
} catch (IllegalStateException e) {
// Expected
}
// Now get the reader
ContentReader reader = store.getReader(ctx.getContentUrl());
Assert.assertNotNull(reader);
Assert.assertTrue(reader.exists());
Assert.assertEquals(content, reader.getContentString());
}
use of org.alfresco.repo.content.ContentContext in project SearchServices by Alfresco.
the class SolrContentStoreTest method getWriter.
@Test
public void getWriter() {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
ContentWriter writer = store.getWriter(ctx);
String url = writer.getContentUrl();
Assert.assertNotNull(url);
Assert.assertEquals("URL of the context does not match the writer URL. ", ctx.getContentUrl(), url);
}
use of org.alfresco.repo.content.ContentContext in project SearchServices by Alfresco.
the class SolrContentStoreTest method delete.
@Test
public void delete() throws Exception {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
String url = ctx.getContentUrl();
ContentWriter writer = store.getWriter(ctx);
writer.putContent("Content goes here.");
// Check the reader
ContentReader reader = store.getReader(url);
Assert.assertNotNull(reader);
Assert.assertTrue(reader.exists());
// Delete
store.delete(url);
reader = store.getReader(url);
Assert.assertNotNull(reader);
Assert.assertFalse(reader.exists());
// Delete when already gone; should just not fail
store.delete(url);
}
use of org.alfresco.repo.content.ContentContext in project SearchServices by Alfresco.
the class SolrContentStoreTest method contentByStream.
@Test
public void contentByStream() throws Exception {
SolrContentStore store = new SolrContentStore(solrHome);
ContentContext ctx = createContentContext("abc");
ContentWriter writer = store.getWriter(ctx);
byte[] bytes = new byte[] { 1, 7, 13 };
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
writer.putContent(bis);
// Now get the reader
ContentReader reader = store.getReader(ctx.getContentUrl());
ByteArrayOutputStream bos = new ByteArrayOutputStream(3);
reader.getContent(bos);
Assert.assertEquals(bytes[0], bos.toByteArray()[0]);
Assert.assertEquals(bytes[1], bos.toByteArray()[1]);
Assert.assertEquals(bytes[2], bos.toByteArray()[2]);
}
Aggregations