mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-04-21 09:31:14 +00:00
v3_issue_811: Fixed the display of count on the controller pages and fixed the filtering issue on rim database. all that's left is fixing up the validation summary pages device.name issue.
This commit is contained in:
parent
3d35eafa51
commit
aa38dc16b0
@ -13,8 +13,6 @@ import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -63,18 +61,18 @@ public class CertificateService {
|
||||
* Takes the provided column names, the search term that the user entered and attempts to find
|
||||
* certificates whose field values matches the provided search term.
|
||||
*
|
||||
* @param entityClass generic entity class
|
||||
* @param entityClass generic certificate entity class
|
||||
* @param searchableColumns list of the searchable column names
|
||||
* @param searchText text that was input in the search textbox
|
||||
* @param searchTerm text that was input in the search textbox
|
||||
* @param archiveFlag archive flag
|
||||
* @param pageable pageable
|
||||
* @param <T> generic entity class
|
||||
* @param <T> generic entity class that extends from certificate
|
||||
* @return page full of the generic certificates.
|
||||
*/
|
||||
public <T extends Certificate> Page<T> findCertificatesBySearchableColumnsAndArchiveFlag(
|
||||
final Class<T> entityClass,
|
||||
final List<String> searchableColumns,
|
||||
final String searchText,
|
||||
final String searchTerm,
|
||||
final boolean archiveFlag,
|
||||
final Pageable pageable) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
@ -84,32 +82,13 @@ public class CertificateService {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
// Dynamically add search conditions for each field that should be searchable
|
||||
if (!StringUtils.isBlank(searchText)) {
|
||||
if (!StringUtils.isBlank(searchTerm)) {
|
||||
// Dynamically loop through columns and create LIKE conditions for each searchable column
|
||||
for (String columnName : searchableColumns) {
|
||||
|
||||
// Get the attribute type from entity root
|
||||
Path<?> fieldPath = rootCertificate.get(columnName);
|
||||
|
||||
// if the field is a string type
|
||||
if (String.class.equals(fieldPath.getJavaType())) {
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(criteriaBuilder.lower(rootCertificate.get(columnName)),
|
||||
"%" + searchText.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
// if the field is a non-string type
|
||||
else {
|
||||
// convert the field to a string
|
||||
Expression<String> fieldAsString = criteriaBuilder
|
||||
.literal(fieldPath).as(String.class);
|
||||
|
||||
Predicate predicate = criteriaBuilder.like(
|
||||
criteriaBuilder.lower(fieldAsString),
|
||||
"%" + searchText.toLowerCase() + "%"
|
||||
);
|
||||
predicates.add(predicate);
|
||||
}
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(criteriaBuilder.lower(rootCertificate.get(columnName)),
|
||||
"%" + searchTerm.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,6 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -72,13 +70,13 @@ public class DeviceService {
|
||||
* devices whose field values matches the provided search term.
|
||||
*
|
||||
* @param searchableColumns list of the searchable column name
|
||||
* @param searchText text that was input in the search textbox
|
||||
* @param searchTerm text that was input in the search textbox
|
||||
* @param pageable pageable
|
||||
* @return page full of devices
|
||||
*/
|
||||
public Page<Device> findAllDevicesBySearchableColumns(
|
||||
final List<String> searchableColumns,
|
||||
final String searchText,
|
||||
final String searchTerm,
|
||||
final Pageable pageable) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Device> query =
|
||||
@ -89,32 +87,14 @@ public class DeviceService {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
// Dynamically add search conditions for each field that should be searchable
|
||||
if (!StringUtils.isBlank(searchText)) {
|
||||
if (!StringUtils.isBlank(searchTerm)) {
|
||||
// Dynamically loop through columns and create LIKE conditions for each searchable column
|
||||
for (String columnName : searchableColumns) {
|
||||
// Get the attribute type from entity root
|
||||
Path<?> fieldPath = deviceRoot.get(columnName);
|
||||
|
||||
// if the field is a string type
|
||||
if (String.class.equals(fieldPath.getJavaType())) {
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(deviceRoot.get(columnName)),
|
||||
"%" + searchText.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
// if the field is a non-string type
|
||||
else {
|
||||
// convert the field to a string
|
||||
Expression<String> fieldAsString = criteriaBuilder
|
||||
.literal(fieldPath).as(String.class);
|
||||
|
||||
Predicate predicate = criteriaBuilder.like(
|
||||
criteriaBuilder.lower(fieldAsString),
|
||||
"%" + searchText.toLowerCase() + "%"
|
||||
);
|
||||
predicates.add(predicate);
|
||||
}
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(deviceRoot.get(columnName)),
|
||||
"%" + searchTerm.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,6 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@ -86,14 +84,14 @@ public class ValidationSummaryReportsService {
|
||||
* validation summaries whose field values matches the provided search term.
|
||||
*
|
||||
* @param searchableColumns list of the searchable column name
|
||||
* @param searchText text that was input in the search textbox
|
||||
* @param searchTerm text that was input in the search textbox
|
||||
* @param archiveFlag archive flag
|
||||
* @param pageable pageable
|
||||
* @return page full of the validation summaries.
|
||||
*/
|
||||
public Page<SupplyChainValidationSummary> findValidationReportsBySearchableColumnsAndArchiveFlag(
|
||||
final List<String> searchableColumns,
|
||||
final String searchText,
|
||||
final String searchTerm,
|
||||
final boolean archiveFlag,
|
||||
final Pageable pageable) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
@ -105,7 +103,7 @@ public class ValidationSummaryReportsService {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
// Dynamically add search conditions for each field that should be searchable
|
||||
if (!StringUtils.isBlank(searchText)) {
|
||||
if (!StringUtils.isBlank(searchTerm)) {
|
||||
// Dynamically loop through columns and create LIKE conditions for each searchable column
|
||||
for (String columnName : searchableColumns) {
|
||||
|
||||
@ -115,35 +113,14 @@ public class ValidationSummaryReportsService {
|
||||
// field name
|
||||
// todo
|
||||
if (columnName.contains(".")) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// assuming the column name is not a nested entity field
|
||||
// Get the attribute type from entity root
|
||||
Path<?> fieldPath = supplyChainValidationSummaryRoot.get(columnName);
|
||||
|
||||
// if the field is a string type
|
||||
if (String.class.equals(fieldPath.getJavaType())) {
|
||||
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(supplyChainValidationSummaryRoot.get(columnName)),
|
||||
"%" + searchText.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
// if the field is a non-string type
|
||||
else {
|
||||
// convert the field to a string
|
||||
Expression<String> fieldAsString = criteriaBuilder
|
||||
.literal(fieldPath).as(String.class);
|
||||
|
||||
Predicate predicate = criteriaBuilder.like(
|
||||
criteriaBuilder.lower(fieldAsString),
|
||||
"%" + searchText.toLowerCase() + "%"
|
||||
);
|
||||
predicates.add(predicate);
|
||||
}
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(supplyChainValidationSummaryRoot.get(columnName)),
|
||||
"%" + searchTerm.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,37 +82,35 @@ public class DevicePageController extends PageController<NoPageParams> {
|
||||
String orderColumnName = input.getOrderColumnName();
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
// get all the devices
|
||||
FilteredRecordsList<Device> deviceList = new FilteredRecordsList<>();
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
org.springframework.data.domain.Page<Device> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult = this.deviceService.findAllDevices(pageable);
|
||||
} else {
|
||||
pagedResult = this.deviceService.findAllDevicesBySearchableColumns(searchableColumns, searchText,
|
||||
pagedResult = this.deviceService.findAllDevicesBySearchableColumns(searchableColumns, searchTerm,
|
||||
pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
deviceList.addAll(pagedResult.getContent());
|
||||
deviceList.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
deviceList.setRecordsTotal(input.getLength());
|
||||
}
|
||||
|
||||
deviceList.setRecordsFiltered(this.deviceService.findDeviceRepositoryCount());
|
||||
deviceList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
deviceList.setRecordsTotal(this.deviceService.findDeviceRepositoryCount());
|
||||
|
||||
FilteredRecordsList<HashMap<String, Object>> records
|
||||
FilteredRecordsList<HashMap<String, Object>> devicesAndAssociatedCertificates
|
||||
= this.deviceService.retrieveDevicesAndAssociatedCertificates(deviceList);
|
||||
|
||||
log.info("Returning the size of the list of devices: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of devices: {}", devicesAndAssociatedCertificates.size());
|
||||
return new DataTableResponse<>(devicesAndAssociatedCertificates, input);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,38 +105,39 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
FilteredRecordsList<EndorsementCredential> records = new FilteredRecordsList<>();
|
||||
FilteredRecordsList<EndorsementCredential> ekFilteredRecordsList =
|
||||
new FilteredRecordsList<>();
|
||||
|
||||
org.springframework.data.domain.Page<EndorsementCredential> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult = this.endorsementCredentialRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
pagedResult =
|
||||
this.certificateService.findCertificatesBySearchableColumnsAndArchiveFlag(
|
||||
EndorsementCredential.class,
|
||||
searchableColumns,
|
||||
searchText,
|
||||
searchTerm,
|
||||
false, pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
records.addAll(pagedResult.getContent());
|
||||
records.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
ekFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(endorsementCredentialRepository.findByArchiveFlag(false).size());
|
||||
ekFilteredRecordsList.setRecordsFiltered(
|
||||
pagedResult.getTotalElements());
|
||||
ekFilteredRecordsList.setRecordsTotal(findEndorsementCredentialRepositoryCount());
|
||||
|
||||
log.debug("Returning the size of the list of endorsement credentials: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.debug("Returning the size of the list of endorsement credentials: {}",
|
||||
ekFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(ekFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,6 +324,15 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the endorsement credential repository.
|
||||
*
|
||||
* @return total number of records in the endorsement credential repository.
|
||||
*/
|
||||
private long findEndorsementCredentialRepositoryCount() {
|
||||
return this.endorsementCredentialRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse the provided file in order to create an Endorsement Credential.
|
||||
*
|
||||
|
@ -104,16 +104,17 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
FilteredRecordsList<IDevIDCertificate> records = new FilteredRecordsList<>();
|
||||
FilteredRecordsList<IDevIDCertificate> idevidFilteredRecordsList =
|
||||
new FilteredRecordsList<>();
|
||||
org.springframework.data.domain.Page<IDevIDCertificate> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult =
|
||||
this.iDevIDCertificateRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
@ -121,21 +122,20 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
this.certificateService.findCertificatesBySearchableColumnsAndArchiveFlag(
|
||||
IDevIDCertificate.class,
|
||||
searchableColumns,
|
||||
searchText,
|
||||
searchTerm,
|
||||
false, pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
records.addAll(pagedResult.getContent());
|
||||
records.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
idevidFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(iDevIDCertificateRepository.findByArchiveFlag(false).size());
|
||||
idevidFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
idevidFilteredRecordsList.setRecordsTotal(findIDevIdCertificateRepositoryCount());
|
||||
|
||||
log.info("Returning the size of the list of IDEVID certificates: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of IDEVID certificates: {}"
|
||||
, idevidFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(idevidFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,6 +323,15 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the idevid certificate repository.
|
||||
*
|
||||
* @return total number of records in the idevid certificate repository.
|
||||
*/
|
||||
private long findIDevIdCertificateRepositoryCount() {
|
||||
return iDevIDCertificateRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse the provided file in order to create an IDevId Certificate.
|
||||
*
|
||||
|
@ -103,16 +103,17 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
FilteredRecordsList<IssuedAttestationCertificate> records = new FilteredRecordsList<>();
|
||||
FilteredRecordsList<IssuedAttestationCertificate> issuedCertificateFilteredRecordsList =
|
||||
new FilteredRecordsList<>();
|
||||
org.springframework.data.domain.Page<IssuedAttestationCertificate> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult =
|
||||
this.issuedCertificateRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
@ -120,21 +121,20 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
this.certificateService.findCertificatesBySearchableColumnsAndArchiveFlag(
|
||||
IssuedAttestationCertificate.class,
|
||||
searchableColumns,
|
||||
searchText,
|
||||
searchTerm,
|
||||
false, pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
records.addAll(pagedResult.getContent());
|
||||
records.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
issuedCertificateFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(issuedCertificateRepository.findByArchiveFlag(false).size());
|
||||
issuedCertificateFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
issuedCertificateFilteredRecordsList.setRecordsTotal(findIssuedCertificateRepoCount());
|
||||
|
||||
log.info("Returning the size of the list of issued certificates: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of issued certificates: {}"
|
||||
, issuedCertificateFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(issuedCertificateFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,9 +276,17 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the issued certificate repository.
|
||||
*
|
||||
* @return total number of records in the issued certificaterepository.
|
||||
*/
|
||||
private long findIssuedCertificateRepoCount() {
|
||||
return this.issuedCertificateRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
}
|
||||
|
@ -110,17 +110,17 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
FilteredRecordsList<PlatformCredential> records = new FilteredRecordsList<>();
|
||||
FilteredRecordsList<PlatformCredential> pcFilteredRecordsList = new FilteredRecordsList<>();
|
||||
|
||||
org.springframework.data.domain.Page<PlatformCredential> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult =
|
||||
this.platformCertificateRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
@ -128,24 +128,22 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
this.certificateService.findCertificatesBySearchableColumnsAndArchiveFlag(
|
||||
PlatformCredential.class,
|
||||
searchableColumns,
|
||||
searchText,
|
||||
searchTerm,
|
||||
false, pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
records.addAll(pagedResult.getContent());
|
||||
records.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
pcFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(platformCertificateRepository.findByArchiveFlag(false).size());
|
||||
pcFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
pcFilteredRecordsList.setRecordsTotal(findPlatformCredentialRepositoryCount());
|
||||
|
||||
EndorsementCredential associatedEC;
|
||||
|
||||
if (!records.isEmpty()) {
|
||||
if (!pcFilteredRecordsList.isEmpty()) {
|
||||
// loop all the platform credentials
|
||||
for (PlatformCredential pc : records) {
|
||||
for (PlatformCredential pc : pcFilteredRecordsList) {
|
||||
// find the EC using the PC's "holder serial number"
|
||||
associatedEC = this.endorsementCredentialRepository
|
||||
.findBySerialNumber(pc.getHolderSerialNumber());
|
||||
@ -159,8 +157,17 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Returning the size of the list of platform credentials: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of platform credentials: {}", pcFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(pcFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the platform credential repository.
|
||||
*
|
||||
* @return total number of records in the platform credential repository.
|
||||
*/
|
||||
private long findPlatformCredentialRepositoryCount() {
|
||||
return this.platformCertificateRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,8 +21,6 @@ import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@ -130,39 +128,43 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
String orderColumnName = input.getOrderColumnName();
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
FilteredRecordsList<ReferenceManifest> records = new FilteredRecordsList<>();
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
FilteredRecordsList<ReferenceManifest> rimFilteredRecordsList = new FilteredRecordsList<>();
|
||||
|
||||
org.springframework.data.domain.Page<ReferenceManifest> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult = this.referenceManifestRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
pagedResult = findRIMSBySearchableColumnsAndArchiveFlag(searchableColumns
|
||||
, searchText,
|
||||
, searchTerm,
|
||||
false,
|
||||
pageable);
|
||||
}
|
||||
|
||||
int rimCount = 0;
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
for (ReferenceManifest manifest : pagedResult.getContent()) {
|
||||
records.add(manifest);
|
||||
rimCount++;
|
||||
}
|
||||
records.setRecordsTotal(rimCount);
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
rimFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(referenceManifestRepository.findByArchiveFlag(false).size());
|
||||
rimFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
rimFilteredRecordsList.setRecordsTotal(findRIMRepoCount());
|
||||
|
||||
log.info("Returning the size of the list of reference manifests: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of reference manifests: {}", rimFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(rimFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the RIM repository.
|
||||
*
|
||||
* @return total number of records in the RIM repository.
|
||||
*/
|
||||
private long findRIMRepoCount() {
|
||||
return this.referenceManifestRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,12 +174,11 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
* @param attr the redirection attributes
|
||||
* @return the redirection view
|
||||
* @throws URISyntaxException if malformed URI
|
||||
* @throws Exception if malformed URI
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
protected RedirectView uploadRIMs(
|
||||
@RequestParam("file") final MultipartFile[] files,
|
||||
final RedirectAttributes attr) throws URISyntaxException, Exception {
|
||||
final RedirectAttributes attr) throws URISyntaxException {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
PageMessages messages = new PageMessages();
|
||||
String fileName;
|
||||
@ -365,14 +366,14 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
* RIMS whose field values matches the provided search term.
|
||||
*
|
||||
* @param searchableColumns list of the searchable column names
|
||||
* @param searchText text that was input in the search textbox
|
||||
* @param searchTerm text that was input in the search textbox
|
||||
* @param archiveFlag archive flag
|
||||
* @param pageable pageable
|
||||
* @return page full of reference manifests
|
||||
*/
|
||||
private org.springframework.data.domain.Page<ReferenceManifest> findRIMSBySearchableColumnsAndArchiveFlag(
|
||||
final List<String> searchableColumns,
|
||||
final String searchText,
|
||||
final String searchTerm,
|
||||
final boolean archiveFlag,
|
||||
final Pageable pageable) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
@ -382,32 +383,14 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
// Dynamically add search conditions for each field that should be searchable
|
||||
if (!StringUtils.isBlank(searchText)) {
|
||||
if (!StringUtils.isBlank(searchTerm)) {
|
||||
// Dynamically loop through columns and create LIKE conditions for each searchable column
|
||||
for (String columnName : searchableColumns) {
|
||||
// Get the attribute type from entity root
|
||||
Path<?> fieldPath = rimRoot.get(columnName);
|
||||
|
||||
// if the field is a string type
|
||||
if (String.class.equals(fieldPath.getJavaType())) {
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(rimRoot.get(columnName)),
|
||||
"%" + searchText.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
// if the field is a non-string type
|
||||
else {
|
||||
// convert the field to a string
|
||||
Expression<String> fieldAsString = criteriaBuilder
|
||||
.literal(fieldPath).as(String.class);
|
||||
|
||||
Predicate predicate = criteriaBuilder.like(
|
||||
criteriaBuilder.lower(fieldAsString),
|
||||
"%" + searchText.toLowerCase() + "%"
|
||||
);
|
||||
predicates.add(predicate);
|
||||
}
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(rimRoot.get(columnName)),
|
||||
"%" + searchTerm.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
@ -102,33 +101,31 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
String orderColumnName = input.getOrderColumnName();
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
FilteredRecordsList<ReferenceDigestValue> referenceDigestValues = new FilteredRecordsList<>();
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
org.springframework.data.domain.Page<ReferenceDigestValue> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult =
|
||||
this.referenceDigestValueRepository.findAll(pageable);
|
||||
} else {
|
||||
pagedResult =
|
||||
findReferenceDigestValuesBySearchableColumns(
|
||||
searchableColumns,
|
||||
searchText, pageable);
|
||||
searchTerm, pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
referenceDigestValues.addAll(pagedResult.getContent());
|
||||
referenceDigestValues.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
referenceDigestValues.setRecordsTotal(input.getLength());
|
||||
}
|
||||
|
||||
referenceDigestValues.setRecordsFiltered(referenceDigestValueRepository.count());
|
||||
referenceDigestValues.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
referenceDigestValues.setRecordsTotal(referenceDigestValueRepository.count());
|
||||
|
||||
// might be able to get rid of this, maybe right a query that looks for not updated
|
||||
SupportReferenceManifest support;
|
||||
@ -146,11 +143,11 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Returning the size of the list of TPM events: {}", referenceDigestValues.size());
|
||||
log.info("Returning the size of the list of reference digest values: {}"
|
||||
, pagedResult.getTotalElements());
|
||||
return new DataTableResponse<>(referenceDigestValues, input);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
@ -163,20 +160,19 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes the provided column names, the search term that the user entered and attempts to find
|
||||
* reference digest values whose field values matches the provided search term.
|
||||
*
|
||||
* @param searchableColumns list of the searchable column name
|
||||
* @param searchText text that was input in the search textbox
|
||||
* @param searchTerm text that was input in the search textbox
|
||||
* @param pageable pageable
|
||||
* @return page full of reference digest values
|
||||
*/
|
||||
private org.springframework.data.domain.Page<ReferenceDigestValue>
|
||||
findReferenceDigestValuesBySearchableColumns(
|
||||
final List<String> searchableColumns,
|
||||
final String searchText,
|
||||
final String searchTerm,
|
||||
final Pageable pageable) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ReferenceDigestValue> query =
|
||||
@ -187,7 +183,7 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
// Dynamically add search conditions for each field that should be searchable
|
||||
if (!StringUtils.isBlank(searchText)) {
|
||||
if (!StringUtils.isBlank(searchTerm)) {
|
||||
// Dynamically loop through columns and create LIKE conditions for each searchable column
|
||||
for (String columnName : searchableColumns) {
|
||||
// Get the attribute type from entity root
|
||||
@ -198,20 +194,19 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(referenceDigestValueRoot.get(columnName)),
|
||||
"%" + searchText.toLowerCase() + "%");
|
||||
"%" + searchTerm.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
// if the field is a non-string type
|
||||
else {
|
||||
// convert the field to a string
|
||||
Expression<String> fieldAsString = criteriaBuilder
|
||||
.literal(fieldPath).as(String.class);
|
||||
|
||||
Predicate predicate = criteriaBuilder.like(
|
||||
criteriaBuilder.lower(fieldAsString),
|
||||
"%" + searchText.toLowerCase() + "%"
|
||||
);
|
||||
predicates.add(predicate);
|
||||
else if (Integer.class.equals(fieldPath.getJavaType())) {
|
||||
// For Integer fields, use EQUAL if the search term is numeric
|
||||
try {
|
||||
Integer searchInteger = Integer.valueOf(searchTerm); // Will throw if not a number
|
||||
Predicate predicate = criteriaBuilder.equal(fieldPath, searchInteger);
|
||||
predicates.add(predicate);
|
||||
} catch (NumberFormatException e) {
|
||||
// If the searchTerm is not a valid number, skip this field
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,17 +143,18 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
FilteredRecordsList<CertificateAuthorityCredential> records = new FilteredRecordsList<>();
|
||||
FilteredRecordsList<CertificateAuthorityCredential> caFilteredRecordsList =
|
||||
new FilteredRecordsList<>();
|
||||
|
||||
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult =
|
||||
this.caCredentialRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
@ -161,22 +162,20 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
this.certificateService.findCertificatesBySearchableColumnsAndArchiveFlag(
|
||||
CertificateAuthorityCredential.class,
|
||||
searchableColumns,
|
||||
searchText,
|
||||
searchTerm,
|
||||
false, pageable);
|
||||
}
|
||||
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
records.addAll(pagedResult.getContent());
|
||||
records.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
caFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(caCredentialRepository.findByArchiveFlag(false).size());
|
||||
caFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
caFilteredRecordsList.setRecordsTotal(findTrustChainCertificateRepoCount());
|
||||
|
||||
log.info("Returning the size of the list of trust chain certificates: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of trust chain certificates: {}"
|
||||
, caFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(caFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,6 +389,15 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the certificate authority (trust chain) repository.
|
||||
*
|
||||
* @return total number of records in the certificate authority (trust chain) repository.
|
||||
*/
|
||||
private long findTrustChainCertificateRepoCount() {
|
||||
return this.caCredentialRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse the provided file in order to create a trust chain certificate.
|
||||
*
|
||||
|
@ -89,40 +89,40 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
||||
String orderColumnName = input.getOrderColumnName();
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchText = input.getSearch().getValue();
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
FilteredRecordsList<SupplyChainValidationSummary> records = new FilteredRecordsList<>();
|
||||
FilteredRecordsList<SupplyChainValidationSummary> reportsFilteredRecordsList =
|
||||
new FilteredRecordsList<>();
|
||||
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
|
||||
org.springframework.data.domain.Page<SupplyChainValidationSummary> pagedResult;
|
||||
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult =
|
||||
this.supplyChainValidatorSummaryRepository.findByArchiveFlagFalse(pageable);
|
||||
} else {
|
||||
pagedResult =
|
||||
this.validationSummaryReportsService.findValidationReportsBySearchableColumnsAndArchiveFlag(
|
||||
searchableColumns,
|
||||
searchText,
|
||||
searchTerm,
|
||||
false,
|
||||
pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
records.addAll(pagedResult.getContent());
|
||||
records.setRecordsTotal(pagedResult.getContent().size());
|
||||
} else {
|
||||
records.setRecordsTotal(input.getLength());
|
||||
reportsFilteredRecordsList.addAll(pagedResult.getContent());
|
||||
}
|
||||
|
||||
records.setRecordsFiltered(supplyChainValidatorSummaryRepository.count());
|
||||
reportsFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
reportsFilteredRecordsList.setRecordsTotal(this.supplyChainValidatorSummaryRepository.count());
|
||||
|
||||
log.info("Returning the size of the list of validation reports: {}", records.size());
|
||||
return new DataTableResponse<>(records, input);
|
||||
log.info("Returning the size of the list of validation reports: {}"
|
||||
, reportsFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(reportsFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user