Class DeviceImportService

java.lang.Object
org.bgerp.plugin.inventoru.sync1c.service.DeviceImportService

public class DeviceImportService extends Object
Bulk import of individually identified units from a CSV — the counterpart of the stock import, which carries nomenclature and quantities. The serial number is the business key: a row whose serial is already known updates that device, an unknown one creates it. That makes re-importing the same file a no-op rather than a way to duplicate the warehouse. Where a unit stands and under which position is stock accounting when the position is serial tracked, so every row is saved through DeviceAccountingService — a receipt, a transfer, an attachment to a balance that was waiting for its serials, or a refusal. On a store whose serials 1C keeps the file only enriches the units (position, MAC, model, inventory number, status); which unit stands there is said by the 1C stock import.
  • Constructor Details

    • DeviceImportService

      public DeviceImportService(Connection con)
  • Method Details

    • manageable

      public DeviceImportService manageable(Set<Integer> storeIds)
      Limits the import to the stores the caller runs: a row creating a unit elsewhere, or touching a unit standing elsewhere, is an error of the row. Without it the bulk import was a way round every check the card of a single unit makes.
      Parameters:
      storeIds - null — no limit (a warehouse admin).
    • preview

      public List<DeviceImportService.Row> preview(byte[] data, Character delimiter, Charset charset, int itemExtIdParamId) throws IOException, SQLException
      Parses and resolves the file without writing anything — the caller shows the result for review before apply(List, int, int).
      Parameters:
      itemExtIdParamId - how the "item" column names a position: 0 — by title, otherwise by the value of this parameter (the 1C code of a connector)
      Throws:
      IOException
      SQLException
    • apply

      public DeviceImportService.Result apply(List<DeviceImportService.Row> rows, int itemExtIdParamId, int userId) throws SQLException, BGMessageException
      Writes the rows, resolving them again first — what was shown in the preview may be stale. Rows that come out with an error are skipped and returned with it; a refusal of an otherwise clean row while writing is thrown, and the caller's transaction takes back everything written before.
      Throws:
      SQLException
      BGMessageException