com.synopsys.integration.blackduck.codelocation.CodeLocationBatchOutput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blackduck-common Show documentation
Show all versions of blackduck-common Show documentation
A library for using various capabilities of Black Duck, notably the REST API and signature scanning.
/*
* blackduck-common
*
* Copyright (c) 2023 Synopsys, Inc.
*
* Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide.
*/
package com.synopsys.integration.blackduck.codelocation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import com.synopsys.integration.util.NameVersion;
public abstract class CodeLocationBatchOutput implements Iterable {
private final Map successfulCodeLocationNamesToExpectedNotificationCounts;
private final List outputs = new ArrayList<>();
public CodeLocationBatchOutput(List outputs) {
successfulCodeLocationNamesToExpectedNotificationCounts =
outputs
.stream()
.peek(this.outputs::add)
.filter(output -> Result.SUCCESS == output.getResult())
.filter(output -> StringUtils.isNotBlank(output.getCodeLocationName()))
.collect(Collectors.toMap(CodeLocationOutput::getCodeLocationName, CodeLocationOutput::getExpectedNotificationCount));
}
public List getOutputs() {
return outputs;
}
public Optional getProjectAndVersion() {
return outputs
.stream()
.map(CodeLocationOutput::getProjectAndVersion)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
}
public Set getSuccessfulCodeLocationNames() {
return successfulCodeLocationNamesToExpectedNotificationCounts.keySet();
}
public int getExpectedNotificationCount() {
return successfulCodeLocationNamesToExpectedNotificationCounts
.values()
.stream()
.mapToInt(Integer::intValue)
.sum();
}
public boolean hasAnyFailures() {
return outputs
.stream()
.map(CodeLocationOutput::getResult)
.anyMatch(Result.FAILURE::equals);
}
@Override
public Iterator iterator() {
return outputs.iterator();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy