88
99namespace OCA \Libresign \Service ;
1010
11+ use OCA \Libresign \AppInfo \Application ;
1112use OCA \Libresign \Db \File as FileEntity ;
1213use OCA \Libresign \Db \FileElementMapper ;
1314use OCA \Libresign \Db \FileMapper ;
1415use OCA \Libresign \Db \IdentifyMethodMapper ;
1516use OCA \Libresign \Db \SignRequest as SignRequestEntity ;
1617use OCA \Libresign \Db \SignRequestMapper ;
18+ use OCA \Libresign \Enum \SignatureFlow ;
1719use OCA \Libresign \Handler \DocMdpHandler ;
1820use OCA \Libresign \Helper \ValidateHelper ;
1921use OCA \Libresign \Service \IdentifyMethod \IIdentifyMethod ;
2022use OCP \AppFramework \Db \DoesNotExistException ;
2123use OCP \Files \IMimeTypeDetector ;
2224use OCP \Files \Node ;
2325use OCP \Http \Client \IClientService ;
26+ use OCP \IAppConfig ;
2427use OCP \IL10N ;
2528use OCP \IUser ;
2629use OCP \IUserManager ;
@@ -47,6 +50,7 @@ public function __construct(
4750 protected DocMdpHandler $ docMdpHandler ,
4851 protected LoggerInterface $ logger ,
4952 protected SequentialSigningService $ sequentialSigningService ,
53+ protected IAppConfig $ appConfig ,
5054 ) {
5155 }
5256
@@ -56,6 +60,7 @@ public function save(array $data): FileEntity {
5660 if (!isset ($ data ['status ' ])) {
5761 $ data ['status ' ] = $ file ->getStatus ();
5862 }
63+ $ this ->sequentialSigningService ->setFile ($ file );
5964 $ this ->associateToSigners ($ data , $ file ->getId ());
6065 return $ file ;
6166 }
@@ -106,10 +111,28 @@ public function saveFile(array $data): FileEntity {
106111 } else {
107112 $ file ->setStatus (FileEntity::STATUS_ABLE_TO_SIGN );
108113 }
114+
115+ if (isset ($ data ['signatureFlow ' ]) && is_string ($ data ['signatureFlow ' ])) {
116+ try {
117+ $ signatureFlow = \OCA \Libresign \Enum \SignatureFlow::from ($ data ['signatureFlow ' ]);
118+ $ file ->setSignatureFlowEnum ($ signatureFlow );
119+ } catch (\ValueError ) {
120+ $ this ->setSignatureFlowFromGlobalConfig ($ file );
121+ }
122+ } else {
123+ $ this ->setSignatureFlowFromGlobalConfig ($ file );
124+ }
125+
109126 $ this ->fileMapper ->insert ($ file );
110127 return $ file ;
111128 }
112129
130+ private function setSignatureFlowFromGlobalConfig (FileEntity $ file ): void {
131+ $ globalFlowValue = $ this ->appConfig ->getValueString (Application::APP_ID , 'signature_flow ' , SignatureFlow::PARALLEL ->value );
132+ $ globalFlow = SignatureFlow::from ($ globalFlowValue );
133+ $ file ->setSignatureFlowEnum ($ globalFlow );
134+ }
135+
113136 private function updateStatus (FileEntity $ file , int $ status ): FileEntity {
114137 if ($ status > $ file ->getStatus ()) {
115138 $ file ->setStatus ($ status );
0 commit comments