@Override public Iterator<String> listGraphUris() { final String uriString = services.getGraphUris(requestLogger, new StringHandle()).get(); String[] uris = uriString.split("\n"); return Arrays.asList(uris).iterator(); }
public String piiGenerate(List<JsonNode> entities) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode node = objectMapper.valueToTree(entities); ResourceServices.ServiceResultIterator resultItr = this.getServices().post(params, new JacksonHandle(node)); if (resultItr == null || !resultItr.hasNext()) { throw new EntityServicesGenerationException("Unable to generate pii config"); } ResourceServices.ServiceResult res = resultItr.next(); return res.getContent(new StringHandle()).get(); }
@Override public boolean isEnabled() { RequestParameters params = new RequestParameters(); ServiceResultIterator resultItr = this.getServices().get(params); if (resultItr == null || ! resultItr.hasNext()) { return false; } ServiceResult res = resultItr.next(); StringHandle handle = new StringHandle(); String enabled = res.getContent(handle).get(); return Boolean.parseBoolean(enabled); } }
@Override public boolean isEnabled() { RequestParameters params = new RequestParameters(); ServiceResultIterator resultItr = this.getServices().get(params); if (resultItr == null || ! resultItr.hasNext()) { return false; } ServiceResult res = resultItr.next(); StringHandle handle = new StringHandle(); String enabled = res.getContent(handle).get(); return Boolean.parseBoolean(enabled); } }
/** * * @param suite * @param runTeardown * @param runSuiteTeardown * @param calculateCoverage * @return */ public JUnitTestSuite runSuite(String suite, boolean runTeardown, boolean runSuiteTeardown, boolean calculateCoverage) { RequestParameters params = buildRequestParameters(suite, FORMAT_JUNIT, runTeardown, runSuiteTeardown, calculateCoverage); String xml = getServices().post(params, (AbstractWriteHandle) null, new StringHandle()).get(); return unitTestXmlParser.parseJUnitTestSuiteResult(xml); }
/** * @return one TestModule for each test module found in the modules database */ public List<TestModule> list() { RequestParameters params = new RequestParameters(); params.add("func", "list"); String xml = getServices().get(params, new StringHandle()).get(); return unitTestXmlParser.parseTestList(xml); }
protected String getModulesFile(String uri) { try { String contents = modMgr.read(uri).next().getContent(new StringHandle()).get(); return contents.replaceFirst("(\\(:|//)\\s+cache\\sbuster:.+\\n", ""); } catch (IllegalStateException e){ return null; } catch(Exception e) { e.printStackTrace(); } return null; }
public String getContents(String entityName, CodeFormat codeFormat, FlowType flowType, String mappingName) { params.add("entity", entityName); params.add("codeFormat", codeFormat.toString()); params.add("flowType", flowType.toString()); if(mappingName != null) { params.add("mapping", mappingName); } ResourceServices.ServiceResultIterator resultItr = this.getServices().get(params); if (resultItr == null || ! resultItr.hasNext()) { throw new RuntimeException("Unable to get Content Plugin scaffold"); } ResourceServices.ServiceResult res = resultItr.next(); return res.getContent(new StringHandle()).get().replaceAll("\n", "\r\n"); }
public String getHubVersion() { try { ResourceServices.ServiceResultIterator resultItr = this.getServices().get(new RequestParameters()); if (resultItr == null || ! resultItr.hasNext()) { return null; } ResourceServices.ServiceResult res = resultItr.next(); return res.getContent(new StringHandle()).get(); } catch(Exception e) {} // 2.0.0 is the version at which we started using this method. It's the // default fallback and should not be changed. return "2.0.0"; }
public void runImpl() { System.out.println("writing " + id); if (isResendable) docMgr.write(id, new StringHandle(resendableDoc)); else docMgr.write(id, new InputStreamHandle(onetimeDoc)); System.out.println(id + "=" + docMgr.read(id, new StringHandle()).get()); docMgr.delete(id); System.out.println("finished " + id); } }
public String deleteJSON(String docUri) { RequestParameters params = new RequestParameters(); params.add("uri", docUri); StringHandle output = new StringHandle(); // call the service getServices().delete(params, output); // iterate over the results return output.get(); } }
@Test public void testThings_Differentmimetypes() throws Exception { gmWriter.setDefaultMimetype(RDFMimeTypes.TRIPLEXML); String tripleGraphUri = "http://test.things.com/multiple"; File file = new File(datasource + "relative5.xml"); gmWriter.write(tripleGraphUri, new FileHandle(file)); file = new File(datasource + "semantics.ttl"); gmWriter.merge(tripleGraphUri, new FileHandle(file).withMimetype(RDFMimeTypes.TURTLE)); StringHandle things = gmWriter.things(new StringHandle(), "http://dbpedia.org/resource/Hadoop"); assertTrue("Things did not return expected Uri's", things.get().contains("Apache Hadoop")); gmWriter.delete(tripleGraphUri); }
@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 testWriteTextDoc() { System.out.println("Running testWriteTextDoc method"); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
@Test public void testWriteTextDoc() { System.out.println("Running testWriteTextDoc method"); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
@Test public void testQueryOptionsManager() throws JAXBException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { QueryOptionsManager mgr = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); assertNotNull("Client could not create query options manager", mgr); mgr.writeOptions("testempty", new StringHandle("{\"options\":{}}").withFormat(Format.JSON)); String optionsResult = mgr.readOptions("testempty", new StringHandle()).get(); logger.debug("Empty options from server {}", optionsResult); assertTrue("Empty options result not empty",optionsResult.contains("options")); assertTrue("Empty options result not empty",optionsResult.contains("\"http://marklogic.com/appservices/search\"/>")); mgr.deleteOptions("testempty"); };
private void check(StructureWriteHandle handle, String optionsName) { QueryManager queryMgr = Common.client.newQueryManager(); queryMgr.setPageLength(0); RawCombinedQueryDefinition query = queryMgr.newRawCombinedQueryDefinition(handle); SearchHandle response = queryMgr.search(query, new SearchHandle()); String wrappedCtsQuery = response.getQuery(new StringHandle()).get(); // remove the <search:query> wrapper element String ctsQuery = wrappedCtsQuery.replaceAll("</?search:query[^>]*>", ""); long numMatches = response.getTotalResults(); checkCts(new StringHandle(ctsQuery), optionsName, numMatches); }
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 testWriteTextDoc() { SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("admin", "admin"); DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, 8015, secContext, getConnType()); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
@Test public void evalHelloWorld() { // javascript hello world and response determined by implicit StringHandle which registered with String.class ServerEvaluationCall query = Common.evalClient.newServerEval().javascript("'hello world'"); String response = query.evalAs(String.class); assertEquals("Return should be 'hello world'", "hello world", response); // xquery hello world with a variable and response explicit set to StringHandle query = Common.evalClient.newServerEval() .xquery("declare variable $planet external;" + "'hello world from ' || $planet") .addVariable("planet", "Mars"); StringHandle strResponse = query.eval(new StringHandle()); assertEquals("Return should be 'hello world from Mars'", "hello world from Mars", strResponse.get()); }