Some changes to the CSV importer for publications (this module is only for internal use)

git-svn-id: https://svn.libreccm.org/ccm/trunk@2087 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-03-17 13:02:27 +00:00
parent 9b263bec1a
commit 25f1478b6b
7 changed files with 121 additions and 55 deletions

View File

@ -8,8 +8,9 @@
<ccm:dependencies>
<ccm:requires name="ccm-core" version="6.6.0" relation="ge"/>
<ccm:requires name="ccm-cms" version="6.6.6" relation="ge"/>
<ccm:requires name="ccm-cms-assets-relatedlink" version="6.6.1" relation="ge"/>
<ccm:requires name="ccm-sci-publications" version="6.6.3" relation="ge"/>
<ccm:requires name="ccm-sci-publications-researchreport" version="6.6.3" relation="ge"/>
<!--<ccm:requires name="ccm-sci-publications-researchreport" version="6.6.3" relation="ge"/>-->
</ccm:dependencies>
<ccm:directories>

View File

@ -2,6 +2,8 @@ package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.categorization.Category;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.cms.contenttypes.Link;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.scipublications.importer.report.AuthorImportReport;
@ -136,6 +138,10 @@ abstract class AbstractPublicationImporter<T extends Publication> {
publication.setMisc(data.getMisc().substring(0, 3975));
}
if ((data.getUrl() != null) && !data.getUrl().isEmpty()) {
processUrl(publication);
}
publication.save();
}
@ -143,6 +149,10 @@ abstract class AbstractPublicationImporter<T extends Publication> {
processAuthors(publication);
}
if ((data.getSeriesTitle() != null) && !data.getSeriesTitle().isEmpty()) {
importerUtil.processSeries(publication, data.getSeriesTitle(), pretend);
}
return publication;
}
@ -163,7 +173,7 @@ abstract class AbstractPublicationImporter<T extends Publication> {
protected Integer getFolderId() {
return Publication.getConfig().getDefaultPublicationsFolder();
}
private void processTitleAndName(final T publication) {
if (!pretend) {
publication.setTitle(data.getTitle());
@ -179,17 +189,17 @@ abstract class AbstractPublicationImporter<T extends Publication> {
private void processYear(final T publication) {
if (!pretend) {
final String year = data.getYear();
try {
publication.setYearOfPublication(Integer.parseInt(year));
} catch(NumberFormatException ex) {
} catch (NumberFormatException ex) {
publication.setYearOfPublication(0);
}
}
report.addField(new FieldImportReport("year", data.getYear()));
}
private void processReviewed(final T publication) {
final String reviewedStr = data.getReviewed();
final boolean reviewed;
@ -258,29 +268,29 @@ abstract class AbstractPublicationImporter<T extends Publication> {
authors.add(author);
} else if (nameTokens.length == 2) {
final AuthorData author = new AuthorData();
author.setSurname(checkForEditor(author, nameTokens[0]));
author.setSurname(checkForEditor(author, nameTokens[0]));
author.setGivenName(checkForEditor(author, nameTokens[1]));
authors.add(author);
} else {
final AuthorData author = new AuthorData();
author.setSurname(checkForEditor(author, nameTokens[0]));
author.setSurname(checkForEditor(author, nameTokens[0]));
author.setGivenName(checkForEditor(author, nameTokens[1]));
authors.add(author);
}
}
}
private String checkForEditor(final AuthorData author, final String token) {
for(String editorStr : EDITOR_STRS) {
for (String editorStr : EDITOR_STRS) {
if (token.endsWith(editorStr)) {
author.setEditor(true);
return token.substring(0, token.length() - editorStr.length()).trim();
}
}
return token.trim();
}
@ -307,4 +317,29 @@ abstract class AbstractPublicationImporter<T extends Publication> {
}
}
protected void processUrl(final Publication publication) {
if (!pretend) {
final RelatedLink link = new RelatedLink();
link.setLinkOwner(publication);
link.setLinkListName("NONE");
link.setTargetItem(null);
link.setTargetURI(getData().getUrl());
link.setTargetType(Link.EXTERNAL_LINK);
link.setTargetWindow("");
if ((getData().getLinkname() == null) || getData().getLinkname().isEmpty()) {
link.setTitle(getData().getUrl());
} else {
link.setTitle(getData().getLinkname());
}
link.save();
}
report.addField(new FieldImportReport("url", getData().getUrl()));
if ((getData().getLinkname() != null) && !getData().getLinkname().isEmpty()) {
report.addField(new FieldImportReport("linkname", getData().getLinkname()));
}
}
}

View File

@ -47,6 +47,7 @@ class ArticleInCollectedVolumeImporter extends AbstractPublicationImporter<Artic
parseAuthors(data.getCollectedVolumeAuthors()),
data.getPublisher(),
data.getPlace(),
null,
isPretend()));
}

