@topconsultnpm/sdkui-react 6.21.0-t3 → 6.21.0-t4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/NewComponents/ContextMenu/TMContextMenu.js +23 -18
- package/lib/components/base/TMPopUp.js +3 -3
- package/lib/components/base/TMTreeView.d.ts +16 -13
- package/lib/components/base/TMTreeView.js +230 -64
- package/lib/components/choosers/TMDistinctValues.js +1 -1
- package/lib/components/editors/TMTextBox.d.ts +1 -0
- package/lib/components/editors/TMTextBox.js +2 -1
- package/lib/components/features/documents/TMDcmtForm.d.ts +2 -0
- package/lib/components/features/documents/TMDcmtForm.js +2 -1
- package/lib/components/features/documents/TMDcmtIcon.d.ts +3 -1
- package/lib/components/features/documents/TMDcmtIcon.js +5 -32
- package/lib/components/features/documents/TMFileUploader.js +1 -1
- package/lib/components/features/documents/TMMasterDetailDcmts.d.ts +2 -0
- package/lib/components/features/documents/TMMasterDetailDcmts.js +54 -14
- package/lib/components/features/documents/TMMergeToPdfForm.d.ts +2 -1
- package/lib/components/features/documents/TMMergeToPdfForm.js +91 -48
- package/lib/components/features/documents/TMRelationViewer.d.ts +12 -10
- package/lib/components/features/documents/TMRelationViewer.js +401 -96
- package/lib/components/features/documents/copyAndMergeDcmtsShared.d.ts +4 -3
- package/lib/components/features/documents/copyAndMergeDcmtsShared.js +47 -23
- package/lib/components/features/documents/mergePdfUtils.d.ts +52 -0
- package/lib/components/features/documents/mergePdfUtils.js +268 -0
- package/lib/components/features/search/TMSearch.d.ts +2 -0
- package/lib/components/features/search/TMSearch.js +2 -2
- package/lib/components/features/search/TMSearchResult.d.ts +2 -0
- package/lib/components/features/search/TMSearchResult.js +58 -9
- package/lib/components/viewers/TMTidViewer.js +14 -2
- package/lib/helper/Enum_Localizator.js +1 -0
- package/lib/helper/SDKUI_Globals.d.ts +1 -0
- package/lib/helper/SDKUI_Globals.js +1 -0
- package/lib/helper/SDKUI_Localizator.d.ts +34 -0
- package/lib/helper/SDKUI_Localizator.js +352 -12
- package/lib/helper/TMUtils.d.ts +33 -1
- package/lib/helper/TMUtils.js +104 -1
- package/lib/helper/certificateImportHelper.d.ts +43 -0
- package/lib/helper/certificateImportHelper.js +403 -0
- package/lib/helper/helpers.js +9 -0
- package/lib/helper/index.d.ts +1 -0
- package/lib/helper/index.js +1 -0
- package/lib/hooks/useDcmtOperations.d.ts +2 -1
- package/lib/hooks/useDcmtOperations.js +10 -2
- package/lib/hooks/useDocumentOperations.d.ts +2 -0
- package/lib/hooks/useDocumentOperations.js +28 -6
- package/lib/services/platform_services.d.ts +1 -1
- package/lib/ts/types.d.ts +2 -1
- package/lib/ts/types.js +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ResultTypes } from '@topconsultnpm/sdk-ts';
|
|
2
|
+
import { DcmtInfo } from '../ts';
|
|
3
|
+
export declare const S4T_USER_REGISTRY_MASTER: string;
|
|
4
|
+
export declare const S4T_CERTIFICATE_REGISTRY_DETAIL: string;
|
|
5
|
+
export interface IntesiCertificateData {
|
|
6
|
+
cid?: number;
|
|
7
|
+
alias?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
description?: any;
|
|
10
|
+
domain?: string;
|
|
11
|
+
providerName?: string;
|
|
12
|
+
providerDescription?: string;
|
|
13
|
+
loginAuth?: number;
|
|
14
|
+
creationDate?: any;
|
|
15
|
+
validFrom?: any;
|
|
16
|
+
validTo?: any;
|
|
17
|
+
certificateStatus?: any;
|
|
18
|
+
revokeDate?: any;
|
|
19
|
+
}
|
|
20
|
+
interface ImportResultInfo {
|
|
21
|
+
rowIndex: number;
|
|
22
|
+
id1: number;
|
|
23
|
+
id2: number;
|
|
24
|
+
resultType: typeof ResultTypes[keyof typeof ResultTypes];
|
|
25
|
+
description?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Importa i certificati remoti per il documento corrente.
|
|
29
|
+
* Verifica se esistono già certificati nel sistema e li aggiorna o crea nuovi.
|
|
30
|
+
* Aggiorna il documento master con i metadati di elaborazione.
|
|
31
|
+
*
|
|
32
|
+
* @returns Array di ImportResultInfo con eventuali warning, o undefined se tutto ok
|
|
33
|
+
*/
|
|
34
|
+
export declare const importCertificatesAsync: (inputDcmt: DcmtInfo, rowIndex: number, fetchRemoteCertificates: ((email: string) => Promise<Array<IntesiCertificateData>>) | undefined, abortSignal?: AbortSignal) => Promise<ImportResultInfo[] | undefined>;
|
|
35
|
+
export declare const archiveUserRegistryDocument: (abortSignal: AbortSignal, params: {
|
|
36
|
+
email: string;
|
|
37
|
+
fiscalCode: string;
|
|
38
|
+
phoneNumber: string;
|
|
39
|
+
name: string;
|
|
40
|
+
surname: string;
|
|
41
|
+
type: string;
|
|
42
|
+
}) => Promise<void>;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { MetadataDataTypes, DcmtTypeListCacheService, SDK_Globals, QueryDescriptor, FromItem, SelectItem, SystemMIDsAsNumber, WhereItem, QueryOperators, ArchiveEngineByID, ResultTypes, DataListCacheService } from '@topconsultnpm/sdk-ts';
|
|
2
|
+
import { SDKUI_Localizator } from './SDKUI_Localizator';
|
|
3
|
+
// Costanti DTD usate nell'importazione certificati
|
|
4
|
+
export const S4T_USER_REGISTRY_MASTER = 'S4T_UserRegistry'.toLowerCase();
|
|
5
|
+
export const S4T_CERTIFICATE_REGISTRY_DETAIL = 'S4T_CertificateRegistry'.toLowerCase();
|
|
6
|
+
/**
|
|
7
|
+
* Formatta il valore di LoginAuth con la descrizione testuale
|
|
8
|
+
* 0 = PIN senza OTP, 2 = PIN con OTP, 4 = Implicit PIN con OTP, 5 = Implicit PIN senza OTP
|
|
9
|
+
*/
|
|
10
|
+
const formatLoginAuth = (value) => {
|
|
11
|
+
if (value === undefined || value === null)
|
|
12
|
+
return undefined;
|
|
13
|
+
switch (value) {
|
|
14
|
+
case 0: return SDKUI_Localizator.LoginAuth_PINWithoutOTP;
|
|
15
|
+
case 2: return SDKUI_Localizator.LoginAuth_PINWithOTP;
|
|
16
|
+
case 4: return SDKUI_Localizator.LoginAuth_ImplicitPINWithOTP;
|
|
17
|
+
case 5: return SDKUI_Localizator.LoginAuth_ImplicitPINWithoutOTP;
|
|
18
|
+
default: return `${SDKUI_Localizator.LoginAuth_Unknown} (${value})`;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Mapping tra nome metadato (lowercase) e proprietà di IntesiCertificateData
|
|
23
|
+
*/
|
|
24
|
+
const getCredentialValue = (cert, fieldName) => {
|
|
25
|
+
switch (fieldName) {
|
|
26
|
+
case 'ig_cid': return cert.cid;
|
|
27
|
+
case 'ig_alias': return cert.alias;
|
|
28
|
+
case 'ig_label': return cert.label;
|
|
29
|
+
case 'ig_description': return cert.description;
|
|
30
|
+
case 'ig_domain': return cert.domain;
|
|
31
|
+
case 'ig_providername': return cert.providerName;
|
|
32
|
+
case 'ig_providerdescription': return cert.providerDescription;
|
|
33
|
+
case 'ig_loginauth': return formatLoginAuth(cert.loginAuth);
|
|
34
|
+
case 'ig_creationdate': return cert.creationDate;
|
|
35
|
+
case 'ig_validfrom': return cert.validFrom;
|
|
36
|
+
case 'ig_validto': return cert.validTo;
|
|
37
|
+
case 'ig_certificatestatus': return cert.certificateStatus;
|
|
38
|
+
case 'ig_revokedate': return cert.revokeDate;
|
|
39
|
+
default: return undefined;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Popola i metadati dell'engine (Archive o Update) dal certificato
|
|
44
|
+
*/
|
|
45
|
+
const setEngineMetadataFromCertificate = (engine, metadata, cert, email) => {
|
|
46
|
+
for (const md of metadata) {
|
|
47
|
+
const mdNameLower = md.name?.toLowerCase();
|
|
48
|
+
const value = getCredentialValue(cert, mdNameLower ?? '');
|
|
49
|
+
if (value !== undefined && value !== null) {
|
|
50
|
+
switch (md.dataType) {
|
|
51
|
+
case MetadataDataTypes.DateTime:
|
|
52
|
+
// I valori arrivano sempre come timestamp in millisecondi
|
|
53
|
+
engine.Metadata_AddDateTime(md.id, new Date(value));
|
|
54
|
+
break;
|
|
55
|
+
case MetadataDataTypes.Number:
|
|
56
|
+
engine.Metadata_AddNumber(md.id, typeof value === 'number' ? value : parseFloat(value));
|
|
57
|
+
break;
|
|
58
|
+
case MetadataDataTypes.Varchar:
|
|
59
|
+
default:
|
|
60
|
+
engine.Metadata_AddString(md.id, String(value));
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Aggiungi il riferimento all'email del documento principale (email) se specificato
|
|
66
|
+
if (email !== undefined) {
|
|
67
|
+
const emailMetadata = metadata.find(md => md.name?.toLowerCase() === 'email');
|
|
68
|
+
if (emailMetadata) {
|
|
69
|
+
engine.Metadata_AddString(emailMetadata.id, email);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Recupera il contesto necessario per l'importazione certificati.
|
|
75
|
+
* Legge i metadati freschi dal backend per ottenere l'email corrente.
|
|
76
|
+
*/
|
|
77
|
+
const getCertificateImportContext = async (dcmtInfo) => {
|
|
78
|
+
const dtdMaster = await DcmtTypeListCacheService.GetAsync(dcmtInfo.TID);
|
|
79
|
+
const emailDescriptor = dtdMaster?.metadata?.find(md => md.name?.toLowerCase() === 'email');
|
|
80
|
+
// Legge i metadati freschi dal backend per ottenere l'email aggiornata
|
|
81
|
+
let email;
|
|
82
|
+
if (emailDescriptor) {
|
|
83
|
+
const metadataResult = await SDK_Globals.tmSession?.NewSearchEngine().GetMetadataAsync(dcmtInfo.TID, dcmtInfo.DID, true);
|
|
84
|
+
if (metadataResult?.selectMIDs && metadataResult?.dtdResult?.rows?.[0]) {
|
|
85
|
+
const midIndex = metadataResult.selectMIDs.indexOf(emailDescriptor.id);
|
|
86
|
+
if (midIndex >= 0) {
|
|
87
|
+
email = metadataResult.dtdResult.rows[0][midIndex];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const allDtds = await DcmtTypeListCacheService.GetAllWithoutMetadataAsync();
|
|
92
|
+
const dtdDetailWithoutMetadata = allDtds.find(d => d.name?.toLowerCase() === S4T_CERTIFICATE_REGISTRY_DETAIL);
|
|
93
|
+
const dtdDetail = dtdDetailWithoutMetadata ? await DcmtTypeListCacheService.GetAsync(dtdDetailWithoutMetadata.id) : undefined;
|
|
94
|
+
if (!email || !dtdMaster || !dtdDetail) {
|
|
95
|
+
const missingItems = [];
|
|
96
|
+
if (!email)
|
|
97
|
+
missingItems.push('email');
|
|
98
|
+
if (!dtdMaster)
|
|
99
|
+
missingItems.push('dtdMaster');
|
|
100
|
+
if (!dtdDetail)
|
|
101
|
+
missingItems.push('dtdDetail');
|
|
102
|
+
return { missingItems };
|
|
103
|
+
}
|
|
104
|
+
return { email, dtdMaster, dtdDetail };
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Costruisce la query per cercare certificati esistenti.
|
|
108
|
+
*/
|
|
109
|
+
const buildCertificateSearchQuery = (certificateTid, emailMid, cidMid, email, certificateCid) => {
|
|
110
|
+
const query = new QueryDescriptor();
|
|
111
|
+
query.from = new FromItem();
|
|
112
|
+
query.from.tid = certificateTid;
|
|
113
|
+
query.select = [];
|
|
114
|
+
const didSelectField = new SelectItem();
|
|
115
|
+
didSelectField.tid = query.from.tid;
|
|
116
|
+
didSelectField.mid = SystemMIDsAsNumber.DID;
|
|
117
|
+
query.select.push(didSelectField);
|
|
118
|
+
query.where = [];
|
|
119
|
+
// Condizione: email = email del documento padre
|
|
120
|
+
const emailCondition = new WhereItem();
|
|
121
|
+
emailCondition.tid = query.from.tid;
|
|
122
|
+
emailCondition.mid = emailMid;
|
|
123
|
+
emailCondition.value1 = email.toString();
|
|
124
|
+
emailCondition.or = false;
|
|
125
|
+
emailCondition.operator = QueryOperators.Equal;
|
|
126
|
+
query.where.push(emailCondition);
|
|
127
|
+
// Condizione: cid = CID del certificato remoto
|
|
128
|
+
const cidCondition = new WhereItem();
|
|
129
|
+
cidCondition.tid = query.from.tid;
|
|
130
|
+
cidCondition.mid = cidMid;
|
|
131
|
+
cidCondition.value1 = certificateCid.toString();
|
|
132
|
+
cidCondition.or = false;
|
|
133
|
+
cidCondition.operator = QueryOperators.Equal;
|
|
134
|
+
query.where.push(cidCondition);
|
|
135
|
+
return query;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Crea un nuovo documento certificato nel sistema.
|
|
139
|
+
*/
|
|
140
|
+
const createNewCertificateDocument = async (dtdDetail, remoteCertificate, email, abortSignal) => {
|
|
141
|
+
if (!dtdDetail)
|
|
142
|
+
throw new Error("DTD Detail non disponibile");
|
|
143
|
+
const ae = new ArchiveEngineByID(SDK_Globals.tmSession);
|
|
144
|
+
ae.TID = dtdDetail.id;
|
|
145
|
+
ae.Metadata_ClearAll();
|
|
146
|
+
setEngineMetadataFromCertificate(ae, dtdDetail.metadata ?? [], remoteCertificate, email);
|
|
147
|
+
await ae.ArchiveAsync(abortSignal);
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Aggiorna i certificati esistenti con i dati del certificato remoto.
|
|
151
|
+
*/
|
|
152
|
+
const updateExistingCertificates = async (rows, dtdDetail, remoteCertificate, email) => {
|
|
153
|
+
if (!dtdDetail)
|
|
154
|
+
throw new Error("DTD Detail non disponibile");
|
|
155
|
+
await Promise.all(rows.map(async (row) => {
|
|
156
|
+
const did = row?.[0];
|
|
157
|
+
if (did === undefined)
|
|
158
|
+
return;
|
|
159
|
+
const ue = SDK_Globals.tmSession?.NewUpdateEngineByID();
|
|
160
|
+
if (!ue)
|
|
161
|
+
throw new Error("Update Engine not available");
|
|
162
|
+
ue.DID = Number(did);
|
|
163
|
+
ue.TID = dtdDetail.id;
|
|
164
|
+
ue.Metadata_ClearAll();
|
|
165
|
+
setEngineMetadataFromCertificate(ue, dtdDetail.metadata ?? [], remoteCertificate, email);
|
|
166
|
+
await ue.UpdateAsync();
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Risultato dell'importazione certificati per determinare come aggiornare il master.
|
|
171
|
+
* Valori corrispondenti alla datalist "SYSTEM - Flusso base":
|
|
172
|
+
* - 2: Elaborato con successo
|
|
173
|
+
* - 3: Elaborato con warning (es. nessun certificato trovato)
|
|
174
|
+
* - 4: Elaborato con errori
|
|
175
|
+
*/
|
|
176
|
+
var ProcessingResult;
|
|
177
|
+
(function (ProcessingResult) {
|
|
178
|
+
ProcessingResult[ProcessingResult["SUCCESS"] = 2] = "SUCCESS";
|
|
179
|
+
ProcessingResult[ProcessingResult["WARNING"] = 3] = "WARNING";
|
|
180
|
+
ProcessingResult[ProcessingResult["ERROR"] = 4] = "ERROR";
|
|
181
|
+
})(ProcessingResult || (ProcessingResult = {}));
|
|
182
|
+
/** Lunghezza massima del campo processingResultDescription */
|
|
183
|
+
const MAX_PROCESSING_RESULT_DESCRIPTION_LENGTH = 500;
|
|
184
|
+
/** Tronca una stringa alla lunghezza massima consentita per processingResultDescription */
|
|
185
|
+
const truncateProcessingResultDescription = (message) => {
|
|
186
|
+
if (message.length <= MAX_PROCESSING_RESULT_DESCRIPTION_LENGTH)
|
|
187
|
+
return message;
|
|
188
|
+
return message.substring(0, MAX_PROCESSING_RESULT_DESCRIPTION_LENGTH - 3) + '...';
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Aggiorna il documento master con i metadati di elaborazione.
|
|
192
|
+
* - processingdate: data/ora corrente (solo se certificati trovati)
|
|
193
|
+
* - processingdatedescription: descrizione esito
|
|
194
|
+
* - guid: resettato (svuotato)
|
|
195
|
+
*/
|
|
196
|
+
const updateMasterDocument = async (dcmtInfo, dtdMaster, outcome, certificatesCount = 0, errorMessage) => {
|
|
197
|
+
const ue = SDK_Globals.tmSession?.NewUpdateEngineByID();
|
|
198
|
+
if (!ue)
|
|
199
|
+
throw new Error("Update Engine not available");
|
|
200
|
+
ue.DID = dcmtInfo.DID;
|
|
201
|
+
ue.TID = dcmtInfo.TID;
|
|
202
|
+
ue.Metadata_ClearAll();
|
|
203
|
+
const metadata = dtdMaster?.metadata ?? [];
|
|
204
|
+
// Trova i descrittori dei metadati (sempre in lowercase)
|
|
205
|
+
const processingDateDescriptor = metadata.find(md => md.name?.toLowerCase() === 'processingdate');
|
|
206
|
+
const processingResultDescriptor = metadata.find(md => md.name?.toLowerCase() === 'processingresult');
|
|
207
|
+
const processingResultDescriptionDescriptor = metadata.find(md => md.name?.toLowerCase() === 'processingresultdescription');
|
|
208
|
+
const guidDescriptor = metadata.find(md => md.name?.toLowerCase() === 'guid');
|
|
209
|
+
// Resetta sempre il metadato guid
|
|
210
|
+
if (guidDescriptor) {
|
|
211
|
+
ue.Metadata_AddString(guidDescriptor.id, '');
|
|
212
|
+
}
|
|
213
|
+
// Salva il risultato dell'elaborazione
|
|
214
|
+
if (processingResultDescriptor) {
|
|
215
|
+
if (processingResultDescriptor.dataListID) {
|
|
216
|
+
// Se esiste una datalist associata, usa il valore numerico
|
|
217
|
+
const dataList = await DataListCacheService.GetAsync(processingResultDescriptor.dataListID);
|
|
218
|
+
if (dataList && dataList.items) {
|
|
219
|
+
const itemExists = dataList.items.some((item) => Number(item.value) === outcome);
|
|
220
|
+
if (itemExists) {
|
|
221
|
+
ue.Metadata_AddNumber(processingResultDescriptor.id, outcome);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// Se non c'è datalist, salva come stringa
|
|
227
|
+
const outcomeString = ProcessingResult[outcome]; // "SUCCESS", "WARNING", "ERROR"
|
|
228
|
+
ue.Metadata_AddString(processingResultDescriptor.id, outcomeString);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Aggiorna sempre la data di elaborazione
|
|
232
|
+
if (processingDateDescriptor) {
|
|
233
|
+
ue.Metadata_AddDateTime(processingDateDescriptor.id, new Date());
|
|
234
|
+
}
|
|
235
|
+
switch (outcome) {
|
|
236
|
+
case ProcessingResult.SUCCESS:
|
|
237
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
238
|
+
// CASO 1: CERTIFICATI TROVATI
|
|
239
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
240
|
+
// I certificati remoti sono stati trovati e importati con successo.
|
|
241
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
242
|
+
if (processingResultDescriptionDescriptor) {
|
|
243
|
+
const message = certificatesCount === 1
|
|
244
|
+
? 'Importazione completata con successo: 1 certificato elaborato'
|
|
245
|
+
: `Importazione completata con successo: ${certificatesCount} certificati elaborati`;
|
|
246
|
+
ue.Metadata_AddString(processingResultDescriptionDescriptor.id, truncateProcessingResultDescription(message));
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
case ProcessingResult.WARNING:
|
|
250
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
251
|
+
// CASO 2: NESSUN CERTIFICATO TROVATO (WARNING)
|
|
252
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
253
|
+
// La chiamata al servizio remoto è andata a buon fine, ma non sono stati
|
|
254
|
+
// restituiti certificati per l'email associata al documento.
|
|
255
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
256
|
+
if (processingResultDescriptionDescriptor) {
|
|
257
|
+
ue.Metadata_AddString(processingResultDescriptionDescriptor.id, truncateProcessingResultDescription('Nessun certificato trovato'));
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
case ProcessingResult.ERROR:
|
|
261
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
262
|
+
// CASO 3: ERRORE DI COMUNICAZIONE O RISPOSTA NON VALIDA
|
|
263
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
264
|
+
// Si è verificato un errore durante la comunicazione con il servizio remoto
|
|
265
|
+
// (es: timeout chiamata API, errore 500, risposta malformata, ecc.)
|
|
266
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
267
|
+
if (processingResultDescriptionDescriptor) {
|
|
268
|
+
ue.Metadata_AddString(processingResultDescriptionDescriptor.id, truncateProcessingResultDescription(errorMessage ?? 'Errore durante l\'importazione dei certificati'));
|
|
269
|
+
}
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
await ue.UpdateAsync();
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Importa i certificati remoti per il documento corrente.
|
|
276
|
+
* Verifica se esistono già certificati nel sistema e li aggiorna o crea nuovi.
|
|
277
|
+
* Aggiorna il documento master con i metadati di elaborazione.
|
|
278
|
+
*
|
|
279
|
+
* @returns Array di ImportResultInfo con eventuali warning, o undefined se tutto ok
|
|
280
|
+
*/
|
|
281
|
+
export const importCertificatesAsync = async (inputDcmt, rowIndex, fetchRemoteCertificates, abortSignal) => {
|
|
282
|
+
const warnings = [];
|
|
283
|
+
// Recupera il contesto di importazione (email e DTD del certificato)
|
|
284
|
+
const importContext = await getCertificateImportContext(inputDcmt);
|
|
285
|
+
if ('missingItems' in importContext) {
|
|
286
|
+
return [{ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: `Impossibile importare i certificati. Valori mancanti: ${importContext.missingItems.join(', ')}` }];
|
|
287
|
+
}
|
|
288
|
+
if (!fetchRemoteCertificates) {
|
|
289
|
+
return [{ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: 'Callback fetchRemoteCertificates non definita. Impossibile importare i certificati.' }];
|
|
290
|
+
}
|
|
291
|
+
const { email, dtdMaster, dtdDetail } = importContext;
|
|
292
|
+
// Recupera i certificati remoti con gestione errori
|
|
293
|
+
let remoteCertificates;
|
|
294
|
+
try {
|
|
295
|
+
remoteCertificates = await fetchRemoteCertificates(email);
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
// Caso 3: errore di comunicazione o risposta non valida
|
|
299
|
+
const errorMessage = error instanceof Error ? error.message : 'Errore sconosciuto durante il recupero dei certificati';
|
|
300
|
+
await updateMasterDocument(inputDcmt, dtdMaster, ProcessingResult.ERROR, 0, errorMessage);
|
|
301
|
+
return [{ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: errorMessage }];
|
|
302
|
+
}
|
|
303
|
+
// Recupera i descrittori dei metadati necessari dal DTD
|
|
304
|
+
const dtd = await DcmtTypeListCacheService.GetAsync(dtdDetail?.id);
|
|
305
|
+
const emailDescriptor = dtd?.metadata?.find(md => md.name?.toLowerCase() === 'email');
|
|
306
|
+
const cidDescriptor = dtd?.metadata?.find(md => md.name?.toLowerCase() === 'ig_cid');
|
|
307
|
+
if (!emailDescriptor || !cidDescriptor) {
|
|
308
|
+
await updateMasterDocument(inputDcmt, dtdMaster, ProcessingResult.ERROR, 0, 'Metadati necessari per l\'importazione dei certificati non trovati nel DTD.');
|
|
309
|
+
return [{ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: 'Metadati necessari per l\'importazione dei certificati non trovati nel DTD.' }];
|
|
310
|
+
}
|
|
311
|
+
if (!remoteCertificates || remoteCertificates.length === 0) {
|
|
312
|
+
// Caso 2: nessun certificato trovato (warning)
|
|
313
|
+
await updateMasterDocument(inputDcmt, dtdMaster, ProcessingResult.WARNING);
|
|
314
|
+
return [{ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: 'Nessun certificato remoto trovato per questo documento.' }];
|
|
315
|
+
}
|
|
316
|
+
// Itera su ogni certificato remoto per verificare se esiste già nel sistema
|
|
317
|
+
// Conta i certificati effettivamente elaborati con successo
|
|
318
|
+
let successfullyProcessedCount = 0;
|
|
319
|
+
try {
|
|
320
|
+
await Promise.all(remoteCertificates.map(async (remoteCertificate) => {
|
|
321
|
+
// Validazione: il certificato deve avere un CID valido
|
|
322
|
+
if (remoteCertificate.cid === undefined) {
|
|
323
|
+
warnings.push({ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: 'Certificato remoto con informazioni incomplete (cid mancante). Impossibile importare questo certificato.' });
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// Costruisce la query per verificare se esiste già un documento certificato
|
|
327
|
+
const certificateSearchQuery = buildCertificateSearchQuery(dtdDetail?.id, emailDescriptor.id, cidDescriptor.id, email, remoteCertificate.cid);
|
|
328
|
+
// Esegue la ricerca
|
|
329
|
+
const searchEngine = SDK_Globals.tmSession?.NewSearchEngine();
|
|
330
|
+
if (!searchEngine)
|
|
331
|
+
throw new Error("Search Engine not available");
|
|
332
|
+
const existingCertificateResult = await searchEngine.SearchByIDAsync(certificateSearchQuery);
|
|
333
|
+
if (existingCertificateResult === undefined) {
|
|
334
|
+
warnings.push({ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: 'Errore durante la verifica dei certificati esistenti. Impossibile importare questo certificato.' });
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const dcmtsFound = existingCertificateResult.dcmtsFound ?? 0;
|
|
338
|
+
if (dcmtsFound === 0) {
|
|
339
|
+
// Crea nuovo certificato
|
|
340
|
+
await createNewCertificateDocument(dtdDetail, remoteCertificate, email, abortSignal);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
// Aggiorna certificati esistenti
|
|
344
|
+
await updateExistingCertificates(existingCertificateResult.dtdResult?.rows ?? [], dtdDetail, remoteCertificate, email);
|
|
345
|
+
}
|
|
346
|
+
// Incrementa il conteggio solo se l'elaborazione è andata a buon fine
|
|
347
|
+
successfullyProcessedCount++;
|
|
348
|
+
}));
|
|
349
|
+
// Determina l'esito in base ai certificati effettivamente elaborati
|
|
350
|
+
if (successfullyProcessedCount === 0) {
|
|
351
|
+
// Nessun certificato elaborato con successo (tutti senza CID o con errori)
|
|
352
|
+
await updateMasterDocument(inputDcmt, dtdMaster, ProcessingResult.ERROR, 0, 'Errore durante l\'importazione dei certificati: nessun certificato valido trovato');
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
// Almeno un certificato elaborato con successo
|
|
356
|
+
await updateMasterDocument(inputDcmt, dtdMaster, ProcessingResult.SUCCESS, successfullyProcessedCount);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
// Caso 3: errore durante l'importazione
|
|
361
|
+
const errorMessage = error instanceof Error ? error.message : 'Errore durante l\'importazione dei certificati';
|
|
362
|
+
await updateMasterDocument(inputDcmt, dtdMaster, ProcessingResult.ERROR, 0, errorMessage);
|
|
363
|
+
warnings.push({ rowIndex, id1: inputDcmt.TID, id2: inputDcmt.DID, resultType: ResultTypes.WARNING, description: errorMessage });
|
|
364
|
+
}
|
|
365
|
+
return warnings.length > 0 ? warnings : undefined;
|
|
366
|
+
};
|
|
367
|
+
export const archiveUserRegistryDocument = async (abortSignal, params) => {
|
|
368
|
+
try {
|
|
369
|
+
const allDtds = await DcmtTypeListCacheService.GetAllWithoutMetadataAsync();
|
|
370
|
+
const dtdMasterWithoutMetadata = allDtds.find(d => d.name?.toLowerCase() === S4T_USER_REGISTRY_MASTER);
|
|
371
|
+
const dtdMaster = dtdMasterWithoutMetadata ? await DcmtTypeListCacheService.GetAsync(dtdMasterWithoutMetadata.id) : undefined;
|
|
372
|
+
if (!dtdMaster) {
|
|
373
|
+
throw new Error(`DTD Master "${S4T_USER_REGISTRY_MASTER}" non trovato`);
|
|
374
|
+
}
|
|
375
|
+
const ae = new ArchiveEngineByID(SDK_Globals.tmSession);
|
|
376
|
+
ae.TID = dtdMaster.id;
|
|
377
|
+
ae.Metadata_ClearAll();
|
|
378
|
+
// Aggiunge i metadati dall'oggetto params
|
|
379
|
+
const metadata = dtdMaster.metadata ?? [];
|
|
380
|
+
const emailDescriptor = metadata.find(md => md.name?.toLowerCase() === 'email');
|
|
381
|
+
if (emailDescriptor)
|
|
382
|
+
ae.Metadata_AddString(emailDescriptor.id, params.email);
|
|
383
|
+
const fiscalCodeDescriptor = metadata.find(md => md.name?.toLowerCase() === 'fiscalcode');
|
|
384
|
+
if (fiscalCodeDescriptor)
|
|
385
|
+
ae.Metadata_AddString(fiscalCodeDescriptor.id, params.fiscalCode);
|
|
386
|
+
const phoneNumberDescriptor = metadata.find(md => md.name?.toLowerCase() === 'phonenumber');
|
|
387
|
+
if (phoneNumberDescriptor)
|
|
388
|
+
ae.Metadata_AddString(phoneNumberDescriptor.id, params.phoneNumber);
|
|
389
|
+
const nameDescriptor = metadata.find(md => md.name?.toLowerCase() === 'name');
|
|
390
|
+
if (nameDescriptor)
|
|
391
|
+
ae.Metadata_AddString(nameDescriptor.id, params.name);
|
|
392
|
+
const surnameDescriptor = metadata.find(md => md.name?.toLowerCase() === 'surname');
|
|
393
|
+
if (surnameDescriptor)
|
|
394
|
+
ae.Metadata_AddString(surnameDescriptor.id, params.surname);
|
|
395
|
+
const typeDescriptor = metadata.find(md => md.name?.toLowerCase() === 'certificatemethod');
|
|
396
|
+
if (typeDescriptor)
|
|
397
|
+
ae.Metadata_AddString(typeDescriptor.id, params.type);
|
|
398
|
+
await ae.ArchiveAsync(abortSignal);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
};
|
package/lib/helper/helpers.js
CHANGED
|
@@ -461,6 +461,15 @@ export const extensionHandler = (fileExt) => {
|
|
|
461
461
|
case 'docx':
|
|
462
462
|
case 'docx.p7m':
|
|
463
463
|
case 'docx.p7m.ts': return FileExtensionHandler.CONVERTIBLE;
|
|
464
|
+
case 'dotm':
|
|
465
|
+
case 'dotm.p7m':
|
|
466
|
+
case 'dotm.p7m.ts': return FileExtensionHandler.CONVERTIBLE;
|
|
467
|
+
case 'docm':
|
|
468
|
+
case 'docm.p7m':
|
|
469
|
+
case 'docm.p7m.ts': return FileExtensionHandler.CONVERTIBLE;
|
|
470
|
+
case 'dotx':
|
|
471
|
+
case 'dotx.p7m':
|
|
472
|
+
case 'dotx.p7m.ts': return FileExtensionHandler.CONVERTIBLE;
|
|
464
473
|
case 'xls':
|
|
465
474
|
case 'xls.p7m':
|
|
466
475
|
case 'xls.p7m.ts': return FileExtensionHandler.CONVERTIBLE;
|
package/lib/helper/index.d.ts
CHANGED
package/lib/helper/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RetrieveFileOptions, DcmtOpers, FileDescriptor, GeneralRetrieveFormats, InvoiceRetrieveFormats, OrderRetrieveFormats, FileFormats } from '@topconsultnpm/sdk-ts';
|
|
2
2
|
import { DcmtInfo, DcmtOperationTypes, DownloadModes, DownloadTypes } from '../ts';
|
|
3
|
+
import { IntesiCertificateData } from '../helper/certificateImportHelper';
|
|
3
4
|
export interface RetrieveFormatOptions {
|
|
4
5
|
retrieveReason?: DcmtOpers;
|
|
5
6
|
cvtFormat?: FileFormats;
|
|
@@ -44,7 +45,7 @@ export interface UseDcmtOperationsReturn {
|
|
|
44
45
|
clearDcmtsFileCache: () => void;
|
|
45
46
|
removeDcmtsFileCache: (key: string) => void;
|
|
46
47
|
isDcmtFileInCache: (key: string) => boolean;
|
|
47
|
-
runOperationAsync: (inputDcmts: DcmtInfo[] | undefined, dcmtOperationType: DcmtOperationTypes, actionAfterOperationAsync?: () => Promise<void>) => Promise<void>;
|
|
48
|
+
runOperationAsync: (inputDcmts: DcmtInfo[] | undefined, dcmtOperationType: DcmtOperationTypes, actionAfterOperationAsync?: () => Promise<void>, fetchRemoteCertificates?: (email: string) => Promise<IntesiCertificateData[]>) => Promise<void>;
|
|
48
49
|
FileSourceDialog: () => JSX.Element;
|
|
49
50
|
}
|
|
50
51
|
export declare const useDcmtOperations: () => UseDcmtOperationsReturn;
|
|
@@ -5,6 +5,7 @@ import { ShowAlert, TMResultManager, FormulaHelper, TMExceptionBoxManager, TMSpi
|
|
|
5
5
|
import { Globalization, getExceptionMessage, dialogConfirmOperation, extensionHandler, downloadBase64File, SDKUI_Globals, dcmtsFileCacheDownload, CACHE_SIZE_LIMIT, clearDcmtsFileCache, dcmtsFileCachePreview, isDcmtFileInCache, removeDcmtsFileCache, SDKUI_Localizator, ZipManager } from '../helper';
|
|
6
6
|
import { DcmtOperationTypes, DownloadTypes, FileExtensionHandler } from '../ts';
|
|
7
7
|
import { useFileDialog, useFileSourceDialog } from './useInputDialog';
|
|
8
|
+
import { importCertificatesAsync } from '../helper/certificateImportHelper';
|
|
8
9
|
import { isXMLFileExt } from '../helper/dcmtsHelper';
|
|
9
10
|
import { ShowConfirm } from '../components/base/TMConfirm';
|
|
10
11
|
import { generateTargetFileName } from '../components/features/documents/copyAndMergeDcmtsShared';
|
|
@@ -132,7 +133,7 @@ export const useDcmtOperations = () => {
|
|
|
132
133
|
let maxFileSize = 0;
|
|
133
134
|
let signerInfoDescriptor = undefined;
|
|
134
135
|
if (inputDcmt?.FILEEXT == undefined || inputDcmt.FILEEXT == '') {
|
|
135
|
-
throw new Error('WARNING#
|
|
136
|
+
throw new Error('WARNING#' + SDKUI_Localizator.MetadataOnlyDocument);
|
|
136
137
|
}
|
|
137
138
|
let ue = SDK_Globals.tmSession?.NewUpdateEngineByID();
|
|
138
139
|
if (ue) {
|
|
@@ -635,7 +636,7 @@ export const useDcmtOperations = () => {
|
|
|
635
636
|
}
|
|
636
637
|
}
|
|
637
638
|
};
|
|
638
|
-
const runOperationAsync = async (inputDcmts, dcmtOperationType, actionAfterOperationAsync) => {
|
|
639
|
+
const runOperationAsync = async (inputDcmts, dcmtOperationType, actionAfterOperationAsync, fetchRemoteCertificates) => {
|
|
639
640
|
if (inputDcmts === undefined)
|
|
640
641
|
return;
|
|
641
642
|
if (inputDcmts.length <= 0)
|
|
@@ -780,6 +781,13 @@ export const useDcmtOperations = () => {
|
|
|
780
781
|
}
|
|
781
782
|
break;
|
|
782
783
|
}
|
|
784
|
+
case DcmtOperationTypes.ImportCertificates: {
|
|
785
|
+
const importWarnings = await importCertificatesAsync(inputDcmts[i], i, fetchRemoteCertificates, abortController.signal);
|
|
786
|
+
if (importWarnings) {
|
|
787
|
+
result.push(...importWarnings);
|
|
788
|
+
}
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
783
791
|
}
|
|
784
792
|
result.push({ rowIndex: i, id1: inputDcmts[i].TID, id2: inputDcmts[i].DID, resultType: ResultTypes.SUCCESS });
|
|
785
793
|
}
|
|
@@ -6,6 +6,7 @@ import { DcmtInfo, MetadataValueDescriptorEx, SearchResultContext, TaskContext }
|
|
|
6
6
|
import { UseCheckInOutOperationsReturn } from "./useCheckInOutOperations";
|
|
7
7
|
import { UseDcmtOperationsReturn } from "./useDcmtOperations";
|
|
8
8
|
import { UseRelatedDocumentsReturn } from "./useRelatedDocuments";
|
|
9
|
+
import { IntesiCertificateData } from '../helper';
|
|
9
10
|
export interface DocumentDataProps {
|
|
10
11
|
dtd: DcmtTypeDescriptor | undefined;
|
|
11
12
|
selectedItems: Array<any>;
|
|
@@ -14,6 +15,7 @@ export interface DocumentDataProps {
|
|
|
14
15
|
currentMetadataValues: Array<MetadataValueDescriptorEx>;
|
|
15
16
|
allUsers?: Array<UserDescriptor>;
|
|
16
17
|
searchResult?: SearchResultDescriptor;
|
|
18
|
+
fetchRemoteCertificates?: (email: string) => Promise<IntesiCertificateData[]>;
|
|
17
19
|
datagridUtility?: {
|
|
18
20
|
visibleItems?: any[];
|
|
19
21
|
onRefreshSearchAsyncDatagrid?: () => Promise<void>;
|