Ejemplo n.º 1
0
class Relationship2GroupRelationship(db.Model, Timestamp):
    """Many-to-many model for Relationship to GroupRelationship."""

    __tablename__ = 'relationship2grouprelationship'
    __table_args__ = (PrimaryKeyConstraint(
        'relationship_id',
        'group_relationship_id',
        name='pk_relationship2grouprelationship'), )
    relationship_id = db.Column(UUIDType,
                                db.ForeignKey(Relationship.id,
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'),
                                nullable=False)
    group_relationship_id = db.Column(UUIDType,
                                      db.ForeignKey(GroupRelationship.id,
                                                    onupdate='CASCADE',
                                                    ondelete='CASCADE'),
                                      nullable=False)

    # DB relationships
    relationship = db.relationship(Relationship,
                                   foreign_keys=[relationship_id],
                                   backref='relationship2group_relationship')
    group_relationship = db.relationship(
        GroupRelationship,
        foreign_keys=[group_relationship_id],
        backref='relationship2group_relationship')

    def __repr__(self):
        """String representation of the model."""
        return f'<{self.group_relationship}: {self.relationship}>'
Ejemplo n.º 2
0
class GroupRelationshipM2M(db.Model, Timestamp):
    """Many-to-many model for Group Relationships."""

    __tablename__ = 'grouprelationshipm2m'
    __table_args__ = (PrimaryKeyConstraint('relationship_id',
                                           'subrelationship_id',
                                           name='pk_grouprelationshipm2m'), )
    relationship_id = db.Column(UUIDType,
                                db.ForeignKey(GroupRelationship.id,
                                              onupdate="CASCADE",
                                              ondelete="CASCADE"),
                                nullable=False)
    subrelationship_id = db.Column(UUIDType,
                                   db.ForeignKey(GroupRelationship.id,
                                                 onupdate="CASCADE",
                                                 ondelete="CASCADE"),
                                   nullable=False)

    relationship = db.relationship(GroupRelationship,
                                   foreign_keys=[relationship_id],
                                   backref='subrelationshipsm2m')
    subrelationship = db.relationship(GroupRelationship,
                                      foreign_keys=[subrelationship_id],
                                      backref='superrelationshipsm2m')

    def __repr__(self):
        """String representation of the model."""
        return f'<{self.relationship}: {self.subrelationship}>'
Ejemplo n.º 3
0
class Identifier2Group(db.Model, Timestamp):
    """Many-to-many model for Identifier and Group."""

    __tablename__ = 'identifier2group'
    __table_args__ = (PrimaryKeyConstraint('identifier_id',
                                           'group_id',
                                           name='pk_identifier2group'), )
    identifier_id = db.Column(UUIDType,
                              db.ForeignKey(Identifier.id,
                                            ondelete='CASCADE',
                                            onupdate='CASCADE'),
                              nullable=False)
    group_id = db.Column(UUIDType,
                         db.ForeignKey(Group.id,
                                       ondelete='CASCADE',
                                       onupdate='CASCADE'),
                         nullable=False)

    # DB relationships
    identifier = db.relationship(Identifier,
                                 foreign_keys=[identifier_id],
                                 backref='id2groups')
    group = db.relationship(Group,
                            foreign_keys=[group_id],
                            backref='id2groups')
Ejemplo n.º 4
0
class RecordSIP(db.Model, Timestamp):
    """An association table for Records and SIPs."""

    __tablename__ = 'sipstore_recordsip'

    sip_id = db.Column(UUIDType,
                       db.ForeignKey(SIP.id,
                                     name='fk_sipstore_recordsip_sip_id'),
                       primary_key=True)
    """Id of SIP."""

    pid_id = db.Column(db.Integer,
                       db.ForeignKey(PersistentIdentifier.id,
                                     name='fk_sipstore_recordsip_pid_id'),
                       primary_key=True)
    """Id of the PID pointing to the record."""

    #
    # Relations
    #
    sip = db.relationship(SIP, backref='record_sips', foreign_keys=[sip_id])
    """Relation to the SIP associated with the record."""

    pid = db.relationship(PersistentIdentifier,
                          backref='record_sips',
                          foreign_keys=[pid_id])
    """Relation to the PID associated with the record SIP."""
Ejemplo n.º 5
0
class ActivityAction(db.Model, TimestampMixin):
    """Define Activety."""

    __tablename__ = 'workflow_activity_action'

    id = db.Column(db.Integer(),
                   nullable=False,
                   primary_key=True,
                   autoincrement=True)
    """Activity_Action identifier."""

    activity_id = db.Column(db.String(24),
                            nullable=False,
                            unique=False,
                            index=True)
    """activity id of Activity Action."""

    action_id = db.Column(db.Integer(),
                          db.ForeignKey(Action.id),
                          nullable=True,
                          unique=False)
    """action id."""

    action_status = db.Column(db.String(1),
                              db.ForeignKey(ActionStatus.action_status_id),
                              nullable=False,
                              unique=False)
    """action status."""

    action_comment = db.Column(db.Text, nullable=True)
    """action comment."""
Ejemplo n.º 6
0
class DocumentsItemsMetadata(db.Model):
    """Relationship between Documents and Items."""

    __tablename__ = 'documents_items'

    item_id = db.Column(
        UUIDType,
        db.ForeignKey(RecordMetadata.id),
        primary_key=True,
        nullable=False,
        # NOTE no unique constrain for better future ...
    )
    """Item related with the document."""

    item = db.relationship(RecordMetadata, foreign_keys=[item_id])
    """Relationship to the item."""

    document_id = db.Column(UUIDType,
                            db.ForeignKey(RecordMetadata.id),
                            primary_key=True,
                            nullable=False)
    """Document related with the item."""

    document = db.relationship(RecordMetadata, foreign_keys=[document_id])
    """It is used by SQLAlchemy for optimistic concurrency control."""
    @classmethod
    def create(cls, document, item):
        """Create a new DocumentsItem and adds it to the session.

        :param document: Document used to relate with the ``Item``.
        :param item: Item used to relate with the ``Record``.
        :returns:
            The :class:
            `~rero_ils.modules.documents_items.models.RecordsItems`
            object created.
        """
        rb = cls(document=document, item=item)
        with db.session.begin_nested():
            db.session.add(rb)
        return rb

    @property
    def parent_id(self):
        """Parent id."""
        return self.document_id

    @classmethod
    def get_parent(cls):
        """Parent id."""
        return cls.document

    @property
    def child_id(self):
        """Parent id."""
        return self.item_id

    @classmethod
    def get_child(cls):
        """Parent id."""
        return cls.item
Ejemplo n.º 7
0
class MembersLocationsMetadata(db.Model):
    """Relationship between Members and Locations."""

    __tablename__ = 'members_locations'

    location_id = db.Column(
        UUIDType,
        db.ForeignKey(RecordMetadata.id),
        primary_key=True,
        nullable=False,
        # NOTE no unique constrain for better future ...
    )
    """Location related with the member."""

    location = db.relationship(RecordMetadata, foreign_keys=[location_id])
    """Relationship to the location."""

    member_id = db.Column(UUIDType,
                          db.ForeignKey(RecordMetadata.id),
                          primary_key=True,
                          nullable=False)
    """Mmember related with the location."""

    member = db.relationship(RecordMetadata, foreign_keys=[member_id])
    """It is used by SQLAlchemy for optimistic concurrency control."""
    @classmethod
    def create(cls, member, location):
        """Create a new memberLocation and adds it to the session.

        :param member: member used to relate with the ``Location``.
        :param location: member used to relate with the ``Member``.
        :returns:
            The :class:
            `~reroils_data.members_locations.models.MembersLocations`
            object created.
        """
        rb = cls(member=member, location=location)
        with db.session.begin_nested():
            db.session.add(rb)
        return rb

    @property
    def parent_id(self):
        """Parent id."""
        return self.member_id

    @classmethod
    def get_parent(cls):
        """Parent id."""
        return cls.member

    @property
    def child_id(self):
        """Parent id."""
        return self.location_id

    @classmethod
    def get_child(cls):
        """Parent id."""
        return cls.location
Ejemplo n.º 8
0
Archivo: models.py Proyecto: vypha/weko
class FlowActionRole(db.Model, TimestampMixin):
    """FlowActionRole list belong to FlowAction

    It relates an allowed action with a role or a user
    """

    __tablename__ = 'workflow_flow_action_role'

    id = db.Column(db.Integer(), nullable=False,
                   primary_key=True, autoincrement=True)
    """FlowAction identifier."""

    flow_action_id = db.Column(
        db.Integer(), db.ForeignKey(FlowAction.id),
        nullable=False, unique=False, index=True)
    """the id of flow_action."""

    action_role = db.Column(db.Integer(), db.ForeignKey(Role.id),
                            nullable=True, unique=False)

    action_role_exclude = db.Column(
        db.Boolean(name='role_exclude'),
        nullable=False, default=False, server_default='0')
    """If set to True, deny the action, otherwise allow it."""

    action_user = db.Column(db.Integer(), db.ForeignKey(User.id),
                            nullable=True, unique=False)

    action_user_exclude = db.Column(
        db.Boolean(name='user_exclude'),
        nullable=False, default=False, server_default='0')
    """If set to True, deny the action, otherwise allow it."""
Ejemplo n.º 9
0
class Term(db.Model):
    __tablename__ = 'iroko_terms'

    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(UUIDType, default=uuid.uuid4)

    identifier = db.Column(db.String, nullable=False, unique=True)
    description = db.Column(db.String)

    vocabulary_id = db.Column(db.String(),
                              db.ForeignKey('iroko_vocab.identifier',
                                            ondelete='CASCADE'),
                              nullable=False,
                              index=True)
    vocabulary = db.relationship("Vocabulary",
                                 backref=db.backref(
                                     "terms",
                                     cascade="all, delete-orphan",
                                     lazy='dynamic'))

    parent_id = db.Column(db.Integer, db.ForeignKey('iroko_terms.id'))
    children = db.relationship("Term", lazy="joined", join_depth=2)

    # any data related to the term
    data = db.Column(JSONType)

    def __str__(self):
        """Representation."""
        return self.identifier
Ejemplo n.º 10
0
class RecordsBuckets(db.Model):
    """Relationship between Records and Buckets."""

    __tablename__ = 'records_buckets'

    record_id = db.Column(
        UUIDType,
        db.ForeignKey(RecordMetadata.id),
        primary_key=True,
        nullable=False,
        # NOTE no unique constrain for better future ...
    )

    bucket_id = db.Column(
        UUIDType,
        db.ForeignKey(Bucket.id),
        primary_key=True,
        nullable=False,
    )

    bucket = db.relationship(Bucket)
    record = db.relationship(
        RecordMetadata,
        backref=db.backref('records_buckets', uselist=False),
        uselist=False,
    )
Ejemplo n.º 11
0
class InstitutionLiterature(db.Model):
    """Keeps track of papers linked to a Institution Records."""

    __tablename__ = "institution_literature"
    __table_args__ = (
        db.Index("ix_institution_literature_institution_uuid",
                 "institution_uuid"),
        db.Index("ix_institution_literature_literature_uuid",
                 "literature_uuid"),
    )

    institution_uuid = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_institution_literature_institution_uuid"),
        nullable=False,
        primary_key=True,
    )
    literature_uuid = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_institution_literature_literature_uuid"),
        nullable=False,
        primary_key=True,
    )

    institution = db.relationship(RecordMetadata,
                                  backref="institution_papers",
                                  foreign_keys=[institution_uuid])

    institution_paper = db.relationship(RecordMetadata,
                                        backref="institutions",
                                        foreign_keys=[literature_uuid])
