Add REST endpoint to resume a project import on project resources
A project import can now be resumed by
PUT /projects/<project-name>/importer~import.resume
This REST endpoint does the same as
PUT /config/server/importer~projects/<project-name>/resume
The advantage of having the import functionality exposed on project
resources is that then it can be offered in the UI as action button on
the project info screen.
Change-Id: I7d67b6f1ab967091a554fda9d5db76d512e5f542
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java b/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java
index b8ac337..c45d18a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java
@@ -45,6 +45,7 @@
put(PROJECT_KIND, "copy").to(CopyProject.class);
put(PROJECT_KIND, "copy.resume").to(ResumeCopyProject.class);
+ put(PROJECT_KIND, "import.resume").to(ResumeProjectImport.OnProjects.class);
}
});
bind(LifecycleListener.class)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
index 40abb1e..04d5df5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
@@ -18,10 +18,13 @@
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.BadRequestException;
+import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
+import com.google.gerrit.server.config.ConfigResource;
import com.google.gerrit.server.project.NoSuchChangeException;
+import com.google.gerrit.server.project.ProjectResource;
import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@@ -61,4 +64,28 @@
return importProjectFactory.create(rsrc.getName())
.resume(input.user, input.pass, rsrc.getImportStatus());
}
+
+ public static class OnProjects implements RestModifyView<ProjectResource, Input> {
+ private final ProjectsCollection projectsCollection;
+ private final ResumeProjectImport resumeProjectImport;
+
+ @Inject
+ public OnProjects(
+ ProjectsCollection projectsCollection,
+ ResumeProjectImport resumeProjectImport) {
+ this.projectsCollection = projectsCollection;
+ this.resumeProjectImport = resumeProjectImport;
+ }
+
+ @Override
+ public Response<String> apply(ProjectResource rsrc, Input input)
+ throws RestApiException, IOException, OrmException,
+ ValidationException, GitAPIException, NoSuchChangeException,
+ NoSuchAccountException {
+ ImportProjectResource projectResource =
+ projectsCollection.parse(new ConfigResource(),
+ IdString.fromDecoded(rsrc.getName()));
+ return resumeProjectImport.apply(projectResource, input);
+ }
+ }
}
diff --git a/src/main/resources/Documentation/rest-api-projects.md b/src/main/resources/Documentation/rest-api-projects.md
index a93ce6c..ebc443f 100644
--- a/src/main/resources/Documentation/rest-api-projects.md
+++ b/src/main/resources/Documentation/rest-api-projects.md
@@ -48,6 +48,31 @@
PUT /projects/myProjectCopy/@PLUGIN@~copy.resume HTTP/1.0
```
+### <a id="resume-project-import"> Resume Project Import
+_PUT /projects/[\{project-name\}](../../../Documentation/rest-api-projects.html#project-name)/@PLUGIN@~import.resume_
+
+Resumes importing to a project from the original copy source.
+
+Information about the import resume must be provided in the request
+body as a [ImportResumeInput](rest-api-config.html#import-resume-input)
+entity.
+
+Caller must be a member of a group that is granted the 'ImportProject'
+capability (provided by this plugin) or the 'Administrate Server'
+capability.
+
+#### Request
+
+```
+ PUT /projects/myProjectCopy/@PLUGIN@~import.resume HTTP/1.0
+ Content-Type: application/json;charset=UTF-8
+
+ {
+ "user": "myUser",
+ "pass": "myPassword"
+ }
+```
+
<a id="json-entities">JSON Entities
-----------------------------------