Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating code with search by resource type #27

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 56 additions & 15 deletions client/src/app/+search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
<input name="id" type="text" class="form-control" [(ngModel)]="filtro.id" placeholder="ID do Log">

<br><span>Data Início: </span><br>
<input name="dataInicio" type="datetime-local" class="input form-control primary-border" [(ngModel)]="dateStart"
placeholder="dd/mm/aaaa --:--">
<p-calendar name="dataInicio" dateFormat="dd.mm.yy" [(ngModel)]="dateStart" [maxDate]="dateEnd" [showTime]="true" [showIcon]="true"></p-calendar>


<br><span>Data Fim: </span><br>
<input name="dataFim" type="datetime-local" class="input form-control primary-border" [(ngModel)]="dateEnd"
placeholder="dd/mm/aaaa --:--">
<p-calendar name="dataFim" dateFormat="dd.mm.yy" [(ngModel)]="dateEnd" [minDate]="dateStart" [showTime]="true" [showIcon]="true"></p-calendar>

<br><span>Ip: </span><br>
<input name="ip" type="text" class="input form-control primary-border" [(ngModel)]="filtro.ip" placeholder="IP">

<br>Criticidade
<br><select name="securitySevel" class="form-control"
[(ngModel)]="filtro.securityLevel">

<br><br><select name="securitySevel" class="form-control"
[(ngModel)]="filtro.securityLevel">

<option value="" selected>---Criticidade---</option> <!-- not selected / blank option -->
<option value="">---Criticidade---</option> <!-- not selected / blank option -->
<option *ngFor="let crit of criticidades" value="{{crit}}"> {{crit}}</option>

</select>

<select name="applicationName" class="form-control"
[(ngModel)]="filtro.applicationName">
<br>Aplicação
<br><select name="applicationName" class="form-control"
[(ngModel)]="filtro.applicationName">

<option value="" selected>---Aplicação---</option> <!-- not selected / blank option -->
<option *ngFor="let aplic of aplicacoes" value="{{aplic}}"> {{aplic}}</option>
<option value="" selected>---Aplicação---</option> <!-- not selected / blank option -->
<option *ngFor="let aplic of aplicacoes" value="{{aplic}}" > {{aplic}}</option>

</select>
</select>

<br>Resource Types
<br><select name="resourceTypes" class="form-control"
Expand Down Expand Up @@ -76,14 +76,16 @@
<div class="container">
<div class="table-responsive tablescroll">


<p-dataTable [value]="eventos"
[rows]="10"
[paginator]="true"
[pageLinks]="3"
lazy="true"
[totalRecords]="totalRecords"
(onLazyLoad)="onLazyLoad($event)">
(onLazyLoad)="onLazyLoad($event)"
selectionMode="single"
[(selection)]="logSelecionado"
(dblclick)="showDialog()">
<p-header>Lista de Eventos</p-header>
<p-column field="id" header="ID"></p-column>
<p-column field="applicationName" header="Aplicação"></p-column>
Expand All @@ -101,6 +103,45 @@

</div>

<p-dialog header="Descrição do Log Selecionado" [(visible)]="display">
<table class="table display">
<thead>
<tr>
<th> ID</th>
<th> Aplicação</th>
<th> Usuário</th>
<th> Ação</th>
<th> Resource Type</th>
<th> Resource Id</th>
<th> Data e Hora</th>
<th> IP</th>
<th> Criticidade</th>
</tr>

</thead>
<tbody>
<tr>
<td> {{ logSelecionado.id }}</td>
<td> {{ logSelecionado.applicationName }}</td>
<td> {{ logSelecionado.userName }}</td>
<td> {{ logSelecionado.action }}</td>
<td> {{ logSelecionado.resource.resourceType }}</td>
<td> {{ logSelecionado.resource.resourceId }}</td>
<td> {{ logSelecionado.dateTime[2] + '/' + logSelecionado.dateTime[1] + '/' +
logSelecionado.dateTime[0] + ' ' + logSelecionado.dateTime[3] + ':' + logSelecionado.dateTime[4] +
':' + logSelecionado.dateTime[5]}}
</td>
<td> {{ logSelecionado.ip }}</td>
<td> {{ logSelecionado.securityLevel }}</td>

</tr>
</tbody>
<th> Descrição</th><br/>
<td> {{ logSelecionado.description}}</td>
</table>
</p-dialog>


<!-- Modal Descrição -->
<div id="details">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
Expand Down
8 changes: 7 additions & 1 deletion client/src/app/+search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
import {Http, Headers, Response} from '@angular/http';
import { saveAs } from 'file-saver';
import {AppService} from "../app.service";
import {Message} from 'primeng/primeng';
import {Dialog, Message} from 'primeng/primeng';
/**
* This class represents the lazy loaded AboutComponent.
*/
Expand All @@ -27,6 +27,9 @@ export class SearchComponent implements OnInit {
totalRecords = 0
rows = 100
down = false
selectedEvent
display: boolean = false;

constructor(private http: Http, private appService: AppService) {

}
Expand Down Expand Up @@ -115,4 +118,7 @@ export class SearchComponent implements OnInit {
}
});
}
showDialog() {
this.display = true;
}
}
3 changes: 2 additions & 1 deletion client/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BrowserAnimationsModule} from "@angular/platform-browser/animations"
import { ToolbarComponent } from './toolbar/index';
import { NavbarComponent } from './navbar/index';

import { CalendarModule, PaginatorModule, DataTableModule, GrowlModule, SharedModule as PShared } from "primeng/primeng"
import { CalendarModule, PaginatorModule, DataTableModule, GrowlModule, DialogModule, SharedModule as PShared } from "primeng/primeng"

/**
* Do not specify providers for modules that might be imported by a lazy loaded module.
Expand All @@ -27,6 +27,7 @@ import { CalendarModule, PaginatorModule, DataTableModule, GrowlModule, SharedMo
PaginatorModule,
DataTableModule,
GrowlModule,
DialogModule,
PShared
]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private Map<String, Object> deleteFilterDate(Map<String, Object> filtro){
if(pair.getKey() == "dateStart" || pair.getKey() == "dateEnd" || pair.getKey() == "timeStart" || pair.getKey() == "timeEnd") {
it.remove();
resp.remove(pair.getKey(), value);
System.out.println(pair.getKey() + " ---> " + pair.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public SearchResponse search(Map<String, Object> filtro, Long start, Long max,
}

public List<String> listApplicationNames() {
return em.createQuery("SELECT distinct e.applicationName from AuditEvent e").getResultList();
return em.createQuery("SELECT distinct e.applicationName from AuditEvent e order by e.applicationName").getResultList();
}

public List<String> listResourceTypes(){
return em.createQuery("SELECT distinct e.resource.resourceType from AuditEvent e").getResultList();
return em.createQuery("SELECT distinct e.resource.resourceType from AuditEvent e order by e.resource.resourceType").getResultList();
}

private SearchResponse buildQuery(Map<String, Object> filtro,
Expand All @@ -68,11 +68,14 @@ private SearchResponse buildQuery(Map<String, Object> filtro,

List<Predicate> predicates = new ArrayList();


Iterator it = filtro.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
String key = (String) pair.getKey();
if (key == "action") {
if(key.equals("resourceType")){
predicates.add(cb.equal(root.get("resource").get(key), pair.getValue()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is better to be a like not equal. User should be able to search for a teach and return teacher or teachers

}else if (key.equals("action")) {
predicates.add(cb.like(root.get(key), pair.getValue() + "%"));
} else {
predicates.add(cb.equal(root.get(key), pair.getValue()));
Expand Down