Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

public interface IRepositoryService {

// CHNG: Remove new pull relation
String RELATION_PULL_WITHOUT_BG = "http://www.sap.com/adt/abapgit/relations/pullwithoutbg"; //$NON-NLS-1$
String RELATION_PULL = "http://www.sap.com/adt/abapgit/relations/pull"; //$NON-NLS-1$
String RELATION_PULL_WITHOUT_BG = "http://www.sap.com/adt/abapgit/relations/pull/v2"; //$NON-NLS-1$
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name, could be RELATION_PULL_WITH_BG_RUN

String RELATION_STATUS = "http://www.sap.com/adt/abapgit/relations/status"; //$NON-NLS-1$
String RELATION_LOG = "http://www.sap.com/adt/abapgit/relations/log"; //$NON-NLS-1$
String RELATION_STAGE = "http://www.sap.com/adt/abapgit/relations/stage"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public IAbapObjects cloneRepository(String url, String branch, String targetPack
IContentHandler<IAbapObjects> responseContentHandlerV1 = new AbapObjectContentHandlerV1();
restResource.addContentHandler(responseContentHandlerV1);

IAdtCompatibleRestResourceFilter compatibilityFilter = AdtCompatibleRestResourceFilterFactory.createFilter(responseContentHandlerV1);
IAdtCompatibleRestResourceFilter compatibilityFilter = AdtCompatibleRestResourceFilterFactory
.createFilter(responseContentHandlerV1);
restResource.addRequestFilter(compatibilityFilter);

return restResource.post(monitor, IAbapObjects.class, repository);
Expand Down Expand Up @@ -205,8 +206,7 @@ public void repositoryChecks(IProgressMonitor monitor, IExternalRepositoryInfoRe
restResource.addRequestFilter(compatibilityFilter);
restResource.addResponseFilter(compatibilityFilter);
if (credentials != null) {
headers = getHttpHeadersForCredentials(credentials.getUser(),
credentials.getPassword());
headers = getHttpHeadersForCredentials(credentials.getUser(), credentials.getPassword());
}
restResource.post(monitor, headers, null);
}
Expand Down Expand Up @@ -268,8 +268,8 @@ public URI getURIFromAtomLink(IRepository repository, String relation) {
}

@Override
public IAbapGitPullModifiedObjects getModifiedObjects(IProgressMonitor monitor, IRepository currRepository,
String user, String password) throws OutDatedClientException {
public IAbapGitPullModifiedObjects getModifiedObjects(IProgressMonitor monitor, IRepository currRepository, String user,
String password) throws OutDatedClientException {
URI uriToModifiedObjects = getURIFromAtomLink(currRepository, IRepositoryService.RELATION_MODIFIED_OBJECTS);

IHeaders headers = null;
Expand All @@ -278,8 +278,7 @@ public IAbapGitPullModifiedObjects getModifiedObjects(IProgressMonitor monitor,
}

IRestResource restResource = AdtRestResourceFactory.createRestResourceFactory()
.createResourceWithStatelessSession(uriToModifiedObjects,
this.destinationId);
.createResourceWithStatelessSession(uriToModifiedObjects, this.destinationId);

IContentHandler<IAbapGitPullModifiedObjects> responseContentHandlerV1 = new AbapGitPullModifiedObjectsContentHandlerV1();
restResource.addContentHandler(responseContentHandlerV1);
Expand All @@ -297,13 +296,27 @@ public IAbapGitPullModifiedObjects getModifiedObjects(IProgressMonitor monitor,
@Override
public IAbapObjects pullRepository(IRepository existingRepository, String branch, String transportRequest, String user, String password,
IAbapGitPullModifiedObjects selectedObjectsToPull, IProgressMonitor monitor) {
URI uriToRepo = getURIFromAtomLink(existingRepository, IRepositoryService.RELATION_PULL_WITHOUT_BG);
URI backgroundUri = AdtBackgroundRunUriDiscoveryFactory.createBackgroundRunUriDiscovery(this.destinationId)
.getBackgroundRunUriIfAuthorized(monitor);
IRestResource restResource = AdtBackgroundRestResourceFactory.createBackgroundRestResourceFactory()
.createResourceWithStatelessSession(backgroundUri, uriToRepo, this.destinationId);
// IRestResource restResource = AdtRestResourceFactory.createRestResourceFactory().createResourceWithStatelessSession(uriToRepo,
// this.destinationId);
IRestResource restResource = null;
URI uriToRepo = null;
// check if background job framework is available and is accessible by the user.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments. The method names should be sufficient.

if (isBackgroundJobSupported(monitor)) {
// get new pull without background resource URI
uriToRepo = getURIFromAtomLink(existingRepository, IRepositoryService.RELATION_PULL_WITHOUT_BG);
// check whether URI is available in the system (this depends on the back end version)
if (uriToRepo != null) {
restResource = getBackgroundRestResource(uriToRepo.getPath(), this.destinationId, monitor);
}
}
// if rest resource is still null, rollback to normal pull URI
if (restResource == null) {
uriToRepo = getURIFromAtomLink(existingRepository, IRepositoryService.RELATION_PULL);
restResource = AdtRestResourceFactory.createRestResourceFactory().createResourceWithStatelessSession(uriToRepo,
this.destinationId);
}
if (restResource == null) {
// if rest resource could not be created, throw exception
throw new IllegalStateException("Unable to create REST resource for pull operation."); //$NON-NLS-1$
}
IContentHandler<IAbapGitPullRequest> requestContentHandlerV1 = new AbapGitPullRequestContentHandler();
restResource.addContentHandler(requestContentHandlerV1);

Expand All @@ -321,9 +334,9 @@ public IAbapObjects pullRepository(IRepository existingRepository, String branch
}

if (selectedObjectsToPull != null) {
abapGitPullReq.setPackageWarningObjects(selectedObjectsToPull.getPackageWarningObjects());
abapGitPullReq.setOverwriteObjects(selectedObjectsToPull.getOverwriteObjects());
}
abapGitPullReq.setPackageWarningObjects(selectedObjectsToPull.getPackageWarningObjects());
abapGitPullReq.setOverwriteObjects(selectedObjectsToPull.getOverwriteObjects());
}

IAdtCompatibleRestResourceFilter compatibilityFilter = AdtCompatibleRestResourceFilterFactory.createFilter(new IContentHandler[0]);
restResource.addRequestFilter(compatibilityFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,8 @@ public void run() {
WizardDialog wizardDialog = new WizardDialog(AbapGitView.this.viewer.getControl().getShell(),
new AbapGitWizardPull(AbapGitView.this.lastProject, this.selRepo, allRepositories));
wizardDialog.open();
}

updateView(true);
}
}
};
this.actionPullWizard.setText(Messages.AbapGitView_context_pull);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.abapgit.adt.ui.internal.repositories;

import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;

public class AbapGitViewUtils {
private static AbapGitViewUtils instance;

private AbapGitViewUtils() {}

public static synchronized AbapGitViewUtils getInstance() {
if (instance == null) {
instance = new AbapGitViewUtils();
}
return instance;
}

public void refreshView() {
org.eclipse.swt.widgets.Display.getDefault().asyncExec(() -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import Display API and then use.

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
? PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
: null;
if (page != null) {
IViewPart view = page.findView(AbapGitView.ID);
if (view instanceof AbapGitView) {
((AbapGitView) view).refresh();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic needs to find the view from all the active views.
I want to avoid this call.
Hence, looking at some other way to keep stuff decoupled.

So,

  1. Refresh of a view should be decoupled from the pull wizard.
  2. Refresh should be part of the action which starts the pull.
  3. Avoid a central disconnected utility just to refresh UI.

Hence I was looking into a callback mechanism.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our actionPullWizard implementation, we could first implement a callback as lamba expression.


		this.actionPullWizard = new Action() {

			private IRepository selRepo;

			public void run() {
				// Create callback that refreshes the view
				Runnable onPullComplete = () -> AbapGitView.this.updateView(true);

and we can send it within the constructor of AbapGitWizardPull and add it as an instance variable.

Then in our finally block of the job, we can run this call back.

} finally {
					// Execute callback after job completes
					if (AbapGitWizardPull.this.onPullComplete!= null) {
						Display.getDefault().asyncExec(AbapGitWizardPull.this.onPullComplete);
					}
				}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also this could be over-engineering and we can as well just pass the AbapGit view instance to the wizard and refresh the view.
Given we have the wizards initiated directly from the view, this should be fine as well.

}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.abapgit.adt.ui.AbapGitUIPlugin;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.repositories.AbapGitView;
import org.abapgit.adt.ui.internal.repositories.AbapGitViewUtils;
import org.abapgit.adt.ui.internal.repositories.exceptions.PackageRefNotFoundException;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizardSwitchBranch;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void run() {
e.getLocalizedMessage());
}
}
this.AbapGitView.refresh();
AbapGitViewUtils.getInstance().refreshView();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.abapgit.adt.backend.model.agitpullmodifiedobjects.IAbapGitPullModifiedObjects;
import org.abapgit.adt.ui.AbapGitUIPlugin;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.repositories.AbapGitViewUtils;
import org.abapgit.adt.ui.internal.repositories.IRepositoryModifiedObjects;
import org.abapgit.adt.ui.internal.util.AbapGitUIServiceFactory;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizard.CloneData;
Expand Down Expand Up @@ -185,6 +186,8 @@ protected IStatus run(IProgressMonitor monitor) {
return Status.OK_STATUS;
} catch (ResourceException e) {
return new Status(IStatus.ERROR, AbapGitUIPlugin.PLUGIN_ID, e.getMessage(), e);
} finally {
AbapGitViewUtils.getInstance().refreshView();
}
}

Expand Down