mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 18:29:12 +02:00
* Add REST business processor
git-svn-id: trunk@60570 -
This commit is contained in:
parent
48ce9f091f
commit
3aa7071ff0
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1843,6 +1843,7 @@ components/fpweb/restimages/filelist.txt svneol=native#text/plain
|
||||
components/fpweb/restimages/genimages.bat svneol=native#text/plain
|
||||
components/fpweb/restimages/genimages.sh svneol=native#text/plain
|
||||
components/fpweb/restimages/trestbasicauthenticator.png -text svneol=unset#image/png
|
||||
components/fpweb/restimages/tsqldbrestbusinessprocessor.png -text svneol=unset#image/png
|
||||
components/fpweb/restimages/tsqldbrestdispatcher.png -text svneol=unset#image/png
|
||||
components/fpweb/restimages/tsqldbrestschema.png -text svneol=unset#image/png
|
||||
components/fpweb/weblaz.lpk svneol=native#text/plain
|
||||
|
@ -1,4 +1,5 @@
|
||||
object RestDataModule: TRestDataModule
|
||||
OnCreate = DataModuleCreate
|
||||
OldCreateOrder = False
|
||||
Height = 294
|
||||
HorizontalOffset = 465
|
||||
@ -22,6 +23,7 @@ object RestDataModule: TRestDataModule
|
||||
item
|
||||
Schema = ExpensesSchema
|
||||
end>
|
||||
DispatchOptions = [rdoExposeMetadata, rdoAccessCheckNeedsDB]
|
||||
Authenticator = AuthBasic
|
||||
EnforceLimit = 0
|
||||
left = 72
|
||||
@ -243,4 +245,15 @@ object RestDataModule: TRestDataModule
|
||||
left = 136
|
||||
top = 104
|
||||
end
|
||||
object BPProjects: TSQLDBRestBusinessProcessor
|
||||
Schema = ExpensesSchema
|
||||
ResourceName = 'projects'
|
||||
OnGetDataset = DoGetDataset
|
||||
OnCheckParams = DoCheckParams
|
||||
OnAllowResource = DoAllowResource
|
||||
OnAllowedOperations = DoAllowedOperations
|
||||
OnAllowRecord = DoAllowedRecord
|
||||
left = 254
|
||||
top = 121
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ unit dmRestBridge;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, sqldbrestbridge, sqldbrestschema, pqconnection, sqldbrestauth,
|
||||
Classes, SysUtils, sqldbrestbridge, sqldbrestschema, pqconnection, sqldbrestauth,db,
|
||||
// Register formats
|
||||
sqldbrestcsv ,sqldbrestxml, sqldbrestcds;
|
||||
|
||||
@ -17,8 +17,14 @@ type
|
||||
AuthBasic: TRestBasicAuthenticator;
|
||||
Dispatcher: TSQLDBRestDispatcher;
|
||||
ExpensesSchema: TSQLDBRestSchema;
|
||||
BPProjects: TSQLDBRestBusinessProcessor;
|
||||
procedure DataModuleCreate(Sender: TObject);
|
||||
procedure DoAllowedOperations(aSender: TObject; aContext: TBaseRestContext; var aOperations: TRestOperations);
|
||||
procedure DoAllowedRecord(aSender: TObject; aContext: TBaseRestContext; aDataSet: TDataset; var allowRecord: Boolean);
|
||||
procedure DoAllowResource(aSender: TObject; aContext: TBaseRestContext; var allowResource: Boolean);
|
||||
procedure DoCheckParams(aSender: TObject; aContext: TBaseRestContext; aOperation: TRestOperation; Params: TParams);
|
||||
procedure DoGetDataset(aSender: TObject; aContext: TBaseRestContext; aFieldList: TRestFieldPairArray; aOrderBy: TRestFieldOrderPairArray; aLimit, aOffset: Int64; var aDataset: TDataset);
|
||||
private
|
||||
|
||||
public
|
||||
|
||||
end;
|
||||
@ -30,5 +36,58 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
uses sqldbrestini;
|
||||
|
||||
{ TRestDataModule }
|
||||
|
||||
procedure TRestDataModule.DataModuleCreate(Sender: TObject);
|
||||
begin
|
||||
if FileExists('connection.ini') then
|
||||
Dispatcher.Connections[0].LoadFromFile('connection.ini');
|
||||
end;
|
||||
|
||||
procedure TRestDataModule.DoAllowedOperations(aSender: TObject;
|
||||
aContext: TBaseRestContext; var aOperations: TRestOperations);
|
||||
begin
|
||||
if IsConsole then
|
||||
Writeln('AllowedOperations for ',aContext.UserID);
|
||||
end;
|
||||
|
||||
procedure TRestDataModule.DoAllowedRecord(aSender: TObject;
|
||||
aContext: TBaseRestContext; aDataSet: TDataset; var allowRecord: Boolean);
|
||||
begin
|
||||
if IsConsole then
|
||||
Writeln('AllowedRecord for ',aContext.UserID);
|
||||
end;
|
||||
|
||||
procedure TRestDataModule.DoAllowResource(aSender: TObject;
|
||||
aContext: TBaseRestContext; var allowResource: Boolean);
|
||||
begin
|
||||
if IsConsole then
|
||||
Writeln('AllowedResource for ',aContext.UserID);
|
||||
end;
|
||||
|
||||
procedure TRestDataModule.DoCheckParams(aSender: TObject;
|
||||
aContext: TBaseRestContext; aOperation: TRestOperation; Params: TParams);
|
||||
|
||||
Var
|
||||
P : TParam;
|
||||
begin
|
||||
if IsConsole then
|
||||
begin
|
||||
Writeln('CheckParams for ',aContext.UserID,', aOperation : ',aOperation);
|
||||
For P in Params do
|
||||
Writeln('Param ',P.Name,' : ',P.AsString);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRestDataModule.DoGetDataset(aSender: TObject;
|
||||
aContext: TBaseRestContext; aFieldList: TRestFieldPairArray;
|
||||
aOrderBy: TRestFieldOrderPairArray; aLimit, aOffset: Int64;
|
||||
var aDataset: TDataset);
|
||||
begin
|
||||
Writeln('DoGetDataset for ',aContext.UserID);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -55,6 +55,9 @@
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="restserver"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
|
@ -40,3 +40,16 @@ LazarusResources.Add('tsqldbrestschema','PNG',[
|
||||
+#230#200#209'='#187#26#180'Z'#188#249'4z'#132',CQu'#27'Z{'#0#207#138#170'd'#1
|
||||
+'A'#151#19#0#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
||||
LazarusResources.Add('tsqldbrestbusinessprocessor','PNG',[
|
||||
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||
+#0#0#1'sRGB'#0#174#206#28#233#0#0#0#4'gAMA'#0#0#177#143#11#252'a'#5#0#0#0#9
|
||||
+'pHYs'#0#0#14#195#0#0#14#195#1#199'o'#168'd'#0#0#0#174'IDATHK'#237#149'K'#10
|
||||
+#2'1'#16'D'#179#242'L'#162#215#243#3#158#206#133'W'#208'kh'#149#164'$4'#147
|
||||
+'t'#5'W'#3#243#224'A'#154'T''3'#155'N'#217#152'a'#7'o'#240#9#223#166#204'^!{'
|
||||
+'S'#24'\:'#196#241#2'S^'#144#225#253#183#234#243#128#202#29#234#154#127#146
|
||||
+#162#175#201#136'9'#183#239#23't'#21#177#238#210'6;'#138'X['#204'4'#173#227#2
|
||||
+#213#173'"'#214#22#189'CZE'#172'-f'#154#214'q'#129#234'V'#177#180'G'#135#196
|
||||
+'P'#219#232#236#209'!V'#168#18#179'V'#175#6#31#135'Y'#198#29'*{'#172#235't'
|
||||
+#248#253'3'#186#233#9#14#225#3#194#25'?'#243#248'P'#230#207#208'z'#128'6@)'
|
||||
+#31#247#7#169#216'\2x<'#0#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
||||
|
@ -56,6 +56,17 @@ Type
|
||||
Class Function StreamType : TRestStreamerType; override;
|
||||
end;
|
||||
|
||||
{ TSQLDBRestResourceNamePropertyEditor }
|
||||
|
||||
TSQLDBRestResourceNamePropertyEditor = class(TStringPropertyEditor)
|
||||
protected
|
||||
function GetResourceList: TSQLDBRestResourceList;virtual;
|
||||
public
|
||||
function GetAttributes: TPropertyAttributes; override;
|
||||
procedure GetValues(Proc: TGetStrProc); override;
|
||||
end;
|
||||
|
||||
|
||||
{ ---------------------------------------------------------------------
|
||||
Component editors
|
||||
---------------------------------------------------------------------}
|
||||
@ -117,7 +128,8 @@ begin
|
||||
RegisterComponents('fpWeb',[
|
||||
TSQLDBRESTDispatcher,
|
||||
TSQLDBRESTSchema,
|
||||
TRESTBasicAuthenticator
|
||||
TRESTBasicAuthenticator,
|
||||
TSQLDBRestBusinessProcessor
|
||||
]);
|
||||
RegisterPropertyEditor(TypeInfo(AnsiString),
|
||||
TSQLDBRestConnection, 'ConnectionType', TSQLDBConnectionTypePropertyEditor);
|
||||
@ -127,7 +139,8 @@ begin
|
||||
TSQLDBRestDispatcher, 'InputFormat', TSQLDBRestInPutFormatPropertyEditor);
|
||||
RegisterPropertyEditor(TypeInfo(UTF8String),
|
||||
TSQLDBRestDispatcher, 'DefaultConnection', TSQLDBRestDefaultConnectionPropertyEditor);
|
||||
|
||||
RegisterPropertyEditor(TypeInfo(UTF8String),
|
||||
TSQLDBRestBusinessProcessor,'ResourceName',TSQLDBRestResourceNamePropertyEditor);
|
||||
RegisterComponentEditor(TSQLDBRESTSchema,TSQLDBRESTSchemaComponentEditor);
|
||||
RegisterComponentEditor(TSQLDBRestDispatcher,TSQLDBRestDispatcherComponentEditor);
|
||||
|
||||
@ -169,6 +182,44 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TSQLDBRestResourceNamePropertyEditor }
|
||||
|
||||
function TSQLDBRestResourceNamePropertyEditor.GetAttributes: TPropertyAttributes;
|
||||
begin
|
||||
Result := [paSortList, paValueList, paRevertable];
|
||||
end;
|
||||
|
||||
function TSQLDBRestResourceNamePropertyEditor.GetResourceList : TSQLDBRestResourceList;
|
||||
|
||||
Var
|
||||
S : TSQLDBRestSchema;
|
||||
C : TPersistent;
|
||||
|
||||
begin
|
||||
Result:=Nil;
|
||||
C:=TPersistent(GetComponent(0));
|
||||
if not (Assigned(C) and (C is TSQLDBRestBusinessProcessor)) then
|
||||
exit;
|
||||
S:=TSQLDBRestBusinessProcessor(C).Schema;
|
||||
if Assigned(S) then
|
||||
Result:=S.Resources;
|
||||
end;
|
||||
|
||||
procedure TSQLDBRestResourceNamePropertyEditor.GetValues(Proc: TGetStrProc);
|
||||
|
||||
Var
|
||||
L : TSQLDBRestResourceList;
|
||||
i : Integer;
|
||||
|
||||
begin
|
||||
L:=GetResourceList;
|
||||
if Not Assigned(L) then
|
||||
exit;
|
||||
For I:=0 to L.Count-1 do
|
||||
Proc(L[i].ResourceName);
|
||||
end;
|
||||
|
||||
|
||||
{ TSQLDBRestDefaultConnectionPropertyEditor }
|
||||
|
||||
function TSQLDBRestDefaultConnectionPropertyEditor.GetAttributes: TPropertyAttributes;
|
||||
|
@ -1,3 +1,4 @@
|
||||
trestbasicauthenticator.png
|
||||
tsqldbrestdispatcher.png
|
||||
tsqldbrestschema.png
|
||||
tsqldbrestbusinessprocessor.png
|
||||
|
BIN
components/fpweb/restimages/tsqldbrestbusinessprocessor.png
Normal file
BIN
components/fpweb/restimages/tsqldbrestbusinessprocessor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 B |
Loading…
Reference in New Issue
Block a user