diff --git a/src/main/java/org/dependencytrack/persistence/ComponentQueryManager.java b/src/main/java/org/dependencytrack/persistence/ComponentQueryManager.java index 7a902cb2c..68079092b 100644 --- a/src/main/java/org/dependencytrack/persistence/ComponentQueryManager.java +++ b/src/main/java/org/dependencytrack/persistence/ComponentQueryManager.java @@ -200,7 +200,7 @@ public PaginatedResult getComponents(final Project project, final boolean includ if (RepositoryType.UNSUPPORTED != type) { final RepositoryMetaComponent repoMetaComponent = getRepositoryMetaComponent(type, purl.getNamespace(), purl.getName()); component.setRepositoryMeta(repoMetaComponent); - component.setComponentMetaInformation(QueryManager.getMetaInformation(purl, component.getUuid())); + component.setComponentMetaInformation(getMetaInformation(purl, component.getUuid())); } } } @@ -332,7 +332,7 @@ public PaginatedResult getComponents(ComponentIdentity identity, Project project if (RepositoryType.UNSUPPORTED != type) { final RepositoryMetaComponent repoMetaComponent = getRepositoryMetaComponent(type, purl.getNamespace(), purl.getName()); component.setRepositoryMeta(repoMetaComponent); - component.setComponentMetaInformation(QueryManager.getMetaInformation(purl, component.getUuid())); + component.setComponentMetaInformation(getMetaInformation(purl, component.getUuid())); } } } diff --git a/src/main/java/org/dependencytrack/persistence/QueryManager.java b/src/main/java/org/dependencytrack/persistence/QueryManager.java index 2633151ca..88a9036db 100644 --- a/src/main/java/org/dependencytrack/persistence/QueryManager.java +++ b/src/main/java/org/dependencytrack/persistence/QueryManager.java @@ -1401,8 +1401,8 @@ public T detachWithGroups(final T object, final List fetchGroups) { * * @param clazz Class of the object to fetch * @param uuids {@link UUID} list of uuids to fetch + * @param Type of the object * @return The list of objects found - * @param Type of the object * @since 4.9.0 */ public List getObjectsByUuids(final Class clazz, final List uuids) { @@ -1415,8 +1415,8 @@ public List getObjectsByUuids(final Class clazz, final List uuid * * @param clazz Class of the object to fetch * @param uuids {@link UUID} list of uuids to fetch + * @param Type of the object * @return The query to execute - * @param Type of the object * @since 4.9.0 */ public Query getObjectsByUuidsQuery(final Class clazz, final List uuids) { @@ -1521,6 +1521,7 @@ public void recursivelyDeleteTeam(Team team) { /** * Returns a list of all {@link DependencyGraphResponse} objects by {@link Component} UUID. + * * @param uuids a list of {@link Component} UUIDs * @return a list of {@link DependencyGraphResponse} objects * @since 4.9.0 @@ -1531,6 +1532,7 @@ public List getComponentDependencyGraphByUuids(final Li /** * Returns a list of all {@link DependencyGraphResponse} objects by {@link ServiceComponent} UUID. + * * @param uuids a list of {@link ServiceComponent} UUIDs * @return a list of {@link DependencyGraphResponse} objects * @since 4.9.0 @@ -1541,6 +1543,7 @@ public List getServiceDependencyGraphByUuids(final List /** * Returns a list of all {@link RepositoryMetaComponent} objects by {@link RepositoryQueryManager.RepositoryMetaComponentSearch} with batchSize 10. + * * @param list a list of {@link RepositoryQueryManager.RepositoryMetaComponentSearch} * @return a list of {@link RepositoryMetaComponent} objects * @since 4.9.0 @@ -1551,7 +1554,8 @@ public List getRepositoryMetaComponentsBatch(final List /** * Returns a list of all {@link RepositoryMetaComponent} objects by {@link RepositoryQueryManager.RepositoryMetaComponentSearch} UUID. - * @param list a list of {@link RepositoryQueryManager.RepositoryMetaComponentSearch} + * + * @param list a list of {@link RepositoryQueryManager.RepositoryMetaComponentSearch} * @param batchSize the batch size * @return a list of {@link RepositoryMetaComponent} objects * @since 4.9.0 @@ -1835,21 +1839,18 @@ public IntegrityAnalysis getIntegrityAnalysisByComponentUuid(UUID uuid) { return getIntegrityAnalysisQueryManager().getIntegrityAnalysisByComponentUuid(uuid); } - public static ComponentMetaInformation getMetaInformation(PackageURL purl, UUID uuid) { + public ComponentMetaInformation getMetaInformation(PackageURL purl, UUID uuid) { Date publishedAt = null; Date lastFetched = null; IntegrityMatchStatus integrityMatchStatus = null; - - try (QueryManager queryManager = new QueryManager()) { - final IntegrityMetaComponent integrityMetaComponent = queryManager.getIntegrityMetaComponent(purl.toString()); - final IntegrityAnalysis integrityAnalysis = queryManager.getIntegrityAnalysisByComponentUuid(uuid); - if (integrityMetaComponent != null) { - publishedAt = integrityMetaComponent.getPublishedAt(); - lastFetched = integrityMetaComponent.getLastFetch(); - } - if (integrityAnalysis != null) { - integrityMatchStatus = integrityAnalysis.getIntegrityCheckStatus(); - } + final IntegrityMetaComponent integrityMetaComponent = getIntegrityMetaComponent(purl.toString()); + final IntegrityAnalysis integrityAnalysis = getIntegrityAnalysisByComponentUuid(uuid); + if (integrityMetaComponent != null) { + publishedAt = integrityMetaComponent.getPublishedAt(); + lastFetched = integrityMetaComponent.getLastFetch(); + } + if (integrityAnalysis != null) { + integrityMatchStatus = integrityAnalysis.getIntegrityCheckStatus(); } return new ComponentMetaInformation(publishedAt, integrityMatchStatus, lastFetched); } diff --git a/src/main/java/org/dependencytrack/resources/v1/ComponentResource.java b/src/main/java/org/dependencytrack/resources/v1/ComponentResource.java index ac3d33db1..04d475f1d 100644 --- a/src/main/java/org/dependencytrack/resources/v1/ComponentResource.java +++ b/src/main/java/org/dependencytrack/resources/v1/ComponentResource.java @@ -153,7 +153,7 @@ public Response getComponentByUuid( detachedComponent.setRepositoryMeta(repoMetaComponent); } if (includeIntegrityMetaData) { - detachedComponent.setComponentMetaInformation(QueryManager.getMetaInformation(component.getPurl(), component.getUuid())); + detachedComponent.setComponentMetaInformation(qm.getMetaInformation(component.getPurl(), component.getUuid())); } } } diff --git a/src/test/java/org/dependencytrack/persistence/QueryManagerTest.java b/src/test/java/org/dependencytrack/persistence/QueryManagerTest.java index a36f7483e..589cce019 100644 --- a/src/test/java/org/dependencytrack/persistence/QueryManagerTest.java +++ b/src/test/java/org/dependencytrack/persistence/QueryManagerTest.java @@ -42,7 +42,7 @@ public void testGetMetaInformation() { integrityMetaComponent.setStatus(FetchStatus.PROCESSED); qm.createIntegrityMetaComponent(integrityMetaComponent); component = qm.createComponent(component, false); - ComponentMetaInformation componentMetaInformation = QueryManager.getMetaInformation(component.getPurl(), component.getUuid()); + ComponentMetaInformation componentMetaInformation = qm.getMetaInformation(component.getPurl(), component.getUuid()); Assert.assertEquals(HASH_MATCH_PASSED, componentMetaInformation.integrityMatchStatus()); Assert.assertEquals(integrityMetaComponent.getPublishedAt(), componentMetaInformation.publishedDate()); Assert.assertEquals(integrityMetaComponent.getLastFetch(), componentMetaInformation.lastFetched()); diff --git a/src/test/java/org/dependencytrack/resources/v1/ComponentResourceTest.java b/src/test/java/org/dependencytrack/resources/v1/ComponentResourceTest.java index 6a800ba0a..99627f489 100644 --- a/src/test/java/org/dependencytrack/resources/v1/ComponentResourceTest.java +++ b/src/test/java/org/dependencytrack/resources/v1/ComponentResourceTest.java @@ -81,6 +81,7 @@ public void getComponentsDefaultRequestTest() { /** * Generate a project with different dependencies + * * @return A project with 1000 dpendencies:
    *
  • 200 outdated dependencies, 75 direct and 125 transitive
  • *
  • 800 recent dependencies, 25 direct, 775 transitive
  • @@ -94,9 +95,9 @@ private Project prepareProject() throws MalformedPackageURLException { Component component = new Component(); component.setProject(project); component.setGroup("component-group"); - component.setName("component-name-"+i); - component.setVersion(String.valueOf(i)+".0"); - component.setPurl(new PackageURL(RepositoryType.MAVEN.toString(), "component-group", "component-name-"+i , String.valueOf(i)+".0", null, null)); + component.setName("component-name-" + i); + component.setVersion(String.valueOf(i) + ".0"); + component.setPurl(new PackageURL(RepositoryType.MAVEN.toString(), "component-group", "component-name-" + i, String.valueOf(i) + ".0", null, null)); component = qm.createComponent(component, false); // direct depencencies if (i < 100) { @@ -109,17 +110,17 @@ private Project prepareProject() throws MalformedPackageURLException { final var metaComponent = new RepositoryMetaComponent(); metaComponent.setRepositoryType(RepositoryType.MAVEN); metaComponent.setNamespace("component-group"); - metaComponent.setName("component-name-"+i); - metaComponent.setLatestVersion(String.valueOf(i+1)+".0"); + metaComponent.setName("component-name-" + i); + metaComponent.setLatestVersion(String.valueOf(i + 1) + ".0"); metaComponent.setLastCheck(new Date()); qm.persist(metaComponent); - } else if (i<500) { + } else if (i < 500) { // 300 recent components, 25 of these are direct dependencies final var metaComponent = new RepositoryMetaComponent(); metaComponent.setRepositoryType(RepositoryType.MAVEN); metaComponent.setNamespace("component-group"); - metaComponent.setName("component-name-"+i); - metaComponent.setLatestVersion(String.valueOf(i)+".0"); + metaComponent.setName("component-name-" + i); + metaComponent.setLatestVersion(String.valueOf(i) + ".0"); metaComponent.setLastCheck(new Date()); qm.persist(metaComponent); } else {