1
1
{
2
2
License OpenMasterdata-for-Delphi
3
3
4
- Copyright (C) 2022 Landrix Software GmbH & Co. KG
4
+ Copyright (C) 2024 Landrix Software GmbH & Co. KG
5
5
6
6
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with this program. If not, see <https://www.gnu.org/licenses/>.
7
+ Licensed to the Apache Software Foundation (ASF) under one
8
+ or more contributor license agreements. See the NOTICE file
9
+ distributed with this work for additional information
10
+ regarding copyright ownership. The ASF licenses this file
11
+ to you under the Apache License, Version 2.0 (the
12
+ "License"); you may not use this file except in compliance
13
+ with the License. You may obtain a copy of the License at
14
+
15
+ http://www.apache.org/licenses/LICENSE-2.0
16
+
17
+ Unless required by applicable law or agreed to in writing,
18
+ software distributed under the License is distributed on an
19
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ KIND, either express or implied. See the License for the
21
+ specific language governing permissions and limitations
22
+ under the License.
19
23
}
20
24
21
25
unit OpenMasterdataUnit1;
@@ -48,8 +52,11 @@ TMainForm = class(TForm)
48
52
procedure FormCreate (Sender: TObject);
49
53
procedure FormDestroy (Sender: TObject);
50
54
procedure ComboBox1Select (Sender: TObject);
55
+ procedure EdgeBrowser1WebResourceRequested (Sender: TCustomEdgeBrowser;
56
+ Args: TWebResourceRequestedEventArgs);
51
57
public
52
58
Configuration : TMemIniFile;
59
+ CurrentAuthorizationToken : String;
53
60
end ;
54
61
55
62
var
@@ -70,25 +77,25 @@ procedure TMainForm.FormCreate(Sender: TObject);
70
77
71
78
configurationFilename := basePath + ' configuration.ini' ;
72
79
73
- Configuration := TMemIniFile.Create(configurationFilename);
80
+ Configuration := TMemIniFile.Create(configurationFilename,TEncoding.UTF8 );
74
81
75
- // Inhaltsaufbau einer Ini-Section je Lieferant
82
+ // Inhaltsaufbau configuration.ini, eine Ini-Section je Lieferant
76
83
// [Lieferant-Name]
77
84
// Username=
78
85
// Password=
79
86
// Customernumber=
80
87
// ClientID=
81
88
// ClientSecret=
82
- // ClientScope=
83
- // GrantType=
84
- // UsernameRequired=
85
- // CustomernumberRequired=
86
- // ClientSecretRequired=
89
+ // ClientScope=openMasterdata
90
+ // GrantType=password or client_credentials
91
+ // UsernameRequired=True or False
92
+ // CustomernumberRequired=True or False
93
+ // ClientSecretRequired=True or False
87
94
// OAuthURL=
88
95
// BySupplierPIDURL=
89
96
// ByManufacturerDataURL=
90
97
// ByGTINURL=
91
- // ArtNoAsCommatext=
98
+ // ArtNoAsCommatext=123,456
92
99
93
100
Configuration.ReadSections(ComboBox1.Items);
94
101
@@ -114,6 +121,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
114
121
for var i : Integer := 0 to CheckListBox1.Items.Count-1 do
115
122
CheckListBox1.Checked[i] := true;
116
123
124
+ EdgeBrowser1.UserDataFolder := ExtractFilePath(Application.ExeName);
117
125
EdgeBrowser1.Navigate(' about:blank' );
118
126
119
127
var _Result : TOpenMasterdataAPI_Result;
@@ -132,6 +140,20 @@ procedure TMainForm.FormCreate(Sender: TObject);
132
140
finally
133
141
_Result.Free;
134
142
end ;
143
+ _Result := TOpenMasterdataAPI_Result.Create;
144
+ try
145
+ try
146
+ _Result.LoadFromJson(TFile.ReadAllText(basePath+' supplierPid_WiedemannRaw.json' ));
147
+ except
148
+ on E:Exception do
149
+ begin
150
+ // FLastErrorMessage := E.ClassName+' '+e.Message;
151
+ exit;
152
+ end ;
153
+ end ;
154
+ finally
155
+ _Result.Free;
156
+ end ;
135
157
_Result := TOpenMasterdataAPI_Result.Create;
136
158
try
137
159
try
@@ -217,6 +239,37 @@ procedure TMainForm.ComboBox1Select(Sender: TObject);
217
239
Memo2.Lines.Add(Configuration.ReadString(ComboBox1.Text,' ByGTINURL' ,' ' ));
218
240
end ;
219
241
242
+ procedure TMainForm.EdgeBrowser1WebResourceRequested (Sender: TCustomEdgeBrowser;
243
+ Args: TWebResourceRequestedEventArgs);
244
+ var
245
+ request: ICoreWebView2WebResourceRequest;
246
+ // requestURI, responseHeaders, method: PWideChar;
247
+ // response: ICoreWebView2WebResourceResponse;
248
+ // requestFilename, localFilename, payload: string;
249
+ headers: ICoreWebView2HttpRequestHeaders;
250
+ // requestStringStream : IStream;
251
+ // core:ICoreWebView2;
252
+ // sett:ICoreWebView2Settings;
253
+ begin
254
+ if CurrentAuthorizationToken = ' ' then
255
+ exit;
256
+ Args.ArgsInterface.Get_Request(request);
257
+ // request.Get_uri(requestURI);
258
+ request.Get_Headers(headers);
259
+ headers.SetHeader(' Authorization' ,PChar(' Bearer ' +CurrentAuthorizationToken));
260
+
261
+ // headers.SetHeader('User-Agent', PChar('TestBrowserDownload v' + GetVersion));
262
+ // headers.SetHeader('Content-Type', PChar('application/x-www-form-urlencoded'));
263
+ // request.Set_Method('POST');
264
+ // payload := 'a=textusw';
265
+ // requestStringStream := TStreamAdapter.Create(TStringStream.Create(payload, TEncoding.UTF8), soOwned);
266
+ // request.Set_Content(requestStringStream);
267
+ // //Versuch IStream für den Dateitransfer zur Verfügung zu stellen...
268
+ // Args.ArgsInterface.Get_Response(response);
269
+ // requestFileStream := TStreamAdapter.Create(TFileStream.Create(extractfilepath(paramstr(0)) + 'test.dat', fmCreate or fmOpenReadWrite or fmShareDenyNone), soOwned);
270
+ // response.Set_Content(requestFileStream);
271
+ end ;
272
+
220
273
procedure TMainForm.btBySupplierPidClick (Sender: TObject);
221
274
var
222
275
client : IOpenMasterdataApiClient;
@@ -228,7 +281,8 @@ procedure TMainForm.btBySupplierPidClick(Sender: TObject);
228
281
var
229
282
tmpJson: System.JSON.TJSONValue;
230
283
begin
231
- tmpJson := System.JSON.TJSONObject.ParseJSONValue(json);
284
+ tmpJson := System.JSON.TJSONObject.ParseJSONValue(
285
+ TOpenMasterdataHelper.FixJson(json),false,true);
232
286
if tmpJson <> nil then
233
287
begin
234
288
Result := Rest.Json.TJson.Format(tmpJson);
@@ -239,6 +293,7 @@ procedure TMainForm.btBySupplierPidClick(Sender: TObject);
239
293
240
294
begin
241
295
Memo1.Clear;
296
+ CurrentAuthorizationToken := ' ' ;
242
297
243
298
if ComboBox1.ItemIndex < 0 then
244
299
exit;
@@ -270,7 +325,9 @@ procedure TMainForm.btBySupplierPidClick(Sender: TObject);
270
325
Memo1.Lines.Text := FormatJSON(client.GetLastBySupplierPIDResponseContent);
271
326
272
327
html := TOpenMasterdataAPI_ViewHelper.AsHtml(supplierPid);
328
+ CurrentAuthorizationToken := client.GetCurrentAuthorizationToken;
273
329
330
+ EdgeBrowser1.AddWebResourceRequestedFilter(' *' , COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
274
331
EdgeBrowser1.NavigateToString(html);
275
332
finally
276
333
supplierPid.Free;
0 commit comments