diff --git a/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java b/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java index 6bd207e70406e5e49cb33470a356d5d522e53551..06124d34558f70c3300e90e05110e57f4eb88003 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java +++ b/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java @@ -15,6 +15,7 @@ import java.util.stream.Collectors; import javax.ws.rs.core.MultivaluedMap; import org.eclipsefoundation.git.eca.model.Commit; +import org.eclipsefoundation.git.eca.model.Project; import org.eclipsefoundation.git.eca.model.ValidationRequest; import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames; import org.jboss.resteasy.specimpl.MultivaluedMapImpl; @@ -63,10 +64,22 @@ public class CommitHelper { public static MultivaluedMap<String, String> getCommitParams(List<String> commitShas, String projectId, String repoUrl) { MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); params.put(GitEcaParameterNames.SHAS_RAW, commitShas); - params.add(GitEcaParameterNames.PROJECT_ID_RAW, projectId); params.add(GitEcaParameterNames.REPO_URL_RAW, repoUrl); + if (projectId != null) { + params.add(GitEcaParameterNames.PROJECT_ID_RAW, projectId); + } return params; } + + /** + * Centralized way of retrieving a checked project ID from a project for use when interacting with commits and commit data. + * + * @param p the current project to attempt to retrieve an ID from + * @return the project ID or the given default (empty string). + */ + public static String getProjectId(Project p) { + return p != null ? p.getProjectId() : ""; + } private CommitHelper() { } diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationService.java index cf117411d562d414920756ee81d2f8ba68e664fd..230bc2e4e7b3e8a597945ec07a59dd790776df10 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationService.java @@ -71,7 +71,7 @@ public class DefaultValidationService implements ValidationService { List<CommitValidationStatus> statuses, Project p) { // remove existing messaging RDBMSQuery<CommitValidationMessage> q = new RDBMSQuery<>(wrapper, filters.get(CommitValidationMessage.class), - CommitHelper.getCommitParams(req, p != null ? p.getProjectId() : null)); + CommitHelper.getCommitParams(req, CommitHelper.getProjectId(p))); List<CommitValidationMessage> messages = new ArrayList<>(); List<CommitValidationStatus> updatedStatuses = new ArrayList<>(); @@ -88,7 +88,7 @@ public class DefaultValidationService implements ValidationService { base = status.get(); } else { base = new CommitValidationStatus(); - base.setProject(p != null ? p.getProjectId() : null); + base.setProject(CommitHelper.getProjectId(p)); base.setCommitHash(e.getKey()); base.setProvider(req.getProvider()); base.setRepoUrl(req.getRepoUrl().toString());