Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
87216f3
Reinstate validation, add resolve for internal schema entities
rjzondervan Dec 10, 2024
8088979
validation of files, oneof etc. first draft
rjzondervan Dec 11, 2024
03a4bb7
Major cleanup on subobjects
rjzondervan Dec 12, 2024
6f06d31
Add docblocks to new functions
rjzondervan Dec 12, 2024
3e2a0a1
Code style fixes
WilcoLouwerse Dec 12, 2024
3167fae
Added docblocks
WilcoLouwerse Dec 12, 2024
d00ce52
Some more small docblock updates
WilcoLouwerse Dec 12, 2024
a5751d7
Big docblock update for ObjectService
WilcoLouwerse Dec 12, 2024
75678f5
added cascade delete in frontend
bbrands02 Dec 12, 2024
f6cc6c8
Added cascade delete
bbrands02 Dec 12, 2024
addef18
Refactor on file synchronization
rjzondervan Dec 12, 2024
c9c6af5
Merge remote-tracking branch 'origin/feature/REGISTERS-75/validate-re…
bbrands02 Dec 13, 2024
64c1f2c
Merge branch 'feature/CONNECTOR-61/cascade-delete' into test-last-bra…
bbrands02 Dec 13, 2024
6957ef5
Fixes from testing
rjzondervan Dec 16, 2024
d6930f2
add oneOf in frontend
bbrands02 Dec 18, 2024
18967c8
Merge branch 'feature/REGISTERS-76/file-refactor' into test-last-bran…
WilcoLouwerse Dec 18, 2024
0decd9b
Start doing some merge fixes...
WilcoLouwerse Dec 18, 2024
9a90e7a
Some style fixes
WilcoLouwerse Dec 18, 2024
fc91258
Merge remote-tracking branch 'origin/development' into test-last-bran…
bbrands02 Dec 20, 2024
b7ca858
pass format
bbrands02 Dec 20, 2024
011ac62
added file formats
bbrands02 Dec 20, 2024
56e404c
fix File defaults
bbrands02 Dec 20, 2024
227a84f
Fix small bug in format detection for files
rjzondervan Dec 30, 2024
e1ffe80
Merge remote-tracking branch 'origin/development' into test-last-bran…
rjzondervan Dec 31, 2024
073eb03
Fix merge conflicts
rjzondervan Dec 31, 2024
4c25bdb
lint fix
bbrands02 Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions lib/Db/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<?php

namespace OCA\OpenRegister\Db;

use DateTime;
use Exception;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
use OCP\IURLGenerator;

class File extends Entity implements JsonSerializable
{
/**
* @var string|null The unique identifier for the file.
*/
protected ?string $uuid = null;

/**
* @var string The name of the file.
*/
protected ?string $filename = null;

/**
* @var string The URL to download the file.
*/
protected ?string $downloadUrl = null;

/**
* @var string The URL to share the file.
*/
protected ?string $shareUrl = null;

/**
* @var string The URL to access the file.
*/
protected ?string $accessUrl = null;

/**
* @var string The file extension (e.g., .txt, .jpg).
*/
protected ?string $extension = null;

/**
* @var string The checksum of the file for integrity verification.
*/
protected ?string $checksum = null;

/**
* @var int|null The source of the file.
*/
protected ?int $source = null;

/**
* @var string The ID of the user associated with the file.
*/
protected ?string $userId = null;

/**
* @var string|null The base64 string for this file.
*/
protected ?string $base64 = null;

/**
* @var string|null The path to this file.
*/
protected ?string $filePath = null;

/**
* @var DateTime|null The date and time when the file was created.
*/
protected ?DateTime $created = null;

/**
* @var DateTime|null The date and time when the file was last updated.
*/
protected ?DateTime $updated = null;

/**
* Constructor for the File entity.
*/
public function __construct()
{
$this->addType('uuid', 'string');
$this->addType('filename', 'string');
$this->addType('downloadUrl', 'string');
$this->addType('shareUrl', 'string');
$this->addType('accessUrl', 'string');
$this->addType('extension', 'string');
$this->addType('checksum', 'string');
$this->addType('source', 'int');
$this->addType('userId', 'string');
$this->addType('base64', 'string');
$this->addType('filePath', 'string');
$this->addType('created', 'datetime');
$this->addType('updated', 'datetime');
}

/**
* Retrieves the fields that should be treated as JSON.
*
* @return array List of JSON field names.
*/
public function getJsonFields(): array
{
return array_keys(
array_filter($this->getFieldTypes(), function ($field) {
return $field === 'json';
})
);
}

/**
* Populates the entity with data from an array.
*
* @param array $object Data to populate the entity.
*
* @return self The hydrated entity.
*/
public function hydrate(array $object): self
{
$jsonFields = $this->getJsonFields();

foreach ($object as $key => $value) {
if (in_array($key, $jsonFields) === true && $value === []) {
$value = [];
}

$method = 'set' . ucfirst($key);

try {
$this->$method($value);
} catch (Exception $exception) {
// Log or handle the exception.
}
}

return $this;
}

/**
* Serializes the entity to a JSON-compatible array.
*
* @return array The serialized entity data.
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'filename' => $this->filename,
'downloadUrl' => $this->downloadUrl,
'shareUrl' => $this->shareUrl,
'accessUrl' => $this->accessUrl,
'extension' => $this->extension,
'checksum' => $this->checksum,
'source' => $this->source,
'userId' => $this->userId,
'base64' => $this->base64,
'filePath' => $this->filePath,
'created' => isset($this->created) === true ? $this->created->format('c') : null,
'updated' => isset($this->updated) === true ? $this->updated->format('c') : null,
];
}

/**
* Generates a JSON schema for the File entity.
*
* @param IURLGenerator $IURLGenerator The URL generator instance.
*
* @return string The JSON schema as a string.
*/
public static function getSchema(IURLGenerator $IURLGenerator): string
{
return json_encode([
'$id' => $IURLGenerator->getBaseUrl().'/apps/openconnector/api/files/schema',
'$schema' => 'https://json-schema.org/draft/2020-12/schema',
'type' => 'object',
'required' => [
],
'properties' => [
'filename' => [
'type' => 'string',
'minLength' => 1,
'maxLength' => 255
],
'downloadUrl' => [
'type' => 'string',
'format' => 'uri',
],
'shareUrl' => [
'type' => 'string',
'format' => 'uri',
],
'accessUrl' => [
'type' => 'string',
'format' => 'uri',
],
'extension' => [
'type' => 'string',
'maxLength' => 10,
],
'checksum' => [
'type' => 'string',
],
'source' => [
'type' => 'number',
],
'userId' => [
'type' => 'string',
],
'base64' => [
'type' => 'string'
]
]
]);
}
}
Loading