for debugging purpose I would like to see what a TraversableBSONDocument has inside, I'm not able to see the content of a response.
I found it ! :
val query = BSONDocument()
.equal("userId", user.id.map(_.value).map(_.toLong).get)
.greaterThanOrEqual("start", interval.start.jodaDateTime)
.lesserThan("end", interval.end.jodaDateTime)
.count("RREntity")
println(BSONDocument.pretty(query))
Related
I'm doing some tests with Gatling using Scala. I'm trying to check whether a response body that is returned is not empty.
I'm doing it like this:
def getImages: ChainBuilder = feed(credentials)
.exec(http("Get Image")
.get(GET_MY_URI)
.queryParam("guid", "${branch}")
.queryParam("t", "0.458654")
.check(status.is(200))
.check(bodyString.transform(_.size > 1).is(true)))
But it's not working. I get:
java.nio.charset.MalformedInputException: Input length = 1
Does somebody know how to achieve what I'm trying?
Replace
.check(bodyString.transform(_.size > 1).is(true)))
with
.check(bodyBytes.exists)
All the DSL is explained here: https://gatling.io/docs/current/cheat-sheet/
I want to add to my app a simple button that on click will call an Action that will create a csv file from two lists I have and download it to the user computer.
This is my Action:
def createAndDownloadFile = Action {
val file = new File("newFile.csv")
val writer = CSVWriter.open(file)
writer.writeAll(List(listOfHeaders, listOfValues))
writer.close()
Ok.sendFile(file, inline = false, _ => file.getName)
}
but this is now working for me, the file is not getting downloaded from the browser...
im expecting to see the file get downloaded by the browser, i thought Ok.sendFile should do the trick..
thanks!
You can use Enumerators and streams for that. It should work like this:
val enum = Enumerator.fromFile(...)
val source = akka.stream.scaladsl.Source.fromPublisher(play.api.libs.streams.Streams.enumeratorToPublisher(enum))
Result(
header = ResponseHeader(OK, Map(CONTENT_DISPOSITION → "attachment; filename=whatever.csv.gz")),
body = HttpEntity.Streamed(source.via(Compression.gzip), None, None)
)
This will actually pipe the download through gzip. Just remove the .via(Compression.gzip) part if that is not needed.
I am trying since few hours to parse an XES file using the Deckfour XES Open library, I want to have the logs of my file however I can't find any parser which parse my .xes
//Getting Xes File
val logXesFile = request.body.file("file").get
val filename = logXesFile.filename
logger.debug(s"filename: $filename")
//Try all available parsers
val otherParsers = XParserRegistry.instance().getAvailable
for(p <- otherParsers){
try{
logger.debug(p.name())
val logs = p.parse(logXesFile.ref.file)
if(logs.size() > 0){
logger.debug(s"Parser founded ! $p")
}
}
catch{
case e : Exception => {logger.debug("Exception !")}
}
}
Here is a screenshot of my debugger :
Also I tried plenty of xes files the problem are definitely not from those, I also tried with the GZIP parser
Ok I finally found !
The "myfile".ref.file allow indeed to get the file however it change the name of the file to something like "multipartBody26...TemporaryFile" and the parser function from the deckfour library do not recognize it as a ".xes" anymore while the content is still an xes file.
So the solution looks to be to rename the file
I have a DataFrame that loads from a huge json file and gets the schema from it. The schema is basically around 1000 columns. I want the same output of printSchema to be saved in a file instead of the console.
Any ideas?
You can do the following if you are working in a local environment :
val filePath = "/path/to/file/schema_file"
new PrintWriter(filePath) { write(df.schema.treeString); close }
If you are on HDFS, you'll need to provide a URI.
This is the body of printSchema():
/**
* Prints the schema to the console in a nice tree format.
* #group basic
* #since 1.3.0
*/
// scalastyle:off println
def printSchema(): Unit = println(schema.treeString)
// scalastyle:on println
So you can't do much, but I have a work around that can work in your case.
Set the out stream to a file Stream so that it gets printed to your File.
Something like this
val out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
I hope I solved your query !
I have a requirement to convert the output of cypher into JSON.
Here is my code snippet.
RestCypherQueryEngine rcqer=new RestCypherQueryEngine(restapi);
String nodeN = "MATCH n=(Company) WITH COLLECT(n) AS paths RETURN EXTRACT(k IN paths | LAST(nodes(k))) as lastNode";
final QueryResult<Map<String,Object>> queryResult = rcqer.query(searchQuery);
for(Map<String,Object> row:queryResult)
{
System.out.println((ArrayList)row.get("lastNode"));
}
Output:
[http://XXX.YY6.192.103:7474/db/data/node/445, http://XXX.YY6.192.103:7474/db/data/node/446, http://XXX.YY6.192.103:7474/db/data/node/447, http://XXX.YY6.192.103:7474/db/data/node/448, http://XXX.YY6.192.103:7474/db/data/node/449, http://XXX.YY6.192.103:7474/db/data/node/450, http://XXX.YY6.192.103:7474/db/data/node/451, http://XXX.YY6.192.103:7474/db/data/node/452, http://XXX.YY6.192.103:7474/db/data/node/453]
I am not able to see the actual data (I am getting URL's). I am pretty sure I am missing something here.
I would also like to convert the output to JSON.
The cypher works in my browser interface.
I looked at various articles around this:
Java neo4j, REST and memory
Neo4j Cypher: How to iterate over ExecutionResult result
Converting ExecutionResult object to json
The last 2 make use of EmbeddedDatabase which may not be possible in my scenario (as the Neo is hosted in another cloud, hence the usage of REST).
Thanks.
Try to understand what you're doing? Your query does not make sense at all.
Perhaps you should re-visit the online course for Cypher: http://neo4j.com/online-course
MATCH n=(Company) WITH COLLECT(n) AS paths RETURN EXTRACT(k IN paths | LAST(nodes(k))) as lastNode
you can just do:
MATCH (c:Company) RETURN c
RestCypherQueryEngine rcqer=new RestCypherQueryEngine(restapi);
final QueryResult<Map<String,Object>> queryResult = rcqer.query(query);
for(Node node : queryResult.to(Node.class))
{
for (String prop : node.getPropertyKeys()) {
System.out.println(prop+" "+node.getProperty(prop));
}
}
I think it's better to use the JDBC driver for what you try to do, and also actually return the properties you're trying to convert to JSON.