package com.perforce.spark; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.fileupload.FileUploadException; import spark.Request; import spark.Response; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.server.IOptionsServer; import com.perforce.spark.navigation.NavBar; import com.perforce.spark.p4depot.DepotFactory; public class AssetHelper { public static List<String> repos; static { repos = new ArrayList<String>(); repos.add("RELEASE"); repos.add("SNAPSHOT"); repos.add("EXPERIMENTAL"); } public static Map<String, Object> depot(Request request, Response response) { Map<String, Object> attributes; attributes = NavBar.attributes("config", request); attributes.put("summary", ""); // test with a p4 session try { ConnectionSession.get(request, response); } catch (P4JavaException e) { response.redirect("/"); return error(attributes, e.getMessage()); } return attributes; } public static Map<String, Object> deploy(Request request, Response response) { IOptionsServer p4; Map<String, Object> attributes; attributes = NavBar.attributes("deploy", request); attributes.put("summary", ""); attributes.put("depots", ""); attributes.put("optsRepositoryID", ""); // test with a p4 session try { p4 = ConnectionSession.get(request, response); attributes.put("depots", DepotFactory.list(p4, AssetType.MAVEN)); attributes.put("optsRepositoryID", selectRepos()); } catch (P4JavaException e) { response.redirect("/"); return error(attributes, e.getMessage()); } return attributes; } public static String selectRepos() { StringBuilder form = new StringBuilder(); for (String repo : repos) { form.append("<option>"); form.append(repo); form.append("</option>"); } return form.toString(); } public static Map<String, Object> upload(Request request, Response response) { IOptionsServer p4; MavenAsset mavenAsset; Map<String, Object> attributes; attributes = NavBar.attributes("deploy", request); attributes.put("summary", ""); // get p4 session try { p4 = ConnectionSession.get(request, response); } catch (P4JavaException e) { response.redirect("/"); return error(attributes, e.getMessage()); } // build asset try { mavenAsset = new MavenAsset(request); } catch (FileUploadException e) { return error(attributes, e.getMessage()); } // publish asset try { mavenAsset.submit(p4); } catch (Exception e) { return error(attributes, e.getMessage()); } Path path = mavenAsset.getPath(); String url = "/browse/" + path; response.redirect(url); return attributes; } private static Map<String, Object> error(Map<String, Object> attributes, String msg) { msg = (msg == null) ? "Unknown Connection Error" : msg; attributes.put("error_show", "inherit"); attributes.put("error_message", msg); return attributes; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#12 | 14726 | Paul Allen | Limit deploy control path, and remove AssetHelper | ||
#11 | 14725 | Paul Allen | Generic deploy/upload | ||
#10 | 14723 | Paul Allen | Tidy up deploy/upload | ||
#9 | 14228 | Paul Allen |
Moved View over to the new model. Retactor connection to package. |
||
#8 | 14181 | Paul Allen | Lots of updates and refactoring. | ||
#7 | 14013 | Paul Allen | Basic proxy | ||
#6 | 13969 | Paul Allen | Depot list/create for Assets | ||
#5 | 13863 | Paul Allen | Minor fix to session vs cookie for login check. | ||
#4 | 13862 | Paul Allen | Submit uploads to Perforce | ||
#3 | 13857 | Paul Allen | Post Multipart form: fields and files. | ||
#2 | 13836 | Paul Allen | Use Dropzone for drag and drop. | ||
#1 | 13798 | Paul Allen | Basic file upload and login/logout cookie tidyup |