Skip to content

Commit

Permalink
Merge pull request #921 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NishaSharma14 authored Nov 28, 2023
2 parents efa68d4 + 47c2020 commit 2b01728
Show file tree
Hide file tree
Showing 62 changed files with 1,406 additions and 1,091 deletions.
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ EUROPEMC_WS_API=https://www.ebi.ac.uk/europepmc/webservices/rest/search
ORCID_ID_SEARCH_API=https://pub.orcid.org/v2.1/search
ORCID_ID_EMPLOYMENT_API=https://pub.orcid.org/v3.0/{orcid_id}/employments
ORCID_ID_PERSON_API=https://pub.orcid.org/v3.0/{orcid_id}/person
CM_API=https://api.naturalproducts.net/latest/
CROSSREF_API=https://api.crossref.org/works/


LOG_CHANNEL=stack
LOG_LEVEL=debug
Expand Down Expand Up @@ -94,3 +97,10 @@ NMRXIV_PROVIDER=NFDI4Chem
NMRXIV_PROVIDER_URL=https://www.nfdi4chem.de/
MEASUREMENT_TECHNIQUE=http://purl.obolibrary.org/obo/CHMO_0000613

#DATACITE Properties
DOI_HOST=datacite
DATACITE_USERNAME=
DATACITE_SECRET=
DATACITE_PREFIX=
DATACITE_ENDPOINT=

114 changes: 59 additions & 55 deletions app/Console/Commands/ExtractSpectra.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,69 +90,73 @@ public function handle()
foreach ($study->datasets as $dataset) {
echo $dataset->identifier;
echo "\r\n";
// if(!$dataset->has_nmrium){
$nmriumInfo = json_decode($study->nmrium['nmrium_info'], true);
$_nmriumJSON = $nmriumInfo;
$fsObject = $dataset->fsObject;

$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name;
// echo($path);
// echo $dataset->type;
// echo "\r\n";
$fsObject = $dataset->fsObject;
$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name;

$pathsMatch = false;
$spectrum = [];
$type = [];
foreach ($nmriumInfo['data']['spectra'] as $spectra) {
unset($_nmriumJSON['data']['spectra']);
$files = $spectra['sourceSelector']['files'];
if ($files) {
foreach ($files as $file) {
if (str_contains($file, $path)) {
$pathsMatch = true;
if (! $dataset->has_nmrium) {
$nmriumInfo = json_decode($study->nmrium['nmrium_info'], true);
$_nmriumJSON = $nmriumInfo;
$fsObject = $dataset->fsObject;

$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name;
$fType = $studyFSObject->type;

// echo($path);
// echo "\r\n";
$fsObject = $dataset->fsObject;
$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name;

$pathsMatch = false;
$spectrum = [];
$type = [];
foreach ($nmriumInfo['data']['spectra'] as $spectra) {
unset($_nmriumJSON['data']['spectra']);
$files = $spectra['sourceSelector']['files'];
if ($files) {
foreach ($files as $file) {
if (str_contains($file, $fType == 'file' ? $path : $path.'/')) {
$pathsMatch = true;
}
}
}
}
if ($pathsMatch) {
array_push($spectrum, $spectra);
$experimentDetailsExists = array_key_exists('experiment', $spectra['info']);
if ($experimentDetailsExists) {
$experiment = $spectra['info']['experiment'];
$nucleus = $spectra['info']['nucleus'];
if (is_array($nucleus)) {
$nucleus = implode('-', $nucleus);
if ($pathsMatch) {
array_push($spectrum, $spectra);
$experimentDetailsExists = array_key_exists('experiment', $spectra['info']);
if ($experimentDetailsExists) {
$experiment = $spectra['info']['experiment'];
$nucleus = $spectra['info']['nucleus'];
if (is_array($nucleus)) {
$nucleus = implode('-', $nucleus);
}
array_push($type, $experiment.' - '.$nucleus);
}
array_push($type, $experiment.' - '.$nucleus);
$pathsMatch = false;
}
$pathsMatch = false;
}
}
if (count($spectrum) > 0) {
$_nmriumJSON['data']['spectra'] = $spectrum;
$_nmrium = $dataset->nmrium;
if ($_nmrium) {
$_nmrium->nmrium_info = json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE);
$dataset->has_nmrium = true;
$_nmrium->save();
} else {
$_nmrium = NMRium::create([
'nmrium_info' => json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE),
]);
$dataset->nmrium()->save($_nmrium);
$dataset->has_nmrium = true;
if (count($spectrum) > 0) {
$_nmriumJSON['data']['spectra'] = $spectrum;
$_nmrium = $dataset->nmrium;
if ($_nmrium) {
$_nmrium->nmrium_info = json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE);
$dataset->has_nmrium = true;
$_nmrium->save();
} else {
$_nmrium = NMRium::create([
'nmrium_info' => json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE),
]);
$dataset->nmrium()->save($_nmrium);
$dataset->has_nmrium = true;
}
}
$uType = array_unique($type);
if (count($uType) == 1) {
$dataset->type = $uType[0];
}
$dataset->save();
}
$uType = array_unique($type);
if (count($uType) == 1) {
$dataset->type = $uType[0];
}
$dataset->save();
// }
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Controllers/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,12 @@ public function markAllNotificationAsRead(Request $request)

return $request->wantsJson() ? new JsonResponse('', 200) : back()->with('status', 'all-notification-markedAsRead');
}

/**
* Impersonate the user
*/
public function impersonate(User $user)
{
return redirect()->route('impersonate', $user->id);
}
}
22 changes: 20 additions & 2 deletions app/Http/Controllers/DraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Jobs\ArchiveStudy;
use App\Jobs\ProcessFiles;
use App\Models\Dataset;
use App\Models\Draft;
use App\Models\FileSystemObject;
Expand Down Expand Up @@ -95,6 +96,24 @@ public function files(Request $request, Draft $draft)
->orderBy('type')
->get(),
],
'missing_files' => FileSystemObject::where([
['draft_id', $draft->id],
['status', 'missing'],
])
->count(),
]);
}

public function missingFiles(Request $request, Draft $draft)
{
return response()->json(
[
'missing_files' => FileSystemObject::select('relative_url')
->where([
['draft_id', $draft->id],
['status', 'missing'],
])
->get(),
]);
}

Expand Down Expand Up @@ -261,7 +280,6 @@ public function process(Request $request, Draft $draft)
$folders = FileSystemObject::with('children')
->where([
['draft_id', $draft->id],
['status', '<>', 'missing'],
['model_type', 'study'],
])
->orderBy('type')
Expand Down Expand Up @@ -443,11 +461,11 @@ public function annotate(Request $request, Draft $draft)
$draftFolders = FileSystemObject::with('children')
->where([
['level', 0],
['status', '<>', 'missing'],
['draft_id', $draft->id],
])
->orderBy('type')
->get();
ProcessFiles::dispatch($draft);
$this->processFolder($draftFolders);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function publicProjectsView(Request $request)

public function publicStudies(Request $request, Project $project)
{
return StudyResource::collection(Study::where([['project_id', $project->id], ['is_public', true]])->filter($request->only('search', 'sort', 'mode'))->paginate(9)->withQueryString());
return StudyResource::collection(Study::where([['project_id', $project->id], ['is_public', true]])->filter($request->only('search', 'sort', 'mode'))->paginate(12)->withQueryString());
}

public function toggleUpVote(Request $request, Project $project)
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class StudyController extends Controller
public function publicStudiesView(Request $request)
{
$moleculeId = $request->get('compound');
$molecule = null;
if ($moleculeId) {
$molecule = Molecule::where('identifier', $moleculeId)->first();
if ($molecule) {
Expand All @@ -46,6 +47,7 @@ public function publicStudiesView(Request $request)
return Inertia::render('Public/Studies', [
'filters' => $request->all('search', 'sort', 'mode'),
'studies' => $studiesResource,
'molecule' => $molecule,
]);
}

Expand Down Expand Up @@ -223,7 +225,7 @@ public function nmriumInfo(Request $request, Study $study)
$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name;

$fType = $studyFSObject->type;
$pathsMatch = false;
$spectrum = [];
$type = [];
Expand All @@ -232,7 +234,7 @@ public function nmriumInfo(Request $request, Study $study)
$files = $spectra['sourceSelector']['files'];
if ($files) {
foreach ($files as $file) {
if (str_contains($file, $path)) {
if (str_contains($file, $fType == 'file' ? $path : $path.'/')) {
$pathsMatch = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function share(Request $request)
'orcidPersonApi' => env('ORCID_ID_PERSON_API'),
'orcidEmploymentApi' => env('ORCID_ID_EMPLOYMENT_API'),
'CM_API' => env('CM_API'),
'CROSSREF_API' => env('CROSSREF_API'),
]);
}
}
10 changes: 9 additions & 1 deletion app/Jobs/ArchiveStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function __construct(Project $project)
$this->project = $project;
}

/**
* Get the unique ID for the job.
*/
public function uniqueId(): string
{
return $this->project->id;
}

/**
* Execute the job.
*/
Expand All @@ -48,7 +56,7 @@ public function handle(): void
$archiveDownloadURL = $study->download_url;
if (! $archiveDownloadURL) {
$fsObject = $study->fsObject;
if ($fsObject && $fsObject->status != 'missing') {
if ($fsObject) {
$path = $fsObject->path;
$s3Client = $this->storageClient();
$bucket = config('filesystems.disks.'.env('FILESYSTEM_DRIVER').'.bucket');
Expand Down
Loading

0 comments on commit 2b01728

Please sign in to comment.