@IsAllowed(Operation.UPDATE)
public static Result settingProject(String ownerId, String projectName)
throws IOException, NoSuchAlgorithmException, UnsupportedOperationException, ServletException {
Form<Project> filledUpdatedProjectForm = form(Project.class).bindFromRequest();
Project project = Project.findByOwnerAndProjectName(ownerId, projectName);
PlayRepository repository = RepositoryService.getRepository(project);
if (validateWhenUpdate(ownerId, filledUpdatedProjectForm)) {
return badRequest(setting.render("title.projectSetting",
filledUpdatedProjectForm, project, repository.getBranches()));
}
Project updatedProject = filledUpdatedProjectForm.get();
FilePart filePart = request().body().asMultipartFormData().getFile("logoPath");
if (!isEmptyFilePart(filePart)) {
Attachment.deleteAll(updatedProject.asResource());
new Attachment().store(filePart.getFile(), filePart.getFilename(), updatedProject.asResource());
}
Map<String, String[]> data = request().body().asMultipartFormData().asFormUrlEncoded();
String defaultBranch = HttpUtil.getFirstValueFromQuery(data, "defaultBranch");
if (StringUtils.isNotEmpty(defaultBranch)) {
repository.setDefaultBranch(defaultBranch);
}
if (!project.name.equals(updatedProject.name)) {
if (!repository.renameTo(updatedProject.name)) {
throw new FileOperationException("fail repository rename to " + project.owner + "/" + updatedProject.name);
}
}
updatedProject.update();