Search in sources :

Example 81 with Optional

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);
}
Also used : DebugConfiguration(org.eclipse.che.ide.api.debug.DebugConfiguration) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) DebugConfigurationType(org.eclipse.che.ide.api.debug.DebugConfigurationType) Test(org.junit.Test)

Example 82 with Optional

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));
                }
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Optional(com.google.common.base.Optional) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 83 with Optional

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);
        }
    });
}
Also used : Status(org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status) FileStatus.defineStatus(org.eclipse.che.ide.ext.git.client.compare.FileStatus.defineStatus) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 84 with Optional

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();
}
Also used : Action(io.druid.server.security.Action) Optional(com.google.common.base.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) TaskStatus(io.druid.indexing.common.TaskStatus) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) DateTime(org.joda.time.DateTime) Pair(io.druid.java.util.common.Pair) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 85 with Optional

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;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) Resource(org.eclipse.che.ide.api.resources.Resource) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) Project(org.eclipse.che.ide.api.resources.Project) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Optional (com.google.common.base.Optional)159 RevFeature (org.locationtech.geogig.api.RevFeature)42 Test (org.junit.Test)38 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)28 ImmutableList (com.google.common.collect.ImmutableList)24 List (java.util.List)24 File (java.io.File)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)20 ArrayList (java.util.ArrayList)18 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)18 Function (com.google.common.base.Function)17 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)17 ObjectId (org.locationtech.geogig.api.ObjectId)17 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 Resource (org.eclipse.che.ide.api.resources.Resource)15 AddOp (org.locationtech.geogig.api.porcelain.AddOp)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 RevObject (org.locationtech.geogig.api.RevObject)13 NodeRef (org.locationtech.geogig.api.NodeRef)12 Feature (org.opengis.feature.Feature)12