Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: mehab <[email protected]>
  • Loading branch information
mehab committed Oct 20, 2023
1 parent dec7141 commit 32c9de2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/org/dependencytrack/persistence/QueryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,8 @@ public <T> T detachWithGroups(final T object, final List<String> fetchGroups) {
*
* @param clazz Class of the object to fetch
* @param uuids {@link UUID} list of uuids to fetch
* @param <T> Type of the object
* @return The list of objects found
* @param <T> Type of the object
* @since 4.9.0
*/
public <T> List<T> getObjectsByUuids(final Class<T> clazz, final List<UUID> uuids) {
Expand All @@ -1415,8 +1415,8 @@ public <T> List<T> getObjectsByUuids(final Class<T> clazz, final List<UUID> uuid
*
* @param clazz Class of the object to fetch
* @param uuids {@link UUID} list of uuids to fetch
* @param <T> Type of the object
* @return The query to execute
* @param <T> Type of the object
* @since 4.9.0
*/
public <T> Query<T> getObjectsByUuidsQuery(final Class<T> clazz, final List<UUID> uuids) {
Expand Down Expand Up @@ -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
Expand All @@ -1531,6 +1532,7 @@ public List<DependencyGraphResponse> 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
Expand All @@ -1541,6 +1543,7 @@ public List<DependencyGraphResponse> 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
Expand All @@ -1551,7 +1554,8 @@ public List<RepositoryMetaComponent> 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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void getComponentsDefaultRequestTest() {

/**
* Generate a project with different dependencies
*
* @return A project with 1000 dpendencies: <ul>
* <li>200 outdated dependencies, 75 direct and 125 transitive</li>
* <li>800 recent dependencies, 25 direct, 775 transitive</li>
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 32c9de2

Please sign in to comment.