Skip to content

Commit

Permalink
refactor: rename from generic login to sap login
Browse files Browse the repository at this point in the history
  • Loading branch information
nickchecan committed Jan 15, 2025
1 parent fabc25a commit a88ff11
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import com.developer.nefarious.zjoule.plugin.login.LoginWizard;
import com.developer.nefarious.zjoule.plugin.login.SapLoginWizard;

/**
* Handles the "Login" action for connecting to a BTP subaccount.
* <p>
* This class extends {@link Action} and launches a {@link LoginWizard} in a
* This class extends {@link Action} and launches a {@link SapLoginWizard} in a
* {@link WizardDialog} when the action is triggered. It also manages the icon for the action.
*/
public class LoginHandler extends Action {
Expand Down Expand Up @@ -60,12 +60,12 @@ private LoginHandler(final Shell shell, final Browser browser) {
/**
* Executes the "Login" action.
* <p>
* This method launches the {@link LoginWizard} in a {@link WizardDialog},
* This method launches the {@link SapLoginWizard} in a {@link WizardDialog},
* allowing the user to log in to their BTP subaccount.
*/
@Override
public void run() {
LoginWizard wizard = new LoginWizard(browser);
SapLoginWizard wizard = new SapLoginWizard(browser);
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.open();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.developer.nefarious.zjoule.plugin.auth.AuthClientHelper;
import com.developer.nefarious.zjoule.plugin.auth.IAuthClient;
import com.developer.nefarious.zjoule.plugin.auth.SessionManager;
import com.developer.nefarious.zjoule.plugin.login.api.ILoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.LoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.LoginClientHelper;
import com.developer.nefarious.zjoule.plugin.login.api.ISapLoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.SapLoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.SapLoginClientHelper;
import com.developer.nefarious.zjoule.plugin.login.memory.TemporaryMemoryAccessToken;
import com.developer.nefarious.zjoule.plugin.login.memory.TemporaryMemoryDeployment;
import com.developer.nefarious.zjoule.plugin.login.memory.TemporaryMemoryResourceGroup;
Expand All @@ -26,24 +26,24 @@
* It integrates with temporary memory components and client objects to handle authentication
* and session management.
*/
public class LoginWizard extends Wizard {
public class SapLoginWizard extends Wizard {

/** The browser instance used for login-related UI updates. */
private Browser browser;

/** The client responsible for managing the login process. */
private ILoginClient loginClient;
private ISapLoginClient sapLoginClient;

/**
* Constructs a new {@code LoginWizard} instance.
*
* @param browser the {@link Browser} instance used for login-related UI updates.
*/
public LoginWizard(final Browser browser) {
public SapLoginWizard(final Browser browser) {
this.browser = browser;

setWindowTitle("AI Provider Setup");
loginClient = createLoginClient();
sapLoginClient = createLoginClient();
}

/**
Expand All @@ -57,21 +57,21 @@ public LoginWizard(final Browser browser) {
*/
@Override
public void addPages() {
addPage(new FirstLoginWizardPage(loginClient));
addPage(new SecondLoginWizardPage(loginClient, TemporaryMemoryResourceGroup.getInstance(), TemporaryMemoryDeployment.getInstance()));
addPage(new FirstLoginWizardPage(sapLoginClient));
addPage(new SecondLoginWizardPage(sapLoginClient, TemporaryMemoryResourceGroup.getInstance(), TemporaryMemoryDeployment.getInstance()));
}

/**
* Creates and initializes the {@link ILoginClient} used for the login process.
* Creates and initializes the {@link ISapLoginClient} used for the login process.
*
* @return a new {@link ILoginClient} instance.
* @return a new {@link ISapLoginClient} instance.
*/
private ILoginClient createLoginClient() {
private ISapLoginClient createLoginClient() {
TemporaryMemoryAccessToken tmpMemoryAccessToken = TemporaryMemoryAccessToken.getInstance();
TemporaryMemoryServiceKey tmpMemoryServiceKey = TemporaryMemoryServiceKey.getInstance();

IAuthClient tmpAuthClient = new AuthClient(tmpMemoryAccessToken, tmpMemoryServiceKey, new AuthClientHelper());
return new LoginClient(new LoginClientHelper(), tmpAuthClient);
return new SapLoginClient(new SapLoginClientHelper(), tmpAuthClient);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* The {@code ILoginClient} defines methods for retrieving deployments and resource groups
* by interacting with the SAP AI Core API.
*/
public interface ILoginClient {
public interface ISapLoginClient {

/**
* Retrieves a list of deployments from the SAP AI Core API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* The {@code ILoginClientHelper} defines methods for creating API request URIs
* and parsing JSON response bodies into their corresponding Java objects.
*/
public interface ILoginClientHelper {
public interface ISapLoginClientHelper {

/**
* Creates a URI for the given API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
import com.developer.nefarious.zjoule.plugin.models.ServiceKey;

/**
* Implements the {@link ILoginClient} interface for managing API interactions related to login operations.
* Implements the {@link ISapLoginClient} interface for managing API interactions related to login operations.
* <p>
* The {@code LoginClient} class communicates with SAP AI Core APIs to retrieve deployments
* and resource groups, leveraging an {@link IAuthClient} for authentication and an {@link ILoginClientHelper}
* and resource groups, leveraging an {@link IAuthClient} for authentication and an {@link ISapLoginClientHelper}
* for building requests and parsing responses.
*/
public class LoginClient implements ILoginClient {
public class SapLoginClient implements ISapLoginClient {

/** The HTTP client used for making API requests. */
private HttpClient httpClient;

/** Helper class for constructing requests and parsing responses. */
private ILoginClientHelper loginClientHelper;
private ISapLoginClientHelper sapLoginClientHelper;

/** The authentication client used for retrieving access tokens. */
private IAuthClient authClient;

/**
* Constructs a new {@code LoginClient} instance.
*
* @param loginClientHelper the helper for constructing requests and parsing responses.
* @param sapLoginClientHelper the helper for constructing requests and parsing responses.
* @param authClient the authentication client for retrieving access tokens.
*/
public LoginClient(final ILoginClientHelper loginClientHelper, final IAuthClient authClient) {
public SapLoginClient(final ISapLoginClientHelper sapLoginClientHelper, final IAuthClient authClient) {
httpClient = HttpClient.newHttpClient();
this.loginClientHelper = loginClientHelper;
this.sapLoginClientHelper = sapLoginClientHelper;
this.authClient = authClient;
}

Expand All @@ -45,7 +45,7 @@ public LoginClient(final ILoginClientHelper loginClientHelper, final IAuthClient
@Override
public GetDeploymentsResponse getDeployments(final ServiceKey serviceKey, final String resourceGroup)
throws IOException, InterruptedException {
URI endpoint = loginClientHelper.createAuthUri(serviceKey.getServiceURL() + "/lm/deployments");
URI endpoint = sapLoginClientHelper.createAuthUri(serviceKey.getServiceURL() + "/lm/deployments");

HttpRequest request = HttpRequest.newBuilder()
.uri(endpoint)
Expand All @@ -56,7 +56,7 @@ public GetDeploymentsResponse getDeployments(final ServiceKey serviceKey, final

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

return loginClientHelper.parseDeploymentsResponseToObject(response.body());
return sapLoginClientHelper.parseDeploymentsResponseToObject(response.body());
}

/**
Expand All @@ -65,7 +65,7 @@ public GetDeploymentsResponse getDeployments(final ServiceKey serviceKey, final
@Override
public GetResourceGroupsResponse getResourceGroups(final ServiceKey serviceKey)
throws IOException, InterruptedException {
URI endpoint = loginClientHelper.createAuthUri(serviceKey.getServiceURL() + "/admin/resourceGroups");
URI endpoint = sapLoginClientHelper.createAuthUri(serviceKey.getServiceURL() + "/admin/resourceGroups");

HttpRequest request = HttpRequest.newBuilder()
.uri(endpoint)
Expand All @@ -75,6 +75,6 @@ public GetResourceGroupsResponse getResourceGroups(final ServiceKey serviceKey)

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

return loginClientHelper.parseResourceGroupsResponseToObject(response.body());
return sapLoginClientHelper.parseResourceGroupsResponseToObject(response.body());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* <p>
* The {@code LoginClientHelper} provides utility methods for creating URIs
* and parsing API responses into their corresponding Java objects.
* Implements the {@link ILoginClientHelper} interface.
* Implements the {@link ISapLoginClientHelper} interface.
*/
public class LoginClientHelper implements ILoginClientHelper {
public class SapLoginClientHelper implements ISapLoginClientHelper {

/** The {@link Gson} instance for parsing JSON responses. */
private Gson gson;
Expand All @@ -21,7 +21,7 @@ public class LoginClientHelper implements ILoginClientHelper {
* <p>
* Initializes a {@link Gson} instance for JSON parsing.
*/
public LoginClientHelper() {
public SapLoginClientHelper() {
gson = new Gson();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.eclipse.swt.events.SelectionEvent;

import com.developer.nefarious.zjoule.plugin.login.api.GetDeploymentsResponse;
import com.developer.nefarious.zjoule.plugin.login.api.ILoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.ISapLoginClient;
import com.developer.nefarious.zjoule.plugin.login.pages.SecondLoginWizardPage;
import com.developer.nefarious.zjoule.plugin.memory.IMemoryObject;
import com.developer.nefarious.zjoule.plugin.models.ServiceKey;
Expand All @@ -24,7 +24,7 @@ public class ResourceGroupSelectionAdapter extends SelectionAdapter {
private SecondLoginWizardPage secondLoginWizardPage;

/** The login client for retrieving deployments. */
private ILoginClient loginClient;
private ISapLoginClient sapLoginClient;

/** The memory manager for storing the selected resource group. */
private IMemoryObject<String> memoryResourceGroup;
Expand All @@ -33,17 +33,17 @@ public class ResourceGroupSelectionAdapter extends SelectionAdapter {
* Constructs a new {@code ResourceGroupSelectionAdapter}.
*
* @param secondLoginWizardPage the {@link SecondLoginWizardPage} containing the resource group dropdown.
* @param loginClient the {@link ILoginClient} for retrieving deployments.
* @param sapLoginClient the {@link ISapLoginClient} for retrieving deployments.
* @param memoryResourceGroup the {@link IMemoryObject<String>} used to store the selected resource group.
*/
// @formatter:off
public ResourceGroupSelectionAdapter(
final SecondLoginWizardPage secondLoginWizardPage,
final ILoginClient loginClient,
final ISapLoginClient sapLoginClient,
final IMemoryObject<String> memoryResourceGroup) {
// @formatter:on
this.secondLoginWizardPage = secondLoginWizardPage;
this.loginClient = loginClient;
this.sapLoginClient = sapLoginClient;
this.memoryResourceGroup = memoryResourceGroup;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ private void enableTheDeploymentSelection() {
private void handleAvailableDeployments() throws IOException, InterruptedException {
String selectedResourceGroup = secondLoginWizardPage.getResourceGroupDropdown().getText();
ServiceKey serviceKey = secondLoginWizardPage.getServiceKey();
GetDeploymentsResponse getDeploymentsResponse = loginClient.getDeployments(serviceKey, selectedResourceGroup);
GetDeploymentsResponse getDeploymentsResponse = sapLoginClient.getDeployments(serviceKey, selectedResourceGroup);
secondLoginWizardPage.setDeploymentsForSelection(getDeploymentsResponse.getDeployments());
memoryResourceGroup.save(selectedResourceGroup);
enableTheDeploymentSelection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.eclipse.swt.events.ModifyListener;

import com.developer.nefarious.zjoule.plugin.login.api.GetResourceGroupsResponse;
import com.developer.nefarious.zjoule.plugin.login.api.ILoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.ISapLoginClient;
import com.developer.nefarious.zjoule.plugin.login.pages.FirstLoginWizardPage;
import com.developer.nefarious.zjoule.plugin.login.utils.JsonValidator;
import com.developer.nefarious.zjoule.plugin.models.ServiceKey;
Expand All @@ -24,7 +24,7 @@ public class ServiceKeyModifyListener implements ModifyListener {
private FirstLoginWizardPage firstLoginWizardPage;

/** The login client used for validating the service key and retrieving resource groups. */
private ILoginClient loginClient;
private ISapLoginClient sapLoginClient;

/** A {@link Gson} instance for parsing the service key from JSON. */
private Gson gson;
Expand All @@ -33,17 +33,17 @@ public class ServiceKeyModifyListener implements ModifyListener {
* Constructs a new {@code ServiceKeyModifyListener}.
*
* @param firstLoginWizardPage the {@link FirstLoginWizardPage} containing the service key input field.
* @param loginClient the {@link ILoginClient} for validating the service key and retrieving resource groups.
* @param sapLoginClient the {@link ISapLoginClient} for validating the service key and retrieving resource groups.
* @param gson the {@link Gson} instance for parsing the service key JSON.
*/
// @formatter:off
public ServiceKeyModifyListener(
final FirstLoginWizardPage firstLoginWizardPage,
final ILoginClient loginClient,
final ISapLoginClient sapLoginClient,
final Gson gson) {
// @formatter:on
this.firstLoginWizardPage = firstLoginWizardPage;
this.loginClient = loginClient;
this.sapLoginClient = sapLoginClient;
this.gson = gson;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ private void enableNextButton() {
* @throws InterruptedException if the resource group retrieval is interrupted.
*/
private void handleValidServiceKey(final ServiceKey serviceKey) throws IOException, InterruptedException {
GetResourceGroupsResponse getResourceGroupsResponse = loginClient.getResourceGroups(serviceKey);
GetResourceGroupsResponse getResourceGroupsResponse = sapLoginClient.getResourceGroups(serviceKey);
firstLoginWizardPage.setResourceGroupsOnTheSecondPage(getResourceGroupsResponse);
firstLoginWizardPage.setServiceKey(serviceKey);
clearMessageLog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.eclipse.swt.widgets.Text;

import com.developer.nefarious.zjoule.plugin.login.api.GetResourceGroupsResponse;
import com.developer.nefarious.zjoule.plugin.login.api.ILoginClient;
import com.developer.nefarious.zjoule.plugin.login.api.ISapLoginClient;
import com.developer.nefarious.zjoule.plugin.login.events.ServiceKeyModifyListener;
import com.developer.nefarious.zjoule.plugin.login.utils.ResourceGroupIdExtractor;
import com.developer.nefarious.zjoule.plugin.models.ServiceKey;
Expand Down Expand Up @@ -47,19 +47,19 @@ public class FirstLoginWizardPage extends WizardPage {
private ServiceKey serviceKey;

/** The login client for handling API interactions. */
private ILoginClient loginClient;
private ISapLoginClient sapLoginClient;

/**
* Constructs a new {@code FirstLoginWizardPage}.
*
* @param loginClient the {@link ILoginClient} used for API interactions during the login process.
* @param sapLoginClient the {@link ISapLoginClient} used for API interactions during the login process.
*/
public FirstLoginWizardPage(final ILoginClient loginClient) {
public FirstLoginWizardPage(final ISapLoginClient sapLoginClient) {
super(PAGE_ID);
setTitle("Provide credentials");
setDescription("Attach the Service Key json file content for the SAP AI Core service.");
setPageComplete(false); // Initially set the page as incomplete
this.loginClient = loginClient;
this.sapLoginClient = sapLoginClient;
}

/**
Expand All @@ -80,7 +80,7 @@ public void createControl(final Composite parent) {
textField.setLayoutData(gridData);

// Add a ModifyListener to monitor textField changes
textField.addModifyListener(new ServiceKeyModifyListener(this, loginClient, new Gson()));
textField.addModifyListener(new ServiceKeyModifyListener(this, sapLoginClient, new Gson()));

// Hidden error text widget
errorText = new Text(container, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
Expand Down
Loading

0 comments on commit a88ff11

Please sign in to comment.