java.lang.Object
fr.paris.lutece.plugins.appointment.modules.importer.business.AppointmentImportHome

public final class AppointmentImportHome extends Object
Home for uploaded import files, slot batches and source rows.
  • Field Details

  • Method Details

    • createFile

      public static int createFile(AppointmentImportFile file)
      Creates an import file.
      Parameters:
      file - the file
      Returns:
      the generated id
    • findFile

      public static AppointmentImportFile findFile(int nId)
      Finds an import file.
      Parameters:
      nId - the id_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 to
      strFormId - optional form id
      strFileName - optional file name
      strStatus - optional status
      strDate - optional date (yyyy-MM-dd) of a slot of the file
      Returns:
      the ids
    • findFilesByIds

      public static List<AppointmentImportFile> findFilesByIds(List<Integer> listIds)
      Finds the files with the given ids, in the order of the list.
      Parameters:
      listIds - the ids
      Returns:
      the files
    • findFileNames

      public static List<String> findFileNames(List<Integer> listFormIds)
      Finds the distinct names of the files imported on the given forms.
      Parameters:
      listFormIds - the forms
      Returns:
      the names
    • existsDuplicateFile

      public static boolean existsDuplicateFile(String strHash, int nFormId)
      Tells whether the same content was already accepted for the form.
      Parameters:
      strHash - the SHA-256 of the content
      nFormId - the form
      Returns:
      true if a duplicate exists
    • updateFileStatus

      public static void updateFileStatus(int nId, String strStatus)
      Updates the status of a file.
      Parameters:
      nId - the id_import_file
      strStatus - the status
    • findFileIdsToClose

      public static List<Integer> findFileIdsToClose()
      Finds the files still pending whose batches are all done.
      Returns:
      the ids
    • fillCounts

      public static void fillCounts(List<AppointmentImportFile> listFiles)
      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 - the id_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 - the id_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 - the id_import_file
    • findRejectedFileIdsToPurge

      public static List<Integer> findRejectedFileIdsToPurge(LocalDateTime dtBefore)
      Finds the files rejected at validation before the given date.
      Parameters:
      dtBefore - the threshold
      Returns:
      the ids
    • createBatch

      public static int createBatch(AppointmentImportBatch batch)
      Creates a batch.
      Parameters:
      batch - the batch
      Returns:
      the generated id
    • findBatch

      public static AppointmentImportBatch findBatch(int nId)
      Finds a batch.
      Parameters:
      nId - the id_import_batch
      Returns:
      the batch, or null
    • findBatchesByFile

      public static List<AppointmentImportBatch> findBatchesByFile(int nFileId)
      Finds the batches of a file, by starting date.
      Parameters:
      nFileId - the id_import_file
      Returns:
      the batches
    • findBatchesByStatus

      public static List<AppointmentImportBatch> findBatchesByStatus(String strStatus)
      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 to
      strFormId - optional form id
      strStatus - optional status
      strFileName - optional file name
      strDate - optional starting date (yyyy-MM-dd)
      Returns:
      the ids
    • findBatchesByIds

      public static List<AppointmentImportBatch> findBatchesByIds(List<Integer> listIds)
      Finds the batches with the given ids, in the order of the list.
      Parameters:
      listIds - the ids
      Returns:
      the batches
    • claimPendingBatch

      public static boolean claimPendingBatch(int nId, String strToken)
      Takes a pending batch for processing.
      Parameters:
      nId - the id_import_batch
      strToken - the token identifying the caller
      Returns:
      true if the caller now owns the batch
    • claimStaleBatch

      public static boolean claimStaleBatch(int nId, LocalDateTime dtLastExecBefore, String strToken)
      Takes over a batch whose processing stopped: it is still PROCESSING but was not touched since the given date.
      Parameters:
      nId - the id_import_batch
      dtLastExecBefore - the date before which the batch is considered abandoned
      strToken - 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 - the id_import_batch
    • updateBatchStatus

      public static void updateBatchStatus(int nId, String strStatus)
      Updates the status of a batch and releases it.
      Parameters:
      nId - the id_import_batch
      strStatus - 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 - the id_import_batch
      Returns:
      true if the batch is now pending, false if it is being processed or archived
    • fillBatchCounts

      public static void fillBatchCounts(List<AppointmentImportBatch> listBatches)
      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 - the id_import_batch
      Returns:
      true if at least one row failed
    • findBatchIdsToPurge

      public static List<Integer> findBatchIdsToPurge(LocalDateTime dtBefore)
      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 - the id_import_batch
      Returns:
      true if the batch was purged, false if it is no longer completed
    • createAppointments

      public static void createAppointments(List<AppointmentImportAppointment> listAppointments)
      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 - the id_import_batch
      strStatus - optional status, null for every row
      Returns:
      the rows
    • countAppointmentsByBatch

      public static int countAppointmentsByBatch(int nBatchId)
      Counts the rows of a batch.
      Parameters:
      nBatchId - the id_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 - the id_import_batch
      Returns:
      the count
    • findAppointment

      public static AppointmentImportAppointment findAppointment(int nId)
      Finds a row.
      Parameters:
      nId - the id_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 - the id_import_appointment
      strGenericAttributesData - the values of the standard columns, as JSON
      strFormFieldsData - the values of the form fields, as JSON
    • requeueErrorRows

      public static void requeueErrorRows(int nBatchId, String strExcludedErrorCode)
      Puts the rows in error of a batch back to pending, except those with the given error code.
      Parameters:
      nBatchId - the id_import_batch
      strExcludedErrorCode - 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 - the id_import_appointment
    • markAppointmentProcessing

      public static void markAppointmentProcessing(int nId)
      Marks a row as being processed, before the appointment is saved.
      Parameters:
      nId - the id_import_appointment
    • markAppointmentCreated

      public static void markAppointmentCreated(int nId, int nAppointmentId)
      Marks a row as created.
      Parameters:
      nId - the id_import_appointment
      nAppointmentId - the created appointment
    • markAppointmentError

      public static void markAppointmentError(int nId, String strCode, String strMessage)
      Marks a row as failed.
      Parameters:
      nId - the id_import_appointment
      strCode - the error code
      strMessage - the error message
    • findAppointmentIdsByFile

      public static Map<Integer,Integer> findAppointmentIdsByFile(int nFileId)
      Gives the ids of the rows of a file, by line.
      Parameters:
      nFileId - the id_import_file
      Returns:
      the id_import_appointment of each line
    • replaceAppointment

      public static boolean replaceAppointment(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.
      Parameters:
      nId - the id_import_appointment
      strExcludedErrorCode - the error code of the rows that cannot be replaced
      strMessage - what replaced the row
      Returns:
      true if the row is replaced
    • completeWithoutErrors

      public static void completeWithoutErrors(AppointmentImportBatch batch)
      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 form
      collectionFingerprints - the fingerprints
      Returns:
      the fingerprints found, with the file and the row that imported them
    • createFingerprints

      public static void createFingerprints(List<AppointmentImportFingerprint> listFingerprints)
      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 row
      nFromAppointmentId - the id_import_appointment of 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 - the id_import_appointment
    • removeFingerprintsBefore

      public static void removeFingerprintsBefore(LocalDate dateBefore)
      Deletes the fingerprints of the appointments before a date: a line in the past is refused anyway.
      Parameters:
      dateBefore - the first date kept