Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pastell Connecteur SAE Maarch RM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
Pastell Connecteur SAE Maarch RM
Commits
5dfca641
Commit
5dfca641
authored
4 years ago
by
Arnaud Pauget
Browse files
Options
Downloads
Patches
Plain Diff
feat () : add files about Maarch RM Rest Client
parent
dc88bd3d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#8282
failed
4 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
MaarchREST.class.php
+238
-0
238 additions, 0 deletions
MaarchREST.class.php
action/MaarchRestVersion.class.php
+12
-0
12 additions, 0 deletions
action/MaarchRestVersion.class.php
entite-properties.yml
+19
-0
19 additions, 0 deletions
entite-properties.yml
with
269 additions
and
0 deletions
MaarchREST.class.php
0 → 100644
+
238
−
0
View file @
5dfca641
<?php
class
MaarchREST
extends
SAEConnecteur
{
private
$curlWrapperFactory
;
private
$url
;
private
$token
;
/** @var DonneesFormulaire */
private
$connecteur_config
;
public
function
__construct
(
CurlWrapperFactory
$curlWrapperFactory
,
\Monolog\Logger
$logger
){
$this
->
curlWrapperFactory
=
$curlWrapperFactory
;
}
public
function
setConnecteurConfig
(
DonneesFormulaire
$donneesFormulaire
)
{
$this
->
url
=
$donneesFormulaire
->
get
(
'url'
);
$this
->
token
=
$donneesFormulaire
->
get
(
'token'
);
$this
->
connecteur_config
=
$donneesFormulaire
;
}
/**
* @param $bordereauSEDA
* @param $archivePath
* @param string $file_type
* @param string $archive_file_name
* @return bool
* @throws Exception
*/
public
function
sendArchive
(
$bordereauSEDA
,
$archivePath
,
$file_type
=
"TARGZ"
,
$archive_file_name
=
"archive.tar.gz"
)
{
$tmpFile
=
new
TmpFile
();
$bordereau_file
=
$tmpFile
->
create
();
file_put_contents
(
$bordereau_file
,
$bordereauSEDA
);
try
{
$this
->
callSedaMessage
(
$bordereau_file
,
$archivePath
);
}
catch
(
Exception
$e
){
$tmpFile
->
delete
(
$bordereau_file
);
throw
$e
;
}
$tmpFile
->
delete
(
$bordereau_file
);
return
true
;
}
/**
* @param $seda_message_path
* @param $attachments_path
* @return bool|mixed
* @throws Exception
*/
public
function
callSedaMessage
(
$seda_message_path
,
$attachments_path
){
$curlWrapper
=
$this
->
curlWrapperFactory
->
getInstance
();
$bodyPackage
=
$this
->
createObjectPackage
(
$seda_message_path
,
$attachments_path
);
$curlWrapper
->
setJsonPostData
(
$bodyPackage
);
return
$this
->
getWS
(
'/medona/archiveTransfer'
,
"application/json"
,
$curlWrapper
);
}
public
function
createObjectPackage
(
$seda_message_path
,
$attachments_path
)
{
$tmpFolder
=
dirname
(
$attachments_path
);
mkdir
(
$tmpFolder
.
"/tmpFiles"
);
try
{
$phar
=
new
PharData
(
$attachments_path
);
$phar
->
extractTo
(
$tmpFolder
.
"/tmpFiles"
,
null
,
true
);
}
catch
(
Exception
$e
)
{
return
(
$e
);
}
$bodyPackage
=
[];
$bodyPackage
[
'messageFile'
]
=
base64_encode
(
file_get_contents
(
$seda_message_path
));
$bodyPackage
[
'format'
]
=
"seda"
;
$bodyPackage
[
'attachments'
]
=
[];
foreach
(
scandir
(
$tmpFolder
.
"/tmpFiles"
)
as
$filename
)
{
if
(
$filename
!=
".."
&&
$filename
!=
"."
)
{
$attachment
=
new
stdClass
();
$attachment
->
filename
=
$filename
;
$attachment
->
data
=
base64_encode
(
file_get_contents
(
$tmpFolder
.
"/tmpFiles/"
.
$filename
));
unlink
(
$tmpFolder
.
"/tmpFiles/"
.
$filename
);
array_push
(
$bodyPackage
[
'attachments'
],
$attachment
);
}
}
rmdir
(
$tmpFolder
.
"/tmpFiles"
);
return
$bodyPackage
;
}
public
function
getErrorString
(
$number
){
return
"Erreur non identifié"
;
}
/**
* @param $id_transfert
* @return string Le contenu du fichier XML contenant l'accusé de reception
* @throws Exception
*/
public
function
getAcuseReception
(
$id_transfert
)
{
if
(
!
$id_transfert
){
throw
new
UnrecoverableException
(
"L'identifiant du transfert n'a pas été trouvé"
);
}
$messageInformations
=
$this
->
getWS
(
"/medona/message/reference?reference="
.
urlencode
(
$id_transfert
.
"_Ack"
),
"application/json"
);
if
(
$messageInformations
)
{
$zipMessage
=
$this
->
getWS
(
"/medona/message/"
.
$messageInformations
[
'messageId'
]
.
"/Export"
,
"application/zip"
);
}
else
{
throw
new
UnrecoverableException
(
"Le paquet du bordereau identifié par "
.
$messageInformations
[
'messageId'
]
.
" n'a pas pu êtr récuperé."
);
}
$tmpFile
=
new
TmpFile
();
$zipTempFile
=
$tmpFile
->
create
();
file_put_contents
(
$zipTempFile
,
$zipMessage
);
// get the absolute path to $file
$path
=
pathinfo
(
realpath
(
$zipTempFile
),
PATHINFO_DIRNAME
);
try
{
shell_exec
(
"7z x
$zipTempFile
-o
$path
*.xml"
);
}
catch
(
Exception
$e
)
{
return
(
$e
);
}
$fullFilePath
=
$path
.
"/"
.
$messageInformations
[
'messageId'
]
.
".xml"
;
if
(
!
file_exists
(
$fullFilePath
))
{
return
"Problème lors de la lecture du fichier
$fullFilePath
."
;
}
$xmlContent
=
file_get_contents
(
$fullFilePath
);
unlink
(
$zipTempFile
);
unlink
(
$fullFilePath
);
return
$xmlContent
;
}
/**
* @param $id_transfert
* @return bool|mixed
* @throws Exception
*/
public
function
getReply
(
$id_transfert
)
{
if
(
!
$id_transfert
){
throw
new
UnrecoverableException
(
"L'identifiant du transfert n'a pas été trouvé"
);
}
$messageInformations
=
$this
->
getWS
(
"/medona/message/reference?reference="
.
urlencode
(
$id_transfert
),
"application/json"
);
if
(
$messageInformations
[
'status'
]
!=
"processed"
)
{
return
"Le bordereau dont la référence est
$id_transfert
n'a pas encore été traité dans le SAE Maarch RM."
;
}
return
$messageInformations
;
}
public
function
getURL
(
$cote
)
{
if
(
empty
(
$this
->
url
)){
return
$cote
;
}
$tab
=
parse_url
(
$this
->
url
);
return
"
{
$tab
[
'scheme'
]
}
://
{
$tab
[
'host'
]
}
/archives/viewByArchiveIdentifier/
$cote
"
;
}
/**
* @param $url
* @param string $accept
* @return bool|mixed
* @throws Exception
*/
private
function
getWS
(
$url
,
$accept
=
"application/json"
,
CurlWrapper
$curlWrapper
=
null
){
if
(
!
$curlWrapper
){
$curlWrapper
=
$this
->
curlWrapperFactory
->
getInstance
();
}
$curlWrapper
->
addHeader
(
"Accept"
,
$accept
);
$curlWrapper
->
addHeader
(
"Cookie"
,
"LAABS-AUTH="
.
$this
->
token
);
$curlWrapper
->
addHeader
(
"User-Agent"
,
"service"
);
$curlWrapper
->
dontVerifySSLCACert
();
$result
=
$curlWrapper
->
get
(
$this
->
url
.
$url
);
if
(
!
$result
){
throw
new
Exception
(
$curlWrapper
->
getLastError
());
}
$http_code
=
$curlWrapper
->
getHTTPCode
();
if
(
$http_code
!=
200
){
throw
new
Exception
(
"
$result
- code d'erreur HTTP :
$http_code
"
);
}
$old_result
=
$result
;
if
(
$accept
==
"application/json"
){
$result
=
json_decode
(
$result
,
true
);
}
if
(
!
$result
){
throw
new
Exception
(
"Le serveur Maarch n'a pas renvoyé une réponse compréhensible - problème de configuration ? :
$old_result
"
);
}
return
$result
;
}
/**
* @return bool|mixed
* @throws Exception
*/
public
function
getVersion
(){
return
$this
->
getWS
(
'/versions'
);
}
/**
* @return bool|mixed
* @throws Exception
*/
public
function
ping
(){
return
$this
->
getWS
(
'/ping'
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
action/MaarchRestVersion.class.php
0 → 100644
+
12
−
0
View file @
5dfca641
<?php
class
MaarchRestVersion
extends
ActionExecutor
{
public
function
go
(){
/** @var AsalaeREST $asalae */
$maarchSae
=
$this
->
getMyConnecteur
();
$message
=
$maarchSae
->
getVersion
();
$this
->
setLastMessage
(
"Connexion réussie: "
.
json_encode
(
$message
));
return
true
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
entite-properties.yml
0 → 100644
+
19
−
0
View file @
5dfca641
nom
:
Maarch Rest
type
:
SAE
description
:
Connecteur pour le SAE Maarch RM
formulaire
:
page0
:
url
:
name
:
"
URL
de
l'instance
Maarch
RM"
token
:
name
:
Jeton URL Encodé du comtpe de service
originating_agency
:
name
:
Identifiant service versant
action
:
version
:
name
:
Tester la connexion (authentification)
action-class
:
MaarchRestVersion
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment