diff --git a/invenio/modules/documents/api.py b/invenio/modules/documents/api.py new file mode 100644 index 000000000..8324abb54 --- /dev/null +++ b/invenio/modules/documents/api.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +## +## This file is part of Invenio. +## Copyright (C) 2013 CERN. +## +## Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +from invenio.modules.jsonalchemy.wrappers import SmartJson +from invenio.modules.jsonalchemy.jsonext.engines.sqlalchemy import SQLAlchemyStorage +from invenio.modules.jsonalchemy.jsonext.readers.json_reader import reader + +from .models import Document as DocumentModel + + +class Document(SmartJson): + storage_engine = SQLAlchemyStorage(DocumentModel) + + @classmethod + def create(cls, data, model='common_document'): + record = reader(data, model=model) + document = cls(record.translate()) + return cls.storage_engine.save_one(document.dumps()) diff --git a/invenio/modules/documents/documentext/__init__.py b/invenio/modules/documents/documentext/__init__.py new file mode 100644 index 000000000..eb537e874 --- /dev/null +++ b/invenio/modules/documents/documentext/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +## +## This file is part of Invenio. +## Copyright (C) 2013 CERN. +## +## Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. diff --git a/invenio/modules/documents/documentext/fields/__init__.py b/invenio/modules/documents/documentext/fields/__init__.py new file mode 100644 index 000000000..eb537e874 --- /dev/null +++ b/invenio/modules/documents/documentext/fields/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +## +## This file is part of Invenio. +## Copyright (C) 2013 CERN. +## +## Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. diff --git a/invenio/modules/documents/documentext/fields/core_fields.cfg b/invenio/modules/documents/documentext/fields/core_fields.cfg new file mode 100644 index 000000000..f244e8446 --- /dev/null +++ b/invenio/modules/documents/documentext/fields/core_fields.cfg @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +## +## This file is part of Invenio. +## Copyright (C) 2013 CERN. +## +## Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +@persistent_identifier(0) +uuid: + checker: + check_field_existence(1, continuable=False) + documentation: + """ + This is the main persistent identifier of a document and will be used + internally as this, therefore the pid important should always be '0'. + """ + +version: + documentation: + """Document version""" + +parent: + calculated: + @do_not_cache + @parse_first(('parent_uuid', )) + @depends_on(('parent_uuid', )) + invenio.modules.documents.api.Document.storage_engine.get_one(self.get('parent_uuid')) + documentation: + """ + Return parent object + """ + +parent_uuid: + documentation: + """ + FIXME: add checker if not None document_exists(parent_uuid) + """ diff --git a/invenio/modules/documents/documentext/models/__init__.py b/invenio/modules/documents/documentext/models/__init__.py new file mode 100644 index 000000000..eb537e874 --- /dev/null +++ b/invenio/modules/documents/documentext/models/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +## +## This file is part of Invenio. +## Copyright (C) 2013 CERN. +## +## Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. diff --git a/invenio/modules/documents/documentext/models/common_document.cfg b/invenio/modules/documents/documentext/models/common_document.cfg new file mode 100644 index 000000000..0421a11f4 --- /dev/null +++ b/invenio/modules/documents/documentext/models/common_document.cfg @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +## +## This file is part of Invenio. +## Copyright (C) 2013 CERN. +## +## Invenio is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 2 of the +## License, or (at your option) any later version. +## +## Invenio is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Invenio; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +fields: + @inherit_from(('common', )) + _id = uuid + version + parent + parent_uuid + modification_date + creation_date +documentation: + """ + Common fields in all the documents inside any Invenio installation. + """ diff --git a/invenio/modules/documents/models.py b/invenio/modules/documents/models.py index 5f2febe76..9acbd7904 100644 --- a/invenio/modules/documents/models.py +++ b/invenio/modules/documents/models.py @@ -1,71 +1,83 @@ # -*- coding: utf-8 -*- # ## This file is part of Invenio. ## Copyright (C) 2012, 2013 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02D111-1307, USA. """ BibDoc Filesystem database model. """ # General imports. from invenio.ext.sqlalchemy import db # Create your models here. from invenio.modules.record_editor.models import Bibdoc class Bibdocfsinfo(db.Model): """Represents a Bibdocfsinfo record.""" __tablename__ = 'bibdocfsinfo' id_bibdoc = db.Column(db.MediumInteger(9, unsigned=True), db.ForeignKey(Bibdoc.id), primary_key=True, nullable=False, autoincrement=False) version = db.Column(db.TinyInteger(4, unsigned=True), primary_key=True, nullable=False, autoincrement=False) format = db.Column(db.String(50), primary_key=True, nullable=False, index=True) last_version = db.Column(db.Boolean, nullable=False, index=True) cd = db.Column(db.DateTime, nullable=False, index=True) md = db.Column(db.DateTime, nullable=False, index=True) checksum = db.Column(db.Char(32), nullable=False) filesize = db.Column(db.BigInteger(15, unsigned=True), nullable=False, index=True) mime = db.Column(db.String(100), nullable=False, index=True) master_format = db.Column(db.String(50)) class Bibdocmoreinfo(db.Model): """Represents a Bibdocmoreinfo record.""" __tablename__ = 'bibdocmoreinfo' id = db.Column(db.MediumInteger(9, unsigned=True), primary_key=True) id_bibdoc = db.Column(db.MediumInteger(9, unsigned=True), db.ForeignKey(Bibdoc.id), nullable=True) version = db.Column(db.TinyInteger(4, unsigned=True), nullable=True) format = db.Column(db.String(50), nullable=True) id_rel = db.Column(db.MediumInteger(9, unsigned=True), nullable=True) namespace = db.Column(db.Char(25), nullable=True) data_key = db.Column(db.Char(25)) data_value = db.Column(db.LargeBinary) __table_args__ = (db.Index('bibdocmoreinfo_key', id_bibdoc, version, format, id_rel, namespace, data_key), db.Model.__table_args__) -__all__ = ['Bibdocfsinfo', - 'Bibdocmoreinfo'] +class Document(db.Model): + """Represents a document object inside the SQL database""" + + __tablename__ = 'documents' + id = db.Column(db.UUID, primary_key=True) + parent_id = db.Column(db.UUID, nullable=True) + creation_date = db.Column(db.DateTime, nullable=False, + server_default='1900-01-01 00:00:00', index=True) + modification_date = db.Column(db.DateTime, nullable=False, + server_default='1900-01-01 00:00:00', + index=True) + json = db.Column(db.JSON, nullable=True) + + #FIXME write better setter for json