use of com.google.common.base.Optional in project che by eclipse.
the class DebugActionTest method actionShouldBePerformed.
@Test
public void actionShouldBePerformed() {
DebugConfiguration debugConfiguration = mock(DebugConfiguration.class);
when(debugConfiguration.getType()).thenReturn(mock(DebugConfigurationType.class));
when(debugConfiguration.getHost()).thenReturn("localhost");
when(debugConfiguration.getPort()).thenReturn(8000);
Map<String, String> connectionProperties = new HashMap<>();
connectionProperties.put("prop1", "val1");
connectionProperties.put("prop2", "val2");
when(debugConfiguration.getConnectionProperties()).thenReturn(connectionProperties);
Optional configurationOptional = mock(Optional.class);
when(configurationOptional.isPresent()).thenReturn(Boolean.TRUE);
when(configurationOptional.get()).thenReturn(debugConfiguration);
when(debugConfigurationsManager.getCurrentDebugConfiguration()).thenReturn(configurationOptional);
action.actionPerformed(null);
verify(debugConfigurationsManager).apply(debugConfiguration);
}
use of com.google.common.base.Optional in project che by eclipse.
the class ProjectTreeStateNotificationOperation method apply.
@Override
public void apply(String endpointId, ProjectTreeStateUpdateDto params) throws JsonRpcException {
final String path = params.getPath();
final FileWatcherEventType type = params.getType();
final int status;
switch(type) {
case CREATED:
{
status = ADDED;
break;
}
case DELETED:
{
status = REMOVED;
break;
}
case MODIFIED:
{
status = UPDATED;
break;
}
default:
{
status = UPDATED;
break;
}
}
Log.debug(getClass(), "Received request\npath: " + path + "\ntype:" + type + "\nstatus:" + status);
if (path == null || path.isEmpty()) {
appContext.getWorkspaceRoot().synchronize();
} else {
appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), status));
}
if (status == ADDED) {
appContext.getWorkspaceRoot().getFile(Path.valueOf(path)).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> arg) throws OperationException {
if (arg.isPresent()) {
appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), UPDATED));
}
}
});
}
}
use of com.google.common.base.Optional in project che by eclipse.
the class CompareWithLatestAction method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
final Project project = appContext.getRootProject();
final Resource resource = appContext.getResource();
checkState(project != null, "Null project occurred");
checkState(project.getLocation().isPrefixOf(resource.getLocation()), "Given selected item is not descendant of given project");
final String selectedItemPath = resource.getLocation().removeFirstSegments(project.getLocation().segmentCount()).removeTrailingSeparator().toString();
service.diff(appContext.getDevMachine(), project.getLocation(), selectedItemPath.isEmpty() ? null : singletonList(selectedItemPath), NAME_STATUS, false, 0, REVISION, false).then(new Operation<String>() {
@Override
public void apply(String diff) throws OperationException {
if (diff.isEmpty()) {
dialogFactory.createMessageDialog(locale.compareMessageIdenticalContentTitle(), locale.compareMessageIdenticalContentText(), null).show();
} else {
final String[] changedFiles = diff.split("\n");
if (changedFiles.length == 1) {
project.getFile(changedFiles[0].substring(2)).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
comparePresenter.showCompareWithLatest(file.get(), defineStatus(changedFiles[0].substring(0, 1)), REVISION);
}
}
});
} else {
Map<String, Status> items = new HashMap<>();
for (String item : changedFiles) {
items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
}
changedListPresenter.show(items, REVISION, null, project);
}
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
}
});
}
use of com.google.common.base.Optional in project druid by druid-io.
the class OverlordResource method getCompleteTasks.
@GET
@Path("/completeTasks")
@Produces(MediaType.APPLICATION_JSON)
public Response getCompleteTasks(@Context final HttpServletRequest req) {
final List<TaskStatus> recentlyFinishedTasks;
if (authConfig.isEnabled()) {
// This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
final Map<Pair<Resource, Action>, Access> resourceAccessMap = new HashMap<>();
final AuthorizationInfo authorizationInfo = (AuthorizationInfo) req.getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
recentlyFinishedTasks = ImmutableList.copyOf(Iterables.filter(taskStorageQueryAdapter.getRecentlyFinishedTaskStatuses(), new Predicate<TaskStatus>() {
@Override
public boolean apply(TaskStatus input) {
final String taskId = input.getId();
final Optional<Task> optionalTask = taskStorageQueryAdapter.getTask(taskId);
if (!optionalTask.isPresent()) {
throw new WebApplicationException(Response.serverError().entity(String.format("No task information found for task with id: [%s]", taskId)).build());
}
Resource resource = new Resource(optionalTask.get().getDataSource(), ResourceType.DATASOURCE);
Action action = Action.READ;
Pair<Resource, Action> key = new Pair<>(resource, action);
if (resourceAccessMap.containsKey(key)) {
return resourceAccessMap.get(key).isAllowed();
} else {
Access access = authorizationInfo.isAuthorized(key.lhs, key.rhs);
resourceAccessMap.put(key, access);
return access.isAllowed();
}
}
}));
} else {
recentlyFinishedTasks = taskStorageQueryAdapter.getRecentlyFinishedTaskStatuses();
}
final List<TaskResponseObject> completeTasks = Lists.transform(recentlyFinishedTasks, new Function<TaskStatus, TaskResponseObject>() {
@Override
public TaskResponseObject apply(TaskStatus taskStatus) {
// Would be nice to include the real created date, but the TaskStorage API doesn't yet allow it.
return new TaskResponseObject(taskStatus.getId(), new DateTime(0), new DateTime(0), Optional.of(taskStatus), TaskLocation.unknown());
}
});
return Response.ok(completeTasks).build();
}
use of com.google.common.base.Optional in project che by eclipse.
the class FileStructurePresenter method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(final Member member) {
if (member.isBinary()) {
final Resource resource = context.getResource();
if (resource == null) {
return;
}
final Optional<Project> project = resource.getRelatedProject();
javaNavigationService.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
javaNavigationService.getContent(project.get().getLocation(), member.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final String clazz = entry.getName().substring(0, entry.getName().indexOf('.'));
final VirtualFile file = new SyntheticFile(entry.getName(), clazz, content.getContent());
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
});
}
});
} else {
context.getWorkspaceRoot().getFile(member.getRootPath()).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
}
});
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
setCursorPosition(member.getFileRegion());
}
});
showInheritedMembers = false;
}
Aggregations