示例#1
0
文件: Antrag.py 项目: Athos1972/PoLZy
 def announceMessage(message,
                     duration=3000,
                     level='default',
                     horizontal='left',
                     vertical='bottom'):
     """
     Will send a toast to the frontend
     :param message: The message text.
     :param duration: None = user needs to click "close" in order to disappear, any other value in MilliSeconds
                      until the Toast disappears
     :param level: 'info' will provide blue background with white font,
                   'default' will provide black background with white font,
                   'success' will bring green backgroudn
                   'error' --> red background
                   'warning' --> orange background
     :param horizontal: "left", "right", "center"
     :param vertical: "bottom", "top"
     :return:
     """
     logger.debug(f"Announce: {message}")
     msg = json.dumps({
         'text': message,
         'autoHideDuration': duration,
         'variant': level,
         'anchorOrigin': {
             'horizontal': horizontal,
             'vertical': vertical,
         }
     })
     messenger.announce(f"data: {msg}\n\n")
示例#2
0
 def process_data(self):
     logger.debug("Processing data")
     self.processor = Process(self, self.classes)
     self.processor.process()
     DatabaseManager.set_processed(self.fileName, self.unprocessed_db_obj,
                                   self.details)
     logger.debug("Data processed")
示例#3
0
 def create_new(file, extension, parent_id=None):
     id_ = str(uuid4())
     lFile = models.File.new(user=admin, filename=file, id=id_, parent_id=parent_id)
     shutil.move(os.path.join(GlobalConstants.filesPath, file),
                 os.path.join(GlobalConstants.filesPath, id_ + extension))  # rename original filename with id
     logger.debug(f"{file} updated in db and renamed with id {id_}")
     return lFile
示例#4
0
def activityWriter(inInstance):
    """
    The usage of "Antrag" here is wrong, usually it's an AntragActivitiy that will be provided in the call.
    It is anyway important to have this reference because otherwise the "where used" doesn't work for "setSearchString"

    """
    from polzyFunctions.Dataclasses.Antrag import Antrag

    lInstance = None
    try:
        lInstance = inInstance.antrag
    except AttributeError:
        pass

    if not lInstance:
        # this will work if the instance itself is an Antrag (happens so far only when the Tag is changed by
        # frontend
        lInstance: Antrag = inInstance

    logger.debug(f"classname = {lInstance.__class__.__name__}")
    # Update search string in this antrag instance. It is the main search criteria.
    try:
        lInstance.setSearchString()
    except AttributeError:
        logger.critical(
            f"We have instance of Type {type(inInstance)}. We can't currently work with that."
        )
        return

    record = AntragActivityRecords.new(lInstance)
    logger.debug(f"Activity recorded with id: {record.id}")
    return record.timestamp
示例#5
0
文件: Antrag.py 项目: Athos1972/PoLZy
    def setFieldValue(self, fieldName, newValue, optional=False):
        """
        Write a new value into a field of this instance.

        :param fieldName:
        :param newValue:
        :param optional: don't raise an error/write to log, if field does not exist
        :return:
        """
        try:
            lFeld = self.Fields.getField(name=fieldName)
            lFeld.value = newValue
        except Exception as e:
            if not optional:
                logger.critical(
                    f"Should have written {newValue} into field {fieldName} "
                    f"and failed with error {e}. Most probably typo in Program."
                )
                raise AttributeError(
                    f"Should have written {newValue} into field {fieldName} "
                    f"and failed with error {e}. Most probably typo in Program."
                )
            else:
                logger.debug(
                    f"Should have written {newValue} into field {fieldName} "
                    f"and failed with error {e}. Most probably typo in Program. Optional was set, so Ok!"
                )
示例#6
0
 def move_processed_file(file):
     if not os.path.exists(os.path.join(GlobalConstants.filesPath, file)):
         return
     directory = os.path.join(GlobalConstants.archivedFiles, datetime.now().strftime("%Y/%m"))
     os.makedirs(directory, exist_ok=True)
     os.replace(os.path.join(GlobalConstants.filesPath, file), os.path.join(directory, file))
     logger.debug(f"{file} moved to processed directory.")
示例#7
0
 def announceMessage(self,
                     message,
                     duration=3000,
                     level='default',
                     horizontal='left',
                     vertical='bottom'):
     """
     Please see docu in Dataclasses/Antrag.py in announceMessage method
     :param message:
     :param duration:
     :param level:
     :param horizontal:
     :param vertical:
     :return:
     """
     logger.debug(f"Announce message: {message}")
     msg = json.dumps({
         'text': message,
         'autoHideDuration': duration,
         'variant': level,
         'anchorOrigin': {
             'horizontal': horizontal,
             'vertical': vertical,
         }
     })
     messenger.announce(f"data: {msg}\n\n")
