Skip to content
Snippets Groups Projects
Commit fab83ad7 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #20284 TIME 2:00 moved route function on top + moved document check in...

FEAT #20284 TIME 2:00 moved route function on top + moved document check in fast return route + simplified xml procedure creation
parent 7834dfe9
No related branches found
No related tags found
No related merge requests found
......@@ -35,90 +35,7 @@ class FastOTPController
{
const OTP_ERROR = 'FastOTP procedure creation failed : ';
public static function createProcedure(array $args)
{
ValidatorModel::notEmpty($args, ['documentId', 'encodedDocument', 'name', 'workflowId']);
ValidatorModel::stringType($args, ['encodedDocument', 'name', 'description']);
ValidatorModel::intVal($args, ['documentId', 'workflowId']);
$workflowExternalInformations = WorkflowExternalInformationModel::getByWorkflowId(['select' => ['*'], 'workflowId' => $args['workflowId']]);
if (empty($workflowExternalInformations)) {
return ['errors' => 'No external informations found'];
}
$workflowExternalInformations['informations'] = json_decode($workflowExternalInformations['informations'], true);
$externalSB = ExternalSignatoryBookModel::getById(['select' => ['*'], 'id' => $workflowExternalInformations['external_signatory_book_id']]);
if (empty($externalSB)) {
return ['errors' => 'No external signatory book configuration found'];
} elseif ($externalSB['type'] !== 'fast') {
return ['errors' => 'External signatory book configuration is invalid'];
}
$externalSB['connection_data'] = json_decode($externalSB['connection_data'], true);
$check = FastOTPController::controlConnectionDataConfig(['connection_data' => $externalSB['connection_data']]);
if (!empty($check['errors'])) {
return ['errors' => $check['errors']];
}
$otpXml = FastOTPController::generateOtpXml([
'prettyPrint' => true,
'filename' => 'METAS_API.xml',
'otpInfo' => [
'OTP_firstname_0' => $workflowExternalInformations['firstname'],
'OTP_lastname_0' => $workflowExternalInformations['lastname'],
'OTP_phonenumber_0' => $workflowExternalInformations['phone'],
'OTP_email_0' => $workflowExternalInformations['email']
]
]);
if (!empty($otpXml['errors'])) {
return ['errors' => $otpXml['errors']];
}
$today = new \DateTimeImmutable();
$token = FastOTPController::generateToken([
'payload' => [
'documentId' => $args['documentId'],
'workflowId' => $args['workflowId']
]
]);
$multipartBody = [
'document' => [
'isFile' => true,
'filename' => "{$args['name']}_{$today->format('d-m-Y_H-i-s')}.pdf",
'content' => base64_decode($args['encodedDocument'])
],
'meta' => [
'isFile' => true,
'filename' => $otpXml['filename'],
'content' => $otpXml['content']
],
'referrer' => ConfigurationModel::getApplicationUrl() . "dist/#/externalSignatoryBookReturn/token/{$token}"
];
$response = FastOTPController::uploadOTP([
'connection_data' => $externalSB['connection_data'],
'multipartBody' => $multipartBody
]);
if (!empty($response['errors'])) {
FastOTPController::updateErrorInfo([
'workflowId' => $args['workflowId'],
'informations' => ['errors' => $response['errors']]
]);
return ['errors' => $response['errors']];
}
$workflowExternalInformations['informations']['token'] = $token;
$workflowExternalInformations['informations']['fastDocId'] = $response['response']['id'];
$workflowExternalInformations['informations']['fastUrl'] = $response['response']['url'];
$informations = json_encode($workflowExternalInformations['informations']);
WorkflowExternalInformationModel::update(['set' => ['informations' => $informations], 'where' => ['workflow_id = ?'], 'data' => [$args['workflowId']]]);
return true;
}
public function getReturnFast(Request $request, Response $response)
public function getReturnFast(Request $request, Response $response): Response
{
$queryParams = $request->getQueryParams();
......@@ -130,6 +47,11 @@ class FastOTPController
$workflowId = $checkToken['workflowId'];
$fastStatus = $queryParams['status'] ?? null;
$document = DocumentModel::getById(['select' => ['id', 'title', 'reference'], 'id' => $documentId]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
$workflow = WorkflowModel::get([
'select' => ['status'],
'where' => ['main_document_id = ?', 'id = ?'],
......@@ -138,7 +60,7 @@ class FastOTPController
if (empty($workflow[0])) {
return $response->withStatus(403)->withJson(['errors' => 'Workflow does not exist']);
} elseif (!empty($workflow[0]['status']) && $workflow[0]['status'] == 'STOP') {
return $response->withStatus(403)->withJson(['errors' => 'Workflow is interrupted']);
return $response->withStatus(403)->withJson(['errors' => 'Workflow is interrupted', 'lang' => 'workflowInterrupted']);
}
$workflowExternalInformations = WorkflowExternalInformationModel::getByWorkflowId(['select' => ['informations', 'external_signatory_book_id'], 'workflowId' => $workflowId]);
......@@ -159,12 +81,11 @@ class FastOTPController
}
$externalSB['connection_data'] = json_decode($externalSB['connection_data'], true);
$comments = null;
if (!empty($fastStatus) && $fastStatus == 'SIGNED') {
$fileResponse = FastOTPController::download([
'connection_data' => $externalSB['connection_data'],
'connection_data' => $externalSB['connection_data'],
'documentId' => $informations['fastDocId']
]);
if (!empty($fileResponse['errors'])) {
......@@ -269,11 +190,6 @@ class FastOTPController
'note' => $comments ?? null
]);
$document = DocumentModel::getById(['select' => ['id', 'title', 'reference'], 'id' => $documentId]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
return $response->withJson([
'docId' => $document['id'],
'docObjet' => $document['title'],
......@@ -281,6 +197,88 @@ class FastOTPController
]);
}
public static function createProcedure(array $args)
{
ValidatorModel::notEmpty($args, ['documentId', 'encodedDocument', 'name', 'workflowId']);
ValidatorModel::stringType($args, ['encodedDocument', 'name', 'description']);
ValidatorModel::intVal($args, ['documentId', 'workflowId']);
$workflowExternalInformations = WorkflowExternalInformationModel::getByWorkflowId(['select' => ['*'], 'workflowId' => $args['workflowId']]);
if (empty($workflowExternalInformations)) {
return ['errors' => 'No external informations found'];
}
$workflowExternalInformations['informations'] = json_decode($workflowExternalInformations['informations'], true);
$externalSB = ExternalSignatoryBookModel::getById(['select' => ['*'], 'id' => $workflowExternalInformations['external_signatory_book_id']]);
if (empty($externalSB)) {
return ['errors' => 'No external signatory book configuration found'];
} elseif ($externalSB['type'] !== 'fast') {
return ['errors' => 'External signatory book configuration is invalid'];
}
$externalSB['connection_data'] = json_decode($externalSB['connection_data'], true);
$check = FastOTPController::controlConnectionDataConfig(['connection_data' => $externalSB['connection_data']]);
if (!empty($check['errors'])) {
return ['errors' => $check['errors']];
}
$otpXml = FastOTPController::generateOtpXml([
'prettyPrint' => true,
'otpInfo' => [
'OTP_firstname_0' => $workflowExternalInformations['firstname'],
'OTP_lastname_0' => $workflowExternalInformations['lastname'],
'OTP_phonenumber_0' => $workflowExternalInformations['phone'],
'OTP_email_0' => $workflowExternalInformations['email']
]
]);
if (!empty($otpXml['errors'])) {
return ['errors' => $otpXml['errors']];
}
$today = new \DateTimeImmutable();
$token = FastOTPController::generateToken([
'payload' => [
'documentId' => $args['documentId'],
'workflowId' => $args['workflowId']
]
]);
$multipartBody = [
'document' => [
'isFile' => true,
'filename' => "{$args['name']}_{$today->format('d-m-Y_H-i-s')}.pdf",
'content' => base64_decode($args['encodedDocument'])
],
'meta' => [
'isFile' => true,
'filename' => 'METAS_API.xml',
'content' => $otpXml['content']
],
'referrer' => ConfigurationModel::getApplicationUrl() . "dist/#/externalSignatoryBookReturn/token/{$token}"
];
$response = FastOTPController::uploadOTP([
'connection_data' => $externalSB['connection_data'],
'multipartBody' => $multipartBody
]);
if (!empty($response['errors'])) {
FastOTPController::updateErrorInfo([
'workflowId' => $args['workflowId'],
'informations' => ['errors' => $response['errors']]
]);
return ['errors' => $response['errors']];
}
$workflowExternalInformations['informations']['token'] = $token;
$workflowExternalInformations['informations']['fastDocId'] = $response['response']['id'];
$workflowExternalInformations['informations']['fastUrl'] = $response['response']['url'];
$informations = json_encode($workflowExternalInformations['informations']);
WorkflowExternalInformationModel::update(['set' => ['informations' => $informations], 'where' => ['workflow_id = ?'], 'data' => [$args['workflowId']]]);
return true;
}
public static function deleteProcedureByWorkflowId(array $args)
{
ValidatorModel::notEmpty($args, ['workflowId']);
......@@ -355,6 +353,7 @@ class FastOTPController
{
ValidatorModel::notEmpty($args, ['connection_data', 'multipartBody']);
ValidatorModel::arrayType($args, ['connection_data', 'multipartBody']);
$curlReturn = CurlModel::exec([
'method' => 'POST',
'url' => $args['connection_data']['apiUri'] . "/documents/v2/otp/{$args['connection_data']['subscriberId']}/signature-otp/upload",
......@@ -378,13 +377,9 @@ class FastOTPController
public static function generateOtpXml(array $args)
{
ValidatorModel::notEmpty($args, ['filename', 'otpInfo']);
ValidatorModel::stringType($args, ['filename']);
ValidatorModel::notEmpty($args, ['otpInfo']);
ValidatorModel::arrayType($args, ['otpInfo']);
if (!in_array($args['filename'], ['METAS_API.xml', 'METAS_Webdav.xml'])) {
return ['errors' => FastOTPController::OTP_ERROR . "The OTP xml filename '{$args['filename']}' is not in correct. The following filenames are accepted : 'METAS_API.xml', 'METAS_Webdav.xml'."];
}
ValidatorModel::boolType($args, ['prettyPrint']);
$otpInfoXML = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <meta-data-list></meta-data-list>');
foreach ($args['otpInfo'] as $name => $value) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment