1.8. La clase GanttData

La clase GanttData será la encargada de trabajar con los datos, es decir los registros que mostrarán los nodos.


//XBB :: http://axlearn2012.blogspot.com.es/ :: XBB_Gantt :: 20141208
class XBB_GanttData_SchedEmpl extends GanttData
{
    XBB_GanttTable_SchedEmpl ganttTable_SchedEmpl;

    Set setLoadPersonnelNumbers;
    Map mapEmptyPersonnelNumber;
}


public Map getMapEmptyPersonnelNumber()
{
 
   return mapEmptyPersonnelNumber
}


Inicializaremos la colección de campos que utilizará el Gantt.



protected void initFieldCollection()
{
    this.initFieldCollectionSchedEmpl();
}
 



En este método se rellenará una lista con los campos que se utilizarán en el Gantt; los que se utilizarán para configurarlo.
Si algún campo está en la tabla pero no lo necesitamos para configurar el Gantt, lo deberemos incluir en la lista de campos excluidos, si no lo hacemos al arrancar el Gantt mostrará una advertencia de que le falta un campo.


protected void initFieldCollectionSchedEmpl()
{

  List  listFields;
  
Set   setExcludeFieldIds = new Set(Types::Integer);

  setExcludeFieldIds.add(

      fieldnum(XBB_GanttTmpSchedEmpl, PSASchedEmplReservationRecId));


  listFields = GanttTableFieldCollection::listDefaultFields(ganttTable_SchedEmpl.tableId(),
setExcludeFieldIds);

  ganttTable_SchedEmpl.fieldCollection().createFromList(listFields);
}


public void initLoadingData()
{
  this.resetLoadingDatesInterval();
  this.adjustLoadingDatesInterval(this.parmGanttClient().parmFromDate(), this.parmGanttClient().parmToDate());
  setLoadPersonnelNumbers = this.parmGanttClient().parmSetLoadIds();
}
 
 


Básicamente rellenará todos los campos que estén configurados en el formulario de Data Tables, recordad que el orden de los campos en este formulario debe ser el del Id del campo de la tabla.



Fijaos que el campo 0 es el ProjId y el 1 es el ActivityNumber. Esto es debido a que el Id del projId es el 60001 y el del ActivityNumber es el 60002 y así para todos los campos.



public void initPreLoadingData()
{
 
   super();

    this.initLoadingData();
}
 



protected void initTableCollection()
{
 
   super();


    this.parmGanttTableCollection().insert(ganttTable_SchedEmpl);
}
 


protected void initTables()
{
 
   super();

   ganttTable_SchedEmpl =   XBB_GanttTable_SchedEmpl::newAllowUserModification(true);
}


Aquí crearemos los registros para nuestra tabla.



protected void insertDataActivities(

   PSASchedEmplReservation _schedEmplReservation)
{

   ganttTable_SchedEmpl.cleanTableBuffer();
   ganttTable_SchedEmpl.initFromPSASchedEmplReservation(_schedEmplReservation);
   ganttTable_SchedEmpl.insert(_schedEmplReservation.recId, _schedEmplReservation.recVersion);
}
 




En el método loadData inicializaremos todos los métodos que carguen datos en nuestra tabla.


protected void loadData()
{
 
   super();

    this.loadDataActivities();
}
 


protected void loadDataActivities()
{
  HcmPersonnelNumberId    personnelNumber;
  SetEnumerator           setEnumerator;
  PSASchedEmplReservation schedEmplReservation;
  CalendarId              calendarId;
  FromDate                fromDate = this.parmGanttClient().parmFromDate();

  ToDate                  toDate = this.parmGanttClient().parmToDate();
 
boolean                 existForWorker;
  container               params;
  container               con;
  int                     x;


  setEnumerator = setLoadPersonnelNumbers.getEnumerator();

  this.resetEmptyPersonnelNumbers();
 
 

  while(setEnumerator && setEnumerator.moveNext())
  {

     personnelNumber = setEnumerator.current();
 
    params = connull();
     params += personnelNumber;
     params += fromDate;
     params += toDate;

     con = XBB_GanttData_SchedEmpl::loadDataActivities_Server(params);
 
    existForWorker = false;

    for (x = 1; x <= conlen(con); x++)
    {
 
      schedEmplReservation = conpeek(con, x);


      this.insertDataActivities(schedEmplReservation);
 
     existForWorker = true;

    }
 
  if (!existForWorker)
   {
      mapEmptyPersonnelNumber.insert(personnelNumber, personnelNumber);
   }
  }
}

 
protected void resetEmptyPersonnelNumbers()
{
 
   mapEmptyPersonnelNumber = new Map(Types::String, Types::String);
}

protected void resetLoadingData()
{
 
   super();

    this.resetLoadPersonnelNumbers();
    this.resetEmptyPersonnelNumbers();
}
 


