Testing out filtering

This commit is contained in:
Cyrus 2024-03-22 12:13:55 -04:00
parent 9ace6e15fa
commit 3e4fe50dc7
2 changed files with 21 additions and 18 deletions

View File

@ -15,6 +15,10 @@ public interface CACredentialRepository extends JpaRepository<CertificateAuthori
List<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag);
Page<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<CertificateAuthorityCredential> findBySubject(String subject);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderBySubjectAsc(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderBySubjectDesc(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderByIssuerAsc(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderByIssuerDesc(boolean archiveFlag, Pageable pageable);
List<CertificateAuthorityCredential> findBySubjectSorted(String subject);
List<CertificateAuthorityCredential> findBySubjectAndArchiveFlag(String subject, boolean archiveFlag);
List<CertificateAuthorityCredential> findBySubjectSortedAndArchiveFlag(String subject, boolean archiveFlag);

View File

@ -20,6 +20,7 @@ import hirs.attestationca.persist.entity.userdefined.certificate.attributes.Comp
import hirs.attestationca.persist.util.CredentialHelper;
import hirs.attestationca.portal.datatables.DataTableInput;
import hirs.attestationca.portal.datatables.DataTableResponse;
import hirs.attestationca.portal.datatables.Order;
import hirs.attestationca.portal.page.Page;
import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.PageMessages;
@ -214,24 +215,9 @@ public class CertificatePageController extends PageController<NoPageParams> {
String orderColumnName = input.getOrderColumnName();
log.debug("Ordering on column: " + orderColumnName);
// check that the alert is not archived and that it is in the specified report
CriteriaModifier criteriaModifier = new CriteriaModifier() {
@Override
public void modify(final CriteriaQuery criteriaQuery) {
Session session = entityManager.unwrap(Session.class);
CriteriaBuilder cb = session.getCriteriaBuilder();
Root<Certificate> rimRoot = criteriaQuery.from(Reference.class);
criteriaQuery.select(rimRoot).distinct(true).where(cb.isNull(rimRoot.get(Certificate.ARCHIVE_FIELD)));
Order order = input.getOrder().get(0);
// add a device alias if this query includes the device table
// for getting the device (e.g. device name).
// use left join, since device may be null. Query will return all
// Certs of this type, whether it has a Device or not (device field may be null)
if (hasDeviceTableToJoin(certificateType)) {
// criteria.createAlias("device", "device", JoinType.LEFT_OUTER_JOIN);
}
}
};
int currentPage = input.getStart() / input.getLength();
Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
@ -289,7 +275,20 @@ public class CertificatePageController extends PageController<NoPageParams> {
return new DataTableResponse<>(records, input);
} else if (certificateType.equals(TRUSTCHAIN)) {
FilteredRecordsList<CertificateAuthorityCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);;
if (orderColumnName.equalsIgnoreCase("Issuer")) {
if (order.isAscending()) {
pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerAsc(false, paging);
} else {
pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerDesc(false, paging);
}
} else if (orderColumnName.equalsIgnoreCase("Subject")) {
if (order.isAscending()) {
pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectAsc(false, paging);
} else {
pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectDesc(false, paging);
}
}
if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent());