Esempio n. 1
0
 def update(self, session: Session, title: str, visible: bool, status: str, projtype: str,
            init_classif_list: List[int],
            classiffieldlist: str, popoverfieldlist: str,
            cnn_network_id: str, comments: str,
            contact: Any,
            managers: List[Any], annotators: List[Any], viewers: List[Any],
            license_: str):
     assert contact is not None, "A valid Contact is needed."
     proj_id = self._project.projid
     # Field reflexes
     if cnn_network_id != self._project.cnn_network_id:
         sub_qry: Query = session.query(ObjectHeader.objid)
         sub_qry = sub_qry.join(Acquisition, Acquisition.acquisid == ObjectHeader.acquisid)
         sub_qry = sub_qry.join(Sample, and_(Sample.sampleid == Acquisition.acq_sample_id,
                                             Sample.projid == proj_id))
         # Delete CNN features which depend on the CNN network
         qry: Query = session.query(ObjectCNNFeature)
         qry = qry.filter(ObjectCNNFeature.objcnnid.in_(sub_qry.subquery()))
         qry.delete(synchronize_session=False)
     # Fields update
     self._project.title = title
     self._project.visible = visible
     self._project.status = status
     self._project.projtype = projtype
     self._project.classiffieldlist = classiffieldlist
     self._project.popoverfieldlist = popoverfieldlist
     self._project.cnn_network_id = cnn_network_id
     self._project.comments = comments
     self._project.license = license_
     # Inverse for extracted values
     self._project.initclassiflist = ",".join([str(cl_id) for cl_id in init_classif_list])
     # Inverse for users by privilege
     # Dispatch members by right
     # TODO: Nothing prevents or cares about redundant rights, such as adding same
     #     user as both Viewer and Annotator.
     by_right = {ProjectPrivilegeBO.MANAGE: managers,
                 ProjectPrivilegeBO.ANNOTATE: annotators,
                 ProjectPrivilegeBO.VIEW: viewers}
     # Remove all to avoid tricky diffs
     session.query(ProjectPrivilege). \
         filter(ProjectPrivilege.projid == proj_id).delete()
     # Add all
     contact_used = False
     for a_right, a_user_list in by_right.items():
         for a_user in a_user_list:
             # Set flag for contact person
             extra = None
             if a_user.id == contact.id and a_right == ProjectPrivilegeBO.MANAGE:
                 extra = 'C'
                 contact_used = True
             session.add(ProjectPrivilege(projid=proj_id,
                                          member=a_user.id,
                                          privilege=a_right,
                                          extra=extra))
     # Sanity check
     assert contact_used, "Could not set Contact, the designated user is not in Managers list."
     session.commit()
Esempio n. 2
0
 def create_parent(session: Session, dict_to_write, prj_id: ProjectIDT,
                   parent_class):
     """
         Create the SQLAlchemy wrapper for Sample, Acquisition or Process.
     :return: The created DB wrapper.
     """
     # noinspection PyCallingNonCallable
     parent = parent_class(**dict_to_write)
     # Link with project
     parent.projid = prj_id
     session.add(parent)
     session.flush()
     return parent