1 16 package com.blandware.atleap.webapp.action.core.globalProperty; 17 18 import com.blandware.atleap.common.util.ConvertUtil; 19 import com.blandware.atleap.model.core.GlobalProperty; 20 import com.blandware.atleap.webapp.action.core.BaseAction; 21 import com.blandware.atleap.webapp.form.core.GlobalPropertyForm; 22 import com.blandware.atleap.webapp.util.core.GlobalProperties; 23 import org.apache.struts.action.ActionForm; 24 import org.apache.struts.action.ActionForward; 25 import org.apache.struts.action.ActionMapping; 26 import org.apache.struts.action.ActionMessage; 27 import org.apache.struts.action.ActionMessages; 28 import org.springframework.orm.ObjectOptimisticLockingFailureException; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.Map ; 36 37 59 public final class UpdateGlobalPropertiesAction extends BaseAction { 60 69 public ActionForward execute(ActionMapping mapping, ActionForm form, 70 HttpServletRequest request, HttpServletResponse response) throws Exception { 71 72 GlobalPropertyForm globalPropertyForm = (GlobalPropertyForm) form; 73 Map properties = globalPropertyForm.getPropertyMap(); 74 List nonExistentPropertyNames = new ArrayList (); 75 boolean alreadyUpdatedExist = false; 76 for ( Iterator i = properties.entrySet().iterator(); i.hasNext(); ) { 77 Map.Entry entry = (Map.Entry ) i.next(); 78 String name = (String ) entry.getKey(); 79 GlobalProperty property = GlobalProperties.getInstance(request.getSession().getServletContext()).retrieveGlobalProperty(name); 80 if ( property == null ) { 81 nonExistentPropertyNames.add(name); 82 continue; 83 } 84 String value = (String ) entry.getValue(); 85 Long version = Long.valueOf((String ) globalPropertyForm.getVersion(name)); 86 property.setValue(value); 87 property.setVersion(version); 88 try { 89 GlobalProperties.getInstance(request.getSession().getServletContext()).updateProperty(property); 90 } catch ( ObjectOptimisticLockingFailureException e ) { 91 alreadyUpdatedExist = true; 92 } 93 } 94 95 if ( !nonExistentPropertyNames.isEmpty() || alreadyUpdatedExist ) { 96 ActionMessages errors = new ActionMessages(); 97 if ( !nonExistentPropertyNames.isEmpty() ) { 98 errors.add("nonExistentProperties", new ActionMessage("core.globalProperty.errors.nonExistentProperties", ConvertUtil.convertListToString(nonExistentPropertyNames, ", "))); 99 } 100 if ( alreadyUpdatedExist ) { 101 errors.add("alreadyUpdatedProperties", new ActionMessage("core.globalProperty.errors.updateFailed")); 102 } 103 saveErrors(request, errors); 104 } else { 105 ActionMessages messages = new ActionMessages(); 106 messages.add("updateSuccessful", new ActionMessage("core.globalProperty.messages.updateSuccessful")); 107 saveMessages(request, messages); 108 } 109 110 return mapping.findForward("listGlobalProperties"); 111 } 112 } | Popular Tags |