Skip to content

Commit

Permalink
Merge pull request #152 from ConductionNL/feature/REGISTER-66/support…
Browse files Browse the repository at this point in the history
…-for-relations

Technical gap for software catalogus
  • Loading branch information
remko48 authored Dec 9, 2024
2 parents b88310d + 2016734 commit 7ee7dca
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 17 deletions.
19 changes: 18 additions & 1 deletion lib/Controller/AttachmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\IAppConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\IURLGenerator;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Uid\Uuid;
Expand All @@ -37,6 +38,7 @@ class AttachmentsController extends Controller
* @param FileService $fileService The file service
* @param IUserSession $userSession The user session
* @param ObjectService $objectService The object service
* @param IURLGenerator $urlGenerator The URL generator
*/
public function __construct
(
Expand All @@ -46,7 +48,8 @@ public function __construct
private readonly AttachmentMapper $attachmentMapper,
private readonly FileService $fileService,
private readonly IUserSession $userSession,
private readonly ObjectService $objectService
private readonly ObjectService $objectService,
private readonly IURLGenerator $urlGenerator
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -129,6 +132,17 @@ public function create(ObjectService $objectService): JSONResponse
// Save the new attachment object.
$object = $this->objectService->saveObject('attachment', $data);

// If object is a class change it to array
if (is_object($object)) {
$object = $object->jsonSerialize();
}

// If we do not have an uri, we need to generate one
if (isset($object['uri']) === false) {
$object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.attachments.show', ['id' => $object['id']]));
$object = $this->objectService->saveObject('attachment', $object);
}

// Return the created object as a JSON response.
return new JSONResponse($object);
}
Expand All @@ -153,6 +167,9 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;

// If we do not have an uri, we need to generate one
$data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.attachments.show', ['id' => $data['id']]));

// Save the updated attachment object
$object = $this->objectService->saveObject('attachment', $data);

Expand Down
21 changes: 19 additions & 2 deletions lib/Controller/CatalogiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

Expand All @@ -32,7 +33,8 @@ class CatalogiController extends Controller
* @param CatalogMapper $catalogMapper The catalog mapper
* @param ObjectService $objectService The object service
* @param DirectoryService $directoryService The directory service
* @param BroadcastService $broadcastService The broadcast service
* @param BroadcastService $broadcastService The broadcast service
* @param IURLGenerator $urlGenerator The URL generator
*/
public function __construct(
$appName,
Expand All @@ -41,7 +43,8 @@ public function __construct(
private readonly CatalogMapper $catalogMapper,
private readonly ObjectService $objectService,
private readonly DirectoryService $directoryService,
private readonly BroadcastService $broadcastService
private readonly BroadcastService $broadcastService,
private readonly IURLGenerator $urlGenerator
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -114,6 +117,17 @@ public function create(ObjectService $objectService): JSONResponse
// Save the new catalog object
$object = $this->objectService->saveObject('catalog', $data);

// If object is a class change it to array
if (is_object($object)) {
$object = $object->jsonSerialize();
}

// If we do not have an uri, we need to generate one
if (isset($object['uri']) === false) {
$object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.catalogs.show', ['id' => $object['id']]));
$object = $this->objectService->saveObject('catalog', $object);
}

// Update all external directories
$this->broadcastService->broadcast();

Expand Down Expand Up @@ -142,6 +156,9 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;

// If we do not have an uri, we need to generate one
$data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.catalogs.show', ['id' => $data['id']]));

// Save the updated catalog object
$object = $this->objectService->saveObject('catalog', $data);

Expand Down
22 changes: 19 additions & 3 deletions lib/Controller/OrganizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;

use OCP\IURLGenerator;
/**
* Class OrganizationsController
*
Expand All @@ -25,14 +25,16 @@ class OrganizationsController extends Controller
* @param IRequest $request The request object
* @param IAppConfig $config The app configuration
* @param OrganizationMapper $organizationMapper The organization mapper
* @param ObjectService $objectService The object service
* @param ObjectService $objectService The object service
* @param IURLGenerator $urlGenerator The URL generator
*/
public function __construct(
$appName,
IRequest $request,
private readonly IAppConfig $config,
private readonly OrganizationMapper $organizationMapper,
private readonly ObjectService $objectService
private readonly ObjectService $objectService,
private readonly IURLGenerator $urlGenerator
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -109,6 +111,17 @@ public function create(): JSONResponse
// Save the new organization object
$object = $this->objectService->saveObject('organization', $data);

// If object is a class change it to array
if (is_object($object)) {
$object = $object->jsonSerialize();
}

// If we do not have an uri, we need to generate one
if (isset($object['uri']) === false) {
$object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.organizations.show', ['id' => $object['id']]));
$object = $this->objectService->saveObject('organization', $object);
}

// Return the created object as a JSON response
return new JSONResponse($object);
}
Expand All @@ -130,6 +143,9 @@ public function update(string|int $id): JSONResponse
// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;

// If we do not have an uri, we need to generate one
$data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.organizations.show', ['id' => $data['id']]));

// Save the updated organization object
$object = $this->objectService->saveObject('organization', $data);

Expand Down
21 changes: 19 additions & 2 deletions lib/Controller/PublicationTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;

use OCP\IURLGenerator;
/**
* Class PublicationTypesController
*
Expand All @@ -29,6 +29,7 @@ class PublicationTypesController extends Controller
* @param ObjectService $objectService The object service
* @param DirectoryService $directoryService The directory service
* @param BroadcastService $broadcastService The broadcast service
* @param IURLGenerator $urlGenerator The URL generator
*/
public function __construct(
$appName,
Expand All @@ -37,7 +38,8 @@ public function __construct(
private readonly PublicationTypeMapper $publicationTypeMapper,
private readonly ObjectService $objectService,
private readonly DirectoryService $directoryService,
private readonly BroadcastService $broadcastService
private readonly BroadcastService $broadcastService,
private readonly IURLGenerator $urlGenerator
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -118,6 +120,17 @@ public function create(): JSONResponse
// Save the new publication type object
$object = $this->objectService->saveObject('publicationType', $data);

// If object is a class change it to array
if (is_object($object)) {
$object = $object->jsonSerialize();
}

// If we do not have an uri, we need to generate one
if (isset($object['uri']) === false) {
$object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.publicationTypes.show', ['id' => $object['id']]));
$object = $this->objectService->saveObject('publicationType', $object);
}

// Update all external directories
$this->broadcastService->broadcast();

Expand All @@ -142,6 +155,10 @@ public function update(string|int $id): JSONResponse
// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;

// If we do not have an uri, we need to generate one
$data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.publicationTypes.show', ['id' => $data['id']]));


// Save the updated publication type object
$object = $this->objectService->saveObject('publicationType', $data);

Expand Down
20 changes: 19 additions & 1 deletion lib/Controller/PublicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IAppConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Uid\Uuid;
Expand All @@ -49,6 +50,8 @@ class PublicationsController extends Controller
* @param FileService $fileService The file service
* @param DownloadService $downloadService The download service
* @param ObjectService $objectService The object service
* @param IURLGenerator $urlGenerator The URL generator
*
*/
public function __construct
(
Expand All @@ -59,7 +62,8 @@ public function __construct
private readonly IAppConfig $config,
private readonly FileService $fileService,
private readonly DownloadService $downloadService,
private ObjectService $objectService
private readonly ObjectService $objectService,
private readonly IURLGenerator $urlGenerator
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -197,6 +201,17 @@ public function create(ObjectService $objectService): JSONResponse
// Save the new publication object
$object = $this->objectService->saveObject('publication', $data);

// If object is a class change it to array
if (is_object($object)) {
$object = $object->jsonSerialize();
}

// If we do not have an uri, we need to generate one
if (isset($object['uri']) === false) {
$object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.publications.show', ['id' => $object['id']]));
$object = $this->objectService->saveObject('publication', $object);
}

// Return the created object as a JSON response
return new JSONResponse($object);
}
Expand All @@ -221,6 +236,9 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;

// If we do not have an uri, we need to generate one
$data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.publications.show', ['id' => $data['id']]));

// Save the updated publication object
$object = $this->objectService->saveObject('publication', $data);

Expand Down
22 changes: 19 additions & 3 deletions lib/Controller/ThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;

use OCP\IURLGenerator;
/**
* Class ThemesController
*
Expand All @@ -27,14 +27,16 @@ class ThemesController extends Controller
* @param ThemeMapper $themeMapper The theme mapper for database operations
* @param IAppConfig $config The app configuration
* @param ObjectService $objectService The service for handling object operations
* @param IURLGenerator $urlGenerator The URL generator
*/
public function __construct
(
$appName,
IRequest $request,
private readonly ThemeMapper $themeMapper,
private readonly IAppConfig $config,
private readonly ObjectService $objectService
private readonly ObjectService $objectService,
private readonly IURLGenerator $urlGenerator
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -97,6 +99,17 @@ public function create(): JSONResponse
// Save the new theme object
$object = $this->objectService->saveObject('theme', $data);

// If object is a class change it to array
if (is_object($object)) {
$object = $object->jsonSerialize();
}

// If we do not have an uri, we need to generate one
if (isset($object['uri']) === false) {
$object['uri'] = $this->urlGenerator->getAbsoluteURL($$this->urlGenerator->linkToRoute('openCatalogi.themes.show', ['id' => $object['id']]));
$object = $this->objectService->saveObject('theme', $object);
}

// Return the created object as a JSON response
return new JSONResponse($object);
}
Expand All @@ -116,7 +129,10 @@ public function update(string|int $id): JSONResponse
$data = $this->request->getParams();

// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;
$data['id'] = $id;

// If we do not have an uri, we need to generate one
$data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.themes.show', ['id' => $data['id']]));

// Save the updated theme object
$object = $this->objectService->saveObject('theme', $data);
Expand Down
3 changes: 3 additions & 0 deletions lib/Db/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class Attachment extends Entity implements JsonSerializable
{
protected ?string $uuid = null;
protected ?string $uri = null;
protected ?string $version = '0.0.1';
protected ?string $reference = null;
protected ?string $title = null;
Expand All @@ -32,6 +33,7 @@ class Attachment extends Entity implements JsonSerializable

public function __construct() {
$this->addType(fieldName: 'uuid', type: 'string');
$this->addType(fieldName: 'uri', type: 'string');
$this->addType(fieldName: 'version', type: 'string');
$this->addType(fieldName: 'reference', type: 'string');
$this->addType(fieldName: 'title', type: 'string');
Expand Down Expand Up @@ -96,6 +98,7 @@ public function jsonSerialize(): array
$array = [
'id' => $this->id,
'uuid' => $this->uuid,
'uri' => $this->uri,
'version' => $this->version,
'reference' => $this->reference,
'title' => $this->title,
Expand Down
Loading

0 comments on commit 7ee7dca

Please sign in to comment.