Skip to content

Commit

Permalink
Merge pull request #12 from diging/develop
Browse files Browse the repository at this point in the history
prepare release
  • Loading branch information
jdamerow authored Mar 5, 2020
2 parents 5c8109c + 56c5d51 commit dc1d2b1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private ResponseEntity<?> makeApiCall(String url, String apiToken, Class<?> resp
}

// let's try again after getting a new OAuth token
entity = buildHeaders(apiToken);
response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
}
return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package edu.asu.diging.citesphere.importer.core.service.impl;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown=true)
public class JobInfo {

private String zotero;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package edu.asu.diging.citesphere.importer.core.service.parse.impl;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;

import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.io.input.BOMInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import edu.asu.diging.citesphere.importer.core.exception.HandlerTestException;
Expand All @@ -19,30 +26,52 @@

@Service
public class WoSHandler implements FileHandler {

@Autowired
private IArticleWoSTagParser parserRegistry;

@Value("${_citesphere_download_path}")
private String downloadPath;

@Override
public boolean canHandle(String path) throws HandlerTestException {
File file = new File(path);

try {
BOMInputStream inputStream = new BOMInputStream(FileUtils.openInputStream(file), false,
ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE,
ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE);
if (inputStream.hasBOM()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
File fileCopy = new File(file.getParent() + File.separator + "CopyOf" + file.getName());
while(reader.ready()) {
FileUtils.write(fileCopy, reader.readLine(), inputStream.getBOMCharsetName(), true);
}
reader.close();
Files.copy(fileCopy.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.deleteIfExists(fileCopy.toPath());
}
} catch (IOException e1) {
throw new HandlerTestException("Unsupported file format.", e1);
}

if (path.toLowerCase().endsWith(".txt") && !file.getName().startsWith(".")) {
try (LineIterator it = FileUtils.lineIterator(file)) {
int linesToRead = 10;
int linesRead = 0;

// we check the first 10 lines if they start with two capitals letters
// followed by a space; if they all match, we assume it's WoS' data format.
while (it.hasNext() && linesRead < linesToRead) {
String line = it.nextLine();
line = line.replaceAll("\\p{C}", "");
if (!line.matches("([A-Z0-9]{2}| {2})( .*$|$)") && !line.trim().isEmpty()) {
return false;
}
linesRead++;
}

return true;
} catch(IOException e) {
} catch (IOException e) {
throw new HandlerTestException("Could not read lines.", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,16 @@ public String processExtra(JsonNode node, BibEntry article) {
}

protected void fillContributorName(Contributor contributor, ObjectNode contributorNode) {
if (contributor.getGivenName() != null && !contributor.getGivenName().trim().isEmpty()
if (contributor.getFullGivenName() != null && !contributor.getFullGivenName().trim().isEmpty()
&& contributor.getFullSurname() != null && !contributor.getFullSurname().trim().isEmpty()) {
contributorNode.put("firstName", contributor.getFullGivenName());
contributorNode.put("lastName", contributor.getFullSurname());
} else if (contributor.getFullSurname() != null && !contributor.getFullSurname().trim().isEmpty()) {
contributorNode.put("name", contributor.getFullSurname());
} else if (contributor.getGivenName() != null && !contributor.getGivenName().trim().isEmpty()
&& contributor.getSurname() != null && !contributor.getSurname().trim().isEmpty()) {
contributorNode.put("firstName", contributor.getGivenName());
contributorNode.put("lastName", contributor.getSurname());

} else if (contributor.getGivenName() != null && !contributor.getGivenName().trim().isEmpty()) {
contributorNode.put("name", contributor.getGivenName());
} else if (contributor.getSurname() != null && !contributor.getSurname().trim().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,29 @@ private void fillPerson(Contributor contrib, ObjectNode creatorNode, int idx) {
if (contrib.getSurname() != null && !contrib.getSurname().isEmpty()) {
nameParts.add(contrib.getSurname());
}
creatorNode.put("name", String.join(" ", nameParts));
creatorNode.put("firstName", contrib.getGivenName());
creatorNode.put("lastName", contrib.getSurname());

List<String> fullNameParts = new ArrayList<>();
if (contrib.getFullGivenName() != null && !contrib.getFullGivenName().isEmpty()) {
fullNameParts.add(contrib.getFullGivenName());
}
if (contrib.getFullSurname() != null && !contrib.getFullSurname().isEmpty()) {
fullNameParts.add(contrib.getFullSurname());
}
if(fullNameParts.size() != 0) {
creatorNode.put("name", String.join(" ", fullNameParts));
creatorNode.put("firstName", contrib.getFullGivenName());
creatorNode.put("lastName", contrib.getFullSurname());
} else {
creatorNode.put("name", String.join(" ", nameParts));
creatorNode.put("firstName", contrib.getGivenName());
creatorNode.put("lastName", contrib.getSurname());
}
creatorNode.put("fullName", String.join(" ", fullNameParts));
creatorNode.put("fullFirstName", contrib.getFullGivenName());
creatorNode.put("fullLastName", contrib.getFullSurname());
creatorNode.put("standardizedName", String.join(" ", nameParts));
creatorNode.put("standardizedFirstName", contrib.getGivenName());
creatorNode.put("standardizedLastName", contrib.getSurname());
creatorNode.put("positionInList", idx);

ArrayNode affiliationArray = creatorNode.arrayNode();
Expand Down

0 comments on commit dc1d2b1

Please sign in to comment.