示例#8
0
 def getInstance():
     """
     Method to get the singleton instance into any calling class/form
     """
     if not ConfigurationProvider.__instance__:
         logger.info("ConfigurationProvider instance created")
         ConfigurationProvider()
     logger.debug("returning existing ConfigurationProvider")
     return ConfigurationProvider.__instance__
示例#9
0
 def get_data_processing_class(self, data, fileName, original_filename):
     for class_ in self.classes:  # loop through all & ask class if it can process data
         if class_.check_processable(data=data,
                                     filename=os.path.basename(fileName),
                                     original_filename=original_filename):
             logger.debug(
                 f"{class_.__name__} is the assigned class for processing.")
             return class_
     raise ValueError(f"Unable to find class relation")
示例#10
0
文件: utils.py 项目: Athos1972/PoLZy
def setActivities(instance, data: dict):
    logger.debug("Setting fields")
    data = updateFieldDataName(data)
    for key, value in data.items():
        if key == "Versicherungsbeginn":
            instance.setFieldValue(CommonFieldnames.policyBeginDate.value,
                                   value)
            continue
        instance.setFieldValue(key, value)
    logger.debug("Fields set.")
示例#11
0
 def record_login_activity(self):
     # we are importing direct methods here as importing decorator on starting was causing import error
     try:
         from polzyFunctions.GamificationActivityRecorder import WriteActivity
         writer = WriteActivity(self)
         writer.activityWriter()
         return True
     except Exception as ex:
         logger.debug(
             f"Gamification Activity can't be written. "
             f"Most probably no gamification settings provided: {ex}")
示例#12
0
    def getActivitiesForAntrag(self):
        """
        Go through all the activities and ask them if they want to be active
        :return:
        """
        # call method checkIsActivityValidForStatus of activity to know if it is suitable for current stats
        self.possibleActivities = [
            x for x in self.possibleActivities
            if x.checkIsActivityValidForStatus()
        ]

        logger.debug(
            f"List of possible Activities for this Antrag in state {self.antrag.status} is: \n{self.possibleActivities}"
        )
        return self.possibleActivities
示例#13
0
    def get_xlsx_header_alignment(self, sht, data_list):
        header_row_count = 0
        header_col_count = 0
        for cell in data_list[0]:
            if cell.value.lower() in headers:  # counting cell values matching with expected headers for column
                header_col_count += 1

        for row in data_list:
            if row[0].value.lower() in headers:  # counting cell values matching with expected headers for row
                header_row_count += 1

        logger.debug(f"Headers matching: column - {str(header_col_count)}, row - {str(header_row_count)}")
        if header_row_count > header_col_count:  # if row matching header count is greater than rows contain headers
            return "row"
        return "column"
示例#14
0
    def addFields(self):
        if not hasattr(ManageFieldCatalog, self.__class__.__name__):
            logger.debug(f"There is no field list for {self.__class__.__name__}. Most probably OK")
            return

        ManageFieldCatalog.determineLanguage(self)  # set Translator to proper Language

        # Execute filling the field catalog for either the antrag, Policy or Activity.
        try:
            getattr(ManageFieldCatalog, self.__class__.__name__)(self)
            logger.debug(f"FielCatalog created for {self.__class__.__name__}")
        except AttributeError as e:
            logger.exception(f"Building field catalog for {self.__class__.__name__} failed. Error was: {e}")

        # Now, that the field-catalog is built, check if we have default values from
        self.deriveDefaultsFromUserOrCompany()
示例#15
0
    def findActivity(self, activity_name):
        try:
            target_activity = AntragActivity
            lActivity = next(
                filter(lambda x: isinstance(x, target_activity),
                       self.instance.Activities), None)
        except TypeError:
            logger.exception(
                f"Didn't find anything useful for activity {activity_name}. If it's a new activity, then"
                f" make sure you imported it in antrag.py and added it to activity_classes on the top. "
            )
            return None

        logger.debug(
            f"Found existing activity inside Antrag: {lActivity.__class__.__name__}"
        )
        return lActivity
