01. DADOS GERAIS

Produto:

Linha de Produto:

Segmento:

Módulo:Sistema - Cadastro de Equipamentos
Função:Componente base para persistência e BiometricDevice
Ticket:
Requisito/Story/Issue (informe o requisito relacionado) :
  1. DLOGPORTOS-19451


02. SITUAÇÃO/REQUISITO

Para atender a necessidade de cadastro de equipamentos de coleta de dados biométricos foi implementada uma estrutura de componentes com persistência na base de dados onde pode ser salvo qualquer tipo de equipamento, bastando derivar da interface IDevice e utilizar a IPersistenceObject para gravar, recuperar, editar e excluir seus dados.

03. SOLUÇÃO

A implementação das interfaces estão nas seguintes units:

Que dependem dos seguintes elementos do framework de desenvolvimento:


São métodos expostos pela implementação da interface IPersistentObject:

  • function SetId(const Value: string): IPersistentObject;

São métodos expostos pela implementação da interface IPersistenceBase:

  • function SetId(const Value: string): IPersistenceBase; reintroduce;
  • function SetReference(const Value: string): IPersistenceBase;
  • function SetAttributes(const Value: TJSONObject): IPersistenceBase;
  • function SetActive(const Value: Boolean): IPersistenceBase;
  • function Load(const AId: string): IPersistenceBase; reintroduce; virtual; abstract;
  • function Save(out AReturn: Cardinal): IPersistenceBase; reintroduce; virtual; abstract;

São métodos expostos pela implementação da interface IPersistenceType:

  • function SetId(const Value: string): IPersistenceType; reintroduce;
  • function SetReference(const Value: string): IPersistenceType; reintroduce;
  • function SetAttributes(const Value: TJSONObject): IPersistenceType; reintroduce;
  • function SetActive(const Value: Boolean): IPersistenceType; reintroduce;
  • function Load(const AId: string): IPersistenceType; reintroduce;
  • function Save(out AReturn: Cardinal): IPersistenceType; reintroduce;
  • function SetConnection(const AConnection: IDBFullConfigConnection): IPersistenceType; reintroduce;

São métodos expostos pela implementação da interface IPersistenceObject:

  • function IsValid: Boolean;
  • function SetId(const Value: string): IPersistenceObject; reintroduce;
  • function SetObjectType(const Value: IPersistenceType): IPersistenceObject;
  • function SetReference(const Value: string): IPersistenceObject; reintroduce;
  • function Load(const AId: string): IPersistenceObject; reintroduce;
  • function Save(out AReturn: Cardinal): IPersistenceObject; reintroduce;
  • function SetConnection(const AConnection: IDBFullConfigConnection): IPersistenceObject; reintroduce;
  • function SetActive(const Value: Boolean): IPersistenceObject; reintroduce;
  • function SetObject(const AObject: IPersistentObject): IPersistenceObject;

São métodos expostos pela implementação da interface IDevice:

  • function SetId(const Value: string): IDevice; reintroduce;
  • function SetDescription(const Value: string): IDevice;
  • function SetManufacturer(const Value: string): IDevice;
  • function SetModel(const Value: string): IDevice;

São métodos expostos pela implementação da interface IBiometricDevice:

  • function SetId(const Value: string): IBiometricDevice; reintroduce;
  • function SetDescription(const Value: string): IBiometricDevice; reintroduce;
  • function SetManufacturer(const Value: string): IBiometricDevice; reintroduce;
  • function SetModel(const Value: string): IBiometricDevice; reintroduce;
  • function SetMode(const Value: TBiometricMode): IBiometricDevice;
  • function SetTemplateSize(const Value: Integer): IBiometricDevice;

São propriedades expostas pela implementação da interface IPersistentObject:

  • property Id: string read GetId write PutId;

São propriedades expostas pela implementação da interface IPersistenceBase:

  • property Reference: string read GetReference write PutReference;
  • property Attributes: TJSONObject read GetAttributes write PutAttributes;
  • property Active: Boolean read GetActive write PutActive;

São propriedades expostas pela implementação da interface IPersistenceType:

  • property Reference: string read GetReference write PutReference;
  • property Attributes: TJSONObject read GetAttributes write PutAttributes;
  • property Active: Boolean read GetActive write PutActive;

São propriedades expostas pela implementação da interface IPersistenceObject:

São propriedades expostas pela implementação da interface IPersistentObject:

São propriedades expostas pela implementação da interface IPersistentObject:

Para utilização da implementação da interface ICATRACABase em aplicações Delphi, segue o exemplo de uso deste componente.


Execução da ação de login:

procedure TComponentDebugger.btnSendToBiometriesClick(Sender: TObject);
var
  Request: TWebRequest;
  Response: TWebResponse;
  Return: THTTPCode;
  ResponseJSON: TJSONObject;

  procedure SetAccessDataInINI;
  var
    URL : string;
    Path: string;
  begin
    URL := string(cbxURL.Text).Replace('{personId}', edtPersonIdBiometries.Text, [rfReplaceAll]);
    Path := URL.Delete('http://localhost/api');
    TIniReader.Instance.OpenFile(FBasePath + BIOMETRIES_INI_FILE)
                       .Section['Extra Headers']
                       .WriteString('Url', URL)
                       .Root
                       .Section['CGI']
                       .WriteString('Logical Path', Path)
                       .WriteString('Physical Path', Path)
                       .UpdateFile;
  end;

  procedure SetRequestWithQueryParams;
  begin
    if chkWithParams.Checked then
    begin
      Request.QueryFields.Add(PAGE_PARAM.Format([edtPageBiometries.Text]));
      Request.QueryFields.Add(PAGE_SIZE_PARAM.Format([edtPageSizeBiometries.Text]));
    end;
  end;

  procedure SetRequest(const AIndex: Integer);
  begin
    if AIndex = 0 then
    begin
      SetRequestWithQueryParams;
    end;
  end;
begin
  SetAccessDataInINI;
  sedtResponse.Lines.Clear;
  Request := TWinCGIRequest.Create(FBasePath + BIOMETRIES_INI_FILE, FBasePath + CONTENT_FILE, FBasePath + OUTPUT_FILE);
  Response := TCGIResponse.Create(Request);
  SetRequest(cbxURL.ItemIndex);

  Return := TCATRACAFactory.Instance.GetObject(BIOMETRIES_CLASS_KEY).TreatRequest(FConnection
                                                                                , Request
                                                                                , Response);

  case Return.IsOkResult of
    True : Application.MessageBox(PWideChar(RESPONSE_MESSAGE.Format([Return.Code, Return.Message])), 'Informação', MB_OK or MB_ICONINFORMATION);
    False: Application.MessageBox(PWideChar(RESPONSE_MESSAGE.Format([Return.Code, Return.Message])), 'Erro', MB_OK or MB_ICONERROR);
  end;

  if Return <> hcNoContent then
  begin
    ResponseJSON := Response.Content.ToJSON;
    sedtResponse.Text := ResponseJSON.PrettyFormat(2);
    ResponseJSON.Free;
  end;

  Request.Free;
end;

Resultado esperado:

Os demais métodos retornam uma mensagem 204No content -, não possuindo retorno visível.


04. DEMAIS INFORMAÇÕES

Outras ações/ações relacionadas 

Por ser dependente do framework de desenvolvimento, os caminhos para os arquivos arquivos desta dependência devem estar presentes no projeto ao ser utilizado.

05. ASSUNTOS RELACIONADOS