# File Exchange

## Introduction

The File Exchange container allows Trust1Connector to upload or download files from the filesystem to the requesting party. In order to be able to access the file system, a separate `file_exchange` consent is required, only when the consent has been configured to true upon installation of the T1C-GCL.

The File Exchange container provides the following functionalities:

* selecting a folder based on application type
* listing files in selected application type
* downloading one or more files into selected application type
* uploading one or more files from the selected application type

An application type resolves locally to an absolute file system path.&#x20;

An application can create additional folders for a given application type, those folders are relative to the absolute path which has been locally mapped on the application type.&#x20;

The File Exchange container provides additionally:

* optional progress bar for file transfers
* optional user notification for file transfer completion
* user notification when browser is closed during file transfer
* implicit user consent based on pre-defined algorithm using the operating system clipboard
* copy and move files between application types

### Notifications

The File Exchange container allows the application to choose whether to notify the users in the application context, or to delegate notification to the T1C. The T1C uses the underlying operating system to notify users. One type of notifications are provided:

* Modal information

### Context and scope

The context of a type mapping is defined by the following concepts:

* **applid** (property of Type class): a string value denoting the application identifier. This is the root context for entity mapping
* **entity**: a string value denoting the root entity for types mapping
* **type**: a string value denoting a file typing, related to the absolute path mapped by an user, this value abstracts absolute paths from an application perspective

![File Exchange object model](https://2632359746-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9hsLHAoFyYqgfdRqBE%2F-LDDTGpCi_8c5_VyYYQo%2F-LDDTWxHGWpAEk7aln6l%2FFile%20exchange%20context.jpg?alt=media\&token=3aaf72e1-546a-4a1d-bdf4-849ef9837479)

The following image depicts the file exchange object model:

### Type Mapping

A 'Type' in the context of the File Exchange container, is a label, used by an application, to abstract the absolute path reference of the local file system. A 'Type' allows the application to perform file transfers, without the notion of the local file system organization. The File Exchange container maps the absolute path, chose by a user, on the application scoped label. We call this action a 'type mapping', this is, an absolute path, in the context of an application, is references by a label.&#x20;

A user can chose to 'persist' the Type mapping, or can decide to assign an absolute path for each individual transaction.

### Bulk File Transfer

The File Exchange container allows for bulk file transfer. The individual methods are stateless requests to the T1C-GCL service, and allows to up- or download one or more files from a user perspective. The progress information can be retrieved by the application for each file separately or for all the actions running on the T1C-GCL service.

### Type subfolders

Subfolders can be managed by the application. All subfolder are relative paths and when requested can be created, optionally recursively, by the File Exchange API. It's important to understand:

* Type mapping : correlates to absolute paths on a local file system
* Type subfolders: correlates to relative paths on a local file system

The File Exchange container maintains the mapping for absolute paths. Relative paths will be created when used in the specified use case. Neither absolute paths or relative paths will result in deletion on the local file system! When deleting a 'type' (aka absolute path), the type will be removed from the File Exchange container, but the references directory will still exist on the user's file system.

In the File Exchange API, the parameter `relpath` refers to an array of strings denoting a directory path.

### Responses

The File Exchange API can be integrated using Promises or callbacks. Both are returning the same result.

### Language

The language, used for OS modals, is determined by the language parameter passed on initialization of the library, as one of the GCLConfig parameters. The languages parameter can take the value: en (English), nl (Dutch), fr (French), de (German) and defaults to en (English).&#x20;

## Interface

```typescript
download(entity: string, type: string, file: ArrayBuffer, filename: string, relpath?: [string], implicitCreationType?: boolean, notifyOnCompletion?: boolean, callback?: (error: RestException, data: FileListResponse) => void): Promise<DataResponse>;
upload(entity: string, type: string, filename: string, relpath?: [string], notifyOnCompletion?: boolean, callback?: (error: RestException, data: FileListResponse) => void): Promise<ArrayBuffer>;
showModal(title: string, text: string, modal: ModalType, timeoutInSeconds?: number, callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
listTypes(entity?: string, page?: Page, callback?: (error: RestException, data: TypeListResponse) => void): Promise<TypeListResponse>;
listType(entity: string, type: string, callback?: (error: RestException, data: TypeResponse) => void): Promise<TypeResponse>;
listTypeContent(entity: string, type: string, relpath?: [string], page?: Page, callback?: (error: RestException, data: FileListResponse) => void): Promise<FileListResponse>;
listContent(entity: string, page?: Page, callback?: (error: RestException, data: FileListResponse) => void): Promise<FileListResponse>;
existsType(entity: string, type: string, callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
existsFile(entity: string, type: string, relpath: [string], callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
getAccessMode(entity: string, type: string, filename?: string, relpath?: [string], callback?: (error: RestException, data: AccessMode) => void): Promise<AccessMode>;
createDir(entity: string, type: string, relpath: [string], recursive?: boolean, callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
copyFile(entity: string, fromType: string, toType: string, filename: string, newfilename: string, fromrelpath?: [string], torelpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
moveFile(entity: string, fromType: string, toType: string, filename: string, fromrelpath?: [string], torelpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
renameFile(entity: string, type: string, filename: string, newfilename: string, relpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
getFileInfo(entity: string, type: string, filename: string, relpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
createType(entity: string, type: string, showModal?: boolean, timeoutInSeconds?: number, initabspath?: [string], callback?: (error: RestException, data: TypeResponse) => void): Promise<TypeResponse>;
createTypeDirs(entity: string, type: string, relpath: [string], showModal?: boolean, timeoutInSeconds?: number, callback?: (error: RestException, data: FileListResponse) => void): Promise<FileListResponse>;
updateType(entity: string, type: string, timeoutInSeconds?: number, callback?: (error: RestException, data: TypeResponse) => void): Promise<TypeResponse>;
deleteType(entity: string, type: string, callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
getEnabledContainers(callback?: (error: RestException, data: DataArrayResponse) => void): Promise<DataArrayResponse>;
```

## Objects

### Enums

The following enumerators have been exported by the File Exchange container:

```typescript
enum FileSort {ASC, DESC}
enum AccessMode {READ, WRITE, EXECUTE}
enum TypeStatus {MAPPED,UNMAPPED}
enum FileAction {UPLOAD, DOWNLOAD, COPY, MOVE}
enum ModalType {INFO, CHOICE}�
```

| Enum       | Values                       | Description                                                                                                                                                                                                                                                                  |
| ---------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| FileSort   | ASC, DESC                    | Used for sorting files. ASC = ascending, DESC = descending                                                                                                                                                                                                                   |
| AccessMode | READ, WRITE, EXECUTE         | Used to inform about the access permissions on the local file system. READ = read access to file or folder, WRITE = write access to file or folder, EXECUTE = execute access to file or folder                                                                               |
| TypeStatus | MAPPED, UNMAPPED             | Use to inform the application if a Type has been mapped to an absolute path by the user.                                                                                                                                                                                     |
| FileAction | UPLOAD, DOWNLOAD, COPY, MOVE | Enum used to track the progress of a file during a file action. UPLOAD = file upload from the local file system to the application, DOWNLOAD = file download from the application to the local file system, COPY = copy on local filesystem, MOVE = move on local filesystem |
| ModalType  | INFO, CHOICE                 | Enum used to show an operating system modal. INFO = for information purpose, CHOICE = yes/no for user choice                                                                                                                                                                 |

### Classes

```typescript
class T1CResponse {
    constructor(public success: boolean, public data?: any) {}
}

class ListFilesRequest {
    constructor(public path: string, public extensions: string[]) {}
}

class File {
    constructor(public extension: string,
        public name: string,
        public path: string,
        public rel_path: string[],
        public size: number,
        public last_modification_time: string,
        public is_dir: boolean,
        public access: AccessMode) {}
}
class FileListResponse extends T1CResponse {
    constructor(public data: FileList, public success: boolean) {
    super(success, data);
    }
}

class FileList {
    constructor(public files: File[], public total: number) {}
}

class FileResponse extends T1CResponse {
    constructor(public data: File, public success: boolean) {
        super(success, data);
    }
}

class TypeListResponse extends T1CResponse {
    constructor(public data: TypeList, public success: boolean) {
        super(success, data);
    }
}

class TypeResponse extends T1CResponse {
    constructor(public data: Type, public success: boolean){
        super(success, data);
    }
}

class Type {
    constructor(public appid: string, public entity: string, public name: string, public abspath: string, access: AccessMode, status: TypeStatus, public files?: number) {}
}

class TypeList{
    constructor(public types: Type[], public total: number) {}
}

class Page {
    constructor (public start: number, public size: number, public sort: FileSort) {}
}

class DataArrayResponse extends T1CResponse {
    constructor(public data: string[], public success: boolean) {
        super(success, data);
    }
}

class DataResponse extends T1CResponse {
    constructor(public data: string, public success: boolean) {
        super(success, data);
    }
}

class RestException {
    constructor(public status: number, public code: string, public description: string, public client?: GCLClient) {
        ObjectUtil.removeNullAndUndefinedFields(this);
    }
}
�
```

## Function Descriptions

The following functions are available in the T1C-JS library:

| JavaScript API |
| -------------- |

| Function             | Input                                                                           | Output                     | Description                                                                                                                                                                                |
| -------------------- | ------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| download             | entity, type, file, filename, relpath, implicitCreationType, notifyOnCompletion | success value              | Creates a file named `filename` at the `type` location, optionally in relative folder denoted by `relpath`, with file contents `file`. Optionally notifies user upon completion.           |
| upload               | entity, type, filename, relpath, notifyOnCompletion                             | array buffer               | Uploads a file named `filename`, from the `type` location, optionally in relative folder denoted with `relpath`. Optionally notifies user upon completion.                                 |
| showModal            | title, text, modal, timeoutInSeconds, type                                      | boolean                    | Triggers a system modal to inform a user, or to ask for a boolean response.                                                                                                                |
| listTypes            | entity, page                                                                    | list of type objects       | Returns a list of existing types. The type object contains information about the mapping of absolute paths. Paging can be used optionally by using the `page` parameter.                   |
| listType             | entity, type                                                                    | type object                | Returns the targeted type object.                                                                                                                                                          |
| listTypeContent      | entity, type, relpath, page                                                     | list of file objects       | Returns a list of file objects for the targeted type. A file can be a directory or a binary file. The `relpath` refers to the directory path where files should be searched for.           |
| listContent          | entity, page                                                                    | list of file objects       | Returns a list of file objects for all known types. The list will contain all files that are present in defined types.                                                                     |
| existsType           | entity, type                                                                    | boolean                    | Verifies if type exists. Be aware that a type can exist, but no mapping has been persisted by the user.                                                                                    |
| existsFile           | entity, type, relpath                                                           | boolean                    | Verifies if a file or directory exists on the local file system.                                                                                                                           |
| getAccessMode        | entity, type, relpath, filename                                                 | access mode                | Returns the access mode for a file or directory. The param `relpath` can be used to target a nested file or directory.                                                                     |
| createDir            | entity, type, relpath, recursive                                                | file object                | Returns the created file object (which in this use case is always a directory). When recursive is set to true, the all subfolders will be created.                                         |
| copyFile             | entity, fromType, toType, filename, newfilename, fromrelpath, torelpath         | file object                | Copy a file or directory on the local file system.                                                                                                                                         |
| moveFile             | entity, fromType, toType, filename, fromrelpath, torelpath                      | file object                | Move a file or directory on the local file system.                                                                                                                                         |
| renameFile           | entity, type, filename, newfilename, relpath                                    | file object                | Rename a file or directory                                                                                                                                                                 |
| getFileInfo          | entity, type, filename, relpath                                                 | file object                | Returns the targeted file information                                                                                                                                                      |
| createType           | entity, type, timeoutInSeconds, initabspath                                     | type object                | Creates a new type mapping, with optional initial path (migration support). When the path is not found on the local system, the user will be prompted with a file chooser.                 |
| createTypeDirs       | entity, type, relpath, showModal, timeoutInSeconds                              | type object                | Creates new subfolders for a type mapping. If the type mapping is not existing, the user will be prompted with a file chooser.                                                             |
| updateType           | entity, type, timeoutInSeconds                                                  | type object                | Prompt the user to force renewal of type mapping. The user will be presented with file chooser, even when the mapping exists already.                                                      |
| deleteType           | entity, type                                                                    | boolean                    | Removes the type mapping, but does not delete directories or files from the local system.                                                                                                  |
| getEnabledContainers | N/A                                                                             | list of enabled containers | Returns the list of enabled containers for the user. The user can activate containers upon installation, if the container has not been activated, it will not appear in the response list. |

## Implicit Consent using Clipboard <a href="#relo-remoteloading-detailedfunctionoverview" id="relo-remoteloading-detailedfunctionoverview"></a>

\
The following component diagram explains the process of interaction between the application, the browser, T1C service and Agent for the purpose of user session identification and authentication. The process is using the clipboard from a browser and from the T1C service.

![](https://2632359746-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9hsLHAoFyYqgfdRqBE%2F-LCcwgHeyJsZ0ACWX7YR%2F-LCcyGqfxZdcB1kDD0fl%2FImplicit-Consent.jpg?alt=media\&token=102e625b-a046-4de1-a9ab-7b2dc15bfd4a)

The user's clipboard is accessible write-only for the browser javascript, and read-write for the T1C agent. The user's browser is running with a user session, and an accompanied T1C agent.

The following steps are implemented:

1. Store(challenge) from the browser by the T1C-lib-js
2. Login(challenge) form the browser by the T1C-lib-js
3. Login(agent, challenge) from the T1C-GCL service to the T1C-GCL agent
4. Fetch challenge and erase clipboard form the T1C-GCL agent to the user's clipboard
5. Access Token(agent) from the T1C-GCL agent to the T1C-GCL service
6. Access Token(agent) from the T1C-GCL service to the T1C-JS running in the context of an application

For more information upon the consent mechanisms supported, you can read:

{% content-ref url="../core/consent" %}
[consent](https://t1t.gitbook.io/t1c-js-belfius-guide/v2.2.3/core/consent)
{% endcontent-ref %}

## Detailed Function Overview <a href="#relo-remoteloading-detailedfunctionoverview" id="relo-remoteloading-detailedfunctionoverview"></a>

### Paging (Page interface) <a href="#relo-remoteloading-opensession" id="relo-remoteloading-opensession"></a>

The File Exchange container uses paging for the endpoints:

* *listTypes*
* *listContent*

The page-parameter can be optionally provided and contains the following properties:

* **start**: start index
* **size**: number of items on a page
* **order**: ordering of file and directory names ascending or descending

When used, the resulting response returns an 'total' property with the total item count for the requested resource.

### download <a href="#relo-remoteloading-opensession" id="relo-remoteloading-opensession"></a>

Creates a file named `filename` at the `type` location in the context of `entity`, optionally in relative folder denoted by `relpath`, with file content `file`. Optionally notifies user upon completion.. When notifications are disabled, the application is assumed to handle user notifications.

The optional `relpath` provided, will be created when not existing, this in a recursive manner.

#### Interface <a href="#relo-remoteloading-interface" id="relo-remoteloading-interface"></a>

```typescript
download(entity: string, type: string, file: ArrayBuffer, filename: string, relpath?: [string], implicitCreationType?: boolean, notifyOnCompletion?: boolean, callback?: (error: RestException, data: FileListResponse) => void): Promise<DataResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity**: the entity context where the type mapping is persisted&#x20;
* **type**: location for the newly created file
* **file**: ArrayBuffer containing binary data to be put in the file
* **filename**: name to be given to the file
* **relpath**:  optional relative path (array of strings), when provided will implicitly create the missing directories.
* **implicitCreationType**: In case the type mapping doesn’t exist, a prompt will be shown to the user for creating the Type before performing the download.
* **notifyOnCompletion**: show modal info form operating system to user upon completion

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileResponse
    success: boolean
}
```

#### Use Cases

The use cases are  the followings with the concerned parameters :

**Use Case 1**

* download with **existing Type** (whatever the value true or false of the flag ‘implicitCreationType’)
  * The user launches the download process with a relpath.
  * The application uses the T1C function download with as parameter a relpath.
  * The file is downloaded to the directory of the path + relpath (recursive creation).&#x20;

**Use Case 2** – download with **non existing Type** and parameter ‘**implicitCreationType’ = false**

* The user launches the download process.
* The application uses the T1C function download with as parameter a relpath.
* The exception 356 is raised due the fact the Type doesn’t exist.
* End&#x20;

**Use Case 3** – download with **non existing Type** and parameter ‘**implicitCreationType’ = true**

* The user launches the download process.
* The application uses the T1C function download with as parameter a relpath.
* The user will see the prompt for the Type creation with a default path.
* The user selects the directory and cancels or validates the creation:
  * Cancellation of the creation.                                                             &#x20;
    * The exception 356 is raised due the fact the Type doesn’t exist.
  * Validation of the creation.
    * The Type is created.&#x20;
    * The file is downloaded to the directory of the path + relpath (recursive creation).5.      End

### upload

Uploads a file named `filename`, from the `type` location, optionally in relative folder denoted with `relpath`. Optionally notifies the user upon completion.. When the notifications are disabled, the application is assumed to handle user notifications.

The optional `relpath` provided, will be created when not existing, this in a recursive manner.

#### Interface <a href="#relo-remoteloading-interface" id="relo-remoteloading-interface"></a>

```typescript
upload(entity: string, type: string, filename: string, relpath?: [string], notifyOnCompletion?: boolean, callback?: (error: RestException, data: FileListResponse) => void): Promise<ArrayBuffer>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity**: the entity context where the type mapping is persisted
* **type**: location for the file to upload
* **filename**: name of the file to be uploaded
* **relpath**:  optional relative path (array of strings)
* **notifyOnCompletion**: show modal info form operating system to user upon completion

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: ArrayBuffer
    success: boolean
}
```

### showModal

Showmodal will show a notification to the user.&#x20;

#### Interface

```javascript
showModal(title: string, text: string, modal: ModalType, timeoutInSeconds?: number, callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **title**: the title of the modal
* **text**: the text to show on the modal
* **modal**: type of the modal
* **timeoutInSeconds**:  timeout in seconds before the dialog is discarded (will result in a false response)

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: ArrayBuffer
    success: boolean
}
```

### listTypes

Retrieve a list of current persisted mappings given an optional entity.

#### Interface

```javascript
listTypes(entity?: string, page?: Page, callback?: (error: RestException, data: TypeListResponse) => void): Promise<TypeListResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted. Optional.
* **page:** apply a paging to the result. Optional.

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: TypeListResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found

### listType

Retrieve a list of current mappings given an entity type context.

#### Interface

```javascript
listType(entity: string, type: string, callback?: (error: RestException, data: TypeResponse) => void): Promise<TypeResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: TypeListResponse
    success: boolean
}
```

#### Exceptions

* 356: Type not found
* 360: Entity not found

### listTypeContent

List all the content for a mapping.

#### Interface

```javascript
listTypeContent(entity: string, type: string, relpath?: [string], page?: Page, callback?: (error: RestException, data: FileListResponse) => void): Promise<FileListResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **relpath:** specify a relative path to retrieve the files
* **page:** apply a paging to the result. Optional.

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileListResponse
    success: boolean
}
```

#### Exceptions

* 356: Type not found
* 360: Entity not found

### listContent

List all the content for a mapping given an entity context..

#### Interface

```javascript
listContent(entity: string, page?: Page, callback?: (error: RestException, data: FileListResponse) => void): Promise<FileListResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **page:** apply a paging to the result. Optional.

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileListResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found

### existsType

Verify if a context mapping exists.

#### Interface

```javascript
existsType(entity: string, type: string, callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: boolean
    success: boolean
}
```

### existsFile

Verify if a file exists in a context mapping.

#### Interface

```javascript
existsFile(entity: string, type: string, relpath: [string], callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **relpath**: a relative path based on the context root folder

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: boolean
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found

### getAccessMode

Get the access mode of a folder or file in a context mapping.

#### Interface

```javascript
getAccessMode(entity: string, type: string, filename?: string, relpath?: [string], callback?: (error: RestException, data: AccessMode) => void): Promise<AccessMode>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **filename:** an optional filename, if not specified the folder access mode will be returned
* **relpath**: an optional relative path based on the context root folder

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: AccessMode
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found
* 358: file or folder not found
* 351: No read access

### createDir

Create a directory in a context mapping.

#### Interface

```javascript
createDir(entity: string, type: string, relpath: [string], recursive?: boolean, callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **relpath**: a relative path based on the context root folder
* **recursive:** indicate whether the directory should be created recursively. If not and the parent directories do not exist, an error will be thrown.

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found
* 358: file or folder not found
* 352: No write access

### copyFile

Copy a file from one context mapping to another.

#### Interface

```javascript
copyFile(entity: string, fromType: string, toType: string, filename: string, newfilename: string, fromrelpath?: [string], torelpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **fromType**: the originating entity type mapping context
* **toType**: the destination entity type mapping context
* **filename**: the name the of the to copy
* **newfilename:** the new destination file name
* **fromrelpath**: an optional originating relative path based on the context root folder
* **torelpath**: an optional destination relative path based on the context root folder

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found
* 358: file or folder not found
* 351: No read access
* 352: No write access

### moveFile

Move a file from one context mapping to another.

#### Interface

```javascript
moveFile(entity: string, fromType: string, toType: string, filename: string, fromrelpath?: [string], torelpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **fromType**: the originating entity type mapping context
* **toType**: the destination entity type mapping context
* **filename**: the name the of the to copy
* **fromrelpath**: an optional originating relative path based on the context root folder
* **torelpath**: an optional destination relative path based on the context root folder

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found
* 358: file or folder not found
* 351: No read access
* 352: No write access

### renameFile

Rename a file in a context mapping.

#### Interface

```javascript
renameFile(entity: string, type: string, filename: string, newfilename: string, relpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **fromType**: the originating entity type mapping context
* **toType**: the destination entity type mapping context
* **filename**: the name the of the to copy
* **relpath**: an optional relative path based on the context root folder

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found
* 358: file or folder not found
* 351: No read access
* 352: No write access

### getFileInfo

Get file information of a file in a context mapping.

#### Interface

```javascript
getFileInfo(entity: string, type: string, filename: string, relpath?: [string], callback?: (error: RestException, data: FileResponse) => void): Promise<FileResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the originating entity type mapping context
* **filename**: the name the of the to copy
* **relpath**: an optional relative path based on the context root folder

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: FileResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found
* 358: file or folder not found
* 351: No read access

### createType

The `initabspath` parameter denotes an initial path proposal from the application.

The optional parameter `showModal` is by default set to true.

When createType is called upon an existing type mapping, the file-chooser shown to the user is defaults to the existing absolute path provided for the type.

The `showModal` flag is used to propose (or not) the prompt to the end user even if the `initabspath` exists or not. This parameter forces the prompt of the file chooser:

* when the `initabspath` is provided and `showModal` is set to true: the `initabspath` is pre-selected in the file-chooser shown to the user if existing, or the file-chooser is shown with a default path.
* when the `initabspath` is provided and `showModal` is set to false: the `initabspath` is used when mapping exists, otherwise  the file-chooser is shown to the user in order to select a valid absolute path.
* when the `initabspath` is not provided and `showModal` is set to true: the file-chooser is shown when the mapping doesn't exist.
* when the `initabspath` is not provided and `showModal` is set to false: a type exception is thrown when the type mapping doesn't exist

#### Interface

```javascript
createType(entity: string, type: string, showModal?: boolean, timeoutInSeconds?: number, initabspath?: [string], callback?: (error: RestException, data: TypeResponse) => void): Promise<TypeResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **showModal:** indicate if the folder dialog must be shown
* **timeoutInSeconds**: optional timeout in seconds before the folder dialog is discarded)
* **inittabspath:** the optional initial root context path for the new type

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: TypeResponse
    success: boolean
}
```

#### Exceptions

* 355: notification error

#### Use Cases

The use cases are  the followings with the concerned parameters:

**Use Case 1**

* createType **with an existing `initabspath`** and parameter **`showModal` = true**
  * The user will create a type mapping.
  * The application uses the T1C function createType with as parameter an existing `initabspath` and the `showModal` set to true.
  * A prompt must appear with the value set to `initabspath`.
  * The user selects (or not) a directory and cancels or validates the creation:
  * Cancellation of the creation.
    * The exception is raised due the fact it has been aborted.
  * Validation of the creation.&#x20;
    * The Type is created.
  * End&#x20;
* **Use Case 2**
  * createType **with** **an existing `initabspath`** and parameter **`showModal` = false**
    * The user will create a Type
  * The application uses the T1C function createType using as parameter an existing `initabspath` and the `showModal` set to false.
  * No prompt will be proposed to the end user but the Type is created.
  * End&#x20;
* **Use Case 3**
  * createType with **a non existing `initabspath`** (whatever the value true or false of the flag `showModal`)
    * The user will create a Type.
  * The application uses the T1C function createType with as parameter a non existing `initabspath`.
  * A prompt must appear with default value.
  * The user selects (or not) a directory and cancels or validates the creation:
    * Cancellation of the creation.
      * The exception is raised due the fact it has been aborted.
    * Validation of the creation.
      * The Type is created.
  * End

### createTypeDirs

Create directories for a context mapping.

#### Interface

```javascript
createTypeDirs(entity: string, type: string, relpath: [string], showModal?: boolean, timeoutInSeconds?: number, callback?: (error: RestException, data: FileListResponse) => void): Promise<FileListResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **relpath**: a relative path based on the context root folder
* **showModal:** indicate if the folder dialog must be shown
* **timeoutInSeconds**: optional timeout in seconds before the folder dialog is discarded)

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: TypeResponse
    success: boolean
}
```

#### Exceptions

* 355: notification error
* 360: Entity not found
* 356: Type not found
* 352: No write access

### updateType

Update a context mapping. A folder dialog will be opened and a new root context path can be choosen.

#### Interface

```javascript
updateType(entity: string, type: string, timeoutInSeconds?: number, callback?: (error: RestException, data: TypeResponse) => void): Promise<TypeResponse>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context
* **timeoutInSeconds**: timeout in seconds before the folder dialog is discarded)

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: TypeResponse
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found

