use of com.cloudbees.jenkins.support.api.ObjectComponent in project support-core-plugin by jenkinsci.
the class SupportObjectAction method parseRequest.
/**
* Parse the stapler JSON output and retrieve configured components.
*
* @param req the request
* @return the {@link DescribableList} of components
*/
protected final List<ObjectComponent<T>> parseRequest(StaplerRequest req) throws ServletException, Descriptor.FormException {
// Inspired by https://github.com/jenkinsci/workflow-job-plugin/blob/workflow-job-2.35/src/main/java/org/jenkinsci/plugins/workflow/job/properties/PipelineTriggersJobProperty.java
DescribableList<ObjectComponent<T>, ObjectComponentDescriptor<T>> components = new DescribableList<>(Saveable.NOOP);
try {
JSONObject componentsSection = req.getSubmittedForm().getJSONObject("components");
components.rebuild(req, componentsSection, getApplicableComponentsDescriptors());
} catch (IOException e) {
throw new Descriptor.FormException(e, "components");
}
return components;
}
use of com.cloudbees.jenkins.support.api.ObjectComponent in project support-core-plugin by jenkinsci.
the class SupportObjectAction method doGenerateAndDownload.
@RequirePOST
// used by Stapler
@SuppressWarnings("unused")
public final void doGenerateAndDownload(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException, Descriptor.FormException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
LOGGER.fine("Preparing response...");
rsp.setContentType("application/zip");
JSONObject json = req.getSubmittedForm();
if (json == null || !json.has("components")) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
LOGGER.fine("Parsing request...");
List<ObjectComponent<T>> components = new ArrayList<>(parseRequest(req));
rsp.addHeader("Content-Disposition", "inline; filename=" + BundleFileName.generate(getBundleNameQualifier()) + ";");
try {
SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication());
try (ACLContext old = ACL.as(ACL.SYSTEM)) {
SupportPlugin.writeBundle(rsp.getOutputStream(), components, new ComponentVisitor() {
@Override
public <C extends Component> void visit(Container container, C component) {
((ObjectComponent<T>) component).addContents(container, object);
}
});
} catch (IOException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
} finally {
SupportPlugin.clearRequesterAuthentication();
}
} finally {
LOGGER.fine("Response completed");
}
}
Aggregations