View File

@ -56,13 +56,13 @@ class ArticleInJournalImporter extends AbstractPublicationImporter<ArticleInJour
}
private void processVolume(final ArticleInJournal article) {
if ((getData().getVolume() != null) && !getData().getVolume().isEmpty()) {
if ((getData().getVolumeOfJournal() != null) && !getData().getVolumeOfJournal().isEmpty()) {
try {
final int volume = Integer.parseInt(getData().getVolume());
final int volume = Integer.parseInt(getData().getVolumeOfJournal());
if (!isPretend()) {
article.setVolume(volume);
}
getReport().addField(new FieldImportReport("Volume", getData().getVolume()));
getReport().addField(new FieldImportReport("Volume", getData().getVolumeOfJournal()));
} catch (NumberFormatException ex) {
getReport().addMessage(String.format("Failed to parse volume data in line '%d'.",
getData().getLineNumber()));

View File

@ -13,8 +13,8 @@ class CsvLine {
private final int lineNumber;
public CsvLine(final String[] cols, final int lineNumber) {
if (cols.length != 30) {
throw new IllegalArgumentException(String.format("Unexpected number of columns. Expected 30 columns, "
if (cols.length != 37) {
throw new IllegalArgumentException(String.format("Unexpected number of columns. Expected 37 columns, "
+ "but provided array has %d entries.", cols.length));
}
this.cols = Arrays.copyOf(cols, cols.length);
@ -93,55 +93,83 @@ class CsvLine {
return cols[16].trim();
}
public String getIssue() {
public String getVolumeOfJournal() {
return cols[17].trim();
}
public String getPublicationDate() {
public String getIssue() {
return cols[18].trim();
}
public String getJournal() {
public String getPublicationDate() {
return cols[19].trim();
}
public String getCollectedVolume() {
public String getJournal() {
return cols[20].trim();
}
public String getCollectedVolumeAuthors() {
public String getJournalSymbol() {
return cols[21].trim();
}
public String getIsbn() {
public String getCollectedVolume() {
return cols[22].trim();
}
public String getIssn() {
public String getCollectedVolumeAuthors() {
return cols[23].trim();
}
public String getLastAccess() {
public String getSeriesTitle() {
return cols[24].trim();
}
public String getUrl() {
public String getVolumeOfSeries() {
return cols[25].trim();
}
public String getUrn() {
public String getEditorOfSeries() {
return cols[26].trim();
}
public String getDoi() {
public String getOrganization() {
return cols[27].trim();
}
public String getConference() {
public String getUrl() {
return cols[28].trim();
}
public String getScope() {
public String getLinkname() {
return cols[29].trim();
}
public String getIsbn() {
return cols[30].trim();
}
public String getIssn() {
return cols[31].trim();
}
public String getLastAccess() {
return cols[32].trim();
}
public String getUrn() {
return cols[33].trim();
}
public String getDoi() {
return cols[34].trim();
}
public String getConference() {
return cols[35].trim();
}
public String getScope() {
return cols[36].trim();
}
}

View File

@ -28,7 +28,7 @@ import com.arsdigita.cms.contenttypes.InternetArticle;
import com.arsdigita.cms.contenttypes.Monograph;
import com.arsdigita.cms.contenttypes.Proceedings;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.ResearchReport;
//import com.arsdigita.cms.contenttypes.ResearchReport;
import com.arsdigita.cms.contenttypes.Review;
import com.arsdigita.cms.contenttypes.WorkingPaper;
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
@ -45,6 +45,7 @@ import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.TransactionContext;
import java.util.Arrays;
import java.util.Map;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import org.apache.log4j.Logger;
@ -85,6 +86,7 @@ public class PublicationsImporter implements SciPublicationsImporter {
@Override
public ImportReport importPublications(final String publications,
final Map<String, String> params,
final boolean pretend,
final boolean publishNewItems)
throws SciPublicationsImportException {
@ -113,7 +115,7 @@ public class PublicationsImporter implements SciPublicationsImporter {
importerUtil);
report.addPublication(result);
} catch (Exception ex) {
tctx.abortTxn();
tctx.abortTxn();
throw new SciPublicationsImportException(ex);
}
@ -132,11 +134,11 @@ public class PublicationsImporter implements SciPublicationsImporter {
final ImporterUtil importerUtil) {
final PublicationImportReport report = new PublicationImportReport();
final String[] cols = line.split(COL_SEP, -30);
final String[] cols = line.split(COL_SEP, -37);
//Check number of cols
if (cols.length != 30) {
if (cols.length != 37) {
report.setSuccessful(false);
report.addMessage(String.format("!!! Wrong number of columns. Exepcted 30 columns but found %d columns. "
report.addMessage(String.format("!!! Wrong number of columns. Exepcted 37 columns but found %d columns. "
+ "Skiping line %d!\n", cols.length, lineNumber));
return report;
}
@ -163,8 +165,8 @@ public class PublicationsImporter implements SciPublicationsImporter {
processProceedings(publishNewItems, data, report, pretend, importerUtil);
} else if (Review.class.getSimpleName().equals(data.getType())) {
processReview(publishNewItems, data, report, pretend, importerUtil);
} else if (ResearchReport.class.getSimpleName().equals(data.getType()) || "Report".equals(data.getType())) {
processResearchReport(publishNewItems, data, report, pretend, importerUtil);
// } else if (ResearchReport.class.getSimpleName().equals(data.getType()) || "Report".equals(data.getType())) {
// processResearchReport(publishNewItems, data, report, pretend, importerUtil);
} else if (WorkingPaper.class.getSimpleName().equals(data.getType())) {
processWorkingPaper(publishNewItems, data, report, pretend, importerUtil);
}
@ -315,20 +317,19 @@ public class PublicationsImporter implements SciPublicationsImporter {
}
private void processResearchReport(final boolean publishNewItems,
final CsvLine data,
final PublicationImportReport report,
final boolean pretend,
final ImporterUtil importerUtil) {
if (isPublicationAlreadyInDatabase(data, ResearchReport.class.getSimpleName(), report)) {
report.setSuccessful(true);
return;
}
final ResearchReportImporter importer = new ResearchReportImporter(data, report, pretend, importerUtil);
importer.doImport(publishNewItems);
}
// private void processResearchReport(final boolean publishNewItems,
// final CsvLine data,
// final PublicationImportReport report,
// final boolean pretend,
// final ImporterUtil importerUtil) {
// if (isPublicationAlreadyInDatabase(data, ResearchReport.class.getSimpleName(), report)) {
// report.setSuccessful(true);
// return;
// }
//
// final ResearchReportImporter importer = new ResearchReportImporter(data, report, pretend, importerUtil);
// importer.doImport(publishNewItems);
// }
private void processWorkingPaper(final boolean publishNewItems,
final CsvLine data,
final PublicationImportReport report,