Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

feat: Enhanced conversation snapshot #120

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions module/Api/config/command-map.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@
CommandCli\InterimEndDateEnforcement::class => CommandHandlerCli\InterimEndDateEnforcement::class,

Command\Messaging\Conversation\StoreSnapshot::class => CommandHandler\Messaging\Conversation\StoreSnapshot::class,
Command\Messaging\Conversation\StoreEnhancedSnapshot::class => CommandHandler\Messaging\Conversation\StoreEnhancedSnapshot::class,
TransferCommand\Messaging\Message\Create::class => CommandHandler\Messaging\Message\Create::class,
TransferCommand\Messaging\Conversation\Create::class => CommandHandler\Messaging\Conversation\Create::class,
];
1 change: 1 addition & 0 deletions module/Api/config/validation-map/messaging.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CommandHandler\Messaging\DisableFileUpload::class => NoValidationRequired::class,
CommandHandler\Messaging\Message\Create::class => NoValidationRequired::class,
CommandHandler\Messaging\Conversation\StoreSnapshot::class => IsSideEffect::class,
CommandHandler\Messaging\Conversation\StoreEnhancedSnapshot::class => IsSideEffect::class,
QueryHandler\Messaging\Conversations\ByOrganisation::class => NoValidationRequired::class,
QueryHandler\Messaging\Subjects\All::class => NoValidationRequired::class,
CommandHandler\Messaging\Conversation\Create::class => NoValidationRequired::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Dvsa\Olcs\Api\Domain\Command\Messaging\Conversation;

use Dvsa\Olcs\Transfer\Command\AbstractCommand;
use Dvsa\Olcs\Transfer\FieldType\Traits\Identity;