### deleteType

Delete a context mapping.

#### Interface

```javascript
deleteType(entity: string, type: string, callback?: (error: RestException, data: boolean) => void): Promise<boolean>;
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **entity:** the entity context where the type mapping is persisted.
* **type**: the entity type mapping context

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: boolean
    success: boolean
}
```

#### Exceptions

* 360: Entity not found
* 356: Type not found

### getEnabledContainers

Retrieve a list of enabled containers. The users can select this during installation of the Trust1Connector.

#### Interface

```javascript
getEnabledContainers(callback?: (error: RestException, data: DataArrayResponse) => void): Promise<DataArrayResponse>;
```

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: DataArrayResponse
    success: boolean
}
```

## Error Responses

The error codes mentioned are added to the File Exchange container. The exception handling follows the framework exception handling and are extensions of status codes mentioned on:

{% content-ref url="../core/status-codes" %}
[status-codes](https://t1t.gitbook.io/t1c-js-belfius-guide/v2.2.3/core/status-codes)
{% endcontent-ref %}

| Code | Description                | Info                                                     |
| ---- | -------------------------- | -------------------------------------------------------- |
| 351  | Access  read Exception     | User has no read access                                  |
| 352  | Access write Exception     | User has no write access                                 |
| 353  | Access execution Exception | User has no execution access                             |
| 354  | File Transfer Exception    | File cannot be transferred                               |
| 355  | Notification Exception     | Notification exception                                   |
| 356  | Type not found             | Non existing type for use cases referring to a type      |
| 357  | Type already exists        | Type already exists                                      |
| 358  | Content Exception          | Non existing file or directory for use case              |
| 359  | Container info exception   | Container activation info not available                  |
| 360  | Entity not found           | Non existing entity for use cases referring to an entity |
| 361  | Entity already exists      | Entity already exists                                    |
