Skip to content

Commit

Permalink
Ror registry data set cache; update bi-weekly; api lookup feature; mi…
Browse files Browse the repository at this point in the history
…gration / install; translations
  • Loading branch information
GaziYucel committed Sep 17, 2024
1 parent 18b6660 commit 73d1f48
Show file tree
Hide file tree
Showing 60 changed files with 1,341 additions and 5 deletions.
146 changes: 146 additions & 0 deletions api/v1/rors/PKPRorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* @file api/v1/rors/PKPRorController.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PKPRorController
*
* @ingroup api_v1_rors
*
* @brief Controller class to handle API requests for ror operations.
*
*/

namespace PKP\API\v1\rors;

use APP\facades\Repo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\plugins\Hook;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\authorization\PolicySet;
use PKP\security\authorization\RoleBasedHandlerOperationPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;

class PKPRorController extends PKPBaseController
{
/** @var int The default number of rors to return in one request */
public const DEFAULT_COUNT = 30;

/** @var int The maximum number of rors to return in one request */
public const MAX_COUNT = 100;

/**
* @copydoc \PKP\core\PKPBaseController::getHandlerPath()
*/
public function getHandlerPath(): string
{
return 'rors';
}

/**
* @copydoc \PKP\core\PKPBaseController::getRouteGroupMiddleware()
*/
public function getRouteGroupMiddleware(): array
{
return [
'has.user',
'has.context',
self::roleAuthorizer([
Role::ROLE_ID_MANAGER,
]),
];
}

/**
* @copydoc \PKP\core\PKPBaseController::getGroupRoutes()
*/
public function getGroupRoutes(): void
{
Route::get('{rorId}', $this->get(...))
->name('ror.getRor')
->whereNumber('rorId');

Route::get('', $this->getMany(...))
->name('ror.getMany');
}

/**
* @copydoc \PKP\core\PKPBaseController::authorize()
*/
public function authorize(PKPRequest $request, array &$args, array $roleAssignments): bool
{
$this->addPolicy(new UserRolesRequiredPolicy($request), true);

$rolePolicy = new PolicySet(PolicySet::COMBINING_PERMIT_OVERRIDES);

$this->addPolicy(new ContextRequiredPolicy($request));

foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}

$this->addPolicy($rolePolicy);

return parent::authorize($request, $args, $roleAssignments);
}

/**
* Get a single ror
*/
public function get(Request $illuminateRequest): JsonResponse
{
if (!Repo::ror()->exists((int) $illuminateRequest->route('rorId'), $this->getRequest()->getContext()->getId())) {
return response()->json([
'error' => __('api.rors.404.rorNotFound')
], Response::HTTP_OK);
}

$ror = Repo::ror()->get((int) $illuminateRequest->route('rorId'));

return response()->json(Repo::ror()->getSchemaMap()->map($ror), Response::HTTP_OK);
}

/**
* Get a collection of rors
*
* @hook API::rors::params [[$collector, $illuminateRequest]]
*/
public function getMany(Request $illuminateRequest): JsonResponse
{
$collector = Repo::ror()->getCollector()
->limit(self::DEFAULT_COUNT)
->offset(0);

foreach ($illuminateRequest->query() as $param => $val) {
switch ($param) {
case 'count':
$collector->limit(min((int) $val, self::MAX_COUNT));
break;
case 'offset':
$collector->offset((int) $val);
break;
case 'searchPhrase':
$collector->searchPhrase($val);
break;
}
}

Hook::call('API::rors::params', [$collector, $illuminateRequest]);

$rors = $collector->getMany();

return response()->json([
'itemsMax' => $collector->getCount(),
'items' => Repo::ror()->getSchemaMap()->summarizeMany($rors->values())->values(),
], Response::HTTP_OK);
}
}
10 changes: 8 additions & 2 deletions classes/facades/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file classes/facades/Repo.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Repo
Expand Down Expand Up @@ -39,6 +39,7 @@
use PKP\log\Repository as EmailLogEntryRepository;
use PKP\note\Repository as NoteRepository;
use PKP\notification\Notification as NotificationRepository;
use PKP\ror\Repository as RorRepository;
use PKP\stageAssignment\Repository as StageAssignmentRepository;
use PKP\submissionFile\Repository as SubmissionFileRepository;
use PKP\userGroup\Repository as UserGroupRepository;
Expand Down Expand Up @@ -115,6 +116,11 @@ public static function jats(): JatsRepository
return app(JatsRepository::class);
}

public static function ror(): RorRepository
{
return app(RorRepository::class);
}

public static function stageAssignment(): StageAssignmentRepository
{
return app(StageAssignmentRepository::class);
Expand Down
63 changes: 63 additions & 0 deletions classes/migration/install/RorsMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* @file classes/migration/install/RorsMigration.php
*
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class RorsMigration
*
* @brief Describe database table structures.
*
*/

namespace PKP\migration\install;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use PKP\migration\Migration;

class RorsMigration extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('rors', function (Blueprint $table) {
$table->comment('Ror registry dataset cache');
$table->bigInteger('ror_id')->autoIncrement();
$table->string('ror')->nullable(false);
$table->string('display_locale', 28)->default('');
$table->smallInteger('is_active')->nullable(false)->default(0);

$table->unique(['ror'], 'rors_unique');
$table->index(['display_locale'], 'rors_display_locale');
$table->index(['is_active'], 'rors_is_active');
});

Schema::create('ror_settings', function (Blueprint $table) {
$table->comment('More data about Ror registry dataset cache');
$table->bigInteger('ror_setting_id')->autoIncrement();
$table->bigInteger('ror_id');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

$table->index(['ror_id'], 'ror_settings_ror_id');
$table->unique(['ror_id', 'locale', 'setting_name'], 'ror_settings_unique');
$table->foreign('ror_id')
->references('ror_id')->on('rors')->cascadeOnDelete();
});
}

/**
* Reverse the migration.
*/
public function down(): void
{
Schema::drop('ror_settings');
Schema::drop('rors');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* @file classes/migration/upgrade/v3_4_0/I7135_CreateNewRorRegistryCacheTables.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I7135_CreateNewRorRegistryCacheTables
*
* @brief Describe database table structures.
*/

namespace PKP\migration\upgrade\v3_4_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema as Schema;
use PKP\install\DowngradeNotSupportedException;
use PKP\migration\Migration;

class I7135_CreateNewRorRegistryCacheTables extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('rors', function (Blueprint $table) {
$table->comment('Ror registry dataset cache');
$table->bigInteger('ror_id')->autoIncrement();
$table->string('ror')->nullable(false);
$table->string('display_locale', 28)->default('');
$table->smallInteger('is_active')->nullable(false)->default(0);

$table->unique(['ror'], 'rors_unique');
$table->index(['display_locale'], 'rors_display_locale');
$table->index(['is_active'], 'rors_is_active');
});

Schema::create('ror_settings', function (Blueprint $table) {
$table->comment('More data about Ror registry dataset cache');
$table->bigInteger('ror_setting_id')->autoIncrement();
$table->bigInteger('ror_id');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

$table->index(['ror_id'], 'ror_settings_ror_id');
$table->unique(['ror_id', 'locale', 'setting_name'], 'ror_settings_unique');
$table->foreign('ror_id')
->references('ror_id')->on('rors')->cascadeOnDelete();
});
}

/**
* Reverse the downgrades
*
* @throws DowngradeNotSupportedException
*/
public function down(): void
{
throw new DowngradeNotSupportedException();
}
}
Loading

0 comments on commit 73d1f48

Please sign in to comment.