source: main/waeup.kofa/trunk/docs/source/userdocs/datacenter/import.rst @ 12869

Last change on this file since 12869 was 12869, checked in by Henrik Bettermann, 9 years ago

Start documenting batch processors.

File size: 7.1 KB
Line 
1.. _import:
2
3Data Import
4***********
5
6Stages of Batch Processing
7==========================
8
9The term 'data import' actually understates the range of functions importers really have. As already stated, many importers do not only restore data once backed up by exporters or, in other words, take values from CSV files and write them one-on-one into the database. The data undergo a complex staged data processing algorithm. Therefore, we prefer calling them 'batch processors' instead of importers. The stages of the import process are as follows.
10
11Stage 1: File Upload
12--------------------
13
14Users with permission
15:py:class:`waeup.manageDataCenter<waeup.kofa.permissions.ManageDataCenter>`
16are allowed to access the data center and also to use the upload page. On this page they can see a long table of available batch processors. The table lists required, optional and non-schema fields (see below) for each processor. It also provides a CSV file template which can be filled and uploaded to avoid header errors.
17
18Data center managers can upload any kind of CSV file from their local computer. The uploader does not check the integrity of the content but the validity of its CSV encoding (see :py:func:`check_csv_charset<waeup.kofa.utils.helpers.check_csv_charset>`). It also checks the filename extension and allows only a limited number of files in the data center.
19
20.. autoattribute:: waeup.kofa.browser.pages.DatacenterUploadPage.max_files
21
22If the upload succeeded the uploader sends an email to all import managers (users with role :py:class:`waeup.ImportManager<waeup.kofa.permissions.ImportManager>`) of the portal that a new file was uploaded.
23
24The uploader changes the filename. An uploaded file ``foo.csv`` will be stored as ``foo_USERNAME.csv`` where username is the user id of the currently logged in user. Spaces in filename are replaced by underscores. Pending data filenames remain unchanged (see below).
25
26After file upload the data center manager can click the 'Process data' button to open the page where files can be selected for import (**import step 1**). After selecting a file the data center manager can preview the header and the first three records of the uploaded file (**import step 2**). If the preview fails or the header contains duplicate column titles, an error message is raised. The user cannot proceed but is requested to replace the uploaded file. If the preview succeeds the user is able to proceed to the next step (**import step 3**) by selecting the appropriate processor and an import mode. In import mode ``create`` new objects are added to the database, `in `update`` mode existing objects are modified and in ``remove`` mode deleted.
27
28Stage 2: File Header Validation
29-------------------------------
30
31Import step 3 is the stage where the file content is assessed for the first time and checked if the column titles correspond with the fields of the processor chosen. The page shows the header and the first record of the uploaded file. The page allows to change column titles or to ignore entire columns during import. It might have happened that one or more column titles are misspelled or that the person, who created the file, ignored the case-sensitivity of field names. Then the data import manager can easily fix this by selecting the correct title and click the 'Set headerfields' button. Setting the column titles is temporary, it does not modify the uploaded file. Consequently, it does not make sense to set new column titles if the file is not imported afterwards.
32
33The page also calls the `checkHeaders` method of the batch processor which checks for required fields. If a required column title is missing, a warning message is raised and the user can't proceed to the next step (**import step 4**).
34
35Stage 3: Data Validation and Import
36-----------------------------------
37
38Import step 4 is the actual data import. The import is started by clicking the 'Perform import' button.
39
40Kofa does not validate the data in advance. It tries to import the data row-by-row while reading the CSV file. The reason is that import files very often  contain thousands or even tenthousands of records. It is not feasable for data managers to edit import files until they are error-free. Very often such an error is not really a mistake made by the person who compiled the file. Example: The import file contains course results although the student has not yet registered the courses. Then the import of this single record has to wait, i.e. it has to be marked pending, until the student has added the course ticket. Only then it can be edited by the batch processor.
41
42The core import method is:
43
44.. automethod:: waeup.kofa.utils.batching.BatchProcessor.doImport()
45   :noindex:
46
47Stage 4: Post-Processing
48------------------------
49
50The data import is finalized by calling :py:meth:`distProcessedFiles<waeup.kofa.datacenter.DataCenter.distProcessedFiles>`. This method moves the ``.pending`` and ``.finished`` files from their temporary to their final location in the storage path of the filesystem from where they can be accessed through browser user interface.
51
52Batch Processors
53================
54
55All batch processors inherit from the :py:class:`waeup.kofa.utils.batching.BatchProcessor` base class. The `doImport` method, described above, always remains unchanged. All processors have a property `available_fields` which defines the set of importable data. They correspond with the column titles of the import file. Available fields are usually composed of location fields, interface fields and additional fields. Overlaps are possible. Location fields define the minumum set of fields which are necessary to locate an existing object in order to update or remove it. Interface fields (schema fields) are the fields defined in the interface of the data entity. Additional fields are additionally needed for data processing. We further distinguish between required and optional fields or between schema and non-schema fields.
56
57In the following we list all available processors of the Kofa base package including some important methods which describe them best. We do not list available fields of each processor here. Available fields are shown in the browser user interface on the upload page of the portal.
58
59User Processor
60--------------
61
62.. autoclass:: waeup.kofa.authentication.UserProcessor()
63  :noindex:
64
65Faculty Processor
66-----------------
67
68.. autoclass:: waeup.kofa.university.batching.FacultyProcessor()
69  :noindex:
70
71Department Processor
72--------------------
73
74.. autoclass:: waeup.kofa.university.batching.DepartmentProcessor()
75  :noindex:
76
77Certificate Processor
78---------------------
79
80.. autoclass:: waeup.kofa.university.batching.CertificateProcessor()
81  :noindex:
82
83Course Processor
84----------------
85
86.. autoclass:: waeup.kofa.university.batching.CourseProcessor()
87  :noindex:
88
89
90Certificate Course Processor
91----------------------------
92
93.. autoclass:: waeup.kofa.university.batching.CertificateCourseProcessor()
94  :noindex:
95
96Applicants Container Processor
97------------------------------
98
99.. autoclass:: waeup.kofa.applicants.batching.ApplicantsContainerProcessor()
100  :noindex:
101
102Applicant Processor
103-------------------
104
105.. autoclass:: waeup.kofa.applicants.batching.ApplicantProcessor()
106  :noindex:
Note: See TracBrowser for help on using the repository browser.