ReCaptcha.scala.scala:114: not found: value compact - scala

I have the following code:
http://www.assembla.com/spaces/liftweb/wiki/ReCaptcha
and compile the project(sbt), send me the following message:
src/main/scala/code/model/ReCaptcha.scala.scala:114: not found: value compact
[error] val RecaptchaOptions = compact(render(reCaptchaOptions))
any suggestions please :(

Compact comes from lift-json I would imagine as thats the only place I recall that method being defined. Try adding this import:
import net.liftweb.json.JsonAST._
In addition, you may want to refer to the lift-json documentation for usage on compact(...)

Related

Parsing a method definition string, don't know how to parse into scala.meta.Decl.Def

I want to be able to parse a string to Decl.Def but the code doesn't compile:
import scala.meta._
val s:String = ... known only at runtime
s.parse[Decl.Def].get
Error:(39, 52) don't know how to parse into scala.meta.Decl.Def
What do I need to do to parse it? Using scalameta 2.0.0
Ok, managed to find the solution:
s.parse[Stat]

" Object java.lang.String not a value" error in scala code

I have the below piece of code in my scala program that uses Flink's Table API.
val custTS = new CsvTableSource("D:\\input\\customerinfo.csv",
Array("customerId","name","address","zip"),
Array(String,String,String,Long))
The editor is displaying error at the third line for the three 'String's with the error message "Object java.lang.String not a value". 'String' is used in many other places in the rest of the code. But it doesn't throw error anywhere else. I saw a couple of Stackoverflow questions with similar issues mentioned, but I couldn't fix this based on the solutions mentioned.
The imports in the program are given below.
import org.apache.flink.api.scala._
import org.apache.flink.table.api.TableEnvironment
import org.apache.flink.table.api.scala._
import org.apache.flink.table.sinks.CsvTableSink
import org.apache.flink.table.sources.CsvTableSource
I have used 'String' in many other scala programs for Flink. But I haven't encountered such an error in any of those programs.
First of all you can't use types (in this case String) as a value in Array. Collections stores objects. You should pass array of type Array[TypeInformation[_]].
So it should look like:
import org.apache.flink.table.api.Types
val custTS = new CsvTableSource(
"D:\\input\\customerinfo.csv",
Array("customerId", "name", "address", "zip"),
Array[TypeInformation[_]](Types.STRING, Types.STRING, Types.STRING, Types.LONG)
)
Unfortunately right now you have to explicitly provide type for the Array. For reasons why, you can have a look at this discussion.

object play.http.HttpEntity.Streamed is not a value

Using Scala and Play 2.5.10 (according to plugin.sbt) I have this code:
import akka.stream.scaladsl.Source
import play.api.libs.streams.Streams
import play.http._
val source = Source.fromPublisher(Streams.enumeratorToPublisher(enumerator))
Ok.sendEntity(HttpEntity.Streamed(source, None, Some("application/zip")))
The imports there are mostly from testing because no matter what I try I can't get the framework to accept HttpEntity.Streamed. With this setup the error is what the title says. Or taken from the console:
Looking at the documentation here I can't really figure out why it doesn't work: https://www.playframework.com/documentation/2.5.10/api/java/play/http/HttpEntity.Streamed.html
This is also what the official examples use: https://www.playframework.com/documentation/2.5.x/ScalaStream
Does anyone at least have some pointers on where to start looking? I've never used Scala or Play before so any hints are welcome.
you should import this one
import play.api.http.HttpEntity
import play.api.libs.streams.Streams
val entity: HttpEntity = HttpEntity.Streamed(fileContent, None, None)
Result(ResponseHeader(200), entity).as(MemeFoRTheFile)
It means that HttpEntity.Streamed is not a value so you should wrap it in a Result() with its ResponseHeader and its extension

Play 2.5.x -- object org.joda.time.Duration is not a value

Compiler problem that doesn't appear to be simple to resolve. (Then again everything is easy once you know how...)
import org.joda.time._
import org.joda.time.format._
import org.joda.time.convert._
val durationLabel = org.joda.time.Duration(duration).toPeriod()
Yet I get this error:
object org.joda.time.Duration is not a value
This question ask the same thing but it's fix doesn't help at all: Object is not a value error in scala
This question's answer doesn't appear to help either: Why is Scala saying it can’t see members of org.joda.time.Period? nor does this one: Type value plusHours is not a member of org.joda.time.DateTime unless I'm being extremely dense.
I believe that jodatime is "built in" somehow as when I add the following to build.sbt
"org.joda" % "joda-convert" % "1.8.1",
it does nothing -- no complaints and no new downloads even after a clean.
So what am I missing?
This
val durationLabel = new org.joda.time.Duration(duration).toPeriod()
should work.
objects in Scala define single instances of a class
There's no corresponding construct in Java, so you'll need to use the new keyword to instantiate your instance of Duration.

Problems with stubbing spy'ed object in scala

I have a pretty complex test where I decided to go with approach of partial stubbing of tested class. in my test I have something like this:
val srv = new Service()
val srvSpy = spy(srv)
doReturn(now).when(srvSpy).getRunDateInTimeZone(futureChecklist)
doReturn("boo").when(srvSpy).interpolateChecklistName("name", now)
val returnTuple = (createdChlRev, createdChl)
doReturn(returnTuple).when(srvSpy).create(fChlCreatorId,
fChlCreatorEmail,
"username",
true,
templateId,
"boo",
optDueDate)(connection)
val (chlRev, chl) = srv.createFromFutureChecklist(futureChecklist)(connection)
In the code above, the first two stubbed methods working as expected. However, the last one throws an error:
[error] Tuple2 cannot be returned by create$default$8() [error]
create$default$8() should return JsObject [error] *** [error] If
you're unsure why you're getting above error read on. [error] Due
to the nature of the syntax above problem might occur because: [error]
1. This exception might occur in wrongly written multi-threaded tests. [error] Please refer to Mockito FAQ on limitations of
concurrency testing. [error] 2. A spy is stubbed using
when(spy.foo()).then() syntax. It is safer to stub spies - [error]
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
I've trying bunch of different approached of stubbing and still getting the same error. At this point I have no idea even where to look.
What am I doing wrong?
Any advice would be helpful.
Thanks
Sorry, it was my own dumb mistake. I was stubbing the spied class, but calling the original one :(
Thanks,