final class StoreEnhancedSnapshot extends AbstractCommand
{
use Identity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Dvsa\Olcs\Api\Domain\Command\Email\CreateCorrespondenceRecord;
use Dvsa\Olcs\Api\Domain\Command\Messaging\Conversation\StoreSnapshot;
use Dvsa\Olcs\Api\Domain\Command\Messaging\Conversation\StoreEnhancedSnapshot;
use Dvsa\Olcs\Api\Domain\Command\Result;
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractUserCommandHandler;
use Dvsa\Olcs\Api\Domain\Exception\RuntimeException;
Expand Down Expand Up @@ -45,6 +46,8 @@ public function handleCommand(CommandInterface $command): Result

$documentResult = $this->handleSideEffect(StoreSnapshot::create(['id' => $conversation->getId()]));
$result->merge($documentResult);
$enhancedDocumentResult = $this->handleSideEffect(StoreEnhancedSnapshot::create(['id' => $conversation->getId()]));
$result->merge($enhancedDocumentResult);

$taskResult = $this->handleSideEffect(CloseTasks::create(['ids' => [$conversation->getTask()->getId()]]));
$result->merge($taskResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Dvsa\Olcs\Api\Domain\CommandHandler\Messaging\Conversation;

use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractCreateSnapshotHandler;
use Dvsa\Olcs\Api\Domain\Repository\Conversation;
use Dvsa\Olcs\Api\Entity\System\Category;
use Dvsa\Olcs\Api\Entity\System\SubCategory;
use Dvsa\Olcs\Snapshot\Service\Snapshots\Messaging\EnhancedGenerator;

final class StoreEnhancedSnapshot extends AbstractCreateSnapshotHandler
{
protected $repoServiceName = Conversation::class;
protected $generatorClass = EnhancedGenerator::class;
protected $documentCategory = Category::CATEGORY_LICENSING;
protected $documentSubCategory = SubCategory::DOC_SUB_CATEGORY_LICENCING_OTHER_DOCUMENTS;
protected $documentDescription = 'Enhanced Conversation Snapshot';
protected $documentLinkId = 'messagingConversation';

/**
* @inheritDoc
*/
protected function getDocumentDescription($entity): string
{
return $this->documentDescription;
}
}
1 change: 1 addition & 0 deletions module/Snapshot/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'ContinuationReview' => Snapshots\ContinuationReview\GeneratorFactory::class,
'ReviewSnapshot' => Snapshots\ApplicationReview\GeneratorFactory::class,
Snapshots\Messaging\Generator::class => Snapshots\Messaging\GeneratorFactory::class,
Snapshots\Messaging\EnhancedGenerator::class => Snapshots\Messaging\EnhancedGeneratorFactory::class,
Review\VariationTypeOfLicenceReviewService::class => Review\GenericFactory::class,
Review\VariationBusinessTypeReviewService::class => Review\GenericFactory::class,
Review\VariationFinancialEvidenceReviewService::class => Review\VariationFinancialEvidenceReviewServiceFactory::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Dvsa\Olcs\Snapshot\Service\Snapshots\Messaging;

use Doctrine\ORM\AbstractQuery;
use Dvsa\Olcs\Api\Domain\Repository\Message as MessageRepo;
use Dvsa\Olcs\Api\Entity\Messaging\MessagingConversation;
use Dvsa\Olcs\Api\Entity\Messaging\MessagingMessage;
use Dvsa\Olcs\Snapshot\Service\Snapshots\AbstractGenerator;
use Dvsa\Olcs\Snapshot\Service\Snapshots\AbstractGeneratorServices;
use Dvsa\Olcs\Snapshot\Service\Snapshots\SnapshotGeneratorInterface;
use Dvsa\Olcs\Transfer\Query\Messaging\Messages\ByConversation;

class EnhancedGenerator extends AbstractGenerator implements SnapshotGeneratorInterface
{
protected MessageRepo $messageRepository;
protected MessagingConversation $conversation;

public function __construct(
AbstractGeneratorServices $abstractGeneratorServices,
MessageRepo $messageRepository
) {
parent::__construct($abstractGeneratorServices);

$this->messageRepository = $messageRepository;
}

public function setData($data): void
{
$this->conversation = $data['entity'];
}

public function generate(): string
{
$query = $this->messageRepository->getBaseMessageListWithContentQuery(
ByConversation::create(
[
'page' => 1,
'limit' => 1000,
],
),
);
$query = $this->messageRepository->filterByConversationId($query, $this->conversation->getId());
/** @var MessagingMessage[] $messages */
$messages = $this->messageRepository->fetchPaginatedList($query, AbstractQuery::HYDRATE_OBJECT);

return $this->generateReadonly(
[
'conversation' => $this->conversation,
'messages' => $messages,
'enhanced' => true,
],
'conversation',
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Dvsa\Olcs\Snapshot\Service\Snapshots\Messaging;

use Dvsa\Olcs\Api\Domain\Repository\Message as MessageRepository;
use Dvsa\Olcs\Snapshot\Service\Snapshots\AbstractGeneratorServices;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class EnhancedGeneratorFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
return new EnhancedGenerator(
$container->get(AbstractGeneratorServices::class),
$container->get('RepositoryServiceManager')->get(MessageRepository::class),
);
}
}
3 changes: 2 additions & 1 deletion module/Snapshot/view/layout/conversation.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/** @global \Dvsa\Olcs\Api\Entity\Messaging\MessagingMessage[] $messages */
/** @global \Dvsa\Olcs\Api\Entity\Messaging\MessagingConversation $conversation */
/** @global bool $enhanced */
?><!DOCTYPE html>
<html lang="en">
<?php echo $this->partial('partials/review-header', ['pageTitle' => 'Conversation Archive']); ?>
Expand All @@ -16,7 +17,7 @@
</caption>

<?php foreach ($messages as $message): ?>
<?php echo $this->partial('partials/read-only/printable-message', ['message' => $message]); ?>
<?php echo $this->partial('partials/read-only/printable-message', ['message' => $message, 'enhanced' => $enhanced]); ?>
<?php endforeach; ?>
</div>
</body>
Expand Down
35 changes: 30 additions & 5 deletions module/Snapshot/view/partials/read-only/printable-message.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php /** @global \Dvsa\Olcs\Api\Entity\Messaging\MessagingMessage $message */ ?>
<?php /** @global bool $enhanced */ ?>
<div class="govuk-!-margin-bottom-6">
<div class="govuk-summary-card">
<div class="govuk-summary-card__title-wrapper">
Expand All @@ -19,11 +20,35 @@
<div class="govuk-summary-card__content">
<p class="govuk-body">
<?php echo nl2br($message->getMessagingContent()->getText()); ?>
<?php
if ($message->getCreatedBy()->getTeam() !== null) {
echo '<p class="govuk-caption-m">'.$sender.'<br/>Caseworker Team</p>';
}
?>
<?php if ($enhanced): ?>
<hr/>
<?php foreach ($message->getUserMessageReads() as $messageRead): /** @var \Dvsa\Olcs\Api\Entity\Messaging\MessagingUserMessageRead $messageRead */ ?>
<p>
<em>
<?php
if ($messageRead->getUser()->getContactDetails() && $messageRead->getUser()->getContactDetails()->getPerson()) {
$readBy = $messageRead->getUser()->getContactDetails()->getPerson()->getFullName();
} elseif ($messageRead->getUser()->getContactDetails() && $messageRead->getUser()->getContactDetails()->getEmailAddress()) {
$readBy = $messageRead->getUser()->getContactDetails()->getEmailAddress();
} else {
$readBy = $messageRead->getUser()->getLoginId();
}

echo sprintf(
'Read by %s on %s',
$readBy,
$messageRead->getCreatedOn(true)->format('l j F Y \a\t H:ia')
); ?>
</em>
</p>
<?php endforeach; ?>
<?php elseif ($message->getCreatedBy()->getTeam() !== null): ?>
jerotire marked this conversation as resolved.
Show resolved Hide resolved
<p class="govuk-caption-m">
<?php echo $sender; ?>
<br/>
Caseworker Team
</p>
<?php endif; ?>
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\Messaging\Conversation;

use Dvsa\Olcs\Api\Domain\Command\Email\CreateCorrespondenceRecord;
use Dvsa\Olcs\Api\Domain\Command\Messaging\Conversation\StoreEnhancedSnapshot;
use Dvsa\Olcs\Api\Domain\Command\Messaging\Conversation\StoreSnapshot;
use Dvsa\Olcs\Api\Domain\Command\Result;
use Dvsa\Olcs\Api\Domain\Command\Task\CreateTask;
use Dvsa\Olcs\Api\Domain\CommandHandler\Messaging\Conversation\Close as CloseConversationHandler;
use Dvsa\Olcs\Api\Domain\Exception\Exception;
use Dvsa\Olcs\Api\Domain\Repository;
use Dvsa\Olcs\Api\Entity;
use Dvsa\Olcs\Transfer\Command\Messaging\Conversation\Close as CloseConversationCommand;
Expand All @@ -29,24 +28,46 @@ public function setUp(): void
AuthorizationService::class => m::mock(AuthorizationService::class),
];

$defaultMockTask = m::mock(Entity\Task\Task::class)->makePartial()->allows('getId')->getMock();
$defaultMockConversation = m::mock(Entity\Messaging\MessagingConversation::class)->makePartial()->allows('getTask')->andReturn($defaultMockTask)->getMock()->allows('getRelatedLicence')->getMock();
$this->repoMap[Repository\Conversation::class]->allows('fetchUsingId')->andReturn($defaultMockConversation)->byDefault();
$this->repoMap[Repository\Conversation::class]->allows('save')->byDefault();
$defaultMockTask = m::mock(Entity\Task\Task::class)
->makePartial()
->allows('getId')
->getMock();
$defaultMockConversation = m::mock(Entity\Messaging\MessagingConversation::class)
->makePartial()
->allows('getTask')
->andReturn($defaultMockTask)
->getMock()
->allows('getRelatedLicence')
->getMock();
$this->repoMap[Repository\Conversation::class]
->allows('fetchUsingId')
->andReturn($defaultMockConversation)
->byDefault();
$this->repoMap[Repository\Conversation::class]
->allows('save')
->byDefault();

parent::setUp();

$this->commandHandler->allows('handleCommand')->andReturn(new Result())->byDefault();
$this->commandHandler->allows('handleCommand')
->andReturn(new Result())
->byDefault();
}

public function testHandleMarksConversationAsClosed()
{
$command = CloseConversationCommand::create($commandParameters = ['id' => 1]);

$this->repoMap[Repository\Conversation::class]->expects('save')->with(m::on(function ($conversation) {
$this->assertTrue($conversation->getIsClosed());
return true;
}));
$command = CloseConversationCommand::create(['id' => 1]);

$this->repoMap[Repository\Conversation::class]
->expects('save')
->with(
m::on(
function ($conversation) {
$this->assertTrue($conversation->getIsClosed());
return true;
},
),
);

$this->sut->handleCommand($command);
}
Expand All @@ -62,16 +83,25 @@ public function testHandleMarksTaskAsClosed()

public function testHandleGeneratesAndStoresSnapshot()
{
$command = CloseConversationCommand::create($commandParameters = ['id' => 1]);
$command = CloseConversationCommand::create(['id' => 1]);

$this->expectedSideEffect(StoreSnapshot::class, [], new Result(), 1);

$this->sut->handleCommand($command);
}

public function testHandleGeneratesAndStoresEnhancedSnapshot()
{
$command = CloseConversationCommand::create(['id' => 1]);

$this->expectedSideEffect(StoreEnhancedSnapshot::class, [], new Result(), 1);

$this->sut->handleCommand($command);
}

public function testHandleCreatesCorrespondenceRecord()
{
$command = CloseConversationCommand::create($commandParameters = ['id' => 1]);
$command = CloseConversationCommand::create(['id' => 1]);

$this->expectedSideEffect(CreateCorrespondenceRecord::class, [], new Result(), 1);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\Messaging\Conversation;

use Dvsa\Olcs\Api\Domain\Command\Messaging\Conversation\StoreEnhancedSnapshot as Cmd;
use Dvsa\Olcs\Api\Domain\CommandHandler\Messaging\Conversation\StoreEnhancedSnapshot as Sut;
use Dvsa\Olcs\Api\Domain\Repository\Conversation;
use Dvsa\Olcs\Api\Entity\Messaging\MessagingConversation;
use Dvsa\Olcs\Api\Entity\System\Category;
use Dvsa\Olcs\Api\Entity\System\SubCategory;
use Dvsa\Olcs\Snapshot\Service\Snapshots\Messaging\EnhancedGenerator;
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCreateSnapshotHandlerTest;

class StoreEnhancedSnapshotTest extends AbstractCreateSnapshotHandlerTest
{
protected $cmdClass = Cmd::class;
protected $sutClass = Sut::class;
protected $repoServiceName = Conversation::class;
protected $repoClass = Conversation::class;
protected $entityClass = MessagingConversation::class;
protected $documentCategory = Category::CATEGORY_LICENSING;
protected $documentSubCategory = SubCategory::DOC_SUB_CATEGORY_LICENCING_OTHER_DOCUMENTS;
protected $documentDescription = 'Enhanced Conversation Snapshot';
protected $documentLinkId = 'messagingConversation';
protected $documentLinkValue = 999;
protected $generatorClass = EnhancedGenerator::class;
}
Loading