Commit 4fe310db authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Refactored package structuring

parent 3096da1d
Pipeline #139 skipped
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.api;
import de.cebitec.common.dbxref.api.DbXRef;
import de.cebitec.common.dbxref.api.Resource;
......@@ -44,7 +44,7 @@ public interface DbXRefService {
if (it.hasNext()) {
return it.next();
} else {
return DbXRefResourceRegistry.getDefault();
throw new IllegalStateException("No DbXRefService provided");
}
}
......
......@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
import de.cebitec.common.dbxref.api.DbXRefService;
import com.google.common.collect.Iterables;
import de.cebitec.common.dbxref.api.DbXRef;
import de.cebitec.common.dbxref.api.Resource;
......@@ -38,21 +39,10 @@ import org.kohsuke.MetaInfServices;
*
* @author cb
* @author Lukas Jelonek {@literal <ljelonek at cebitec.uni-bielefeld.de>}
* @deprecated Don't use this class directly. Use the service interface instead. The visibility of this implementation
* will be changed to package private in a future release.
*/
@MetaInfServices
public class DbXRefResourceRegistry implements DbXRefService {
private static DbXRefResourceRegistry instance;
public static DbXRefResourceRegistry getDefault() {
if (instance == null) {
instance = new DbXRefResourceRegistry();
}
return instance;
}
Iterable<? extends DbXRefResolver> getResolvers() {
// service provider lookup von resolvern
Iterator<DbXRefResolver> it = ServiceLoader.load(DbXRefResolver.class, this.getClass().getClassLoader()).iterator();
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
import de.cebitec.common.dbxref.persistence.SimpleDbXRef;
import de.cebitec.common.dbxref.api.DbXRef;
......
......@@ -14,13 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
/**
*
* @author Lukas Jelonek {@literal <ljelonek at cebitec.uni-bielefeld.de>}
*/
public class DbXrefParserException extends RuntimeException {
class DbXrefParserException extends RuntimeException {
/**
* Creates a new instance of
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
/**
*
......
......@@ -14,9 +14,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref.api;
package de.cebitec.common.dbxref.impl;
import com.google.common.base.Preconditions;
import de.cebitec.common.dbxref.api.DbXRef;
import de.cebitec.common.dbxref.api.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
......
......@@ -42,6 +42,8 @@ public class CompositeProvider implements DbXRefResolver {
Gson gson = new Gson();
InputStream is = this.getClass().getResourceAsStream("providers.json");
InputStreamReader isr = new InputStreamReader(is);
@SuppressWarnings("unchecked")
List<Map<String, List<String>>> fromJson = gson.fromJson(isr, List.class);
for (Map<String, List<String>> entry : fromJson) {
GenericDbXRefProvider.ResolverData data = new GenericDbXRefProvider.ResolverData();
......
......@@ -19,7 +19,7 @@ package de.cebitec.common.dbxref.providers;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Lists;
import de.cebitec.common.dbxref.api.DbXRef;
import de.cebitec.common.dbxref.api.GenericResource;
import de.cebitec.common.dbxref.impl.GenericResource;
import de.cebitec.common.dbxref.api.Resource;
import de.cebitec.common.dbxref.api.Resource.Type;
import de.cebitec.common.dbxref.spi.DbXRefResolver;
......
......@@ -16,9 +16,9 @@
*/
package de.cebitec.common.dbxref.providers;
import de.cebitec.common.dbxref.DbXrefResourceException;
import de.cebitec.common.dbxref.impl.DbXrefResourceException;
import de.cebitec.common.dbxref.api.DbXRef;
import de.cebitec.common.dbxref.api.GenericResource;
import de.cebitec.common.dbxref.impl.GenericResource;
import de.cebitec.common.dbxref.spi.DbXRefResolver;
import de.cebitec.common.dbxref.api.Resource;
import java.net.URI;
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
import de.cebitec.common.dbxref.persistence.SimpleDbXRef;
import de.cebitec.common.dbxref.api.Resource;
......@@ -28,7 +28,7 @@ import static org.junit.Assert.*;
* @author cb
*/
public class DbXRefResourceRegistryTest {
public DbXRefResourceRegistryTest() {
}
......@@ -37,9 +37,10 @@ public class DbXRefResourceRegistryTest {
*/
@Test
public void testResolve_DbXRef() {
DbXRef validGI = new SimpleDbXRef("GI", "731497");
Iterable<? extends DbXRefResolver> resolvers = DbXRefResourceRegistry.getDefault().getResolvers();
DbXRef validGI = new SimpleDbXRef("GI", "731497");
DbXRefResourceRegistry registry = new DbXRefResourceRegistry();
Iterable<? extends DbXRefResolver> resolvers = registry.getResolvers();
System.out.println("resolvers = " + resolvers);
Iterable<? extends Resource> resources = DbXRefResourceRegistry.getDefault().resolve(validGI);
Iterable<? extends Resource> resources = registry.resolve(validGI);
}
}
......@@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
import de.cebitec.common.dbxref.api.DbXRefService;
import java.util.ServiceLoader;
import org.junit.Test;
import static org.junit.Assert.*;
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cebitec.common.dbxref;
package de.cebitec.common.dbxref.impl;
import de.cebitec.common.dbxref.api.DbXRef;
import org.junit.Test;
......
......@@ -16,7 +16,6 @@
*/
package de.cebitec.common.dbxref.persistence;
import de.cebitec.common.dbxref.DbXrefParser;
import de.cebitec.common.dbxref.api.DbXRef;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
......@@ -35,8 +34,7 @@ public class PersistenceTest {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("DbXRefTest");
EntityManager em = emf.createEntityManager();
DbXrefParser p = new DbXrefParser();
DbXRef parse = p.parse("GO:0000001");
DbXRef parse = new SimpleDbXRef("GO", "0000001");
EntityTransaction transaction = em.getTransaction();
transaction.begin();
em.persist(parse);
......
......@@ -16,8 +16,8 @@
*/
package de.cebitec.common.dbxref.providers;
import de.cebitec.common.dbxref.DbXrefParser;
import de.cebitec.common.dbxref.api.DbXRef;
import de.cebitec.common.dbxref.api.DbXRefService;
import de.cebitec.common.dbxref.api.Resource;
import de.cebitec.common.dbxref.spi.DbXRefResolver;
import java.util.Arrays;
......@@ -64,7 +64,7 @@ public class ValidResourceAvailableTest {
public ValidResourceAvailableTest(DbXRefResolver provider, String dbxref) {
this.provider = provider;
this.dbxref = new DbXrefParser().parse(dbxref);
this.dbxref = DbXRefService.getInstance().create(dbxref);
}
@Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment