diff options
17 files changed, 846 insertions, 6 deletions
diff --git a/features/org.eclipse.osee.x.core.feature/feature.xml b/features/org.eclipse.osee.x.core.feature/feature.xml index 893be749086..3b2451180d4 100644 --- a/features/org.eclipse.osee.x.core.feature/feature.xml +++ b/features/org.eclipse.osee.x.core.feature/feature.xml @@ -187,6 +187,13 @@ unpack="false"/> <plugin + id="org.eclipse.osee.account.rest.client" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin id="org.eclipse.osee.account.rest.model" download-size="0" install-size="0" diff --git a/plugins/org.eclipse.osee.account.rest.client/.classpath b/plugins/org.eclipse.osee.account.rest.client/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.account.rest.client/.project b/plugins/org.eclipse.osee.account.rest.client/.project new file mode 100644 index 00000000000..eee1e6f2a58 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.account.rest.client</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..d9428238095 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OSEE Account REST Client (Incubation) +Bundle-SymbolicName: org.eclipse.osee.account.rest.client +Bundle-Version: 0.17.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Service-Component: OSGI-INF/*.xml +Import-Package: com.google.inject, + com.google.inject.binder, + com.google.inject.matcher, + com.google.inject.spi, + com.sun.jersey.api.client;version="1.18.0", + com.sun.jersey.api.client.async;version="1.18.0", + com.sun.jersey.api.client.config;version="1.18.0", + com.sun.jersey.api.client.filter;version="1.18.0", + javax.ws.rs, + javax.ws.rs.core, + org.eclipse.osee.account.rest.model, + org.eclipse.osee.framework.core.services, + org.eclipse.osee.framework.jdk.core.type, + org.eclipse.osee.rest.client, + org.eclipse.osee.rest.model +Export-Package: org.eclipse.osee.account.rest.client +Bundle-Vendor: Eclipse Open System Engineering Environment +Require-Bundle: org.codehaus.jackson.core;bundle-version="1.9.2", + org.codehaus.jackson.jaxrs;bundle-version="1.9.2", + org.codehaus.jackson.mapper;bundle-version="1.9.2" diff --git a/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml b/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml new file mode 100644 index 00000000000..b874e8e7ae1 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop"> + <implementation class="org.eclipse.osee.account.rest.client.internal.AccountClientImpl"/> + <service> + <provide interface="org.eclipse.osee.account.rest.client.AccountClient"/> + </service> + <reference bind="setWebClientProvider" cardinality="1..1" interface="org.eclipse.osee.rest.client.WebClientProvider" name="WebClientProvider" policy="static"/> + <reference bind="setUriProvider" cardinality="1..1" interface="org.eclipse.osee.framework.core.services.URIProvider" name="URIProvider" policy="static"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.account.rest.client/build.properties b/plugins/org.eclipse.osee.account.rest.client/build.properties new file mode 100644 index 00000000000..c58ea2178c3 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ diff --git a/plugins/org.eclipse.osee.account.rest.client/pom.xml b/plugins/org.eclipse.osee.account.rest.client/pom.xml new file mode 100644 index 00000000000..380ed54283d --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/pom.xml @@ -0,0 +1,34 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.x.core.parent</artifactId> + <version>0.17.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.x.core.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.account.rest.client</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OSEE Account REST Client - (Incubation)</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClient.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClient.java new file mode 100644 index 00000000000..29ed34f2bca --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClient.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.account.rest.client; + +import java.util.Map; +import org.eclipse.osee.account.rest.model.AccountAccessData; +import org.eclipse.osee.account.rest.model.AccountDetailsData; +import org.eclipse.osee.account.rest.model.AccountInfoData; +import org.eclipse.osee.account.rest.model.AccountInput; +import org.eclipse.osee.account.rest.model.AccountPreferencesData; +import org.eclipse.osee.account.rest.model.AccountSessionData; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; + +/** + * AccountId parameter can be any field that uniquely identifies an account such as: + * <ol> + * <li>ID</li> + * <li>UUID</li> + * <li>Email</li> + * <li>User name</li> + * <li>Display name</li> + * </ol> + * + * @author Roberto E. Escobar + */ +public interface AccountClient { + + AccountSessionData login(String scheme, String username, String password); + + boolean logout(AccountSessionData session); + + AccountInfoData createAccount(String userName, AccountInput input); + + boolean deleteAccount(String uuid); + + ResultSet<AccountAccessData> getAccountAccessDataByUniqueField(String accountId); + + ResultSet<AccountInfoData> getAllAccounts(); + + AccountDetailsData getAccountDetailsByUniqueField(String accountId); + + AccountPreferencesData getAccountPreferencesByUniqueField(String accountId); + + boolean setAccountActive(String accountId, boolean active); + + boolean isAccountActive(String accountId); + + boolean setAccountPreferences(String accountId, Map<String, String> preferences); + +} diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java new file mode 100644 index 00000000000..5ffc678a102 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.account.rest.client; + +import org.eclipse.osee.account.rest.client.internal.AccountClientImpl; +import org.eclipse.osee.account.rest.client.internal.AccountClientModule; +import org.eclipse.osee.rest.client.OseeClientConfig; +import org.eclipse.osee.rest.client.OseeRestClientStandaloneSetup; +import com.google.inject.Module; + +/** + * Class to use when using the API in a non-OSGI environment + * + * @author Roberto E. Escobar + */ +public final class AccountClientStandaloneSetup { + + private AccountClientStandaloneSetup() { + // Utility class + } + + public static AccountClient createClient(OseeClientConfig config) { + Module module = new AccountClientModule(); + return OseeRestClientStandaloneSetup.createClient(AccountClientImpl.class, config, module); + } +} diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java new file mode 100644 index 00000000000..8ff9b2ae0b8 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.account.rest.client.internal; + +import java.net.URI; +import java.util.Map; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import org.eclipse.osee.account.rest.client.AccountClient; +import org.eclipse.osee.account.rest.model.AccountAccessData; +import org.eclipse.osee.account.rest.model.AccountActiveData; +import org.eclipse.osee.account.rest.model.AccountContexts; +import org.eclipse.osee.account.rest.model.AccountDetailsData; +import org.eclipse.osee.account.rest.model.AccountInfoData; +import org.eclipse.osee.account.rest.model.AccountInput; +import org.eclipse.osee.account.rest.model.AccountLoginData; +import org.eclipse.osee.account.rest.model.AccountPreferencesData; +import org.eclipse.osee.account.rest.model.AccountPreferencesInput; +import org.eclipse.osee.account.rest.model.AccountSessionData; +import org.eclipse.osee.framework.core.services.URIProvider; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.eclipse.osee.framework.jdk.core.type.ResultSets; +import org.eclipse.osee.rest.client.WebClientProvider; +import com.google.inject.Inject; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.UniformInterfaceException; +import com.sun.jersey.api.client.WebResource; + +/** + * @author Roberto E. Escobar + */ +public class AccountClientImpl implements AccountClient { + + private URIProvider uriProvider; + private WebClientProvider clientProvider; + + @Inject + public void setWebClientProvider(WebClientProvider clientProvider) { + this.clientProvider = clientProvider; + } + + @Inject + public void setUriProvider(URIProvider uriProvider) { + this.uriProvider = uriProvider; + } + + public void start() { + // + } + + public void stop() { + // + } + + private UriBuilder newBuilder() { + return UriBuilder.fromUri(uriProvider.getApplicationServerURI()).path(AccountContexts.ACCOUNTS_BASE); + } + + private <T> T get(URI uri, Class<T> clazz) { + WebResource resource = clientProvider.createResource(uri); + try { + return resource.accept(MediaType.APPLICATION_JSON_TYPE).get(clazz); + } catch (UniformInterfaceException ex) { + throw clientProvider.handleException(ex); + } + } + + @Override + public AccountSessionData login(String scheme, String username, String password) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_LOGIN)// + .build(); + + AccountLoginData data = new AccountLoginData(); + data.setUsername(username); + data.setPassword(password); + data.setScheme(scheme); + + WebResource resource = clientProvider.createResource(uri); + try { + return resource.post(AccountSessionData.class, data); + } catch (UniformInterfaceException ex) { + throw clientProvider.handleException(ex); + } + } + + @Override + public boolean logout(AccountSessionData session) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_LOGOUT)// + .build(); + + WebResource resource = clientProvider.createResource(uri); + int status; + try { + ClientResponse response = resource.post(ClientResponse.class, session); + status = response.getStatus(); + } catch (UniformInterfaceException ex) { + ClientResponse clientResponse = ex.getResponse(); + status = clientResponse.getStatus(); + if (Status.NOT_MODIFIED.getStatusCode() != status) { + throw clientProvider.handleException(ex); + } + } + return Status.OK.getStatusCode() == status; + } + + @Override + public AccountInfoData createAccount(String userName, AccountInput input) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_USERNAME_TEMPLATE)// + .build(userName); + + WebResource resource = clientProvider.createResource(uri); + try { + AccountInfoData data = + resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).post( + AccountInfoData.class, input); + return data; + } catch (UniformInterfaceException ex) { + throw clientProvider.handleException(ex); + } + } + + @Override + public boolean deleteAccount(String accountId) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// + .build(accountId); + WebResource resource = clientProvider.createResource(uri); + + ClientResponse response; + try { + response = resource.delete(ClientResponse.class); + } catch (UniformInterfaceException ex) { + throw clientProvider.handleException(ex); + } + int status = response.getStatus(); + return Status.OK.getStatusCode() == status; + } + + @Override + public ResultSet<AccountAccessData> getAccountAccessDataByUniqueField(String accountId) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE) // + .path(AccountContexts.ACCOUNT_SESSSIONS)// + .build(accountId); + AccountAccessData[] data = get(uri, AccountAccessData[].class); + return ResultSets.newResultSet(data); + } + + @Override + public ResultSet<AccountInfoData> getAllAccounts() { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .build(); + AccountInfoData[] accounts = get(uri, AccountInfoData[].class); + return ResultSets.newResultSet(accounts); + } + + @Override + public AccountDetailsData getAccountDetailsByUniqueField(String accountId) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// + .build(accountId); + return get(uri, AccountDetailsData.class); + } + + @Override + public AccountPreferencesData getAccountPreferencesByUniqueField(String accountId) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// + .path(AccountContexts.ACCOUNT_PREFERENCES)// + .build(accountId); + AccountPreferencesData data = get(uri, AccountPreferencesData.class); + return data; + } + + @Override + public boolean setAccountActive(String accountId, boolean active) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// + .path(AccountContexts.ACCOUNT_ACTIVE)// + .build(accountId); + WebResource resource = clientProvider.createResource(uri); + boolean result; + if (active) { + result = setAccountActive(resource); + } else { + result = setAccountInActive(resource); + } + return result; + } + + @Override + public boolean isAccountActive(String accountId) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// + .path(AccountContexts.ACCOUNT_ACTIVE)// + .build(accountId); + AccountActiveData data = get(uri, AccountActiveData.class); + return data.isActive(); + } + + private boolean setAccountActive(WebResource resource) { + int status; + try { + ClientResponse response = resource.put(ClientResponse.class); + status = response.getStatus(); + } catch (UniformInterfaceException ex) { + ClientResponse clientResponse = ex.getResponse(); + status = clientResponse.getStatus(); + if (Status.NOT_MODIFIED.getStatusCode() != status) { + throw clientProvider.handleException(ex); + } + } + return Status.OK.getStatusCode() == status; + } + + private boolean setAccountInActive(WebResource resource) { + int status; + try { + ClientResponse response = resource.delete(ClientResponse.class); + status = response.getStatus(); + } catch (UniformInterfaceException ex) { + ClientResponse clientResponse = ex.getResponse(); + status = clientResponse.getStatus(); + if (Status.NOT_MODIFIED.getStatusCode() != status) { + throw clientProvider.handleException(ex); + } + } + return Status.OK.getStatusCode() == status; + } + + @Override + public boolean setAccountPreferences(String accountId, Map<String, String> preferences) { + URI uri = newBuilder()// + .path(AccountContexts.ACCOUNTS)// + .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// + .path(AccountContexts.ACCOUNT_PREFERENCES)// + .build(accountId); + + AccountPreferencesInput input = new AccountPreferencesInput(); + input.setMap(preferences); + + WebResource resource = clientProvider.createResource(uri); + int status; + try { + ClientResponse response = resource.put(ClientResponse.class, input); + status = response.getStatus(); + } catch (UniformInterfaceException ex) { + ClientResponse clientResponse = ex.getResponse(); + status = clientResponse.getStatus(); + if (Status.NOT_MODIFIED.getStatusCode() != status) { + throw clientProvider.handleException(ex); + } + } + return Status.OK.getStatusCode() == status; + } + +} diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java new file mode 100644 index 00000000000..82b20903f18 --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.account.rest.client.internal; + +import org.eclipse.osee.account.rest.client.AccountClient; +import org.eclipse.osee.framework.core.services.URIProvider; +import com.google.inject.AbstractModule; +import com.google.inject.TypeLiteral; +import com.google.inject.matcher.AbstractMatcher; +import com.google.inject.matcher.Matcher; +import com.google.inject.spi.InjectionListener; +import com.google.inject.spi.TypeEncounter; +import com.google.inject.spi.TypeListener; + +/** + * @author Roberto E. Escobar + */ +public class AccountClientModule extends AbstractModule { + + @Override + protected void configure() { + bind(AccountClient.class).to(AccountClientImpl.class); + TypeListener listener = new TypeListener() { + + @Override + public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { + encounter.register(new InjectionListener<I>() { + + @Override + public void afterInjection(I injectee) { + AccountClientImpl client = (AccountClientImpl) injectee; + client.start(); + } + }); + } + }; + bindListener(subtypeOf(AccountClientImpl.class), listener); + bind(URIProvider.class).to(StandadloneUriProviderImpl.class); + } + + private static Matcher<? super TypeLiteral<?>> subtypeOf(Class<?> superclass) { + return new SubTypeOfMatcher(TypeLiteral.get(AccountClientImpl.class)); + } + + private static final class SubTypeOfMatcher extends AbstractMatcher<TypeLiteral<?>> { + private final TypeLiteral<AccountClientImpl> superType; + + public SubTypeOfMatcher(TypeLiteral<AccountClientImpl> superType) { + super(); + this.superType = superType; + } + + @Override + public boolean matches(TypeLiteral<?> subType) { + return subType.equals(superType) || superType.getRawType().isAssignableFrom(subType.getRawType()); + } + } + +} diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/StandadloneUriProviderImpl.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/StandadloneUriProviderImpl.java new file mode 100644 index 00000000000..c7357b2cfda --- /dev/null +++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/StandadloneUriProviderImpl.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.account.rest.client.internal; + +import java.net.URI; +import java.net.URISyntaxException; +import org.eclipse.osee.framework.core.services.URIProvider; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.rest.client.OseeServerAddress; +import com.google.inject.Inject; + +/** + * @author Roberto E. Escobar + */ +public class StandadloneUriProviderImpl implements URIProvider { + + private final String serverAddress; + + @Inject + public StandadloneUriProviderImpl(@OseeServerAddress String serverAddress) { + this.serverAddress = serverAddress; + } + + @Override + public URI getApplicationServerURI() { + URI toReturn = null; + try { + toReturn = new URI(serverAddress); + } catch (URISyntaxException ex) { + throw new OseeCoreException(ex); + } + return toReturn; + } + +}; diff --git a/plugins/org.eclipse.osee.x.core.parent/pom.xml b/plugins/org.eclipse.osee.x.core.parent/pom.xml index 9f18774bc37..02df270547e 100644 --- a/plugins/org.eclipse.osee.x.core.parent/pom.xml +++ b/plugins/org.eclipse.osee.x.core.parent/pom.xml @@ -38,7 +38,7 @@ <module>../../plugins/org.eclipse.osee.account.admin</module> <module>../../plugins/org.eclipse.osee.account.admin.test</module> - + <module>../../plugins/org.eclipse.osee.framework.logging</module> <module>../../plugins/org.eclipse.osee.framework.logging.test</module> @@ -60,10 +60,11 @@ <module>../../plugins/org.eclipse.osee.rest.admin.test</module> <module>../../plugins/org.eclipse.osee.rest.client</module> - <module>../../plugins/org.eclipse.osee.account.rest</module> - <module>../../plugins/org.eclipse.osee.account.rest.test</module> <module>../../plugins/org.eclipse.osee.account.rest.model</module> - + <module>../../plugins/org.eclipse.osee.account.rest</module> + <module>../../plugins/org.eclipse.osee.account.rest.test</module> + <module>../../plugins/org.eclipse.osee.account.rest.client</module> + <module>../../features/org.eclipse.osee.x.core.external.feature</module> <module>../../features/org.eclipse.osee.x.core.feature</module> diff --git a/plugins/org.eclipse.osee.x.server.integration.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.x.server.integration.tests/META-INF/MANIFEST.MF index 378ab51dc1f..faf860da3c1 100644 --- a/plugins/org.eclipse.osee.x.server.integration.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.x.server.integration.tests/META-INF/MANIFEST.MF @@ -9,7 +9,10 @@ Require-Bundle: org.junit, org.eclipse.osee.orcs.rest.model, org.eclipse.osee.orcs.rest.client, org.databene.contiperf -Import-Package: org.eclipse.osee.framework.core.data, +Import-Package: org.apache.commons.lang.math, + org.eclipse.osee.account.rest.client, + org.eclipse.osee.account.rest.model, + org.eclipse.osee.framework.core.data, org.eclipse.osee.framework.core.enums, org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.jdk.core.type, diff --git a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/ServerIntegrationTestSuite.java b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/ServerIntegrationTestSuite.java index ad700d45b9f..7ffe074724b 100644 --- a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/ServerIntegrationTestSuite.java +++ b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/ServerIntegrationTestSuite.java @@ -10,12 +10,13 @@ *******************************************************************************/ package org.eclipse.osee.x.server.integration.tests; +import org.eclipse.osee.x.server.integration.tests.performance.AccountClientTest; import org.eclipse.osee.x.server.integration.tests.performance.OseeClientQueryTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) -@Suite.SuiteClasses({OseeClientQueryTest.class}) +@Suite.SuiteClasses({OseeClientQueryTest.class, AccountClientTest.class}) public class ServerIntegrationTestSuite { // Test Suite } diff --git a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/AccountClientTest.java b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/AccountClientTest.java new file mode 100644 index 00000000000..80b55798e11 --- /dev/null +++ b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/AccountClientTest.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.x.server.integration.tests.performance; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.lang.math.RandomUtils; +import org.eclipse.osee.account.rest.client.AccountClient; +import org.eclipse.osee.account.rest.model.AccountAccessData; +import org.eclipse.osee.account.rest.model.AccountDetailsData; +import org.eclipse.osee.account.rest.model.AccountInfoData; +import org.eclipse.osee.account.rest.model.AccountInput; +import org.eclipse.osee.account.rest.model.AccountPreferencesData; +import org.eclipse.osee.account.rest.model.AccountSessionData; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.MethodRule; +import org.junit.rules.TestName; +import org.junit.runners.MethodSorters; + +/** + * @author Roberto E. Escobar + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class AccountClientTest { + + @Rule + public MethodRule performanceRule = IntegrationUtil.createPerformanceRule(); + + @Rule + public TestName testName = new TestName(); + + private final AtomicBoolean isFirst = new AtomicBoolean(true); + + private AccountClient client; + private AccountInfoData newAccount; + private String username; + private String name; + private String email; + private boolean active; + private long accountId; + private String guid; + private Map<String, String> prefs; + + @Before + public void setUp() { + client = IntegrationUtil.createAccountClient(); + + String methodName = testName.getMethodName(); + + if (isFirst.compareAndSet(true, false)) { + double value = RandomUtils.nextDouble(); + + username = String.format("userName_%s_%s", methodName, value); + name = String.format("name__%s_%s", methodName, value); + email = String.format("email_%s_%s@hello.com", methodName, value); + active = true; + + prefs = new HashMap<String, String>(); + prefs.put("a", "1"); + prefs.put("b", "2"); + prefs.put("c", "3"); + + AccountInput input = new AccountInput(); + input.setActive(active); + input.setEmail(email); + input.setName(name); + input.setPreferences(prefs); + + newAccount = client.createAccount(username, input); + accountId = newAccount.getAccountId(); + guid = newAccount.getGuid(); + + assertTrue(newAccount.getAccountId() > 0L); + assertNotNull(newAccount.getGuid()); + + assertEquals(email, newAccount.getEmail()); + assertEquals(name, newAccount.getName()); + assertEquals(username, newAccount.getUserName()); + assertEquals(active, newAccount.isActive()); + } + } + + @Test + public void test_A_LogInOut() { + AccountSessionData session1 = client.login("none", email, "dummy"); + + assertEquals(accountId, session1.getAccountId()); + assertNotNull(session1.getToken()); + + AccountAccessData access = client.getAccountAccessDataByUniqueField(email).getExactlyOne(); + + assertEquals(accountId, access.getAccountId()); + assertNotNull(access.getAccessDetails()); + assertNotNull(access.getAccessedFrom()); + assertNotNull(access.getCreatedOn()); + assertNotNull(access.getLastAccessedOn()); + + AccountSessionData session2 = client.login("none", email, "dummy"); + assertEquals(accountId, session2.getAccountId()); + assertNotNull(session2.getToken()); + + assertEquals(false, session1.getToken().equals(session2.getToken())); + + ResultSet<AccountAccessData> result = client.getAccountAccessDataByUniqueField(email); + assertEquals(2, result.size()); + Iterator<AccountAccessData> iterator = result.iterator(); + AccountAccessData access1 = iterator.next(); + AccountAccessData access2 = iterator.next(); + assertEquals(accountId, access1.getAccountId()); + assertEquals(accountId, access2.getAccountId()); + + assertEquals(true, client.logout(session1)); + assertEquals(true, client.logout(session2)); + + ResultSet<AccountAccessData> result2 = client.getAccountAccessDataByUniqueField(email); + assertEquals(true, result2.isEmpty()); + } + + @Test + public void test_B_GetAccountDetails() { + AccountDetailsData actual = client.getAccountDetailsByUniqueField(email); + + assertEquals(accountId, actual.getAccountId()); + assertEquals(guid, actual.getGuid()); + assertEquals(email, actual.getEmail()); + assertEquals(name, actual.getName()); + assertEquals(username, actual.getUserName()); + assertEquals(active, actual.isActive()); + } + + @Test + public void test_C_GetAccounts() { + ResultSet<AccountInfoData> result = client.getAllAccounts(); + assertEquals(false, result.isEmpty()); + } + + @Test + public void test_D_GetAccountPreferences() { + AccountPreferencesData actual = client.getAccountPreferencesByUniqueField(email); + + assertEquals(accountId, actual.getId()); + Map<String, String> actualMap = actual.getMap(); + assertEquals(3, actualMap.size()); + assertEquals("1", actualMap.get("a")); + assertEquals("2", actualMap.get("b")); + assertEquals("3", actualMap.get("c")); + } + + @Test + public void test_E_Active() { + boolean actual = client.isAccountActive(email); + assertEquals(active, actual); + + boolean modified = client.setAccountActive(email, active); + assertEquals(false, modified); + + modified = client.setAccountActive(email, !active); + assertEquals(true, modified); + + actual = client.isAccountActive(email); + assertEquals(!active, actual); + + modified = client.setAccountActive(email, active); + assertEquals(true, modified); + + actual = client.isAccountActive(email); + assertEquals(active, actual); + } + + @Test + public void test_F_SetAccountPreferences() { + Map<String, String> newPrefs = new HashMap<String, String>(); + newPrefs.put("r", "7"); + newPrefs.put("s", "8"); + newPrefs.put("t", "9"); + newPrefs.put("u", "10"); + + boolean modified = client.setAccountPreferences(email, newPrefs); + assertEquals(true, modified); + + modified = client.setAccountPreferences(email, newPrefs); + assertEquals(false, modified); + + AccountPreferencesData actual = client.getAccountPreferencesByUniqueField(email); + + assertEquals(accountId, actual.getId()); + Map<String, String> actualMap = actual.getMap(); + assertEquals(4, actualMap.size()); + assertEquals("7", actualMap.get("r")); + assertEquals("8", actualMap.get("s")); + assertEquals("9", actualMap.get("t")); + assertEquals("10", actualMap.get("u")); + } + + @Test + public void test_G_DeleteAccount() { + int beforeDelete = client.getAllAccounts().size(); + + boolean modified = client.deleteAccount(email); + assertEquals(true, modified); + + modified = client.deleteAccount(email); + assertEquals(false, modified); + + int afterDelete = client.getAllAccounts().size(); + assertEquals(beforeDelete - 1, afterDelete); + } +} diff --git a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java index 0f0cdbe071d..1c0590b4e71 100644 --- a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java +++ b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java @@ -14,6 +14,8 @@ import org.databene.contiperf.junit.ContiPerfRule; import org.databene.contiperf.report.CSVLatencyReportModule; import org.databene.contiperf.report.CSVSummaryReportModule; import org.databene.contiperf.report.HtmlReportModule; +import org.eclipse.osee.account.rest.client.AccountClient; +import org.eclipse.osee.account.rest.client.AccountClientStandaloneSetup; import org.eclipse.osee.orcs.rest.client.OseeClient; import org.eclipse.osee.orcs.rest.client.OseeClientStandaloneSetup; import org.eclipse.osee.rest.client.OseeClientConfig; @@ -43,4 +45,9 @@ public final class IntegrationUtil { return config; } + public static AccountClient createAccountClient() { + OseeClientConfig config = createClientConfig(); + return AccountClientStandaloneSetup.createClient(config); + } + } |