Solr 4.0 and ResourceLoader: getLines undefined - java

I'm translating to Lucene 4.0 a plug-in developed over Lucene 3.6, but I'm having so much troubles with ResourceLoader.
I've changed the imports related to ResourceLoader from:
import org.apache.solr.common.ResourceLoader;
import org.apache.solr.util.plugin.ResourceLoaderAware;
to:
import org.apache.lucene.analysis.util.ResourceLoader;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
But at the inform method:
public void inform(ResourceLoader loader) {
when I try to use the getLines function:
List list = loader.getLines("file");
I get the following error:
The method getLines(String) is undefined for the type ResourceLoader
What am I doing wrong?
Kind regards

At Lucene 4.0, getLines doesn't have to be invoked as a method from ResourceLoader.
Here you can see an example.

Related

How do I declare a default parser for Rest Assured 3.0.3 (using Java and TestNG)?

Good day folks,
I am an admittedly novice Java programmer but I take care to research docs and FAQ's to try to get past issues. This is a problem that I have not been able to overcome, however. I am using RestAssured (version 3.0.3, as pulled by Maven) and cannot get RestAssured to parse "text/plain" content (rather, I cannot get Java to compile the code to do so).
This compiles but gives an error:
import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
import static io.restassured.module.jsv.JsonSchemaValidator.*;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
public class TestNG2 {
/*
userName, passWord and server defined here as protected static Strings
*/
#Test
public void filter_Asset(){
given().
auth().basic(userName, passWord).
when().
get ("http://" + server +"/api/filter?type=$tAsset").
then().
statusCode(200).
body("count", greaterThan(0));
}
}
The error:
java.lang.IllegalStateException: Expected response body to be verified as JSON, HTML or XML but content-type 'text/plain' is not supported out of the box.
Try registering a custom parser using:
RestAssured.registerParser("text/plain", );
However, when I try to include the following line in the filter_Asset test:
RestAssured.registerParser("text/plain", Parser.JSON);
The code will not compile with the following complaint:
java.lang.Error: Unresolved compilation problems:
RestAssured cannot be resolved
Parser cannot be resolved to a variable
I receive similar complaints when I try to use the following declaration:
RestAssured.defaultParser = Parser.JSON;
For what it's worth, I am working on a Windows 7, 64-bit machine. Using Eclipse Neon.3 (4.6.3) and my JDK is 1.8_131
I've consulted the RestAssured usage and documentation pages, believe am importing the packages correctly, etc. Am I making a rookie error somewhere?
It was a rookie mistake!
In addition to statically importing the class methods, the compiler also required importing of the following classes:
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
After those declarations, I was able to register the default Parser in the filter_Asset test:
RestAssured.registerParser("text/plain", Parser.JSON);

undefined method - geoBoundingBoxQuery(String location)

I am trying to create a geoBoundingBoxQuery("pin.location") in Java for Elastic Search. Eclipse is not able to resolve imports for this method although the Elastic Search Java API documentation specifically suggests to use this method.
What class do I need to import which has this method?
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-geo-queries.html#java-query-dsl-geo-bounding-box-query
geoBoundingBoxQuery("pin.location") is defined as a static method in class org.elasticsearch.index.query.QueryBuilders, so you can use it this way:
QueryBuilder q = QueryBuilders.geoBoundingBoxQuery("pin.location");
Elasticsearch documentation is assuming you're using a static import like:
import static org.elasticsearch.index.query.QueryBuilders.geoBoundingBoxQuery;
so you don't need qualify the method with class name:
QueryBuilder q = geoBoundingBoxQuery("pin.location");
For anyone who is having the same issue, I have found the answer.
Its the version of Elastic search java API that I am using is the issue. The documentation is for version 2.1 whereas I am using an older version. For the older version, you need to do the following:
FilterBuilders.geoBoundingBoxFilter("pin.location")

getBundleContext method is undefined issue

I'm trying to setup an application that runs on OSGi internally and have tried using the tutorial here, but I get the error "The method getBundleContext() is undefined for the type Framework" all the time. As far as I can tell, I'm using the right library, but it's not specified in the mentioned article, so I'm not 100% sure. I've also tried the examples on Apache's website, here, which results in the same issue. Code below:
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class Main {
public static void main(String[] args) throws BundleException {
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
Framework framework = frameworkFactory.newFramework(config);
framework.start();
// Throws error that it cannot find method getBundleContext()
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();
installedBundles.add(context.installBundle("file:org.apache.felix.shell-1.4.2.jar"));
installedBundles.add(context.installBundle("file:org.apache.felix.shell.tui-1.4.1.jar"));
for (Bundle bundle : installedBundles) {
bundle.start();
}
}
}
The only thing that makes sense is that either I'm using the wrong libraries, or the libraries have changed and the method I'm attempting to call has since been deprecated out in the last 4 years. Anyone know how I can fix this?
I doubt it makes much of a difference, but in case it does, I'm using Bndtools for Eclipse to create this project.
Found the issue. Apparently, the import of osgi.core that was in the Bndtools' project build path was out of date, preventing the code from accessing the correct version of the framework libraries. Updating that fixed the issue.
Additional side-note; Since I'm using Bndtools, I was adding this to the project build path via the bnd.bnd file's build tab. This, however, was not grabbing the correct version of osgi.core, so I had to go under source and add the version=latest in order to force it to get the latest version available, so the line now appears as: osgi.core;version=latest where it was previously just osgi.core under the -buildpath: section.

MongoDB updates with java driver version 3.0

I'm migrating my aplications to MongoDb 3.0.2. I have no problems with inserts, finds and deletes. But,Problems with the update. Specially with the eq().
In this sentence:
coll.updateOne(eq("_id", id), new Document("$set", new Document("name", name)));
The id variable is defined ObjectId. Eclipse gives me an error:
The method eq(String, ObjectId) is undefined for the
type SystemDAO (my java class).
What am I doing wrong? I followed the examples in the Mongo java driver documents.
you need to import the static method eq from the package com.mongodb.client.model.Filters.
add this infront of your class to your other imports:
import static com.mongodb.client.model.Filters.*;
In Eclipse it should give a quick-fix to import the right package if you do a mouse over on your error. But for static imports this does not work all the time.

CompilationTestHelper is either not found or its access discouraged

I want to write some tests for my compiler but can't get past an error.
I'm following an example from 'Implementing DSL with Xtext and Xtend' by L. Bettini (great book btw). I've downloaded the code for the 'entities' DSL from https://github.com/LorenzoBettini/packtpub-xtext-book-examples and the tests in EntitiesGenerator.xtend work great.
If I write a test for the default DSL (MyDsl) using the same code, I've got an error:
org.eclipse.xtext.xbase.compiler.CompilationTestHelper cannot be resolved to a type.
or, if I add org.eclipse.xtext.xbase.junit (2.4.1) to the list of required plug-ins, I get
Discouraged access: The type CompilationTestHelper is not accessible due to restriction on required project org.xtext.example.myDsl.tests
I can allow access to it, but then get a runtime error anyway. If I try to add org.eclipse.xtext.xbase.lib as well, only org.eclipse.xtext.xbase.lib.source appears in the list. I don't know it that matters. In any case, adding it doesn't change anything.
What do I need to do to make it work?
I'm using Juno with Xtext 2.4.1., Java 1.7.
The content of the test class:
package org.xtext.example.myDsl.tests
import com.google.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.compiler.CompilationTestHelper // error here
import org.xtext.example.myDsl.MyDslInjectorProvider
import org.junit.Test
import org.junit.runner.RunWith
#RunWith(typeof(XtextRunner))
#InjectWith(typeof(MyDslInjectorProvider))
class MyDslGeneratorTest {
#Inject extension CompilationTestHelper
#Test
def void testGeneratedCode() {
'''
Hello some1!
Hello some2!
'''.assertCompilesTo(
'''some content''')
}
}
Thank you in advance!
the xtext guys mark stuff that may be changed NOT as api. this is why you get this warning.
it should work anyway. (although it is meant to be used for xbase languages only)
P.S: you have to add a dependency to jdt.core too

Categories