示例#16
0
 def loadFromJsonFromPersistence(self, dic):
     """
     After antrags-instance was loaded from database, this method is called to also load state from JSON.
     :param dic:
     :return:
     """
     logger.debug(f"Updating {self.name} Activity class from json values.")
     for key, value in dic.items():
         if key == "activityFields":  # loading Field data in InputFields
             new_dic = {
                 js.get("name"): (js.get("value")
                                  or js.get("valueChosenOrEntered"))
                 for js in dic[key]
             }
             self.updateFieldValues(new_dic)
         else:
             setattr(self, key, value)
     return self
示例#17
0
    def updateFieldValues(self, updateValues):
        """
        Frontend calls this method e.g. when "inputTriggersComplexUpdate" is set. We'll receive all current fields and
        their values and deal with them accordingly.
        :param updateValues: [{<field>: <value>, {},...]
        :return: nothing
        """
        if not updateValues:
            return

        logger.debug(f'New Values: {updateValues}')
        for name, value in updateValues.items():
            if name == CommonFieldnames.addressDict.value:
                if isinstance(value, dict):
                    for k, v in value.items():
                        self._updateFieldValue(k, v)
                continue

            self._updateFieldValue(name, value)
示例#18
0
文件: utils.py 项目: Athos1972/PoLZy
def updateFieldDataName(data):
    sanitized_data = dict()
    for key, value in data.items():
        if key not in valid_headers:  # then most probably this key contains value of some other keys in it -
            try:
                sanitize = getattr(sys.modules[__name__], key.lower())(
                    value)  # e.g. name is first_name and last_name
                sanitized_data.update(sanitize)
            except Exception as ex:
                logger.critical(
                    f"Found new header: {key}. This shouldn't be the case. Error was {ex}"
                )
        elif key in dateObj:  # if key is in date object category that means we need to convert value in datetime object
            processed = returnDate(value)
            sanitized_data[key] = processed
        else:
            if key not in skipped_headers:  # if key in skipped headers, that means current we want to avoid those keys.
                sanitized_data[key] = value
            else:
                logger.debug(f"{key} skipped.")
    return sanitized_data
示例#19
0
文件: Antrag.py 项目: Athos1972/PoLZy
    def loadActivitiesFromDict(self, activities: dict):
        """
        This method is used in persistence function. It takes a dictionary as input which contains classname as key &
        its attributes as value. Classname is used to create/get class instance and then value is supplied to that
        class instance in order to load its attributes.

        This method can be overwritten in any subclass if you want to execute several tasks after all fields and
        all activties have been loaded
        :param activities: Dict of Activities loaded from DB-Field of the antrag-Instance as JSON.
        :return:
        """
        for classname, value in activities.items():
            instance = self.get_activity(classname, optional=True)
            if instance:
                # if instance of same activity is already their than update it
                #instance = instance[0]
                logger.debug(
                    f"Found existing instance of {classname}. Using it to update persistence values."
                )
                instance.loadFromJsonFromPersistence(value)
            else:  # if no existing instance of activity found than create a new and add to list
                logger.debug(
                    f"No instance found of {classname}. Creating New.")
                class_ = "fasifu.Activities." + classname  # used to dynamically import module
                if classname == "AntragClone":  # AntragClone class's module name is not same. Hence updating it
                    class_ += "Copy"
                mod = __import__(
                    class_,
                    fromlist=[''])  # Importing class object from module
                instance = getattr(mod, classname)(
                    self)  # creating Activity instance
                instance.loadFromJsonFromPersistence(value)
                self.Activities.append(instance)
            logger.debug(f"{classname} loading successful.")
示例#20
0
文件: Antrag.py 项目: Athos1972/PoLZy
    def parseToFrontend(self):
        """
        Creates the JSON that is sent as payload to the frontend
        :return: the JSON
        """

        try:
            lActivitiesJson = [a.toJSON() for a in self.Activities]
            logger.debug(f"lActivitiesJSON hat den Wert: {lActivitiesJson}")
        except Exception as e:
            lActivitiesJson = {}
            logger.critical(f"Fehler bei Aktiviäten JSONisierung: {e}")

        frontendDict = {
            'id': self.uuid,
            'tag': self.tag,
            "number": self.antragsnummer,
            'status': self.status,
            'product_line': {
                'name': self.lineOfBusiness,
                'attributes': {
                    'Produkt': self.productName
                },
            },
            'possible_activities': lActivitiesJson,
            'fields': self.parseToFrontendFieldsWithoutGroup(),
            'speedometerValue': self.getSpeedometerValue(),
        }

        lFieldGroups = self.parseToFrontendFieldGroups()
        if lFieldGroups:
            frontendDict.update(lFieldGroups)
            frontendDict.update(self.parseToFrontendFieldGroupFields())

        logger.debug(
            f"Antrag for Frontend class {self.__class__.__name__} is:\n {frontendDict}"
        )

        return frontendDict
