All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.pmckeown.dependencytrack.finding.FindingsAction Maven / Gradle / Ivy

Go to download

Maven plugin to integrate with a Dependency Track server to submit dependency manifests and gather project metrics.

There is a newer version: 1.7.0
Show newest version
package io.github.pmckeown.dependencytrack.finding;

import io.github.pmckeown.dependencytrack.DependencyTrackException;
import io.github.pmckeown.dependencytrack.Response;
import io.github.pmckeown.dependencytrack.project.Project;
import io.github.pmckeown.util.Logger;
import kong.unirest.UnirestException;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Singleton
public class FindingsAction {

    private FindingsClient findingClient;

    private Logger logger;

    @Inject
    public FindingsAction(FindingsClient findingClient, Logger logger) {
        this.findingClient = findingClient;
        this.logger = logger;
    }

    List getFindings(Project project) throws DependencyTrackException {
        logger.info("Getting findings for project %s-%s", project.getName(), project.getVersion());

        try {
            Response> response = findingClient.getFindingsForProject(project);
            Optional> body = response.getBody();
            if (response.isSuccess()) {
                if (body.isPresent()) {
                    return body.get();
                } else {
                    logger.info("No findings available for project %s-%s", project.getName(),
                            project.getVersion());
                    return Collections.emptyList();
                }
            } else {
                throw new DependencyTrackException("Error received from server");
            }
        } catch (UnirestException ex) {
            logger.error(ex.getMessage());
            throw new DependencyTrackException(ex.getMessage());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy