Пример #1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('job',
                            type=int,
                            required=True,
                            help="This field cannot be blank")
        parser.add_argument('user',
                            type=int,
                            required=True,
                            help="This field cannot be blank")
        data = parser.parse_args()
        application_job = data['job']
        application_candidate = data['user']
        find_if_application_exists = ApplicationModel.find_by_job_and_candidate(
            application_job, application_candidate)
        if find_if_application_exists:
            return {
                'message':
                'Application Already exists with the job and the candidate'
            }, 400

        job = ApplicationModel(application_job, application_candidate)
        job.save_to_db()

        return {'message': 'Application Created Successfully'}, 200
Пример #2
0
    def delete(self, lendercode):
        if not safe_str_cmp(current_identity.lendercode, '000'):
            return {
                "Message":
                "You do not have the rights to create lenders. Please consult a member of (000) Admin Lender."
            }, 401
        lender = LenderModel.find_by_lendercode(lendercode)
        if lender is None:
            return {
                "Message":
                "No lender with lendercode '{}' exists.".format(lendercode)
            }, 304
        if safe_str_cmp(lendercode, '000'):
            return {"Message": "Lender 000 cannot be deleted."}, 403

        try:
            UserModel.delete_all_by_lendercode(lendercode)
            ApplicationModel.delete_all_by_lendercode(lendercode)
            lender.delete_from_db()
            return {
                "Message":
                "Lender and all related users/applications were deleted successfully."
            }, 200
        except RuntimeError:
            return {
                "Message":
                "Problem deleting. Please try again. Error: " +
                ReferenceError.message
            }, 500
    def get(cls):
        '''Get All Applications'''
        try:
            claims = get_jwt_claims()
            if claims:
                if claims['is_admin']:
                    applications = ApplicationModel.fetch_all()
                    if applications:
                        return application_schemas.dump(applications), 200
                    return {
                        'message': 'There are no antivirus applications yet.'
                    }, 404
            applications = ApplicationModel.fetch_all()
            if applications:
                application_list = application_schemas.dump(applications)
                for application in application_list:
                    license_count = len(application['licenses'])
                    application['licenses'] = license_count
                return application_list, 200
            return {'message': 'There are no antivirus applications yet.'}, 404

        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not retrieve any applications.'}, 500
    def post(cls):
        '''Post Application'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            args = upload_parser.parse_args()
            description = args['description'].title()
            software_id = args['software_id']

            image_file = args.get('logo')  # This is FileStorage instance

            if description == '':
                return {'message': 'You never included a description.'}, 400

            software = SoftwareModel.fetch_by_id(id=software_id)
            if software:
                price = args['price']
                download_link = args['download_link']

                if image_file.filename == '':
                    return {'message': 'No logo was found.'}, 400

                if image_file and allowed_file(image_file.filename):
                    logo = secure_filename(image_file.filename)
                    image_file.save(os.path.join('uploads', logo))

                    new_application = ApplicationModel(
                        logo=logo,
                        description=description,
                        download_link=download_link,
                        price=price,
                        software_id=software_id)
                    new_application.insert_record()

                    # Record this event in user's logs
                    log_method = 'post'
                    log_description = f'Added application <{description}> to software <{software_id}>'
                    authorization = request.headers.get('Authorization')
                    auth_token = {"Authorization": authorization}
                    record_user_log(auth_token, log_method, log_description)

                    return {'application': description}, 201
                return {
                    'message': 'The logo you uploaded is not recognised.'
                }, 400
            return {
                'message':
                'The specified software does not exist for this application!'
            }, 400

        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not submit application.'}, 500
    def delete(cls, id: int):
        '''Delete Application'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            application = ApplicationModel.fetch_by_id(id)
            if application:
                ApplicationModel.delete_by_id(id)

                # Record this event in user's logs
                log_method = 'delete'
                log_description = f'Deleted application <{id}>'
                authorization = request.headers.get('Authorization')
                auth_token = {"Authorization": authorization}
                record_user_log(auth_token, log_method, log_description)
                return {'message': f'Deleted software <{id}>'}, 200
            return {'message': 'This record does not exist!'}, 404

        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not delete this application.'}, 500
Пример #6
0
    def get(self):
        applications = ApplicationModel.find_all()
        print(type(applications))
        list_of_applications = []
        for application in applications:
            list_of_applications.append(application.json())

        return list_of_applications
