Skip to content

Commit

Permalink
Merge pull request #80 from griidc/release/5.6.0
Browse files Browse the repository at this point in the history
Release/5.6.0
  • Loading branch information
praneethpr authored Nov 6, 2018
2 parents 5e102c3 + 956d663 commit 8a28933
Show file tree
Hide file tree
Showing 25 changed files with 996 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$newRevision->getRev()
);

if ($articleDiff['status']['same'] === DIF::STATUS_APPROVED) {
if ($i === ($numberOfRevisions - 1) and $articleDiff['status']['same'] === DIF::STATUS_APPROVED) {
$approvedDateTimeStamp = $articleDiff['modificationTimeStamp']['old'];
break;
} else if ($articleDiff['status']['new'] === DIF::STATUS_APPROVED) {
}

if ($articleDiff['status']['new'] === DIF::STATUS_APPROVED) {
if (!empty($articleDiff['modificationTimeStamp']['new'])) {
$approvedDateTimeStamp = $articleDiff['modificationTimeStamp']['new'];
break;
} else {
$approvedDateTimeStamp = $articleDiff['modificationTimeStamp']['same'];
break;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/Pelagos/Bundle/AppBundle/Controller/Api/DIFController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Form\FormInterface;

use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

use FOS\RestBundle\Controller\Annotations as Rest;

Expand Down Expand Up @@ -206,7 +206,7 @@ public function patchAction($id, Request $request)
*
* @param integer $id The id of the DIF to submit.
*
* @throws AccessDeniedException When the DIF authenticated user does not have permission to submit the DIF.
* @throws AccessDeniedHttpException When the DIF authenticated user does not have permission to submit the DIF.
* @throws BadRequestHttpException When the DIF could not be submitted.
*
* @ApiDoc(
Expand All @@ -229,7 +229,7 @@ public function submitAction($id)
// Check if the user has permission to submit it.
if (!$this->isGranted(DIFVoter::CAN_SUBMIT, $dif)) {
// Throw an exception if they don't.
throw new AccessDeniedException(
throw new AccessDeniedHttpException(
'You do not have sufficient privileges to submit this ' . $dif::FRIENDLY_NAME . '.'
);
}
Expand All @@ -253,7 +253,7 @@ public function submitAction($id)
*
* @param integer $id The id of the DIF to approve.
*
* @throws AccessDeniedException When the DIF authenticated user does not have permission to approve the DIF.
* @throws AccessDeniedHttpException When the DIF authenticated user does not have permission to approve the DIF.
* @throws BadRequestHttpException When the DIF could not be approved.
*
* @ApiDoc(
Expand All @@ -276,7 +276,7 @@ public function approveAction($id)
// Check if the user has permission to approve it.
if (!$this->isGranted(DIFVoter::CAN_APPROVE, $dif)) {
// Throw an exception if they don't.
throw new AccessDeniedException(
throw new AccessDeniedHttpException(
'You do not have sufficient privileges to approve this ' . $dif::FRIENDLY_NAME . '.'
);
}
Expand Down Expand Up @@ -304,7 +304,7 @@ public function approveAction($id)
*
* @param integer $id The id of the DIF to reject.
*
* @throws AccessDeniedException When the DIF authenticated user does not have permission to reject the DIF.
* @throws AccessDeniedHttpException When the DIF authenticated user does not have permission to reject the DIF.
* @throws BadRequestHttpException When the DIF could not be rejected.
*
* @ApiDoc(
Expand All @@ -327,7 +327,7 @@ public function rejectAction($id)
// Check if the user has permission to reject it.
if (!$this->isGranted(DIFVoter::CAN_REJECT, $dif)) {
// Throw an exception if they don't.
throw new AccessDeniedException(
throw new AccessDeniedHttpException(
'You do not have sufficient privileges to reject this ' . $dif::FRIENDLY_NAME . '.'
);
}
Expand All @@ -351,7 +351,7 @@ public function rejectAction($id)
*
* @param integer $id The id of the DIF to unlock.
*
* @throws AccessDeniedException When the DIF authenticated user does not have permission to unlock the DIF.
* @throws AccessDeniedHttpException When the DIF authenticated user does not have permission to unlock the DIF.
* @throws BadRequestHttpException When the DIF could not be unlocked.
*
* @ApiDoc(
Expand All @@ -374,7 +374,7 @@ public function unlockAction($id)
// Check if the user has permission to unlock it.
if (!$this->isGranted(DIFVoter::CAN_UNLOCK, $dif)) {
// Throw an exception if they don't.
throw new AccessDeniedException(
throw new AccessDeniedHttpException(
'You do not have sufficient privileges to unlock this ' . $dif::FRIENDLY_NAME . '.'
);
}
Expand All @@ -398,7 +398,7 @@ public function unlockAction($id)
*
* @param integer $id The id of the DIF to request unlock for.
*
* @throws AccessDeniedException When the authenticated user does not have
* @throws AccessDeniedHttpException When the authenticated user does not have
* permission to request unlock for the DIF.
* @throws BadRequestHttpException When the DIF could not be requested to be unlocked.
*
Expand All @@ -423,7 +423,7 @@ public function requestUnlockAction($id)
// Check if the user has permission to request it be unlocked.
if (!$this->isGranted(DIFVoter::CAN_REQUEST_UNLOCK, $dif)) {
// Throw an exception if they don't.
throw new AccessDeniedException(
throw new AccessDeniedHttpException(
'You do not have sufficient privileges to request this ' . $dif::FRIENDLY_NAME . ' be unlocked'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;


use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

use Pelagos\Bundle\AppBundle\Form\ReportDatasetDownloadType;

use Pelagos\Exception\InvalidDateSelectedException;

use Pelagos\Entity\Dataset;
use Pelagos\Entity\LogActionItem;
use Pelagos\Entity\Person;
use Pelagos\Exception\InvalidDateSelectedException;
use Pelagos\Entity\DatasetSubmission;

/**
* The dataset download report generator.
Expand Down Expand Up @@ -99,7 +101,8 @@ protected function getData(array $options = null)
'PRIMARY POINT OF CONTACT EMAIL',
'TOTAL DOWNLOADS',
'# OF GOMRI DOWNLOADS',
'# OF GOOGLE DOWNLOADS'
'# OF GOOGLE DOWNLOADS',
'FILE SIZE(MB)'
));

//prepare body's data
Expand Down Expand Up @@ -141,6 +144,7 @@ protected function getData(array $options = null)
'totalCount' => 0,
'GoMRI' => 0,
'NonGoMRI' => 0,
'fileSize' => null
);

$dataset = $this->container->get('doctrine')->getRepository(Dataset::class)
Expand All @@ -160,6 +164,12 @@ protected function getData(array $options = null)
->getEmailAddress();
}

// get file size from dataset submission
$datasetSubmission = $dataset->getDatasetSubmission();
if ($datasetSubmission instanceof DatasetSubmission) {
$dataArray[$currentIndex]['fileSize'] = $this->formatSizeUnits($datasetSubmission->getDatasetFileSize());
}

}
//count user downloads and total download
if ($result['payLoad']['userType'] == 'GoMRI') {
Expand All @@ -173,4 +183,21 @@ protected function getData(array $options = null)
}
return array_merge($this->getDefaultHeaders(), $additionalHeaders, $labels, $dataArray);
}

/**
* Used to format the file size units to MB.
*
* @param integer $fileSizeBytes File size in bytes.
*
* @return float
*/
private function formatSizeUnits($fileSizeBytes)
{
if ($fileSizeBytes) {
// Formats the size to MB
$fileSizeBytes = number_format(($fileSizeBytes / 1000000), 6);
}

return $fileSizeBytes;
}
}
206 changes: 206 additions & 0 deletions src/Pelagos/Bundle/AppBundle/Controller/UI/SideBySideController.php
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();
}
}
Loading

0 comments on commit 8a28933

Please sign in to comment.