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

org.conqat.engine.service.shared.data.FindingsServiceOptions Maven / Gradle / Ivy

There is a newer version: 2025.1.0
Show newest version
/*
 * Copyright (c) CQSE GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.conqat.engine.service.shared.data;

import org.conqat.engine.index.shared.CommitDescriptor;
import org.conqat.engine.service.shared.client.ServiceClientUris;
import org.conqat.lib.commons.collections.ListMap;

/**
 * Collects options for Teamscale's findings service into one place making it
 * easy for writing tests.
 */
public class FindingsServiceOptions {
	/**
	 * The uniform path for which findings should be retrieved. This can be either a
	 * concrete file or a container. In the latter case the recursive parameter can
	 * be used to specify whether sub-trees should be considered.
	 */
	private final String uniformPath;

	/**
	 * Optional commit descriptor (timestamp & branch info) at which findings should
	 * be retrieved.
	 */
	private final CommitDescriptor commitDescriptor;

	/** Optional baseline at which findings should be retrieved */
	private final String baseline;

	/** Optionally include (or not) findings in changed code */
	private final boolean includeChangedCodeFindings;

	/** Optionally limit findings to findings in changed code only */
	private final boolean onlyChangedCodeFindings;

	/** Optionally have Teamscale fetch all findings or not */
	private final boolean fetchAll;

	public FindingsServiceOptions(String uniformPath, CommitDescriptor commitDescriptor, String baseline,
			boolean includeChangedCodeFindings, boolean onlyChangedCodeFindings, boolean fetchAll) {
		this.uniformPath = uniformPath;
		this.commitDescriptor = commitDescriptor;
		this.baseline = baseline;
		this.includeChangedCodeFindings = includeChangedCodeFindings;
		this.onlyChangedCodeFindings = onlyChangedCodeFindings;
		this.fetchAll = fetchAll;
	}

	public FindingsServiceOptions(String uniformPath, CommitDescriptor commitDescriptor, String baseline,
			boolean includeChangedCodeFindings, boolean fetchAll) {
		this(uniformPath, commitDescriptor, baseline, includeChangedCodeFindings, false, fetchAll);
	}

	public FindingsServiceOptions(CommitDescriptor commitDescriptor, String baseline,
			boolean includeChangedCodeFindings, boolean fetchAll) {
		this(null, commitDescriptor, baseline, includeChangedCodeFindings, fetchAll);
	}

	/**
	 * Builds a list-map of options to be used for the
	 * ServiceClient.getFindings() service call.
	 */
	public ListMap buildOptionsForServiceCall() {
		ListMap options = new ListMap<>();

		if (uniformPath != null) {
			options.add("uniform-path", uniformPath);
		}

		if (commitDescriptor != null) {
			options.add(ServiceClientUris.TIMESTAMP_PARAMETER_NAME, commitDescriptor.toServiceCallFormat());
		}

		if (baseline != null) {
			options.add(ServiceClientUris.BASELINE_PARAMETER, baseline);
			options.add(ServiceClientUris.INCLUDE_CHANGED_CODE_FINDINGS_PARAMETER,
					String.valueOf(includeChangedCodeFindings));
			options.add(ServiceClientUris.ONLY_CHANGED_CODE_FINDINGS_PARAMETER,
					String.valueOf(onlyChangedCodeFindings));
		}

		if (fetchAll) {
			// this corresponds to
			// com.teamscale.index.findings.calculation.FindingsPaginationOptions.NO_PAGINATION_PARAMETER_NAME
			// (not accessible from here)
			options.add("all", "true");
		}

		return options;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy