Skip to content

Commit

Permalink
Adjusting logic #12
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Feb 3, 2019
1 parent f921205 commit cc869a1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
Expand Up @@ -79,8 +79,25 @@ public String retrieveByJournalMetadata(String title, String volume, String firs
return injectIdsByDoi(outputData.getJsonObject(), outputData.getDOI());
}

public void retrieveByJournalMetadataAsync(String title, String volume, String firstPage, Consumer<MatchingDocument> callback) {
metadataMatching.retrieveByMetadataAsync(title, volume, firstPage, matchingDocument -> {
public void retrieveByJournalMetadataAsync(String jtitle, String volume, String firstPage, String atitle, String firstAuthor, Boolean postValidate, Consumer<MatchingDocument> callback) {
metadataMatching.retrieveByMetadataAsync(jtitle, volume, firstPage, matchingDocument -> {
if (!matchingDocument.isException()) {
if (postValidate != null && postValidate) {
if (!areMetadataMatching(atitle, firstAuthor, matchingDocument, true)) {
callback.accept(new MatchingDocument(new NotFoundException("Article found but it didn't passed the postValidation.")));
return;
}
}

final String s = injectIdsByDoi(matchingDocument.getJsonObject(), matchingDocument.getDOI());
matchingDocument.setFinalJsonObject(s);
}
callback.accept(matchingDocument);
});
}

public void retrieveByJournalMetadataAsync(String jtitle, String volume, String firstPage, Consumer<MatchingDocument> callback) {
metadataMatching.retrieveByMetadataAsync(jtitle, volume, firstPage, matchingDocument -> {
if (!matchingDocument.isException()) {
final String s = injectIdsByDoi(matchingDocument.getJsonObject(), matchingDocument.getDOI());
matchingDocument.setFinalJsonObject(s);
Expand Down Expand Up @@ -117,10 +134,10 @@ private MatchingDocument validateJsonBody(Boolean postValidate, String firstAuth
throw new NotFoundException("Article not found");
}

if (postValidate != null && postValidate) {
if (postValidate != null && postValidate && isNotBlank(firstAuthor)) {
outputData = extractTitleAndFirstAuthorFromJson(outputData);

if (!areMetadataMatching(atitle, firstAuthor, outputData)) {
if (!areMetadataMatching(atitle, firstAuthor, outputData, true)) {
throw new NotFoundException("Article found but it didn't passed the post Validation.");
}
}
Expand Down Expand Up @@ -256,6 +273,7 @@ public void retrieveByBiblioAsync(String biblio, Boolean postValidate, String fi
//no title and author, extract with grobid. if grobid unavailable... it will fail.
if (isBlank(firstAuthor) && parseReference) {
try {
grobidClient.ping();
GrobidResponseStaxHandler.GrobidResponse response = grobidClient.processCitation(biblio, "0");
if (!areMetadataMatching(response.getAtitle(), response.getFirstAuthor(), matchingDocument, false)) {
callback.accept(new MatchingDocument(new NotFoundException("Article found but it didn't passed the postValidation.")));
Expand Down Expand Up @@ -314,10 +332,10 @@ public String fetchDOI(String input) {
* against the (incomplete) source bibliographic item to block
* inconsistent results.
*/
private boolean areMetadataMatching(String title, String firstAuthor, MatchingDocument result, boolean onlyAuthor) {
private boolean areMetadataMatching(String title, String firstAuthor, MatchingDocument result, boolean ignoreTitleIfNotPresent) {
boolean valid = true;

if (onlyAuthor) {
if (ignoreTitleIfNotPresent) {
if (isNotBlank(title)) {
if (ratcliffObershelpDistance(title, result.getTitle(), false) < 0.8)
return false;
Expand All @@ -330,7 +348,9 @@ private boolean areMetadataMatching(String title, String firstAuthor, MatchingDo
return valid;
}

/** default version checking title and authors **/
/**
* default version checking title and authors
**/
private boolean areMetadataMatching(String title, String firstAuthor, MatchingDocument result) {
return areMetadataMatching(title, firstAuthor, result, false);
}
Expand Down
Expand Up @@ -115,11 +115,11 @@ protected void getByQuery(
AsyncResponse asyncResponse
) {

boolean processed = false;
// boolean processed = false;
StringBuilder messagesSb = new StringBuilder();

if (isNotBlank(doi)) {
processed = true;
// processed = true;
try {
final String response = lookupEngine.retrieveByDoi(doi, postValidate, firstAuthor, atitle);

Expand All @@ -136,7 +136,7 @@ protected void getByQuery(
}

if (isNotBlank(pmid)) {
processed = true;
// processed = true;
try {
final String response = lookupEngine.retrieveByPmid(pmid, postValidate, firstAuthor, atitle);

Expand All @@ -150,7 +150,7 @@ protected void getByQuery(
}

if (isNotBlank(pmc)) {
processed = true;
// processed = true;
try {
final String response = lookupEngine.retrieveByPmid(pmc, postValidate, firstAuthor, atitle);
if (isNotBlank(response)) {
Expand All @@ -164,7 +164,7 @@ protected void getByQuery(
}

if (isNotBlank(istexid)) {
processed = true;
// processed = true;
try {
final String response = lookupEngine.retrieveByIstexid(istexid, postValidate, firstAuthor, atitle);

Expand All @@ -179,12 +179,12 @@ protected void getByQuery(
}

if (isNotBlank(atitle) && isNotBlank(firstAuthor)) {
processed = true;
// processed = true;
lookupEngine.retrieveByArticleMetadataAsync(atitle, firstAuthor, postValidate, matchingDocument -> {
if (matchingDocument.isException()) {
// error with article info - trying to match with journal infos (without first Page)
if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) {
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, matchingDocumentJournal -> {
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> {
if (matchingDocumentJournal.isException()) {

//error with journal info - trying to match biblio
Expand All @@ -209,7 +209,7 @@ protected void getByQuery(

// error with article info - trying to match with journal infos (with first Page)
if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) {
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, firstAuthor, matchingDocumentJournal -> {
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocumentJournal -> {
if (matchingDocumentJournal.isException()) {

//error with journal info - trying to match biblio
Expand Down Expand Up @@ -254,8 +254,8 @@ protected void getByQuery(
}

if (isNotBlank(jtitle) && isNotBlank(volume) && isNotBlank(firstPage)) {
processed = true;
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, matchingDocument -> {
// processed = true;
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> {
if (matchingDocument.isException()) {
//error with journal info - trying to match biblio
if (isNotBlank(biblio)) {
Expand All @@ -278,8 +278,8 @@ protected void getByQuery(
}

if (isNotBlank(jtitle) && isNotBlank(firstAuthor) && isNotBlank(volume) && isNotBlank(firstPage)) {
processed = true;
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, firstAuthor, matchingDocument -> {
// processed = true;
lookupEngine.retrieveByJournalMetadataAsync(jtitle, volume, firstPage, atitle, firstAuthor, postValidate, matchingDocument -> {
if (matchingDocument.isException()) {
//error with journal info - trying to match biblio
if (isNotBlank(biblio)) {
Expand All @@ -302,18 +302,22 @@ protected void getByQuery(
}

if (isNotBlank(biblio)) {
processed = true;
lookupEngine.retrieveByBiblioAsync(biblio, matchingDocument -> {
dispatchResponseOrException(asyncResponse, matchingDocument);
// processed = true;
lookupEngine.retrieveByBiblioAsync(biblio, postValidate, firstAuthor, atitle, parseReference, matchingDocumentBiblio -> {
if (matchingDocumentBiblio.isException()) {
asyncResponse.resume(matchingDocumentBiblio.getException());
} else {
asyncResponse.resume(matchingDocumentBiblio.getFinalJsonObject());
}
});
return;
}

if (!processed) {
// if (processed) {
// throw new ServiceException(404, messagesSb.toString());
// } else {
throw new ServiceException(400, "The supplied parameters were not sufficient to select the query");
} else {
throw new ServiceException(404, messagesSb.toString());
}
// }
}

/**
Expand Down

0 comments on commit cc869a1

Please sign in to comment.