Commit 0e60f8af authored by Thiago Anders's avatar Thiago Anders

BuscarEmprestimos funcionando.

parent 6b6ef2a2
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -7,6 +7,13 @@ FROM ngCliente
WHERE (ngCliente.Nome LIKE '%'+?nome:acString+'%' OR ?nome:acString IS NULL)
AND (ngCliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL)]]></query>
</oql>
<oql name="ObterEmprestimos" oqltype="0">
<description>Obtem emprestimos por cliente.</description>
<query><![CDATA[SELECT ngEmprestimo
FROM ngEmprestimo
WHERE (ngEmprestimo.Cliente.Nome LIKE '%'+?nome:acString+'%' OR ?nome:acString IS NULL)
AND (ngEmprestimo.Cliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL)]]></query>
</oql>
<oql name="ObterExemplares" oqltype="0">
<description></description>
<query><![CDATA[SELECT ngExemplar
......
This diff is collapsed.
......@@ -99,7 +99,8 @@ uses
nguExemplar in 'ngu\nguExemplar.pas',
nguLivro in 'ngu\nguLivro.pas',
nguSituacaoExemplar in 'ngu\nguSituacaoExemplar.pas',
nguVersaoBanco in 'ngu\nguVersaoBanco.pas';
nguVersaoBanco in 'ngu\nguVersaoBanco.pas',
ucuBuscarEmprestimos in 'ucu\ucuBuscarEmprestimos.pas';
var
lErros : TStringList;
......
......@@ -1228,6 +1228,16 @@ begin
lUseCaseTicket.InheritsFrom := 'ucUseCase';
end;
procedure NewUseCaseTicket_ucBuscarEmprestimos_3223(piMetaModel: acMetaModel);
var
lUseCaseTicket: acUseCaseTicket;
begin
//Criao do UseCaseTicket ucBuscarEmprestimos (3223)
lUseCaseTicket := piMetaModel.NewUseCaseTicket('3223', nil, True);
lUseCaseTicket.Name := 'ucBuscarEmprestimos';
lUseCaseTicket.InheritsFrom := 'ucUseCase';
end;
function GetXSDIn_3215_smucHelloWorld_Executando_RM_CUMPRIMENTAR: String;
begin
Result := '<?xml version="1.0"?>' + #13#10 +
......@@ -1774,6 +1784,89 @@ begin
'';
end;
function GetXSDIn_3223_smucBuscarEmprestimos_Executando_RM_BUSCAR_EMPRESTIMOS: String;
begin
Result := '<?xml version="1.0"?>' + #13#10 +
'<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->' + #13#10 +
'<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">' + #13#10 +
' <xs:element name="SYSMSG">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 +
' <xs:element name="Cliente">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:attribute name="CPF" type="xs:string" use="optional"/>' + #13#10 +
' <xs:attribute name="Nome" type="xs:string" use="optional"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
'</xs:schema>' + #13#10 +
'';
end;
function GetXSDOut_3223_smucBuscarEmprestimos_Executando_RM_BUSCAR_EMPRESTIMOS: String;
begin
Result := '<?xml version="1.0"?>' + #13#10 +
'<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->' + #13#10 +
'<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">' + #13#10 +
' <xs:element name="SYSMSG">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 +
' <xs:element minOccurs="1" maxOccurs="1" name="Emprestimos">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="0" maxOccurs="unbounded">' + #13#10 +
' <xs:element name="Emprestimo">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence>' + #13#10 +
' <xs:element name="Cliente">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:attribute name="Nome" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="CPF" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="OID" type="xs:int" use="required"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' <xs:element name="Exemplar">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 +
' <xs:element name="Livro">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:attribute name="Titulo" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="Autor" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="OID" type="xs:int" use="required"/>' + #13#10 +
' <xs:attribute name="Edicao" type="xs:string" use="required"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:attribute name="Codigo" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="OID" type="xs:int" use="required"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:attribute name="Retirada" type="xs:date" use="required"/>' + #13#10 +
' <xs:attribute name="PrevistaDev" type="xs:date" use="required"/>' + #13#10 +
' <xs:attribute name="DataDev" type="xs:date" use="optional"/>' + #13#10 +
' <xs:attribute name="OID" type="xs:int" use="required"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
'</xs:schema>' + #13#10 +
'';
end;
procedure RegisterUseCases1(piMetaModel: acMetaModel);
var
lUseCaseTicket: acUseCaseTicket;
......@@ -1792,6 +1885,7 @@ begin
NewUseCaseTicket_ucCadastroUsuarioSistema_101(piMetaModel);
NewUseCaseTicket_ucHelloWorld_3215(piMetaModel);
NewUseCaseTicket_ucEmprestarLivro_3219(piMetaModel);
NewUseCaseTicket_ucBuscarEmprestimos_3223(piMetaModel);
//Gerando StateMachine para o casu de uso 'ucImportaConfiguracaoSistema'
lUseCaseTicket := piMetaModel.UseCaseTicketByCode['1327'];
......@@ -2651,6 +2745,77 @@ begin
lTransition.AddEffect('Effect_CancelarEmprestimo');
//Gerando StateMachine para o casu de uso 'ucBuscarEmprestimos'
lUseCaseTicket := piMetaModel.UseCaseTicketByCode['3223'];
lStateMachine := lUseCaseTicket.StateMachine;
lStateMachine.Name := 'smServer';
utState.Create(lStateMachine, 'Initializing');
lSubMachineState := utSubMachineState.Create(lStateMachine, 'UseCaseSubmachine');
lSubMachineUseCaseTicket := piMetaModel.UseCaseTicketByCode['3223'];
lSubMachineState.StateMachine := acUseCaseStateMachine.Create(lSubMachineUseCaseTicket, lSubMachineState);
utFinalState.Create(lStateMachine, 'smBase_FinalState');
//Define o InitialState do StateMachine
lStateMachine.InitialState := lStateMachine.FindState('Initializing');
//Adiciona as transicoes dos estados
lState := lStateMachine.FindState('Initializing');
lTransition := lState.NewOutgoingTransition('READY');
lTransition.SourceState := lState;
lTransition.TargetState := lStateMachine.FindState('UseCaseSubmachine');
lTransition.AddTrigger('READY');
lState := lStateMachine.FindState('UseCaseSubmachine');
lTransition := lState.NewOutgoingTransition('ABORT');
lTransition.SourceState := lState;
lTransition.TargetState := lStateMachine.FindState('smBase_FinalState');
lTransition.AddTrigger('UM_ABORT','4');
lTransition.AddEffect('EFFECT_Abort');
lTransition := lState.NewOutgoingTransition('TIMEOUTCHECK');
lTransition.SourceState := lState;
lTransition.TargetState := lState;
lTransition.AddTrigger('RM_TIMEOUT_CHECK','16');
lTransition.AddEffect('EFFECT_TimeOutCheck');
lTransition := lState.NewOutgoingTransition('GETTRIGGERSFROMCURRENTSTATE');
lTransition.SourceState := lState;
lTransition.TargetState := lState;
lTransition.AddTrigger('RM_GET_TRIGGERS_FROM_CURRENT_STATE');
lTransition.AddEffect('EFFECT_GetTriggersFromCurrentState');
lTransition := lState.NewOutgoingTransition('GETXSDBYTRIGGERFROMCURRENTSTATE');
lTransition.SourceState := lState;
lTransition.TargetState := lState;
lTransition.AddTrigger('RM_GET_XSD_BY_TRIGGER_FROM_CURRENT_STATE');
lTransition.AddEffect('EFFECT_GetXSDByTriggerFromCurrentState');
// SUBSTATEMACHINE smucBuscarEmprestimos ///////////////////////
lStateMachine := lUseCaseTicket.FindStateMachine('smServer');
lStateMachine := utSubMachineState(lStateMachine.FindState('UseCaseSubmachine')).StateMachine as acUseCaseStateMachine;
lStateMachine.Name := 'smucBuscarEmprestimos';
utState.Create(lStateMachine, 'Executando');
utFinalState.Create(lStateMachine, 'FinalState1');
//Define o InitialState do StateMachine
lStateMachine.InitialState := lStateMachine.FindState('Executando');
//Adiciona as transicoes dos estados
lState := lStateMachine.FindState('Executando');
lTransition := lState.NewOutgoingTransition('RM_BUSCAR_EMPRESTIMOS');
lTransition.SourceState := lState;
lTransition.TargetState := lState;
lTransition.AddTrigger('RM_BUSCAR_EMPRESTIMOS');
lTransition.AddEffect('Effect_BuscarEmprestimos');
lTransition.XsdIn.XML := GetXSDIn_3223_smucBuscarEmprestimos_Executando_RM_BUSCAR_EMPRESTIMOS;
lTransition.XsdOut.XML := GetXSDOut_3223_smucBuscarEmprestimos_Executando_RM_BUSCAR_EMPRESTIMOS;
lTransition := lState.NewOutgoingTransition('RM_SAIR');
lTransition.SourceState := lState;
lTransition.TargetState := lStateMachine.FindState('FinalState1');
lTransition.AddTrigger('RM_SAIR');
lTransition.AddEffect('Effect_Sair');
end;
procedure RegisterModelMappings(piMetaModel: acMetaModel);
......
......@@ -4,7 +4,7 @@ unit nguEmprestimo;
interface
uses
acuframework, utuMessage;
utuStateMachine, utuRequest, ucuUseCase, acuFramework,utuMessage;
type
ngEmprestimo = class(acPersistentObject)
......
<?xml version="1.0"?>
<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SYSMSG">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="Cliente">
<xs:complexType>
<xs:attribute name="CPF" type="xs:string" use="optional"/>
<xs:attribute name="Nome" type="xs:string" use="optional"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0"?>
<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SYSMSG">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element minOccurs="1" maxOccurs="1" name="Emprestimos">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="Emprestimo">
<xs:complexType>
<xs:sequence minOccurs="2" maxOccurs="2">
<xs:element name="Cliente">
<xs:complexType>
<xs:attribute name="Nome" type="xs:string" use="required"/>
<xs:attribute name="CPF" type="xs:string" use="required"/>
<xs:attribute name="OID" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Exemplar">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="Livro">
<xs:complexType>
<xs:attribute name="Nome" type="xs:string" use="required"/>
<xs:attribute name="Titulo" type="xs:string" use="required"/>
<xs:attribute name="Autor" type="xs:string" use="required"/>
<xs:attribute name="OID" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Codigo" type="xs:string" use="required"/>
<xs:attribute name="OID" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Retirada" type="xs:date" use="required"/>
<xs:attribute name="PrevistaDev" type="xs:date" use="required"/>
<xs:attribute name="DataDev" type="xs:date" use="optional"/>
<xs:attribute name="OID" type="xs:int" use="required"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:schema>
unit ucuBuscarEmprestimos;
interface
uses
utuStateMachine, utuRequest, ucuUseCase, acuFramework;
type
ucBuscarEmprestimos = class(ucUseCase)
public
procedure Initialize; Override;
procedure Finalize; Override;
published
procedure Effect_BuscarEmprestimos(piRequest: utRequest; piTransition: utTransition);
end;
implementation
uses
ucuManager,
utuMessage {define utField},
utuEmprestimoOQL,
acuObject {define acEnumerator},
nguExemplar,
nguLivro,
nguSituacaoExemplar,
nguEmprestimo,
nguCliente,
dateUtils;
procedure ucBuscarEmprestimos.Initialize;
begin
inherited;
end;
procedure ucBuscarEmprestimos.Finalize;
begin
inherited;
end;
procedure ucBuscarEmprestimos.Effect_BuscarEmprestimos(piRequest: utRequest; piTransition: utTransition);
var
lFieldEmprestimos,
lFieldEmprestimo,
lFieldExemplar,
lFieldLivro,
lFieldCliente: utField;
lEmprestimo: ngEmprestimo;
lExemplar: ngExemplar;
lLivro: ngLivro;
lCliente: ngCliente;
lOQL: IObterEmprestimos;
lListaEmprestimos: acPersistentObjectList;
lEnumEmprestimo: acEnumerator;
begin
lFieldCliente := piRequest.Message.RootField.FieldByName('Cliente');
lOQL := utEmprestimoOQL.ObterEmprestimos(Self.Session);
lFieldEmprestimos:= piRequest.Response.RootField.AddField('Emprestimos');
lListaEmprestimos := acPersistentObjectList.Create(ngEmprestimo);
try
if lFieldCliente.HasAttribute('Nome')
then lOQL.Param_nome.Value := lFieldCliente.AttributeByName('Nome').AsString
else lOQL.Param_nome.SetNull;
if lFieldCliente.HasAttribute('CPF')
then lOQL.Param_cpf.Value := lFieldCliente.AttributeByName('CPF').AsString
else lOQL.Param_cpf.SetNull;
lOQL.LoadList(lListaEmprestimos);
lEnumEmprestimo := acEnumerator.Create(lListaEmprestimos);
try
while not lEnumEmprestimo.EOL do
begin
lEmprestimo := lEnumEmprestimo.Current as ngEmprestimo;
lExemplar := lEmprestimo.Exemplar.Partner as ngExemplar;
lLivro := lExemplar.Livro.Partner as ngLivro;
lCliente := lEmprestimo.Cliente.Partner as ngCliente;
lFieldEmprestimo := lFieldEmprestimos.AddField('Emprestimo');
lFieldCliente := lFieldEmprestimo.AddField('Cliente');
lFieldExemplar := lFieldEmprestimo.AddField('Exemplar');
lFieldLivro := lFieldExemplar.AddField('Livro');
lEmprestimo.toXML(lFieldEmprestimo);
lCliente.toXML(lFieldCliente);
lExemplar.toXML(lFieldExemplar);
lLivro.toXML(lFieldLivro);
lEnumEmprestimo.MoveNext;
end;
finally
lEnumEmprestimo.Free;
end;
finally
lListaEmprestimos.Free;
end;
piRequest.Processed := True;
end;
initialization
gucManager.RegisterClass(3223,ucBuscarEmprestimos);
end.
......@@ -11,6 +11,11 @@ type
function Param_cpf: acOQLParamString;
end;
IObterEmprestimos = interface(IOQLQuery)
function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString;
end;
IObterExemplares = interface(IOQLQuery)
function Param_titulo: acOQLParamString;
function Param_codigo: acOQLParamString;
......@@ -18,6 +23,7 @@ type
utEmprestimoOQL = class
class function ObterClientes(piSessao: acPersistenceSession): IObterClientes;
class function ObterEmprestimos(piSessao: acPersistenceSession): IObterEmprestimos;
class function ObterExemplares(piSessao: acPersistenceSession): IObterExemplares;
end;
......@@ -30,6 +36,11 @@ type
function Param_cpf: acOQLParamString;
end;
TObterEmprestimos = class(acOQLQuery, IObterEmprestimos)
function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString;
end;
TObterExemplares = class(acOQLQuery, IObterExemplares)
function Param_titulo: acOQLParamString;
function Param_codigo: acOQLParamString;
......@@ -47,6 +58,18 @@ begin
result := acOQLParamString(Self.ParamByName('cpf'));
end;
{ TObterEmprestimos }
function TObterEmprestimos.Param_nome: acOQLParamString;
begin
result := acOQLParamString(Self.ParamByName('nome'));
end;
function TObterEmprestimos.Param_cpf: acOQLParamString;
begin
result := acOQLParamString(Self.ParamByName('cpf'));
end;
{ TObterExemplares }
function TObterExemplares.Param_titulo: acOQLParamString;
......@@ -70,6 +93,15 @@ begin
' AND (ngCliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL)');
end;
class function utEmprestimoOQL.ObterEmprestimos(piSessao: acPersistenceSession): IObterEmprestimos;
begin
result := TObterEmprestimos.Create(pisessao,
'SELECT ngEmprestimo' + #13#10 +
'FROM ngEmprestimo' + #13#10 +
'WHERE (ngEmprestimo.Cliente.Nome LIKE ''%''+?nome:acString+''%'' OR ?nome:acString IS NULL)' + #13#10 +
' AND (ngEmprestimo.Cliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL)');
end;
class function utEmprestimoOQL.ObterExemplares(piSessao: acPersistenceSession): IObterExemplares;
begin
result := TObterExemplares.Create(pisessao,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment