ucAddPostInsert

Purpose

This allows additional error reporting by returning an error message.

Applies To

Add Issue screen

Signature

public void ucAddPostInsert (	
      Problem pProblem,		// the problem or case
      ArrayList pReleases,	// the list of releases
      ArrayList pModules,	// the list of modules
      ArrayList pUdfs,		// the list of UDF's
      SesameSession session)	// the current sesame Session

Notes

This is called after a record has been successfully added to the database.

Example

This example shows how after the record has been added, information pertaining to the record is read and an update is in turn made to another record. Technically, this same example could be achieved in Business Rules within the directive, in conjunction with a rule.

public void ucAddPostInsert (    
        Problem pProblem,    // the problem or case
        ArrayList pReleases,    // the list of releases
        ArrayList pModules,    // the list of modules
        ArrayList pUdfs,    // the list of UDF's
        SesameSession session)    // the current sesame Session
{
    // Call Business Rules
    super.ucAddPostInsert(pProblem, pReleases, pModules, pUdfs, session);
    
    String status = pProblem.getStatus();
    String projectId = pProblem.getProjctId();
    Z.log.writeToLog(Z.log.WARN, "UC: ucAddPostInsert - projectId=" + projectId);
    
    // PROJ__BUGS_DATA is a static String object,
    // populated in the class constructor and if status closed
    if (P_BUGS_DATA.equals(projectId) && "OPEN".equals(status) )
    {
        Connection dbConn = null;
        String childId = null;
        HashMap fp = new FormParameters();
        
        try
        {
            // Get database connection
            dbConn = Z.pool.getConnection("ucAddPostInsert");

            // Iterate through udf's to find special child id
            Iterator itr = pUdfs.iterator();
            while (itr.hasNext())
            {
                Problem_UDF udf = (Problem_UDF) itr.next();
        
                if ("SPECIAL_CHILD_ID".equals(udf.getName()) )
                {
                childId = udf.getValue();
                break;
                }
            }
        
            // Populate form parameter object as needed
            fp.put("STATUS", "DUPLICATE");
            fp.put("COMMENTS", "This record was marked as Duplicate because it was " +
            "the 'Special Child' of a new Bug record: " +
                pProblem.getId() + " that was Opened.");
        
            // If child records not null then update using another User Custom method
            if (childId != null) {
                apiEditItem(fp, dbConn, session, childId);
            }
        
        } catch (Exception e) {
            Z.log.writeToLog(Z.log.ERROR, "UC: ucAddPostInsert Exception: " + e);
            ErrorWriter.write(e, ErrorWriter.LOGERR);
        
        } finally {
            // Close the database connection
            if (dbConn != null) { Z.pool.close(dbConn); }
        }
    }
}