Пример #7
0
 def get(self, id):
     application = ApplicationModel.find_by_id(id)
     if application is not None:
         job = application.json()['job']
         candidate = application.json()['candidate']
         return {'job': job, 'candidate': candidate}, 200
     else:
         return {'error': 'Application with that id doesnot exist'}, 404
Пример #8
0
    def post(self):
        data = Application.parser.parse_args()
        if not safe_str_cmp(
                current_identity.lendercode, '000') and not safe_str_cmp(
                    current_identity.lendercode, '1') and not safe_str_cmp(
                        current_identity.lendercode, data['lendercode']):
            return {
                'Message':
                "You do not have access to submit to that lender. Application lendercode: {} and User lendercode: {}"
                .format(data['lendercode'], current_identity.lendercode)
            }, 401

        appData = (data['firstname'], data['lastname'], data['ssn'],
                   data['employer'], data['income'], data['incomeFrequency'],
                   data['requestedAmount'], data['requestedTerm'],
                   data['phoneNumber'], data['emailAddress'],
                   data['isBranchEmployee'], data['employeeID'],
                   data['lendercode'], "Submitted")
        application = ApplicationModel(appData)
        application.getNewStatus()
        application.save_to_db()
        return {
            'Message': 'Application submitted successfully.',
            'Application': application.json()
        }, 200
Пример #9
0
    def get(self):
        apps = ApplicationModel.all()

        if not apps:
            return {'message': 'No applications was found'}, 404

        return {
            'applications': [application.json() for application in apps]
        }, 200
Пример #10
0
    def get(self, code):
        if not safe_str_cmp(current_identity.lendercode,
                            '000') and not safe_str_cmp(
                                current_identity.lendercode, code):
            return {
                'Message':
                "You do not have access to those applications. Attempted lendercode: {} and User lendercode: {}"
                .format(code, current_identity.lendercode)
            }, 401

        return {'Applications': ApplicationModel.find_by_lender(code)}, 200
Пример #11
0
    def get(self, id):
        application = ApplicationModel.find_by_job(id)
        candidate_list_id = []
        for appl in application:
            candidate_list_id.append(appl.json()['candidate'])
        candidates_applied = []
        for id in candidate_list_id:
            candidate = UserModel.find_by_id(id).json()
            candidates_applied.append(candidate)

        return candidates_applied
    def put(cls, id: int):
        '''Update Logo'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            args = logo_parser.parse_args()
            image_file = args.get('logo')  # This is FileStorage instance

            application = ApplicationModel.fetch_by_id(id)
            if application:
                if image_file.filename == '':
                    return {'message': 'No logo was found.'}, 400

                if image_file and allowed_file(image_file.filename):
                    logo = secure_filename(image_file.filename)
                    image_file.save(os.path.join('uploads', logo))

                    ApplicationModel.update_logo(id=id, logo=logo)

                    # Record this event in user's logs
                    log_method = 'put'
                    log_description = f'Updated logo for application <{id}>'
                    authorization = request.headers.get('Authorization')
                    auth_token = {"Authorization": authorization}
                    record_user_log(auth_token, log_method, log_description)
                    return application_schema.dump(application), 200
                return {
                    'message': 'The logo you uploaded is not recognised.'
                }, 400
            return {'message': 'This record does not exist!'}, 404

        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not submit software logo.'}, 500
Пример #13
0
    def post(self):

        parser = self.default_parser
        parser.add_argument('name',
                            type=str,
                            required=True,
                            help="An app needs a name")
        parser.add_argument('photo', type=str)
        parser.add_argument('description', type=str)
        data = parser.parse_args()

        app = ApplicationModel.find_by_name(data.get('name'))

        if app:
            return {
                'message':
                'Application is already registered with id {}'.format(app.id)
            }

        app = ApplicationModel(**data)

        try:
            app.save_to_db()
        except Exception as e:
            return {
                'message': 'something goes wrong with your insert db action',
                'error': e.args
            }

        return app.json(), 201
Пример #14
0
class ApplicationService():
    m_application = ApplicationModel()

    @gen.coroutine
    def insert_application(self, application, callback=None):
        project_url = application.get("project_url", None)
        if project_url is None:
            raise gen.Return(None)
        app = yield self.m_application.find_one({"project_url": project_url})
        model = {}
        if app is None:
            model = yield self.m_application.insert_one(application)
            app = yield self.m_application.find_one(model.inserted_id)
        else:
            model = yield self.m_application.update_one(
                {"project_url": project_url}, {"$set": application})
        raise gen.Return(application)

    @gen.coroutine
    def exist_application(self, project_url, callback=None):
        result = yield self.m_application.find_one(
            {"project_url": project_url})
        if result == None or not isinstance(result, dict):
            raise gen.Return(False)
        else:
            raise gen.Return(True)

    @gen.coroutine
    def find_one(self, project_url, callback=None):
        print project_url
        result = yield self.m_application.find_one(
            {"project_url": project_url})
        if result == None or not isinstance(result, dict):
            raise gen.Return(None)
        else:
            raise gen.Return(result)

    @gen.coroutine
    def get_appliactions(self,
                         spec,
                         fields=None,
                         sorts=None,
                         page_index=0,
                         page_size=20,
                         callback=None):
        skip = page_index * page_size
        result_list = yield self.m_application.get_list(
            spec, fields, sorts, skip, page_size)
        if not result_list or len(result_list) == 0:
            raise gen.Return(None)
        else:
            raise gen.Return(result_list)
Пример #15
0
 def getSecurtyIds(self, appId):
     if appId in self.appSecurtyDict.keys():
         return self.appSecurtyDict[appId]
     SecurtyIdArray = []
     Application = ApplicationModel.find_by_id(appId)
     SecurityApplictions = SecurityApplictionModel.find_by_applicationID(
         appId)
     for SecurityAppliction in SecurityApplictions:
         # check if to this security have image
         if SecurityAppliction.securityRankIdFeature != -1:
             SecurtyIdArray.append(SecurityAppliction.securityId)
     self.appSecurtyDict[appId] = SecurtyIdArray
     return self.appSecurtyDict[appId]
Пример #16
0
    def get(self, id):
        claims = get_jwt_claims()
        print(claims)
        application = ApplicationModel.find_by_candidate(id)
        job_list_id = []
        for appl in application:
            job_list_id.append(appl.json()['job'])
        jobs_applied = []
        for list_of_jobs in job_list_id:
            job_list = JobModel.find_by_id(list_of_jobs).json()
            jobs_applied.append(job_list)

        return jobs_applied
Пример #17
0
    def get(self, _id):
        application = ApplicationModel.find_by_id(_id)
        if not safe_str_cmp(
                current_identity.lendercode, '000') and not safe_str_cmp(
                    current_identity.lendercode, application.lendercode):
            return {
                'Message':
                "You do not have access to that application. Application lendercode: {} and User lendercode: {}"
                .format(application.lendercode, current_identity.lendercode)
            }, 401

        if application:
            return {'Application': application.json()}, 200
        return {"Message": "No application found with that ID."}, 404
    def put(cls, id: int):
        '''Update Application'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message':
                    'You are not authorised to access this resource!'
                }, 403

            data = api.payload
            if not data:
                return {'message': 'No input data detected!'}, 400

            # description = data['description']
            # download_link = data['download_link']
            # price = data['price']

            application = ApplicationModel.fetch_by_id(id)
            if application:
                ApplicationModel.update_application(
                    id=id, **data
                )  # description=description, download_link=download_link, price=price)

                # Record this event in user's logs
                log_method = 'put'
                log_description = f'Updated application <{id}>'
                authorization = request.headers.get('Authorization')
                auth_token = {"Authorization": authorization}
                record_user_log(auth_token, log_method, log_description)
                return application_schema.dump(application), 200
            return {'message': 'This record does not exist.'}, 404
        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not update application.'}, 500
 def get(cls, software_id: int):
     '''Get Application by software'''
     try:
         applications = ApplicationModel.fetch_by_software_id(software_id)
         if applications:
             application_list = application_schemas.dump(applications)
             for application in application_list:
                 license_count = len(application['licenses'])
                 application['licenses'] = license_count
             return application_list, 200
         return {'message': 'These records do not exist.'}, 404
     except Exception as e:
         print('========================================')
         print('Error description: ', e)
         print('========================================')
         return {'message': 'Could not retrieve application.'}, 500
 def get(cls, id: int):
     '''Get Single Application'''
     try:
         application = ApplicationModel.fetch_by_id(id)
         if application:
             app = application_schema.dump(application)
             license_count = len(app['licenses'])
             app['licenses'] = license_count
             return app, 200
         return {
             'message': 'This antivirus application does not exist.'
         }, 404
     except Exception as e:
         print('========================================')
         print('Error description: ', e)
         print('========================================')
         return {'message': 'Could not retrieve application.'}, 500
