zach-m / jonix

Commercial-grade library for extracting data from ONIX sources
Apache License 2.0
57 stars 17 forks source link

Jonix Unify #15

Closed nidhinprathap closed 4 years ago

nidhinprathap commented 4 years ago

HI, Using Unify can I get the additional details that are not available in base class.. Like Images, Contributor description etc.

For example right now to take Auther description I need to do the following:- product.contributors.findByRole(ContributorRoles.By_author).get(0).biographicalNote This will return the the 1st Authors description. What for Images,countries etc?

zach-m commented 4 years ago

There are various types of images.

For example, in Onix3, the typical way to find a Front Cover Url (although you have to check with your specific providers) is in ResourceLink tag, like that:

FrontCoverlUrl

So for example, with Jonix9 using streams syntax, given a Product object, you can do something like that:

List<String> frontCoverUrls =
    product.collateralDetail().supportingResources().stream()
        .filter(sr -> sr.resourceContentType().value == ResourceContentTypes.Front_cover).findFirst()
        .flatMap(sr -> sr.resourceVersions().stream()
            .filter(rv -> rv.resourceForm().value == ResourceForms.Downloadable_file)
            .findFirst().map(rv -> rv.resourceLinks().values()))
        .orElse(null);

Two important conditions here:

As there could be more than one, this code snippets will get you a list of the URLs in the order they appear in the ONIX file.

I hope this points you at the right direction.