Ejemplo n.º 12
0
class PageList(db.Model):
    """Represent association between page and list."""

    __versioned__ = {}

    __tablename__ = 'pages_pagelist'

    id = db.Column(db.Integer,
                   nullable=False,
                   primary_key=True,
                   autoincrement=True)
    """PageList identifier."""

    list_id = db.Column(db.Integer, db.ForeignKey(Page.id), nullable=False)
    """Id of a list."""

    page_id = db.Column(db.Integer, db.ForeignKey(Page.id), nullable=False)
    """Id of a page."""

    order = db.Column(db.Integer, nullable=False)

    list = db.relationship(Page,
                           backref=db.backref("pages",
                                              cascade="all, delete-orphan"),
                           foreign_keys=[list_id])
    """Relation to the list."""

    page = db.relationship(Page,
                           backref=db.backref("lists",
                                              cascade="all, delete-orphan"),
                           foreign_keys=[page_id])
    """Relation to the page."""
Ejemplo n.º 13
0
class StudentsAdvisors(db.Model):
    """Links students with their thesis advisors"""

    __tablename__ = "students_advisors"
    __table_args__ = (db.Index("ix_students_advisors_student_id",
                               "student_id"), )

    advisor_id = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_students_advisors_advisor_id"),
        nullable=False,
        primary_key=True,
    )

    student_id = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_students_advisors_student_id"),
        nullable=False,
        primary_key=True,
    )

    degree_type = db.Column(
        ENUM(*[key.value for key in DegreeType], name="enum_degree_type"))
Ejemplo n.º 14
0
class ExperimentLiterature(db.Model):
    """Keeps track of papers linked to Experiment Records."""

    __tablename__ = "experiment_literature"
    __table_args__ = (
        db.Index("ix_experiment_literature_experiment_uuid",
                 "experiment_uuid"),
        db.Index("ix_experiment_literature_literature_uuid",
                 "literature_uuid"),
    )

    experiment_uuid = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_experiment_literature_experiment_uuid"),
        nullable=False,
        primary_key=True,
    )
    literature_uuid = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_experiment_literature_literature_uuid"),
        nullable=False,
        primary_key=True,
    )

    experiment = db.relationship(RecordMetadata,
                                 backref="experiment_papers",
                                 foreign_keys=[experiment_uuid])

    experiment_paper = db.relationship(RecordMetadata,
                                       backref="experiments",
                                       foreign_keys=[literature_uuid])
Ejemplo n.º 15
0
class RecordCitations(db.Model):
    """Adds Citation table which holds all references
       which are also eligible citations"""

    __tablename__ = "records_citations"

    __table_args__ = (db.Index("ix_records_citations_cited_id", "cited_id"), )

    citer_id = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_records_citations_citer_id"),
        nullable=False,
        primary_key=True,
    )
    cited_id = db.Column(
        UUIDType,
        db.ForeignKey("records_metadata.id",
                      name="fk_records_citations_cited_id"),
        nullable=False,
        primary_key=True,
    )
    citation_date = db.Column(Date)
    # Relationship: Relation to record which cites
    # Backref: List of all references of this record
    # which are counted as citations in other records.
    citer = db.relationship(RecordMetadata,
                            backref="references",
                            foreign_keys=[citer_id])
    # Relationship: Relation to cited article
    # Backref: List of all citations of this record.
    cited = db.relationship(RecordMetadata,
                            backref="citations",
                            foreign_keys=[cited_id])
