Skip to content
Snippets Groups Projects
Verified Commit 7412873f authored by Damien's avatar Damien
Browse files

FEAT #14849 TIME 2:15 Alfresco mapping

parent 9926ee5a
No related branches found
No related tags found
No related merge requests found
{ {
"mapping": { "mapping": {
"cm:name": "subject", "document" : {
"cm:title": "subject", "cm:title": "subject",
"cm:description": "alt_identifier" "cm:description": "alt_identifier"
},
"attachment" : {
"cm:name": "title"
}
} }
} }
...@@ -41,6 +41,7 @@ use Resource\controllers\StoreController; ...@@ -41,6 +41,7 @@ use Resource\controllers\StoreController;
use Resource\models\ResModel; use Resource\models\ResModel;
use Resource\models\ResourceContactModel; use Resource\models\ResourceContactModel;
use Respect\Validation\Validator; use Respect\Validation\Validator;
use SrcCore\controllers\LogsController;
use SrcCore\models\CoreConfigModel; use SrcCore\models\CoreConfigModel;
use SrcCore\models\DatabaseModel; use SrcCore\models\DatabaseModel;
use SrcCore\models\ValidatorModel; use SrcCore\models\ValidatorModel;
...@@ -903,6 +904,16 @@ class ActionMethodController ...@@ -903,6 +904,16 @@ class ActionMethodController
$sent = AlfrescoController::sendResource(['resId' => $args['resId'], 'userId' => $GLOBALS['id'], 'folderId' => $args['data']['folderId'], 'folderName' => $args['data']['folderName']]); $sent = AlfrescoController::sendResource(['resId' => $args['resId'], 'userId' => $GLOBALS['id'], 'folderId' => $args['data']['folderId'], 'folderName' => $args['data']['folderName']]);
if (!empty($sent['errors'])) { if (!empty($sent['errors'])) {
LogsController::add([
'isTech' => true,
'moduleId' => 'alfresco',
'level' => 'ERROR',
'tableName' => '',
'recordId' => '',
'eventType' => 'Error Exec Curl : ' . $sent['errors'],
'eventId' => 'Alfresco Error'
]);
return ['errors' => [$sent['errors']]]; return ['errors' => [$sent['errors']]];
} }
......
...@@ -556,8 +556,8 @@ class AlfrescoController ...@@ -556,8 +556,8 @@ class AlfrescoController
$document = ResModel::getById([ $document = ResModel::getById([
'select' => [ 'select' => [
'filename', 'subject', 'alt_identifier', 'external_id', 'type_id', 'priority', 'fingerprint', 'custom_fields', 'filename', 'subject', 'alt_identifier', 'external_id', 'type_id', 'priority', 'fingerprint', 'custom_fields', 'dest_user',
'creation_date', 'modification_date', 'doc_date', 'destination', 'process_limit_date', 'closing_date', 'docserver_id', 'path', 'filename' 'creation_date', 'modification_date', 'doc_date', 'destination', 'initiator', 'process_limit_date', 'closing_date', 'docserver_id', 'path', 'filename'
], ],
'resId' => $args['resId'] 'resId' => $args['resId']
]); ]);
...@@ -618,40 +618,64 @@ class AlfrescoController ...@@ -618,40 +618,64 @@ class AlfrescoController
'cm:description' => $document['alt_identifier'] 'cm:description' => $document['alt_identifier']
]; ];
$alfrescoParameters = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/alfresco.json']); $alfrescoParameters = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/alfresco.json']);
if (!empty($alfrescoParameters['mapping'])) { if (!empty($alfrescoParameters['mapping']['document'])) {
$resourceContacts = ResourceContactModel::get([ $resourceContacts = ResourceContactModel::get([
'where' => ['res_id = ?', 'mode = ?'], 'where' => ['res_id = ?', 'mode = ?'],
'data' => [$args['resId'], 'sender'] 'data' => [$args['resId'], 'sender']
]); ]);
$contactRaw = []; $rawContacts = [];
if ($resourceContacts[0]['type'] == 'contact') { foreach ($resourceContacts as $resourceContact) {
$contactRaw = ContactModel::getById([ if ($resourceContact['type'] == 'contact') {
'select' => ['*'], $rawContacts[] = ContactModel::getById([
'id' => $resourceContacts[0]['item_id'] 'select' => ['*'],
]); 'id' => $resourceContact['item_id']
]);
}
} }
foreach ($alfrescoParameters['mapping'] as $key => $alfrescoParameter) { foreach ($alfrescoParameters['mapping']['document'] as $key => $alfrescoParameter) {
if ($alfrescoParameter == 'alfrescoLogin') { if ($alfrescoParameter == 'alfrescoLogin') {
$properties[$key] = $entityInformations['alfresco']['login']; $properties[$key] = $entityInformations['alfresco']['login'];
} elseif ($alfrescoParameter == 'doctypeLabel') { } elseif ($alfrescoParameter == 'doctypeLabel') {
$doctype = DoctypeModel::getById(['select' => ['description'], 'id' => $document['type_id']]); $doctype = DoctypeModel::getById(['select' => ['description'], 'id' => $document['type_id']]);
$properties[$key] = $doctype['description']; $properties[$key] = $doctype['description'];
} elseif ($alfrescoParameter == 'priorityLabel') { } elseif ($alfrescoParameter == 'priorityLabel') {
$priority = PriorityModel::getById(['select' => ['label'], 'id' => $document['priority']]); if (!empty($document['priority'])) {
$properties[$key] = $priority['label']; $priority = PriorityModel::getById(['select' => ['label'], 'id' => $document['priority']]);
} elseif ($alfrescoParameter == 'senderCompany') { $properties[$key] = $priority['label'];
$properties[$key] = $contactRaw['company']; }
} elseif ($alfrescoParameter == 'senderCivility') { } elseif ($alfrescoParameter == 'destinationLabel') {
$properties[$key] = ContactModel::getCivilityLabel(['civilityId' => $contactRaw['civility']]); if (!empty($document['destination'])) {
} elseif ($alfrescoParameter == 'senderFirstname') { $destination = EntityModel::getByEntityId(['entityId' => $document['destination'], 'select' => ['entity_label']]);
$properties[$key] = $contactRaw['firstname']; $properties[$key] = $destination['entity_label'];
} elseif ($alfrescoParameter == 'senderLastname') { }
$properties[$key] = $contactRaw['lastname']; } elseif ($alfrescoParameter == 'initiatorLabel') {
} elseif ($alfrescoParameter == 'senderFunction') { if (!empty($document['initiator'])) {
$properties[$key] = $contactRaw['function']; $initiator = EntityModel::getByEntityId(['entityId' => $document['initiator'], 'select' => ['entity_label']]);
} elseif ($alfrescoParameter == 'senderAddress') { $properties[$key] = $initiator['entity_label'];
$contactToDisplay = ContactController::getFormattedContactWithAddress(['contact' => $contactRaw]); }
} elseif ($alfrescoParameter == 'destUserLabel') {
if (!empty($document['dest_user'])) {
$properties[$key] = UserModel::getLabelledUserById(['id' => $document['dest_user']]);
}
} elseif (strpos($alfrescoParameter, 'senderCompany_') !== false) {
$contactNb = explode('_', $alfrescoParameter)[1];
$properties[$key] = $rawContacts[$contactNb]['company'];
} elseif (strpos($alfrescoParameter, 'senderCivility_') !== false) {
$contactNb = explode('_', $alfrescoParameter)[1];
$properties[$key] = ContactModel::getCivilityLabel(['civilityId' => $rawContacts[$contactNb]['civility']]);
} elseif (strpos($alfrescoParameter, 'senderFirstname_') !== false) {
$contactNb = explode('_', $alfrescoParameter)[1];
$properties[$key] = $rawContacts[$contactNb]['firstname'];
} elseif (strpos($alfrescoParameter, 'senderLastname_') !== false) {
$contactNb = explode('_', $alfrescoParameter)[1];
$properties[$key] = $rawContacts[$contactNb]['lastname'];
} elseif (strpos($alfrescoParameter, 'senderFunction_') !== false) {
$contactNb = explode('_', $alfrescoParameter)[1];
$properties[$key] = $rawContacts[$contactNb]['function'];
} elseif (strpos($alfrescoParameter, 'senderAddress_') !== false) {
$contactNb = explode('_', $alfrescoParameter)[1];
$contactToDisplay = ContactController::getFormattedContactWithAddress(['contact' => $rawContacts[$contactNb]]);
$properties[$key] = $contactToDisplay['contact']['address']; $properties[$key] = $contactToDisplay['contact']['address'];
} elseif ($alfrescoParameter == 'doctypeSecondLevelLabel') { } elseif ($alfrescoParameter == 'doctypeSecondLevelLabel') {
$doctype = DoctypeModel::getById(['select' => ['doctypes_second_level_id'], 'id' => $document['type_id']]); $doctype = DoctypeModel::getById(['select' => ['doctypes_second_level_id'], 'id' => $document['type_id']]);
...@@ -661,6 +685,9 @@ class AlfrescoController ...@@ -661,6 +685,9 @@ class AlfrescoController
$customId = explode('_', $alfrescoParameter)[1]; $customId = explode('_', $alfrescoParameter)[1];
$customValue = json_decode($document['custom_fields'], true); $customValue = json_decode($document['custom_fields'], true);
$properties[$key] = (!empty($customValue[$customId]) && is_string($customValue[$customId])) ? $customValue[$customId] : ''; $properties[$key] = (!empty($customValue[$customId]) && is_string($customValue[$customId])) ? $customValue[$customId] : '';
} elseif ($alfrescoParameter == 'currentDate') {
$date = new \DateTime();
$properties[$key] = $date->format('d-m-Y H:i');
} else { } else {
$properties[$key] = $document[$alfrescoParameter]; $properties[$key] = $document[$alfrescoParameter];
} }
...@@ -686,7 +713,7 @@ class AlfrescoController ...@@ -686,7 +713,7 @@ class AlfrescoController
ResModel::update(['set' => ['external_id' => json_encode($externalId)], 'where' => ['res_id = ?'], 'data' => [$args['resId']]]); ResModel::update(['set' => ['external_id' => json_encode($externalId)], 'where' => ['res_id = ?'], 'data' => [$args['resId']]]);
$attachments = AttachmentModel::get([ $attachments = AttachmentModel::get([
'select' => ['res_id', 'title', 'identifier', 'external_id', 'docserver_id', 'path', 'filename', 'format'], 'select' => ['res_id', 'title', 'identifier', 'external_id', 'docserver_id', 'path', 'filename', 'format', 'attachment_type'],
'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status not in (?)'], 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status not in (?)'],
'data' => [$args['resId'], ['signed_response'], ['DEL', 'OBS']] 'data' => [$args['resId'], ['signed_response'], ['DEL', 'OBS']]
]); ]);
...@@ -756,10 +783,17 @@ class AlfrescoController ...@@ -756,10 +783,17 @@ class AlfrescoController
$attachmentId = $curlResponse['response']['entry']['id']; $attachmentId = $curlResponse['response']['entry']['id'];
$properties = [
'cm:description' => $attachment['identifier']
];
if (!empty($alfrescoParameters['mapping']['attachment'])) {
foreach ($alfrescoParameters['mapping']['attachment'] as $key => $alfrescoParameter) {
$properties[$key] = $attachment[$alfrescoParameter];
}
}
$body = [ $body = [
'properties' => [ 'properties' => $properties,
'cm:description' => $attachment['identifier'],
],
]; ];
$curlResponse = CurlModel::execSimple([ $curlResponse = CurlModel::execSimple([
'url' => "{$alfrescoUri}/alfresco/versions/1/nodes/{$attachmentId}", 'url' => "{$alfrescoUri}/alfresco/versions/1/nodes/{$attachmentId}",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment