Skip to content

Instantly share code, notes, and snippets.

View remeniuk's full-sized avatar

Vasil Remeniuk remeniuk

View GitHub Profile
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.vasilrem.ideabox.web.resources</param-value>
trait ResourcesUtil {
def serializeAsJSON(obj: AnyRef): String = new String(Serializer.SJSON.out(obj))
def deserializeJSON[T](json: Array[Byte])(implicit m: Manifest[T]): AnyRef =
Serializer.SJSON.in[T](json)(m)
}
@Path("/idea")
class IdeaResource extends ResourcesUtil{
@BeanInfo
case class Author(id: String, name: String) extends DomainClass{
private def this() = this(null, null)
}
@BeanInfo
case class Topic(id: String, name: String) extends DomainClass{
private def this() = this(null, null)
}
@BeanInfo
@Data public class Topic{
private final String id;
private final String name;
}
case class Topic(id: String, name: String)
public class Topic {
private final String id;
private final String name;
public Topic(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
doBeforeSpec{
preparedFunction.loadPreparedFunctions(List(“/mongo/preparedFunctions.js”))
}
“Calls prepared function ‘test’ with parameter ‘prepared’” in {
preparedFunction.call(“test(‘prepared’)”) must beEqualTo(“test prepared”)
}
def call(functionCall: String): Object = {
var ret:Object = null
MongoDB.use(DefaultMongoIdentifier) ( db => {
ret = db.eval(“db.eval(\”" + functionCall + “\”)”)
}
)
ret
}
def loadPreparedFunctions(classPathResources: List[String]) = {
classPathResources.foreach {
resourceName =>
val fileContent = new FileBulkReader(new File(getClass().getResource(resourceName).getFile)).read // load the files with server-side code
MongoDB.use(DefaultMongoIdentifier) ( db => {
db.eval(
fileContent // evaluate the code in mongo
)
/**
* Just a small dummy function
* @param string any string
* @return ‘test $passed string$’
*/
test = function(string){
return ‘test ‘ + string
}