Package org.gjt.bugrat.db

Source Code of org.gjt.bugrat.db.Bug

package org.gjt.bugrat.db;

import java.io.Serializable;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.Hashtable;

import org.gjt.bugrat.dbi.*;


public
class    Bug
extends    JartDBObject
implements  Cloneable, BugRatConstants
  {
  private int        bugId;

  private String      source;
  private int        srcid;
  private int        responsible;
  private Date      opened;
  private Date      closed;
  private String      confidence;
  private String      severity;
  private String      priority;
  private String      state;
  private String      bugclass;
  private String      project;
  private String      category;
  private String      subcat;

  private Description    bugdesc;
  private EnvDescription  envdesc;
  private Description    repro;
  private Description    around;


  public static Bug
  getBug( int id )
    throws DBIException
    {
    return DBIManager.getInstance().getBugDBI().getBug( id );
    }

  public static Bug
  getNewBug()
    throws DBIException
    {
    return DBIManager.getInstance().getBugDBI().getNewBug();
    }

  public static Vector
  matchBugs( String whereClause )
    throws DBIException
    {
    return DBIManager.getInstance().getBugDBI().matchBugs( whereClause );
    }

  public
  Bug( int id )
    {
    this.bugId = id;
    }

  public int
  getId()
    {
    return this.bugId;
    }

  public String
  getSource()
    {
    return this.source;
    }

  public void
  setSource( String source )
    {
    this.source = source;
    }

  public int
  getSourceId()
    {
    return this.srcid;
    }

  public void
  setSourceId( int id )
    {
    this.srcid = id;
    }

  public java.util.Date
  getOpenDate()
    {
    return this.opened;
    }

  public void
  setOpenDate( java.util.Date opened )
    {
    this.opened = opened;
    }

  public java.util.Date
  getCloseDate()
    {
    return this.closed;
    }

  public void
  setCloseDate( java.util.Date closed )
    {
    this.closed = closed;
    }

  public String
  getProject()
    {
    return this.project;
    }

  public void
  setProject( String project )
    {
    this.project = project;
    }

  public String
  getCategory()
    {
    return this.category;
    }

  public void
  setCategory( String category )
    {
    this.category = category;
    }

  public String
  getSubCategory()
    {
    return this.subcat;
    }

  public void
  setSubCategory( String subcat )
    {
    this.subcat = subcat;
    }

  public String
  getSeverity()
    {
    return this.severity;
    }

  public void
  setSeverity( String severity )
    {
    this.severity = severity;
    }

  public int
  getResponsible()
    {
    return this.responsible;
    }

  public void
  setResponsible( int responsible )
    {
    this.responsible = responsible;
    }

  public String
  getBugClass()
    {
    return this.bugclass;
    }

  public void
  setBugClass( String cls )
    {
    this.bugclass = cls;
    }

  public boolean
  isClosed()
    {
    return this.state.equals( STATE_CLOSED );
    }

  public String
  getState()
    {
    return this.state;
    }

  public void
  setState( String state )
    {
    this.state = state;
    }

  public String
  getPriority()
    {
    return this.priority;
    }

  public void
  setPriority( String priority )
    {
    this.priority = priority;
    }

  public String
  getConfidence()
    {
    return this.confidence;
    }

  public void
  setConfidence( String confidence )
    {
    this.confidence = confidence;
    }

  public Description
  getDescription()
    {
    return this.bugdesc;
    }

  public void
  setDescription( Description desc )
    {
    this.bugdesc = desc;
    }

  public EnvDescription
  getEnvDescription()
    {
    return this.envdesc;
    }

  public void
  setEnvDescription( EnvDescription desc )
    {
    this.envdesc = desc;
    }

  public Description
  getReproDescription()
    {
    return this.repro;
    }

  public void
  setReproDescription( Description desc )
    {
    this.repro = desc;
    }

  public Description
  getAroundDescription()
    {
    return this.around;
    }

  public void
  setAroundDescription( Description desc )
    {
    this.around = desc;
    }

  public void
  commit()
    throws DBIException
    {
    this.getDBI().commit( this );
    }

  public Object
  clone()
    {
    Bug bug = (Bug) super.clone();   

    bug.opened = new Date( this.opened.getTime() );
    bug.closed =
      ( this.closed == null )
        ? null
        : new Date( this.closed.getTime() );

    if ( this.bugdesc != null )
      bug.bugdesc = (Description) this.bugdesc.clone();

    if ( this.envdesc != null )
      bug.envdesc = (EnvDescription) this.envdesc.clone();

    if ( this.repro != null )
      bug.repro = (Description) this.repro.clone();

    if ( this.around != null )
      bug.around = (Description) this.around.clone();

    return bug;
    }

  public StringBuffer
  getDeltaDescription( Bug that, String prefix, StringBuffer buf, DBConfig cfg )
    {
    boolean mods = false;

    // SOURCE
    if ( ! this.source.equals( that.source ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Source changed from '" );
      buf.append( that.source );
      buf.append( "' to '" );
      buf.append( this.source );
      buf.append( "'.\n" );
      }

    // SOURCE ID
    if ( this.srcid != that.srcid )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Source ID changed from '" );
      buf.append( that.srcid );
      buf.append( "' to '" );
      buf.append( this.srcid );
      buf.append( "'.\n" );
      }

    // CONFIDENCE
    if ( ! this.confidence.equals( that.confidence ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Confidence changed from '" );
      buf.append( cfg.getConfidenceName( that.confidence ) );
      buf.append( "' to '" );
      buf.append( cfg.getConfidenceName( this.confidence ) );
      buf.append( "'.\n" );
      }

    // SEVERITY
    if ( ! this.severity.equals( that.severity ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Severity changed from '" );
      buf.append( cfg.getSeverityName( that.severity ) );
      buf.append( "' to '" );
      buf.append( cfg.getSeverityName( this.severity ) );
      buf.append( "'.\n" );
      }

    // PRIORITY
    if ( ! this.priority.equals( that.priority ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Priority changed from '" );
      buf.append( cfg.getPriorityName( that.priority ) );
      buf.append( "' to '" );
      buf.append( cfg.getPriorityName( this.priority ) );
      buf.append( "'.\n" );
      }

    // STATE
    if ( ! this.state.equals( that.state ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "State changed from '" );
      buf.append( cfg.getStateName( that.state ) );
      buf.append( "' to '" );
      buf.append( cfg.getStateName( this.state ) );
      buf.append( "'.\n" );
      }

    // CLASS
    if ( ! this.bugclass.equals( that.bugclass ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Class changed from '" );
      buf.append( cfg.getClassName( that.bugclass ) );
      buf.append( "' to '" );
      buf.append( cfg.getClassName( this.bugclass ) );
      buf.append( "'.\n" );
      }

    // PROJECT
    if ( ! this.project.equals( that.project ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Project changed from '" );
      buf.append( cfg.getProjectName( that.project ) );
      buf.append( "' to '" );
      buf.append( cfg.getProjectName( this.project ) );
      buf.append( "'.\n" );
      }

    // CATEGORY
    if ( ! this.category.equals( that.category ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Category changed from '" );
      buf.append( cfg.getCategoryName
            ( that.project, that.category ) );
      buf.append( "' to '" );
      buf.append( cfg.getCategoryName
            ( this.project, this.category ) );
      buf.append( "'.\n" );
      }

    // SUBCATEGORY
    if ( ! this.subcat.equals( that.subcat ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Subcategory changed from '" );
      buf.append( cfg.getSubCategoryName
            ( that.project, that.category, that.subcat ) );
      buf.append( "' to '" );
      buf.append( cfg.getSubCategoryName
            ( this.project, this.category, this.subcat ) );
      buf.append( "'.\n" );
      }

    // RESPONSIBLE
    if ( this.responsible != that.responsible )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Responsible ID changed from '" );
      buf.append( that.responsible );
      buf.append( "' to '" );
      buf.append( this.responsible );
      buf.append( "'.\n" );
      }

    StringBuffer dBuf = new StringBuffer();
    SimpleDateFormat dFmt =
      new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss" );

    // OPEN DATE
    if ( this.opened.getTime() != that.opened.getTime() )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Open date changed from '" );
      dFmt.format( that.opened, dBuf, new FieldPosition(0) );
      buf.append( dBuf );
      buf.append( "' to '" );
      dFmt.format( this.opened, dBuf, new FieldPosition(0) );
      buf.append( dBuf );
      buf.append( "'.\n" );
      }

    // CLOSE DATE
    if ( this.closed == null && that.closed == null )
      {
      // No mods
      }
    else if ( this.closed == null && that.closed != null )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Close date unset, previous value was '" );
      dFmt.format( that.closed, dBuf, new FieldPosition(0) );
      buf.append( dBuf );
      buf.append( "'.\n" );
      }
    else if ( this.closed != null && that.closed == null )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Close date set to '" );
      dFmt.format( this.closed, dBuf, new FieldPosition(0) );
      buf.append( dBuf );
      buf.append( "'.\n" );
      }
    else if ( this.closed.getTime() != that.closed.getTime() )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Close date changed from '" );
      dFmt.format( that.closed, dBuf, new FieldPosition(0) );
      buf.append( dBuf );
      buf.append( "' to '" );
      dFmt.format( this.closed, dBuf, new FieldPosition(0) );
      buf.append( dBuf );
      buf.append( "'.\n" );
      }

    if ( ! this.envdesc.equals( that.envdesc ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "\nEnvironment description modified:\n" );
      this.envdesc.getDeltaDescription
        ( that.envdesc, prefix + "   ", buf, cfg );
      }

    if ( ! this.bugdesc.equals( that.bugdesc ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "\nBug description modified:\n" );
      this.bugdesc.getDeltaDescription
        ( that.bugdesc, prefix + "   ", buf, cfg );
      }

    if ( this.repro != null && that.repro == null )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Reproduce description added.\n" );
      }
    else if ( this.repro == null && that.repro != null )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Reproduce description removed.\n" );
      }
    else if ( this.repro != null && that.repro != null
        && ! this.repro.equals( that.repro ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Reproduce description modified:\n" );
      this.repro.getDeltaDescription
        ( that.repro, prefix + "   ", buf, cfg );
      buf.append( "\n" );
      }

    if ( this.around != null && that.around == null )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Work around description added.\n" );
      }
    else if ( this.around == null && that.around != null )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Work around description removed.\n" );
      }
    else if ( this.around != null && that.around != null
        && ! this.around.equals( that.around ) )
      {
      mods = true;
      buf.append( prefix );
      buf.append( "Work around description modified:\n" );
      this.around.getDeltaDescription
        ( that.around, prefix + "   ", buf, cfg );
      buf.append( "\n" );
      }

    if ( ! mods )
      {
      buf.append( prefix );
      buf.append( "There were no modifications to the bug.\n" );
      }

    return buf;
    }

  /**
   * Returns the currently set ReportDBI, which is the class that
   * performs our database needs in a generic fashion.
   *
   * @return The ReportDBI subclass that is currently set.
   * @see ReportDBI
   */

  private BugDBI
  getDBI()
    throws DBIException
    {
    return DBIManager.getInstance().getBugDBI();
    }

  public String
  toString()
    {
    return "[" + super.toString()
      + " bugId=" + this.bugId + "]";
    }

  }

TOP

Related Classes of org.gjt.bugrat.db.Bug

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.