Class AppointmentImportHome
java.lang.Object
fr.paris.lutece.plugins.appointment.modules.importer.business.AppointmentImportHome
Home for uploaded import files, slot batches and source rows.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidarchiveFile(int nFileId) Archives a file and removes its validation report.static booleanbatchHasErrors(int nBatchId) Tells whether a row of the batch failed.static booleanclaimPendingBatch(int nId, String strToken) Takes a pending batch for processing.static booleanclaimStaleBatch(int nId, LocalDateTime dtLastExecBefore, String strToken) Takes over a batch whose processing stopped: it is stillPROCESSINGbut was not touched since the given date.static voidCompletes a batch, and its file, completed with errors that have no row in error any more.static intcountAppointmentsByBatch(int nBatchId) Counts the rows of a batch.static intcountProcessedAppointmentsByBatch(int nBatchId) Counts the rows of a batch that are created or in error.static voidcreateAppointments(List<AppointmentImportAppointment> listAppointments) Creates the rows of an import.static intCreates a batch.static intCreates an import file.static voidcreateFingerprints(List<AppointmentImportFingerprint> listFingerprints) Inserts fingerprints.static booleanexistsDuplicateFile(String strHash, int nFormId) Tells whether the same content was already accepted for the form.static booleanfileAllBatchesArchived(int nFileId) Tells whether every batch of the file is archived.static booleanfileHasErrors(int nFileId) Tells whether a row of the file failed.static voidfillBatchCounts(List<AppointmentImportBatch> listBatches) Fills the number of rows by outcome of each batch.static voidfillCounts(List<AppointmentImportFile> listFiles) Fills the number of rows by outcome of each file.static AppointmentImportAppointmentfindAppointment(int nId) Finds a row.findAppointmentIdsByFile(int nFileId) Gives the ids of the rows of a file, by line.static List<AppointmentImportAppointment>findAppointmentsByBatch(int nBatchId, String strStatus) Finds the rows of a batch, by source line.static AppointmentImportBatchfindBatch(int nId) Finds a batch.static List<AppointmentImportBatch>findBatchesByFile(int nFileId) Finds the batches of a file, by starting date.static List<AppointmentImportBatch>findBatchesByIds(List<Integer> listIds) Finds the batches with the given ids, in the order of the list.static List<AppointmentImportBatch>findBatchesByStatus(String strStatus) Finds the batches with the given status, oldest first.findBatchIds(List<Integer> listFormIds, String strFormId, String strStatus, String strFileName, String strDate) Finds the ids of the batches matching the filters, newest first.findBatchIdsToPurge(LocalDateTime dtBefore) Finds the completed batches last updated before the given date.static AppointmentImportFilefindFile(int nId) Finds an import file.findFileIds(List<Integer> listFormIds, String strFormId, String strFileName, String strStatus, String strDate) Finds the ids of the files matching the filters, newest first.Finds the files still pending whose batches are all done.findFileNames(List<Integer> listFormIds) Finds the distinct names of the files imported on the given forms.static List<AppointmentImportFile>findFilesByIds(List<Integer> listIds) Finds the files with the given ids, in the order of the list.static List<AppointmentImportFingerprint>findFingerprints(int nFormId, Collection<String> collectionFingerprints) Finds the lines already imported on a form among the given fingerprints.findRejectedFileIdsToPurge(LocalDateTime dtBefore) Finds the files rejected at validation before the given date.static voidmarkAppointmentCreated(int nId, int nAppointmentId) Marks a row as created.static voidmarkAppointmentError(int nId, String strCode, String strMessage) Marks a row as failed.static voidmarkAppointmentProcessing(int nId) Marks a row as being processed, before the appointment is saved.static booleanpurgeBatch(int nBatchId) Deletes the rows of a completed batch and archives it, in one transaction.static booleanreassignFingerprint(AppointmentImportFingerprint fingerprint, int nFromAppointmentId) Gives a fingerprint to a new row, if it still belongs to the given row.static voidremoveFingerprintByAppointment(int nAppointmentId) Deletes the fingerprint of a row.static voidremoveFingerprintsBefore(LocalDate dateBefore) Deletes the fingerprints of the appointments before a date: a line in the past is refused anyway.static booleanreplaceAppointment(int nId, String strExcludedErrorCode, String strMessage) Marks a row in error as replaced by a row of another file, unless it was interrupted while its appointment was being saved.static booleanrequeueBatch(int nBatchId) Puts a completed or pending batch back in the queue of the daemon; a batch being processed or archived is left as it is.static voidrequeueErrorRows(int nBatchId, String strExcludedErrorCode) Puts the rows in error of a batch back to pending, except those with the given error code.static voidrequeueRow(int nId) Puts a row in error back to pending.static voidtouchBatch(int nId) Records that a batch is still being processed.static voidupdateAppointmentData(int nId, String strGenericAttributesData, String strFormFieldsData) Replaces the values of a row.static voidupdateBatchStatus(int nId, String strStatus) Updates the status of a batch and releases it.static voidupdateFileStatus(int nId, String strStatus) Updates the status of a file.
-
Field Details
-
PLUGIN_NAME
Name of the module plugin- See Also:
-
-
Method Details
-
createFile
Creates an import file.- Parameters:
file- the file- Returns:
- the generated id
-
findFile
Finds an import file.- Parameters:
nId- theid_import_file- Returns:
- the file, or null
-
findFileIds
public static List<Integer> findFileIds(List<Integer> listFormIds, String strFormId, String strFileName, String strStatus, String strDate) Finds the ids of the files matching the filters, newest first.- Parameters:
listFormIds- the forms the files must belong tostrFormId- optional form idstrFileName- optional file namestrStatus- optional statusstrDate- optional date (yyyy-MM-dd) of a slot of the file- Returns:
- the ids
-
findFilesByIds
Finds the files with the given ids, in the order of the list.- Parameters:
listIds- the ids- Returns:
- the files
-
findFileNames
Finds the distinct names of the files imported on the given forms.- Parameters:
listFormIds- the forms- Returns:
- the names
-
existsDuplicateFile
Tells whether the same content was already accepted for the form.- Parameters:
strHash- the SHA-256 of the contentnFormId- the form- Returns:
- true if a duplicate exists
-
updateFileStatus
Updates the status of a file.- Parameters:
nId- theid_import_filestrStatus- the status
-
findFileIdsToClose
Finds the files still pending whose batches are all done.- Returns:
- the ids
-
fillCounts
Fills the number of rows by outcome of each file.- Parameters:
listFiles- the files
-
fileHasErrors
public static boolean fileHasErrors(int nFileId) Tells whether a row of the file failed.- Parameters:
nFileId- theid_import_file- Returns:
- true if at least one row failed
-
fileAllBatchesArchived
public static boolean fileAllBatchesArchived(int nFileId) Tells whether every batch of the file is archived.- Parameters:
nFileId- theid_import_file- Returns:
- true if no batch is left to archive
-
archiveFile
public static void archiveFile(int nFileId) Archives a file and removes its validation report.- Parameters:
nFileId- theid_import_file
-
findRejectedFileIdsToPurge
Finds the files rejected at validation before the given date.- Parameters:
dtBefore- the threshold- Returns:
- the ids
-
createBatch
Creates a batch.- Parameters:
batch- the batch- Returns:
- the generated id
-
findBatch
Finds a batch.- Parameters:
nId- theid_import_batch- Returns:
- the batch, or null
-
findBatchesByFile
Finds the batches of a file, by starting date.- Parameters:
nFileId- theid_import_file- Returns:
- the batches
-
findBatchesByStatus
Finds the batches with the given status, oldest first.- Parameters:
strStatus- the status- Returns:
- the batches
-
findBatchIds
public static List<Integer> findBatchIds(List<Integer> listFormIds, String strFormId, String strStatus, String strFileName, String strDate) Finds the ids of the batches matching the filters, newest first.- Parameters:
listFormIds- the forms the batches must belong tostrFormId- optional form idstrStatus- optional statusstrFileName- optional file namestrDate- optional starting date (yyyy-MM-dd)- Returns:
- the ids
-
findBatchesByIds
Finds the batches with the given ids, in the order of the list.- Parameters:
listIds- the ids- Returns:
- the batches
-
claimPendingBatch
Takes a pending batch for processing.- Parameters:
nId- theid_import_batchstrToken- the token identifying the caller- Returns:
- true if the caller now owns the batch
-
claimStaleBatch
Takes over a batch whose processing stopped: it is stillPROCESSINGbut was not touched since the given date.- Parameters:
nId- theid_import_batchdtLastExecBefore- the date before which the batch is considered abandonedstrToken- the token identifying the caller- Returns:
- true if the caller now owns the batch
-
touchBatch
public static void touchBatch(int nId) Records that a batch is still being processed.- Parameters:
nId- theid_import_batch
-
updateBatchStatus
Updates the status of a batch and releases it.- Parameters:
nId- theid_import_batchstrStatus- the status
-
requeueBatch
public static boolean requeueBatch(int nBatchId) Puts a completed or pending batch back in the queue of the daemon; a batch being processed or archived is left as it is.- Parameters:
nBatchId- theid_import_batch- Returns:
- true if the batch is now pending, false if it is being processed or archived
-
fillBatchCounts
Fills the number of rows by outcome of each batch.- Parameters:
listBatches- the batches
-
batchHasErrors
public static boolean batchHasErrors(int nBatchId) Tells whether a row of the batch failed.- Parameters:
nBatchId- theid_import_batch- Returns:
- true if at least one row failed
-
findBatchIdsToPurge
Finds the completed batches last updated before the given date.- Parameters:
dtBefore- the threshold- Returns:
- the ids
-
purgeBatch
public static boolean purgeBatch(int nBatchId) Deletes the rows of a completed batch and archives it, in one transaction. A batch retried meanwhile is left as it is, with its rows.- Parameters:
nBatchId- theid_import_batch- Returns:
- true if the batch was purged, false if it is no longer completed
-
createAppointments
Creates the rows of an import.- Parameters:
listAppointments- the rows
-
findAppointmentsByBatch
public static List<AppointmentImportAppointment> findAppointmentsByBatch(int nBatchId, String strStatus) Finds the rows of a batch, by source line.- Parameters:
nBatchId- theid_import_batchstrStatus- optional status, null for every row- Returns:
- the rows
-
countAppointmentsByBatch
public static int countAppointmentsByBatch(int nBatchId) Counts the rows of a batch.- Parameters:
nBatchId- theid_import_batch- Returns:
- the count
-
countProcessedAppointmentsByBatch
public static int countProcessedAppointmentsByBatch(int nBatchId) Counts the rows of a batch that are created or in error.- Parameters:
nBatchId- theid_import_batch- Returns:
- the count
-
findAppointment
Finds a row.- Parameters:
nId- theid_import_appointment- Returns:
- the row, or null
-
updateAppointmentData
public static void updateAppointmentData(int nId, String strGenericAttributesData, String strFormFieldsData) Replaces the values of a row.- Parameters:
nId- theid_import_appointmentstrGenericAttributesData- the values of the standard columns, as JSONstrFormFieldsData- the values of the form fields, as JSON
-
requeueErrorRows
Puts the rows in error of a batch back to pending, except those with the given error code.- Parameters:
nBatchId- theid_import_batchstrExcludedErrorCode- the error code of the rows to leave in error
-
requeueRow
public static void requeueRow(int nId) Puts a row in error back to pending.- Parameters:
nId- theid_import_appointment
-
markAppointmentProcessing
public static void markAppointmentProcessing(int nId) Marks a row as being processed, before the appointment is saved.- Parameters:
nId- theid_import_appointment
-
markAppointmentCreated
public static void markAppointmentCreated(int nId, int nAppointmentId) Marks a row as created.- Parameters:
nId- theid_import_appointmentnAppointmentId- the created appointment
-
markAppointmentError
Marks a row as failed.- Parameters:
nId- theid_import_appointmentstrCode- the error codestrMessage- the error message
-
findAppointmentIdsByFile
Gives the ids of the rows of a file, by line.- Parameters:
nFileId- theid_import_file- Returns:
- the
id_import_appointmentof each line
-
replaceAppointment
Marks a row in error as replaced by a row of another file, unless it was interrupted while its appointment was being saved.- Parameters:
nId- theid_import_appointmentstrExcludedErrorCode- the error code of the rows that cannot be replacedstrMessage- what replaced the row- Returns:
- true if the row is replaced
-
completeWithoutErrors
Completes a batch, and its file, completed with errors that have no row in error any more.- Parameters:
batch- the batch
-
findFingerprints
public static List<AppointmentImportFingerprint> findFingerprints(int nFormId, Collection<String> collectionFingerprints) Finds the lines already imported on a form among the given fingerprints.- Parameters:
nFormId- the formcollectionFingerprints- the fingerprints- Returns:
- the fingerprints found, with the file and the row that imported them
-
createFingerprints
Inserts fingerprints. One already there for its form fails: the line was imported meanwhile.- Parameters:
listFingerprints- the fingerprints
-
reassignFingerprint
public static boolean reassignFingerprint(AppointmentImportFingerprint fingerprint, int nFromAppointmentId) Gives a fingerprint to a new row, if it still belongs to the given row.- Parameters:
fingerprint- the fingerprint with its new rownFromAppointmentId- theid_import_appointmentof the row it belongs to- Returns:
- true if the fingerprint belongs to the new row
-
removeFingerprintByAppointment
public static void removeFingerprintByAppointment(int nAppointmentId) Deletes the fingerprint of a row.- Parameters:
nAppointmentId- theid_import_appointment
-
removeFingerprintsBefore
Deletes the fingerprints of the appointments before a date: a line in the past is refused anyway.- Parameters:
dateBefore- the first date kept
-