use of uk.ac.ebi.spot.goci.model.Publication in project goci by EBISPOT.
the class FilteringTest method testFilter.
@Test
public void testFilter() {
SingleNucleotidePolymorphism template = template(SingleNucleotidePolymorphism.class);
Filter<SingleNucleotidePolymorphism, String> filter = refine(template).on(template.getRsId()).hasValue("rs123456");
assertEquals("Filter type does not match expected", SingleNucleotidePolymorphism.class, filter.getFilteredType());
assertEquals("Filtered method does not match expected", "getRsId", filter.getFilteredMethod().getName());
assertEquals("Filtered value does not match expected", "rs123456", filter.getFilteredValues().get(0));
Association template2 = template(Association.class);
Filter<Association, Float> filter2 = refine(template2).on(template2.getPvalueMantissa()).hasValue(Float.valueOf("10"));
assertEquals("Filter type does not match expected", Association.class, filter2.getFilteredType());
assertEquals("Filtered method does not match expected", "getPvalueMantissa", filter2.getFilteredMethod().getName());
assertEquals(Float.valueOf("10"), filter2.getFilteredValues().get(0), 0.0d);
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
Date from = null;
Date to = null;
try {
from = df1.parse("2005-01-01");
to = df1.parse("2010-01-01");
} catch (ParseException e) {
e.printStackTrace();
}
String fromValue = df2.format(from).toString();
String toValue = df2.format(to).toString();
System.out.println(fromValue);
System.out.println(toValue);
Publication publication = template(Publication.class);
Filter dateFilter = refine(publication).on(publication.getPublicationDate()).hasRange(fromValue, toValue);
Filter dateFilter2 = refine(publication).on(publication.getPublicationDate()).hasRange(fromValue, toValue);
assertEquals("Filter type does not match expected", Publication.class, dateFilter.getFilteredType());
assertEquals("Filtered method does not match expected", "getPublicationDate", dateFilter.getFilteredMethod().getName());
assertEquals("Filtered value does not match expected", "2010-01-01T00:00:00.0", dateFilter.getFilteredRange().to());
assertEquals("Hashcodes of the two date filters differ", dateFilter.hashCode(), dateFilter2.hashCode());
}
use of uk.ac.ebi.spot.goci.model.Publication in project goci by EBISPOT.
the class EuropePMCDeserializer method getPublicatonInfo.
public Publication getPublicatonInfo(JsonNode info) {
Publication publication = new Publication();
JsonNode root = info.get("resultList").get("result").get(0);
System.out.println("Publication");
publication.setPubmedId(root.get("pmid").asText());
// publication.setPublicationDate(root.get("firstPublicationDate").asText());
publication.setPublication(root.get("journalInfo").get("journal").get("medlineAbbreviation").asText());
publication.setTitle(root.get("title").asText());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
/**
* Priority to eletronicDate. *
*/
String datePublication = "";
if (root.has("electronicPublicationDate")) {
datePublication = root.get("electronicPublicationDate").asText();
} else {
if (root.get("journalInfo").has("printPublicationDate")) {
datePublication = root.get("journalInfo").get("printPublicationDate").asText();
}
}
if (datePublication.contains("/")) {
datePublication = datePublication.replace("/", "-");
}
java.util.Date studyDate = null;
try {
studyDate = format.parse(datePublication);
} catch (ParseException e1) {
e1.printStackTrace();
}
publication.setPublicationDate(new Date(studyDate.getTime()));
return publication;
}
use of uk.ac.ebi.spot.goci.model.Publication in project goci by EBISPOT.
the class PussycatGOCIController method setDateFilter.
private Filter setDateFilter(String dateMin, String dateMax) {
Filter dateFilter;
DateFormat df_input = new SimpleDateFormat("yyyy-MM-dd");
Date to, from;
try {
if (dateMax != null) {
int endYearVar = Integer.parseInt(dateMax.split("-")[0]);
int endMonthVar = Integer.parseInt(dateMax.split("-")[1]);
String end_month, end_year;
// API call provides date for "up to and including the end of" - must increment month for query
if (endMonthVar == 12) {
end_month = "01";
endYearVar++;
end_year = Integer.toString(endYearVar);
} else {
endMonthVar++;
if (endMonthVar > 9) {
end_month = Integer.toString(endMonthVar);
} else {
end_month = "0".concat(Integer.toString(endMonthVar));
}
end_year = Integer.toString(endYearVar);
}
to = df_input.parse(end_year + "-" + end_month + "-01");
} else {
// change to use today's date
to = df_input.parse(df_input.format(new Date()));
}
if (dateMin != null) {
from = df_input.parse(dateMin + "-01");
} else {
from = df_input.parse("2005-01-01");
}
Calendar fromValue = Calendar.getInstance();
fromValue.setTime(from);
Calendar toValue = Calendar.getInstance();
toValue.setTime(to);
// Study study = template(Study.class);
// dateFilter = refine(study).on(study.getPublicationId().getPublicationDate()).hasRange(fromValue, toValue);
Publication publication = template(Publication.class);
dateFilter = refine(publication).on(publication.getPublicationDate()).hasRange(fromValue, toValue);
} catch (ParseException e) {
getLog().error("Bad date in URL for date range '" + dateMin + "' to '" + dateMax, e);
throw new RuntimeException("Bad date in URL for date range '" + dateMin + "' to '" + dateMax, e);
}
return dateFilter;
}
use of uk.ac.ebi.spot.goci.model.Publication in project goci by EBISPOT.
the class PublicationOperationsService method addPublication.
@Transactional
public Publication addPublication(String pubmedId, EuropePMCData europePMCResult, Boolean newImport) throws Exception {
Publication publication = publicationService.createOrFindByPumedId(pubmedId);
publication.setPubmedId(pubmedId);
publication.setPublication(europePMCResult.getPublication().getPublication());
publication.setTitle(europePMCResult.getPublication().getTitle());
// The date was already curated. So we don't want to import again this data
if (newImport) {
publication.setPublicationDate(europePMCResult.getPublication().getPublicationDate());
}
publicationService.save(publication);
authorOperationsService.addAuthorsToPublication(publication, europePMCResult);
addFirstAuthorToPublication(publication, europePMCResult);
return publication;
}
use of uk.ac.ebi.spot.goci.model.Publication in project goci by EBISPOT.
the class PublicationOperationsService method importNewPublications.
// Import the a list of pubmedid
public ArrayList<HashMap<String, String>> importNewPublications(String pubmedIdList, SecureUser currentUser) {
getLog().info("Importing publications: {}", pubmedIdList);
ArrayList<HashMap<String, String>> listPublications = new ArrayList<>();
String regex = "[0-9, /,]+";
// Remove whitespace
String pubmedIdListTrim = pubmedIdList.trim();
if (!pubmedIdListTrim.matches(regex)) {
getLog().error("Error found when parsing publication list: Pubmed list must be number follow by comma");
HashMap<String, String> error = new HashMap<String, String>();
error.put("pubmedId", "general");
error.put("error", "Pubmed List must be number follow by comma");
listPublications.add(error);
return listPublications;
}
List<String> pubmedIds = Arrays.asList(pubmedIdListTrim.split("\\s*,\\s*"));
for (String pubmedId : pubmedIds) {
HashMap<String, String> pubmedResult = new HashMap<String, String>();
pubmedId = pubmedId.trim();
if (pubmedId == "") {
getLog().error("Error found when processing pubmed entry: Found empty Pubmed ID");
pubmedResult.put("pubmedId", "general");
pubmedResult.put("error", "Empty pubmed id - The pubmedId is mandatory");
listPublications.add(pubmedResult);
}
// Check if there is an existing study with the same pubmed id
Collection<Study> existingStudies = publicationService.findStudiesByPubmedId(pubmedId);
if (existingStudies != null) {
pubmedResult.put("pubmedId", "general");
pubmedResult.put("error", "Pubmed " + pubmedId + " already exists.");
listPublications.add(pubmedResult);
} else {
// Study importedStudy = defaultPubMedSearchService.findPublicationSummary(pubmedId);
try {
getLog().debug("Publication ");
getLog().debug(pubmedId);
Publication publication = importSinglePublication(pubmedId, true);
Study importedStudy = new Study();
importedStudy.setPublicationId(publication);
Study savedStudy = studyOperationsService.createStudy(importedStudy, currentUser);
pubmedResult.put("pubmedId", pubmedId);
pubmedResult.put("author", savedStudy.getPublicationId().getFirstAuthor().getFullname());
pubmedResult.put("title", savedStudy.getPublicationId().getTitle());
pubmedResult.put("study_id", "studies/" + savedStudy.getId().toString());
listPublications.add(pubmedResult);
// Create directory to store associated files
studyFileService.createStudyDir(savedStudy.getId());
} catch (NoStudyDirectoryException e) {
getLog().error("No study directory exception");
pubmedResult.put("pubmedId", "general");
pubmedResult.put("error", "No study directory exception for pubmed: " + pubmedId);
listPublications.add(pubmedResult);
} catch (PubmedLookupException ple) {
getLog().error("Encountered Pubmed lookup exception: {}", ple.getMessage(), ple);
pubmedResult.put("pubmedId", "general");
pubmedResult.put("error", "Pubmed " + pubmedId + " lookup exception: " + ple.getMessage());
listPublications.add(pubmedResult);
} catch (Exception e) {
getLog().error("Encountered error: {}", e.getMessage(), e);
pubmedResult.put("pubmedId", "general");
pubmedResult.put("error", "Pubmed " + pubmedId + " encountered error: " + e.getMessage());
listPublications.add(pubmedResult);
}
}
}
return listPublications;
}
Aggregations