Skip to content

Commit

Permalink
CHE-4014; remove deprecated RemotePreferenceDao (#4455)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaposhnik committed Mar 17, 2017
1 parent c69d7aa commit 4521969
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 469 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public class WsAgentModule extends AbstractModule {
protected void configure() {
bind(ApiInfoService.class);

bind(PreferenceDao.class).to(org.eclipse.che.RemotePreferenceDao.class);

bind(OAuthTokenProvider.class).to(RemoteOAuthTokenProvider.class);
bind(SshServiceClient.class).to(HttpSshServiceClient.class);

Expand Down
14 changes: 10 additions & 4 deletions wsagent/che-core-api-git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-user</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-inject</artifactId>
Expand Down Expand Up @@ -117,6 +113,16 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-user</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ protected void configure() {
bind(TagListWriter.class);
bind(GitWebSocketMessenger.class);

//bind(GitConnectionFactory.class).to(NativeGitConnectionFactory.class);

bind(GitCheckoutDetector.class).asEagerSingleton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
*******************************************************************************/
package org.eclipse.che.api.git;

import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.ApiException;
import org.eclipse.che.api.core.rest.HttpJsonRequestFactory;
import org.eclipse.che.api.git.shared.GitUser;
import org.eclipse.che.api.user.server.spi.PreferenceDao;
import org.eclipse.che.commons.env.EnvironmentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.Map;

import static com.google.common.base.Strings.isNullOrEmpty;
Expand All @@ -34,23 +35,28 @@ public class LocalGitUserResolver implements GitUserResolver {

private static final Logger LOG = LoggerFactory.getLogger(LocalGitUserResolver.class);

private final PreferenceDao preferenceDao;
private final String apiUrl;
private final HttpJsonRequestFactory requestFactory;

@Inject
public LocalGitUserResolver(PreferenceDao preferenceDao) {
this.preferenceDao = preferenceDao;
public LocalGitUserResolver(@Named("che.api") String apiUrl, HttpJsonRequestFactory requestFactory) {
this.apiUrl = apiUrl;
this.requestFactory = requestFactory;
}

@Override
public GitUser getUser() {
String name = null;
String email = null;
try {
Map<String, String> preferences = preferenceDao.getPreferences(EnvironmentContext.getCurrent().getSubject().getUserId(),
"git.committer.\\w+");
Map<String, String> preferences = requestFactory.fromUrl(apiUrl + "/preferences")
.useGetMethod()
.addQueryParam("filter", "git.committer.\\w+")
.request()
.asProperties();
name = preferences.get("git.committer.name");
email = preferences.get("git.committer.email");
} catch (ServerException e) {
} catch (ApiException | IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
GitUser gitUser = newDto(GitUser.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
/*******************************************************************************
+ * Copyright (c) 2012-2017 Codenvy, S.A.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Codenvy, S.A. - initial API and implementation
+ *******************************************************************************/
package org.eclipse.che.api.git;

import org.eclipse.che.api.core.rest.HttpJsonRequest;
import org.eclipse.che.api.core.rest.HttpJsonRequestFactory;
import org.eclipse.che.api.core.rest.HttpJsonResponse;
import org.eclipse.che.api.user.server.PreferencesService;
import org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;


import static javax.ws.rs.core.UriBuilder.fromUri;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* Tests for {@link LocalGitUserResolver}
*
* @author Max Shaposhnik
*/

@Listeners(MockitoTestNGListener.class)
public class LocalGitUserResolverTest {

private final static String API_URL = "apiUrl";
private final static String PREFECENCES_URL = "apiUrl/preferences";

@Mock
private HttpJsonRequestFactory requestFactory;
@Mock
private HttpJsonResponse jsonResponse;

private HttpJsonRequest jsonRequest;

private LocalGitUserResolver resolver;

@BeforeMethod
public void setup() throws Exception {
jsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
when(jsonRequest.request()).thenReturn(jsonResponse);
when(requestFactory.fromUrl(anyString())).thenReturn(jsonRequest);
resolver = new LocalGitUserResolver(API_URL, requestFactory);
}

@Test
public void shouldMakeGetPreferencesRequest() throws Exception {
//when
resolver.getUser();
//then
String url = fromUri(PREFECENCES_URL).path(PreferencesService.class, "find").build().toString();
verify(requestFactory).fromUrl(eq(url));
verify(jsonRequest).useGetMethod();
verify(jsonRequest).request();
verify(jsonResponse).asProperties();
}
}
4 changes: 0 additions & 4 deletions wsagent/che-core-git-impl-jgit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-user</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
Expand Down
8 changes: 0 additions & 8 deletions wsagent/wsagent-local/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-user</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down

This file was deleted.

Loading

0 comments on commit 4521969

Please sign in to comment.