Added finally touches to not display archived items. As well display

the correct count that doesn't include the archived items.  Also added
additional exception checks after testing uploading the wrong element to
the wrong /list page
This commit is contained in:
Cyrus 2023-11-14 08:54:08 -05:00
parent cfb30d9a4b
commit 861508c0ef
8 changed files with 31 additions and 29 deletions

View File

@ -60,9 +60,10 @@ public abstract class ArchivableEntity extends AbstractEntity {
* false is archived time is already set, signifying the entity has been archived.
*/
public final boolean archive() {
this.archiveFlag = !archiveFlag;
this.archiveFlag = false;
if (this.archivedTime == null) {
this.archivedTime = new Date();
archiveFlag = true;
return true;
}
return false;
@ -112,6 +113,7 @@ public abstract class ArchivableEntity extends AbstractEntity {
if (this.archivedTime != null) {
this.archivedTime = null;
this.archivedDescription = null;
archiveFlag = false;
return true;
}
return false;

View File

@ -1,8 +1,9 @@
package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.CertificateAuthorityCredential;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -11,9 +12,8 @@ import java.util.UUID;
@Repository
public interface CACredentialRepository extends JpaRepository<CertificateAuthorityCredential, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='CertificateAuthorityCredential' AND archiveFlag=false", nativeQuery = true)
@Override
List<CertificateAuthorityCredential> findAll();
List<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag);
Page<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<CertificateAuthorityCredential> findBySubject(String subject);
List<CertificateAuthorityCredential> findBySubjectSorted(String subject);
CertificateAuthorityCredential findBySubjectKeyIdentifier(byte[] subjectKeyIdentifier);

View File

@ -1,9 +1,9 @@
package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.EndorsementCredential;
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.math.BigInteger;
@ -13,9 +13,8 @@ import java.util.UUID;
@Repository
public interface EndorsementCredentialRepository extends JpaRepository<EndorsementCredential, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='EndorsementCredential' AND archiveFlag=false", nativeQuery = true)
@Override
List<EndorsementCredential> findAll();
List<EndorsementCredential> findByArchiveFlag(boolean archiveFlag);
Page<EndorsementCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
EndorsementCredential findByHolderSerialNumber(BigInteger holderSerialNumber);
List<EndorsementCredential> findByDeviceId(UUID deviceId);
}

View File

@ -1,8 +1,9 @@
package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.IssuedAttestationCertificate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -11,8 +12,7 @@ import java.util.UUID;
@Repository
public interface IssuedCertificateRepository extends JpaRepository<IssuedAttestationCertificate, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='IssuedAttestationCertificate' AND archiveFlag=false", nativeQuery = true)
@Override
List<IssuedAttestationCertificate> findAll();
List<IssuedAttestationCertificate> findByArchiveFlag(boolean archiveFlag);
Page<IssuedAttestationCertificate> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<IssuedAttestationCertificate> findByDeviceId(UUID deviceId);
}

View File

@ -1,8 +1,9 @@
package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -11,8 +12,7 @@ import java.util.UUID;
@Repository
public interface PlatformCertificateRepository extends JpaRepository<PlatformCredential, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='PlatformCredential' AND archiveFlag=false", nativeQuery = true)
@Override
List<PlatformCredential> findAll();
List<PlatformCredential> findByArchiveFlag(boolean archiveFlag);
Page<PlatformCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<PlatformCredential> findByDeviceId(UUID deviceId);
}

View File

@ -43,5 +43,6 @@ public interface ReferenceManifestRepository extends JpaRepository<ReferenceMani
List<SupportReferenceManifest> getSupportByManufacturerModel(String manufacturer, String model);
@Query(value = "SELECT * FROM ReferenceManifest WHERE platformModel = ?1 AND DTYPE = 'EventLogMeasurements'", nativeQuery = true)
EventLogMeasurements getLogByModel(String model);
List<ReferenceManifest> findByArchiveFlag(boolean archiveFlag);
Page<ReferenceManifest> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
}

View File

@ -235,7 +235,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
// serial number. (pc.HolderSerialNumber = ec.SerialNumber)
if (certificateType.equals(PLATFORMCREDENTIAL)) {
FilteredRecordsList<PlatformCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<PlatformCredential> pagedResult = this.platformCertificateRepository.findAll(paging);
org.springframework.data.domain.Page<PlatformCredential> pagedResult = this.platformCertificateRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent());
@ -244,7 +244,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength());
}
records.setRecordsFiltered(platformCertificateRepository.count());
records.setRecordsFiltered(platformCertificateRepository.findByArchiveFlag(false).size());
EndorsementCredential associatedEC;
if (!records.isEmpty()) {
@ -268,7 +268,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
return new DataTableResponse<>(records, input);
} else if (certificateType.equals(ENDORSEMENTCREDENTIAL)) {
FilteredRecordsList<EndorsementCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<EndorsementCredential> pagedResult = this.endorsementCredentialRepository.findAll(paging);
org.springframework.data.domain.Page<EndorsementCredential> pagedResult = this.endorsementCredentialRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent());
@ -277,13 +277,13 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength());
}
records.setRecordsFiltered(endorsementCredentialRepository.count());
records.setRecordsFiltered(endorsementCredentialRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input);
} else if (certificateType.equals(TRUSTCHAIN)) {
FilteredRecordsList<CertificateAuthorityCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findAll(paging);
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent());
@ -292,13 +292,13 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength());
}
records.setRecordsFiltered(caCredentialRepository.count());
records.setRecordsFiltered(caCredentialRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input);
} else if (certificateType.equals(ISSUEDCERTIFICATES)) {
FilteredRecordsList<IssuedAttestationCertificate> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<IssuedAttestationCertificate> pagedResult = this.issuedCertificateRepository.findAll(paging);
org.springframework.data.domain.Page<IssuedAttestationCertificate> pagedResult = this.issuedCertificateRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent());
@ -307,7 +307,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength());
}
records.setRecordsFiltered(issuedCertificateRepository.count());
records.setRecordsFiltered(issuedCertificateRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input);
@ -821,7 +821,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
log.error(failMessage, dEx);
messages.addError(failMessage + dEx.getMessage());
return null;
} catch (IllegalArgumentException iaEx) {
} catch (IllegalArgumentException | IllegalStateException iaEx) {
final String failMessage = String.format(
"Certificate format not recognized(%s): ", fileName);
log.error(failMessage, iaEx);

View File

@ -133,7 +133,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
records.setRecordsTotal(input.getLength());
}
records.setRecordsFiltered(referenceManifestRepository.count());
records.setRecordsFiltered(referenceManifestRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input);
@ -413,7 +413,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
baseRims.add(baseRim);
}
}
} catch (IOException ioEx) {
} catch (IOException | NullPointerException ioEx) {
final String failMessage
= String.format("Failed to parse uploaded file (%s): ", fileName);
log.error(failMessage, ioEx);