class VolumeImport extends Import

Properties

protected string $path

Path to the directory with the import files.

from  Import
protected Collection $importVolumes

Caches the decoded volume import file.

protected UserImport $userImport

The user import instance that belongs to this import.

protected LabelTreeImport $labelTreeImport

The label tree import instance that belongs to this import.

Methods

__construct(string $path)

Create a new instance.

from  Import
bool
filesMatch()

Check if this import matches to the given import files.

from  Import
validateFiles()

Check if the files of this import are valid.

from  Import
array
expectedFiles()

The files expected by this import.

array
files()

Get the basename of each file of this import.

from  Import
validateFile(string $basename)

Validate a file of this import.

expectKeysInJson(string $file, array $expectation, bool $array = true)

Validates a JSON file to contain an array of objects, each of which has all the expected keys.

from  Import
expectColumnsInCsv(string $file, array $expectation)

Validates a CSV file to contain the expected columns.

from  Import
Collection
collectJson(string $file)

Read a JSON file containing an array and wrap it in a Laravel collection.

from  Import
array
perform(Project $project, User $creator, array $only = null, array $newUrls = [], array $nameConflictResolution = [], array $parentConflictResolution = [])

Perform the import.

Collection
getImportVolumes()

Get the contents of the volume import file.

Collection
getImportLabelTrees()

Get the contents of the label tree import file.

Collection
getVolumeImportCandidates()

Get all volumes of this import augmented by the IDs of the users, label trees and labels that they require.

Collection
getLabelTreeImportCandidates()

Get all label trees that might have to be imported for the volumes.

Collection
getLabelImportCandidates()

Get all labels that might have to be imported for the volumes.

Collection
getUserImportCandidates()

Get the users who might have to be imported for the volumes.

getUserImport()

Get the user import instance that belongs to this import.

getLabelTreeImport()

Get the label tree import instance that belongs to this import.

Collection
getCsvIdMap(string $basename, string $value, string $key = 'id')

Get a map of one CSV ID column to another.

array
getRequiredEntities()

Get the list of labels and users that whould need to be imported for each volume.

Collection
insertVolumes(Collection $candidates, User $creator, array $newUrls)

Insert import volumes into the database.

array
insertUsers(Collection $volumeCandidates)

Insert import users into the database.

array
insertLabelTreesAndLabels(Collection $volumeCandidates, array $nameConflictResolution, array $parentConflictResolution)

Insert import label trees and labels into the database.

array
insertFiles(array $volumeIdMap, string $csv, string $modelClass)

Insert import files into the database.

array
insertImages(array $volumeIdMap)

Insert import images into the database.

array
insertVideos(array $volumeIdMap)

Insert import videos into the database.

insertImageLabels(array $imageIdMap, array $labelIdMap, array $userIdMap)

Insert import image labels into the database.

insertVideoLabels(array $videoIdMap, array $labelIdMap, array $userIdMap)

Insert import video labels into the database.

insertImageAnnotations(array $volumeIdMap, array $imageIdMap, array $labelIdMap, array $userIdMap)

Insert import image annotations into the database.

insertVideoAnnotations(array $volumeIdMap, array $videoIdMap, array $labelIdMap, array $userIdMap)

Insert import video annotations into the database.

Details

in Import at line 23
__construct(string $path)

Create a new instance.

Parameters

string $path

Path to the directory with the import files.

in Import at line 33
bool filesMatch()

Check if this import matches to the given import files.

Return Value

bool

in Import at line 48
validateFiles()

Check if the files of this import are valid.

Exceptions

Exception

at line 213
protected array expectedFiles()

The files expected by this import.

Return Value

array

in Import at line 70
protected array files()

Get the basename of each file of this import.

Return Value

array

at line 233
protected validateFile(string $basename)

Validate a file of this import.

Parameters

string $basename

Basename of the file.

Exceptions

Exception

in Import at line 98
protected expectKeysInJson(string $file, array $expectation, bool $array = true)

Validates a JSON file to contain an array of objects, each of which has all the expected keys.

Parameters

string $file

File name under $this->path

array $expectation

Expected keys.

bool $array

Specifies if the file to validate contains an array or not.

Exceptions

Exception

in Import at line 124
protected expectColumnsInCsv(string $file, array $expectation)

Validates a CSV file to contain the expected columns.

Parameters

string $file

File name under $this->path

array $expectation

Expected columns.

Exceptions

Exception

in Import at line 148
protected Collection collectJson(string $file)

Read a JSON file containing an array and wrap it in a Laravel collection.

Parameters

string $file

File name under $this->path

Return Value

Collection

at line 62
array perform(Project $project, User $creator, array $only = null, array $newUrls = [], array $nameConflictResolution = [], array $parentConflictResolution = [])

Perform the import.

Parameters

Project $project

Project to attach the imported volumes to

User $creator

Creator of the new volumes.

array $only

IDs of the volume import candidates to limit the import to.

array $newUrls

New URLs of imported volumes.

array $nameConflictResolution

Array mapping label IDs to 'import' or 'existing' for how to resolve name conflicts.

array $parentConflictResolution

Array mapping label IDs to 'import' or 'existing' for how to resolve parent conflicts.

Return Value

array

Array containing 'volumes', 'labelTrees', 'labels' and 'users', mapping external IDs (from the import file) to IDs of the database.