示例#21
0
文件: Antrag.py 项目: Athos1972/PoLZy
    def setFieldInvisible(self, fieldName, optional=False):
        """

        :param fieldName:
        :param optional: Don't write log, if field doesn't exist in the field catalog
        :return:
        """
        try:
            lField = self.Fields.getField(name=fieldName)
            lField.fieldVisibilityType = FieldVisibilityTypes.hidden
            if lField.value and lField.fieldDataType == FieldDataType(
                    InputFieldTypes.TYPEBOOLEAN):
                lField.value = False
        except Exception:
            if optional:
                logger.debug(
                    f"Field {fieldName} should be set invisible. Doesn't exist. "
                    f"'Optional' is set, so most likely Ok")
            else:
                logger.exception(
                    f"Field {fieldName} should be set invisible. Doesn't exist. Most probaly typo!"
                )
示例#22
0
    def toJSON(self):
        """
        Translates the fields and fieldgroups of this activity to JSON for the frontend.
        :return:
        """
        frontendDict = {
            'name': self.name,
            'description': self.description,
            'icon': self.icon,
            'postExecution': self.postExecuteBehavior,
            'fields': self.parseToFrontendFieldsWithoutGroup(),
            'actions': self.frontendActions,
        }

        lFieldGroups = self.parseToFrontendFieldGroups()
        if lFieldGroups:
            frontendDict.update(lFieldGroups)
            frontendDict.update(self.parseToFrontendFieldGroupFields())

        logger.debug(
            f"Activity dict for class {self.__class__.__name__} is \n {frontendDict}"
        )
        return frontendDict
示例#23
0
    def __checkAndReadConfigurations(self, configurationEnvironmentKey: str) -> bool:
        """
        See, if we had loaded this configuration already. If it was not loaded before, don't retry. Otherwise try to
        read it.

        :param configurationEnvironmentKey:
        :return: True if configuration was found or existed already. False if not found.
        """
        if configurationEnvironmentKey in self.configsRead.keys():
            return True

        if configurationEnvironmentKey in self.badConfigs.keys():
            logger.debug(f"Configuration {configurationEnvironmentKey} was already not found before. Not retrying.")
            return False

        configReadResult = ConfigurationProvider.__readConfigurationFromFile(
            self.pathToConfig.joinpath(f"{configurationEnvironmentKey}.json"))

        if configReadResult:
            self.configsRead[configurationEnvironmentKey] = configReadResult
            return True
        else:
            self.badConfigs[configurationEnvironmentKey] = True
            return False
示例#24
0
    def _updateFieldValue(self, name, value, optional=None):
        """

        :param name: fieldname of the activtiy
        :param value: current field value
        :param optional: True if the field might not exist (and not log message is requested in case it can't be found)
        :return:
        """

        # set parent flag
        if hasattr(self, 'polizze'):
            parent_flag = self.PARENT_POLICY
        elif hasattr(self, 'antrag'):
            parent_flag = self.PARENT_ANTRAG
        else:
            logger.debug(
                f"Activity {self.name} is not assigned to any policy or antrag instance"
            )
            return

        lUpdatedField = self.activityFields.getField(name=name)
        if not lUpdatedField:
            # policy cse
            if parent_flag == self.PARENT_POLICY:
                logger.debug(
                    f"Field provided {name} with value {value}. But not in policy activity"
                )

            # antrag case
            # Maybe field from Antrag, not from activity:
            lUpdatedField = self.antrag.Fields.getField(name=name)
            if not lUpdatedField:
                if not optional:
                    logger.error(
                        f"Field provided {name} with value {value}. But not in activity nor in Antrag"
                    )
                else:
                    logger.debug(
                        f"Field provided {name} with value {value}. But not in activity nor in Antrag. "
                        f"'Optional' is set, so no problem.")
                return

        lUpdatedField.value = value
        try:
            if parent_flag == self.PARENT_ANTRAG:
                self.antrag._updateTechnicalFieldValuesAfterChange(
                    lUpdatedField)
        except Exception as e:
            logger.exception(
                f"Error in _updateTechnicalFieldValuesAfterChange (or Methode doesn't exist). "
                f"Class was {self.__class__.__name__}. Error: {e}. Field: {name}, "
                f"Value: {value}")
示例#25
0
 def get_data(self):
     logger.debug(f"Getting data.")
     try:
         return getattr(self, self.extension[1:])(self.fileNameAndPath)  # function names and extension name are same
     except AttributeError:
         raise Exception(f"{self.extension} files are not supported yet")
