示例#1
0
  @Override
  public void askDetails(StoredDocumentList incomplete) {
    for (StoredDocument stored : incomplete) {
      String id = getDetailInfo(stored);
      if (id != null) {
        try {
          URI uri =
              new URI(
                  "http",
                  "www.mendeley.com",
                  "/oapi/documents/details/" + id,
                  "consumer_key=" + CONSUMER_KEY,
                  null);

          String json = getNet().read(uri, "UTF-8");
          json = json.replace("\"abstract\":", "\"abstrakt\":");
          MendeleyDocDetails docDetails = gson.fromJson(json, MendeleyDocDetails.class);

          if (docDetails != null) {
            Document document = stored.getDocument();
            String abstrakt = docDetails.getAbstrakt();
            if (abstrakt != null) {
              document.setFieldValue(Field.ABSTRACT, abstrakt);
            }
            String pages = docDetails.getPages();
            if (pages != null) {
              document.setFieldValue(Field.PAGES, pages);
            }
            String volume = docDetails.getVolume();
            if (volume != null) {
              document.setFieldValue(Field.VOLUME, volume);
            }
          }

          setDetailTimestampToCurrent(stored);
        } catch (JsonParseException e) {
          logger.error(e.getMessage(), e);
        } catch (URISyntaxException e) {
          logger.error(e.getMessage(), e);
        }
      }
    }
  }
示例#2
0
  @Override
  protected StoredDocumentList process(DocumentQuery query) {
    String q = queryConverter.convert(query.getQuery());

    try {
      URI uri =
          new URI(
              "http",
              "www.mendeley.com",
              "/oapi/documents/search/" + q,
              "consumer_key=" + CONSUMER_KEY + "&items=" + MAX_RESULTS,
              null);
      String json = getNet().read(uri, "UTF-8");
      MendeleySearchResult searchResult = gson.fromJson(json, MendeleySearchResult.class);

      if (searchResult != null) {
        Filter filter = new Filter(query);
        StoredDocumentList result = new StoredDocumentList();
        MendeleyDoc[] documents = searchResult.getDocuments();
        if (documents != null) {
          for (MendeleyDoc md : documents) {
            Document document = new TextDocument();
            document.setTitle(md.getTitle());
            document.setYear(md.getYear());
            document.addDetailURL(new URL(md.getMendeleyUrl()));
            document.setFieldValue(Field.DOI, md.getDoi());
            PersonList pl = new PersonList();
            pl.add(new Person(md.getAuthors()));
            document.setAuthorList(pl);

            if (filter.check(document)) {
              StoredDocument stored = new StoredDocument(document);
              stored.addSource(new SourceInfo(SOURCE_ID, md.getUuid()));
              result.add(stored);
            }
          }
        }
        return result;
      } else {
        return null;
      }

    } catch (IOException e) {
      logger.error(e.getMessage(), e);
      return null;
    } catch (JsonParseException e) {
      logger.error(e.getMessage(), e);
      return null;
    } catch (URISyntaxException e) {
      logger.error(e.getMessage(), e);
      return null;
    }
  }