Skip to content

Commit

Permalink
Merge pull request #529 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NishaSharma14 authored Oct 21, 2022
2 parents 4d00f79 + 9ee2c32 commit 89a5593
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 51 deletions.
75 changes: 75 additions & 0 deletions app/Console/Commands/UnpublishProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
namespace App\Console\Commands;

use App\Actions\Project\UnPublishProject;
use App\Models\Draft;
use App\Models\FileSystemObject;
use App\Models\Project;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class UnpublishProjects extends Command
{
Expand Down Expand Up @@ -36,7 +40,78 @@ public function handle(UnPublishProject $unpublisher)
$projects = Project::whereIn('identifier', $ids)->get();
foreach ($projects as $project) {
$unpublisher->unPublish($project);
$user_id = $project->owner->id;
$team_id = $project->team_id;
$id = Str::uuid();
$environment = env('APP_ENV', 'local');
$path = preg_replace(
'~//+~',
'/',
$environment.'/'.$user_id.'/drafts/'.$id
);

$draft = Draft::create([
'name' => $project->name,
'slug' => Str::slug('$project->name'),
'description' => $project->description,
'relative_url' => rtrim(
preg_replace('~//+~', '/', '/'.$id),
'/'
),
'path' => $path,
'owner_id' => $user_id,
'team_id' => $team_id ? $team_id : null,
'key' => $id,
]);

$projectFSObjects = FileSystemObject::with('children')
->where([
['project_id', $project->id],
['level', 0],
])
->get();

foreach ($projectFSObjects as $FSObject) {
$this->moveFolder($FSObject, $project, $draft);
}

$project->status = null;
$project->process_logs = null;
$project->draft_id = $draft->id;
$project->save();

foreach ($project->studies as $study) {
$study->draft_id = $draft->id;
$study->save();
foreach ($study->datasets as $dataset) {
$dataset->draft_id = $draft->id;
$dataset->save();
}
}
}
});
}

public function moveFolder($fsObject, $project, $draft)
{
$newPath = '/'.$draft->path.$fsObject->relative_url;
$fsObject->path = $newPath;
$fsObject->draft_id = $draft->id;
$fsObject->save();

$fsObjectChildren = $fsObject->children;
foreach ($fsObjectChildren as $fsObjectChild) {
if ($fsObjectChild->type == 'file') {
$newFilePath = '/'.$draft->path.$fsObjectChild->relative_url;
if ($fsObjectChild->path && $newFilePath && $fsObjectChild->path != $newFilePath) {
Storage::disk(env('FILESYSTEM_DRIVER'))->move($fsObjectChild->path, $newFilePath);
$fsObjectChild->path = $newFilePath;
$fsObjectChild->draft_id = $draft->id;
$fsObjectChild->save();
}
} else {
$this->moveFolder($fsObjectChild, $project, $draft);
}
}
}
}
72 changes: 55 additions & 17 deletions app/Models/HasDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,98 @@ public function generateDOI($doiService)
$users = [];
$suffix = null;
$url = 'https://www.nmrxiv.org/';
$releaseDate = null;
$citation = null;

if ($this instanceof Project) {
$users = $this->allUsers();
$authors = $this->authors ? $this->authors : [];
$suffix = 'P'.$identifier;
$url = $url.'P'.$identifier;
$releaseDate = $this->release_date;
$resourceType = 'Project';
$citationDoi = $this->citation->doi;
} elseif ($this instanceof Study) {
$users = $this->allUsers();
$authors = $this->project->authors ? $this->project->authors : [];
$projectIdentifier = $this->getIdentifier($this->project, 'identifier');
$suffix = 'P'.$projectIdentifier.'.'.'S'.$identifier;
$url = $url.'S'.$identifier;
$releaseDate = $this->release_date;
$resourceType = 'Study';
$citationDoi = $this->project->citation->doi;
} elseif ($this instanceof Dataset) {
$users = $this->study->allUsers();
$authors = $this->project->authors ? $this->project->authors : [];
$projectIdentifier = $this->getIdentifier($this->project, 'identifier');
$studyIdentifier = $this->getIdentifier($this->study, 'identifier');
$suffix = 'P'.$projectIdentifier.'.'.'S'.$studyIdentifier.'.'.'D'.$identifier;
$url = $url.'D'.$identifier;
$releaseDate = $this->study->release_date;
$resourceType = 'Dataset';
$citationDoi = $this->project->citation->doi;
}

$creators = [];
foreach ($users as $user) {
array_push($creators, [
'name' => $user->last_name.' '.$user->first_name,
foreach ($authors as $user) {
array_push($contributors, [
'name' => $user->family_name.', '.$user->given_name,
'nameType' => 'Personal',
'givenName' => $user->first_name,
'familyName' => $user->last_name,
'affiliation' => [],
'nameIdentifiers' => [],
'givenName' => $user->given_name,
'familyName' => $user->family_name,
'nameIdentifiers' => $user->orcid_id,
'nameIdentifierScheme' => 'ORCID',
'schemeURI' => 'https://orcid.org',
'affiliation' => $user->affiliation,
]);
}

$contributors = [];
foreach ($authors as $user) {
array_push($contributors, [
'name' => $user->family_name.' '.$user->given_name,
foreach ($users as $user) {
array_push($creators, [
'contributorType' => 'Other',
'name' => $user->last_name.', '.$user->first_name,
'nameType' => 'Personal',
'contributorType' => 'RightsHolder',
'givenName' => $user->given_name,
'familyName' => $user->family_name,
'affiliation' => [],
'nameIdentifiers' => [],
'givenName' => $user->first_name,
'familyName' => $user->last_name,
]);
}

$citations = [
'relatedIdentifier' => $this->citationDoi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'IsSupplementTo',
];

$rights = [
'rights' => $this->license,
'rightsURI' => $license->url,
'rightsIdentifier' => $license->spdx_id,
'rightsIdentifierScheme' => 'SPDX',
'schemeURI' => 'https://spdx.org/licenses/',
];

$description = [
'description' => $this->description,
'descriptionType' => 'Other',
];

$attributes = [
'creators' => $creators,
'titles' => [
[
'title' => $this->name,
],
],
'url' => $url,
'creators' => $creators,
'publisher' => 'nmrXiv',
'contributors' => $contributors,
'publicationYear' => $releaseDate,
'language' => 'en',
'resourceType' => $this->resourceType,
'resourceTypeGeneral' => 'Dataset',
'rights' => $rights,
'description' => $description,
'url' => $url,
'isActive' => true,
'event' => 'publish',
'state' => 'findable',
Expand Down
1 change: 1 addition & 0 deletions app/Models/HasProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function sharedProjects()
public function sharedDrafts()
{
$sharedProjects = $this->projects()->wherePivot('role', '!=', 'creator');

return Draft::whereIn('id', $sharedProjects->pluck('draft_id'))->get();
}

Expand Down
2 changes: 1 addition & 1 deletion resources/js/Jetstream/ApplicationLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<a
style="font-size: 0.7em"
class="float-left font-bold border-red-900 text-red-900 absolute top-0 left-0 mx-1 my-1 text-xs border px-1 rounded-md"
>Beta</a
>v1.0-rc</a
>
</div>
</template>
64 changes: 32 additions & 32 deletions resources/js/Shared/AddAuthor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export default {
"Please enter a DOI or ORCID id to proceed.";
} else {
this.queryParam = this.importAuthorsForm.input;
if(this.checkDOI(this.importAuthorsForm.input)){
if (this.checkDOI(this.importAuthorsForm.input)) {
this.queryParam = "DOI:" + this.queryParam;
this.isDoi = true;
}
Expand All @@ -519,7 +519,8 @@ export default {
})
.then((res) => {
this.authorsListDOI = this.formatAuthorResponse(
res.data.resultList.result[0], this.importAuthorsForm.input
res.data.resultList.result[0],
this.importAuthorsForm.input
);
})
.catch((error) => {
Expand Down Expand Up @@ -615,22 +616,22 @@ export default {
});
},
/*Format the response*/
formatAuthorResponse(response,input) {
formatAuthorResponse(response, input) {
var authorsList = [];
var author = {};
var authors = [];
var tempList = [];
if(response){
if(!this.checkDOI(input)){
if (response) {
if (!this.checkDOI(input)) {
tempList = response.authorList.author;
var orcidId = "";
tempList.forEach((item) => {
if(item.hasOwnProperty("authorId")) {
if (item.hasOwnProperty("authorId")) {
var idType = item["authorId"].type;
if(idType.toLowerCase() == "orcid"){
if (idType.toLowerCase() == "orcid") {
orcidId = item["authorId"].value;
}
if(orcidId == input){
if (orcidId == input) {
authors.push(item);
}
}
Expand All @@ -640,30 +641,29 @@ export default {
}
}
authors.forEach((item) => {
author["given_name"] = item.hasOwnProperty("firstName")
? item["firstName"]
: null;
author["family_name"] = item.hasOwnProperty("lastName")
? item["lastName"]
: null;
if (item.hasOwnProperty("authorAffiliationDetailsList")) {
var affiliationList =
item["authorAffiliationDetailsList"]
.authorAffiliation;
affiliationList.forEach((item) => {
author["affiliation"] = item["affiliation"];
});
}
if (item.hasOwnProperty("authorId")) {
var idType = item["authorId"].type;
if (idType.toLowerCase() == "orcid") {
author["orcid_id"] = item["authorId"].value;
author["given_name"] = item.hasOwnProperty("firstName")
? item["firstName"]
: null;
author["family_name"] = item.hasOwnProperty("lastName")
? item["lastName"]
: null;
if (item.hasOwnProperty("authorAffiliationDetailsList")) {
var affiliationList =
item["authorAffiliationDetailsList"].authorAffiliation;
affiliationList.forEach((item) => {
author["affiliation"] = item["affiliation"];
});
}
}
authorsList.push(author);
author = {};
});
return authorsList;
if (item.hasOwnProperty("authorId")) {
var idType = item["authorId"].type;
if (idType.toLowerCase() == "orcid") {
author["orcid_id"] = item["authorId"].value;
}
}
authorsList.push(author);
author = {};
});
return authorsList;
},
/*Validating form*/
validateForm() {
Expand Down Expand Up @@ -715,7 +715,7 @@ export default {
return link;
},
/*Checking if the input is DOI*/
checkDOI(input){
checkDOI(input) {
var testKey = String(input);
var DOIpattern = new RegExp(/\b(10[.][0-9]{4,}(?:[.][0-9]+)*)\b/g);
var isDOI = DOIpattern.test(testKey);
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Shared/Submission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ export default {
let selectedDraft = this.drafts.find(
(d) => d.id == data.draft_id
);
if(!selectedDraft){
if (!selectedDraft) {
selectedDraft = this.sharedDrafts.find(
(d) => d.id == data.draft_id
);
Expand Down

0 comments on commit 89a5593

Please sign in to comment.