Skip to content
Snippets Groups Projects
Commit 33633fd0 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Merge branch 'master' into teiheader

parent 87ba6ec4
No related branches found
No related tags found
No related merge requests found
/.settings /.settings
/.classpath /.classpath
/target
package info.textgrid.services.aggregator;
import info.textgrid.middleware.tgsearch.client.SearchClient;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import javax.ws.rs.WebApplicationException;
public interface ITextGridRep {
public SearchClient getPublicSearchClient();
public TGCrudService getCRUDService();
public String getConfValue(final String key) throws WebApplicationException;
}
\ No newline at end of file
package info.textgrid.services.aggregator; package info.textgrid.services.aggregator;
import info.textgrid.middleware.confclient.ConfservClient;
import info.textgrid.middleware.confclient.ConfservClientConstants;
import info.textgrid.middleware.tgsearch.client.SearchClient;
import info.textgrid.namespaces.metadata.core._2010.MetadataContainerType; import info.textgrid.namespaces.metadata.core._2010.MetadataContainerType;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService_Service;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -32,11 +24,6 @@ ...@@ -32,11 +24,6 @@
import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import javax.xml.stream.XMLStreamException;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.MTOMFeature;
import org.codehaus.jettison.json.JSONException;
/* /*
* Generating a TEIcorpus document from a (single) aggregation * Generating a TEIcorpus document from a (single) aggregation
...@@ -65,11 +52,8 @@ ...@@ -65,11 +52,8 @@
@Path("/teicorpus") @Path("/teicorpus")
public class TEICorpus { public class TEICorpus {
private static final String CONF_ENDPOINT = "https://www.textgridlab.org/1.0/confserv"; private final ITextGridRep repository = TextGridRepProvider.getInstance();
private ConfservClient confservClient;
private SearchClient searchClient;
private HashMap<String, String> config;
private TGCrudService crud;
final Logger logger = Logger.getLogger("info.textgrid.services.aggregator"); final Logger logger = Logger.getLogger("info.textgrid.services.aggregator");
@GET @GET
...@@ -77,12 +61,12 @@ public class TEICorpus { ...@@ -77,12 +61,12 @@ public class TEICorpus {
@Produces("text/xml") @Produces("text/xml")
public Response get(@PathParam("aggregation") final URI uri, @QueryParam("attach") @DefaultValue("true") final boolean attach) throws URISyntaxException { public Response get(@PathParam("aggregation") final URI uri, @QueryParam("attach") @DefaultValue("true") final boolean attach) throws URISyntaxException {
logger.fine("TEIcorpus called for root aggregation: " + uri); logger.fine("TEIcorpus called for root aggregation: " + uri);
final TGCrudService crud = getCRUDService(); final TGCrudService crud = repository.getCRUDService();
logger.finest("Yo, clients are there."); logger.finest("Yo, clients are there.");
try { try {
final MetadataContainerType rootAggregationMetadata = crud.readMetadata(null, null, uri.toString()); final MetadataContainerType rootAggregationMetadata = crud.readMetadata(null, null, uri.toString());
logger.finer("CRUD request for root aggregation successful"); logger.finer("CRUD request for root aggregation successful");
final TEICorpusSerializer serializer = new TEICorpusSerializer(rootAggregationMetadata.getObject(), this); final TEICorpusSerializer serializer = new TEICorpusSerializer(rootAggregationMetadata.getObject());
final String format = rootAggregationMetadata.getObject().getGeneric().getProvided().getFormat(); final String format = rootAggregationMetadata.getObject().getGeneric().getProvided().getFormat();
if (!format.contains("aggregation")) { if (!format.contains("aggregation")) {
logger.log(Level.SEVERE, "The requested object {0} is a {1}, not an aggregation, and thus cannot be aggregated.", new Object[] {uri,format}); logger.log(Level.SEVERE, "The requested object {0} is a {1}, not an aggregation, and thus cannot be aggregated.", new Object[] {uri,format});
...@@ -128,39 +112,4 @@ public Response get(@PathParam("aggregation") final URI uri, @QueryParam("attach ...@@ -128,39 +112,4 @@ public Response get(@PathParam("aggregation") final URI uri, @QueryParam("attach
// return null; // return null;
} }
TGCrudService getCRUDService() {
if (crud == null) {
final URL wsdl = TGCrudService_Service.class.getResource("/wsdl/TGCrudService.wsdl");
final TGCrudService_Service tgCrudService_Service = new TGCrudService_Service(wsdl);
final TGCrudService _crud = tgCrudService_Service.getTGCrudPort(new MTOMFeature());
final BindingProvider bp = (BindingProvider) _crud;
final Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getConfValue(ConfservClientConstants.TG_CRUD));
crud = _crud;
}
return crud;
}
SearchClient getSearchClient() {
if (searchClient == null)
searchClient = new SearchClient(getConfValue(ConfservClientConstants.TG_SEARCH_PUBLIC));
return searchClient;
}
String getConfValue(final String key) throws WebApplicationException {
if (config == null) {
try {
confservClient = new ConfservClient(CONF_ENDPOINT);
config = confservClient.getAll();
} catch (final IOException e) {
throw new WebApplicationException(e);
} catch (final JSONException e) {
throw new WebApplicationException(e);
} catch (final XMLStreamException e) {
throw new WebApplicationException(e);
}
}
return config.get(key);
}
} }
...@@ -41,11 +41,12 @@ public class TEICorpusSerializer implements StreamingOutput { ...@@ -41,11 +41,12 @@ public class TEICorpusSerializer implements StreamingOutput {
private static final String TEI_NS = "http://www.tei-c.org/ns/1.0"; private static final String TEI_NS = "http://www.tei-c.org/ns/1.0";
private final Logger logger = Logger.getLogger("info.textgrid.services.aggregator.teicorpus.serializer"); private final Logger logger = Logger.getLogger("info.textgrid.services.aggregator.teicorpus.serializer");
private final ITextGridRep repository = TextGridRepProvider.getInstance();
private XMLOutputFactory outputFactory; private XMLOutputFactory outputFactory;
private XMLEventFactory eventFactory; private XMLEventFactory eventFactory;
private XMLEventWriter writer; private XMLEventWriter writer;
private final ObjectType rootObject; private final ObjectType rootObject;
private final TEICorpus teiCorpus;
private XMLInputFactory inputFactory; private XMLInputFactory inputFactory;
private final Set<String> seen = Sets.newHashSet(); private final Set<String> seen = Sets.newHashSet();
private static final EventFilter NO_DOCUMENT_NODE = new EventFilter() { private static final EventFilter NO_DOCUMENT_NODE = new EventFilter() {
...@@ -61,9 +62,8 @@ private static String toString(final ObjectType object) { ...@@ -61,9 +62,8 @@ private static String toString(final ObjectType object) {
object.getGeneric().getProvided().getFormat() + ")"; object.getGeneric().getProvided().getFormat() + ")";
} }
public TEICorpusSerializer(final ObjectType object, final TEICorpus teiCorpus) { public TEICorpusSerializer(final ObjectType object) {
this.rootObject = object; this.rootObject = object;
this.teiCorpus = teiCorpus;
logger.info("Starting TEIcorpus serialization for " + toString(object)); logger.info("Starting TEIcorpus serialization for " + toString(object));
} }
...@@ -104,7 +104,8 @@ private void write(final OutputStream output, final ObjectType object) throws XM ...@@ -104,7 +104,8 @@ private void write(final OutputStream output, final ObjectType object) throws XM
private void writeAggregation(final OutputStream output, final ObjectType object) throws XMLStreamException { private void writeAggregation(final OutputStream output, final ObjectType object) throws XMLStreamException {
logger.fine("[Processing aggregation " + toString(object)); logger.fine("[Processing aggregation " + toString(object));
final info.textgrid.namespaces.middleware.tgsearch.Response response = teiCorpus.getSearchClient().listAggregation( final info.textgrid.namespaces.middleware.tgsearch.Response response = repository
.getPublicSearchClient().listAggregation(
object.getGeneric().getGenerated().getTextgridUri().getValue()); object.getGeneric().getGenerated().getTextgridUri().getValue());
final List<ResultType> result = response.getResult(); final List<ResultType> result = response.getResult();
...@@ -123,7 +124,7 @@ private void writeAggregation(final OutputStream output, final ObjectType object ...@@ -123,7 +124,7 @@ private void writeAggregation(final OutputStream output, final ObjectType object
logger.fine("Finished aggregation " + toString(object) + "]"); logger.fine("Finished aggregation " + toString(object) + "]");
} }
private void writeHeader(ObjectType object) throws XMLStreamException { private void writeHeader(final ObjectType object) throws XMLStreamException {
writer.add(eventFactory.createStartElement("", TEI_NS, "teiHeader")); writer.add(eventFactory.createStartElement("", TEI_NS, "teiHeader"));
writer.add(eventFactory.createComment("This is a (temporary) header generated from aggregation metadata.")); writer.add(eventFactory.createComment("This is a (temporary) header generated from aggregation metadata."));
writer.add(eventFactory.createStartElement("", TEI_NS, "fileDesc")); writer.add(eventFactory.createStartElement("", TEI_NS, "fileDesc"));
...@@ -154,7 +155,7 @@ private void writeHeader(ObjectType object) throws XMLStreamException { ...@@ -154,7 +155,7 @@ private void writeHeader(ObjectType object) throws XMLStreamException {
writer.add(eventFactory.createEndElement("", TEI_NS, "teiHeader")); writer.add(eventFactory.createEndElement("", TEI_NS, "teiHeader"));
} }
private void writeSimpleTEIElement(String element, final String content) throws XMLStreamException { private void writeSimpleTEIElement(final String element, final String content) throws XMLStreamException {
writer.add(eventFactory.createStartElement("", TEI_NS, element)); writer.add(eventFactory.createStartElement("", TEI_NS, element));
writer.add(eventFactory.createCharacters(content)); writer.add(eventFactory.createCharacters(content));
writer.add(eventFactory.createEndElement("", TEI_NS, element)); writer.add(eventFactory.createEndElement("", TEI_NS, element));
...@@ -165,7 +166,11 @@ private void writeXML(final OutputStream output, final ObjectType object) { ...@@ -165,7 +166,11 @@ private void writeXML(final OutputStream output, final ObjectType object) {
final Holder<MetadataContainerType> mdHolder = new Holder<MetadataContainerType>(); final Holder<MetadataContainerType> mdHolder = new Holder<MetadataContainerType>();
final Holder<DataHandler> dhHolder = new Holder<DataHandler>(); final Holder<DataHandler> dhHolder = new Holder<DataHandler>();
try { try {
teiCorpus.getCRUDService().read("", "", object.getGeneric().getGenerated().getTextgridUri().getValue(), mdHolder, repository.getCRUDService().read(
"",
"",
object.getGeneric().getGenerated().getTextgridUri()
.getValue(), mdHolder,
dhHolder); dhHolder);
final XMLEventReader reader = inputFactory.createFilteredReader( final XMLEventReader reader = inputFactory.createFilteredReader(
inputFactory.createXMLEventReader(dhHolder.value.getInputStream()), inputFactory.createXMLEventReader(dhHolder.value.getInputStream()),
......
package info.textgrid.services.aggregator;
import info.textgrid.middleware.confclient.ConfservClient;
import info.textgrid.middleware.confclient.ConfservClientConstants;
import info.textgrid.middleware.tgsearch.client.SearchClient;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService_Service;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.WebApplicationException;
import javax.xml.stream.XMLStreamException;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.MTOMFeature;
import org.codehaus.jettison.json.JSONException;
public class TextGridRepProvider implements ITextGridRep {
private HashMap<String, String> config;
private ConfservClient confservClient;
private TGCrudService crud;
private SearchClient publicSearchClient;
private static final String CONF_ENDPOINT = "https://www.textgridlab.org/1.0/confserv";
private static final ITextGridRep instance = new TextGridRepProvider();
@Override
public String getConfValue(final String key) throws WebApplicationException {
if (config == null) {
try {
confservClient = new ConfservClient(CONF_ENDPOINT);
config = confservClient.getAll();
} catch (final IOException e) {
throw new WebApplicationException(e);
} catch (final JSONException e) {
throw new WebApplicationException(e);
} catch (final XMLStreamException e) {
throw new WebApplicationException(e);
}
}
return config.get(key);
}
@Override
public TGCrudService getCRUDService() {
if (crud == null) {
final URL wsdl = TGCrudService_Service.class.getResource("/wsdl/TGCrudService.wsdl");
final TGCrudService_Service tgCrudService_Service = new TGCrudService_Service(wsdl);
final TGCrudService _crud = tgCrudService_Service.getTGCrudPort(new MTOMFeature());
final BindingProvider bp = (BindingProvider) _crud;
final Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getConfValue(ConfservClientConstants.TG_CRUD));
crud = _crud;
}
return crud;
}
@Override
public SearchClient getPublicSearchClient() {
if (publicSearchClient == null)
publicSearchClient = new SearchClient(getConfValue(ConfservClientConstants.TG_SEARCH_PUBLIC));
return publicSearchClient;
}
public static ITextGridRep getInstance() {
return instance;
}
}
...@@ -10,6 +10,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/sch ...@@ -10,6 +10,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/sch
http://cxf.apache.org/jaxrs http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd"> http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<context:property-placeholder/> <context:property-placeholder/>
......
...@@ -7,15 +7,20 @@ ...@@ -7,15 +7,20 @@
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import org.junit.Test; import org.junit.Test;
import org.springframework.stereotype.Service;
public class TEICorpusTest { @Service
public class TextGridRepTest {
private TEICorpus teicorpus; private final ITextGridRep repository = TextGridRepProvider.getInstance();
TEICorpus getTeiCorpus() { ITextGridRep getTeiCorpus() {
if (teicorpus == null) return repository;
teicorpus = new TEICorpus(); }
return teicorpus;
@Test
public void testAutoWire() {
assertNotNull(repository);
} }
@Test @Test
...@@ -33,7 +38,7 @@ public void testGetCRUDService() { ...@@ -33,7 +38,7 @@ public void testGetCRUDService() {
@Test @Test
public void testGetSearchClient() { public void testGetSearchClient() {
final SearchClient searchClient = getTeiCorpus().getSearchClient(); final SearchClient searchClient = getTeiCorpus().getPublicSearchClient();
assertNotNull("TG-search service is null!?", searchClient); assertNotNull("TG-search service is null!?", searchClient);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment