1 64 65 package com.jcorporate.expresso.services.controller.dbmaint; 66 67 68 import com.jcorporate.expresso.core.controller.Controller; 69 import com.jcorporate.expresso.core.controller.ControllerException; 70 import com.jcorporate.expresso.core.controller.ControllerRequest; 71 import com.jcorporate.expresso.core.controller.ControllerResponse; 72 import com.jcorporate.expresso.core.controller.Input; 73 import com.jcorporate.expresso.core.controller.NonHandleableException; 74 import com.jcorporate.expresso.core.controller.Transition; 75 import com.jcorporate.expresso.core.dataobjects.DataFieldMetaData; 76 import com.jcorporate.expresso.core.dataobjects.DataObject; 77 import com.jcorporate.expresso.core.dataobjects.DataObjectMetaData; 78 import com.jcorporate.expresso.core.dataobjects.Securable; 79 import com.jcorporate.expresso.core.db.DBException; 80 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 81 import com.jcorporate.expresso.core.misc.StringUtil; 82 import com.jcorporate.expresso.core.security.User; 83 import com.jcorporate.expresso.services.controller.ui.DefaultAutoElement; 84 import com.jcorporate.expresso.services.dbobj.Setup; 85 86 import java.util.HashMap ; 87 import java.util.Map ; 88 89 90 100 public class Add 101 extends GetBase { 102 private Map fixedFields = new HashMap (); 103 104 public Add() { 105 106 } 107 108 114 public Add(String stateName, String descrip) { 115 super(stateName, descrip); 116 } 117 118 119 129 protected void autoField(String oneFieldName) 130 throws DBException, ControllerException { 131 DataObject myDBObj = this.getDataObject(); 132 StringUtil.assertNotBlank(oneFieldName, "Field Name must not be null"); 133 134 if (myDBObj == null) { 135 throw new DBException("Database object must be " + 136 "initialized before calling autoField"); 137 } 138 139 DataFieldMetaData metadata = myDBObj.getFieldMetaData(oneFieldName); 140 DataObjectMetaData objMetadata = myDBObj.getMetaData(); 141 142 if (metadata.isVirtual()) { 143 return; 144 } 145 146 147 boolean readOnly = false; 148 149 150 151 if (metadata.isReadOnly()) { 152 readOnly = true; 153 } 154 155 156 String fixedValue = (String ) fixedFields.get(oneFieldName); 157 158 if (fixedValue != null) { 159 readOnly = true; 160 } 161 162 163 String cachedValue = StringUtil.notNull(getFormCache(oneFieldName)); 164 165 if (cachedValue != null && cachedValue.length() == 0) { 169 cachedValue = null; 170 } 171 172 myDBObj.setStatus(DataObject.STATUS_NEW); 175 Input i = DefaultAutoElement.getAutoControllerElement() 176 .renderDBObjectField(getControllerResponse(), 177 myDBObj, 178 oneFieldName, 179 cachedValue, 180 readOnly); 181 182 if (i == null) { 183 return; 184 } 185 186 187 188 String lookupObjectName = StringUtil.notNull(objMetadata.getLookupObject(oneFieldName)); 189 190 if (!lookupObjectName.equals("")) { 191 Transition lookup = new Transition(); 192 lookup.setName("lookup"); 193 lookup.addParam("dbobj", lookupObjectName); 194 lookup.addParam(Controller.STATE_PARAM_KEY, "Search"); 195 lookup.setDescription("Look up Values"); 196 i.addNested(lookup); 197 } 198 199 this.addInput(i); 200 201 } 202 203 204 212 public void run(ControllerRequest req, ControllerResponse res) 213 throws NonHandleableException, ControllerException { 214 super.run(req, res); 215 fixedFields = getFixedFields(); 216 217 DataObject myDBObj = this.getDataObject(); 218 219 try { 220 if (myDBObj instanceof Securable) { 221 ((Securable) myDBObj).isAllowed("A"); 222 } else { 223 if (getUid() == SecuredDBObject.SYSTEM_ACCOUNT 224 || User.getUserFromId(getUid(), this.getControllerRequest().getDataContext()).isAdmin()) { 225 } else { 227 String allowInsecure = Setup.getValue(req.getDataContext(), 228 com.jcorporate.expresso.core.ExpressoSchema.class.getName(), 229 "insecureDBMaint"); 230 if (!(StringUtil.toBoolean(allowInsecure))) { 231 throw new SecurityException ("Access to unsecured Objects not allowed"); 232 } 233 } 234 } 235 236 showNext = false; 237 showPrev = false; 238 showForm(); 239 240 Transition addUpdate = new Transition("AddUpdate", getController()); 241 addParams(addUpdate); 242 add(addUpdate); 243 } catch (DBException de) { 244 throw new ControllerException(de); 245 } 246 } 247 } | Popular Tags |