public void createSecForm(CFSecurityAuthorization Authorization, CFSecuritySecFormBuff Buff) { final String S_ProcName = "createSecForm"; CFSecuritySecFormPKey pkey = schema.getFactorySecForm().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecFormId( ((CFInternetRamClusterTable) schema.getTableCluster()) .nextSecFormIdGen(Authorization, Buff.getRequiredClusterId())); Buff.setRequiredClusterId(pkey.getRequiredClusterId()); Buff.setRequiredSecFormId(pkey.getRequiredSecFormId()); CFSecuritySecFormByClusterIdxKey keyClusterIdx = schema.getFactorySecForm().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFSecuritySecFormBySecAppIdxKey keySecAppIdx = schema.getFactorySecForm().newSecAppIdxKey(); keySecAppIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keySecAppIdx.setRequiredSecAppId(Buff.getRequiredSecAppId()); CFSecuritySecFormByUJEEServletIdxKey keyUJEEServletIdx = schema.getFactorySecForm().newUJEEServletIdxKey(); keyUJEEServletIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyUJEEServletIdx.setRequiredSecAppId(Buff.getRequiredSecAppId()); keyUJEEServletIdx.setRequiredJEEServletMapName(Buff.getRequiredJEEServletMapName()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory() .newPrimaryKeyNotNewException(getClass(), S_ProcName, pkey); } if (dictByUJEEServletIdx.containsKey(keyUJEEServletIdx)) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, "SecFormUJEEServletIdx", keyUJEEServletIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema .getTableCluster() .readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory() .newUnresolvedRelationException( getClass(), S_ProcName, "Owner", "SecFormCluster", "Cluster", null); } } } { boolean allNull = true; allNull = false; allNull = false; if (!allNull) { if (null == schema .getTableSecApp() .readDerivedByIdIdx( Authorization, Buff.getRequiredClusterId(), Buff.getRequiredSecAppId())) { throw CFLib.getDefaultExceptionFactory() .newUnresolvedRelationException( getClass(), S_ProcName, "Container", "SecFormApplication", "SecApp", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); Map<CFSecuritySecFormPKey, CFSecuritySecFormBuff> subdictClusterIdx; if (dictByClusterIdx.containsKey(keyClusterIdx)) { subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx); } else { subdictClusterIdx = new HashMap<CFSecuritySecFormPKey, CFSecuritySecFormBuff>(); dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx); } subdictClusterIdx.put(pkey, Buff); Map<CFSecuritySecFormPKey, CFSecuritySecFormBuff> subdictSecAppIdx; if (dictBySecAppIdx.containsKey(keySecAppIdx)) { subdictSecAppIdx = dictBySecAppIdx.get(keySecAppIdx); } else { subdictSecAppIdx = new HashMap<CFSecuritySecFormPKey, CFSecuritySecFormBuff>(); dictBySecAppIdx.put(keySecAppIdx, subdictSecAppIdx); } subdictSecAppIdx.put(pkey, Buff); dictByUJEEServletIdx.put(keyUJEEServletIdx, Buff); }
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { CFBamXMsgSchemaMessageFormatter schemaFormatter = null; try { // Common XML Attributes String attrId = null; String attrRevision = null; // SecForm Attributes String attrClusterId = null; String attrSecFormId = null; String attrSecAppId = null; String attrJEEServletMapName = null; String attrCreatedAt = null; String attrCreatedBy = null; String attrUpdatedAt = null; String attrUpdatedBy = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstSecFormCreate"); CFBamXMsgRqstHandler xmsgRqstHandler = (CFBamXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); ICFBamSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate an edit buffer for the parsed information ICFBamSecFormEditObj editBuff = (ICFBamSecFormEditObj) schemaObj.getSecFormTableObj().newInstance().beginEdit(); CFSecuritySecFormBuff dataBuff = (CFSecuritySecFormBuff) editBuff.getSecFormBuff(); // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedAt")) { if (attrCreatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedBy")) { if (attrCreatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedAt")) { if (attrUpdatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedBy")) { if (attrUpdatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ClusterId")) { if (attrClusterId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrClusterId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SecFormId")) { if (attrSecFormId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSecFormId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SecAppId")) { if (attrSecAppId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSecAppId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("JEEServletMapName")) { if (attrJEEServletMapName != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrJEEServletMapName = attrs.getValue(idxAttr); } else { throw CFLib.getDefaultExceptionFactory() .newUnrecognizedAttributeException( getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrClusterId == null) || (attrClusterId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ClusterId"); } if ((attrSecFormId == null) || (attrSecFormId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "SecFormId"); } if ((attrSecAppId == null) || (attrSecAppId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "SecAppId"); } if (attrJEEServletMapName == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "JEEServletMapName"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. long natClusterId = Long.parseLong(attrClusterId); dataBuff.setRequiredClusterId(natClusterId); int natSecAppId = Integer.parseInt(attrSecAppId); dataBuff.setRequiredSecAppId(natSecAppId); String natJEEServletMapName = attrJEEServletMapName; dataBuff.setRequiredJEEServletMapName(natJEEServletMapName); UUID createdBy = null; if (attrCreatedBy != null) { createdBy = UUID.fromString(attrCreatedBy); } Calendar createdAt = null; if (attrCreatedAt != null) { createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt); } UUID updatedBy = null; if (attrUpdatedBy != null) { updatedBy = UUID.fromString(attrUpdatedBy); } Calendar updatedAt = null; if (attrUpdatedAt != null) { updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt); } if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } // Attempt the create editBuff.copyBuffToPKey(); // Allow for predefined ids ICFBamSecFormObj created = (ICFBamSecFormObj) editBuff.create(); editBuff.endEdit(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFBamXMsgSecFormMessageFormatter.formatSecFormRspnCreated( "\n\t\t\t", created.getSecFormBuff()) + "\n" + schemaFormatter.formatRspnXmlPostamble(); ((CFBamXMsgRqstHandler) getParser()).appendResponse(response); } catch (RuntimeException e) { CFBamXMsgRqstHandler xmsgRqstHandler = ((CFBamXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFBamXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { CFBamXMsgRqstHandler xmsgRqstHandler = ((CFBamXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFBamXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }