use of jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider in project teamcity-rest by JetBrains.
the class BuildPromotionFinder method getBuildFilter.
@NotNull
private MultiCheckerFilter<SBuild> getBuildFilter(@NotNull final Locator locator) {
final MultiCheckerFilter<SBuild> result = new MultiCheckerFilter<SBuild>();
final String buildNumber = locator.getSingleDimensionValue(NUMBER);
if (buildNumber != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return buildNumber.equals(item.getBuildNumber());
}
});
}
final String status = locator.getSingleDimensionValue(STATUS);
if (status != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return status.equalsIgnoreCase(item.getStatusDescriptor().getStatus().getText());
}
});
}
final Boolean pinned = locator.getSingleDimensionValueAsBoolean(PINNED);
if (pinned != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return FilterUtil.isIncludedByBooleanFilter(pinned, item.isPinned());
}
});
}
final Boolean hanging = locator.getSingleDimensionValueAsBoolean(HANGING);
if (hanging != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
if (item.isFinished())
return !hanging;
return FilterUtil.isIncludedByBooleanFilter(hanging, ((SRunningBuild) item).isProbablyHanging());
}
});
}
if (locator.isUnused(AGENT_NAME)) {
final String agentName = locator.getSingleDimensionValue(AGENT_NAME);
if (agentName != null) {
final ValueCondition agentNameCondition = ParameterCondition.createValueCondition(agentName);
result.add(item -> agentNameCondition.matches(item.getAgentName()));
}
}
if (locator.isUnused(AGENT_TYPE_ID)) {
final Long agentTypeId = locator.getSingleDimensionValueAsLong(AGENT_TYPE_ID);
if (agentTypeId != null) {
result.add(item -> agentTypeId.intValue() == item.getAgent().getAgentTypeId());
}
}
// see also settings cut off date in main filter
final Date sinceDate = DataProvider.parseDate(locator.getSingleDimensionValue(SINCE_DATE));
if (sinceDate != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return sinceDate.before(item.getStartDate());
}
});
}
final Date untilDate = DataProvider.parseDate(locator.getSingleDimensionValue(UNTIL_DATE));
if (untilDate != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return !(untilDate.before(item.getStartDate()));
}
});
}
final List<String> statisticValues = locator.getDimensionValue(STATISTIC_VALUE);
if (!statisticValues.isEmpty()) {
final Matcher<ParametersProvider> parameterCondition = ParameterCondition.create(statisticValues);
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return parameterCondition.matches(new AbstractMapParametersProvider(Build.getBuildStatisticsValues(item)));
}
});
}
if (locator.isUnused(TEST_OCCURRENCE)) {
final String testOccurrence = locator.getSingleDimensionValue(TEST_OCCURRENCE);
if (testOccurrence != null) {
TestOccurrenceFinder testOccurrenceFinder = myServiceLocator.getSingletonService(TestOccurrenceFinder.class);
Set<Long> buildPromotionIds = testOccurrenceFinder.getItems(testOccurrence).myEntries.stream().map(sTestRun -> sTestRun.getBuild().getBuildPromotion().getId()).collect(Collectors.toSet());
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return buildPromotionIds.contains(item.getBuildPromotion().getId());
}
});
}
}
final String test = locator.getSingleDimensionValue(TEST);
if (test != null) {
TestFinder testFinder = myServiceLocator.getSingletonService(TestFinder.class);
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
String locator = new Locator(test).setDimension(TestFinder.BUILD, getLocator(item.getBuildPromotion())).setDimension(PagerData.COUNT, "1").getStringRepresentation();
return !testFinder.getItems(locator).myEntries.isEmpty();
}
});
}
return result;
}
use of jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider in project teamcity-rest by JetBrains.
the class VcsRootInstanceFinder method getFilter.
@NotNull
@Override
public ItemFilter<VcsRootInstance> getFilter(@NotNull final Locator locator) {
final MultiCheckerFilter<VcsRootInstance> result = new MultiCheckerFilter<VcsRootInstance>();
result.add(item -> hasPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, item));
final String type = locator.getSingleDimensionValue(TYPE);
if (type != null) {
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return type.equals(item.getVcsName());
}
});
}
if (locator.isUnused(BUILD)) {
final String build = locator.getSingleDimensionValue(BUILD);
if (build != null) {
Set<Long> vcsRootInstanceIds = getVcsRootInstancesByBuilds(build).map(vcsRE -> vcsRE.getId()).collect(Collectors.toSet());
result.add(item -> vcsRootInstanceIds.contains(item.getId()));
}
}
if (locator.isUnused(VCS_ROOT_DIMENSION)) {
final String vcsRootLocator = locator.getSingleDimensionValue(VCS_ROOT_DIMENSION);
if (vcsRootLocator != null) {
final List<SVcsRoot> vcsRoots = myVcsRootFinder.getItems(vcsRootLocator).myEntries;
result.add(item -> vcsRoots.contains(item.getParent()));
}
}
// todo: rework to be "there are usages directly in the project", also add to getPrefilteredItems
// todo: support usage as versioned settings root
// todo: support multiple here for "from all not archived projects" case
final String projectLocator = locator.getSingleDimensionValue(PROJECT);
if (projectLocator != null) {
final SProject project = myProjectFinder.getItem(projectLocator);
VcsRootInstance settingsInstance = myVersionedSettingsManager.getVersionedSettingsVcsRootInstance(project);
final Boolean nonVersionedSettings = locator.lookupSingleDimensionValueAsBoolean(HAS_VERSIONED_SETTINGS_ONLY);
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return // todo: rework project dimensions for the instance to mean smth. more meaningful
project.equals(VcsRoot.getProjectByRoot(item.getParent())) || (nonVersionedSettings == null || nonVersionedSettings) && item.equals(settingsInstance);
}
});
}
final String repositoryIdString = locator.getSingleDimensionValue(REPOSITORY_ID_STRING);
if (repositoryIdString != null) {
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return VcsRootFinder.repositoryIdStringMatches(item, repositoryIdString, myVcsManager);
}
});
}
final List<String> properties = locator.getDimensionValue(PROPERTY);
if (!properties.isEmpty()) {
final Matcher<ParametersProvider> parameterCondition = ParameterCondition.create(properties);
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return parameterCondition.matches(new AbstractMapParametersProvider(item.getProperties()));
}
});
}
final String status = locator.getSingleDimensionValue(STATUS);
if (status != null) {
TypedFinderBuilder<VcsRootInstanceEx> builder = new TypedFinderBuilder<VcsRootInstanceEx>();
builder.dimensionEnum(TypedFinderBuilder.Dimension.single(), VcsRootStatus.Type.class).description("status of the VCS root instance").valueForDefaultFilter(root -> root.getStatus().getType());
final TypedFinderBuilder<VcsRootCheckStatus> statusFilterBuilder = new TypedFinderBuilder<VcsRootCheckStatus>();
statusFilterBuilder.dimensionEnum(new TypedFinderBuilder.Dimension<>("status"), VcsRootStatus.Type.class).description("type of operation").valueForDefaultFilter(vcsRootCheckStatus -> vcsRootCheckStatus.myStatus.getType());
statusFilterBuilder.dimensionTimeCondition(new TypedFinderBuilder.Dimension<>("timestamp"), myTimeCondition).description("time of the operation start").valueForDefaultFilter(vcsRootCheckStatus -> vcsRootCheckStatus.myStatus.getTimestamp());
statusFilterBuilder.dimensionEnum(new TypedFinderBuilder.Dimension<>("requestorType"), OperationRequestor.class).description("requestor of the operation").valueForDefaultFilter(vcsRootCheckStatus -> vcsRootCheckStatus.myRequestor);
Finder<VcsRootCheckStatus> vcsRootCheckStatusFinder = statusFilterBuilder.build();
builder.dimensionFinderFilter(new TypedFinderBuilder.Dimension<>("current"), vcsRootCheckStatusFinder, "VCS check status condition").description("current VCS root status").valueForDefaultFilter(root -> new VcsRootCheckStatus(root.getStatus(), root.getLastRequestor()));
builder.dimensionFinderFilter(new TypedFinderBuilder.Dimension<>("previous"), vcsRootCheckStatusFinder, "VCS check status condition").description("previous VCS root status").valueForDefaultFilter(root -> new VcsRootCheckStatus(root.getPreviousStatus(), null));
final ItemFilter<VcsRootInstanceEx> filter = builder.build().getFilter(status);
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return filter.isIncluded((VcsRootInstanceEx) item);
}
});
}
final Boolean commitHookMode = locator.getSingleDimensionValueAsBoolean(COMMIT_HOOK_MODE);
if (commitHookMode != null) {
result.add(item -> FilterUtil.isIncludedByBooleanFilter(commitHookMode, !((VcsRootInstanceEx) item).isPollingMode()));
}
TimeCondition.FilterAndLimitingDate<VcsRootInstance> finishFiltering = myTimeCondition.processTimeConditions(FINISH_VCS_CHECKING_FOR_CHANGES, locator, (vcsRootInstance) -> getFinishCheckingForChanges(vcsRootInstance), null);
if (finishFiltering != null)
result.add(finishFiltering.getFilter());
final String repositoryState = locator.getSingleDimensionValue(REPOSITORY_STATE);
if (repositoryState != null) {
TypedFinderBuilder<RepositoryState> builder = new TypedFinderBuilder<RepositoryState>();
builder.dimensionTimeCondition(new TypedFinderBuilder.Dimension<>("timestamp"), myTimeCondition).description("time of the repository state creation").valueForDefaultFilter(item -> item.getCreateTimestamp());
builder.dimensionValueCondition(new TypedFinderBuilder.Dimension<>("branchName")).description("branch name").filter((valueCondition, item) -> {
for (String branchName : item.getBranchRevisions().keySet()) {
if (valueCondition.matches(branchName))
return true;
}
return false;
});
final ItemFilter<RepositoryState> filter = builder.build().getFilter(repositoryState);
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return filter.isIncluded(((VcsRootInstanceEx) item).getLastUsedState());
}
});
}
if (locator.isUnused(BUILD_TYPE)) {
final String buildTypesLocator = locator.getSingleDimensionValue(BUILD_TYPE);
if (buildTypesLocator != null) {
Set<VcsRootInstance> vcsRootInstances = getInstances(buildTypesLocator, locator.lookupSingleDimensionValueAsBoolean(HAS_VERSIONED_SETTINGS_ONLY));
result.add(item -> vcsRootInstances.contains(item));
}
}
// todo: support multiple here
final String affectedProjectLocator = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectLocator != null) {
final Set<VcsRootInstance> vcsRootInstances = getVcsRootInstancesUnderProject(myProjectFinder.getItem(affectedProjectLocator), locator.getSingleDimensionValueAsBoolean(HAS_VERSIONED_SETTINGS_ONLY));
result.add(new FilterConditionChecker<VcsRootInstance>() {
public boolean isIncluded(@NotNull final VcsRootInstance item) {
return vcsRootInstances.contains(item);
}
});
}
return result;
}
Aggregations