use of jetbrains.buildServer.serverSide.TagData in project teamcity-rest by JetBrains.
the class TagFinder method getFilter.
@NotNull
@Override
public ItemFilter<TagData> getFilter(@NotNull final Locator locator) {
if (locator.isSingleValue()) {
final String singleValue = locator.getSingleValue();
final MultiCheckerFilter<TagData> result = new MultiCheckerFilter<TagData>();
result.add(new FilterConditionChecker<TagData>() {
public boolean isIncluded(@NotNull final TagData item) {
// the code should correspond to TagFinder.isIncluded method
return item.isPublic() && item.getLabel().equals(singleValue);
}
});
return result;
}
final MultiCheckerFilter<TagData> result = new MultiCheckerFilter<TagData>();
final String nameDimension = locator.getSingleDimensionValue(NAME);
if (nameDimension != null) {
result.add(new FilterConditionChecker<TagData>() {
public boolean isIncluded(@NotNull final TagData item) {
// conditions are supported via "condition" dimension
return nameDimension.equalsIgnoreCase(item.getLabel());
}
});
}
final Boolean privateDimension = locator.getSingleDimensionValueAsBoolean(PRIVATE);
if (privateDimension != null) {
result.add(new FilterConditionChecker<TagData>() {
public boolean isIncluded(@NotNull final TagData item) {
return FilterUtil.isIncludedByBooleanFilter(privateDimension, item.getOwner() != null);
}
});
}
final String ownerLocator = locator.getSingleDimensionValue(OWNER);
if (ownerLocator != null) {
final SUser user = myUserFinder.getItem(ownerLocator);
result.add(new FilterConditionChecker<TagData>() {
public boolean isIncluded(@NotNull final TagData item) {
final SUser owner = item.getOwner();
if (privateDimension == null && owner == null) {
// locator "private:any,owner:<user>" should return all public and private of the user (the defaults)
return true;
}
return user.equals(owner);
}
});
}
final String condition = locator.getSingleDimensionValue(CONDITION);
if (condition != null) {
final ValueCondition parameterCondition = ParameterCondition.createValueCondition(condition);
result.add(new FilterConditionChecker<TagData>() {
public boolean isIncluded(@NotNull final TagData item) {
return parameterCondition.matches(item.getLabel());
}
});
}
return result;
}
use of jetbrains.buildServer.serverSide.TagData in project teamcity-rest by JetBrains.
the class TagFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<TagData> getPrefilteredItems(@NotNull final Locator locator) {
if (myBuildPromotion == null)
throw new OperationException("Attempt to use the tags locator without setting build");
final ArrayList<TagData> result = new ArrayList<TagData>(myBuildPromotion.getTagDatas());
Collections.sort(result, new Comparator<TagData>() {
public int compare(final TagData o1, final TagData o2) {
if (o1 == o2)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return 1;
if (o1.isPublic()) {
if (o2.isPublic()) {
return o1.getLabel().compareToIgnoreCase(o2.getLabel());
}
return -1;
}
if (o2.isPublic()) {
return 1;
}
final SUser user1 = o1.getOwner();
final SUser user2 = o2.getOwner();
if (user1 == user2 || user1 == null || user2 == null)
return o1.getLabel().compareToIgnoreCase(o2.getLabel());
return user1.getUsername().compareToIgnoreCase(user2.getUsername());
}
});
return getItemHolder(result);
}
Aggregations