Exemple #1
0
    def create_xml(self, queryset=None):
        if queryset is None:
            queryset = self.get_queryset()

        pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(jhs.Namespace, self.NAMESPACE)

        tos_info = jhs.TosTiedot(
            id=uuid.uuid4(),
            Nimeke=jhs.Nimeke(jhs.NimekeKielella('TOS dokumentti', kieliKoodi='fi')),
            YhteyshenkiloNimi='John Doe',  # TODO
            TosVersio=self.TOS_VERSION
        )

        functions = []
        for function in queryset:
            self.msg('processing function %s' % function)
            phases = []
            handling = None
            func = None
            try:
                for phase in function.phases.all():
                    actions = []
                    for action in phase.actions.all():
                        records = []
                        for record in action.records.all():
                            handling = record
                            records.append(self._handle_record(record))
                        handling = action
                        actions.append(self._handle_action(action, records))
                    handling = phase
                    phases.append(self._handle_phase(phase, actions))
                handling = function
                func = self._handle_function(function, phases)
            except Exception as e:
                error = '%s: %s' % (e.__class__.__name__, e)
                if handling:
                    self.msg('ERROR %s while processing %s' % (error, handling))
                else:
                    self.msg('ERROR %s' % error)
            if func:
                try:
                    func.toDOM()  # validates
                    functions.append(func)
                except pyxb.PyXBException as e:
                    self.msg('ERROR validating the function, details:\n%s' % e.details())

        self.msg('creating the actual XML...')

        tos_root = jhs.Tos(
            TosTiedot=tos_info,
            Luokka=functions,
        )

        try:
            dom = tos_root.toDOM()
        except pyxb.PyXBException as e:
            self.msg('ERROR while creating the XML file: %s' % e.details())
            raise JHSExporterException(e.details())

        return dom.toprettyxml(' ', encoding='utf-8')
Exemple #2
0
    def _handle_classification(self, classification):
        try:
            function = Function.objects.prefetch_related(
                'phases', 'phases__actions',
                'phases__actions__records').filter(
                    classification__uuid=classification.uuid).latest_approved(
                    ).get()

        except Function.DoesNotExist:
            return jhs.Luokka(
                id=classification.uuid,
                Luokitustunnus=classification.code,
                Nimeke=jhs.Nimeke(
                    jhs.NimekeKielella(classification.title, kieliKoodi='fi')),
            )

        logger.info('Processing function %s' % function)

        phases = []
        handling = None
        try:
            for phase in function.phases.all():
                actions = []
                for action in phase.actions.all():
                    records = []
                    for record in action.records.all():
                        handling = record
                        records.append(self._handle_record(record))
                    handling = action
                    actions.append(self._handle_action(action, records))
                handling = phase
                phases.append(self._handle_phase(phase, actions))
            handling = function
            func = self._handle_function(function, phases)
        except Exception as e:
            error = '%s: %s' % (e.__class__.__name__, e)
            if handling:
                logger.error('ERROR %s while processing %s' %
                             (error, handling))
                return False
            else:
                logger.error(error)
                return False
        if func:
            try:
                func.toDOM()  # validates
            except pyxb.PyXBException as e:
                logger.error('ERROR validating the function, details:\n%s' %
                             e.details())
                return False

        return func
Exemple #3
0
 def _handle_function(self, function, phases):
     information_system = self._get_attribute_value(function, 'InformationSystem')
     handling_process_info = jhs.KasittelyprosessiTiedot(
         id=uuid.uuid4(),
         Kayttorajoitustiedot=self._create_restriction_info(function),
         Sailytysaikatiedot=self._create_retention_info(function),
         TietojarjestelmaNimi=jhs.TietojarjestelmaNimi(information_system) if information_system else None,
         Toimenpidetiedot=phases
     )
     return jhs.Luokka(
         id=function.uuid,
         Luokitustunnus=function.get_classification_code(),
         Nimeke=jhs.Nimeke(jhs.NimekeKielella(function.get_name(), kieliKoodi='fi')),
         KasittelyprosessiTiedot=handling_process_info
     )
Exemple #4
0
    def create_xml(self, queryset=None):
        if queryset is None:
            queryset = self.get_queryset()

        pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(
            jhs.Namespace, self.NAMESPACE)

        tos_info = jhs.TosTiedot(
            id=uuid.uuid4(),
            Nimeke=jhs.Nimeke(
                jhs.NimekeKielella(
                    'Helsingin kaupungin Tiedonohjaussuunnitelma',
                    kieliKoodi='fi')),
            OrganisaatioNimi='Helsingin kaupunki',
            YhteyshenkiloNimi='Tiedonhallinta',
            LisatiedotTeksti='JHS 191 XML {:%Y-%m-%d %H:%M%Z} {}'.format(
                datetime.now(tz=pytz.timezone(settings.TIME_ZONE)),
                settings.XML_EXPORT_DESCRIPTION),
            TilaKoodi='3',
            TosVersio=self.TOS_VERSION)

        classifications = []
        for classification in queryset.all():
            item = self._handle_classification(classification)
            if item:
                classifications.append(item)

        classifications.sort(key=lambda a: a.Luokitustunnus)
        logger.info('Creating the actual XML...')

        tos_root = jhs.Tos(
            TosTiedot=tos_info,
            Luokka=classifications,
        )

        try:
            dom = tos_root.toDOM()
        except pyxb.PyXBException as e:
            logger.error('ERROR while creating the XML file: %s' % e.details())
            raise JHSExporterException(e.details())

        return dom.toprettyxml(' ', encoding='utf-8')