protected void resetLoadPersonnelNumbers()
{
 
   setLoadPersonnelNumbers = new Set(Types::String);
}


Sobrescribiremos este método para poder guardar los datos cuando se modifiquen en el Gantt.



protected void saveData(

    boolean _onlyValidate   = false,
    boolean _skipValidation = true)
{
 
   Set            setRecIdsToBeSaved = new Set(Types::Int64);
    SetEnumerator  setEnumerator;

    XBB_GanttTmpSchedEmpl ganttTmpSchedEmpl;

 
   super();

    if(_onlyValidate)
    {
       this.progressInitValidating();
    }
 
   else
    {
       this.progressInitSaving();
    }

    setRecIdsToBeSaved = ganttTable_SchedEmpl.parmSetUserModifiedRecIds();
    setEnumerator      = setRecIdsToBeSaved.getEnumerator();

    this.progressTotal(setRecIdsToBeSaved.elements());
 
 

    while(setEnumerator && setEnumerator.moveNext())
    {
 
      ganttTable_SchedEmpl.findRecId(setEnumerator.current(), true);
       ganttTmpSchedEmpl = ganttTable_SchedEmpl.parmTableBuffer();
 
 

       if(!_skipValidation && !ganttTable_SchedEmpl.validateWrite())
       {
  
        throw Exception::Error;
       }

       XBB_GanttData_SchedEmpl::updateOrigData (

             ganttTmpSchedEmpl,
             _onlyValidate);

       this.progressUpdate();
    }

    this.progressFinish();
}
 


public static XBB_GanttData_SchedEmpl construct()
{
   
  return new XBB_GanttData_SchedEmpl();
}

public static server container loadDataActivities_Server(

   container   _params)
{
 
Query                q = new Query();
  QueryBuildDataSource qbds;
  QueryRun             qr;

  HcmWorker            hcmWorker;
  HcmPersonnelNumberId hcmPersonnelNumber;
  PSASchedEmplReservation PSASchedEmplReservation;


  FromDate fromDate;
  ToDate toDate;
 
  container ret;


  #define.personnelNumberIdx(1)
  #define.fromDateIdx(2)
  #define.toDateIdx(3)

  hcmPersonnelNumber = conpeek(_params, #personnelNumberIdx);

  fromDate = conpeek(_params, #fromDateIdx);
  toDate   = conpeek(_params, #toDateIdx);

  hcmWorker = HcmWorker::findByPersonnelNumber(hcmPersonnelNumber);
 
smmActivities.recordLevelSecurity(true);

  qbds = q.addDataSource(tableNum(PSASchedEmplReservation));
  qbds.addRange(fieldNum(PSASchedEmplReservation, Worker)). value(queryValue(hcmWorker.RecId));
  qbds.addRange(fieldNum(PSASchedEmplReservation, TransDate)).value(queryRange(fromDate, toDate));

  qr = new QueryRun(q);

  while (qr.next())
  {
 
     PSASchedEmplReservation = qr.get(tableNum(PSASchedEmplReservation));

      ret += [PSASchedEmplReservation];

  }
 
 

  return ret;
}

public static XBB_GanttData_SchedEmpl newGanttClient    (XBB_GanttClient_SchedEmpl _ganttClient)
{

     XBB_GanttData_SchedEmpl ganttData = XBB_GanttData_SchedEmpl::construct();


     ganttData.parmGanttClient(_ganttClient);
 
 

     return ganttData;
}


Este método nos guardará las modificaciones de nuestra tabla temporal a la tabla original.



protected static server void updateOrigData(

   XBB_GanttTmpSchedEmpl _ganttTmpSchedEmpl,
   boolean               _onlyValidate = false)
{

   PSASchedEmplReservation PSASchedEmplReservation;


 
PSASchedEmplReservation = PSASchedEmplReservation::findRecId(_ganttTmpSchedEmpl.PSASchedEmplReservationRecId, true);

   if (!PSASchedEmplReservation.RecId)
   {
 
       throw error(strfmt("@SYS115421",     

                   PSASchedEmplReservation.ActivityNumber));
   }

   PSASchedEmplReservation.ActivityNumber = ganttTmpSchedEmpl.ActivityNumber;
   PSASchedEmplReservation.EndTime   = _ganttTmpSchedEmpl.EndTime;
   PSASchedEmplReservation.ProjId    = _ganttTmpSchedEmpl.ProjId;
   PSASchedEmplReservation.StartTime = _ganttTmpSchedEmpl.StartTime;
   PSASchedEmplReservation.TransDate = _ganttTmpSchedEmpl.StartDate;
   PSASchedEmplReservation.Worker    = HcmWorker::findByPersonnelNumber(_ganttTmpSchedEmpl.PersonnelNumberId).RecId;
 

   if (!_onlyValidate)
   {

       PSASchedEmplReservation.update();
   }
}
 
 








Comentarios