Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Compiled Bug Fixes from the October Muse Bug Bash #287

Merged
merged 25 commits into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,14 +27,17 @@ public ApiTokenAuthenticationToken(Object principal, Object credentials,
super.setAuthenticated(true);
}

@Override
public Object getCredentials() {
return this.credentials;
}

@Override
public Object getPrincipal() {
return this.principal;
}


@Override
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
if (isAuthenticated) {
throw new IllegalArgumentException(
Expand Down
Expand Up @@ -22,6 +22,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ApiTokenRequestFilter extends AbstractAuthenticationProcessingFilter {

Expand All @@ -36,6 +37,7 @@ public ApiTokenRequestFilter(String path, AuthenticationManager authManager, Aut
setFilterProcessesUrl(path);
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest) req;
Expand All @@ -60,8 +62,8 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
String authHeader = request.getHeader("Authorization");

String encodedAuthStr = authHeader.substring(authHeader.indexOf(" "), authHeader.length());
byte[] encodedAuthbytes = encodedAuthStr.getBytes();
String decodedAuthStr = new String(Base64.decodeBase64(encodedAuthbytes));
byte[] encodedAuthbytes = encodedAuthStr.getBytes(StandardCharsets.UTF_8);
String decodedAuthStr = new String(Base64.decodeBase64(encodedAuthbytes), StandardCharsets.UTF_8);
String decodedAuthJson = decodedAuthStr.substring(decodedAuthStr.indexOf(":") + 1, decodedAuthStr.length());

JSONParser jsonParser = new JSONParser();
Expand Down
Expand Up @@ -12,6 +12,7 @@
@Component
public class DefaultRestOperationsSupplier implements RestOperationsSupplier {

@Override
public RestOperations get() {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(Integer.getInteger(HygieiaRestConnection.REST_CONNECT_TIMEOUT, 5000));
Expand Down
Expand Up @@ -64,7 +64,7 @@ public Map<ObjectId, Set<ObjectId>> processGenericItems(List<String> toolServers
gci.setProcessTime(System.currentTimeMillis());
genericCollectorItemRepository.save(gci);
});
return collectorItemBuildIds;
return Collections.unmodifiableMap(collectorItemBuildIds);
nescohen marked this conversation as resolved.
Show resolved Hide resolved
}

public abstract Map<String, Object> getGenericCollectorItemOptions(String serverUrl, GenericCollectorItem genericCollectorItem);
Expand Down
Expand Up @@ -107,6 +107,7 @@ protected String getMappingBasePackage() {
return com.capitalone.dashboard.model.Application.class.getPackage().getName();
}

@Override
@Bean
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongo(), getDatabaseName());
Expand Down
Expand Up @@ -128,7 +128,7 @@ private boolean allTagsMatch(List<NameValue> tags2) {
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
if (o == null || !(o instanceof CloudConfig))
return false;

CloudConfig that = (CloudConfig) o;
Expand Down
Expand Up @@ -117,9 +117,9 @@ private void processBuild(Build build) {
*/
Map<String, PipelineCommit> commitStageCommits = pipeline.getCommitsByEnvironmentName(PipelineStage.COMMIT.getName());
Map<String, PipelineCommit> buildStageCommits = pipeline.getCommitsByEnvironmentName(PipelineStage.BUILD.getName());
for (String rev : commitStageCommits.keySet()) {
PipelineCommit commit = commitStageCommits.get(rev);
if ((commit.getScmCommitTimestamp() < build.getStartTime()) && !buildStageCommits.containsKey(rev) && isMoveCommitToBuild(build, commit, commitRepository)) {
for (Map.Entry<String, PipelineCommit> e : commitStageCommits.entrySet()) {
PipelineCommit commit = e.getValue();
if ((commit.getScmCommitTimestamp() < build.getStartTime()) && !buildStageCommits.containsKey(e.getKey()) && isMoveCommitToBuild(build, commit, commitRepository)) {
pipeline.addCommit(PipelineStage.BUILD.getName(), commit);
}
}
Expand Down Expand Up @@ -154,13 +154,4 @@ private List<Dashboard> findAllDashboardsForBuild(Build build) {
}
return dashboards;
}


private CollectorItem getCollectorItem(ObjectId id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming these are unused private methods please confirm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above ^

return collectorItemRepository.findOne(id);
}

private Collector getCollector(ObjectId id) {
return collectorRepository.findOne(id);
}
}
Expand Up @@ -188,9 +188,9 @@ private void addCommitsToEnvironmentStage(EnvironmentComponent environmentCompon
*/
Map<String, PipelineCommit> commitStageCommits = pipeline.getCommitsByEnvironmentName(PipelineStage.COMMIT.getName());
Map<String, PipelineCommit> envStageCommits = pipeline.getCommitsByEnvironmentName(pseudoEnvName);
for (String rev : commitStageCommits.keySet()) {
PipelineCommit commit = commitStageCommits.get(rev);
if ((commit.getScmCommitTimestamp() < build.getStartTime()) && !envStageCommits.containsKey(rev) && PipelineUtils.isMoveCommitToBuild(build, commit, commitRepository)) {
for (Map.Entry<String, PipelineCommit> e : commitStageCommits.entrySet()) {
PipelineCommit commit = e.getValue();
if ((commit.getScmCommitTimestamp() < build.getStartTime()) && !envStageCommits.containsKey(e.getKey()) && PipelineUtils.isMoveCommitToBuild(build, commit, commitRepository)) {
pipeline.addCommit(pseudoEnvName, commit);
}
}
Expand Down
@@ -1,5 +1,10 @@
package com.capitalone.dashboard.event;

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;

import com.capitalone.dashboard.model.Collector;
import com.capitalone.dashboard.model.CollectorItem;
import com.capitalone.dashboard.model.CollectorType;
Expand All @@ -9,10 +14,6 @@
import com.capitalone.dashboard.repository.CollectorItemRepository;
import com.capitalone.dashboard.repository.CollectorRepository;
import com.capitalone.dashboard.repository.PipelineRepository;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;

import java.util.List;

public abstract class HygieiaMongoEventListener<T> extends AbstractMongoEventListener<T> {

Expand Down Expand Up @@ -43,6 +44,9 @@ private Collector getProductCollector(){
*/
protected CollectorItem getTeamDashboardCollectorItem(Dashboard teamDashboard) {
ObjectId productCollectorId = getProductCollector().getId();
if(productCollectorId == null) {
throw new Error("productCollectorId is null");
}
ObjectId dashboardId = teamDashboard.getId();
return collectorItemRepository.findTeamDashboardCollectorItemsByCollectorIdAndDashboardId(productCollectorId, dashboardId.toString());
}
Expand All @@ -54,6 +58,7 @@ protected CollectorItem getTeamDashboardCollectorItem(Dashboard teamDashboard) {
*/
protected Pipeline getOrCreatePipeline(Dashboard teamDashboard) {
CollectorItem teamDashboardCollectorItem = getTeamDashboardCollectorItem(teamDashboard);

return getOrCreatePipeline(teamDashboardCollectorItem);
}

Expand Down
Expand Up @@ -34,7 +34,7 @@ public RelatedCollectorItemEventListener(
public void onAfterSave(AfterSaveEvent<RelatedCollectorItem> event) {
RelatedCollectorItem relatedCollectorItem = event.getSource();
try {
syncDashboard.sync(relatedCollectorItem,!(Reason.ARTIFACT_REASON.getAction().equalsIgnoreCase(relatedCollectorItem.getReason())));
syncDashboard.sync(relatedCollectorItem,!Reason.ARTIFACT_REASON.getAction().equalsIgnoreCase(relatedCollectorItem.getReason()));
} catch (SyncException e) {
LOG.error("Error processing related collector item. ID = " + relatedCollectorItem.getId() + ". Reason " + e.getMessage());
}
Expand Down
Expand Up @@ -5,7 +5,7 @@ public enum Reason {
CODEQUALITY_TRIGGERED_REASON("Code scan triggered by build"),
ARTIFACT_REASON ("Artifact pushed by build");

private String action;
private final String action;

public String getAction() {
return action;
Expand Down
Expand Up @@ -241,7 +241,7 @@ public void sync(Build build) {
//create a list of the repo collector items that are being built, most cases have only 1
if (CollectionUtils.isEmpty(repos)) return;
CollectionUtils.filter(repos, PredicateUtils.notNullPredicate());
repos.forEach((
repos.forEach(
repoBranch -> {
Map<String, Object> options = new HashMap<>();
options.put("url", repoBranch.getUrl());
Expand All @@ -250,7 +250,7 @@ public void sync(Build build) {
}
repoCollectorItemsInBuild.addAll(IterableUtils.toList(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(options, scmCollectorIds)));

}));
});

repoCollectorItemsInBuild.forEach(rci->{
rci.setEnabled(true);
Expand Down
Expand Up @@ -76,7 +76,7 @@ public boolean equals(Object obj) {
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
if (!(obj instanceof ArtifactIdentifier))
return false;
ArtifactIdentifier other = (ArtifactIdentifier) obj;
if (classifier == null) {
Expand Down
Expand Up @@ -134,6 +134,7 @@ public void setResponseContentType(String responseContentType) {

public void setResponseTime(long responseTime) { this.responseTime = responseTime; }

@Override
public String toString() {
return "REST Request - " + "[" + this.method + "] [PARAMETERS:" + parameter + "] [APIUSER:" + apiUser + "] [BODY:" + requestBody + "] [REMOTE:" + client + "] [clientReference:" + clientReference + "] [STATUS:" + responseCode + "] [RESPONSE TIME:" + responseTime + "]";
}
Expand Down
@@ -1,13 +1,15 @@
package com.capitalone.dashboard.model;

import com.capitalone.dashboard.misc.HygieiaException;
import java.util.HashMap;
import java.util.Map;

import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;
import com.capitalone.dashboard.misc.HygieiaException;

/**
* Entry class to hold the Auto Discovered entries: Jira project, github project, build job etc.
Expand Down Expand Up @@ -93,7 +95,7 @@ public void setStatus(AutoDiscoveryStatusType status) {
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;
if (o == null || !(o instanceof AutoDiscoveredEntry)) return false;

AutoDiscoveredEntry that = (AutoDiscoveredEntry) o;

Expand Down
@@ -1,15 +1,15 @@
package com.capitalone.dashboard.model;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;

/**
* Binary artifacts produced by build jobs and stored in an artifact repository.
*
Expand Down Expand Up @@ -343,7 +343,7 @@ public int compare(BinaryArtifact o1, BinaryArtifact o2) {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
if (obj == null || !(obj instanceof BinaryArtifact))
return false;

BinaryArtifact that = (BinaryArtifact) obj;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/capitalone/dashboard/model/ChangeOrder.java
@@ -1,12 +1,13 @@
package com.capitalone.dashboard.model;

import java.lang.StringBuilder;
import java.util.Objects;

import org.bson.types.ObjectId;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Objects;

@Document(collection="changeorder")
public class ChangeOrder extends BaseModel{

Expand Down Expand Up @@ -184,7 +185,7 @@ public void setService(String service) {
public boolean equals(Object compareTo){
boolean doesEqual = true;

if(compareTo == null || !compareTo.getClass().isAssignableFrom(Incident.class)){
if (!(compareTo instanceof Incident)) {
doesEqual = false;
}else {
Incident newIncident = (Incident) compareTo;
Expand All @@ -205,11 +206,11 @@ public boolean equals(Object compareTo){
@Override
public String toString() {

StringBuffer buf = new StringBuffer(210);
buf.append("changeID: ")
StringBuilder builder = new StringBuilder(210);
builder.append("changeID: ")
.append(changeID);

return buf.toString();
return builder.toString();
}

@Override
Expand Down
Expand Up @@ -131,7 +131,7 @@ public void setNetworkOut(double networkOut) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (o == null || !(o instanceof CloudInstanceHistory)) return false;

CloudInstanceHistory that = (CloudInstanceHistory) o;

Expand Down
@@ -1,12 +1,12 @@
package com.capitalone.dashboard.model;


import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "cloud_volume")
public class CloudVolumeStorage extends BaseModel{
@Indexed
Expand Down Expand Up @@ -100,7 +100,7 @@ public List<String> getAttachInstances() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (o == null || !(o instanceof CloudVolumeStorage)) return false;

CloudVolumeStorage that = (CloudVolumeStorage) o;

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/capitalone/dashboard/model/Cmdb.java
Expand Up @@ -307,17 +307,16 @@ public int hashCode()
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
if (obj == null) {
return false;
}
if (getClass() != obj.getClass())
{
if (!(obj instanceof Cmdb)) {
return false;
}
final Cmdb other = (Cmdb) obj;
return Objects.equals(this.configurationItem, other.configurationItem)
&& Objects.equals(this.configurationKey, other.configurationKey)
&& Objects.equals(this.itemType, other.itemType)
&& Objects.equals(this.assignmentGroup, other.assignmentGroup)
&& Objects.equals(this.appServiceOwner, other.appServiceOwner)
&& Objects.equals(this.businessOwner, other.businessOwner)
Expand Down
Expand Up @@ -67,7 +67,7 @@ public void addInstance(Instance instance){
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (o == null || !(o instanceof CodeQualityMetric)) return false;

return name.equals(((CodeQualityMetric) o).name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/capitalone/dashboard/model/Feature.java
Expand Up @@ -542,7 +542,7 @@ public void setIssueLinks(Collection<FeatureIssueLink> issueLinks) {
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
if (o == null || !(o instanceof Feature))
return false;

Feature that = (Feature) o;
Expand Down
Expand Up @@ -4,7 +4,7 @@ public enum FeatureStatus {
BACKLOG("Backlog"), GROOMING("Grooming"), WAITING("Waiting"), IN_PROGRESS("In Progress"), IMPEDED(
"Impeded"), DONE("Done"), ACCEPTED("Accepted");

private String status;
private final String status;

FeatureStatus(String status) {
this.status = status;
Expand Down