Skip to content

Commit

Permalink
Merge pull request #76 from SURFnet/feature/publication-of-production…
Browse files Browse the repository at this point in the history
…-entity

Publish production entity
  • Loading branch information
MKodde authored Nov 3, 2017
2 parents f8bc178 + 59382c0 commit 6fc9ea9
Show file tree
Hide file tree
Showing 26 changed files with 881 additions and 59 deletions.
22 changes: 22 additions & 0 deletions \
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pick 27b45ca Update entity state when editing prod-published
fixup 3b96458 fixup! Update entity state when editing prod-published
pick 3bdf2f1 Upgrade the service mail message

# Rebase 1406950..3b96458 onto 1406950 (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
34 changes: 34 additions & 0 deletions app/DoctrineMigrations/Version20171103103244.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171103103244 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE entity ADD status VARCHAR(255) NOT NULL');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE entity DROP status');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Copyright 2017 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity;

use Surfnet\ServiceProviderDashboard\Application\Command\Command;
use Surfnet\ServiceProviderDashboard\Domain\Mailer\Message;
use Symfony\Component\Validator\Constraints as Assert;

class PublishEntityProductionCommand implements Command
{
/**
* @var string
* @Assert\NotBlank
* @Assert\Uuid
*/
private $id;

/**
* @var Message
*/
private $message;

/**
* @param string $id
* @param Message $message
*/
public function __construct($id, Message $message)
{
$this->id = $id;
$this->message = $message;
}

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @return Message
*/
public function getMessage()
{
return $this->message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Surfnet\ServiceProviderDashboard\Application\Command\Command;
use Symfony\Component\Validator\Constraints as Assert;

class PublishEntityCommand implements Command
class PublishEntityTestCommand implements Command
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* Copyright 2017 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity;

use Surfnet\ServiceProviderDashboard\Application\Command\Command;

class UpdateEntityStatusCommand implements Command
{
/**
* @var string
* @Assert\NotBlank
* @Assert\Uuid
*/
private $id;

/**
* @param string $id
* @param string $status
*/
public function __construct($id, $status)
{
$this->id = $id;
$this->status = $status;
}

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @return string
*/
public function getStatus()
{
return $this->status;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Copyright 2017 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Surfnet\ServiceProviderDashboard\Application\CommandHandler\Entity;

use League\Tactician\CommandBus;
use Psr\Log\LoggerInterface;
use Surfnet\ServiceProviderDashboard\Application\Command\Entity\PublishEntityProductionCommand;
use Surfnet\ServiceProviderDashboard\Application\Command\Mail\PublishToProductionMailCommand;
use Surfnet\ServiceProviderDashboard\Application\CommandHandler\CommandHandler;
use Surfnet\ServiceProviderDashboard\Application\Exception\InvalidArgumentException;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity;
use Surfnet\ServiceProviderDashboard\Domain\Repository\EntityRepository;

class PublishEntityProductionCommandHandler implements CommandHandler
{
/**
* @var EntityRepository
*/
private $repository;

/**
* @var CommandBus
*/
private $commandBus;

/**
* @var LoggerInterface
*/
private $logger;

public function __construct(
EntityRepository $entityRepository,
CommandBus $commandBus,
LoggerInterface $logger
) {
$this->repository = $entityRepository;
$this->commandBus = $commandBus;
$this->logger = $logger;
}

/**
* @param PublishEntityProductionCommand $command
*
* @throws InvalidArgumentException
*/
public function handle(PublishEntityProductionCommand $command)
{
$entity = $this->repository->findById($command->getId());
$this->logger->info(sprintf('Sending publish request mail to servicedesk for "%s".', $entity->getNameEn()));

// Send the confirmation mail
$mailCommand = new PublishToProductionMailCommand($command->getMessage());
$this->commandBus->handle($mailCommand);

// Set entity status to published even though it is not realy published to manage
$entity->setStatus(Entity::STATE_PUBLISHED);
$this->logger->info(sprintf('Updating status of "%s" to published.', $entity->getNameEn()));
$this->repository->save($entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Psr\Log\LoggerInterface;
use Surfnet\ServiceProviderDashboard\Application\Command\Entity\PublishEntityCommand;
use Surfnet\ServiceProviderDashboard\Application\Command\Entity\PublishEntityTestCommand;
use Surfnet\ServiceProviderDashboard\Application\CommandHandler\CommandHandler;
use Surfnet\ServiceProviderDashboard\Application\Exception\InvalidArgumentException;
use Surfnet\ServiceProviderDashboard\Application\Factory\MotivationMetadataFactory;
Expand All @@ -32,7 +33,7 @@
use Surfnet\ServiceProviderDashboard\Infrastructure\Manage\Exception\PushMetadataException;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;

class PublishEntityCommandHandler implements CommandHandler
class PublishEntityTestCommandHandler implements CommandHandler
{
/**
* @var EntityRepository
Expand Down Expand Up @@ -89,11 +90,11 @@ public function __construct(
}

/**
* @param PublishEntityCommand $command
* @param PublishEntityTestCommand $command
*
* @throws InvalidArgumentException
*/
public function handle(PublishEntityCommand $command)
public function handle(PublishEntityTestCommand $command)
{
$entity = $this->repository->findById($command->getId());
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* Copyright 2017 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Surfnet\ServiceProviderDashboard\Application\CommandHandler\Entity;

use League\Tactician\CommandBus;
use Psr\Log\LoggerInterface;
use Surfnet\ServiceProviderDashboard\Application\Command\Entity\PublishEntityProductionCommand;
use Surfnet\ServiceProviderDashboard\Application\Command\Entity\UpdateEntityStatusCommand;
use Surfnet\ServiceProviderDashboard\Application\Command\Mail\PublishToProductionMailCommand;
use Surfnet\ServiceProviderDashboard\Application\CommandHandler\CommandHandler;
use Surfnet\ServiceProviderDashboard\Application\Exception\InvalidArgumentException;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity;
use Surfnet\ServiceProviderDashboard\Domain\Repository\EntityRepository;

class UpdateEntityStatusCommandHandler implements CommandHandler
{
/**
* @var EntityRepository
*/
private $repository;

public function __construct(EntityRepository $entityRepository)
{
$this->repository = $entityRepository;
}

public function handle(UpdateEntityStatusCommand $command)
{
$entity = $this->repository->findById($command->getId());

$entity->setStatus(Entity::STATE_DRAFT);

$this->repository->save($entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function fromEntity(DomainEntity $entity)
$entity->getEntityId(),
$entity->getNameEn(),
$formattedContact,
'draft',
$entity->getStatus(),
$entity->getEnvironment()
);
}
Expand Down
Loading

0 comments on commit 6fc9ea9

Please sign in to comment.