Search in sources :

Example 1 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class BreakpointManagerImpl method restoreBreakpoints.

private void restoreBreakpoints() {
    Storage localStorage = Storage.getLocalStorageIfSupported();
    if (localStorage == null) {
        return;
    }
    String data = localStorage.getItem(LOCAL_STORAGE_BREAKPOINTS_KEY);
    if (data == null || data.isEmpty()) {
        return;
    }
    List<StorableBreakpointDto> allDtoBreakpoints = dtoFactory.createListDtoFromJson(data, StorableBreakpointDto.class);
    Promise<Void> bpPromise = promises.resolve(null);
    for (final StorableBreakpointDto dto : allDtoBreakpoints) {
        bpPromise.thenPromise(new Function<Void, Promise<Void>>() {

            @Override
            public Promise<Void> apply(Void ignored) throws FunctionException {
                return appContext.getWorkspaceRoot().getFile(dto.getPath()).then(new Function<Optional<File>, Void>() {

                    @Override
                    public Void apply(Optional<File> file) throws FunctionException {
                        if (!file.isPresent()) {
                            return null;
                        }
                        if (dto.getType() == Type.CURRENT) {
                            doSetCurrentBreakpoint(file.get(), dto.getLineNumber());
                        } else {
                            addBreakpoint(new Breakpoint(dto.getType(), dto.getLineNumber(), dto.getPath(), file.get(), dto.isActive()));
                        }
                        return null;
                    }
                }).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError arg) throws OperationException {
                        Log.error(getClass(), "Failed to restore breakpoint. ", arg.getCause());
                    }
                });
            }
        });
    }
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) Optional(com.google.common.base.Optional) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) StorableBreakpointDto(org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto) Promise(org.eclipse.che.api.promises.client.Promise) Storage(com.google.gwt.storage.client.Storage) PromiseError(org.eclipse.che.api.promises.client.PromiseError) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 2 with Optional

use of com.google.common.base.Optional in project druid by druid-io.

the class OverlordResource method securedTaskRunnerWorkItem.

private Collection<? extends TaskRunnerWorkItem> securedTaskRunnerWorkItem(Collection<? extends TaskRunnerWorkItem> collectionToFilter, HttpServletRequest req) {
    final Map<Pair<Resource, Action>, Access> resourceAccessMap = new HashMap<>();
    final AuthorizationInfo authorizationInfo = (AuthorizationInfo) req.getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
    return Collections2.filter(collectionToFilter, new Predicate<TaskRunnerWorkItem>() {

        @Override
        public boolean apply(TaskRunnerWorkItem input) {
            final String taskId = input.getTaskId();
            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();
            }
        }
    });
}
Also used : Action(io.druid.server.security.Action) TaskRunnerWorkItem(io.druid.indexing.overlord.TaskRunnerWorkItem) 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) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) Pair(io.druid.java.util.common.Pair)

Example 3 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class OpenImplementationPresenter method actionPerformed.

public void actionPerformed(final Member member) {
    if (member.isBinary()) {
        final Resource resource = context.getResource();
        if (resource == null) {
            return;
        }
        final Optional<Project> project = resource.getRelatedProject();
        service.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                service.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(member.getFileRegion());
                            }
                        });
                    }
                });
            }
        });
    } 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(member.getFileRegion());
                        }
                    });
                }
            }
        });
    }
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            activeEditor.setFocus();
        }
    });
}
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)

Example 4 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class BasicActiveFileHandler method tryFindFileInProject.

protected void tryFindFileInProject(final Location location, final AsyncCallback<VirtualFile> callback) {
    Resource resource = appContext.getResource();
    if (resource == null) {
        callback.onFailure(new IllegalStateException("Resource is undefined"));
        return;
    }
    Optional<Project> project = resource.getRelatedProject();
    if (!project.isPresent()) {
        callback.onFailure(new IllegalStateException("Project is undefined"));
        return;
    }
    project.get().getFile(location.getTarget()).then(new Operation<Optional<File>>() {

        @Override
        public void apply(Optional<File> file) throws OperationException {
            if (file.isPresent()) {
                openFileAndScrollToLine(file.get(), location.getLineNumber(), callback);
            } else {
                callback.onFailure(new IllegalArgumentException(location.getTarget() + " not found."));
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            callback.onFailure(new IllegalArgumentException(location.getTarget() + " not found."));
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Optional(com.google.common.base.Optional) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 5 with Optional

use of com.google.common.base.Optional in project hadoop by apache.

the class ReconfigurationProtocolServerSideUtils method getReconfigurationStatus.

public static GetReconfigurationStatusResponseProto getReconfigurationStatus(ReconfigurationTaskStatus status) {
    GetReconfigurationStatusResponseProto.Builder builder = GetReconfigurationStatusResponseProto.newBuilder();
    builder.setStartTime(status.getStartTime());
    if (status.stopped()) {
        builder.setEndTime(status.getEndTime());
        assert status.getStatus() != null;
        for (Map.Entry<PropertyChange, Optional<String>> result : status.getStatus().entrySet()) {
            GetReconfigurationStatusConfigChangeProto.Builder changeBuilder = GetReconfigurationStatusConfigChangeProto.newBuilder();
            PropertyChange change = result.getKey();
            changeBuilder.setName(change.prop);
            changeBuilder.setOldValue(change.oldVal != null ? change.oldVal : "");
            if (change.newVal != null) {
                changeBuilder.setNewValue(change.newVal);
            }
            if (result.getValue().isPresent()) {
                // Get full stack trace.
                changeBuilder.setErrorMessage(result.getValue().get());
            }
            builder.addChanges(changeBuilder);
        }
    }
    return builder.build();
}
Also used : PropertyChange(org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange) Optional(com.google.common.base.Optional) GetReconfigurationStatusResponseProto(org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusResponseProto) Map(java.util.Map) GetReconfigurationStatusConfigChangeProto(org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.GetReconfigurationStatusConfigChangeProto)

Aggregations

Optional (com.google.common.base.Optional)319 List (java.util.List)79 Test (org.junit.Test)72 ArrayList (java.util.ArrayList)64 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)45 Map (java.util.Map)44 RevFeature (org.locationtech.geogig.api.RevFeature)42 Collections (java.util.Collections)38 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)36 Logger (org.slf4j.Logger)36 LoggerFactory (org.slf4j.LoggerFactory)36 ExecutionException (java.util.concurrent.ExecutionException)35 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)33 ImmutableList (com.google.common.collect.ImmutableList)32 HashMap (java.util.HashMap)32 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)30 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)30 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)28 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)28 File (java.io.File)27