/**
  * Add a numeric range facet.
  *
  * @param field The field
  * @param start The start of range
  * @param end The end of the range
  * @param gap The gap between each count
  * @return this
  */
 public SolrQuery addDateRangeFacet(String field, Date start, Date end, String gap) {
   add(FacetParams.FACET_RANGE, field);
   add(
       String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_START),
       DateUtil.getThreadLocalDateFormat().format(start));
   add(
       String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_END),
       DateUtil.getThreadLocalDateFormat().format(end));
   add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_GAP), gap);
   this.set(FacetParams.FACET, true);
   return this;
 }
  private Long retrieveLastUpdateDate(ArtifactVersionBean artifactVersionBean) {
    HttpClient httpClient = new DefaultHttpClient();
    String url =
        String.format(
            configurer.getArtifactVersionRepositoryPomUrl(),
            artifactVersionBean.getGroupId().replace(".", "/"),
            artifactVersionBean.getArtifactId(),
            artifactVersionBean.getVersion());
    HttpHead httpHead = new HttpHead(url);
    httpHead.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);

    // The possible errors here are considered as secondary and will not be seen by the user
    // We may want to reconsider it
    try {
      HttpResponse response = httpClient.execute(httpHead);
      Header lastUpdateDate = response.getFirstHeader(LAST_MODIFIED_HEADER);
      if (lastUpdateDate != null) {
        return DateUtil.parseDate(lastUpdateDate.getValue()).getTime();
      }
      LOGGER.error(
          "An error occurred while retrieving the last update date for "
              + artifactVersionBean.getId());
    } catch (Exception e) {
      LOGGER.error(
          "An error occurred while retrieving the last update date for "
              + artifactVersionBean.getId(),
          e);
    }
    return null;
  }
Пример #3
0
  public static void writeXML(SolrInputDocument doc, Writer writer) throws IOException {
    writer.write("<doc boost=\"" + doc.getDocumentBoost() + "\">");

    for (SolrInputField field : doc) {
      float boost = field.getBoost();
      String name = field.getName();
      for (Object v : field) {
        if (v instanceof Date) {
          v = DateUtil.getThreadLocalDateFormat().format((Date) v);
        } else if (v instanceof byte[]) {
          byte[] bytes = (byte[]) v;
          v = Base64.byteArrayToBase64(bytes, 0, bytes.length);
        } else if (v instanceof ByteBuffer) {
          ByteBuffer bytes = (ByteBuffer) v;
          v =
              Base64.byteArrayToBase64(
                  bytes.array(), bytes.position(), bytes.limit() - bytes.position());
        }

        if (boost != 1.0f) {
          XML.writeXML(writer, "field", v.toString(), "name", name, "boost", boost);
        } else if (v != null) {
          XML.writeXML(writer, "field", v.toString(), "name", name);
        }

        // only write the boost for the first multi-valued field
        // otherwise, the used boost is the product of all the boost values
        boost = 1.0f;
      }
    }
    writer.write("</doc>");
  }
 /** Parse a date string in the standard format, or any supported by DateUtil.parseDate */
 public Date parseDateLenient(String s, SolrQueryRequest req) throws ParseException {
   // request could define timezone in the future
   try {
     return fmtThreadLocal.get().parse(s);
   } catch (Exception e) {
     return DateUtil.parseDate(s);
   }
 }
  private static SeadEvent getEvent(SolrDocument doc) {
    SeadEvent event = new SeadEvent();

    event.setId(get(doc, EntityField.ID));

    Date date = (Date) doc.getFirstValue(EventField.DATE.solrName());

    if (date != null) {
      event.setDate(DateUtil.getThreadLocalDateFormat().format(date));
    }

    event.setDetail(getFirst(doc, EventField.DETAIL));
    event.setOutcome(getFirst(doc, EventField.OUTCOME));
    event.setEventType(getFirst(doc, EventField.TYPE));
    event.setTargets(getEntityRefSet(doc, EventField.TARGET));
    event.setAlternateIds(getResourceIdentifierSet(doc));

    SeadLogDetail logDetail = new SeadLogDetail();

    //   if (has(doc, DetailLogField.IPADDRESS)) {

    logDetail.setIpAddress(
        (String) doc.getFieldValue(SeadSolrField.DetailLogField.IPADDRESS.solrName()));
    //  }
    if (has(doc, SeadSolrField.DetailLogField.USERAGENT)) {

      logDetail.setUserAgent(
          (String) doc.getFieldValue(SeadSolrField.DetailLogField.USERAGENT.solrName()));
    }
    if (has(doc, SeadSolrField.DetailLogField.SUBJECT)) {

      logDetail.setSubject(
          (String) doc.getFieldValue(SeadSolrField.DetailLogField.SUBJECT.solrName()));
    }
    if (has(doc, SeadSolrField.DetailLogField.NODEIDENTIFIER)) {

      logDetail.setNodeIdentifier(
          (String) doc.getFieldValue(SeadSolrField.DetailLogField.NODEIDENTIFIER.solrName()));
    }

    event.setLogDetail(logDetail);

    return event;
  }
  private static DcsEntity getDeliverableUnit(SolrDocument doc) {
    SeadDeliverableUnit du = new SeadDeliverableUnit();

    du.setId(get(doc, EntityField.ID));

    if (has(doc, CoreMetadataField.RIGHTS)) {
      du.setRights(get(doc, CoreMetadataField.RIGHTS));
    }

    du.setCollections(getCollectionRefSet(doc, DeliverableUnitField.COLLECTIONS));
    du.setFormerExternalRefs(getStringSet(doc, DeliverableUnitField.FORMER_REFS));

    if (has(doc, CoreMetadataField.TITLE)) {
      du.setTitle(getFirst(doc, CoreMetadataField.TITLE));
    }

    if (has(doc, SeadSolrField.EntityField.ABSTRACT)) {
      String abstrct = get(doc, SeadSolrField.EntityField.ABSTRACT);
      abstrct = StringEscapeUtils.unescapeHtml(abstrct);
      du.setAbstrct(abstrct);
    }

    if (has(doc, SeadSolrField.EntityField.PUBDATE)) {
      String pubdate = getFirst(doc, SeadSolrField.EntityField.PUBDATE);
      du.setPubdate(pubdate);
    }

    if (has(doc, SeadSolrField.EntityField.MDUPDATE_DATE)) {
      Date date = (Date) doc.getFirstValue(SeadSolrField.EntityField.MDUPDATE_DATE.solrName());

      if (date != null) {
        du.setMetadataUpdateDate(DateUtil.getThreadLocalDateFormat().format(date));
      }
    }

    //        if (has(doc, DeliverableUnitField.LOCATION)) {
    //            String location = getFirst(doc, DeliverableUnitField.LOCATION);
    //            du.addSite(location);
    //        }

    du.setSites(getStringSet(doc, SeadSolrField.DeliverableUnitField.LOCATION));

    if (has(doc, SeadSolrField.DeliverableUnitField.SIZEBYTES)) {
      long size = (Long) doc.getFirstValue(SeadSolrField.DeliverableUnitField.SIZEBYTES.solrName());
      if (size > 0) {
        du.setSizeBytes(size);
      }
    }

    if (has(doc, SeadSolrField.DeliverableUnitField.FILENO)) {
      long fileNo = (Long) doc.getFirstValue(SeadSolrField.DeliverableUnitField.FILENO.solrName());
      if (fileNo > 0) {
        du.setFileNo(fileNo);
      }
    }

    if (has(doc, SeadSolrField.CoreMetadataField.CONTACT)) {
      String contact = getFirst(doc, SeadSolrField.CoreMetadataField.CONTACT);
      du.setContact(contact);
    }

    du.setCollections(getCollectionRefSet(doc, DeliverableUnitField.COLLECTIONS));
    du.setFormerExternalRefs(getStringSet(doc, DeliverableUnitField.FORMER_REFS));

    if (has(doc, DeliverableUnitField.DIGITAL_SURROGATE)) {
      du.setDigitalSurrogate(
          (Boolean) doc.getFieldValue(DeliverableUnitField.DIGITAL_SURROGATE.solrName()));
    }

    du.setMetadataRef(getMetadataRefSet(doc, EntityField.METADATA_REF));
    du.setMetadata(getMetadataSet(doc));
    du.setRelations(getRelations(doc));
    du.setParents(getDeliverableUnitRefSet(doc, DeliverableUnitField.PARENT));

    du.setSubjects(getStringSet(doc, CoreMetadataField.SUBJECT));
    du.setDataContributors(getCreatorSet(doc));
    du.setSubmitter(getSubmitter(doc));
    du.setAlternateIds(getResourceIdentifierSet(doc));
    SeadDataLocation primaryDataLocation = getPrimaryDataLocation(doc);
    du.setPrimaryLocation(primaryDataLocation);
    du.setSecondaryDataLocations(getSecondaryDataLocationSet(doc));

    if (has(doc, CoreMetadataField.TYPE)) {
      du.setType(getFirst(doc, CoreMetadataField.TYPE));
    }

    return du;
  }
  private static DcsFile getFile(SolrDocument doc) {
    SeadFile file = new SeadFile();

    file.setId(get(doc, EntityField.ID));
    file.setFixity(getFixitySet(doc));
    file.setFormats(getFormatSet(doc));
    file.setExtant((Boolean) doc.getFieldValue(FileField.EXTANT.solrName()));

    if (has(doc, FileField.VALID)) {
      file.setValid((Boolean) doc.getFieldValue(FileField.VALID.solrName()));
    }

    if (has(doc, FileField.NAME)) {
      file.setName(getFirst(doc, FileField.NAME));
    }

    if (has(doc, FileField.SOURCE)) {
      file.setSource(getFirst(doc, FileField.SOURCE));
    }

    if (has(doc, SeadSolrField.EntityField.IMMEDIATEANCESTRY)) {
      file.setParent(getFirst(doc, SeadSolrField.EntityField.IMMEDIATEANCESTRY));
    }

    if (has(doc, SeadSolrField.EntityField.MDUPDATE_DATE)) {
      Object object = doc.getFirstValue(SeadSolrField.EntityField.MDUPDATE_DATE.solrName());
      if (object instanceof Date) {
        Date date = (Date) object;

        if (date != null) {
          file.setMetadataUpdateDate(DateUtil.getThreadLocalDateFormat().format(date));
        }
      } else {

        if (object != null) {
          file.setMetadataUpdateDate(object.toString());
        }
      }
    } else {
      file.setMetadataUpdateDate("2012-10-27T22:05:20.809Z");
    }

    if (has(doc, SeadSolrField.FileField.DEPOSITDATE)) {

      Object object = doc.getFirstValue(SeadSolrField.FileField.DEPOSITDATE.solrName());
      if (object instanceof Date) {
        Date date = (Date) object; // doc.getFirstValue(FileField.DEPOSITDATE.solrName());

        if (date != null) {
          file.setDepositDate(DateUtil.getThreadLocalDateFormat().format(date));
        }
      } else {

        if (object != null) {
          file.setDepositDate(object.toString());
        }
      }
    } else {
      file.setDepositDate("2012-10-27T22:05:20.809Z");
    }

    long size = (Long) doc.getFirstValue(FileField.SIZE.solrName());
    if (size > 0) {
      file.setSizeBytes(size);
    }

    file.setMetadata(getMetadataSet(doc));
    file.setMetadataRef(getMetadataRefSet(doc, EntityField.METADATA_REF));
    file.setAlternateIds(getResourceIdentifierSet(doc));
    SeadDataLocation primaryDataLocation = getPrimaryDataLocation(doc);
    file.setPrimaryLocation(primaryDataLocation);

    file.setSecondaryDataLocations(getSecondaryDataLocationSet(doc));

    return file;
  }
Пример #8
0
  /**
   * Returns a formatter that can be use by the current thread if needed to convert Date objects to
   * the Internal representation.
   *
   * @deprecated use {@link org.apache.solr.common.util.DateUtil#getThreadLocalDateFormat()}
   */
  @Deprecated
  public static DateFormat getThreadLocalDateFormat() {

    return DateUtil.getThreadLocalDateFormat();
  }
Пример #9
0
 /**
  * Returns a formatter that can be use by the current thread if needed to convert Date objects to
  * the Internal representation.
  *
  * @throws ParseException
  * @throws DateParseException
  * @deprecated Use {@link org.apache.solr.common.util.DateUtil#parseDate(String)}
  */
 @Deprecated
 public static Date parseDate(String d) throws ParseException, DateParseException {
   return DateUtil.parseDate(d);
 }