Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull feature with ATOM links check #3

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,5 +1,7 @@
package org.abapgit.adt.backend;

import java.net.URI;

public interface IRepository {
public String getKey();

Expand Down Expand Up @@ -36,4 +38,7 @@ public interface IRepository {
public void setPassword(String password);

public void setTransportRequest(String transportRequest);

public URI getLink(String relation);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import org.eclipse.core.runtime.IProgressMonitor;

public interface IRepositoryService {

String RELATION_PULL = "http://www.sap.com/adt/abapgit/relations/pull"; //$NON-NLS-1$

IRepositories getRepositories(IProgressMonitor monitor);

void cloneRepository(String url, String branch, String targetPackage, String transportRequest, String user,
String password, IProgressMonitor monitor);

void unlinkRepository(String key, IProgressMonitor monitor);

void pullRepository(IRepository existingRepository, String branch, String transportRequest, String user, String password,
IProgressMonitor monitor);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.abapgit.adt.backend.internal;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import org.abapgit.adt.backend.IRepository;

public class Repository implements IRepository {
Expand All @@ -13,6 +17,7 @@ public class Repository implements IRepository {
private String createdBy;
private String remotePassword;
private String transportRequest;
private final Map<String, URI> links = new HashMap<>();

@Override
public String getUrl() {
Expand Down Expand Up @@ -128,4 +133,14 @@ public String getCreatedBy() {
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}

@Override
public URI getLink(String relation) {
return this.links.get(relation);
}

public void addLink(String relation, URI uri) {
this.links.put(relation, uri);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.abapgit.adt.backend.internal;

import java.net.URI;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
Expand All @@ -11,7 +13,7 @@
public class RepositorySerializer {

public IRepository deserializeRepository(XMLStreamReader xmlReader, String contentType) throws XMLStreamException {
IRepository repository = new Repository();
Repository repository = new Repository();

int depth = 0;
loop: while (xmlReader.hasNext()) {
Expand All @@ -37,6 +39,9 @@ public IRepository deserializeRepository(XMLStreamReader xmlReader, String conte
case "package": //$NON-NLS-1$
repository.setPackage(xmlReader.getElementText());
break;
case "link": //$NON-NLS-1$
repository.addLink(xmlReader.getAttributeValue(null, "rel"), URI.create(xmlReader.getAttributeValue(null, "href")));
break;
default:
depth++;
break;
Expand All @@ -63,11 +68,11 @@ public void serializeRepository(IRepository repository, XMLStreamWriter xmlStrea
writeElementIfNonEmpty(xmlStreamWriter, "created_at", repository.getFirstCommit()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "key", repository.getKey()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "package", repository.getPackage()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "password", repository.getRemotePassword()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "transportRequest", repository.getTransportRequest()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "url", repository.getUrl()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "created_by", repository.getCreatedBy()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "user", repository.getRemoteUser()); //$NON-NLS-1$
writeElementIfNonEmpty(xmlStreamWriter, "password", repository.getRemotePassword()); //$NON-NLS-1$
xmlStreamWriter.writeEndElement();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,40 @@ public void cloneRepository(String url, String branch, String targetPackage, Str
restResource.post(monitor, null, repository);
}

@Override
public void pullRepository(IRepository existingRepository, String branch, String transportRequest, String user, String password,
IProgressMonitor monitor) {

URI uriToRepo = existingRepository.getLink(IRepositoryService.RELATION_PULL); //$NON-NLS-1$
IRestResource restResource = AdtRestResourceFactory.createRestResourceFactory().createResourceWithStatelessSession(uriToRepo,
this.destinationId);

IContentHandler<IRepository> requestContentHandlerV1 = new RepositoryContentHandlerV1();
restResource.addContentHandler(requestContentHandlerV1);

IRepository repository = new Repository();
repository.setBranch(branch);
repository.setTransportRequest(transportRequest);

if (user != null && !user.isEmpty()) {
repository.setRemoteUser(user);
}

if (password != null && !password.isEmpty()) {
repository.setPassword(password);
}
// repository.setKey(key);

IAdtCompatibleRestResourceFilter compatibilityFilter = AdtCompatibleRestResourceFilterFactory.createFilter(new IContentHandler[0]);
restResource.addRequestFilter(compatibilityFilter);
restResource.addResponseFilter(compatibilityFilter);

restResource.post(monitor, null, repository);
}

@Override
public void unlinkRepository(String key, IProgressMonitor monitor) {
URI uriToRepo = new UriBuilder(uri).addPathSegments(key).getUri();
URI uriToRepo = new UriBuilder(this.uri).addPathSegments(key).getUri();
IRestResource restResource = AdtRestResourceFactory.createRestResourceFactory()
.createResourceWithStatelessSession(uriToRepo, this.destinationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class Messages extends NLS {
public static String AbapGitView_context_dialog_unlink_title;
public static String AbapGitView_context_unlink;
public static String AbapGitView_context_unlink_error;
public static String AbapGitView_context_pull;
public static String AbapGitView_context_pull_error;
public static String AbapGitView_context_dialog_pull_message;
public static String AbapGitView_context_dialog_pull_title;
public static String AbapGitView_no_abap_project;
public static String AbapGitView_not_supported;
public static String AbapGitView_repos_in_project;
Expand All @@ -25,6 +29,7 @@ public class Messages extends NLS {
public static String AbapGitView_task_fetch_repos_error;
public static String AbapGitWizard_task_cloning_repository;
public static String AbapGitWizard_title;
public static String AbapGitWizardPull_title;
public static String AbapGitWizardPageBranchAndPackage_btn_browse;
public static String AbapGitWizardPageBranchAndPackage_combobox_branch_message;
public static String AbapGitWizardPageBranchAndPackage_description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ AbapGitView_column_firstcommitat=First Commit At
AbapGitView_column_package=Package
AbapGitView_column_url=URL
AbapGitView_column_user=User
AbapGitView_context_pull=Pull
AbapGitView_context_dialog_pull_message=Do you really want to pull from {0} Repository to Package {1}?
AbapGitView_context_dialog_pull_title=Pull from repository
AbapGitView_context_pull_error=Error pulling from Repository
AbapGitView_context_dialog_unlink_message=Do you really want to unlink the abapGit Repository {0} from Package {1}?
AbapGitView_context_dialog_unlink_title=Unlink abapGit Repository
AbapGitView_context_unlink=Unlink
Expand All @@ -19,6 +23,7 @@ AbapGitView_task_fetch_repos=Fetching abapGit Repositories
AbapGitView_task_fetch_repos_error=Error fetching abapGit Repositories
AbapGitWizard_task_cloning_repository=Cloning repository...
AbapGitWizard_title=Clone abapGit Repository
AbapGitWizardPull_title=Pull from abapGit Repository
AbapGitWizardPageBranchAndPackage_btn_browse=Browse...
AbapGitWizardPageBranchAndPackage_combobox_branch_message=Specify a branch
AbapGitWizardPageBranchAndPackage_description=Select repository branch and target ABAP package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.abapgit.adt.ui.AbapGitUIPlugin;
import org.abapgit.adt.ui.internal.i18n.Messages;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizard;
import org.abapgit.adt.ui.internal.wizards.AbapGitWizardPull;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -98,6 +99,8 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
}
};

private Action actionPullWizard;

@Override
public void init(IViewSite site) throws PartInitException {
super.init(site);
Expand Down Expand Up @@ -236,11 +239,14 @@ public void menuAboutToShow(IMenuManager manager) {
if (AbapGitView.this.viewer.getStructuredSelection().size() == 1) {
Object firstElement = AbapGitView.this.viewer.getStructuredSelection().getFirstElement();
if (firstElement instanceof IRepository) {
manager.add(new UnlinkAction(AbapGitView.this.lastProject, (IRepository) firstElement));

manager.add(new Separator());

if (((IRepository) firstElement).getLink(IRepositoryService.RELATION_PULL) != null) {
manager.add(AbapGitView.this.actionPullWizard);
manager.add(new Separator());
}
manager.add(AbapGitView.this.actionCopy);
manager.add(new UnlinkAction(AbapGitView.this.lastProject, (IRepository) firstElement));

}
}
}
Expand Down Expand Up @@ -268,15 +274,15 @@ public void run() {

this.actionCopy = new Action() {
public void run() {
Table table = AbapGitView.this.viewer.getTable();
copy(table);
copy();
}
};
this.actionCopy.setText(Messages.AbapGitView_action_copy);
this.actionCopy.setToolTipText(Messages.AbapGitView_action_copy);

this.actionCopy.setAccelerator(SWT.ALT | 'C');

this.actionCopy.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
// this.actionCopy
// .setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(AbapGitUIPlugin.PLUGIN_ID, "icons/etool/refresh.png")); //$NON-NLS-1$

Expand All @@ -295,6 +301,33 @@ public void run() {
this.actionWizard.setText(Messages.AbapGitView_action_clone);
this.actionWizard.setToolTipText(Messages.AbapGitView_action_clone);
this.actionWizard.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));

this.actionPullWizard = new Action() {

private IRepository selRepo;

public void run() {
if (!AdtLogonServiceUIFactory.createLogonServiceUI().ensureLoggedOn(AbapGitView.this.lastProject).isOK()) {
return;
}

Object firstElement = AbapGitView.this.viewer.getStructuredSelection().getFirstElement();
this.selRepo = null;

if (firstElement instanceof IRepository) {
this.selRepo = ((IRepository) firstElement);
}

WizardDialog wizardDialog = new WizardDialog(AbapGitView.this.viewer.getControl().getShell(),
new AbapGitWizardPull(AbapGitView.this.lastProject, this.selRepo));

wizardDialog.open();
updateView(true);
}
};
this.actionPullWizard.setText(Messages.AbapGitView_context_pull);
// this.actionPullWizard
// .setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED));
}

private List<IRepository> getRepositories(String destinationId) {
Expand Down Expand Up @@ -374,26 +407,27 @@ private void setControlsEnabled(boolean enabled) {
* @param table
* the data source
*/
protected void copy(Table table) {
if (canCopy(table)) {
final StringBuilder data = new StringBuilder();
protected void copy() {

for (int row = 0; row < table.getSelectionCount(); row++) {
// data.append(table.getSelection()[row]);
IRepository currRepository;
Object firstElement = AbapGitView.this.viewer.getStructuredSelection().getFirstElement();
currRepository = null;

for (int j = 0; j <= table.getColumnCount() - 1; j++) {
data.append(table.getItem(row).getText(j) + " "); //$NON-NLS-1$
}
if (firstElement instanceof IRepository) {
currRepository = ((IRepository) firstElement);
}

final StringBuilder data = new StringBuilder();

if (currRepository != null) {
data.append(currRepository.getPackage() + " " + currRepository.getUrl() + " " + currRepository.getBranch() + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ currRepository.getCreatedBy());
}
final Clipboard clipboard = new Clipboard(table.getDisplay());

final Clipboard clipboard = new Clipboard(AbapGitView.this.viewer.getControl().getDisplay());
clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
clipboard.dispose();
}
}

protected boolean canCopy(final Table table) {
return table.getColumnCount() > 0 && table.getSelectionCount() > 0;
}

/**
Expand Down Expand Up @@ -424,6 +458,7 @@ public UnlinkAction(IProject project, IRepository repository) {
this.project = project;
this.repository = repository;
setText(Messages.AbapGitView_context_unlink);
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_DELETE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AbapGitWizardPageRepositoryAndCredentials extends WizardPage {

private final IProject project;
private final String destination;
private Boolean pullAction;
private final CloneData cloneData;

private Text txtURL;
Expand All @@ -44,8 +45,13 @@ public AbapGitWizardPageRepositoryAndCredentials(IProject project, String destin
this.project = project;
this.destination = destination;
this.cloneData = cloneData;
this.pullAction = false;
setTitle(Messages.AbapGitWizardPageRepositoryAndCredentials_title);
setDescription(Messages.AbapGitWizardPageRepositoryAndCredentials_description);

if (this.cloneData.url != null) {
setTitle(Messages.AbapGitWizardPull_title);
}
}

@Override
Expand Down Expand Up @@ -100,11 +106,31 @@ public void createControl(Composite parent) {

setControl(container);
setPageComplete(false);

if (this.cloneData.url != null) {
this.pullAction = true;
this.txtURL.setText(this.cloneData.url);
this.txtURL.setEnabled(false);
this.cloneData.externalRepoInfo = null;
validateAll();
}

}


@Override
public void setVisible(boolean visible) {

//Navigate to transport request page if repo is public
if (this.cloneData.externalRepoInfo != null && this.cloneData.externalRepoInfo.getAccessMode() == AccessMode.PUBLIC
&& this.pullAction == true) {
getContainer().showPage(getNextPage());
getContainer().getCurrentPage().setVisible(visible);
return;
}

if (visible && !this.wasVisibleBefore) {

this.wasVisibleBefore = true;
boolean isSupported[] = new boolean[1];
try {
Expand All @@ -128,9 +154,11 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
setMessage(e.getMessage(), DialogPage.ERROR);
return;
}

}

super.setVisible(visible);

}

private boolean validateClientOnly() {
Expand Down Expand Up @@ -171,7 +199,7 @@ public boolean validateAll() {
}
}
if (this.cloneData.repositories.getRepositories().stream()
.anyMatch(r -> r.getUrl().toString().equals(this.txtURL.getText()))) {
.anyMatch(r -> r.getUrl().toString().equals(this.txtURL.getText())) && this.pullAction == false) {
setPageComplete(false);
setMessage(Messages.AbapGitWizardPageRepositoryAndCredentials_repo_in_use_error, DialogPage.ERROR);
return false;
Expand Down
Loading