1 64 65 package com.jcorporate.expresso.services.controller.dbmaint; 66 67 72 73 import com.jcorporate.expresso.core.controller.ControllerException; 74 import com.jcorporate.expresso.core.controller.ControllerRequest; 75 import com.jcorporate.expresso.core.controller.ControllerResponse; 76 import com.jcorporate.expresso.core.controller.ErrorCollection; 77 import com.jcorporate.expresso.core.controller.NonHandleableException; 78 import com.jcorporate.expresso.core.controller.Output; 79 import com.jcorporate.expresso.core.dataobjects.DataObject; 80 import com.jcorporate.expresso.core.dataobjects.Securable; 81 import com.jcorporate.expresso.core.db.DBException; 82 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 83 import com.jcorporate.expresso.core.misc.StringUtil; 84 import com.jcorporate.expresso.core.security.User; 85 import com.jcorporate.expresso.services.controller.ui.DefaultAutoElement; 86 import com.jcorporate.expresso.services.dbobj.Setup; 87 import org.apache.log4j.Logger; 88 89 90 98 public class UpdateUpdate 99 extends UpdateBase { 100 private Logger log = Logger.getLogger(UpdateUpdate.class); 101 102 public UpdateUpdate() { 103 104 } 105 106 112 public UpdateUpdate(String code, String descrip) { 113 super(code, descrip); 114 } 115 116 122 public void run(ControllerRequest req, ControllerResponse res) 123 throws NonHandleableException, ControllerException { 124 super.run(req, res); 125 126 DataObject myDBObj = this.getDataObject(); 127 ErrorCollection ee = new ErrorCollection(); 128 129 try { 130 setFormCache(); 131 myDBObj = this.retrieveMyDBObject(); 132 133 myDBObj = DefaultAutoElement.getAutoControllerElement().parseDBObject(req, myDBObj, ee); 134 135 136 if (ee.getErrorCount() > 0) { 137 res.saveErrors(ee); 138 transition("Update", req, res); 139 return; 140 } 141 142 if (myDBObj instanceof Securable) { 143 ((Securable) myDBObj).isAllowed(SecuredDBObject.UPDATE); 144 145 } else { 146 if (getUid() == SecuredDBObject.SYSTEM_ACCOUNT 147 || User.getUserFromId(getUid(), this.getControllerRequest().getDataContext()).isAdmin()) { 148 } else { 150 String allowInsecure = Setup.getValue(req.getDataContext(), 151 com.jcorporate.expresso.core.ExpressoSchema.class.getName(), 152 "insecureDBMaint"); 153 if (!(StringUtil.toBoolean(allowInsecure))) { 154 throw new SecurityException ("Access to unsecured Objects not allowed"); 155 } 156 } 157 } 158 159 myDBObj.update(); 160 161 super.saveBlobFields(myDBObj); 163 164 165 addOutput(new Output("title", "Data Saved")); 166 showUserName(""); 167 showNext = false; 168 showPrev = false; 169 addOutput(new Output("message", "Data Updated")); 170 showKey(true); 171 showOptions(); 172 clearFormCache(); 173 } catch (DBException de) { 174 log.warn(de); 175 ee.addError(de); 176 res.saveErrors(ee); 177 transition("Update", req, res); 178 return; 179 } 180 if (ee.getErrorCount() > 0) { 181 res.saveErrors(ee); 182 setResponse(getController().newState("Update", req)); 183 184 } 186 } 187 188 189 } 190 191 | Popular Tags |