Пример #21
0
    def put(self):
        data = Application.parser.parse_args()
        application = ApplicationModel.find_by_id(data['id'])
        if application == None:
            return {
                'Message':
                "Application with id of '{}' does not exist.".format(
                    data['id'])
            }, 404
        if not safe_str_cmp(
                current_identity.lendercode, '000') and not safe_str_cmp(
                    current_identity.lendercode, application.lendercode):
            return {
                'Message':
                "You do not have access to that application. Application lendercode: {} and User lendercode: {}"
                .format(application.lendercode, current_identity.lendercode)
            }, 401

        application.firstname = data['firstname']
        application.lastname = data['lastname']
        application.ssn = data['ssn']
        application.employer = data['employer']
        application.income = data['income']
        application.incomeFrequency = data['incomeFrequency']
        application.requestedAmount = data['requestedAmount']
        application.requestedTerm = data['requestedTerm']
        application.phoneNumber = data['phoneNumber']
        application.emailAddress = data['emailAddress']
        application.isBranchEmployee = data['isBranchEmployee']
        application.employeeID = data['employeeID']
        application.lendercode = data['lendercode']
        application.status = "Re-Submitted"

        if data['status']:
            application.status = data['status']
        else:
            application.getNewStatus()

        application.save_to_db()
        return {
            'Message': 'Application re-submitted successfully.',
            'Application': application.json()
        }, 200
Пример #22
0
    def delete(self, _id):
        application = ApplicationModel.find_by_id(_id)
        if application is None:
            return {
                'Message':
                "Application with id of '{}' does not exist.".format(_id)
            }, 404
        if not safe_str_cmp(
                current_identity.lendercode, '000') and not safe_str_cmp(
                    current_identity.lendercode, application.lendercode):
            return {
                'Message':
                "You do not have access to that application. Application lendercode: {} and User lendercode: {}"
                .format(application.lendercode, current_identity.lendercode)
            }, 401

        if application:
            application.delete_from_db()

        return {'Message': 'Application deleted.'}, 200
Пример #23
0
    def post(cls):
        '''Post License'''
        try:
            claims = get_jwt_claims()
            if not claims['is_admin']:
                return {
                    'message': 'You are not authorised to use this resource'
                }, 403

            data = api.payload
            if not data:
                return {'message': 'No input data detected'}, 400

            application_id = data['application_id']
            license_key = data['license_key']

            if license_key == '':
                return {'message': 'You have not specified any key.'}, 400

            application = ApplicationModel.fetch_by_id(id=application_id)
            if application:
                new_license = LicenseModel(application_id=application_id,
                                           license_key=license_key)
                new_license.insert_record()

                # Record this event in user's logs
                log_method = 'post'
                log_description = f'Added license to application <{application_id}>'
                authorization = request.headers.get('Authorization')
                auth_token = {"Authorization": authorization}
                record_user_log(auth_token, log_method, log_description)

                return {'message': 'Successfully added license'}, 201
            return {
                'message': 'The specified application does not exist.'
            }, 400
        except Exception as e:
            print('========================================')
            print('Error description: ', e)
            print('========================================')
            return {'message': 'Could not fetch licenses.'}, 500
Пример #24
0
    def get(self, id):
        claims = get_jwt_claims()
        print(claims)
        if claims['identity'] == id:
            application = ApplicationModel.find_by_candidate(id)
            job_list_id = []
            for appl in application:
                job_list_id.append(appl.json()['job'])
            jobs_applied = []
            for list_of_jobs in job_list_id:
                job_list = json.dumps(JobModel.find_by_id(list_of_jobs).json(),
                                      indent=1,
                                      sort_keys=True,
                                      default=str)
                jobs_applied.append(json.loads(job_list))

            return jobs_applied
        else:
            return {
                'message': 'Unauthorized Access',
                'error': 'authorization_required'
            }, 401
Пример #25
0
 def getAppImage(self, appId):
     if appId in self.appDict.keys():
         return self.appDict[appId]
     root = '/pictures/'
     imageDict = {}
     imageArray = []
     Application = ApplicationModel.find_by_id(appId)
     if (Application != False):
         imageDict['picture1'] = root + Application.picture1
         imageDict['picture2'] = root + Application.picture2
         imageArray.append(Application.picture1)
         imageArray.append(Application.picture2)
     SecurityApplictions = SecurityApplictionModel.find_by_applicationID(
         appId)
     imageDict['securtyImges'] = []
     for SecurityAppliction in SecurityApplictions:
         # check if to this security have image
         if SecurityAppliction.securityRankIdFeature != -1:
             imageDict['securtyImges'].append(root +
                                              SecurityAppliction.image)
             imageArray.append(SecurityAppliction.image)
     self.appDict[appId] = imageDict
     return imageDict
