Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
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.
*
* @param archiveFlag archive flag
* @param pageable pageable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +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.
*
* @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);

/**
* 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,25 @@
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.
*
* @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);
}
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
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.
*
* @param archiveFlag archive flag
* @param pageable pageable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,19 @@ 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.
* Retrieves a paginated list of {@link ReferenceManifest} instances matching the specified subclass types.
*
* @param types the list of {@link ReferenceManifest} subclass types to include
* @param pageable pageable
* @return a page of reference manifests
* @return a page of matching {@link ReferenceManifest} instances
*/
@Query(value = "SELECT * FROM ReferenceManifest WHERE DTYPE IN "
+ "('BaseReferenceManifest', 'SupportReferenceManifest')", nativeQuery = true)
Page<ReferenceManifest> findAllBaseAndSupportRimsPageable(Pageable pageable);
Page<ReferenceManifest> findByClassIn(List<Class<? extends ReferenceManifest>> types, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
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
Expand Down
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.findAll(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
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import java.util.List;

/**
* A service layer class responsible for encapsulating all business logic related to the Endorsement
* Credentials Page.
* Service class responsible for encapsulating all business logic related to the Endorsement Credentials Page.
*/
@Log4j2
@Service
@Log4j2
public class EndorsementCredentialPageService {
private final EndorsementCredentialRepository endorsementCredentialRepository;

Expand All @@ -28,8 +27,7 @@ public class EndorsementCredentialPageService {
* @param endorsementCredentialRepository endorsement credential repository
*/
@Autowired
public EndorsementCredentialPageService(
final EndorsementCredentialRepository endorsementCredentialRepository) {
public EndorsementCredentialPageService(final EndorsementCredentialRepository endorsementCredentialRepository) {
this.endorsementCredentialRepository = endorsementCredentialRepository;
}

Expand All @@ -42,7 +40,7 @@ public EndorsementCredentialPageService(
*/
public Page<EndorsementCredential> findEndorsementCredentialsByArchiveFlag(final boolean archiveFlag,
final Pageable pageable) {
return this.endorsementCredentialRepository.findByArchiveFlag(archiveFlag, pageable);
return endorsementCredentialRepository.findByArchiveFlag(archiveFlag, pageable);
}

/**
Expand All @@ -51,7 +49,7 @@ public Page<EndorsementCredential> findEndorsementCredentialsByArchiveFlag(final
* @return total number of records in the endorsement credential repository.
*/
public long findEndorsementCredentialRepositoryCount() {
return this.endorsementCredentialRepository.findByArchiveFlag(false).size();
return endorsementCredentialRepository.countByArchiveFlag(false);
}

/**
Expand All @@ -71,8 +69,8 @@ public EndorsementCredential parseEndorsementCredential(final MultipartFile file
try {
fileBytes = file.getBytes();
} catch (IOException ioEx) {
final String failMessage = String.format(
"Failed to read uploaded endorsement credential file (%s): ", fileName);
final String failMessage =
String.format("Failed to read uploaded endorsement credential file (%s): ", fileName);
log.error(failMessage, ioEx);
errorMessages.add(failMessage + ioEx.getMessage());
return null;
Expand All @@ -81,26 +79,25 @@ public EndorsementCredential parseEndorsementCredential(final MultipartFile file
try {
return new EndorsementCredential(fileBytes);
} catch (IOException ioEx) {
final String failMessage = String.format(
"Failed to parse uploaded endorsement credential file (%s): ", fileName);
final String failMessage =
String.format("Failed to parse uploaded endorsement credential file (%s): ", fileName);
log.error(failMessage, ioEx);
errorMessages.add(failMessage + ioEx.getMessage());
return null;
} catch (DecoderException dEx) {
final String failMessage = String.format(
"Failed to parse uploaded endorsement credential pem file (%s): ", fileName);
final String failMessage =
String.format("Failed to parse uploaded endorsement credential pem file (%s): ", fileName);
log.error(failMessage, dEx);
errorMessages.add(failMessage + dEx.getMessage());
return null;
} catch (IllegalArgumentException iaEx) {
final String failMessage = String.format(
"Endorsement credential format not recognized(%s): ", fileName);
final String failMessage = String.format("Endorsement credential format not recognized(%s): ", fileName);
log.error(failMessage, iaEx);
errorMessages.add(failMessage + iaEx.getMessage());
return null;
} catch (IllegalStateException isEx) {
final String failMessage = String.format(
"Unexpected object while parsing endorsement credential %s ", fileName);
final String failMessage =
String.format("Unexpected object while parsing endorsement credential %s ", fileName);
log.error(failMessage, isEx);
errorMessages.add(failMessage + isEx.getMessage());
return null;
Expand Down
Loading
Loading