Skip to content

Commit

Permalink
feat: allow searching of release manifests by advisory id or name
Browse files Browse the repository at this point in the history
  • Loading branch information
vibe13 committed Dec 19, 2024
1 parent 2b2657c commit dce92b5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ protected StringBuilder addConfigCondition(
return query;
}

protected StringBuilder addReleaseMetadataCondition(
StringBuilder query,
String condition,
String sbomAlias,
String property,
String operator) {
query.append(" ")
.append(condition)
.append(sbomAlias != null && sbomAlias.length() > 0 ? " " + sbomAlias + "." : " ")
.append("release_metadata ->> '")
.append(property)
.append("' ")
.append(operator)
.append(" :")
.append(property);
return query;
}

protected long executeCountQuery(String query, Map<String, Object> params) {
Query q = getEntityManager().createNativeQuery(query);
for (Map.Entry<String, Object> entry : params.entrySet()) {
Expand Down Expand Up @@ -291,13 +309,18 @@ public List<V1BaseBeta1RequestRecord> searchRequestRecords(QueryParameters param
});
}

private static final String RELEASE_METADATA_ERRATA_ID = "release.errata_id";
private static final String RELEASE_METADATA_ERRATA_FULLNAME = "release.errata_fullname";

private static final Set<String> ALLOWED_TYPE_KEYS = Set.of(
"id",
ErrataAdvisoryRequestConfig.TYPE_NAME,
ImageRequestConfig.TYPE_NAME,
PncAnalysisRequestConfig.TYPE_NAME,
PncBuildRequestConfig.TYPE_NAME,
PncOperationRequestConfig.TYPE_NAME);
PncOperationRequestConfig.TYPE_NAME,
RELEASE_METADATA_ERRATA_ID,
RELEASE_METADATA_ERRATA_FULLNAME);

private static final Map<String, Class<? extends RequestConfig>> TYPE_TO_CONFIG_CLASS = Map.of(
ImageRequestConfig.TYPE_NAME,
Expand Down Expand Up @@ -368,6 +391,16 @@ private Map<String, Object> filterAndBuildQueryParams(StringBuilder sb, String t
sb.append("WHERE re.id = :id");
return Map.of("id", typeValue);
}
if (RELEASE_METADATA_ERRATA_ID.equals(typeKey)) {
sb.append("WHERE s.release_metadata is not null");
addReleaseMetadataCondition(sb, "AND", "s", "errata_id", "=");
return Map.of("errata_id", typeValue);
}
if (RELEASE_METADATA_ERRATA_FULLNAME.equals(typeKey)) {
sb.append("WHERE s.release_metadata is not null");
addReleaseMetadataCondition(sb, "AND", "s", "errata_fullname", "=");
return Map.of("errata_fullname", typeValue);
}

String identifierKey = getValueOfField(TYPE_TO_CONFIG_CLASS.get(typeKey), "IDENTIFIER_KEY");
addConfigCondition(sb, "WHERE", REQUEST_CONFIG_TYPE, "=");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ public class RequestsV1Beta1 {
name = "Filter requests of events generated for the PNC analysis on the for the specified milestone"),
@ExampleObject(
value = "pnc-operation=BDQXCNRZJYYAA",
name = "Filter requests of events generated for the specified PNC operation") })
name = "Filter requests of events generated for the specified PNC operation"),
@ExampleObject(
value = "release.errata_id=1234",
name = "Filter requests of events generated for the specified Errata release by advisory id "),
@ExampleObject(
value = "release.errata_fullname=ERRATA",
name = "Filter requests of events generated for the specified Errata release by advisory name") })
@APIResponse(
responseCode = "200",
description = "The request event with all the manifest generated",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ protected StringBuilder addConfigCondition(
return query;
}

@Override
protected StringBuilder addReleaseMetadataCondition(
StringBuilder query,
String condition,
String sbomAlias,
String property,
String operator) {
query.append(" ")
.append(condition)
.append(
sbomAlias != null && sbomAlias.length() > 0 ? " JSON_EXTRACT(" + sbomAlias + "."
: " JSON_EXTRACT(")
.append("release_metadata, '$.")
.append(property)
.append("') ")
.append(operator)
.append(" :")
.append(property);
return query;
}

@Override
protected Instant convertFromTimestamp(Object rawTimeObject) {
OffsetDateTime offsetDateTime = (OffsetDateTime) rawTimeObject;
Expand Down

0 comments on commit dce92b5

Please sign in to comment.