use of com.google.common.base.Predicate in project druid by druid-io.
the class RulesResourceFilter method filter.
@Override
public ContainerRequest filter(ContainerRequest request) {
if (getAuthConfig().isEnabled()) {
// This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
final String dataSourceName = request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {
@Override
public boolean apply(PathSegment input) {
return input.getPath().equals("rules");
}
}) + 1).getPath();
Preconditions.checkNotNull(dataSourceName);
final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq().getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
final Access authResult = authorizationInfo.isAuthorized(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
if (!authResult.isAllowed()) {
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
}
}
return request;
}
use of com.google.common.base.Predicate in project druid by druid-io.
the class ConvertSegmentTask method run.
@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
final Iterable<DataSegment> segmentsToUpdate;
if (segment == null) {
final List<DataSegment> segments = toolbox.getTaskActionClient().submit(new SegmentListUsedAction(getDataSource(), getInterval(), null));
segmentsToUpdate = FunctionalIterable.create(segments).filter(new Predicate<DataSegment>() {
@Override
public boolean apply(DataSegment segment) {
final Integer segmentVersion = segment.getBinaryVersion();
if (!CURR_VERSION_INTEGER.equals(segmentVersion)) {
return true;
} else if (force) {
log.info("Segment[%s] already at version[%s], forcing conversion", segment.getIdentifier(), segmentVersion);
return true;
} else {
log.info("Skipping[%s], already version[%s]", segment.getIdentifier(), segmentVersion);
return false;
}
}
});
} else {
log.info("I'm in a subless mood.");
segmentsToUpdate = Collections.singleton(segment);
}
// Vestigial from a past time when this task spawned subtasks.
for (final Task subTask : generateSubTasks(getGroupId(), segmentsToUpdate, indexSpec, force, validate, getContext())) {
final TaskStatus status = subTask.run(toolbox);
if (!status.isSuccess()) {
return TaskStatus.fromCode(getId(), status.getStatusCode());
}
}
return success();
}
use of com.google.common.base.Predicate in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method injectChunkIntoWorld.
public void injectChunkIntoWorld(Chunk chunk, int x, int z, boolean putInId2ChunkMap) {
ChunkProviderServer provider = (ChunkProviderServer) worldObj.getChunkProvider();
//TileEntities will break if you don't do this
chunk.isChunkLoaded = true;
chunk.isModified = true;
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
if (putInId2ChunkMap) {
provider.id2ChunkMap.put(ChunkPos.chunkXZ2Int(x, z), chunk);
}
PlayerChunkMap map = ((WorldServer) worldObj).getPlayerChunkMap();
PlayerChunkMapEntry entry = new PlayerChunkMapEntry(map, x, z) {
@Override
public boolean hasPlayerMatchingInRange(double range, Predicate<EntityPlayerMP> predicate) {
return true;
}
};
long i = map.getIndex(x, z);
map.playerInstances.put(i, entry);
map.playerInstanceList.add(entry);
entry.sentToPlayers = true;
entry.players = watchingPlayers;
claimedChunksEntries[x - ownedChunks.minX][z - ownedChunks.minZ] = entry;
// MinecraftForge.EVENT_BUS.post(new ChunkEvent.Load(chunk));
}
use of com.google.common.base.Predicate in project intellij-community by JetBrains.
the class CCUtils method updateHigherElements.
/**
* This method decreases index and updates directory names of
* all tasks/lessons that have higher index than specified object
*
* @param dirs directories that are used to get tasks/lessons
* @param getStudyItem function that is used to get task/lesson from VirtualFile. This function can return null
* @param threshold index is used as threshold
* @param prefix task or lesson directory name prefix
*/
public static void updateHigherElements(VirtualFile[] dirs, @NotNull final Function<VirtualFile, ? extends StudyItem> getStudyItem, final int threshold, final String prefix, final int delta) {
ArrayList<VirtualFile> dirsToRename = new ArrayList<>(Collections2.filter(Arrays.asList(dirs), new Predicate<VirtualFile>() {
@Override
public boolean apply(VirtualFile dir) {
final StudyItem item = getStudyItem.fun(dir);
if (item == null) {
return false;
}
int index = item.getIndex();
return index > threshold;
}
}));
Collections.sort(dirsToRename, (o1, o2) -> {
StudyItem item1 = getStudyItem.fun(o1);
StudyItem item2 = getStudyItem.fun(o2);
//if we delete some dir we should start increasing numbers in dir names from the end
return (-delta) * EduUtils.INDEX_COMPARATOR.compare(item1, item2);
});
for (final VirtualFile dir : dirsToRename) {
final StudyItem item = getStudyItem.fun(dir);
final int newIndex = item.getIndex() + delta;
item.setIndex(newIndex);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
dir.rename(this, prefix + newIndex);
} catch (IOException e) {
LOG.error(e);
}
}
});
}
}
use of com.google.common.base.Predicate in project selenium-tests by Wikia.
the class TopNoteModalDialog method clickApprove.
public void clickApprove() {
super.clickConfirm();
new WebDriverWait(driver, DiscussionsConstants.TIMEOUT).until((Predicate<WebDriver>) input -> !post.getAttribute("class").contains("is-reported"));
}
Aggregations