Skip to content

Commit

Permalink
Merge pull request #84 from ConductionNL/development
Browse files Browse the repository at this point in the history
Update master with latest changes dev, includes public themes endpoint
  • Loading branch information
remko48 authored Sep 30, 2024
2 parents 051b2cd + 354da59 commit 4229939
Show file tree
Hide file tree
Showing 158 changed files with 4,846 additions and 3,578 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"javascript.preferences.importModuleSpecifier": "relative",
"javascript.preferences.importModuleSpecifierEnding": "js",
}
9 changes: 7 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
['name' => 'search#indexInternal', 'url' => '/api/search/internal', 'verb' => 'GET'],
['name' => 'search#show', 'url' => '/api/search/{id}', 'verb' => 'GET'],
['name' => 'search#showInternal', 'url' => '/api/search/internal/{id}', 'verb' => 'GET'],
['name' => 'search#preflighted_cors', 'url' => '/api/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
['name' => 'themes#index', 'url' => '/search/themes', 'verb' => 'GET'],
['name' => 'themes#index', 'url' => '/api/search/themes', 'verb' => 'GET'],
['name' => 'themes#indexInternal', 'url' => '/api/themes', 'verb' => 'GET'],
['name' => 'themes#show', 'url' => '/api/search/themes/{id}', 'verb' => 'GET'],
['name' => 'themes#showInternal', 'url' => '/api/themes/{id}', 'verb' => 'GET'],
['name' => 'directory#page', 'url' => '/directory', 'verb' => 'GET'],
['name' => 'directory#synchronise', 'url' => '/api/directory/{id}/sync', 'verb' => 'GET'],
['name' => 'configuration#index', 'url' => '/configuration', 'verb' => 'GET'],
['name' => 'configuration#create', 'url' => '/configuration', 'verb' => 'POST'],
['name' => 'search#preflighted_cors', 'url' => '/api/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']]
['name' => 'configuration#create', 'url' => '/configuration', 'verb' => 'POST']
],
];
16 changes: 8 additions & 8 deletions lib/Controller/AttachmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function __construct

private function insertNestedObjects(array $object, ObjectService $objectService, array $config): array
{
foreach($object as $key => $value) {
foreach ($object as $key => $value) {
try {
if(
if (
is_string(value: $value)
&& $key !== 'id'
&& Uuid::isValid(uuid: $value) === true
Expand Down Expand Up @@ -109,8 +109,8 @@ public function index(ObjectService $objectService): JSONResponse
$filters = $this->request->getParams();
unset($filters['_route']);

foreach($filters as $key => $value) {
if(str_starts_with($key, '_')) {
foreach ($filters as $key => $value) {
if (str_starts_with($key, '_')) {
unset($filters[$key]);
}
}
Expand Down Expand Up @@ -306,8 +306,8 @@ public function create(ObjectService $objectService, ElasticSearchService $elast

// Remove fields we should never post.
unset($data['id']);
foreach($data as $key => $value) {
if(str_starts_with(haystack: $key, needle: '_')) {
foreach ($data as $key => $value) {
if (str_starts_with(haystack: $key, needle: '_')) {
unset($data[$key]);
}
}
Expand Down Expand Up @@ -343,8 +343,8 @@ public function update(string|int $id, ObjectService $objectService, ElasticSear

// Remove fields we should never post.
unset($data['id']);
foreach($data as $key => $value) {
if(str_starts_with(haystack: $key, needle: '_')) {
foreach ($data as $key => $value) {
if (str_starts_with(haystack: $key, needle: '_')) {
unset($data[$key]);
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/CatalogiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function index(ObjectService $objectService, SearchService $searchService
unset($filters['_route']);
$fieldsToSearch = ['title', 'description', 'summary'];

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
Expand Down Expand Up @@ -80,7 +80,7 @@ public function index(ObjectService $objectService, SearchService $searchService
*/
public function show(string|int $id, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
try {
Expand Down Expand Up @@ -124,11 +124,11 @@ public function create(ObjectService $objectService, DirectoryService $directory
}

// @todo dit is alleen omdat er een onredenlijke verplichting aan de database is toegeveoegd
if(array_key_exists('metadata',$data) === false){
if (array_key_exists('metadata',$data) === false){
$data['metadata'] = [];
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$result = $this->catalogMapper->createFromArray(object: $data);
Expand Down Expand Up @@ -177,7 +177,7 @@ public function update(string|int $id, ObjectService $objectService, DirectorySe
unset($data['id']);
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$result = $this->catalogMapper->updateFromArray(id: (int) $id, object: $data);
Expand Down Expand Up @@ -218,7 +218,7 @@ public function destroy(string|int $id, ObjectService $objectService, DirectoryS
$directoryService->listCatalog(['id' => $id, 'listed' => false]);


if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$this->catalogMapper->delete($this->catalogMapper->find((int) $id));
Expand Down
14 changes: 7 additions & 7 deletions lib/Controller/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function index(ObjectService $objectService, SearchService $searchService
unset($filters['_route']);
$fieldsToSearch = ['summary'];

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
Expand Down Expand Up @@ -85,7 +85,7 @@ public function index(ObjectService $objectService, SearchService $searchService
*/
public function show(string|int $id, ObjectService $objectService, DirectoryService $directoryService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
try {
Expand Down Expand Up @@ -129,14 +129,14 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon

// Remove fields we should never post
unset($data['id']);
foreach($data as $key => $value) {
if(str_starts_with($key, '_')) {
foreach ($data as $key => $value) {
if (str_starts_with($key, '_')) {
unset($data[$key]);
}
}


if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
return new JSONResponse($this->listingMapper->updateFromArray(id: (int) $id, object: $data));
Expand Down Expand Up @@ -164,7 +164,7 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
*/
public function destroy(string|int $id, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$this->listingMapper->delete($this->listingMapper->find((int) $id));
Expand Down Expand Up @@ -192,7 +192,7 @@ public function destroy(string|int $id, ObjectService $objectService): JSONRespo
*/
public function synchronise(string|int $id, DirectoryService $directoryService, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
try {
Expand Down
24 changes: 12 additions & 12 deletions lib/Controller/MetaDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function index(ObjectService $objectService, SearchService $searchService
unset($filters['_route']);
$fieldsToSearch = ['title', 'description'];

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
Expand Down Expand Up @@ -86,7 +86,7 @@ public function index(ObjectService $objectService, SearchService $searchService
*/
public function show(string|int $id, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
try {
Expand Down Expand Up @@ -120,20 +120,20 @@ public function create(ObjectService $objectService, IURLGenerator $urlGenerator
unset($data['id']);


foreach($data as $key => $value) {
if(str_starts_with($key, '_')) {
foreach ($data as $key => $value) {
if (str_starts_with($key, '_')) {
unset($data[$key]);
}
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$object = $this->metaDataMapper->createFromArray(object: $data);

$id = $object->getId();

if($object->getSource() === null) {
if ($object->getSource() === null) {
$source = $urlGenerator->getAbsoluteURL($urlGenerator->linkToRoute(routeName:"opencatalogi.metadata.show", arguments: ['id' => $id]));
$object->setSource($source);
$this->metaDataMapper->update($object);
Expand All @@ -153,10 +153,10 @@ public function create(ObjectService $objectService, IURLGenerator $urlGenerator
config: $dbConfig
);

if(isset($data['source']) === false || $data['source'] === null) {
if (isset($data['source']) === false || $data['source'] === null) {
$returnData['source'] = $urlGenerator->getAbsoluteURL($urlGenerator->linkToRoute(routeName:"opencatalogi.metadata.show", arguments: ['id' => $returnData['id']]));
$returnData = $objectService->saveObject(
data: $data,
data: $returnData,
config: $dbConfig
);
}
Expand All @@ -175,13 +175,13 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon

// Remove fields we should never post
unset($data['id'],$data['source']);
foreach($data as $key => $value) {
if(str_starts_with($key, '_')) {
foreach ($data as $key => $value) {
if (str_starts_with($key, '_')) {
unset($data[$key]);
}
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
return new JSONResponse($this->metaDataMapper->updateFromArray(id: (int) $id, object: $data));
Expand Down Expand Up @@ -209,7 +209,7 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
*/
public function destroy(string|int $id, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$this->metaDataMapper->delete($this->metaDataMapper->find(id: (int) $id));
Expand Down
19 changes: 11 additions & 8 deletions lib/Controller/OrganisationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function index(ObjectService $objectService, SearchService $searchService
unset($filters['_route']);
$fieldsToSearch = ['title', 'description', 'summary'];

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
Expand Down Expand Up @@ -92,7 +92,7 @@ public function index(ObjectService $objectService, SearchService $searchService
*/
public function show(string $id, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
try {
Expand Down Expand Up @@ -137,7 +137,7 @@ public function create(ObjectService $objectService): JSONResponse
unset($data[$key]);
}
}
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
return new JSONResponse($this->organisationMapper->createFromArray(object: $data));
Expand All @@ -150,11 +150,14 @@ public function create(ObjectService $objectService): JSONResponse
'mongodbCluster' => $this->config->getValueString($this->appName, 'mongodbCluster')
];

$filters['_schema'] = 'organisation';
$data['_schema'] = 'organisation';

$result = $objectService->findObjects(filters: $filters, config: $dbConfig);
$returnData = $objectService->saveObject(
data: $data,
config: $dbConfig
);

return new JSONResponse(["results" => $result['documents']]);
return new JSONResponse($returnData);
} catch (\Exception $e) {
return new JSONResponse(['error' => $e->getMessage()], 500);
}
Expand All @@ -181,7 +184,7 @@ public function update(string $id, ObjectService $objectService): JSONResponse
unset($data['id']);
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
return new JSONResponse($this->organisationMapper->updateFromArray(id: (int) $id, object: $data));
Expand Down Expand Up @@ -213,7 +216,7 @@ public function update(string $id, ObjectService $objectService): JSONResponse
*/
public function destroy(string $id, ObjectService $objectService): JSONResponse
{
if($this->config->hasKey($this->appName, 'mongoStorage') === false
if ($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$this->organisationMapper->delete($this->organisationMapper->find((int) $id));
Expand Down
Loading

0 comments on commit 4229939

Please sign in to comment.