use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class FinderImpl method getItemsByLocator.
@NotNull
private PagedSearchResult<ITEM> getItemsByLocator(@Nullable final Locator originalLocator, final boolean multipleItemsQuery) {
long startTime = System.nanoTime();
Locator locator;
if (originalLocator == null) {
// go on with empty locator
locator = createLocator(null, Locator.createEmptyLocator());
} else {
locator = originalLocator;
locator.processHelpRequest();
}
String contextItemText = locator.getSingleDimensionValue(CONTEXT_ITEM_DIMENSION_NAME);
if (contextItemText != null) {
List<ITEM> contextObjects = getContextItems(contextItemText);
if (contextObjects == null)
throw new BadRequestException("Context variable '" + contextItemText + "' is used in locator, but is not present in the context");
if (contextObjects.isEmpty())
throw new BadRequestException("Context variable '" + contextItemText + "' is used in locator, but the list does not contain any elements");
// so far do not support additional filtering or other dimensions if context item is used
locator.checkLocatorFullyProcessed();
return new PagedSearchResult<>(contextObjects, null, null);
}
if (!locator.isEmpty()) {
final ITEM singleItem;
try {
singleItem = myDataBinding.findSingleItem(locator);
} catch (NotFoundException e) {
if (multipleItemsQuery && !isReportErrorOnNothingFound(locator)) {
// returning empty collection for multiple items query
return new PagedSearchResult<>(Collections.emptyList(), null, null);
}
throw e;
}
if (singleItem != null) {
final Set<String> singleItemUsedDimensions = locator.getUsedDimensions();
// ignore start:0 dimension
final Long startDimension = locator.getSingleDimensionValueAsLong(PagerData.START);
if (startDimension == null || startDimension != 0) {
locator.markUnused(PagerData.START);
}
ItemFilter<ITEM> filter;
try {
filter = getDataBindingWithLogicOpsSupport(locator, myDataBinding).getFilter();
} catch (NotFoundException e) {
throw new NotFoundException("Invalid filter for found single item, try omitting extra dimensions: " + e.getMessage(), e);
} catch (BadRequestException e) {
throw new BadRequestException("Invalid filter for found single item, try omitting extra dimensions: " + e.getMessage(), e);
} catch (Exception e) {
throw new BadRequestException("Invalid filter for found single item, try omitting extra dimensions: " + e.toString(), e);
}
// mark as used as it has no influence on single item
locator.markUsed(DIMENSION_UNIQUE);
// checking before invoking filter to report any unused dimensions before possible error reporting in filter
locator.checkLocatorFullyProcessed();
if (!filter.isIncluded(singleItem)) {
final String message = "Found single item by " + StringUtil.pluralize("dimension", singleItemUsedDimensions.size()) + " " + singleItemUsedDimensions + ", but that was filtered out using the entire locator '" + locator + "'";
if (multipleItemsQuery && !isReportErrorOnNothingFound(locator)) {
LOG.debug(message);
return new PagedSearchResult<>(Collections.emptyList(), null, null);
} else {
throw new NotFoundException(message);
}
}
return new PagedSearchResult<>(Collections.singletonList(singleItem), null, null);
}
// nothing found - no dimensions should be marked as used then
locator.markAllUnused();
}
FinderDataBinding.ItemHolder<ITEM> unfilteredItems;
PagingItemFilter<ITEM> pagingFilter;
try {
FinderDataBinding.LocatorDataBinding<ITEM> locatorDataBinding = getDataBindingWithLogicOpsSupport(locator, myDataBinding);
unfilteredItems = locatorDataBinding.getPrefilteredItems();
DuplicateChecker<ITEM> duplicateChecker = myDataBinding.createDuplicateChecker();
if (duplicateChecker != null) {
// get the dimension only for supporting finders so that unused dimension is reported otherwise
boolean deduplicate = locator.getSingleDimensionValueAsStrictBoolean(DIMENSION_UNIQUE, locator.isAnyPresent(DIMENSION_ITEM));
if (deduplicate) {
unfilteredItems = new DeduplicatingItemHolder<>(unfilteredItems, duplicateChecker);
}
}
pagingFilter = getPagingFilter(locator, locatorDataBinding.getFilter());
} catch (LocatorProcessException | BadRequestException | IllegalArgumentException e) {
if (!locator.isHelpRequested()) {
throw e;
}
throw new BadRequestException(e.getMessage() + "\nLocator details: " + locator.getLocatorDescription(locator.helpOptions().getSingleDimensionValueAsStrictBoolean("hidden", false)), e);
}
locator.checkLocatorFullyProcessed();
return getItems(pagingFilter, unfilteredItems, locator, startTime);
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class DataProvider method getTrigger.
public static BuildTriggerDescriptor getTrigger(final BuildTypeSettings buildType, final String triggerLocator) {
if (StringUtil.isEmpty(triggerLocator)) {
throw new BadRequestException("Empty trigger locator is not supported.");
}
final Locator locator = new Locator(triggerLocator);
if (locator.isSingleValue()) {
// no dimensions found, assume it's trigger id
final String triggerId = locator.getSingleValue();
if (StringUtil.isEmpty(triggerId)) {
throw new BadRequestException("Trigger id cannot be empty.");
}
@SuppressWarnings("ConstantConditions") final BuildTriggerDescriptor foundTrigger = buildType.findTriggerById(triggerId);
if (foundTrigger == null) {
throw new NotFoundException("No trigger found by id '" + triggerLocator + "' in build type.");
}
return foundTrigger;
}
throw new BadRequestException("No trigger can be found by locator '" + triggerLocator + "'. Locator should be trigger id.");
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class UserGroupFinder method getGroup.
@NotNull
public SUserGroup getGroup(final String groupLocator) {
if (StringUtil.isEmpty(groupLocator)) {
throw new BadRequestException("Empty group locator is not supported.");
}
final Locator locator = new Locator(groupLocator);
if (locator.isSingleValue()) {
// no dimensions found, assume it's group key
SUserGroup group = myUserGroupManager.findUserGroupByKey(groupLocator);
if (group == null) {
throw new NotFoundException("No group can be found by key '" + groupLocator + "'.");
}
return group;
}
String groupKey = locator.getSingleDimensionValue(KEY);
if (groupKey != null) {
SUserGroup group = myUserGroupManager.findUserGroupByKey(groupKey);
if (group == null) {
throw new NotFoundException("No group can be found by key '" + groupKey + "'.");
}
return group;
}
String groupName = locator.getSingleDimensionValue(NAME);
if (groupName != null) {
SUserGroup group = myUserGroupManager.findUserGroupByName(groupName);
if (group == null) {
throw new NotFoundException("No group can be found by name '" + groupName + "'.");
}
return group;
}
throw new NotFoundException("Group locator '" + groupLocator + "' is not supported.");
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class VcsRootFinder method findSingleItem.
@Nullable
@Override
public SVcsRoot findSingleItem(@NotNull final Locator locator) {
if (locator.isSingleValue()) {
// no dimensions found, assume it's an internal id or external id
return getVcsRootByExternalOrInternalId(locator.getSingleValue());
}
final String id = locator.getSingleDimensionValue(DIMENSION_ID);
if (id != null) {
SVcsRoot root;
if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
root = getVcsRootByExternalOrInternalId(id);
} else {
root = myProjectManager.findVcsRootByExternalId(id);
if (root == null) {
throw new NotFoundException("No VCS root can be found by id '" + id + "'.");
}
// todo: this and other invocations except for in getFilter can be removed as the filter is applied to all items
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
}
return root;
}
Long internalId = locator.getSingleDimensionValueAsLong(INTERNAL_ID);
if (internalId != null) {
SVcsRoot root = myVcsManager.findRootById(internalId);
if (root == null) {
throw new NotFoundException("No VCS root can be found by internal id '" + internalId + "'.");
}
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
return root;
}
String uuid = locator.getSingleDimensionValue(UUID);
if (uuid != null) {
final EntityId<Long> internalVCSRootId = myVcsRootIdentifiersManager.findEntityIdByConfigId(uuid);
if (internalVCSRootId != null) {
SVcsRoot root = myVcsManager.findRootById(internalVCSRootId.getInternalId());
if (root != null) {
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
return root;
}
}
// protecting against brute force uuid guessing
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
throw new NotFoundException("No VCS root can be found by uuid '" + uuid + "'.");
}
return null;
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class BuildPromotionFinder method getFilter.
@NotNull
@Override
public ItemFilter<BuildPromotion> getFilter(@NotNull final Locator locator) {
final MultiCheckerFilter<BuildPromotion> result = new MultiCheckerFilter<BuildPromotion>();
// checking permissions to view - workaround for TW-45544
result.add(item -> {
try {
ensureCanView(item);
return true;
} catch (AccessDeniedException e) {
// excluding from the lists as secure wrappers usually do
return false;
}
});
if (locator.isSingleValue()) {
try {
long foundPromotionId = getBuildPromotionById(locator.getSingleValueAsLong(), myBuildPromotionManager, myBuildsManager).getId();
result.add(item -> foundPromotionId == item.getId());
} catch (NotFoundException e) {
result.add(item -> false);
}
}
if (locator.isUnused(DEFAULT_FILTERING)) {
// basically, mark as used if it is not yet processed, but is unset or is set to false
final Boolean defaultFiltering = locator.getSingleDimensionValueAsBoolean(DEFAULT_FILTERING);
if (defaultFiltering != null && defaultFiltering) {
locator.markUnused(DEFAULT_FILTERING);
}
}
final Long id = locator.getSingleDimensionValueAsLong(DIMENSION_ID);
if (id != null) {
try {
long foundPromotionId = getBuildPromotionById(id, myBuildPromotionManager, myBuildsManager).getId();
result.add(item -> foundPromotionId == item.getId());
} catch (NotFoundException e) {
result.add(item -> false);
}
}
final Long promotionId = locator.getSingleDimensionValueAsLong(PROMOTION_ID);
if (promotionId != null) {
try {
long foundPromotionId = BuildFinder.getBuildPromotion(promotionId, myBuildPromotionManager).getId();
result.add(item -> foundPromotionId == item.getId());
} catch (NotFoundException e) {
result.add(item -> false);
}
}
final Long promotionIdAlias = locator.getSingleDimensionValueAsLong(PROMOTION_ID_ALIAS);
if (promotionIdAlias != null) {
try {
long foundPromotionId = BuildFinder.getBuildPromotion(promotionIdAlias, myBuildPromotionManager).getId();
result.add(item -> foundPromotionId == item.getId());
} catch (NotFoundException e) {
result.add(item -> false);
}
}
final Long buildId = locator.getSingleDimensionValueAsLong(BUILD_ID);
if (buildId != null) {
result.add(item -> buildId.equals(item.getAssociatedBuildId()));
}
Locator stateLocator = getStateLocator(locator);
if (!isStateIncluded(stateLocator, STATE_QUEUED)) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return item.getQueuedBuild() == null;
}
});
}
if (!isStateIncluded(stateLocator, STATE_RUNNING)) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild associatedBuild = item.getAssociatedBuild();
return associatedBuild == null || associatedBuild.isFinished();
}
});
}
if (!isStateIncluded(stateLocator, STATE_FINISHED)) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild associatedBuild = item.getAssociatedBuild();
return associatedBuild == null || !associatedBuild.isFinished();
}
});
}
final Boolean composite = locator.getSingleDimensionValueAsBoolean(COMPOSITE);
if (composite != null) {
result.add(item -> FilterUtil.isIncludedByBooleanFilter(composite, item.isCompositeBuild()));
}
if (locator.isUnused(PROJECT)) {
SProject project = getProjectFromDimension(locator, PROJECT);
if (project != null) {
result.add(item -> {
final SBuildType buildType = item.getBuildType();
return buildType != null && project.equals(buildType.getProject());
});
}
}
if (locator.isUnused(AFFECTED_PROJECT)) {
SProject affectedProject = getProjectFromDimension(locator, AFFECTED_PROJECT);
if (affectedProject != null && !affectedProject.isRootProject()) {
result.add(item -> {
final SBuildType buildType = item.getBuildType();
return buildType != null && ProjectFinder.isSameOrParent(affectedProject, buildType.getProject());
});
}
}
if (locator.isUnused(BUILD_TYPE)) {
final String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
if (buildTypeLocator != null) {
final Set<SBuildType> buildTypes = new HashSet<>(myBuildTypeFinder.getBuildTypes(getProjectFromDimension(locator, PROJECT), buildTypeLocator));
if (buildTypes.isEmpty()) {
throw new NotFoundException("No build types found for locator '" + buildTypeLocator + "'");
}
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return buildTypes.contains(item.getParentBuildType());
}
});
}
}
final String branchLocatorValue = locator.getSingleDimensionValue(BRANCH);
if (branchLocatorValue != null) {
PagedSearchResult<? extends Branch> branches = null;
BadRequestException exceptinoOnFullSearch = null;
try {
branches = myBranchFinder.getItemsIfValidBranchListLocator(locator.lookupSingleDimensionValue(BUILD_TYPE), branchLocatorValue);
} catch (BadRequestException e) {
// not a valid branches listing locator
exceptinoOnFullSearch = e;
}
if (branches != null) {
// branches found - use them
Set<String> branchNames = getBranchNamesSet(branches.myEntries);
Set<String> branchDisplayNames = getBranchDisplayNamesSet(branches.myEntries);
boolean defaultBranchIncluded = branches.myEntries.stream().anyMatch(Branch::isDefaultBranch);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final Branch buildBranch = BranchData.fromBuild(item);
return (defaultBranchIncluded && buildBranch.isDefaultBranch()) || branchNames.contains(buildBranch.getName()) || branchDisplayNames.contains(buildBranch.getDisplayName());
}
});
} else {
// branches not found by locator - try to use filter
BranchFinder.BranchFilterDetails branchFilterDetails;
try {
branchFilterDetails = myBranchFinder.getBranchFilterDetails(branchLocatorValue);
} catch (LocatorProcessException locatorException) {
throw new BadRequestException("Invalid sub-locator '" + BRANCH + "': Cannot" + (exceptinoOnFullSearch != null ? " find branches: " + exceptinoOnFullSearch.getMessage() + "; and cannot " : "") + " create filter: " + locatorException.getMessage(), locatorException);
}
if (!branchFilterDetails.isAnyBranch()) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return branchFilterDetails.isIncluded(item);
}
});
}
}
}
final Boolean branched = locator.getSingleDimensionValueAsBoolean(BRANCHED);
if (branched != null) {
result.add(item -> FilterUtil.isIncludedByBooleanFilter(branched, item.getBranch() != null));
}
if (locator.isUnused(AGENT)) {
final String agentLocator = locator.getSingleDimensionValue(AGENT);
if (agentLocator != null) {
Set<Integer> agentIds = myAgentFinder.getItemsNotEmpty(agentLocator).myEntries.stream().map(agent -> agent.getId()).filter(i -> i != Agent.UNKNOWN_AGENT_ID).collect(Collectors.toSet());
result.add(item -> {
// for queued build using compatible agents
final SQueuedBuild queuedBuild = item.getQueuedBuild();
if (queuedBuild != null) {
return queuedBuild.getCanRunOnAgents().stream().anyMatch(agent -> agentIds.contains(agent.getId()));
}
final SBuild build = item.getAssociatedBuild();
if (build != null) {
return agentIds.contains(build.getAgent().getId());
}
return false;
});
}
}
// compatibility support
final String tags = locator.getSingleDimensionValue(TAGS);
if (tags != null) {
final List<String> tagsList = Arrays.asList(tags.split(","));
if (tagsList.size() > 0) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return item.getTags().containsAll(tagsList);
}
});
}
}
if (locator.isUnused(TAG)) {
result.add(getFilterByTag(locator.getDimensionValue(TAG)));
}
final String compatibleAgentLocator = locator.getSingleDimensionValue(COMPATIBLE_AGENT);
if (compatibleAgentLocator != null) {
List<SBuildAgent> agents = myAgentFinder.getItems(compatibleAgentLocator).myEntries;
result.add(build -> agents.stream().anyMatch(agent -> myAgentFinder.canActuallyRun(agent, build)));
}
// experimental, only for queued builds
final Long compatibleAgentsCount = locator.getSingleDimensionValueAsLong(COMPATIBLE_AGENTS_COUNT);
if (compatibleAgentsCount != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
long count = 0;
for (SBuildAgent agent : myAgentFinder.getItems(null).myEntries) {
// or should process unauthorized as well?
if (myAgentFinder.canActuallyRun(agent, item))
count++;
if (count > compatibleAgentsCount)
return false;
}
return count == compatibleAgentsCount;
}
});
}
final Boolean personal = locator.getSingleDimensionValueAsBoolean(PERSONAL);
if (personal != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return FilterUtil.isIncludedByBooleanFilter(personal, item.isPersonal());
}
});
}
final Boolean history = locator.getSingleDimensionValueAsBoolean(HISTORY);
if (history != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return FilterUtil.isIncludedByBooleanFilter(history, item.isOutOfChangesSequence());
}
});
}
final String userDimension = locator.getSingleDimensionValue(USER);
if (userDimension != null) {
final SUser user = myUserFinder.getItem(userDimension);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
SUser owner = item.getOwner();
if (owner != null) {
// if owner is present, consider only it: this is consistent with the builds search in the prefiltering
return user.getId() == owner.getId();
}
SUser actualUser = Util.resolveNull(getTriggeredBy(item), TriggeredBy::getUser);
return actualUser != null && user.getId() == actualUser.getId();
}
});
}
final String triggeredDimension = locator.getSingleDimensionValue(TRIGGERED);
if (triggeredDimension != null) {
final ItemFilter<TriggeredBy> filter = myTriggerByFinder.getFilter(triggeredDimension);
result.add(item -> Util.resolveNull(getTriggeredBy(item), filter::isIncluded, false));
}
final List<String> properties = locator.getDimensionValue(PROPERTY);
if (!properties.isEmpty()) {
final Matcher<ParametersProvider> parameterCondition = ParameterCondition.create(properties);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
if (!Build.canViewRuntimeData(myPermissionChecker, item))
return false;
// TeamCity open API issue
return parameterCondition.matches(Build.getBuildResultingParameters(item, myServiceLocator));
}
});
}
if (locator.getUnusedDimensions().contains(SNAPSHOT_DEP)) {
// performance optimization: do not filter if already processed
final String snapshotDepDimension = locator.getSingleDimensionValue(SNAPSHOT_DEP);
if (snapshotDepDimension != null) {
final Set<BuildPromotion> snapshotRelatedBuilds = new HashSet<>(getSnapshotRelatedBuilds(snapshotDepDimension));
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return snapshotRelatedBuilds.contains(item);
}
});
}
}
if (locator.getUnusedDimensions().contains(ARTIFACT_DEP)) {
// performance optimization: do not filter if already processed
final String artifactDepDimension = locator.getSingleDimensionValue(ARTIFACT_DEP);
if (artifactDepDimension != null) {
final Set<BuildPromotion> artifactRelatedBuilds = new HashSet<>(getArtifactRelatedBuilds(artifactDepDimension, locator));
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return artifactRelatedBuilds.contains(item);
}
});
}
}
if (locator.isUnused(SNAPSHOT_PROBLEM)) {
final String snapshotDepProblem = locator.getSingleDimensionValue(SNAPSHOT_PROBLEM);
if (snapshotDepProblem != null) {
final Set<BuildPromotion> snapshotDepProblemBuilds = new HashSet<>(getSnapshotDepProblemBuilds(snapshotDepProblem));
result.add(item -> snapshotDepProblemBuilds.contains(item));
}
}
if (locator.getUnusedDimensions().contains(EQUIVALENT)) {
// performance optimization: do not filter if already processed
final String equivalent = locator.getSingleDimensionValue(EQUIVALENT);
if (equivalent != null) {
final Set<BuildPromotion> filter = new HashSet<BuildPromotion>(((BuildPromotionEx) getItem(equivalent)).getStartedEquivalentPromotions(-1));
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return filter.contains(item);
}
});
}
}
if (locator.getUnusedDimensions().contains(METADATA)) {
// performance optimization: do not filter if already processed
final String metadata = locator.getSingleDimensionValue(METADATA);
if (metadata != null) {
final Iterator<BuildMetadataEntry> metadataEntries = getBuildMetadataEntryIterator(metadata);
final Set<Long> buildIds = new HashSet<Long>();
while (metadataEntries.hasNext()) {
BuildMetadataEntry metadataEntry = metadataEntries.next();
buildIds.add(metadataEntry.getBuildId());
}
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
if (!Build.canViewRuntimeData(myPermissionChecker, item))
return false;
return buildIds.contains(item.getAssociatedBuildId());
}
});
}
}
if (locator.getUnusedDimensions().contains(ORDERED)) {
// performance optimization: do not filter if already processed
final String graphLocator = locator.getSingleDimensionValue(ORDERED);
if (graphLocator != null) {
final GraphFinder<BuildPromotion> graphFinder = new BuildPromotionOrderedFinder(BuildPromotionFinder.this);
final Set<BuildPromotion> filter = new HashSet<BuildPromotion>(graphFinder.getItems(graphLocator).myEntries);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return filter.contains(item);
}
});
}
}
final String sinceBuildDimension = locator.getSingleDimensionValue(SINCE_BUILD);
BuildPromotion sinceBuildPromotion = null;
Long sinceBuildId = null;
if (sinceBuildDimension != null) {
try {
sinceBuildPromotion = getItem(sinceBuildDimension);
final SQueuedBuild queuedBuild = sinceBuildPromotion.getQueuedBuild();
if (queuedBuild != null) {
// compare queued builds by id (triggering sequence)
final long buildPromotionId = getBuildId(sinceBuildPromotion);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return buildPromotionId < getBuildId(item);
}
});
} else {
// for started build, compare by start time
final SBuild limitingBuild = sinceBuildPromotion.getAssociatedBuild();
if (limitingBuild != null) {
final Date startDate = limitingBuild.getStartDate();
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild build = item.getAssociatedBuild();
if (build == null)
return true;
if (startDate.equals(build.getStartDate()) && limitingBuild.getBuildId() != build.getBuildId())
return true;
return startDate.before(build.getStartDate());
}
});
}
}
} catch (NotFoundException e) {
// build not found by sinceBuild locator, extract id ad filter using it
sinceBuildId = getBuildId(sinceBuildDimension);
final long sinceBuildIdFinal = sinceBuildId;
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return sinceBuildIdFinal < getBuildId(item);
}
});
}
}
final String untilBuild = locator.getSingleDimensionValue(UNTIL_BUILD);
if (untilBuild != null) {
try {
final BuildPromotion untilBuildPromotion = getItem(untilBuild);
final SQueuedBuild queuedBuild = untilBuildPromotion.getQueuedBuild();
if (queuedBuild != null) {
// compare queued builds by id (triggering sequence)
final long buildPromotionId = getBuildId(untilBuildPromotion);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return !(buildPromotionId < getBuildId(item));
}
});
} else {
// for started build, compare by start time
final SBuild limitingBuild = untilBuildPromotion.getAssociatedBuild();
if (limitingBuild != null) {
final Date startDate = limitingBuild.getStartDate();
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild build = item.getAssociatedBuild();
return build == null || !startDate.before(build.getStartDate());
}
});
}
}
} catch (NotFoundException e) {
// build not found by sinceBuild locator, extract id ad filter using it
final long untilBuildId = getBuildId(untilBuild);
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
return !(untilBuildId < getBuildId(item));
}
});
}
}
TimeCondition.FilterAndLimitingDate<BuildPromotion> queuedFiltering = myTimeCondition.processTimeConditions(QUEUED_TIME, locator, TimeCondition.QUEUED_BUILD_TIME, TimeCondition.QUEUED_BUILD_TIME);
if (queuedFiltering != null)
result.add(queuedFiltering.getFilter());
TimeCondition.FilterAndLimitingDate<BuildPromotion> startedFiltering = myTimeCondition.processTimeConditions(STARTED_TIME, locator, TimeCondition.STARTED_BUILD_TIME, TimeCondition.STARTED_BUILD_TIME);
@Nullable Date sinceStartDate = null;
if (startedFiltering != null) {
result.add(startedFiltering.getFilter());
sinceStartDate = startedFiltering.getLimitingDate();
}
// todo: add processing cut of based on assumption of max build time (say, a week); for other times as well
TimeCondition.FilterAndLimitingDate<BuildPromotion> finishFiltering = myTimeCondition.processTimeConditions(FINISHED_TIME, locator, TimeCondition.FINISHED_BUILD_TIME, TimeCondition.FINISHED_BUILD_TIME);
if (finishFiltering != null)
result.add(finishFiltering.getFilter());
final String revisionLocatorText = locator.getSingleDimensionValue(REVISION);
if (revisionLocatorText != null) {
final Locator revisionLocator = new Locator(revisionLocatorText, "version", "internalVersion", "vcsRoot", Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME);
final String revision = revisionLocator.getSingleValue();
if (revision != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
// use getAllrevisions map??
final List<BuildRevision> buildRevisions = item.getRevisions();
for (BuildRevision rev : buildRevisions) {
if (revision.equals(rev.getRevisionDisplayName())) {
return true;
}
}
return false;
}
});
} else {
final String vcsRootLocator = revisionLocator.getSingleDimensionValue("vcsRoot");
final SVcsRoot vcsRoot = vcsRootLocator == null ? null : myVcsRootFinder.getItem(vcsRootLocator);
final ValueCondition versionCondition = ParameterCondition.createValueCondition(revisionLocator.getSingleDimensionValue("version"));
final ValueCondition internalVersionCondition = ParameterCondition.createValueCondition(revisionLocator.getSingleDimensionValue("internalVersion"));
revisionLocator.checkLocatorFullyProcessed();
if (vcsRoot != null || versionCondition != null || internalVersionCondition != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
// use getAllrevisions map??
final List<BuildRevision> revisions = item.getRevisions();
for (BuildRevision rev : revisions) {
if ((vcsRoot == null || vcsRoot.getId() == rev.getRoot().getParent().getId()) && (versionCondition == null || versionCondition.matches(rev.getRevisionDisplayName())) && (internalVersionCondition == null || internalVersionCondition.matches(rev.getRevision()))) {
return true;
}
}
return false;
}
});
}
}
}
final MultiCheckerFilter<SBuild> buildFilter = getBuildFilter(locator);
if (buildFilter.getSubFiltersCount() > 0) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild build = item.getAssociatedBuild();
if (build == null) {
return false;
}
return buildFilter.isIncluded(build);
}
});
}
// see also filtering in getBuildFilter
sinceStartDate = TimeCondition.maxDate(sinceStartDate, DataProvider.parseDate(locator.getSingleDimensionValue(SINCE_DATE)));
final Boolean canceled = locator.getSingleDimensionValueAsBoolean(CANCELED);
if (canceled != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild build = item.getAssociatedBuild();
return FilterUtil.isIncludedByBooleanFilter(canceled, build != null && build.getCanceledInfo() != null);
}
});
}
final Boolean failedToStart = locator.getSingleDimensionValueAsBoolean(FAILED_TO_START);
if (failedToStart != null) {
result.add(new FilterConditionChecker<BuildPromotion>() {
public boolean isIncluded(@NotNull final BuildPromotion item) {
final SBuild build = item.getAssociatedBuild();
return FilterUtil.isIncludedByBooleanFilter(failedToStart, build != null && build.isInternalError());
}
});
}
return getFilterWithProcessingCutOff(result, locator.getSingleDimensionValueAsLong(SINCE_BUILD_ID_LOOK_AHEAD_COUNT), sinceBuildPromotion, sinceBuildId, sinceStartDate);
}
Aggregations