Ticket #879: openmrs-879.patch
| File openmrs-879.patch, 7.7 kB (added by upul, 2 years ago) |
|---|
Some cosmetic changes |
-
src/org/openmrs/modulerepository/RepositoryService.java
old new 178 178 } 179 179 180 180 } 181 182 /** 183 * Delete a module 184 * 185 * @param id 186 * @param version 187 * @param user 188 * @throws Throwable 189 */ 190 public static void deleteModule(String id, String version, String user) 191 throws Throwable { 192 checkPermissions(id, user); 181 193 194 Connection conn = getDatabaseConnection(); 195 conn.setAutoCommit(false); 196 197 try { 198 199 // remove module_version table entries 200 PreparedStatement update = conn 201 .prepareStatement("delete from module_version where id = ? and version = ?"); 202 update.setString(1, id); 203 update.setString(2, version); 204 update.executeUpdate(); 205 update.close(); 206 207 // are there any versions for the module 208 PreparedStatement versions = conn.prepareStatement( 209 "select m.id, version from module m join module_version mv on m.id = mv.id where m.id = ?"); 210 versions.setString(1, id); 211 ResultSet resultSet = versions.executeQuery(); 212 213 // if there are no other versions then delete the module 214 if(!resultSet.next()) { 215 // remove all current editors 216 PreparedStatement deleteEditors = conn 217 .prepareStatement("delete from module_edit_permission where id = ?"); 218 deleteEditors.setString(1, id); 219 deleteEditors.executeUpdate(); 220 deleteEditors.close(); 221 222 // finally remove module entry 223 PreparedStatement updateModule = conn 224 .prepareStatement("delete from module where id = ?"); 225 updateModule.setString(1, id); 226 updateModule.executeUpdate(); 227 updateModule.close(); 228 229 // delete update.rdf 230 RepositoryUtil.deleteRdfFile(id); 231 232 } else { 233 // other versions of the module exist. so remake the update.rdf. 234 remakeUpdateFile(id); 235 } 236 resultSet.close(); 237 238 // delete module file .omod 239 RepositoryUtil.deleteModuleFile(id, version); 240 241 // remake the complete rss file 242 remakeRssFile(); 243 244 245 } catch (Throwable t) { 246 log.warn("error: ", t); 247 conn.rollback(); 248 throw t; 249 } finally { 250 conn.commit(); 251 conn.close(); 252 } 253 254 } 255 182 256 /** 183 257 * Checks to see if the user is the module owner or an editor 184 258 * -
src/org/openmrs/modulerepository/servlet/DeleteModuleServlet.java
old new 1 package org.openmrs.modulerepository.servlet; 2 3 import java.io.IOException; 4 5 import javax.servlet.ServletException; 6 import javax.servlet.http.HttpServlet; 7 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletResponse; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.openmrs.modulerepository.RepositoryService; 13 import org.openmrs.modulerepository.RepositoryUtil; 14 15 public class DeleteModuleServlet extends HttpServlet { 16 17 private Log log = LogFactory.getLog(this.getClass()); 18 19 private static final long serialVersionUID = -8456919175340498522L; 20 21 @Override 22 protected void doGet(HttpServletRequest request, 23 HttpServletResponse response) throws ServletException, IOException { 24 throw new ServletException("Invalid access"); 25 } 26 27 @Override 28 protected void doPost(HttpServletRequest request, 29 HttpServletResponse response) throws ServletException, IOException { 30 31 String id = request.getParameter("id"); 32 String version = request.getParameter("version"); 33 34 String user; 35 try { 36 user = RepositoryUtil.getUser(request); 37 } catch (Exception e) { 38 throw new ServletException("Unable get user", e); 39 } 40 41 String msg = "Module deleted"; 42 try { 43 RepositoryService.deleteModule(id, version, user); 44 } catch (Throwable e) { 45 log.error("Error deleting module", e); 46 msg = "Unable to delete module " + e.getMessage(); 47 } 48 49 response.sendRedirect("/modules/list.jsp?msg=" + msg); 50 51 } 52 53 } -
src/org/openmrs/modulerepository/RepositoryUtil.java
old new 150 150 } 151 151 } 152 152 153 public static void deleteModuleFile(String id, String version) throws IOException { 154 File modFolder = new File(RepositoryUtil.MODULE_REPOSITORY_FILE_LOCATION, id); 155 File modFile = new File(modFolder, RepositoryUtil.getModuleFilename(id, version)); 156 modFile.delete(); 157 } 158 159 public static void deleteRdfFile(String id) throws IOException { 160 File folder = new File(RepositoryUtil.MODULE_REPOSITORY_FILE_LOCATION, id); 161 File updateFile = new File(folder, RepositoryUtil.UPDATE_FILENAME); 162 updateFile.delete(); 163 } 164 153 165 /** 154 166 * Removes seemingly random whitespace introduced by good formatting an xml file 155 167 * -
web/view.jsp
old new 55 55 <div id="editModule" style="width: 100%; text-align: right"> 56 56 <a href="/modules/admin/edit.jsp?module=${module}">Edit Module</a> 57 57 </div> 58 58 <div id="deleteModule" style="width: 100%; text-align: right"> 59 <a href="/modules/admin/delete.jsp?module=${module}&version=${row.version}">Delete Module</a> 60 </div> 59 61 </div> 60 62 61 63 … … 80 82 <tr class="<c:choose><c:when test="${status.index % 2 == 0}">evenRow</c:when><c:otherwise>oddRow</c:otherwise></c:choose>"> 81 83 <td id="editLinks"> 82 84 <a href="/modules/download/${module}/${module}-${row.version}.omod">Download</a> | 83 <a href="/modules/admin/edit.jsp?module=${module}&version=${row.version}">Edit</a> 85 <a href="/modules/admin/edit.jsp?module=${module}&version=${row.version}">Edit</a> | 86 <a href="/modules/admin/delete.jsp?module=${module}&version=${row.version}">Delete</a> 84 87 </td> 85 88 <td class="version">${row.version}</td> 86 89 <td class="requireOpenMRSVersion">${row.require_openmrs_version}</td> -
web/admin/delete.jsp
old new 1 <%@ include file="/WEB-INF/template/include.jsp" %> 2 3 <%@ include file="/WEB-INF/template/header.jsp" %> 4 5 <c:set var="module" value="${fn:escapeXml(param.module)}" /> 6 <c:set var="version" value="${fn:escapeXml(param.version)}" /> 7 8 <sql:query var="rs" dataSource="jdbc/modules" maxRows="1"> 9 select 10 m.id, version, name 11 from 12 module m 13 left join module_version mv 14 on m.id = mv.id 15 where 16 m.id = '${module}' and mv.version = '${version}' 17 order by 18 version desc 19 </sql:query> 20 21 <c:forEach var="row" items="${rs.rows}" varStatus="status"> 22 <c:if test="${status.index == 0}"> 23 <p>Do you want to delete the module ${row.name} version ${row.version}?</p> 24 <form method="post" action="/modules/admin/deleteModule"><input type="submit" value="Delete Module"/> 25 <input type="hidden" name="id" value="${row.id}"/> 26 <input type="hidden" name="version" value="${row.version}"/> 27 </form> 28 <br/> 29 <p><a href="/modules/view.jsp?module=${row.id}">Back</a></p> 30 </c:if> 31 </c:forEach> 32 33 <br /> 34 35 <%@ include file="/WEB-INF/template/footer.jsp" %>
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/