Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2021-01-26 02:01:28 +0000
committerRyan D. Brooks2021-01-28 17:25:39 +0000
commitbcfe6c92d38f7488652a06d562c0aca3a4f60e5b (patch)
tree6225d3a18b22e58bf578954ba8a7215e67c56787
parent1ec92efa795c6ef356ea862de803e153542072ae (diff)
downloadorg.eclipse.osee-bcfe6c92d38f7488652a06d562c0aca3a4f60e5b.tar.gz
org.eclipse.osee-bcfe6c92d38f7488652a06d562c0aca3a4f60e5b.tar.xz
org.eclipse.osee-bcfe6c92d38f7488652a06d562c0aca3a4f60e5b.zip
refactor[TW18625]: Remove JaxRsClient usage from account.rest.client
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml3
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClient.java7
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java114
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java7
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java31
-rw-r--r--plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java8
-rw-r--r--plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java2
8 files changed, 88 insertions, 89 deletions
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
index 132cb64145a..ac70241085b 100644
--- a/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF
@@ -10,9 +10,8 @@ Import-Package: javax.ws.rs,
javax.ws.rs.client,
javax.ws.rs.core,
org.eclipse.osee.account.rest.model,
+ org.eclipse.osee.framework.core,
org.eclipse.osee.framework.core.data,
- org.eclipse.osee.framework.jdk.core.type,
- org.eclipse.osee.jaxrs,
- org.eclipse.osee.jaxrs.client
+ org.eclipse.osee.framework.jdk.core.type
Export-Package: org.eclipse.osee.account.rest.client
Bundle-Vendor: Eclipse Open System Engineering Environment
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
index b7f7404b4c2..0a792b46ea0 100644
--- 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
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
-<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" modified="update">
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start">
<implementation class="org.eclipse.osee.account.rest.client.internal.AccountClientImpl"/>
<service>
<provide interface="org.eclipse.osee.account.rest.client.AccountClient"/>
</service>
+ <reference bind="bindJaxRsApi" cardinality="1..1" interface="org.eclipse.osee.framework.core.JaxRsApi" name="jaxRsApi" policy="static"/>
</scr:component>
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
index 07afaf1e01b..8e95e4800e4 100644
--- 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
@@ -71,9 +71,4 @@ public interface AccountClient {
ResultSet<UnsubscribeInfo> getUnsubscribeUris(Long accountId, Collection<String> groupNames);
AccountWebPreferences getAccountWebPreferencesByUniqueField(ArtifactId accountId);
-
- boolean isLocalHost();
-
- String getBaseUri();
-
-}
+} \ No newline at end of file
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
index 94d2fe3e761..292b201b53b 100644
--- 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
@@ -15,12 +15,10 @@ package org.eclipse.osee.account.rest.client.internal;
import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNTS;
import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_ACTIVE;
-import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_ID_TEMPLATE;
import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_LOGIN;
import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_LOGOUT;
import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_PREFERENCES;
import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_SESSSIONS;
-import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_USERNAME_TEMPLATE;
import static org.eclipse.osee.framework.core.data.OseeClient.OSEE_APPLICATION_SERVER;
import java.net.URI;
import java.util.ArrayList;
@@ -28,6 +26,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -44,39 +43,29 @@ import org.eclipse.osee.account.rest.model.AccountSessionData;
import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
import org.eclipse.osee.account.rest.model.AccountWebPreferences;
import org.eclipse.osee.account.rest.model.SubscriptionData;
+import org.eclipse.osee.framework.core.JaxRsApi;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.type.ResultSets;
-import org.eclipse.osee.jaxrs.client.JaxRsClient;
-import org.eclipse.osee.jaxrs.client.JaxRsWebTarget;
/**
* @author Roberto E. Escobar
*/
public class AccountClientImpl implements AccountClient {
- private volatile JaxRsClient client;
- private volatile URI baseUri;
+ private URI baseUri;
+ private JaxRsApi jaxRsApi;
- public void start(Map<String, Object> properties) {
- update(properties);
- }
-
- public void stop() {
- client = null;
- baseUri = null;
+ public void bindJaxRsApi(JaxRsApi jaxRsApi) {
+ this.jaxRsApi = jaxRsApi;
}
- public void update(Map<String, Object> properties) {
- client = JaxRsClient.newBuilder().properties(properties).build();
+ public void start(Map<String, Object> properties) {
String address = properties != null ? (String) properties.get(OSEE_APPLICATION_SERVER) : null;
if (address == null) {
address = System.getProperty(OSEE_APPLICATION_SERVER, "");
}
baseUri = UriBuilder.fromUri(address).build();
- }
- private JaxRsWebTarget newTarget(URI uri) {
- return client.target(uri);
}
@Override
@@ -86,114 +75,97 @@ public class AccountClientImpl implements AccountClient {
data.setPassword(password);
data.setScheme(scheme);
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_LOGIN).build();
- return newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(data), AccountSessionData.class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, ACCOUNT_LOGIN);
+ return target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(data), AccountSessionData.class);
}
@Override
public boolean logout(AccountSessionData session) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_LOGOUT).build();
- Response response = newTarget(uri).request().post(Entity.json(session));
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, ACCOUNT_LOGOUT);
+ Response response = target.request().post(Entity.json(session));
return Status.OK.getStatusCode() == response.getStatus();
}
@Override
public AccountInfoData createAccount(String userName, AccountInput input) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_USERNAME_TEMPLATE).build(userName);
- return newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(input), AccountInfoData.class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, userName);
+ return target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(input), AccountInfoData.class);
}
@Override
public boolean deleteAccount(Long accountId) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).build(accountId);
- Response response = newTarget(uri).request().delete();
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId.toString());
+ Response response = target.request().delete();
return Status.OK.getStatusCode() == response.getStatus();
}
@Override
public ResultSet<AccountSessionDetailsData> getAccountSessionDataByUniqueField(String accountId) {
- URI uri =
- UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_SESSSIONS).build(accountId);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId, ACCOUNT_SESSSIONS);
AccountSessionDetailsData[] data =
- newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(AccountSessionDetailsData[].class);
+ target.request(MediaType.APPLICATION_JSON_TYPE).get(AccountSessionDetailsData[].class);
return ResultSets.newResultSet(data);
}
@Override
public ResultSet<AccountInfoData> getAllAccounts() {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).build();
- AccountInfoData[] accounts = newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(AccountInfoData[].class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS);
+ AccountInfoData[] accounts = target.request(MediaType.APPLICATION_JSON_TYPE).get(AccountInfoData[].class);
return ResultSets.newResultSet(accounts);
}
@Override
public AccountDetailsData getAccountDetailsById(Long accountId) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).build(accountId);
- return newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(AccountDetailsData.class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId.toString());
+ return target.request(MediaType.APPLICATION_JSON_TYPE).get(AccountDetailsData.class);
}
@Override
public AccountPreferencesData getAccountPreferencesById(Long accountId) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_PREFERENCES).build(
- accountId);
- return newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(AccountPreferencesData.class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId.toString(), ACCOUNT_PREFERENCES);
+ return target.request(MediaType.APPLICATION_JSON_TYPE).get(AccountPreferencesData.class);
}
@Override
public AccountWebPreferences getAccountWebPreferencesByUniqueField(ArtifactId accountId) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_PREFERENCES).path(ACCOUNT_ID_TEMPLATE).build(
- accountId.getId());
- return newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(AccountWebPreferences.class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, ACCOUNT_PREFERENCES, accountId.getIdString());
+ return target.request(MediaType.APPLICATION_JSON_TYPE).get(AccountWebPreferences.class);
}
@Override
public boolean setAccountActive(Long accountId, boolean active) {
- URI uri =
- UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_ACTIVE).build(accountId);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId.toString(), ACCOUNT_ACTIVE);
- boolean result;
+ Response response;
if (active) {
- result = setAccountActive(uri);
+ response = target.request().put(null);
} else {
- result = setAccountInActive(uri);
+ response = target.request().delete();
}
- return result;
+
+ return Status.OK.getStatusCode() == response.getStatus();
}
@Override
public boolean isAccountActive(Long accountId) {
- URI uri =
- UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_ACTIVE).build(accountId);
-
- AccountActiveData data = newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(AccountActiveData.class);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId.toString(), ACCOUNT_ACTIVE);
+ AccountActiveData data = target.request(MediaType.APPLICATION_JSON_TYPE).get(AccountActiveData.class);
return data.isActive();
}
- private boolean setAccountActive(URI uri) {
- Response response = newTarget(uri).request().put(null);
- return Status.OK.getStatusCode() == response.getStatus();
- }
-
- private boolean setAccountInActive(URI uri) {
- Response response = newTarget(uri).request().delete();
- return Status.OK.getStatusCode() == response.getStatus();
- }
-
@Override
public boolean setAccountPreferences(Long accountId, Map<String, String> preferences) {
- URI uri = UriBuilder.fromUri(baseUri).path(ACCOUNTS).path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_PREFERENCES).build(
- accountId);
+ WebTarget target = jaxRsApi.newTarget(ACCOUNTS, accountId.toString(), ACCOUNT_PREFERENCES);
AccountPreferencesInput input = new AccountPreferencesInput();
input.setMap(preferences);
- Response response = newTarget(uri).request().put(Entity.json(input));
+ Response response = target.request().put(Entity.json(input));
return Status.OK.getStatusCode() == response.getStatus();
}
private ResultSet<SubscriptionData> getSubscriptionsForAccount(Long accountId) {
- URI uri =
- UriBuilder.fromUri(baseUri).path("subscriptions").path("for-account").path("{account-id}").build(accountId);
- SubscriptionData[] data = newTarget(uri).request(MediaType.APPLICATION_JSON_TYPE).get(SubscriptionData[].class);
+ WebTarget target = jaxRsApi.newTarget("subscriptions", "for-account", accountId.toString());
+ SubscriptionData[] data = target.request(MediaType.APPLICATION_JSON_TYPE).get(SubscriptionData[].class);
return ResultSets.newResultSet(data);
}
@@ -231,14 +203,4 @@ public class AccountClientImpl implements AccountClient {
}
};
}
-
- @Override
- public boolean isLocalHost() {
- return baseUri.toString().contains("localhost");
- }
-
- @Override
- public String getBaseUri() {
- return baseUri.toString();
- }
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java
index 2717ba15050..66b6644b226 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java
@@ -44,7 +44,12 @@ public interface JaxRsApi {
WebTarget newTarget(String path);
- WebTarget newTarget(String path, String serverUsername, String serverPassword);
+ /**
+ * @return a WebTarget using the url created by the server's base url appened with the provided path segments
+ */
+ WebTarget newTarget(String... pathSegments);
+
+ WebTarget newTargetPasswd(String path, String serverUsername, String serverPassword);
<T> T newProxy(WebTarget target, Class<T> clazz);
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java
index b601b30eaeb..427ea95d842 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java
@@ -101,6 +101,37 @@ public class Collections {
return strB.toString();
}
+ public static String toString(String[] items, String separator) {
+ return toString(items, null, separator, null);
+ }
+
+ public static String toString(String[] items, String prefix, String separator, String suffix) {
+ if (items == null) {
+ return "";
+ }
+ StringBuilder strB = new StringBuilder();
+
+ if (prefix != null) {
+ strB.append(prefix);
+ }
+
+ boolean first = true;
+ for (String item : items) {
+ if (first) {
+ first = false;
+ } else {
+ strB.append(separator);
+ }
+ strB.append(item);
+ }
+
+ if (suffix != null) {
+ strB.append(suffix);
+ }
+
+ return strB.toString();
+ }
+
public static String toString(String separator, Object... items) {
return toString(separator, Arrays.asList(items));
}
diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java
index 4c8574fd42f..12a16be27eb 100644
--- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java
+++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java
@@ -34,6 +34,7 @@ import org.eclipse.osee.framework.core.data.RelationTypeToken;
import org.eclipse.osee.framework.core.util.JsonUtil;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.jaxrs.client.JaxRsClient.JaxRsClientFactory;
import org.eclipse.osee.jaxrs.client.internal.JaxRsClientRuntime;
@@ -99,7 +100,12 @@ public final class JaxRsApiImpl implements JaxRsApi {
}
@Override
- public WebTarget newTarget(String path, String serverUsername, String serverPassword) {
+ public WebTarget newTarget(String... pathSegments) {
+ return factory.newWebTarget(Collections.toString(pathSegments, baseUrl + "/", "/", null));
+ }
+
+ @Override
+ public WebTarget newTargetPasswd(String path, String serverUsername, String serverPassword) {
JaxRsClientConfig config = factory.copyDefaultConfig();
config.setServerPassword(serverPassword);
config.setServerUsername(serverUsername);
diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java
index 3c565d5dcf5..38140472592 100644
--- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java
+++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java
@@ -107,7 +107,7 @@ public class JaxRsOAuthResourceServerFilter implements ContainerRequestFilter {
}
private JaxRsOAuthResourceServerFilter build(ClientAccessTokenValidator validator) {
- validator.setTarget(jaxRsApi.newTarget(validationServerUri, resourceServerKey, resourceServerSecret));
+ validator.setTarget(jaxRsApi.newTargetPasswd(validationServerUri, resourceServerKey, resourceServerSecret));
OAuth2RequestFilter filter = new OAuth2RequestFilter();
filter.setTokenValidator(validator);

Back to the top