Ejemplo n.º 16
0
class WorkflowsAudit(db.Model):

    __tablename__ = "workflows_audit_logging"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    # Date that the action was taken
    created = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)

    user_id = db.Column(
        db.Integer,
        db.ForeignKey("accounts_user.id", ondelete='CASCADE'),
        nullable=True,
        index=True,
    )
    object_id = db.Column(
        db.Integer,
        db.ForeignKey("workflows_object.id", ondelete='CASCADE'),
        nullable=False,
        index=True,
    )

    # Score from model, action taken, recommendation from the model
    score = db.Column(db.Float, default=0, nullable=False)
    user_action = db.Column(db.Text, default="", nullable=False)
    decision = db.Column(db.Text, default="", nullable=False)

    source = db.Column(db.Text, default="", nullable=False)
    action = db.Column(db.Text, default="", nullable=False)

    def save(self):
        """Save object to persistent storage."""
        with db.session.begin_nested():
            db.session.add(self)
Ejemplo n.º 17
0
class CommunitySchemaVersion(db.Model):
    """Represent a version of a community's schema in the database.

    Each Community has only one schema, which can have multiple versions. All
    released community schemas are immutable.

    The last released Community schema is used to validate all the new records
    submitted to this Community.
    """

    __tablename__ = 'b2share_community_schema_version'

    community = db.Column(UUIDType, db.ForeignKey(Community.id),
                          primary_key=True)
    """Community accepting this schema."""

    version = db.Column(db.Integer, primary_key=True, default=None,
                        nullable=False, autoincrement=False)
    "Schema version."

    released = sa.Column(sa.DateTime, default=datetime.utcnow, nullable=False)
    """Schema release date."""

    root_schema = db.Column(db.Integer,
                            db.ForeignKey(RootSchemaVersion.version),
                            nullable=False)
    """Root schema used by this community."""

    community_schema = db.Column(db.String, nullable=False, default="{}")
Ejemplo n.º 18
0
class RecordSIP(db.Model, Timestamp):
    """An association table for Records and SIPs."""

    __tablename__ = 'sipstore_recordsip'

    sip_id = db.Column(UUIDType,
                       db.ForeignKey(SIP.id,
                                     name='fk_sipstore_recordsip_sip_id'),
                       primary_key=True)
    """Id of SIP."""

    pid_id = db.Column(db.Integer,
                       db.ForeignKey(PersistentIdentifier.id,
                                     name='fk_sipstore_recordsip_pid_id'),
                       primary_key=True)
    """Id of the PID pointing to the record."""

    #
    # Relations
    #
    sip = db.relationship(SIP, backref='record_sips', foreign_keys=[sip_id])
    """Relation to the SIP associated with the record."""

    pid = db.relationship(PersistentIdentifier,
                          backref='record_sips',
                          foreign_keys=[pid_id])
    """Relation to the PID associated with the record SIP."""
    @classmethod
    def get_by_sip(cls, sip_id):
        """Return the corresponding PIDs from SIP."""
        return cls.query.filter_by(sip_id=sip_id).all()
Ejemplo n.º 19
0
class SIPMetadata(db.Model, Timestamp):
    """Extra SIP info regarding metadata."""

    __tablename__ = 'sipstore_sipmetadata'

    sip_id = db.Column(UUIDType,
                       db.ForeignKey(SIP.id, name='fk_sipmetadata_sip_id'),
                       primary_key=True)
    """Id of SIP."""

    type_id = db.Column(db.Integer(),
                        db.ForeignKey(SIPMetadataType.id,
                                      name='fk_sipmetadatatype_type'),
                        primary_key=True)
    """ID of the metadata type."""

    content = db.Column(db.Text, nullable=False)
    """Text blob of the metadata content."""

    #
    # Relations
    #
    sip = db.relationship(SIP, backref='sip_metadata', foreign_keys=[sip_id])
    """Relation to the SIP along which given metadata was submitted."""

    type = db.relationship(SIPMetadataType)
    """Relation to the SIPMetadataType."""
class SIPFile(db.Model, Timestamp):
    """Extra SIP info regarding files."""

    __tablename__ = 'sipstore_sipfile'

    sip_id = db.Column(UUIDType, db.ForeignKey(SIP.id))
    """Id of SIP."""

    filepath = db.Column(db.Text().with_variant(mysql.VARCHAR(255), 'mysql'),
                         nullable=False)
    """Filepath of submitted file within the SIP record."""

    file_id = db.Column(UUIDType,
                        db.ForeignKey(FileInstance.id, ondelete='RESTRICT'),
                        primary_key=True,
                        nullable=False)
    """Id of the FileInstance."""
    @validates('filepath')
    def validate_key(self, filepath, filepath_):
        """Validate key."""
        if len(filepath_) > current_app.config['SIPSTORE_FILEPATH_MAX_LEN']:
            raise ValueError('Filepath too long ({0}).'.format(len(filepath_)))
        return filepath_

    #
    # Relations
    #
    sip = db.relationship(SIP, backref='sip_files', foreign_keys=[sip_id])
    """Relation to the SIP along which given file was submitted."""

    file = db.relationship(FileInstance,
                           backref='sip_files',
                           foreign_keys=[file_id])
    """Relation to the SIP along which given file was submitted."""
Ejemplo n.º 21
0
class GitSubscriberSnapshots(db.Model):
    """Connection model between snapshot and webhook subscribers."""
    __tablename__ = 'git_subscriber_snapshots'

    snapshot_id = db.Column(db.Integer,
                            db.ForeignKey('git_snapshot.id'),
                            primary_key=True)
    subscriber_id = db.Column(db.Integer,
                              db.ForeignKey('git_subscriber.id'),
                              primary_key=True)
Ejemplo n.º 22
0
class FlowAction(db.Model, TimestampMixin):
    """Action list belong to Flow."""

    __tablename__ = 'workflow_flow_action'

    id = db.Column(db.Integer(),
                   nullable=False,
                   primary_key=True,
                   autoincrement=True)
    """FlowAction identifier."""

    flow_id = db.Column(UUIDType,
                        db.ForeignKey(FlowDefine.flow_id),
                        nullable=False,
                        unique=False,
                        index=True)
    """the id of flow."""

    action_id = db.Column(db.Integer(),
                          db.ForeignKey(Action.id),
                          nullable=False,
                          unique=False)
    """the id of action."""

    action_version = db.Column(db.String(64), nullable=True)
    """the version of used action."""

    action_order = db.Column(db.Integer(), nullable=False, unique=False)
    """the order of action."""

    action_condition = db.Column(db.String(255), nullable=True, unique=False)
    """the condition of transition."""

    TATUSPOLICY = [
        (AvailableStautsPolicy.USABLE,
         AvailableStautsPolicy.describe(AvailableStautsPolicy.USABLE)),
        (AvailableStautsPolicy.UNUSABLE,
         AvailableStautsPolicy.describe(AvailableStautsPolicy.UNUSABLE)),
    ]
    """Subscription policy choices."""

    action_status = db.Column(ChoiceType(TATUSPOLICY, impl=db.String(1)),
                              nullable=False,
                              default=AvailableStautsPolicy.USABLE)
    """the status of flow action."""

    action_date = db.Column(db.DateTime, nullable=False, default=datetime.now)
    """the use date of action."""

    action = db.relationship(Action, backref=db.backref('flow_action'))
    """flow action relationship."""

    action_roles = db.relationship('FlowActionRole',
                                   backref=db.backref('flow_action'))
    """flow action relationship."""
Ejemplo n.º 23
0
class GroupRelationship(db.Model, Timestamp):
    """Group relationship model."""

    __tablename__ = 'grouprelationship'
    __table_args__ = (
        UniqueConstraint('source_id',
                         'target_id',
                         'relation',
                         name='uq_grouprelationship_source_target_relation'),
        # TODO: Change to "index=True"
        Index('ix_grouprelationship_source', 'source_id'),
        Index('ix_grouprelationship_target', 'target_id'),
        Index('ix_grouprelationship_relation', 'relation'),
    )

    id = db.Column(UUIDType, default=uuid.uuid4, primary_key=True)
    type = db.Column(db.Enum(GroupType), nullable=False)
    relation = db.Column(db.Enum(Relation), nullable=False)
    source_id = db.Column(UUIDType,
                          db.ForeignKey(Group.id,
                                        ondelete='CASCADE',
                                        onupdate='CASCADE'),
                          nullable=False)
    target_id = db.Column(UUIDType,
                          db.ForeignKey(Group.id,
                                        ondelete='CASCADE',
                                        onupdate='CASCADE'),
                          nullable=False)

    # DB relationships
    source = db.relationship(Group,
                             foreign_keys=[source_id],
                             backref='sources')
    target = db.relationship(Group,
                             foreign_keys=[target_id],
                             backref='targets')

    relationships = db.relationship(
        'GroupRelationship',
        secondary=lambda: GroupRelationshipM2M.__table__,
        primaryjoin=lambda:
        (GroupRelationship.id == GroupRelationshipM2M.relationship_id),
        secondaryjoin=lambda:
        (GroupRelationship.id == GroupRelationshipM2M.subrelationship_id))

    # TODO:
    # We don't store 'deleted' as in the relation as most likely don't need
    # that as 'ground truth' in precomputed groups anyway

    def __repr__(self):
        """String representation of the group relationship."""
        return f'<{self.source} {self.relation.name} {self.target}>'
Ejemplo n.º 24
0
class ReanaJob(db.Model):
    """Model defining REANA job."""

    __tablename__ = 'reana'

    id = db.Column(UUIDType,
                   primary_key=True,
                   nullable=False,
                   default=uuid.uuid4)

    user_id = db.Column(
        db.Integer,
        db.ForeignKey(User.id),
        nullable=False,
    )

    record_id = db.Column(
        UUIDType,
        db.ForeignKey(RecordMetadata.id),
        nullable=False,
    )

    name = db.Column(db.String(100), unique=False, nullable=False)

    params = db.Column(JSONType().with_variant(
        postgresql.JSONB(none_as_null=True),
        'postgresql',
    ).with_variant(
        JSONType(),
        'sqlite',
    ),
                       default=lambda: dict(),
                       nullable=True)

    output = db.Column(JSONType().with_variant(
        postgresql.JSONB(none_as_null=True),
        'postgresql',
    ).with_variant(
        JSONType(),
        'sqlite',
    ),
                       default=lambda: dict(),
                       nullable=True)

    user = db.relationship('User')
    record = db.relationship('RecordMetadata')

    @classmethod
    def get_jobs(cls, user_id, record_id):
        """Return all the jobs run by user for this record."""
        return cls.query.filter_by(user_id=user_id, record_id=record_id).all()
Ejemplo n.º 25
0
class TermSources(db.Model):
    __tablename__ = 'iroko_terms_sources'

    # TODO: Esta relacion deberia hacerse con los UUIDs y no con los IDs
    term_id = db.Column(db.Integer,
                        db.ForeignKey('iroko_terms.id'),
                        primary_key=True)
    sources_id = db.Column(db.Integer,
                           db.ForeignKey('iroko_sources.id'),
                           primary_key=True)
    data = db.Column(JSONType)

    source = db.relationship("Source", backref=db.backref("term_sources"))
    term = db.relationship("Term", backref=db.backref("term_sources"))
Ejemplo n.º 26
0
class PropertyValue(db.Model, Timestamp):
    """Property and Value match to be used in Property based ACL queries."""

    __tablename__ = 'explicit_acls_propertyvalue'

    #
    # Fields
    #
    id = db.Column(db.String(36), default=gen_uuid_key, primary_key=True)
    """Primary key."""

    acl_id = db.Column(
        db.ForeignKey('explicit_acls_propertyvalueacl.id',
                      name='fk_explicit_acls_propertyvalue_acl_id'))
    acl = db.relationship('PropertyValueACL', back_populates='property_values')

    name = db.Column(db.String(64))
    """Name of the property in elasticsearch."""

    value = db.Column(db.String(128))
    """Value of the property in elasticsearch."""

    match_operation = db.Column(ChoiceType(MatchOperation,
                                           impl=db.String(length=10)),
                                default=MatchOperation.term)
    """Property value matching mode: can be either term or match."""

    bool_operation = db.Column(ChoiceType(BoolOperation,
                                          impl=db.String(length=10)),
                               default=BoolOperation.must)
    """Bool filter operation mode this property belongs to."""

    originator_id = db.Column(db.ForeignKey(
        User.id,
        ondelete='CASCADE',
    ),
                              nullable=False,
                              index=True)
    originator = db.relationship(User,
                                 backref=db.backref("authored_properties"))
    """The originator (person that last time modified the Property)"""
    def __str__(self):
        """Returns string representation of the class."""
        return '%s: %s(%s=%s)' % (
            self.bool_operation,
            self.match_operation,
            self.name,
            self.value,
        )
