Search in sources :

Example 1 with RecordRelatedIndexingException

use of eu.europeana.indexing.exception.RecordRelatedIndexingException in project metis-framework by europeana.

the class FullBeanPublisher method getSolrDocuments.

private SolrDocumentList getSolrDocuments(Map<String, String> queryParamMap) throws IndexerRelatedIndexingException, RecordRelatedIndexingException {
    MapSolrParams queryParams = new MapSolrParams(queryParamMap);
    QueryResponse response;
    try {
        response = solrServer.query(queryParams);
    } catch (SolrServerException e) {
        throw new IndexerRelatedIndexingException(SOLR_SERVER_SEARCH_ERROR, e);
    } catch (IOException e) {
        throw new RecordRelatedIndexingException(SOLR_SERVER_SEARCH_ERROR, e);
    }
    return response.getResults();
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IOException(java.io.IOException)

Example 2 with RecordRelatedIndexingException

use of eu.europeana.indexing.exception.RecordRelatedIndexingException in project metis-framework by europeana.

the class StringToFullBeanConverter method convertToRdf.

/**
 * Converts an input stream (XML of RDF) to an RDF object.
 *
 * @param record The record as an input stream. This stream is not closed.
 * @return The RDF instance.
 * @throws IndexingException In case there was a problem with the parsing or conversion.
 */
public RDF convertToRdf(InputStream record) throws IndexingException {
    // Convert string to RDF
    final RDF rdf;
    final IBindingFactory rdfBindingFactory = rdfBindingFactorySupplier.get();
    try {
        final IUnmarshallingContext context = rdfBindingFactory.createUnmarshallingContext();
        rdf = (RDF) context.unmarshalDocument(record, DEFAULT_CHARSET.name());
    } catch (JiBXException e) {
        throw new RecordRelatedIndexingException("Could not convert record to RDF.", e);
    }
    // Sanity check - shouldn't happen
    if (rdf == null) {
        throw new RecordRelatedIndexingException("Could not convert record to RDF: null was returned.");
    }
    // Done.
    return rdf;
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) RDF(eu.europeana.metis.schema.jibx.RDF) IBindingFactory(org.jibx.runtime.IBindingFactory) JiBXException(org.jibx.runtime.JiBXException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException)

Example 3 with RecordRelatedIndexingException

use of eu.europeana.indexing.exception.RecordRelatedIndexingException in project metis-framework by europeana.

the class FullBeanPublisher method publish.

/**
 * Publishes an RDF.
 *
 * @param rdf RDF to publish.
 * @param recordDate The date that would represent the created/updated date of a record
 * @param datasetIdsToRedirectFrom The dataset ids that their records need to be redirected
 * @param performRedirects flag that indicates if redirect should be performed
 * @throws IndexingException which can be one of:
 * <ul>
 * <li>{@link IndexerRelatedIndexingException} In case an error occurred during publication.</li>
 * <li>{@link SetupRelatedIndexingException} in case an error occurred during indexing setup</li>
 * <li>{@link RecordRelatedIndexingException} in case an error occurred related to record
 * contents</li>
 * </ul>
 */
private void publish(RdfWrapper rdf, Date recordDate, List<String> datasetIdsToRedirectFrom, boolean performRedirects) throws IndexingException {
    // Convert RDF to Full Bean.
    final RdfToFullBeanConverter fullBeanConverter = fullBeanConverterSupplier.get();
    final FullBeanImpl fullBean = fullBeanConverter.convertRdfToFullBean(rdf);
    // Provide the preprocessor: this will set the created and updated timestamps as needed.
    final TriConsumer<FullBeanImpl, FullBeanImpl, Pair<Date, Date>> fullBeanPreprocessor = preserveUpdateAndCreateTimesFromRdf ? EMPTY_PREPROCESSOR : (FullBeanPublisher::setUpdateAndCreateTime);
    // Perform redirection
    final List<Pair<String, Date>> recordsForRedirection;
    try {
        recordsForRedirection = RecordRedirectsUtil.checkAndApplyRedirects(recordRedirectDao, rdf, recordDate, datasetIdsToRedirectFrom, performRedirects, this::getSolrDocuments);
    } catch (RuntimeException e) {
        throw new RecordRelatedIndexingException(REDIRECT_PUBLISH_ERROR, e);
    }
    // Publish to Mongo
    final FullBeanImpl savedFullBean;
    try {
        savedFullBean = new FullBeanUpdater(fullBeanPreprocessor).update(fullBean, recordDate, recordsForRedirection.stream().map(Pair::getValue).min(Comparator.naturalOrder()).orElse(null), edmMongoClient);
    } catch (MongoIncompatibleDriverException | MongoConfigurationException | MongoSecurityException e) {
        throw new SetupRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
    } catch (MongoSocketException | MongoClientException | MongoInternalException | MongoInterruptedException e) {
        throw new IndexerRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
    } catch (RuntimeException e) {
        throw new RecordRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
    }
    // Publish to Solr
    try {
        retryableExternalRequestForNetworkExceptions(() -> {
            try {
                publishToSolr(rdf, savedFullBean);
            } catch (IndexingException e) {
                throw new RuntimeException(e);
            }
            return null;
        });
    } catch (Exception e) {
        throw new RecordRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
    }
}
Also used : MongoConfigurationException(com.mongodb.MongoConfigurationException) MongoClientException(com.mongodb.MongoClientException) MongoInterruptedException(com.mongodb.MongoInterruptedException) MongoIncompatibleDriverException(com.mongodb.MongoIncompatibleDriverException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) MongoInternalException(com.mongodb.MongoInternalException) MongoClientException(com.mongodb.MongoClientException) MongoConfigurationException(com.mongodb.MongoConfigurationException) MongoSocketException(com.mongodb.MongoSocketException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexingException(eu.europeana.indexing.exception.IndexingException) MongoInterruptedException(com.mongodb.MongoInterruptedException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IOException(java.io.IOException) MongoSecurityException(com.mongodb.MongoSecurityException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) MongoIncompatibleDriverException(com.mongodb.MongoIncompatibleDriverException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IndexingException(eu.europeana.indexing.exception.IndexingException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) FullBeanImpl(eu.europeana.corelib.solr.bean.impl.FullBeanImpl) MongoSecurityException(com.mongodb.MongoSecurityException) RdfToFullBeanConverter(eu.europeana.indexing.fullbean.RdfToFullBeanConverter) FullBeanUpdater(eu.europeana.indexing.mongo.FullBeanUpdater) MongoSocketException(com.mongodb.MongoSocketException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) Pair(org.apache.commons.lang3.tuple.Pair) MongoInternalException(com.mongodb.MongoInternalException)

Example 4 with RecordRelatedIndexingException

use of eu.europeana.indexing.exception.RecordRelatedIndexingException in project metis-framework by europeana.

the class FullBeanPublisher method publishToSolr.

private void publishToSolr(RdfWrapper rdf, FullBeanImpl fullBean) throws IndexingException {
    // Create Solr document.
    final SolrDocumentPopulator documentPopulator = new SolrDocumentPopulator();
    final SolrInputDocument document = new SolrInputDocument();
    documentPopulator.populateWithProperties(document, fullBean);
    documentPopulator.populateWithFacets(document, rdf);
    // Save Solr document.
    try {
        solrServer.add(document);
    } catch (IOException e) {
        throw new IndexerRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
    } catch (SolrServerException | RuntimeException e) {
        throw new RecordRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocumentPopulator(eu.europeana.indexing.solr.SolrDocumentPopulator) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IOException(java.io.IOException)

Example 5 with RecordRelatedIndexingException

use of eu.europeana.indexing.exception.RecordRelatedIndexingException in project metis-framework by europeana.

the class RdfTierUtils method setTierInternal.

private static void setTierInternal(RDF rdf, Tier tier) throws IndexingException {
    // Get the right instance of RdfTier.
    final RdfTier rdfTier = tiersByValue.get(tier);
    if (rdfTier == null) {
        throw new SetupRelatedIndexingException("Cannot find settings for tier value " + tier.getClass());
    }
    // Determine if there is something to reference and somewhere to add the reference.
    final RdfWrapper rdfWrapper = new RdfWrapper(rdf);
    final Set<String> aggregationAbouts = rdfWrapper.getAggregations().stream().filter(Objects::nonNull).map(Aggregation::getAbout).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
    if (aggregationAbouts.isEmpty()) {
        throw new RecordRelatedIndexingException("Cannot find provider aggregation in record.");
    }
    final EuropeanaAggregationType europeanaAggregation = rdfWrapper.getEuropeanaAggregation().orElseThrow(() -> new RecordRelatedIndexingException("Cannot find Europeana aggregation in record."));
    final String choAbout = Optional.ofNullable(europeanaAggregation.getAggregatedCHO()).map(AggregatedCHO::getResource).orElseThrow(() -> new RecordRelatedIndexingException("Cannot find aggregated CHO in Europeana aggregation."));
    final String annotationAboutBase = "/item" + choAbout;
    // Create the annotation
    final QualityAnnotation annotation = new QualityAnnotation();
    final Created created = new Created();
    created.setString(Instant.now().toString());
    annotation.setCreated(created);
    annotation.setHasTargetList(aggregationAbouts.stream().map(about -> {
        final HasTarget hasTarget = new HasTarget();
        hasTarget.setResource(about);
        return hasTarget;
    }).collect(Collectors.toList()));
    final HasBody hasBody = new HasBody();
    hasBody.setResource(rdfTier.getUri());
    annotation.setHasBody(hasBody);
    annotation.setAbout(annotationAboutBase + rdfTier.getAboutSuffix());
    // Add the annotation (remove all annotations with the same about)
    final Stream<QualityAnnotation> existingAnnotations = rdfWrapper.getQualityAnnotations().stream().filter(existingAnnotation -> !annotation.getAbout().equals(existingAnnotation.getAbout()));
    rdf.setQualityAnnotationList(Stream.concat(existingAnnotations, Stream.of(annotation)).collect(Collectors.toList()));
    // Add the link to the annotation to the europeana aggregation.
    final HasQualityAnnotation link = new HasQualityAnnotation();
    link.setResource(annotation.getAbout());
    final Stream<HasQualityAnnotation> existingLinks = Optional.ofNullable(europeanaAggregation.getHasQualityAnnotationList()).stream().flatMap(Collection::stream).filter(existingLink -> !link.getResource().equals(existingLink.getResource()));
    europeanaAggregation.setHasQualityAnnotationList(Stream.concat(existingLinks, Stream.of(link)).collect(Collectors.toList()));
}
Also used : HasQualityAnnotation(eu.europeana.metis.schema.jibx.HasQualityAnnotation) HasBody(eu.europeana.metis.schema.jibx.HasBody) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) HasTarget(eu.europeana.metis.schema.jibx.HasTarget) Created(eu.europeana.metis.schema.jibx.Created) Aggregation(eu.europeana.metis.schema.jibx.Aggregation) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) HasQualityAnnotation(eu.europeana.metis.schema.jibx.HasQualityAnnotation) QualityAnnotation(eu.europeana.metis.schema.jibx.QualityAnnotation) EuropeanaAggregationType(eu.europeana.metis.schema.jibx.EuropeanaAggregationType)

Aggregations

RecordRelatedIndexingException (eu.europeana.indexing.exception.RecordRelatedIndexingException)5 IndexerRelatedIndexingException (eu.europeana.indexing.exception.IndexerRelatedIndexingException)3 IOException (java.io.IOException)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 SetupRelatedIndexingException (eu.europeana.indexing.exception.SetupRelatedIndexingException)2 MongoClientException (com.mongodb.MongoClientException)1 MongoConfigurationException (com.mongodb.MongoConfigurationException)1 MongoIncompatibleDriverException (com.mongodb.MongoIncompatibleDriverException)1 MongoInternalException (com.mongodb.MongoInternalException)1 MongoInterruptedException (com.mongodb.MongoInterruptedException)1 MongoSecurityException (com.mongodb.MongoSecurityException)1 MongoSocketException (com.mongodb.MongoSocketException)1 FullBeanImpl (eu.europeana.corelib.solr.bean.impl.FullBeanImpl)1 IndexingException (eu.europeana.indexing.exception.IndexingException)1 RdfToFullBeanConverter (eu.europeana.indexing.fullbean.RdfToFullBeanConverter)1 FullBeanUpdater (eu.europeana.indexing.mongo.FullBeanUpdater)1 SolrDocumentPopulator (eu.europeana.indexing.solr.SolrDocumentPopulator)1 Aggregation (eu.europeana.metis.schema.jibx.Aggregation)1 Created (eu.europeana.metis.schema.jibx.Created)1 EuropeanaAggregationType (eu.europeana.metis.schema.jibx.EuropeanaAggregationType)1