Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
public interface CACredentialRepository extends JpaRepository<CertificateAuthorityCredential, UUID> {

/**
* Query that retrieves a list of certificate authority credentials using the provided archive flag.
* Query that retrieves a count of certificate authority credentials in the database filtered by the provided
* archive flag.
*
* @param archiveFlag archive flag
* @return a list of certificate authority credentials
* @return a count of certificate authority credentials
*/
List<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was originally used to retrieve all entries from the repository and then count them using .size(). Since its only purpose was to get the total number of entries, it was replaced with countBy…, which performs a direct count query in the database, making it more efficient.

long countByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of certificate authority credentials using the provided archive
* flag and the provided pageable.
* Query that retrieves a page of certificate authority credentials filtered by the specified archive flag,
* sorted by create time in descending order.
*
* @param archiveFlag archive flag
* @param pageable pageable
* @return a page of certificate authority credentials
*/
Page<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderByCreateTimeDesc(boolean archiveFlag, Pageable pageable);

/**
* Query that retrieves a list of certificate authority credentials using the provided subject.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hirs.attestationca.persist.entity.manager;

import hirs.attestationca.persist.entity.userdefined.Device;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -15,4 +17,13 @@ public interface DeviceRepository extends JpaRepository<Device, UUID> {
* @return a device
*/
Device findByName(String deviceName);

/**
* Query that retrieves a page of all devices using the provided pageable value sorted in descending order by their
* creation time.
*
* @param pageable pageable
* @return a page of all devices sorted in descending order by their creation time
*/
Page<Device> findAllByOrderByCreateTimeDesc(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,22 @@
public interface EndorsementCredentialRepository extends JpaRepository<EndorsementCredential, UUID> {

/**
* Query that retrieves a list of endorsement credentials using the provided archive flag.
* Query that retrieves a count of endorsement credentials in the database filtered by the provided archive flag.
*
* @param archiveFlag archive flag
* @return a list of endorsement credentials
* @return a count of endorsement credentials
*/
List<EndorsementCredential> findByArchiveFlag(boolean archiveFlag);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was originally used to retrieve all entries from the repository and then count them using .size(). Since its only purpose was to get the total number of entries, it was replaced with countBy…, which performs a direct count query in the database, making it more efficient.

long countByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of endorsement credentials using provided archive flag and pageable value.
* Query that retrieves a page of endorsement credentials filtered by the specified archive flag,
* sorted by create time in descending order.
*
* @param archiveFlag archive flag
* @param pageable pageable value
* @return a page of endorsement credentials
*/
Page<EndorsementCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);

/**
* Query that retrieves an endorsement credential using the provided holder serial number.
*
* @param holderSerialNumber big integer representation of the holder serial number
* @return an endorsement credential
*/
EndorsementCredential findByHolderSerialNumber(BigInteger holderSerialNumber);
Page<EndorsementCredential> findByArchiveFlagOrderByCreateTimeDesc(boolean archiveFlag, Pageable pageable);

/**
* Query that retrieves an endorsement credential using the provided serial number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,26 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface IDevIDCertificateRepository extends JpaRepository<IDevIDCertificate, UUID> {

/**
* Query that retrieves a list of IDevId certificates using the provided archive flag.
* Query that retrieves a count of IDevId certificates in the database filtered by the provided archive flag.
*
* @param archiveFlag archive flag
* @return a list of IDevId certificates
* @return a count of idevid certificates
*/
List<IDevIDCertificate> findByArchiveFlag(boolean archiveFlag);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was originally used to retrieve all entries from the repository and then count them using .size(). Since its only purpose was to get the total number of entries, it was replaced with countBy…, which performs a direct count query in the database, making it more efficient.

long countByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of IDevId certificates using the provided archive flag and pageable value.
* Query that retrieves a page of IDevId certificates filtered by the specified archive flag,
* sorted by create time in descending order.
*
* @param archiveFlag archive flag
* @param pageable pageable value
* @return a page of IDevId certificates
*/
Page<IDevIDCertificate> findByArchiveFlag(boolean archiveFlag, Pageable pageable);


// /**
// * Query that retrieves a list of IDevId certificates using the provided subject.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed unused repository methods.

// *
// * @param subject string representation of the subject
// * @return a list of IDevId certificates
// */
// List<IDevIDCertificate> findBySubject(String subject);
//
// /**
// * Query that retrieves a sorted list of IDevId certificates using the provided subject.
// *
// * @param subject string representation of the subject
// * @return a sorted list of IDevId certificates
// */
// List<IDevIDCertificate> findBySubjectSorted(String subject);
//
// /**
// * Query that retrieves a list of IDevId certificates using the provided subject and archive flag.
// *
// * @param subject string representation of the subject
// * @param archiveFlag archive flag
// * @return a list of IDevId certificates
// */
// List<IDevIDCertificate> findBySubjectAndArchiveFlag(String subject, boolean archiveFlag);
//
// /**
// * Query that retrieves a sorted list of IDevId certificates using the provided subject
// * and archive flag.
// *
// * @param subject string representation of the subject
// * @param archiveFlag archive flag
// * @return a sorted list of IDevId certificates
// */
// List<IDevIDCertificate> findBySubjectSortedAndArchiveFlag(String subject, boolean archiveFlag);
//
// /**
// * Query that retrieves an IDevId certificate using the provided subject key identifier.
// *
// * @param subjectKeyIdentifier byte representation of the subject key identifier
// * @return an IDevId certificate
// */
// IDevIDCertificate findBySubjectKeyIdentifier(byte[] subjectKeyIdentifier);
//
// /**
// * Query that retrieves an IDevId certificate using the provided subject key and archive flag.
// *
// * @param subjectKeyIdString string representation of the subject key id
// * @param archiveFlag archive flag
// * @return an IDevId certificate
// */
// IDevIDCertificate findBySubjectKeyIdStringAndArchiveFlag(String subjectKeyIdString,
// boolean archiveFlag);
Page<IDevIDCertificate> findByArchiveFlagOrderByCreateTimeDesc(boolean archiveFlag, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
public interface IssuedCertificateRepository extends JpaRepository<IssuedAttestationCertificate, UUID> {

/**
* Query that retrieves a list of issued attestation certificates using the provided archive flag.
* Query that retrieves a count of issued certificates in the database filtered by the provided archive flag.
*
* @param archiveFlag archive flag
* @return a list of issued attestation certificates
* @return a count of issued certificates
*/
List<IssuedAttestationCertificate> findByArchiveFlag(boolean archiveFlag);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was originally used to retrieve all entries from the repository and then count them using .size(). Since its only purpose was to get the total number of entries, it was replaced with countBy…, which performs a direct count query in the database, making it more efficient.

long countByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of issued attestation certificates using the provided archive flag
Expand All @@ -28,7 +28,7 @@ public interface IssuedCertificateRepository extends JpaRepository<IssuedAttesta
* @param pageable pageable value
* @return a page of issued attestation certificates
*/
Page<IssuedAttestationCertificate> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
Page<IssuedAttestationCertificate> findByArchiveFlagOrderByCreateTimeDesc(boolean archiveFlag, Pageable pageable);

/**
* Query that retrieves a list of issued attestation certificates using the provided device id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
public interface PlatformCertificateRepository extends JpaRepository<PlatformCredential, UUID> {

/**
* Query that retrieves a list of platform credentials using the provided archive flag.
* Query that retrieves a count of platform credentials in the database filtered by the provided archive flag.
*
* @param archiveFlag archive flag
* @return a list of platform credentials
* @return a count of platform credentials
*/
List<PlatformCredential> findByArchiveFlag(boolean archiveFlag);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was originally used to retrieve all entries from the repository and then count them using .size(). Since its only purpose was to get the total number of entries, it was replaced with countBy…, which performs a direct count query in the database, making it more efficient.

long countByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of platform credentials using the provided archive flag
* and pageable value.
* Query that retrieves a page of platform credentials filtered by the specified archive flag,
* sorted by create time in descending order.
*
* @param archiveFlag archive flag
* @param pageable pageable
* @return a page of platform credentials
*/
Page<PlatformCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
Page<PlatformCredential> findByArchiveFlagOrderByCreateTimeDesc(boolean archiveFlag, Pageable pageable);

/**
* Query that retrieves a list of platform credentials using the provided device id.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hirs.attestationca.persist.entity.manager;

import hirs.attestationca.persist.entity.userdefined.rim.ReferenceDigestValue;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -58,4 +60,14 @@ public interface ReferenceDigestValueRepository extends JpaRepository<ReferenceD
* @return a list of reference digest values
*/
List<ReferenceDigestValue> findByManufacturerAndModel(String manufacturer, String model);


/**
* Query that retrieves a page of all reference digest values using the provided pageable value sorted in
* descending order by their creation time.
*
* @param pageable pageable
* @return a page of all reference digest values sorted in descending order by their creation time
*/
Page<ReferenceDigestValue> findAllByOrderByCreateTimeDesc(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,21 @@ public interface ReferenceManifestRepository extends JpaRepository<ReferenceMani
List<ReferenceManifest> findByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of reference manifests using the provided archive flag and pageable value.
* Query that retrieves a count of reference manifests in the database filtered by the provided archive flag.
*
* @param archiveFlag archive flag
* @param pageable pageable
* @return a page of reference manifests
* @return a count of reference manifests
*/
Page<ReferenceManifest> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was originally used to retrieve all entries from the repository and then count them using .size(). Since its only purpose was to get the total number of entries, it was replaced with countBy…, which performs a direct count query in the database, making it more efficient.

long countByArchiveFlag(boolean archiveFlag);

/**
* Query that retrieves a page of base and support reference manifests and pageable value.
*
* @param pageable pageable
* @return a page of reference manifests
*/
@Query(value = "SELECT * FROM ReferenceManifest WHERE DTYPE IN "
+ "('BaseReferenceManifest', 'SupportReferenceManifest')", nativeQuery = true)
Page<ReferenceManifest> findAllBaseAndSupportRimsPageable(Pageable pageable);
+ "('BaseReferenceManifest', 'SupportReferenceManifest') "
+ "ORDER BY create_time DESC", nativeQuery = true)
Page<ReferenceManifest> findAllBaseAndSupportRimsPageableOrderByCreateTime(Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
package hirs.attestationca.persist.entity.manager;

import hirs.attestationca.persist.entity.userdefined.Device;
import hirs.attestationca.persist.entity.userdefined.SupplyChainValidationSummary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface SupplyChainValidationSummaryRepository
extends JpaRepository<SupplyChainValidationSummary, UUID> {

/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed unused methods.

* Query that retrieves a supply chain validation summary using the provided device.
*
* @param device device
* @return a supply chain validation summary
*/
SupplyChainValidationSummary findByDevice(Device device);

/**
* Query that retrieves a list of supply chain validation summaries where the archive flag is false.
*
* @return a list of supply chain validation summary
*/
List<SupplyChainValidationSummary> findByArchiveFlagFalse();
public interface SupplyChainValidationSummaryRepository extends JpaRepository<SupplyChainValidationSummary, UUID> {

/**
* Query that retrieves a page of supply chain validation summaries using the provided pageable value
* and where the archive flag is false.
* and where the archive flag is false, sorted by create time in descending order.
*
* @param pageable pageable
* @return a page of supply chain validation summary
*/
Page<SupplyChainValidationSummary> findByArchiveFlagFalse(Pageable pageable);
Page<SupplyChainValidationSummary> findByArchiveFlagFalseOrderByCreateTimeDesc(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.UUID;

/**
* A service layer class responsible for encapsulating all business logic related to the Device Page.
* Service class responsible for encapsulating all business logic related to the Device Page.
*/
@Service
@Log4j2
Expand Down Expand Up @@ -206,7 +206,7 @@ public Page<Device> findDevicesByGlobalAndColumnSpecificSearchTerm(
* @return a page of all devices
*/
public Page<Device> findAllDevices(final Pageable pageable) {
return this.deviceRepository.findAll(pageable);
return deviceRepository.findAllByOrderByCreateTimeDesc(pageable);
}

/**
Expand All @@ -215,7 +215,7 @@ public Page<Device> findAllDevices(final Pageable pageable) {
* @return total number of records in the device repository.
*/
public long findDeviceRepositoryCount() {
return this.deviceRepository.count();
return deviceRepository.count();
}

/**
Expand Down Expand Up @@ -275,7 +275,7 @@ private void addPlatformCredentialEntryToDeviceMap(final Device device,
final HashMap<String, Set<UUID>> certificatePropertyMap) {
// find all platform certificates associated with this device id
final List<PlatformCredential> platformCredentialList =
this.platformCertificateRepository.findByDeviceId(device.getId());
platformCertificateRepository.findByDeviceId(device.getId());

final String platformCredentialIdsKey = PlatformCredential.class.getSimpleName() + "Ids";

Expand All @@ -300,7 +300,7 @@ private void addEndorsementCredentialEntryToDeviceMap(final Device device,
final HashMap<String, Set<UUID>> certificatePropertyMap) {
// find all endorsement certificates associated with this device id
final List<EndorsementCredential> endorsementCredentialList =
this.endorsementCredentialRepository.findByDeviceId(device.getId());
endorsementCredentialRepository.findByDeviceId(device.getId());

final String endorsementCredentialIdsKey = EndorsementCredential.class.getSimpleName() + "Ids";

Expand All @@ -325,7 +325,7 @@ private void addIssuedCertificateEntryToDeviceMap(final Device device,
final HashMap<String, Set<UUID>> certificatePropertyMap) {
// find all issued certificates associated with this device id
final List<IssuedAttestationCertificate> issuedCertificateList =
this.issuedCertificateRepository.findByDeviceId(device.getId());
issuedCertificateRepository.findByDeviceId(device.getId());

final String issuedCertificatesIdsKey = IssuedAttestationCertificate.class.getSimpleName() + "Ids";

Expand Down
Loading
Loading