def createfoiministryrequestfromobject(self, ministryschema, requestschema,
                                           userid):
        requestdict = self.createfoiministryrequestfromobject1(
            ministryschema, requestschema)

        foiministryrequest = FOIMinistryRequest()
        foiministryrequest.foiministryrequestid = ministryschema[
            "foiministryrequestid"]
        foiministryrequest.version = ministryschema["version"] + 1
        foiministryrequest.foirequest_id = ministryschema["foirequest_id"]
        foiministryrequest.foirequestversion_id = ministryschema[
            "foirequestversion_id"]
        foiministryrequest.description = ministryschema["description"]
        foiministryrequest.recordsearchfromdate = requestdict[
            'recordsearchfromdate']
        foiministryrequest.recordsearchtodate = requestdict[
            'recordsearchtodate']
        foiministryrequest.filenumber = ministryschema["filenumber"]
        foiministryrequest.cfrduedate = requestdict['cfrduedate']
        foiministryrequest.startdate = requestdict['startdate']
        foiministryrequest.duedate = requestdict['duedate']
        foiministryrequest.assignedministrygroup = requestdict[
            'assignedministrygroup']
        if 'assignedministryperson' in requestschema:
            foiministryrequest.assignedministryperson = requestschema[
                'assignedministryperson']
            firstname = requestschema[
                'assignedministrypersonFirstName'] if requestschema[
                    'assignedministryperson'] != None else None
            middlename = None
            lastname = requestschema[
                'assignedministrypersonLastName'] if requestschema[
                    'assignedministryperson'] != None else None
            self.createfoiassigneefromobject(
                requestschema['assignedministryperson'], firstname, middlename,
                lastname)
        else:
            foiministryrequest.assignedministryperson = ministryschema[
                "assignedministryperson"]

        foiministryrequest.assignedgroup = requestdict['assignedgroup']
        if 'assignedto' in requestschema:
            foiministryrequest.assignedto = requestschema['assignedto']
            fn = requestschema['assignedtoFirstName'] if requestschema[
                'assignedto'] != None else None
            mn = None
            ln = requestschema['assignedtoLastName'] if requestschema[
                'assignedto'] != None else None
            self.createfoiassigneefromobject(requestschema['assignedto'], fn,
                                             mn, ln)
        else:
            foiministryrequest.assignedto = ministryschema["assignedto"]

        foiministryrequest.requeststatusid = requestdict['requeststatusid']
        foiministryrequest.programareaid = requestdict['programareaid']
        foiministryrequest.createdby = userid
        if 'divisions' in requestschema:
            foiministryrequest.divisions = self.createfoirequestdivision(
                requestschema, ministryschema["foiministryrequestid"],
                ministryschema["version"] + 1, userid)
        else:
            divisions = FOIMinistryRequestDivision().getdivisions(
                ministryschema["foiministryrequestid"],
                ministryschema["version"])
            foiministryrequest.divisions = self.createfoirequestdivisionfromobject(
                divisions, ministryschema["foiministryrequestid"],
                ministryschema["version"] + 1, userid)
        foiministryrequest.documents = self.createfoirequestdocuments(
            requestschema, ministryschema["foiministryrequestid"],
            ministryschema["version"] + 1, userid)
        foiministryrequest.extensions = self.createfoirequestextensions(
            ministryschema["foiministryrequestid"],
            ministryschema["version"] + 1, userid)
        foiministryrequest.closedate = requestdict['closedate']
        foiministryrequest.closereasonid = requestdict['closereasonid']
        return foiministryrequest
Esempio n. 2
0
    def createministry(self,
                       requestschema,
                       ministry,
                       activeversion,
                       userid,
                       filenumber=None,
                       ministryid=None):
        foiministryrequest = FOIMinistryRequest()
        foiministryrequest.__dict__.update(ministry)
        foiministryrequest.requeststatusid = requestschema.get(
            "requeststatusid")
        foiministryrequest.isactive = True
        foiministryrequest.filenumber = self.generatefilenumber(
            ministry["code"], requestschema.get(
                "foirawrequestid")) if filenumber is None else filenumber
        foiministryrequest.programareaid = self.getvalueof(
            "programArea", ministry["code"])
        foiministryrequest.description = requestschema.get("description")
        foiministryrequest.duedate = requestschema.get("dueDate")
        if requestschema.get("cfrDueDate") is not None and requestschema.get(
                "cfrDueDate") != "":
            foiministryrequest.cfrduedate = requestschema.get("cfrDueDate")
        foiministryrequest.startdate = requestschema.get("startDate")
        foiministryrequest.created_at = datetime2.now().isoformat()
        foiministryrequest.createdby = userid
        requeststatusid = self.getpropertyvaluefromschema(
            requestschema, 'requeststatusid')
        if requeststatusid is not None:
            status = self.getstatusname(requeststatusid)
            if self.__isgrouprequired(status):
                foiministryrequest.assignedministrygroup = MinistryTeamWithKeycloackGroup[
                    ministry["code"]].value
        if self.isNotBlankorNone(requestschema, "fromDate", "main") == True:
            foiministryrequest.recordsearchfromdate = requestschema.get(
                "fromDate")
        if self.isNotBlankorNone(requestschema, "toDate", "main") == True:
            foiministryrequest.recordsearchtodate = requestschema.get("toDate")
        foiministryrequest.assignedgroup = requestschema.get("assignedGroup")
        if self.isNotBlankorNone(requestschema, "assignedTo", "main") == True:
            foiministryrequest.assignedto = requestschema.get("assignedTo")
            requestserviceministrybuilder().createfoiassigneefromobject(
                requestschema.get("assignedTo"),
                requestschema.get("assignedToFirstName"),
                requestschema.get("assignedToMiddleName"),
                requestschema.get("assignedToLastName"))
        else:
            foiministryrequest.assignedto = None
        if self.isNotBlankorNone(requestschema, "assignedministrygroup",
                                 "main") == True:
            foiministryrequest.assignedministrygroup = requestschema.get(
                "assignedministrygroup")
        if self.isNotBlankorNone(requestschema, "assignedministryperson",
                                 "main") == True:
            foiministryrequest.assignedministryperson = requestschema.get(
                "assignedministryperson")
            requestserviceministrybuilder().createfoiassigneefromobject(
                requestschema.get("assignedministryperson"),
                requestschema.get("assignedministrypersonFirstName"),
                requestschema.get("assignedministrypersonMiddleName"),
                requestschema.get("assignedministrypersonLastName"))
        if (ministryid is None and filenumber is None and status == "Open"):
            foiministryrequest.assignedto = None
            foiministryrequest.assignedgroup = self.__getgroupname(
                requestschema.get("requestType"), ministry["code"])

        if ministryid is not None:
            foiministryrequest.foiministryrequestid = ministryid
            activeversion = FOIMinistryRequest.getversionforrequest(
                ministryid)[0] + 1
            divisions = FOIMinistryRequestDivision().getdivisions(
                ministryid, activeversion - 1)
            foiministryrequest.divisions = requestserviceministrybuilder(
            ).createfoirequestdivisionfromobject(divisions, ministryid,
                                                 activeversion, userid)
            foiministryrequest.documents = requestserviceministrybuilder(
            ).createfoirequestdocuments(requestschema, ministryid,
                                        activeversion, userid)
            foiministryrequest.extensions = requestserviceministrybuilder(
            ).createfoirequestextensions(ministryid, activeversion, userid)
        foiministryrequest.version = activeversion
        foiministryrequest.closedate = self.getpropertyvaluefromschema(
            requestschema, 'closedate')
        foiministryrequest.closereasonid = self.getpropertyvaluefromschema(
            requestschema, 'closereasonid')
        return foiministryrequest