at line 113
Collection getImportVolumes()

Get the contents of the volume import file.

Return Value

Collection

at line 127
Collection getImportLabelTrees()

Get the contents of the label tree import file.

Return Value

Collection

at line 138
Collection getVolumeImportCandidates()

Get all volumes of this import augmented by the IDs of the users, label trees and labels that they require.

Return Value

Collection

at line 184
Collection getLabelTreeImportCandidates()

Get all label trees that might have to be imported for the volumes.

Return Value

Collection

at line 194
Collection getLabelImportCandidates()

Get all labels that might have to be imported for the volumes.

Return Value

Collection

at line 205
Collection getUserImportCandidates()

Get the users who might have to be imported for the volumes.

These may be creators of annotation/image labels or admins of required label trees.

Return Value

Collection

at line 321
protected UserImport getUserImport()

Get the user import instance that belongs to this import.

Return Value

UserImport

at line 335
protected LabelTreeImport getLabelTreeImport()

Get the label tree import instance that belongs to this import.

Return Value

LabelTreeImport

at line 354
protected Collection getCsvIdMap(string $basename, string $value, string $key = 'id')

Get a map of one CSV ID column to another.

E.g. a map of the image 'id' in column 0 to the 'volume_id' in column 2.

Parameters

string $basename

Name of the CSV file

string $value

Name of the value column

string $key

Name of the key column

Return Value

Collection

at line 378
protected array getRequiredEntities()

Get the list of labels and users that whould need to be imported for each volume.

This is based on image annotation labels, image labels, video annotation labels and video labels of each volume.

Return Value

array

Maps volume IDs to a list of label IDs and a list of user IDs.

at line 448
protected Collection insertVolumes(Collection $candidates, User $creator, array $newUrls)

Insert import volumes into the database.

Parameters

Collection $candidates

The import volumes to insert.

User $creator

The creator of the new volumes.

array $newUrls

Array mapping a volume ID to a new volume URL (optional).

Return Value

Collection

Exceptions

UnprocessableEntityHttpException

at line 492
protected array insertUsers(Collection $volumeCandidates)

Insert import users into the database.

Parameters

Collection $volumeCandidates

The import volumes to insert.

Return Value

array

Map of import user IDs to existing user IDs.

at line 511
protected array insertLabelTreesAndLabels(Collection $volumeCandidates, array $nameConflictResolution, array $parentConflictResolution)

Insert import label trees and labels into the database.

Parameters

Collection $volumeCandidates

The import volumes to insert.

array $nameConflictResolution

Array mapping label IDs to 'import' or 'existing' for how to resolve name conflicts.

array $parentConflictResolution

Array mapping label IDs to 'import' or 'existing' for how to resolve parent conflicts.

Return Value

array

Map of import IDs to existing IDs of 'users' (who belong to imported label trees), 'labelTrees', and 'labels'.

at line 539
protected array insertFiles(array $volumeIdMap, string $csv, string $modelClass)

Insert import files into the database.

Parameters

array $volumeIdMap

Map of import volume IDs to existing volume IDs.

string $csv

Filename of the import CSV.

string $modelClass

File model class.

Return Value

array

Map of import file IDs to existing file IDs.

at line 592
protected array insertImages(array $volumeIdMap)

Insert import images into the database.

Parameters

array $volumeIdMap

Map of import volume IDs to existing volume IDs.

Return Value

array

Map of import image IDs to existing image IDs.

at line 604
protected array insertVideos(array $volumeIdMap)

Insert import videos into the database.

Parameters

array $volumeIdMap

Map of import volume IDs to existing volume IDs.

Return Value

array

Map of import video IDs to existing video IDs.

at line 616
protected insertImageLabels(array $imageIdMap, array $labelIdMap, array $userIdMap)

Insert import image labels into the database.

Parameters

array $imageIdMap

Map of import image IDs to existing image IDs.

array $labelIdMap

Map of import label IDs to existing label IDs.

array $userIdMap

Map of import user IDs to existing user IDs.

at line 643
protected insertVideoLabels(array $videoIdMap, array $labelIdMap, array $userIdMap)

Insert import video labels into the database.

Parameters

array $videoIdMap

Map of import video IDs to existing video IDs.

array $labelIdMap

Map of import label IDs to existing label IDs.

array $userIdMap

Map of import user IDs to existing user IDs.

at line 671
protected insertImageAnnotations(array $volumeIdMap, array $imageIdMap, array $labelIdMap, array $userIdMap)

Insert import image annotations into the database.

Parameters

array $volumeIdMap

Map of import volume IDs to existing volume IDs.

array $imageIdMap

Map of import image IDs to existing image IDs.

array $labelIdMap

Map of import label IDs to existing label IDs.

array $userIdMap

Map of import user IDs to existing user IDs.

at line 762
protected insertVideoAnnotations(array $volumeIdMap, array $videoIdMap, array $labelIdMap, array $userIdMap)

Insert import video annotations into the database.

Parameters

array $volumeIdMap

Map of import volume IDs to existing volume IDs.

array $videoIdMap

Map of import video IDs to existing video IDs.

array $labelIdMap

Map of import label IDs to existing label IDs.

array $userIdMap

Map of import user IDs to existing user IDs.