@Override public AbstractWriteHandle getHandle() { // TODO: maybe serialize plan to JSON using JSON writer? return new StringHandle(getAst()).withFormat(Format.JSON); }
@Override public void executeUpdate(SPARQLQueryDefinition qdef) { executeQueryImpl(qdef, (TriplesReadHandle) new StringHandle().withFormat(Format.JSON), null, true); }
private void patchRecord(String docId, String docContent) { StringHandle patchHandle = new StringHandle(docContent); if (MarkLogicOutputProperties.DocType.JSON == docType) { patchHandle.withFormat(Format.JSON); } else if (MarkLogicOutputProperties.DocType.XML == docType) { patchHandle.withFormat(Format.XML); } else { throw new MarkLogicException(new MarkLogicErrorCode("Cant patch for docType " + docType)); } docMgr.patch(docId, patchHandle); }
private void patchRecord(String docId, String docContent) { StringHandle patchHandle = new StringHandle(docContent); if (MarkLogicOutputProperties.DocType.JSON == docType) { patchHandle.withFormat(Format.JSON); } else if (MarkLogicOutputProperties.DocType.XML == docType) { patchHandle.withFormat(Format.XML); } else { throw new MarkLogicException(new MarkLogicErrorCode("Cant patch for docType " + docType)); } docMgr.patch(docId, patchHandle); }
@Override public PojoQueryDefinition filteredQuery(StructuredQueryDefinition query) { CombinedQueryBuilder cqb = new CombinedQueryBuilderImpl(); StringHandle options = new StringHandle( "<options><search-option>filtered</search-option></options>") .withFormat(Format.XML); return cqb.combine(query, options); }
@Override public DocumentWriteSet disableDefault() { add(new DocumentWriteOperationImpl(OperationType.DISABLE_METADATA_DEFAULT, null, new StringHandle("{ }").withFormat(Format.JSON), null)); return this; }
@Override public void enable() { RequestParameters params = new RequestParameters(); params.add("enable", "true"); this.getServices().post(params, new StringHandle("{}").withFormat(Format.JSON)); }
@Override public void enable() { RequestParameters params = new RequestParameters(); params.add("enable", "true"); this.getServices().post(params, new StringHandle("{}").withFormat(Format.JSON)); }
@Override public void disable() { RequestParameters params = new RequestParameters(); params.add("enable", "false"); this.getServices().post(params, new StringHandle("{}").withFormat(Format.JSON)); }
@Override public void disable() { RequestParameters params = new RequestParameters(); params.add("enable", "false"); this.getServices().post(params, new StringHandle("{}").withFormat(Format.JSON)); }
public QueryOptionsWriteHandle buildOptions() throws UnsupportedEncodingException, XMLStreamException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeOptions(makeXMLStreamWriter(baos)); return new StringHandle(baos.toString("UTF-8")).withFormat(Format.XML); }
public void writeXQueryTransform(TransformExtensionsManager extensionMgr) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { extensionMgr.writeXQueryTransform( XQUERY_NAME, new StringHandle().withFormat(Format.TEXT).with(xqueryTransform), makeXQueryMetadata() ); } public void writeXSLTransform(TransformExtensionsManager extensionMgr)
public void writeXSLTransform(TransformExtensionsManager extensionMgr) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { extensionMgr.writeXSLTransform( XSLT_NAME, new StringHandle().withFormat(Format.XML).withMimetype("application/xslt+xml").with(xslTransform), makeXSLTMetadata() ); } }
@Test public void testJSON() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.term("leaf3"); // create a handle for the search results StringHandle resultsHandle = new StringHandle().withFormat(Format.JSON); // run the search queryMgr.search(t, resultsHandle); assertEquals("{", resultsHandle.get().substring(0, 1)); // It's JSON, right? }
@Test public void testWriteInvalidXMLAndThrowException() { String directory = "/WriteBatcherTest/testWriteInvalidXMLAndThrowException/"; DocumentWriteSet writeSet = client.newDocumentManager().newWriteSet(); writeSet.add(directory + uri5, new StringHandle("this is not valid XML").withFormat(Format.XML)); testExceptions(writeSet, 0, 1); }
@Test public void testWriteValidAndInvalidDocsAndThrowException() { String directory = "/WriteBatcherTest/testWriteValidAndInvalidDocsAndThrowException/"; DocumentWriteSet writeSet = client.newDocumentManager().newWriteSet(); writeSet.add(directory + uri1, new StringHandle("test")); writeSet.add(directory + uri5, new StringHandle("this is not valid XML").withFormat(Format.XML)); writeSet.add(directory + uri2, new StringHandle("test")); writeSet.add(directory + uri5, new StringHandle("this is not valid XML").withFormat(Format.XML)); writeSet.add(directory + uri3, new StringHandle("test")); testExceptions(writeSet, 3, 2); }
public String putJSON(String docUri) { RequestParameters params = new RequestParameters(); params.add("uri", docUri); String input = "{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}"; StringHandle readHandle = new StringHandle(); // call the service getServices().put(params, new StringHandle(input).withFormat(Format.JSON), readHandle); // iterate over the results return readHandle.get(); }
@Test public void testBadQueryAndThrowException() { RawStructuredQueryDefinition query = client.newQueryManager().newRawStructuredQueryDefinition( new StringHandle("<this is not a valid structured query>").withFormat(JSON)); // we'll see one failure per forest List<String> urisIterator = testQueryExceptions(query, 0, moveMgr.readForestConfig().listForests().length); // without any matching uris, there will be no success or failure batches testIteratorExceptions(urisIterator, 0, 0); }
@Test public void testJavascriptMlcpTransformAdapter() throws Exception{ String transformContents = Common.testFileToString("SampleMlcpTransform.sjs"); libMgr.write("/ext/SampleMlcpTransform.sjs", new StringHandle(transformContents).withFormat(Format.TEXT)); ServerTransform transform = new ServerTransform(MLCP_TRANSFORM_ADAPTER) .addParameter("ml.module", "/ext/SampleMlcpTransform.sjs") .addParameter("attr-value", "true"); runTransform(transform); libMgr.delete("/ext/SampleMlcpTransform.sjs"); }
@Test public void testXQueryMlcpTransformAdapter() throws Exception{ String transformContents = Common.testFileToString("SampleMlcpTransform.xqy"); libMgr.write("/ext/SampleMlcpTransform.xqy", new StringHandle(transformContents).withFormat(Format.TEXT)); ServerTransform transform = new ServerTransform(MLCP_TRANSFORM_ADAPTER) .addParameter("ml.module", "/ext/SampleMlcpTransform.xqy") .addParameter("ml.namespace", "http://marklogic.com/example") .addParameter("attr-value", "true"); runTransform(transform); libMgr.delete("/ext/SampleMlcpTransform.xqy"); }