/**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->serviceManager = Bootstrap::getServiceManager();
     $this->versionService = $this->serviceManager->get(VersionService::class);
     $version = new Version();
     $version->setId(1);
     $versionType = new Type();
     $versionType->setDescription('This is the description');
     $version->setVersionType($versionType);
     $this->versionService->setVersion($version);
     $project = new Project();
     $project->setProject('This is the project');
     $this->projectService = $this->serviceManager->get(ProjectService::class);
     //        $this->projectService->setProject($project);
     $this->projectService->setProjectId(1);
     $this->versionService->getVersion()->setProject($this->projectService->getProject());
     $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock();
     $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true));
     $viewHelperManager = $this->serviceManager->get('viewhelpermanager');
     $viewHelperManager->setService('isAllowed', $authorizeServiceMock);
     $urlViewHelperMock = $this->getMockBuilder(Url::class)->disableOriginalConstructor()->getMock();
     $urlViewHelperMock->expects($this->any())->method('__invoke')->will($this->returnValue(true));
     $viewHelperManager->setService('url', $urlViewHelperMock);
     $this->versionLink = $viewHelperManager->get('versionlink');
 }
Exemple #2
0
 /**
  * @return VersionService
  */
 public function getVersionService()
 {
     /*
      * Create the versionService when not known already
      */
     if (is_null($this->versionService)) {
         $this->versionService = new VersionService();
         $version = new Version();
         if (is_null($this->getProjectService())) {
             throw new \InvalidArgumentException(sprintf("ProjectService is cannot be null for a new version"));
         }
         $version->setProject($this->getProjectService()->getProject());
         $version->setVersionType($this->getProjectService()->getNextMode()->versionType);
         $this->addRouterParam('docRef', $this->getProjectService()->getProject()->getDocRef());
         $this->getVersionService()->setVersion($version);
     }
     return $this->versionService;
 }
Exemple #3
0
 /**
  * @return Version
  */
 public function provider()
 {
     $dateTime = new \DateTime();
     $dateStart = $dateTime->sub(new \DateInterval('P1Y'));
     $dateEnd = $dateTime->add(new \DateInterval('P4Y'));
     $dateTime = new \DateTime();
     $dateSubmitted = $dateTime->add(new \DateInterval('P3Y'));
     $dateReviewed = $dateTime->add(new \DateInterval('P3Y'));
     $projectTest = new ProjectTest();
     $contactTest = new ContactTest();
     $versionTypeTest = new TypeTest();
     $version = new Version();
     $version->setDateSubmitted($dateSubmitted);
     $version->setDateReviewed($dateReviewed);
     $version->setApproved(Version::STATUS_APPROVED);
     $version->setDateStart($dateStart);
     $version->setDateEnd($dateEnd);
     $version->setProject($projectTest->provider()[0][0]);
     $version->setContact($contactTest->provider()[0][0]);
     $version->setVersionType($versionTypeTest->provider()[0][0]);
     return [[$version]];
 }
 /**
  * @param ObjectManager $manager
  *
  * @return array
  */
 public function load(ObjectManager $manager)
 {
     /**
      * Create a PO
      */
     $version = new Version();
     $dateTime = new \DateTime();
     $version->setDateCreated($dateTime->sub(new \DateInterval('P1Y')));
     $version->setDateSubmitted($dateTime->add(new \DateInterval('P4Y')));
     $dateTime = new \DateTime();
     $version->setDateReviewed($dateTime->sub(new \DateInterval('P6M')));
     $version->setDateStart($dateTime->add(new \DateInterval('P3Y')));
     $version->setDateEnd($dateTime->add(new \DateInterval('P3Y')));
     $version->setApproved(Version::STATUS_APPROVED);
     $version->setProject($manager->find("Project\\Entity\\Project", 1));
     $version->setContact($manager->find("Contact\\Entity\\Contact", 1));
     $version->setVersionType($manager->find("Project\\Entity\\Version\\Type", 1));
     $manager->persist($version);
     $manager->flush();
     /**
      * Create a CR
      */
     $version = new Version();
     $dateTime = new \DateTime();
     $version->setDateCreated($dateTime->sub(new \DateInterval('P1Y')));
     $version->setDateSubmitted($dateTime->add(new \DateInterval('P4Y')));
     $dateTime = new \DateTime();
     $version->setDateReviewed($dateTime->sub(new \DateInterval('P6M')));
     $version->setDateStart($dateTime->add(new \DateInterval('P3Y')));
     $version->setDateEnd($dateTime->add(new \DateInterval('P3Y')));
     $version->setApproved(Version::STATUS_APPROVED);
     $version->setProject($manager->find("Project\\Entity\\Project", 1));
     $version->setContact($manager->find("Contact\\Entity\\Contact", 1));
     $version->setVersionType($manager->find("Project\\Entity\\Version\\Type", 3));
     $manager->persist($version);
     $manager->flush();
 }
 public function testParseStatus()
 {
     $version = new Version();
     $versionType = new Type();
     $versionType->setType(Type::TYPE_PO);
     $version->setVersionType($versionType);
     $this->versionService->setVersion($version);
     $this->assertEquals('Unsubmitted', $this->versionService->parseStatus());
     $this->versionService->getVersion()->setDateSubmitted(new \DateTime());
     $this->versionService->getVersion()->setDateReviewed(null);
     $this->assertEquals('Decision Pending', $this->versionService->parseStatus());
     $this->versionService->getVersion()->setDateReviewed(new \DateTime());
     $this->versionService->getVersion()->setApproved(Version::STATUS_REJECTED);
     $this->assertEquals('Rejected', $this->versionService->parseStatus());
     $this->versionService->getVersion()->setApproved(Version::STATUS_APPROVED);
     $this->assertEquals('Approved', $this->versionService->parseStatus());
     $this->versionService->getVersion()->setApproved(Version::STATUS_SELECTED);
     $this->assertEquals('Selected', $this->versionService->parseStatus());
     $this->versionService->getVersion()->setApproved(Version::STATUS_RESUBMIT);
     $this->assertEquals('Resubmit', $this->versionService->parseStatus());
 }
Exemple #6
0
 /**
  * @param Acl               $acl
  * @param RoleInterface     $role
  * @param ResourceInterface $resource
  * @param null              $privilege
  *
  * @return bool
  *
  * @throws \InvalidArgumentException
  */
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     $id = $this->getRouteMatch()->getParam('id');
     /*
      * When the privilege is_null (not given by the isAllowed helper), get it from the routeMatch
      */
     if (is_null($privilege)) {
         $privilege = $this->getRouteMatch()->getParam('privilege');
     }
     /*
      * When the assertion is called via a route (and not via the viewHelper) we have the situation that
      * the resource is generic. We need to create the resource hen on the fly
      */
     if (!$resource instanceof VersionEntity) {
         /*
          * This can be called when creating a new version (the id is now null) or when viewing a version
          * The id is then not null.
          */
         if (!is_null($this->getRouteMatch()->getParam('docRef'))) {
             //This mode is called when we want to create a new version. We only have the project docRef now
             $project = $this->getProjectService()->findEntityByDocRef('Project', $this->getRouteMatch()->getParam('docRef'));
             $this->getProjectService()->setProject($project);
             $resource = new VersionEntity();
             $resource->setVersionType($this->getProjectService()->getNextMode()->versionType);
             $resource->setProject($project);
         }
         if (!is_null($this->getRouteMatch()->getParam('id'))) {
             $resource = $this->getVersionService()->setVersionId($id)->getVersion();
         }
     }
     //A contact is always needed
     if (!$this->hasContact()) {
         return false;
     }
     switch ($privilege) {
         case 'view-community':
             //Viewing and downloading is the same
         //Viewing and downloading is the same
         case 'download-version-document-binder':
             return $this->getProjectAssert()->assert($acl, $role, $resource->getProject(), 'view-community');
         case 'create-community':
             /*
              * To check if a new version can be created we need to know if the user has edit-rights on the
              * project, and if there is a correct period open for the user to create the version
              */
             if (is_null($resource->getVersionType()) || is_null($resource->getProject())) {
                 throw new \InvalidArgumentException("A new version type and project must be set to determine if a new version can be created");
             }
             /*
              * Check if the user has rights to edit the project (this can be done by checking the correct role
              * and the check of the permissions
              */
             if (!$this->getContactService()->hasPermit('edit', $resource->getProject())) {
                 return false;
             }
             /*
              * Check if the requirements for the checklist has been met.
              *
              * @var CheckList
              */
             $checkList = $this->getServiceLocator()->get("ControllerPluginManager")->get("checklist");
             $checkList->setProject($resource->getProject());
             if ($checkList->hasErrors()) {
                 return false;
             }
             /*
              * Depending on the type we should check if the user has rights to create the version in the correct
              * moment in time
              */
             $this->getProjectService()->setProject($resource->getProject());
             /*
              * Only create a version when we are in prepare-mode
              */
             if (!$this->getProjectService()->isPrepareMode()) {
                 return false;
             }
             /*
              * If the project has stopped, no new version can be created
              */
             if ($this->getProjectService()->isStopped()) {
                 return false;
             }
             switch ($this->getProjectService()->getNextMode()->versionType->getId()) {
                 case Type::TYPE_PO:
                 case Type::TYPE_FPP:
                     return !is_null($this->getCallService()->findOpenCall($this->getProjectService()->getNextMode()->versionType->getId()));
                     break;
                 default:
                     //A CR is only possible when the previous one has not been submitted yet
                     /*
                      * Check the status of the current (un submitted) version
                      */
                     $latestVersion = $this->getProjectService()->getLatestProjectVersion(null, null, true);
                     $this->getVersionService()->setVersion($latestVersion);
                     /*
                      * We cannot create a new CR when the previous has been submitted (and not approved yet)
                      */
                     if ($this->getVersionService()->isSubmitted() && !$this->getVersionService()->isApproved()) {
                         return false;
                     }
                     return true;
             }
             break;
         case 'edit-community':
             /*
              * We cannot edit a version when the auto-submit is switched on
              */
             if ($this->getVersionService()->hasAutoSubmit()) {
                 return false;
             }
             return !$this->getVersionService()->isSubmitted();
     }
     return false;
 }
Exemple #7
0
 /**
  * This functions created a new version based on the current status of a project
  * It will use the next mode system to find the Type and fill the object already with the correct project.
  *
  * @return Version;
  */
 public function getNextVersion()
 {
     $version = new Version();
     $version->setVersionType($this->getNextMode()->versionType);
     $version->setProject($this->getProject());
     return $version;
 }
 public function testParseProjectVersion()
 {
     $date = new \DateTime();
     $yesterday = $date->sub(new \DateInterval('P1D'));
     $date = new \DateTime();
     $tomorrow = $date->add(new \DateInterval('P1D'));
     $project = new Project();
     $call = new Call();
     $call->setFppCloseDate($yesterday);
     $project->setCall($call);
     $this->projectService->setProject($project);
     $versionType = new Type();
     $versionType->setId(Type::TYPE_PO);
     $version = new Version();
     $version->setApproved(Version::STATUS_APPROVED);
     $version->setVersionType($versionType);
     $versionService = new VersionService();
     $versionService->setVersion($version);
     $this->assertEquals('No FPP Submitted', $this->projectService->parseProjectVersion($versionService), 'Call close date is yesterday and version is approved');
     $this->projectService->getProject()->getCall()->setFppCloseDate($tomorrow);
     $this->assertContains('PO', $this->projectService->parseProjectVersion($versionService), 'Call close date is tomorrow and version is approved');
     $versionService->getVersion()->getVersionType()->setId(Type::TYPE_FPP);
     $versionService->getVersion()->getVersionType()->setType('fpp');
     $this->assertContains('Labelled', $this->projectService->parseProjectVersion($versionService), 'FPP submitted and approved');
     $versionService->getVersion()->getVersionType()->setId(Type::TYPE_CR);
     $this->projectService->getProject()->setDateStartActual($tomorrow);
     $this->assertEquals('Labelled', $this->projectService->parseProjectVersion($versionService), 'CR Project is labelled (will start)');
     $this->projectService->getProject()->setDateStartActual($yesterday);
     $this->assertEquals('Running', $this->projectService->parseProjectVersion($versionService), 'CR Project is running');
     $this->projectService->getProject()->setDateStartActual($yesterday);
     $this->projectService->getProject()->setDateEndActual($yesterday);
     $this->assertEquals('Completed', $this->projectService->parseProjectVersion($versionService), 'CR Project is completed');
     $versionService->getVersion()->getVersionType()->setId(Type::TYPE_SR);
     $this->assertEquals('Cancelled', $this->projectService->parseProjectVersion($versionService), 'CR Project is cancelled');
     $versionService->getVersion()->getVersionType()->setId('blaat');
     $this->assertEquals('Cannot determine state.', $this->projectService->parseProjectVersion($versionService), 'Incomplete state');
 }
Exemple #9
0
 /**
  * @return Version;
  */
 public function createVersion()
 {
     set_time_limit(0);
     /*
      * Depending on some settings, we are doing different things.
      * a PO or FPP can always be overwritten, so we will throw the previous version away.
      *
      * This will give the impression that the previous version is overwritten, but we actually will
      * create a new version and delete the previous one (only for PO and FPP)
      */
     switch ($this->getVersionType()->getId()) {
         case VersionType::TYPE_PO:
             //PO == FPP == CR
         //PO == FPP == CR
         case VersionType::TYPE_FPP:
             //FPP == PO == CR
             $previousVersion = $this->getProjectService()->getLatestProjectVersion($this->getVersionType(), null, true);
             if (!is_null($previousVersion)) {
                 $this->getVersionService()->removeEntity($previousVersion);
             }
             break;
         case VersionType::TYPE_CR:
             break;
         case VersionType::TYPE_SR:
             break;
     }
     /*
      * Create the version first
      */
     $version = new Version();
     $version->setProject($this->getProject());
     $version->setVersionType($this->getVersionType());
     $version->setApproved(Version::STATUS_SELECTED);
     $authentication = $this->getServiceLocator()->getServiceLocator()->get('zfcuser_auth_service');
     $version->setContact($authentication->getIdentity());
     $version->setDateStart($this->getProject()->getDateStart());
     $version->setDateEnd($this->getProject()->getDateEnd());
     /*
      * Auto submit always the created version
      */
     switch ($this->getVersionType()->getId()) {
         case VersionType::TYPE_PO:
             //PO == FPP == CR
         //PO == FPP == CR
         case VersionType::TYPE_FPP:
             //PO == FPP == CR
         //PO == FPP == CR
         case VersionType::TYPE_CR:
             $version->setDateSubmitted(new \DateTime());
             break;
         case VersionType::TYPE_SR:
             break;
     }
     /*
      * Transfer the documents to the version
      */
     foreach ($this->getVersionDocuments() as $document) {
         /*
          * When the document is if the correct type, we allow to merge it
          */
         try {
             if ($version->getVersionType()->getId() !== VersionType::TYPE_CR && $this->getDocumentService()->setDocument($document)->canBeMerged()) {
                 $mergedVersionDocument = new Document();
                 $mergedVersionDocument->setVersion($version);
                 $mergedVersionDocument->setContentType($document->getContentType());
                 /*
                  * Create the document by referencing to the corresponding plugin
                  */
                 $mergedDocument = $this->getController()->createMergedDocument()->setDocument($document)->createProposal();
                 /*
                  * Determine the type and select the name and document type
                  */
                 switch ($version->getVersionType()->getId()) {
                     case VersionType::TYPE_PO:
                         $mergedVersionDocument->setType($this->getDocumentService()->getDocumentTypeByType(Type::TYPE_NAME_PO_DOCUMENT));
                         $mergedVersionDocument->setDocument('Auto Generated Merged PO');
                         break;
                     case VersionType::TYPE_FPP:
                     case VersionType::TYPE_CR:
                         $mergedVersionDocument->setType($this->getDocumentService()->getDocumentTypeByType(Type::TYPE_NAME_FPP_DOCUMENT));
                         $mergedVersionDocument->setDocument('Auto Generated Merged FPP');
                         break;
                     default:
                         throw new \InvalidArgumentException(sprintf("Documents if this type %s cannot be merged for version %s", $this->getDocumentService()->getDocument()->getType(), $version->getVersionType()));
                         break;
                 }
                 $mergedVersionDocument->setSize(strlen($mergedDocument->getMergedDocument()));
                 /*
                  * Create the object and save it
                  */
                 $mergedVersionDocumentObject = new DocumentObject();
                 $mergedVersionDocumentObject->setObject($mergedDocument->getMergedDocument());
                 $mergedVersionDocumentObject->setDocument($mergedVersionDocument);
                 $this->getVersionService()->newEntity($mergedVersionDocumentObject);
             }
         } catch (\Exception $exception) {
             //Save at least the version because this is now not handled by the new document
             $version = $this->getVersionService()->newEntity($version);
             $logger = $this->getServiceLocator()->getServiceLocator()->get('ZendLog');
             $logger->Error(sprintf("Exception: Merge conflict during version create - documentId %s", $document->getId()));
             $logger->Info(sprintf("Message %s. Trace %s", $exception->getMessage(), $exception->getTraceAsString()));
         }
         /*
          * Save the document finally to avoid confusion with the merged documents which holds references
          * to the used objects
          */
         /*
          * Save the original document here in the version
          */
         $object = $document->getObject()[0]->getObject();
         //Rewind to have the stream back
         rewind($object);
         $versionDocument = new Document();
         $versionDocument->setVersion($version);
         $versionDocument->setDocument($document->getDocument());
         $versionDocument->setType($document->getType());
         $versionDocument->setSize($document->getSize());
         $versionDocument->setContentType($document->getContentType());
         $versionDocumentObject = new DocumentObject();
         $versionDocumentObject->setObject($object);
         $versionDocumentObject->setDocument($versionDocument);
         $this->getVersionService()->newEntity($versionDocumentObject);
     }
     /*
      * Copy the cost and effort in the corresponding effortVersion and costEffort tables
      */
     foreach ($this->getAffiliationService()->findAffiliationByProjectAndWhich($this->getProject()) as $affiliationService) {
         /*
          * Create the affiliationVersion.
          *
          * @var Affiliation
          */
         $affiliation = $affiliationService->getAffiliation();
         $affiliationVersion = new AffiliationVersion();
         $affiliationVersion->setAffiliation($affiliation);
         $affiliationVersion->setContact($affiliation->getContact());
         $affiliationVersion->setVersion($version);
         $affiliationVersion = $this->getAffiliationService()->newEntity($affiliationVersion);
         /*
          * Include the cost
          */
         $costPerAffiliation = $this->getProjectService()->findCostByAffiliation($affiliation);
         foreach ($costPerAffiliation as $cost) {
             $costVersion = new Cost\Version();
             $costVersion->setAffiliationVersion($affiliationVersion);
             $costVersion->setCosts($cost->getCosts());
             $costVersion->setDateStart($cost->getDateStart());
             $costVersion->setDateEnd($cost->getDateEnd());
             $this->getProjectService()->newEntity($costVersion);
         }
         /*
          * Include the effort
          */
         foreach ($this->getProject()->getWorkpackage() as $workpackage) {
             /*
              * Include the cost
              */
             $effortPerAffiliationAndWorkpackage = $this->getProjectService()->findEffortByWorkpackageAndAffiliation($workpackage, $affiliation);
             foreach ($effortPerAffiliationAndWorkpackage as $effort) {
                 $effortVersion = new Effort\Version();
                 $effortVersion->setAffiliationVersion($affiliationVersion);
                 $effortVersion->setWorkpackage($effort->getWorkpackage());
                 $effortVersion->setEffort($effort->getEffort());
                 $effortVersion->setDateStart($effort->getDateStart());
                 $effortVersion->setDateEnd($effort->getDateEnd());
                 $this->getProjectService()->newEntity($effortVersion);
             }
         }
     }
     /*
      * Update the project
      */
     $this->getProject()->setMode(Project::MODE_DEFAULT);
     $this->getProjectService()->updateEntity($this->getProject());
     return $version;
 }