Commit 063c9f73 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Rename the method Automaton.check_by_field (origin) to get_by_field (origin).

parent adf646a7
......@@ -26,16 +26,63 @@ class Articles(Automaton):
# the preprint categories
self.id_preprint = get_id(self.db.categories, code="PRE")
def check_by_origin(self,
id_publisher=None,
my_authors=None,
oai_url=None,
pages=None,
publication_url=None,
title=None,
volume=None,
year=None):
"""Check that a record already exist using the origin field.
def check_record(self, record):
"""Check the content of the article in order to fix non conformities.
@type record: L{Record}
@param record:
@rtype: bool
@return: C{False} when a non conformity is found and can not be
corrected.
"""
if not Automaton.check_record(self, record):
return False
if self.dbg:
print "select article record"
try:
self.check.clean_erratum(record)
if not record.is_published():
self.logs[-1].reject(MSG_NO_EDITOR, record.year())
return False
self.check.my_authors(record,
reference=self._my_author_list(record),
cmpFct=family_name_fr)
self.check.oai(record)
self.check.submitted(record)
self.check.year(record)
self.check.paper_reference(record)
self.check.format_editor(record)
except CheckException as e:
self.logs[-1].reject(e, record.year())
return False
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
return True
def get_by_origin(self,
id_publisher=None,
my_authors=None,
oai_url=None,
pages=None,
publication_url=None,
title=None,
volume=None,
year=None):
"""Get an existing record using the origin field.
- Transform a preprint into article.
- Actions are logged.
......@@ -83,17 +130,17 @@ class Articles(Automaton):
return (rec_id, 1)
def check_by_fields(self,
id_publisher=None,
my_authors=None,
oai_url=None,
pages=None,
publication_url=None,
preprint_number=None,
title=None,
volume=None,
year=None):
"""Check that a record already exist using the fields: id_projects,
def get_by_fields(self,
id_publisher=None,
my_authors=None,
oai_url=None,
pages=None,
publication_url=None,
preprint_number=None,
title=None,
volume=None,
year=None):
"""Get a record matching the fields: id_projects,
id_publishers, id_teams, pages, volume and year.
- Fix the field origin when a match is found.
......@@ -116,7 +163,7 @@ class Articles(Automaton):
"""
if self.dbg:
print "check existing article by fields"
print "get existing article by fields"
db = self.db
......@@ -170,53 +217,6 @@ class Articles(Automaton):
return (rec_id, 1)
def check_record(self, record):
"""Check the content of the article in order to fix non conformities.
@type record: L{Record}
@param record:
@rtype: bool
@return: C{False} when a non conformity is found and can not be
corrected.
"""
if not Automaton.check_record(self, record):
return False
if self.dbg:
print "select article record"
try:
self.check.clean_erratum(record)
if not record.is_published():
self.logs[-1].reject(MSG_NO_EDITOR, record.year())
return False
self.check.my_authors(record,
reference=self._my_author_list(record),
cmpFct=family_name_fr)
self.check.oai(record)
self.check.submitted(record)
self.check.year(record)
self.check.paper_reference(record)
self.check.format_editor(record)
except CheckException as e:
self.logs[-1].reject(e, record.year())
return False
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
return True
def insert_record(self, record):
"""Insert an article in the database.
The method assume that erratum are removed.
......@@ -247,33 +247,33 @@ class Articles(Automaton):
id_publisher = self.get_create_publisher(editor)
id_collaboration = self.get_create_collaboration(record.collaboration())
# check against already published articles or preprint
# A preprint is transform itno an article.
# get already published articles or preprint
# A preprint is transform into an article.
#
# NOTE: The check is performed by origin then by fields.
# The latter is useful to cover the case where the record
# is entered by hand or by another haverster.
# is entered by hand or by another harvester.
#
rec_id, status = self.check_by_origin(id_publisher=id_publisher,
my_authors=record.my_authors,
oai_url=oai_url,
pages=pages,
publication_url=publication_url,
title=title,
volume=volume,
year=year)
rec_id, status = self.get_by_origin(id_publisher=id_publisher,
my_authors=record.my_authors,
oai_url=oai_url,
pages=pages,
publication_url=publication_url,
title=title,
volume=volume,
year=year)
if rec_id:
return status
rec_id, status = self.check_by_fields(id_publisher=id_publisher,
my_authors=record.my_authors,
oai_url=oai_url,
pages=pages,
publication_url=publication_url,
preprint_number=preprint_number,
title=title,
volume=volume,
year=year)
rec_id, status = self.get_by_fields(id_publisher=id_publisher,
my_authors=record.my_authors,
oai_url=oai_url,
pages=pages,
publication_url=publication_url,
preprint_number=preprint_number,
title=title,
volume=volume,
year=year)
if rec_id:
return status
......
......@@ -288,9 +288,43 @@ class Automaton(object):
return self.__reference
def check_by_fields(self, **kwargs):
"""Check that a record already exist using the fields defined
in the keyword arguments.
def check_record(self, record):
"""Check the content of the record in order to fix non conformities.
Return False when a non conformities has been found and can not be
corrected.
@note: Some checks depend on the type of publications and have to be
implemented in inherited class.
@note: The order of the checks matter. It should be oai,
temporary record, authors, my authors and then a series of checks
specific to the publication type.
@type record: L{Record}
@param record:
@rtype: bool
@return: C{False} when a non conformity is found and can not be
corrected.
"""
if self.dbg:
print "check record"
try:
self.check.temporary_record(record)
self.check.authors(record)
self.check.format_authors(record, format_author_fr)
self.check.collaboration(record)
except Exception as e:
self.logs[-1].reject(e, record.year())
return False
return True
def get_by_fields(self, **kwargs):
"""Get database record matching fields defined in the keyword arguments.
- Fix the field origin when a match is found.
- Actions are logged.
......@@ -308,7 +342,7 @@ class Automaton(object):
"""
if self.dbg:
print "check existing record by fields"
print "get existing record by fields"
db = self.db
......@@ -366,41 +400,6 @@ class Automaton(object):
return get_create_id(self.db.publishers, abbreviation=value)
def check_record(self, record):
"""Check the content of the record in order to fix non conformities.
Return False when a non conformities has been found and can not be
corrected.
@note: Some checks depend on the type of publications and have to be
implemented in inherited class.
@note: The order of the checks matter. It should be oai,
temporary record, authors, my authors and then a series of checks
specific to the publication type.
@type record: L{Record}
@param record:
@rtype: bool
@return: C{False} when a non conformity is found and can not be
corrected.
"""
if self.dbg:
print "check record"
try:
self.check.temporary_record(record)
self.check.authors(record)
self.check.format_authors(record, format_author_fr)
self.check.collaboration(record)
except Exception as e:
self.logs[-1].reject(e, record.year())
return False
return True
def insert_record(self, record):
"""Insert the record in the database.
......
......@@ -71,14 +71,14 @@ class Notes(Automaton):
title = record.title()
year = record.year()
# check against already published notes
rec_id, status = self.check_by_fields(first_author=first_author,
id_categories=self.id_category,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
title=title,
year=year)
# get existing notes
rec_id, status = self.get_by_fields(first_author=first_author,
id_categories=self.id_category,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
title=title,
year=year)
if rec_id:
return status
......
......@@ -98,15 +98,15 @@ class Preprints(Automaton):
# get the collaboration identifier
id_collaboration = self.get_create_collaboration(record.collaboration())
# check against preprint or article already published
rec_id, status = self.check_by_fields(first_author=first_author,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
preprint=preprint,
submitted=submitted,
title=title,
year=year)
# get existing preprint or article
rec_id, status = self.get_by_fields(first_author=first_author,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
preprint=preprint,
submitted=submitted,
title=title,
year=year)
if rec_id:
return status
......
......@@ -101,20 +101,20 @@ class Proceedings(Automaton):
id_collaboration = self.get_create_collaboration(record.collaboration())
id_publisher = self.get_create_publisher(editor)
# check against an already published proceeding
rec_id, status = self.check_by_fields(authors=authors,
conference_title=conference_title,
first_author=first_author,
id_publishers=id_publisher,
oai_url=oai_url,
preprint=preprint,
pages=pages,
publication_url=url,
report_numbers=report_numbers,
submitted=submitted,
volume=volume,
title=title,
year=year)
# get an already published proceeding
rec_id, status = self.get_by_fields(authors=authors,
conference_title=conference_title,
first_author=first_author,
id_publishers=id_publisher,
oai_url=oai_url,
preprint=preprint,
pages=pages,
publication_url=url,
report_numbers=report_numbers,
submitted=submitted,
volume=volume,
title=title,
year=year)
if rec_id:
return status
......
......@@ -90,13 +90,13 @@ class Reports(Automaton):
# get the collaboration identifier
id_collaboration = self.get_create_collaboration(record.collaboration())
# check against already published reports
rec_id, status = self.check_by_fields(id_categories=self.id_category,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
title=title,
year=year)
# get an already published reports
rec_id, status = self.get_by_fields(id_categories=self.id_category,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
title=title,
year=year)
if rec_id:
return status
......
......@@ -83,12 +83,12 @@ class Talks(Automaton):
# get the collaboration identifier
id_collaboration = self.get_create_collaboration(record.collaboration())
# check against already published talk using fields
rec_id, status = self.check_by_fields(conference_title=conference_title,
first_author=first_author,
oai_url=oai_url,
title=title,
year=year)
# get an already published talk
rec_id, status = self.get_by_fields(conference_title=conference_title,
first_author=first_author,
oai_url=oai_url,
title=title,
year=year)
if rec_id:
return status
......
......@@ -83,18 +83,18 @@ class Thesis(Automaton):
title = record.title()
universities = ', '.join(record.these_universities())
# extract the year from the defense date
# extract the year from the defence date
# this approach seems the most reliable
year = re.search(r"(\d\d\d\d)", defense_date).group(1)
# check against already published thesis
rec_id, status = self.check_by_fields(first_author=first_author,
defense=defense_date,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
title=title,
year=year)
# get an already published thesis
rec_id, status = self.get_by_fields(first_author=first_author,
defense=defense_date,
id_projects=self.id_project,
id_teams=self.id_team,
oai_url=oai_url,
title=title,
year=year)
if rec_id:
return status
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment