Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you retrieve a record from a repository? #14

Open
mmalmeida opened this issue Jun 11, 2014 · 1 comment
Open

How do you retrieve a record from a repository? #14

mmalmeida opened this issue Jun 11, 2014 · 1 comment
Labels

Comments

@mmalmeida
Copy link

I am playing around with the framework and trying to retrieve a record (see test case below), but it is failing with something to do with the Transformers:

    at com.lyncode.xoai.xml.XSLPipeline.process(XSLPipeline.java:36)
    at com.lyncode.xoai.serviceprovider.parsers.RecordParser.parse(RecordParser.java:67)
    at com.lyncode.xoai.serviceprovider.parsers.GetRecordParser.parse(GetRecordParser.java:65)
    at com.lyncode.xoai.serviceprovider.handler.GetRecordHandler.handle(GetRecordHandler.java:45)
    at com.lyncode.xoai.serviceprovider.ServiceProvider.getRecord(ServiceProvider.java:61)

What is missing in the example? This is definitely that would be tackled in #13 .
Note that I've also tried without the context.withTransformer(t). withTransformer the code will reach the exception cycle with two transformers in the list, the one supplied and a null.

public class RemoteRepoTest {

    ServiceProvider underTest;

    @Before
    public void before() throws TransformerConfigurationException, TransformerFactoryConfigurationError{
        Context context = new Context().withBaseUrl("http://www.rcaap.pt/oai");
        Transformer t  = TransformerFactory.newInstance().newTransformer();
        context.withTransformer(t);
        HttpOAIClient client = new HttpOAIClient(context);
        context.withOAIClient(client);

        underTest = new ServiceProvider(context);

    }

    @Test
    public void remoteRepoTest() throws Exception {

        Identify identify = underTest.identify();
        assertEquals(identify.getRepositoryName(), "RCAAP - Repositório Científico de Acesso Aberto de Portugal");
    }

    @Test
    public void getRecord() throws Exception {
        GetRecordParameters parameters = new GetRecordParameters().withIdentifier("oai:digituma.uma.pt:10400.13/9").withMetadataFormatPrefix("oai_dc");
        Record record = underTest.getRecord(parameters);
        record.getAbouts();
    }
}
@mmalmeida
Copy link
Author

Following up on this, I advanced a bit, changing the @before (essentially adding the withMetadataTransformer to the context:

    @Before
    public void before() throws TransformerConfigurationException, TransformerFactoryConfigurationError{
        Transformer t  = TransformerFactory.newInstance().newTransformer();
        Context context = new Context().withBaseUrl("http://www.rcaap.pt/oai").
                withMetadataTransformer("oai_dc", t);
        HttpOAIClient client = new HttpOAIClient(context);

        context.withOAIClient(client);
        underTest = new ServiceProvider(context);

    }

The exception is now the one below - basically the MetadataParser breaks at "reader.next(elementName(localPart(equalTo("metadata"))));" since it cannot find an element called metadata.

java.util.NoSuchElementException
    at org.codehaus.stax2.ri.Stax2EventReaderImpl.throwEndOfInput(Stax2EventReaderImpl.java:453)
    at org.codehaus.stax2.ri.Stax2EventReaderImpl.nextEvent(Stax2EventReaderImpl.java:242)
    at com.lyncode.xml.XmlReader.next(XmlReader.java:132)
    at com.lyncode.xoai.serviceprovider.parsers.MetadataParser.parse(MetadataParser.java:39)
    at com.lyncode.xoai.serviceprovider.parsers.RecordParser.parse(RecordParser.java:67)
    at com.lyncode.xoai.serviceprovider.parsers.GetRecordParser.parse(GetRecordParser.java:65)
    at com.lyncode.xoai.serviceprovider.handler.GetRecordHandler.handle(GetRecordHandler.java:45)
    at com.lyncode.xoai.serviceprovider.ServiceProvider.getRecord(ServiceProvider.java:61)

It seems the code is trying to find the metadata element twice, because in the RecordParser.parse that preceeds this code the contents of the metadata tag are already being populated in a content String:

            reader.next(elementName(localPart(equalTo("metadata")))).next(aStartElement());
            String content = reader.retrieveCurrentAsString();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant