-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from griidc/release/5.6.0
Release/5.6.0
- Loading branch information
Showing
25 changed files
with
996 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
src/Pelagos/Bundle/AppBundle/Controller/UI/SideBySideController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
<?php | ||
|
||
namespace Pelagos\Bundle\AppBundle\Controller\UI; | ||
|
||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
|
||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
use Pelagos\Bundle\AppBundle\Form\DatasetSubmissionType; | ||
|
||
use Pelagos\Entity\Account; | ||
use Pelagos\Entity\DatasetSubmission; | ||
use Pelagos\Entity\Dataset; | ||
use Pelagos\Entity\DIF; | ||
use Pelagos\Entity\PersonDatasetSubmissionDatasetContact; | ||
|
||
use Pelagos\Response\TerminateResponse; | ||
|
||
/** | ||
* The DIF controller for the Pelagos UI App Bundle. | ||
* | ||
* @Route("/sidebyside") | ||
*/ | ||
class SideBySideController extends UIController | ||
{ | ||
/** | ||
* Valid values for $datasetFileTransferType and $metadataFileTransferType. | ||
*/ | ||
const SUBMISSIONS_STATES = array( | ||
DatasetSubmission::STATUS_UNSUBMITTED => 'Unsubmitted', | ||
DatasetSubmission::STATUS_INCOMPLETE => 'Draft', | ||
DatasetSubmission::STATUS_COMPLETE => 'Submitted', | ||
DatasetSubmission::STATUS_IN_REVIEW => 'In Review', | ||
); | ||
|
||
/** | ||
* The default action for Side by Side. | ||
* | ||
* @param Request $request The Symfony request object. | ||
* @param string|null $udi The UDI of the Dataset to load. | ||
* | ||
* @Route("/{udi}") | ||
* | ||
* @return Response A Response instance. | ||
*/ | ||
public function defaultAction(Request $request, $udi = null) | ||
{ | ||
if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) { | ||
return $this->redirect('/user/login?destination=' . $request->getPathInfo()); | ||
} | ||
|
||
if (!$this->isGranted(array('ROLE_DATA_REPOSITORY_MANAGER', 'ROLE_SUBJECT_MATTER_EXPERT'))) { | ||
return $this->render('PelagosAppBundle:template:AdminOnly.html.twig'); | ||
} | ||
|
||
return $this->render( | ||
'PelagosAppBundle:SideBySide:index.html.twig' | ||
); | ||
} | ||
|
||
/** | ||
* The get versions action for Side by Side. | ||
* | ||
* @param Request $request The Symfony request object. | ||
* | ||
* @Route("/") | ||
* | ||
* @Method("POST") | ||
* | ||
* @return Response A Response instance. | ||
*/ | ||
public function getVersions(Request $request) | ||
{ | ||
$udi = $request->request->get('udi'); | ||
|
||
try { | ||
$datasetSubmissionHistory = $this->getDatasetSubmissionHistory($udi); | ||
} catch (\Exception $e) { | ||
return new JsonResponse( | ||
null, | ||
JsonResponse::HTTP_BAD_REQUEST | ||
); | ||
} | ||
|
||
$submissions = array(); | ||
|
||
foreach ($datasetSubmissionHistory->getIterator() as $i => $submission) { | ||
$data = array(); | ||
$data['version'] = $i; | ||
$data['udi'] = $submission->getDataset()->getUdi(); | ||
$data['sequence'] = $submission->getSequence(); | ||
$data['status'] = self::SUBMISSIONS_STATES[$submission->getStatus()]; | ||
$data['modifier'] = $submission->getModifier()->getLastName() . | ||
', ' . $submission->getModifier()->getFirstName(); | ||
$data['modificationtimestamp'] = $submission->getModificationTimeStamp()->format('c'); | ||
$submissions[] = $data; | ||
} | ||
|
||
return new JsonResponse( | ||
$submissions, | ||
JsonResponse::HTTP_OK | ||
); | ||
} | ||
|
||
/** | ||
* The get submission form action for the Side By Side controller. | ||
* | ||
* @param Request $request The Symfony request object. | ||
* @param string|null $udi The UDI of the Dataset to load. | ||
* @param string|null $revision The revision number of the Submission to load. | ||
* | ||
* @throws \Exception If revision does not exists. | ||
* | ||
* @Route("/getForm/{udi}/{revision}") | ||
* | ||
* @return Response A Response instance. | ||
*/ | ||
public function getSubmissionFormAction(Request $request, $udi = null, $revision = null) | ||
{ | ||
if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) { | ||
return $this->redirect('/user/login?destination=' . $request->getPathInfo()); | ||
} | ||
|
||
try { | ||
$datasetSubmissionHistory = $this->getDatasetSubmissionHistory($udi); | ||
|
||
if ($datasetSubmissionHistory->count() < $revision and $revision !== null) { | ||
throw new \Exception("Revision $revision does not exist for UDI: $udi"); | ||
} | ||
} catch (\Exception $e) { | ||
return new TerminateResponse( | ||
$e->getMessage(), | ||
Response::HTTP_BAD_REQUEST | ||
); | ||
} | ||
|
||
if ($revision !== null) { | ||
$datasetSubmission = $datasetSubmissionHistory[$revision]; | ||
} else { | ||
$datasetSubmission = $datasetSubmissionHistory->first(); | ||
} | ||
|
||
$researchGroupList = array(); | ||
$account = $this->getUser(); | ||
if (null !== $account) { | ||
$user = $account->getPerson(); | ||
// Find all RG's user has CREATE_DIF_DIF_ON on. | ||
$researchGroups = $user->getResearchGroups(); | ||
$researchGroupList = array_map( | ||
function ($researchGroup) { | ||
return $researchGroup->getId(); | ||
}, | ||
$researchGroups | ||
); | ||
} | ||
|
||
$form = $this->get('form.factory')->createNamed(null, DatasetSubmissionType::class, $datasetSubmission); | ||
|
||
$terminateResponse = new TerminateResponse(); | ||
|
||
return $this->render( | ||
'PelagosAppBundle:SideBySide:submissionForm.html.twig', | ||
array( | ||
'form' => $form->createView(), | ||
'datasetSubmission' => $datasetSubmission, | ||
'showForceImport' => false, | ||
'showForceDownload' => false, | ||
'researchGroupList' => $researchGroupList, | ||
'mode' => 'view', | ||
), | ||
$terminateResponse | ||
); | ||
} | ||
|
||
/** | ||
* Get the dataset submission history from UDI. | ||
* | ||
* @param string|null $udi The UDI of the Dataset to load. | ||
* | ||
* @throws \Exception If dataset if not found. | ||
* @throws \Exception If more than one dataset is returned. | ||
* | ||
* @return DatasetSubmissionHistory An array collection of submissions. | ||
*/ | ||
private function getDatasetSubmissionHistory($udi) | ||
{ | ||
$datasets = $this->entityHandler->getBy(Dataset::class, array('udi' => $udi)); | ||
|
||
if (count($datasets) == 0) { | ||
throw new \Exception("No dataset found for UDI: $udi"); | ||
} | ||
|
||
if (count($datasets) > 1) { | ||
throw new \Exception("Got more than one return for UDI: $udi"); | ||
} | ||
|
||
$dataset = $datasets[0]; | ||
|
||
return $dataset->getDatasetSubmissionHistory(); | ||
} | ||
} |
Oops, something went wrong.