Пример #26
0
    def get(self, id):
        claims = get_jwt_claims()
        id_recruiter = claims['identity']
        jobs = JobModel.find_by_posted_by(id_recruiter)
        id_exists = False
        for job in jobs:
            if job.json()['id'] == id:
                id_exists = True

        if id_exists:
            application = ApplicationModel.find_by_job(id)
            candidate_list_id = []
            for appl in application:
                candidate_list_id.append(appl.json()['candidate'])
            candidates_applied = []
            for id in candidate_list_id:
                candidate = UserModel.find_by_id(id).json()
                candidates_applied.append(candidate)
            return candidates_applied
        else:
            return {
                'message': 'Job Not Associated with the recruiter',
                'error': 'unauthorized_access'
            }, 401
Пример #27
0
    def getApplictionTable(self):
        applicationsCategory1 = ApplicationModel.find_by_categoryId(1)
        applicationsCategory2 = ApplicationModel.find_by_categoryId(2)
        applicationsCategory3 = ApplicationModel.find_by_categoryId(3)
        applicationsCategory4 = ApplicationModel.find_by_categoryId(4)

        privacies = PrivacyModel.find_all_PrivacyFact()
        RankPrivacy = RankPrivacyModel.find_all_RankPrivacy()
        PrivaciesAppliction = PrivacyApplictionModel.find_all_PrivacyFact()

        Securties = SecurtyModel.find_all_SecurtyFeature()
        RankSecurty = RankSecurtyModel.find_all_RankSecurty()
        SecuritiesAppliction = SecurityApplictionModel.find_all_SecurityAppliction(
        )
        SecurityApplictionDescriptions = SecurityApplictionDescriptionModel.find_all(
        )

        table = []
        privacyDict = unionModel.getPrivacyDict(privacies)
        privacyRankDict = unionModel.getPrivacyRankDict(RankPrivacy)

        SecurtyDict = unionModel.getSecurtyDict(Securties)
        SecurtyRankDict = unionModel.getSecurtyRankDict(RankSecurty)

        for applicationCategory1 in applicationsCategory1:
            column = {}
            column['id'] = str(applicationCategory1.id)
            column['realName'] = str(applicationCategory1.realName)
            column['falseName'] = str(applicationCategory1.falseName)
            column['category'] = 'high privacy and high security'
            column['Traditional_summary_old'] = {}
            column['Traditional_summary_new'] = {}
            column['Contextual'] = {}
            column['Traditional_summary_old']['Privacy'] = {}
            column['Traditional_summary_new']['Privacy'] = {}
            for PrivacyAppliction in PrivaciesAppliction:
                if (PrivacyAppliction.applicationId == applicationCategory1.id
                        and PrivacyAppliction.part == 1):
                    column['Traditional_summary_old']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
                if (PrivacyAppliction.applicationId == applicationCategory1.id
                        and PrivacyAppliction.part == 2):
                    column['Traditional_summary_new']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
            column['Traditional_summary_old']['Security'] = {}
            column['Traditional_summary_new']['Security'] = {}
            for SecurityAppliction in SecuritiesAppliction:
                if (SecurityAppliction.applicationId == applicationCategory1.id
                        and SecurityAppliction.part == 1):
                    column['Traditional_summary_old']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                if (SecurityAppliction.applicationId == applicationCategory1.id
                        and SecurityAppliction.part == 2):
                    column['Traditional_summary_new']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                    if (SecurityAppliction.securityRankIdFeature != -1):
                        column['Contextual'][str(
                            SecurtyDict[SecurityAppliction.securityId])] = {}
                    for SecurityApplictionDescription in SecurityApplictionDescriptions:
                        if (SecurityApplictionDescription.securityApplictionId
                                == SecurityAppliction.id):
                            column['Contextual'][str(
                                SecurtyDict[SecurityAppliction.securityId]
                            )][privacyDict[SecurityApplictionDescription.
                                           privacyId]] = privacyRankDict[
                                               SecurityApplictionDescription.
                                               privacyRankId]
            table.append(column)

        for applicationCategory2 in applicationsCategory2:
            column = {}
            column['id'] = str(applicationCategory2.id)
            column['realName'] = str(applicationCategory2.realName)
            column['falseName'] = str(applicationCategory2.falseName)
            column['category'] = 'low privacy and high security'
            column['Traditional_summary_old'] = {}
            column['Traditional_summary_new'] = {}
            column['Contextual'] = {}
            column['Traditional_summary_old']['Privacy'] = {}
            column['Traditional_summary_new']['Privacy'] = {}
            for PrivacyAppliction in PrivaciesAppliction:
                if (PrivacyAppliction.applicationId == applicationCategory2.id
                        and PrivacyAppliction.part == 1):
                    column['Traditional_summary_old']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
                if (PrivacyAppliction.applicationId == applicationCategory2.id
                        and PrivacyAppliction.part == 2):
                    column['Traditional_summary_new']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
            column['Traditional_summary_old']['Security'] = {}
            column['Traditional_summary_new']['Security'] = {}
            for SecurityAppliction in SecuritiesAppliction:
                if (SecurityAppliction.applicationId == applicationCategory2.id
                        and SecurityAppliction.part == 1):
                    column['Traditional_summary_old']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                if (SecurityAppliction.applicationId == applicationCategory2.id
                        and SecurityAppliction.part == 2):
                    column['Traditional_summary_new']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                    if (SecurityAppliction.securityRankIdFeature != -1):
                        column['Contextual'][str(
                            SecurtyDict[SecurityAppliction.securityId])] = {}
                    for SecurityApplictionDescription in SecurityApplictionDescriptions:
                        if (SecurityApplictionDescription.securityApplictionId
                                == SecurityAppliction.id):
                            column['Contextual'][str(
                                SecurtyDict[SecurityAppliction.securityId]
                            )][privacyDict[SecurityApplictionDescription.
                                           privacyId]] = privacyRankDict[
                                               SecurityApplictionDescription.
                                               privacyRankId]
            table.append(column)

        for applicationCategory3 in applicationsCategory3:
            column = {}
            column['id'] = str(applicationCategory3.id)
            column['realName'] = str(applicationCategory3.realName)
            column['falseName'] = str(applicationCategory3.falseName)
            column['category'] = 'high privacy and low security'
            column['Traditional_summary_old'] = {}
            column['Traditional_summary_new'] = {}
            column['Contextual'] = {}
            column['Traditional_summary_old']['Privacy'] = {}
            column['Traditional_summary_new']['Privacy'] = {}
            for PrivacyAppliction in PrivaciesAppliction:
                if (PrivacyAppliction.applicationId == applicationCategory3.id
                        and PrivacyAppliction.part == 1):
                    column['Traditional_summary_old']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
                if (PrivacyAppliction.applicationId == applicationCategory3.id
                        and PrivacyAppliction.part == 2):
                    column['Traditional_summary_new']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
            column['Traditional_summary_old']['Security'] = {}
            column['Traditional_summary_new']['Security'] = {}
            for SecurityAppliction in SecuritiesAppliction:
                if (SecurityAppliction.applicationId == applicationCategory3.id
                        and SecurityAppliction.part == 1):
                    column['Traditional_summary_old']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                if (SecurityAppliction.applicationId == applicationCategory3.id
                        and SecurityAppliction.part == 2):
                    column['Traditional_summary_new']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                    if (SecurityAppliction.securityRankIdFeature != -1):
                        column['Contextual'][str(
                            SecurtyDict[SecurityAppliction.securityId])] = {}
                    for SecurityApplictionDescription in SecurityApplictionDescriptions:
                        if (SecurityApplictionDescription.securityApplictionId
                                == SecurityAppliction.id):
                            column['Contextual'][str(
                                SecurtyDict[SecurityAppliction.securityId]
                            )][privacyDict[SecurityApplictionDescription.
                                           privacyId]] = privacyRankDict[
                                               SecurityApplictionDescription.
                                               privacyRankId]
            table.append(column)

        for applicationCategory4 in applicationsCategory4:
            column = {}
            column['id'] = str(applicationCategory4.id)
            column['realName'] = str(applicationCategory4.realName)
            column['falseName'] = str(applicationCategory4.falseName)
            column['category'] = 'low privacy and low security'
            column['Traditional_summary_old'] = {}
            column['Traditional_summary_new'] = {}
            column['Contextual'] = {}
            column['Traditional_summary_old']['Privacy'] = {}
            column['Traditional_summary_new']['Privacy'] = {}
            for PrivacyAppliction in PrivaciesAppliction:
                if (PrivacyAppliction.applicationId == applicationCategory4.id
                        and PrivacyAppliction.part == 1):
                    column['Traditional_summary_old']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
                if (PrivacyAppliction.applicationId == applicationCategory4.id
                        and PrivacyAppliction.part == 2):
                    column['Traditional_summary_new']['Privacy'][str(
                        privacyDict[PrivacyAppliction.privacyId]
                    )] = privacyRankDict[PrivacyAppliction.privacyRankId]
            column['Traditional_summary_old']['Security'] = {}
            column['Traditional_summary_new']['Security'] = {}
            for SecurityAppliction in SecuritiesAppliction:
                if (SecurityAppliction.applicationId == applicationCategory4.id
                        and SecurityAppliction.part == 1):
                    column['Traditional_summary_old']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                if (SecurityAppliction.applicationId == applicationCategory4.id
                        and SecurityAppliction.part == 2):
                    column['Traditional_summary_new']['Security'][str(
                        SecurtyDict[SecurityAppliction.securityId]
                    )] = SecurtyRankDict[SecurityAppliction.securityRankId]
                    if (SecurityAppliction.securityRankIdFeature != -1):
                        column['Contextual'][str(
                            SecurtyDict[SecurityAppliction.securityId])] = {}
                    for SecurityApplictionDescription in SecurityApplictionDescriptions:
                        if (SecurityApplictionDescription.securityApplictionId
                                == SecurityAppliction.id):
                            column['Contextual'][str(
                                SecurtyDict[SecurityAppliction.securityId]
                            )][privacyDict[SecurityApplictionDescription.
                                           privacyId]] = privacyRankDict[
                                               SecurityApplictionDescription.
                                               privacyRankId]
            table.append(column)

        return table
Пример #28
0
    def get(self, _id=None):
        app = ApplicationModel.find_by_id(_id)
        if app:
            return app.json(), 200

        return {'message': 'Application not found'.format(_id)}, 404
Пример #29
0
 def getExperimentTable(self):
     Experiments = ExperimentModel.find_all_Experiment()
     ExperimentApps = ExperimentAppModel.find_all_ExperimentApp()
     Application = ApplicationModel.find_all()
     ExperimentDetailes = ExperimentDetaileModel.find_all_ExperimentDetailes(
     )
     users = UserModel.find_all_user()
     table = []
     dictApp = unionModel.getApplictionsDict(Application)
     dictUser = unionModel.getUsersDict(users)
     for Experiment in Experiments:
         column = {}
         column['id'] = str(Experiment.id)
         if (str(Experiment.type) == '1'):
             column['type'] = 'Type 1 experiment'
         else:
             if (str(Experiment.type) == '2'):
                 column['type'] = 'Type 2 experiment'
             else:
                 column['type'] = 'Type 3 experiment'
         column['Number of participants'] = str(Experiment.numberParti)
         if (Experiment.run == 1):
             column['done'] = 'no'
         else:
             column['done'] = 'yes'
         column['app in experiment'] = []
         for ExperimentApp in ExperimentApps:
             if (ExperimentApp.ExperimentId == Experiment.id):
                 column['app in experiment'].append(
                     dictApp[ExperimentApp.applicationId])
         column['ExperimentDetaile'] = {}
         for ExperimentDetaile in ExperimentDetailes:
             if ExperimentDetaile.ExperimentId == Experiment.id:
                 column['ExperimentDetaile'][
                     ExperimentDetaile.groupExp] = {}
                 column['ExperimentDetaile'][
                     ExperimentDetaile.groupExp]['user'] = '******'
                 column['ExperimentDetaile'][
                     ExperimentDetaile.groupExp]['order'] = []
         for ExperimentDetaile in ExperimentDetailes:
             if ExperimentDetaile.ExperimentId == Experiment.id:
                 if ExperimentDetaile.userID != 0:
                     column['ExperimentDetaile'][
                         ExperimentDetaile.groupExp]['user'] = dictUser[
                             ExperimentDetaile.userID]
                 if ExperimentDetaile.questionDisplay == 1:
                     column['ExperimentDetaile'][ExperimentDetaile.groupExp][
                         'questionDisplay'] = 'new traditional summary => Security features'
                 else:
                     if ExperimentDetaile.questionDisplay == 2:
                         column['ExperimentDetaile'][
                             ExperimentDetaile.groupExp][
                                 'questionDisplay'] = 'Security features => new traditional summary'
                     else:
                         if ExperimentDetaile.questionDisplay == 3:
                             column['ExperimentDetaile'][
                                 ExperimentDetaile.groupExp][
                                     'questionDisplay'] = 'Security features'
                         else:
                             if ExperimentDetaile.questionDisplay == 4:
                                 column['ExperimentDetaile'][
                                     ExperimentDetaile.groupExp][
                                         'questionDisplay'] = 'old traditional summary'
                             else:
                                 column['ExperimentDetaile'][
                                     ExperimentDetaile.groupExp][
                                         'questionDisplay'] = 'new traditional summary'
                 column['ExperimentDetaile'][
                     ExperimentDetaile.groupExp]['order'].append(
                         dictApp[ExperimentDetaile.applicationId])
         table.append(column)
     return table