Ejemplo n.º 27
0
class WorkFlow(db.Model, TimestampMixin):
    """Define WorkFlow."""

    __tablename__ = 'workflow_workflow'

    id = db.Column(db.Integer(),
                   nullable=False,
                   primary_key=True,
                   autoincrement=True)
    """Flows identifier."""

    flows_id = db.Column(UUIDType,
                         nullable=False,
                         unique=True,
                         index=True,
                         default=uuid.uuid4())
    """the id of flows."""

    flows_name = db.Column(db.String(255),
                           nullable=True,
                           unique=False,
                           index=False)
    """the name of flows."""

    itemtype_id = db.Column(db.Integer(),
                            db.ForeignKey(ItemType.id),
                            nullable=False,
                            unique=False)
    """the id of itemtype."""

    itemtype = db.relationship(ItemType,
                               backref=db.backref(
                                   'workflow',
                                   lazy='dynamic',
                                   order_by=desc('item_type.tag')))

    index_tree_id = db.Column(db.BigInteger, nullable=True, unique=False)
    """Index tree id that this workflow will belong to"""

    flow_id = db.Column(db.Integer(),
                        db.ForeignKey(FlowDefine.id),
                        nullable=False,
                        unique=False)
    """the id of flow."""

    flow_define = db.relationship(FlowDefine,
                                  backref=db.backref('workflow',
                                                     lazy='dynamic'))
Ejemplo n.º 28
0
class DraftMetadata(db.Model, DraftMetadataBase):
    """Represent a marc21 record draft metadata."""

    __tablename__ = "marc21_drafts_metadata"

    bucket_id = db.Column(UUIDType, db.ForeignKey(Bucket.id))
    bucket = db.relationship(Bucket)
Ejemplo n.º 29
0
class ActionRoles(ActionNeedMixin, db.Model):
    """ActionRoles data model.

    It relates an allowed action with a role.
    """

    __tablename__ = 'access_actionsroles'

    __table_args__ = (UniqueConstraint('action',
                                       'exclude',
                                       'argument',
                                       'role_id',
                                       name='access_actionsroles_unique'), )

    role_id = db.Column(db.Integer(),
                        db.ForeignKey(Role.id, ondelete='CASCADE'),
                        nullable=False,
                        index=True)

    role = db.relationship("Role",
                           backref=db.backref("actionusers",
                                              cascade="all, delete-orphan"))

    @property
    def need(self):
        """Return RoleNeed instance."""
        return RoleNeed(self.role.name)
Ejemplo n.º 30
0
class SubmissionParticipant(db.Model):
    """
    This table stores information about the reviewers and
    uploaders of a HEPdata submission
    """
    __tablename__ = "submissionparticipant"

    id = db.Column(db.Integer,
                   primary_key=True,
                   nullable=False,
                   autoincrement=True)

    publication_recid = db.Column(db.Integer)

    full_name = db.Column(db.String(128))
    email = db.Column(db.String(128))
    affiliation = db.Column(db.String(128))
    invitation_cookie = db.Column(UUIDType, default=uuid.uuid4)

    # when the user logs in with their cookie,
    # this user_account should be updated.
    user_account = db.Column(db.Integer, db.ForeignKey(User.id))

    # e.g., reviewer or uploader
    role = db.Column(db.String(32), default='')
    # e.g. primary or reserve reviewer/uploader
    status = db.Column(db.String(32), default='reserve')
    action_date = db.Column(db.DateTime, nullable=True, index=True)