refactor: service address
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -50,8 +50,6 @@ class DefaultController extends ControllerAbstract {
|
||||
private const ERR_INVALID_TARGETS = 'Invalid parameter: targets must be an array';
|
||||
private const ERR_INVALID_DATA = 'Invalid parameter: data must be an array';
|
||||
|
||||
private const STREAM_FLUSH_INTERVAL = 1;
|
||||
|
||||
public function __construct(
|
||||
private readonly SessionTenant $tenantIdentity,
|
||||
private readonly SessionIdentity $userIdentity,
|
||||
@@ -162,7 +160,7 @@ class DefaultController extends ControllerAbstract {
|
||||
'entity.patch' => $this->entityPatch($tenantId, $userId, $data),
|
||||
'entity.move' => $this->entityMove($tenantId, $userId, $data),
|
||||
'entity.copy' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
|
||||
'entity.transmit' => $this->entityTransmit($tenantId, $userId, $data),
|
||||
'entity.submit' => $this->entitySubmit($tenantId, $userId, $data),
|
||||
'entity.download' => $this->entityDownload($tenantId, $userId, $data),
|
||||
|
||||
default => throw new InvalidArgumentException(self::ERR_INVALID_OPERATION . $operation)
|
||||
@@ -839,29 +837,21 @@ class DefaultController extends ControllerAbstract {
|
||||
return $this->mailManager->entityMove($tenantId, $userId, $target, ...$sources->all());
|
||||
}
|
||||
|
||||
private function entityTransmit(string $tenantId, string $userId, array $data): mixed {
|
||||
if (!isset($data['provider'])) {
|
||||
throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER);
|
||||
private function entitySubmit(string $tenantId, string $userId, array $data): mixed {
|
||||
if (!isset($data['sender'])) {
|
||||
throw new InvalidArgumentException(self::ERR_MISSING_SENDER);
|
||||
}
|
||||
if (!is_string($data['provider'])) {
|
||||
throw new InvalidArgumentException(self::ERR_INVALID_PROVIDER);
|
||||
if (!is_string($data['sender'])) {
|
||||
throw new InvalidArgumentException(self::ERR_INVALID_SENDER);
|
||||
}
|
||||
if (!isset($data['service'])) {
|
||||
throw new InvalidArgumentException(self::ERR_MISSING_SERVICE);
|
||||
}
|
||||
if (!is_string($data['service'])) {
|
||||
throw new InvalidArgumentException(self::ERR_INVALID_SERVICE);
|
||||
}
|
||||
|
||||
$jobId = $this->mailManager->entityTransmit(
|
||||
|
||||
return $this->mailManager->entitySubmit(
|
||||
$tenantId,
|
||||
$userId,
|
||||
$data['provider'],
|
||||
$data['service'],
|
||||
$data['data']
|
||||
$data['sender'],
|
||||
$data['source'] ?? null,
|
||||
$data['message'] ?? null,
|
||||
);
|
||||
|
||||
return ['jobId' => $jobId];
|
||||
}
|
||||
|
||||
private function entityDownload(string $tenantId, string $userId, array $data): mixed {
|
||||
|
||||
+30
-2
@@ -10,6 +10,8 @@ use KTXF\Mail\Collection\CollectionBaseInterface;
|
||||
use KTXF\Mail\Collection\CollectionPropertiesMutableInterface;
|
||||
use KTXF\Mail\Collection\ICollectionBase;
|
||||
use KTXF\Mail\Entity\IMessageBase;
|
||||
use KTXF\Mail\Object\Address;
|
||||
use KTXF\Mail\Object\AddressInterface;
|
||||
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
|
||||
use KTXF\Mail\Provider\ProviderBaseInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
|
||||
@@ -19,11 +21,14 @@ use KTXF\Mail\Service\ServiceBaseInterface;
|
||||
use KTXF\Mail\Service\ServiceCollectionMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceConfigurableInterface;
|
||||
use KTXF\Mail\Service\ServiceEntityMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceEntitySubmitInterface;
|
||||
use KTXF\Mail\Service\ServiceMutableInterface;
|
||||
use KTXF\Mail\Submission\EntitySubmitResult;
|
||||
use KTXF\Resource\BinaryResource;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifierInterface;
|
||||
use KTXF\Resource\Identifier\ResourceIdentifiers;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
@@ -796,7 +801,7 @@ class Manager {
|
||||
}
|
||||
// retrieve entities for each collection
|
||||
foreach ($collectionSelected as $collectionId) {
|
||||
$entities = $service->entityList($collectionId, $entityFilter, $entitySort, $entityRange, null);
|
||||
$entities = $service->entityListBulk($collectionId, $entityFilter, $entitySort, $entityRange, null);
|
||||
// skip collections with no entities
|
||||
if ($entities === []) {
|
||||
continue;
|
||||
@@ -905,7 +910,7 @@ class Manager {
|
||||
// group identifiers by provider/service
|
||||
$groupedIdentifiers = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
$groupedIdentifiers[$identifier->provider()][$identifier->service()][] = $identifier->entity();
|
||||
$groupedIdentifiers[$identifier->provider()][$identifier->service()][] = $identifier;
|
||||
}
|
||||
// retrieve each service and fetch entities
|
||||
$list = [];
|
||||
@@ -1302,4 +1307,27 @@ class Manager {
|
||||
return $operationOutcome;
|
||||
}
|
||||
|
||||
public function entitySubmit(string $tenantId, string $userId, AddressInterface|string $sender, EntityIdentifierInterface|null $source = null, MessagePropertiesMutableInterface|array|null $message = null): EntitySubmitResult {
|
||||
$service = $this->serviceFindByAddress($tenantId, $userId, $sender);
|
||||
if ($service === null || $service->getEnabled() === false) {
|
||||
throw new InvalidArgumentException("Service not found for sender '{$sender}' or service is disabled");
|
||||
}
|
||||
if ($service instanceof ServiceEntitySubmitInterface === false) {
|
||||
throw new InvalidArgumentException("Service '{$service->identifier()}' does not support entity submission");
|
||||
}
|
||||
|
||||
if ($source === null && $message === null) {
|
||||
throw new InvalidArgumentException("At least one of source or message must be provided for entity submission");
|
||||
}
|
||||
|
||||
if ($sender instanceof AddressInterface === false) {
|
||||
$sender = new Address($sender);
|
||||
}
|
||||
if ($message !== null && $message instanceof MessagePropertiesMutableInterface === false) {
|
||||
$message = $service->entityFresh()->getProperties()->jsonDeserialize($message);
|
||||
}
|
||||
|
||||
return $service->entitySubmit($sender, $source, $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user