Skip to content

Commit

Permalink
Merge branch 'development' into feature/DIMOC-231/catalogi-add-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
RalkeyOfficial committed Aug 8, 2024
2 parents 386b160 + e94fc24 commit 9abef04
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 66 deletions.
26 changes: 19 additions & 7 deletions lib/Db/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
class Catalog extends Entity implements JsonSerializable
{

protected ?string $title = null;
protected ?string $summary = null;
protected ?string $description = null;
protected ?string $image = null;
protected ?string $search = null;
protected ?string $title = null;
protected ?string $summary = null;
protected ?string $description = null;
protected ?string $image = null;
protected ?string $search = null;

protected bool $listed = false;
protected bool $listed = false;
protected ?string $organisation = null;
protected ?array $metadata = null;

public function __construct() {
$this->addType(fieldName: 'title', type: 'string');
Expand All @@ -24,6 +26,8 @@ public function __construct() {
$this->addType(fieldName: 'image', type: 'string');
$this->addType(fieldName: 'search', type: 'string');
$this->addType(fieldName: 'listed', type: 'boolean');
$this->addType(fieldName: 'organisation', type: 'string');
$this->addType(fieldName: 'metadata', type: 'json');

}

Expand All @@ -38,11 +42,17 @@ public function getJsonFields(): array

public function hydrate(array $object): self
{


if(isset($object['metadata']) === false) {
$object['metadata'] = [];
}

$jsonFields = $this->getJsonFields();

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

$method = 'set'.ucfirst($key);
Expand All @@ -67,6 +77,8 @@ public function jsonSerialize(): array
'image' => $this->image,
'search' => $this->search,
'listed' => $this->listed,
'metadata' => $this->metadata,
'organisation'=> $this->organisation,

];

Expand Down
10 changes: 8 additions & 2 deletions lib/Db/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public function hydrate(array $object): self
$this->setAttachments(null);
$this->setOrganization(null);
$this->setData(null);
$this->setModified(new DateTime());


if(isset($object['published']) === false) {
$object['published'] = null;
}

foreach($object as $key => $value) {
if (in_array($key, $jsonFields) === true && $value === []) {
Expand Down Expand Up @@ -113,8 +119,8 @@ public function jsonSerialize(): array
'portal' => $this->portal,
'catalogi' => $this->catalogi,
'metaData' => $this->metaData,
'published' => $this->published->format('c'),
'modified' => $this->modified->format('c'),
'published' => $this->published?->format('c'),
'modified' => $this->modified?->format('c'),
'featured' => $this->featured !== null ? (bool) $this->featured : null,
'organization' => $this->organization,
'data' => $this->data,
Expand Down
6 changes: 3 additions & 3 deletions lib/Migration/Version6Date20240723125106.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
]
);
$table->addColumn(name: 'organization', typeName: TYPES::JSON, options: [
'default' => [],
'default' => 'a:0:{}',
'notnull' => false,
]);
$table->addColumn(name: 'data', typeName: TYPES::JSON, options: [
'default' => [],
'default' => 'a:0:{}',
'notnull' => false,
]);
$table->addColumn(name: 'attachments', typeName: TYPES::JSON, options: [
'default' => [],
'default' => 'a:0:{}',
'notnull' => false,
]);
$table->addColumn(name: 'attachment_count', typeName: TYPES::INTEGER);
Expand Down
77 changes: 77 additions & 0 deletions lib/Migration/Version6Date20240808085441.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\OpenCatalogi\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version6Date20240808085441 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/**
* @var ISchemaWrapper $schema
*/
$schema = $schemaClosure();

if($schema->hasTable(tableName: 'catalogi') === true) {
$table = $schema->getTable(tableName: 'catalogi');

if($table->hasColumn(name: 'organization') === false) {
$table->addColumn(
name: 'organization',
typeName: Types::STRING,
options: [
'notNull' => false,
'default' => null
]);
}
if($table->hasColumn(name: 'metadata') === false) {
$table->addColumn(
name: 'metadata',
typeName: Types::JSON,
options: [
'notNull' => false,
'default' => 'a:0:{}'
]);
}

}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
63 changes: 63 additions & 0 deletions lib/Migration/Version6Date20240808092738.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\OpenCatalogi\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version6Date20240808092738 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/**
* @var ISchemaWrapper $schema
*/
$schema = $schemaClosure();

if($schema->hasTable(tableName: 'publications') === true) {
$table = $schema->getTable(tableName: 'publications');

if($table->hasColumn(name: 'published') === true) {
$column = $table->getColumn(name: 'published');
$column->setDefault(default: null);
}

}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
62 changes: 62 additions & 0 deletions lib/Migration/Version6Date20240808093230.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\OpenCatalogi\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version6Date20240808093230 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/**
* @var ISchemaWrapper $schema
*/
$schema = $schemaClosure();

if($schema->hasTable(tableName: 'publications') === true) {
$table = $schema->getTable(tableName: 'publications');

if($table->hasColumn(name: 'published') === true) {
$column = $table->getColumn(name: 'published');
$column->setNotnull(notnull: false);
}

}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
18 changes: 11 additions & 7 deletions lib/Service/DirectoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Client;
use OCA\OpenCatalogi\Db\Catalog;
use OCA\OpenCatalogi\Db\CatalogMapper;
use OCA\OpenCatalogi\Db\Listing;
use OCA\OpenCatalogi\Db\ListingMapper;
use OCP\IAppConfig;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -52,21 +53,26 @@ public function registerToExternalDirectory (array $newDirectory = [], ?string $


if($this->config->getValueString($this->appName, 'mongoStorage') !== '1') {
$catalogi = $this->catalogMapper->findAll();
$catalogi = $this->listingMapper->findAll();
} else {
$dbConfig['base_uri'] = $this->config->getValueString('opencatalogi', 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString('opencatalogi', 'mongodbKey');
$dbConfig['mongodbCluster'] = $this->config->getValueString('opencatalogi', 'mongodbCluster');

$catalogi = $this->objectService->findObjects(filters: ['_schema' => 'catalog'], config: $dbConfig)['documents'];
$catalogi = $this->objectService->findObjects(filters: ['_schema' => 'directory'], config: $dbConfig)['documents'];
}

foreach($catalogi as $catalog) {
if($catalog instanceof Catalog) {
if($catalog instanceof Listing) {
$catalog = $catalog->jsonSerialize();
}
$directory = $this->getDirectoryEntry($catalog['id']);
$result = $this->client->post(uri: $url, options: ['json' => $directory, 'http_errors' => false]);
unset($catalog['_id'], $catalog['id'], $catalog['_schema']);

if($catalog['directory'] !== $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute(routeName:"opencatalogi.directory.index"))) {
continue;
}

$result = $this->client->post(uri: $url, options: ['json' => $catalog, 'http_errors' => false]);
}

$externalDirectories = $this->fetchFromExternalDirectory(url: $url);
Expand Down Expand Up @@ -107,8 +113,6 @@ private function createDirectoryFromResult(array $result): ?array
$this->listingMapper->createFromArray($result);
}

$this->registerToExternalDirectory(newDirectory: $result);

return $returnData;
}

Expand Down
3 changes: 1 addition & 2 deletions src/views/Views.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { navigationStore, searchStore } from '../store/store.js'
<Catalogi v-if="navigationStore.selected === 'catalogi'" />
<Organisations v-if="navigationStore.selected === 'organisations'" />
<Themes v-if="navigationStore.selected === 'themes'" />
<Catalogi v-if="navigationStore.selected === 'catalogi'" />
<Dashboard v-if="navigationStore.selected === 'dashboard'" />
<Dashboard v-if="navigationStore.selected === 'dashboard'" :search="searchStore.search" />
<Directory v-if="navigationStore.selected === 'directory'" />
<Publications v-if="navigationStore.selected === 'publication'" />
<Matadata v-if="navigationStore.selected === 'metaData'" />
Expand Down
6 changes: 5 additions & 1 deletion src/views/catalogi/CatalogiList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { catalogiStore, navigationStore } from '../../store/store.js'
</template>
Help
</NcActionButton>
<NcActionButton :disabled="loading" @click="fetchData">
<NcActionButton :disabled="loading" @click="refresh">
<template #icon>
<Refresh :size="20" />
</template>
Expand Down Expand Up @@ -152,6 +152,10 @@ export default {
this.fetchData()
},
methods: {
refresh(e) {
e.preventDefault()
this.fetchData()
},
fetchData(search = null) {
this.loading = true
catalogiStore.refreshCatalogiList(search)
Expand Down
Loading

0 comments on commit 9abef04

Please sign in to comment.