Search in sources :

Example 1 with Temporal

use of org.opencastproject.metadata.dublincore.Temporal in project opencast by opencast.

the class SeriesServiceSolrIndex method createDocument.

/**
 * Creates solr document for inserting into solr index.
 *
 * @param dc
 *          {@link DublinCoreCatalog} to be stored in index
 * @return {@link SolrInputDocument} created out of Dublin core
 */
protected SolrInputDocument createDocument(DublinCoreCatalog dc) {
    final SolrInputDocument doc = new SolrInputDocument();
    String dublinCoreId = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
    String orgId = securityService.getOrganization().getId();
    doc.addField(SolrFields.COMPOSITE_ID_KEY, getCompositeKey(dublinCoreId, orgId));
    doc.addField(SolrFields.ORGANIZATION, orgId);
    doc.addField(SolrFields.IDENTIFIER_KEY, dublinCoreId);
    try {
        doc.addField(SolrFields.XML_KEY, serializeDublinCore(dc));
    } catch (IOException e1) {
        throw new IllegalArgumentException(e1);
    }
    doc.addField(SolrFields.OPT_OUT, false);
    // single valued fields
    if (dc.hasValue(DublinCore.PROPERTY_TITLE)) {
        doc.addField(SolrFields.TITLE_KEY, dc.getFirst(DublinCore.PROPERTY_TITLE));
        doc.addField(SolrFields.TITLE_KEY + "_sort", dc.getFirst(DublinCore.PROPERTY_TITLE));
    }
    if (dc.hasValue(DublinCore.PROPERTY_CREATED)) {
        final Temporal temporal = EncodingSchemeUtils.decodeTemporal(dc.get(DublinCore.PROPERTY_CREATED).get(0));
        temporal.fold(new Temporal.Match<Void>() {

            @Override
            public Void period(DCMIPeriod period) {
                doc.addField(SolrFields.CREATED_KEY, period.getStart());
                return null;
            }

            @Override
            public Void instant(Date instant) {
                doc.addField(SolrFields.CREATED_KEY, instant);
                return null;
            }

            @Override
            public Void duration(long duration) {
                throw new IllegalArgumentException("Dublin core dc:created is neither a date nor a period");
            }
        });
    }
    if (dc.hasValue(DublinCore.PROPERTY_AVAILABLE)) {
        Temporal temporal = EncodingSchemeUtils.decodeTemporal(dc.get(DublinCore.PROPERTY_AVAILABLE).get(0));
        temporal.fold(new Temporal.Match<Void>() {

            @Override
            public Void period(DCMIPeriod period) {
                if (period.hasStart()) {
                    doc.addField(SolrFields.AVAILABLE_FROM_KEY, period.getStart());
                }
                if (period.hasEnd()) {
                    doc.addField(SolrFields.AVAILABLE_TO_KEY, period.getEnd());
                }
                return null;
            }

            @Override
            public Void instant(Date instant) {
                doc.addField(SolrFields.AVAILABLE_FROM_KEY, instant);
                return null;
            }

            @Override
            public Void duration(long duration) {
                throw new IllegalArgumentException("Dublin core field dc:available is neither a date nor a period");
            }
        });
    }
    // multivalued fields
    addMultiValuedFieldToSolrDocument(doc, SolrFields.SUBJECT_KEY, dc.get(DublinCore.PROPERTY_SUBJECT));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.CREATOR_KEY, dc.get(DublinCore.PROPERTY_CREATOR));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.PUBLISHER_KEY, dc.get(DublinCore.PROPERTY_PUBLISHER));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.CONTRIBUTOR_KEY, dc.get(DublinCore.PROPERTY_CONTRIBUTOR));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.ABSTRACT_KEY, dc.get(DublinCore.PROPERTY_ABSTRACT));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.DESCRIPTION_KEY, dc.get(DublinCore.PROPERTY_DESCRIPTION));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.LANGUAGE_KEY, dc.get(DublinCore.PROPERTY_LANGUAGE));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.RIGHTS_HOLDER_KEY, dc.get(DublinCore.PROPERTY_RIGHTS_HOLDER));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.SPATIAL_KEY, dc.get(DublinCore.PROPERTY_SPATIAL));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.TEMPORAL_KEY, dc.get(DublinCore.PROPERTY_TEMPORAL));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.IS_PART_OF_KEY, dc.get(DublinCore.PROPERTY_IS_PART_OF));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.REPLACES_KEY, dc.get(DublinCore.PROPERTY_REPLACES));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.TYPE_KEY, dc.get(DublinCore.PROPERTY_TYPE));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.ACCESS_RIGHTS_KEY, dc.get(DublinCore.PROPERTY_ACCESS_RIGHTS));
    addMultiValuedFieldToSolrDocument(doc, SolrFields.LICENSE_KEY, dc.get(DublinCore.PROPERTY_LICENSE));
    return doc;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) Temporal(org.opencastproject.metadata.dublincore.Temporal) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

IOException (java.io.IOException)1 Date (java.util.Date)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 DCMIPeriod (org.opencastproject.metadata.dublincore.DCMIPeriod)1 Temporal (org.opencastproject.metadata.dublincore.Temporal)1