Пример #30
0
    def getAnswerTable(self, experimentId):
        Experiment = ExperimentModel.find_by_id(experimentId)
        ExperimentDetailes = ExperimentDetaileModel.find_all_ExperimentDetailes_by_ExperimentID(
            experimentId)
        users = UserModel.find_all_user()
        table = []
        Application = ApplicationModel.find_all()
        Questions = QuestionModel.find_all_Question()

        dictApp = unionModel.getApplictionsDict(Application)
        dictUser = unionModel.getUsersDict(users)
        dictQustion = unionModel.getQustionDict(Questions)

        Securties = SecurtyModel.find_all_SecurtyFeature()
        SecurtyDict = unionModel.getSecurtyDict(Securties)

        generalReports = generalReportModel.find_by_experimentId(experimentId)
        column = {}
        column['user'] = '******'
        column['Traditional_summary_old'] = '-'
        column['Traditional_summary_new'] = '-'

        for Securty in Securties:
            column[SecurtyDict[Securty.id]] = '-'
        # run on all grop exp
        j = 0
        for i in range(0, Experiment.numberParti):
            groupExpDict = {}
            for ExperimentDetaile in ExperimentDetailes:
                if ExperimentDetaile.groupExp != i:
                    continue
                j += 1
                dictExp = {}
                strType = ""
                if ExperimentDetaile.questionDisplay == 1:
                    strType = 'new traditional summary => Security features'
                else:
                    if ExperimentDetaile.questionDisplay == 2:
                        strType = 'Security features => new traditional summary'
                    else:
                        if ExperimentDetaile.questionDisplay == 3:
                            strType = 'Security features'
                        else:
                            if ExperimentDetaile.questionDisplay == 4:
                                strType = 'old traditional summary'
                            else:
                                strType = 'new traditional summary'
                key = dictApp[ExperimentDetaile.applicationId] + ': ' + strType
                dictExp[key] = {}
                Reports = ReportModel.find_all_report_by_experimentDetailes(
                    ExperimentDetaile.id)
                for Question in Questions:
                    if (Question.section == 1):
                        columnCopy = column.copy()
                        if (ExperimentDetaile.userID != 0):
                            columnCopy['user'] = dictUser[
                                ExperimentDetaile.userID]
                        for Report in Reports:
                            if (Report.questionID == Question.id):
                                if Report.part == 1:
                                    columnCopy[
                                        'Traditional_summary_old'] = Report.answer
                                else:
                                    if Report.part == 2 and int(
                                            Report.securityId) == 0:
                                        columnCopy[
                                            'Traditional_summary_new'] = Report.answer
                                    else:
                                        columnCopy[SecurtyDict[int(
                                            Report.securityId
                                        )]] = Report.answer
                        dictExp[key][dictQustion[Question.id]] = columnCopy
                groupExpDict[j] = dictExp
            table.append(groupExpDict)

        # generalReport
        columnGeneral = {}
        for Question in Questions:
            if (Question.section == 2):
                columnGeneral[dictQustion[Question.id]] = '-'

        generalDict = {}
        generalDict['general report'] = {}
        lastUser = -1
        for generalReport in generalReports:
            if (lastUser == -1
                    or (lastUser != -1 and lastUser != generalReport.userID)):
                generalDict['general report'][dictUser[
                    generalReport.userID]] = copy.deepcopy(columnGeneral)
            lastUser = generalReport.userID
            generalDict['general report'][dictUser[generalReport.userID]][
                dictQustion[generalReport.questionID]] = generalReport.answer
        table.append(generalDict)

        return table