示例#26
0
文件: Antrag.py 项目: Athos1972/PoLZy
 def setCustomTag(self, tag):
     logger.debug(f"Tag is set to {tag}")
     self.tag = tag
示例#27
0
    def sanitize_filename(self, fileNameAndPath):
        if not os.path.isfile(fileNameAndPath):
            logger.critical(f"{fileNameAndPath} doesn't exist. Skipping it!")
            raise Exception(f"{fileNameAndPath} doesn't exist")
        return fileNameAndPath, os.path.splitext(fileNameAndPath)[1].lower()

    def process_data(self):
        logger.debug("Processing data")
        self.processor = Process(self, self.classes)
        self.processor.process()
        DatabaseManager.set_processed(self.fileName, self.unprocessed_db_obj,
                                      self.details)
        logger.debug("Data processed")


if __name__ == "__main__":
    lDatabaseManager = DatabaseManager()
    if not lDatabaseManager.unprocessed_rows:
        logger.debug("No file to be processed!")
    for unprocessed in lDatabaseManager.unprocessed_rows:
        logger.debug(
            f"{unprocessed.filename} file with id {unprocessed.id} is ready to be processed"
        )
        filename = os.path.join(GlobalConstants.filesPath,
                                unprocessed.get_current_filename())
        m = Manager(filename, unprocessed.filename, unprocessed, [])

# command to execute this file as main
# python -m FileManager.Manager
示例#28
0
 def __init__(self, default="en"):
     logger.debug("Language translation backend module initialized - buffered")
     self.default_language = default.lower()
     self.data = Data().data  # getting data from singleton class's attribute
示例#29
0
    def _saveXMLorJSONResultAsPrettyPrinted(self,
                                            resultToPrint,
                                            operation: str = None):
        """
        Used for debugging when we want to save requests/responses from XML or JSON to files.
        :param resultToPrint:
        :param operation:
        :return:
        """
        if not LogLevelUpdater().saveJson:
            return

        if not operation:
            operation = self.__class__.__name__

        try:
            lFileNameResult = f"{self.configurationProvider.basePath}/JsonFilesDelete/{self.polizze.polizzenNummer}_" \
                              f"{operation}_" \
                              f"{datetime.now().strftime(GlobalConstants.dateFormatLong)}_reply.json"
        except Exception:
            if hasattr(self, "antrag"):
                lFileNameResult = f"{self.configurationProvider.basePath}/JsonFilesDelete/" \
                                  f"Antrag_{self.antrag.sapClient}_" \
                                  f"{self.antrag.productName.replace('/', '_')}_" \
                                  f"{operation}_{datetime.now().strftime(GlobalConstants.dateFormatLong)}_reply.json"
            else:
                lFileNameResult = f"{self.configurationProvider.basePath}/JsonFilesDelete/" \
                                  f"UnknownRootObject_" \
                                  f"{operation}_{datetime.now().strftime(GlobalConstants.dateFormatLong)}_reply.json"

        if isinstance(resultToPrint, dict):
            try:
                with open(lFileNameResult, "w") as resultFile:
                    json.dump(resultToPrint, fp=resultFile, indent=4)
                logger.debug(f"File written: {lFileNameResult}")
                return
            except Exception as e:
                logger.critical(f"Fehler beim JSON-Dump {e}")
                return

        if not resultToPrint:
            logger.info(
                "Should have printed result of call, but there was nothing in it."
            )
            return

        try:
            lDOMString = xml.dom.minidom.parseString(resultToPrint)
            with open(lFileNameResult, "w") as resultFile:
                resultFile.write(lDOMString.toprettyxml())
            logger.debug(f"File written: {lFileNameResult}")
            return
        except Exception as e:
            logger.debug(
                f"Error during XML-Dump: {e}, will fallback to text dump.")

        # If we can't write it as XML nor JSON, maybe we can save a text at least:
        try:
            with open(lFileNameResult, "w") as resultFile:
                resultFile.write(str(resultToPrint))
            logger.debug(f"File written {lFileNameResult}")
        except Exception as e:
            logger.critical(
                f"Error {e} during writing of interface file. Filename was {lFileNameResult}. "
                f"resultToPrint was {resultToPrint}. Error as ")
示例#30
0
 def __init__(self):
     logger.debug(
         "Language translation backend module initialized - buffered")
     self.data = self.get_data(
         os.path.join(os.path.dirname(os.path.abspath(__file__)),
                      "language_data.json"))