Skip to content

Instantly share code, notes, and snippets.

@dutchand
Forked from SamOrozco/Plant4SheetsFacade.java
Created September 14, 2017 14:26
Show Gist options
  • Save dutchand/e5354233e4474dfe0aa899f92ffac2de to your computer and use it in GitHub Desktop.
Save dutchand/e5354233e4474dfe0aa899f92ffac2de to your computer and use it in GitHub Desktop.
Java Exmaples
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package plant.four.admin.entities;
import erp.admin.entities.MaintenanceLog;
import erp.admin.entities.MaintenanceLogFacade;
import erp.admin.entities.Plant;
import erp.admin.entities.PlantFacade;
import erp.production.veneer.entities.ScannerSummary;
import erp.production.veneer.entities.ScannerSummaryFacade;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import erp.util.helpers.DateHelper;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.List;
import javax.ejb.EJB;
import javax.persistence.Query;
/**
*
* @author samo PLANT 4 SHEETS FACADE
*/
@Stateless
public class Plant4SheetsFacade extends AbstractFacade<Sheets> {
// Samo Variables
//EJB'S
@EJB
private PlantFacade plantFacade;
@EJB
private ScannerSummaryFacade scannerFacade;
@EJB
private MaintenanceLogFacade maintFacade;
//STATIC VARIABLES
private static final String _dry = "Dry";
private static final String _plant4ImportJob = "GS2000 Maintenance Summary -- Plant 4";
private static final String _zeroRecordsFromDataBase = "Zero Records Returned From GS2000 Database";
private static final String _inserted = "Inserted: ";
private static final String _rowsInto = "rows into ScannerSummary table";
private static final String _plantId = "P4";
private static final String _plant4Source = "Plant 4";
private static final String _width = "54";
private static final String _day = "Day";
private static final String _swing = "Swing";
private static final String _graveyard = "Graveyard";
private static final String _whiteFir = "WF";
private static final String _dougFir = "DF";
private static final String _relief = "Relief";
//NON STATIC VARIABLES
private Plant plant;
private ScannerSummary insertScanner;
private DateHelper dHelper;
private Date insertDate;
private int insertNum;
private int status;
@PersistenceContext(unitName = "PlantFourScanner-ejbPU")
private EntityManager em;
//end samo variables
public void prepareHourlySummary(Date start, Date end) {
setPlant(plantFacade.find(_plantId));
insertDate = start;
List<Object[]> res = getSumList(start, end);
if (res == null || res.isEmpty()) {
this.insertMaintenance(_plant4ImportJob, _zeroRecordsFromDataBase, 0, 0, start, end);
} else if (res != null || !res.isEmpty()) {
doQuery(res);
if(this.insertNum == 0) this.status = 0;
else this.status = 1;
this.insertMaintenance(_plant4ImportJob, _inserted + res.size() + _rowsInto , 1, res.size(), start, end);
}
}
public void prepareSummary(Date reportStart, Date reportEnd) {
setPlant(plantFacade.find(_plantId));
Date localStart = getLocalStartFirst(reportStart);
Date localEnd = getLocalEndTime(reportStart);
reportEnd = dHelper.setEndOfDayTime(reportEnd);
//setting report end to a day before report date selected
Calendar cal = Calendar.getInstance();
cal.setTime(reportEnd);
cal.add(Calendar.DATE, -1);
reportEnd = cal.getTime();
while (localEnd.compareTo(reportEnd) <= 0) {
insertDate = localEnd;
List<Object[]> result = getSumList(localStart, localEnd);
if (result == null || result.isEmpty()) {
this.insertMaintenance(_plant4ImportJob, _zeroRecordsFromDataBase, 0, 0, localStart, localEnd);
} else if (result != null || !result.isEmpty()) {
doQuery(result);
if(this.insertNum == 0)this.status = 0;
this.insertMaintenance(_plant4ImportJob, _inserted + result.size() + _rowsInto , 1, result.size(), localStart, localEnd);
this.insertNum = 0;
}
Calendar tmpDate = new GregorianCalendar();
tmpDate.setTime(localStart);
tmpDate.add(Calendar.DATE, 1);
localStart = getLocalStart(tmpDate.getTime());
tmpDate.add(Calendar.DATE, 1);
localEnd = getLocalEndTime(tmpDate.getTime());
}
}
private void doQuery(List<Object[]> resList) {
this.insertNum = 0;
for (Object[] scanner : resList) {
ScannerSummary tmpScanner = new ScannerSummary();
tmpScanner = createSummaryFromArray(scanner);
if(!inTable(tmpScanner))
{
++insertNum;
scannerFacade.create(tmpScanner);
}
else
{
tmpScanner = null;
}
}
}
private boolean inTable(ScannerSummary scanner) {
return scannerFacade.inTable(scanner);
}
private Date getLocalStartFirst(Date first) {
Calendar cal = new GregorianCalendar();
cal.setTime(first);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DATE);
--day;
cal.set(year, month, day, 23, 0, 0);
return cal.getTime();
}
private Date getLocalEndTime(Date end) {
Calendar cal = new GregorianCalendar();
cal.setTime(end);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DATE);
cal.set(year, month, day, 23, 0, 0);
return cal.getTime();
}
private ScannerSummary createSummaryFromArray(Object[] tmpObj) {
ScannerSummary tmpScanner = new ScannerSummary();
tmpScanner.setPiececount((Long) tmpObj[0]);
tmpScanner.setSpecies(pullSpecieName((String) tmpObj[1]));
tmpScanner.setThickness(pullThickFromSpecie((String) tmpObj[1]));
tmpScanner.setGrade((String) tmpObj[2]);
tmpScanner.setShift(pullShiftFromShift((String) tmpObj[3]));
tmpScanner.setDryerNumber(String.valueOf(tmpObj[4]));
tmpScanner.setWidth(_width);
tmpScanner.setLength(8);
tmpScanner.setSource(_plant4Source);
tmpScanner.setPlant(getPlant());
tmpScanner.setDayProduced(insertDate);
tmpScanner.setInTimestamp(new Date());
tmpScanner.setMoisture(_dry);
tmpScanner.setSurface(this.getSurfaceFromScanner(tmpScanner));
tmpScanner.setFootage(this.getNominalArea(tmpScanner));
return tmpScanner;
}
private Long getNominalArea(ScannerSummary scanner) {
double tmpValue = scanner.getSurface() * scanner.getThickness() / .375;
return (Long) Math.round(tmpValue);
}
private String pullShiftFromShift(String shift) {
if (shift.contains("#1")) {
return _graveyard;
} else if (shift.contains("#2")) {
return _day;
} else if (shift.contains("#3")) {
return _swing;
}
else if(shift.contains("#4"))
{
return _relief;
}
else {
return "Unknown";
}
}
private Long getSurfaceFromScanner(ScannerSummary scanner) {
Long l = scanner.getPiececount() * 32;
return l;
}
private double pullThickFromSpecie(String specie) {
double tmpThickness = 0.0;
int thickness = 0;
if (specie.contains("#")) {
String[] stringSeg = specie.split("-");
return (double) Integer.parseInt(stringSeg[1]) * .001;
} else {
thickness = Integer.parseInt(specie.substring(0, 2));
tmpThickness = thickness * .001;
}
return (double) tmpThickness;
}
private String pullSpecieName(String specie) {
if (specie.contains("White Fir")) {
return _whiteFir;
} else if (specie.contains("Doug Fir")) {
return _dougFir;
} else {
return "Uknown Specie:" + specie;
}
}
public List<Object[]> getSumList(Date start, Date end) {
String query = "";
query += "SELECT COUNT(s) pCount,"
// + "SUM(s.nominalArea),"
+ "p.nameText,"
+ "g.nameText,"
+ "t.shiftID , "
// + "s.surfaceMeasure"
+ "s.dryerNum"
+ " FROM Sheets s , Gradenames g , Specienames p, Shifttimes t"
+ " WHERE s.createdLocal >= :start and s.createdLocal < :end"
+ " AND s.specieNameIndex = p.nameIndex "
+ " AND s.gradeNameIndex = g.nameIndex"
+ " AND s.shiftIndex = t.shiftIndex"
+ " GROUP BY t.shiftID, p.nameText , g.nameText, s.dryerNum";
Query q = em.createQuery(query);
q.setParameter("start", start);
q.setParameter("end", end);
return q.getResultList();
}
private void insertMaintenance(String job, String logInformation, int status, int numRows, Date start, Date end) {
MaintenanceLog maint = new MaintenanceLog();
maint.setJob(job);
maint.setQueryDate(new Date());
maint.setLogInformation(logInformation);
maint.setRowNumber(numRows);
maint.setStatus(status);
maint.setQueryStartTime(start);
maint.setQueryEndTime(end);
maintFacade.create(maint);
}
public Date getLocalStart(Date date) {
Calendar cal = new GregorianCalendar();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DATE);
cal.set(year, month, day, 23, 0, 0);
return cal.getTime();
}
private Double roundDoubles(Double numberToRound, int Places) {
BigDecimal bd = new BigDecimal(numberToRound);
bd = bd.setScale(Places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
public void setPlant(Plant plant) {
this.plant = plant;
}
public Plant getPlant() {
return this.plant;
}
@Override
protected EntityManager getEntityManager() {
return em;
}
public Plant4SheetsFacade() {
super(Sheets.class);
}
}
package erp.production.controller;
import erp.admin.entities.Plant;
import erp.admin.entities.WorkCenter;
import erp.admin.exceptions.ProductTypeException;
import erp.common.entities.Grade;
import erp.common.entities.Product;
import erp.common.entities.Shift;
import erp.common.entities.Species;
import erp.common.lumber.entities.LumberProduct;
import erp.common.plywood.entities.PlywoodProduct;
import erp.util.controller.JsfUtil;
import erp.util.controller.PaginationHelper;
import erp.util.helpers.DateHelper;
import erp.common.veneer.entities.VeneerProduct;
import erp.production.common.entities.Bundle;
import erp.production.common.entities.Run;
import erp.production.common.entities.RunComparator;
import erp.production.common.entities.RunFacade;
import erp.production.common.entities.RunItem;
import erp.production.common.entities.RunItemComparator;
import erp.production.exceptions.RunItemsRequiredException;
import erp.production.exceptions.productException;
import erp.production.lumber.entities.LumberRun;
import erp.production.lumber.entities.LumberRunItem;
import erp.production.plywood.entities.PlywoodRun;
import erp.production.plywood.entities.PlywoodRunItem;
import erp.production.plywood.entities.SawlineRunItem;
import erp.production.veneer.entities.SawLineBundle;
import erp.production.veneer.entities.VeneerBundle;
import erp.production.veneer.entities.VeneerRun;
import erp.production.veneer.entities.VeneerRunItem;
import erp.util.helpers.FootageHelper;
import java.io.Serializable;
import java.math.BigDecimal;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
@SessionScoped
@Named("runController")
public class RunController implements Serializable {
/**
* @return the _editRunProduct
*/
public static String getEditRunProduct() {
return _editRunProduct;
}
/**
* @return the _sawlineReport
*/
public static String getSawlineReport() {
return _sawlineReport;
}
/**
* @param aSawlineReport the _sawlineReport to set
*/
public static void setSawlineReport(String aSawlineReport) {
_sawlineReport = aSawlineReport;
}
private Run current;
private DataModel items = null;
@EJB
private erp.production.common.entities.RunFacade ejbFacade;
@EJB
private erp.production.veneer.entities.VeneerRunFacade ejbVeneerFacade;
@EJB
private erp.production.lumber.entities.LumberRunFacade ejbLumberFacade;
@EJB
private erp.production.plywood.entities.PlywoodRunFacade ejbPlywoodFacade;
@EJB
private erp.production.common.entities.RunItemFacade ejbRunItemFacade;
@EJB
private erp.production.plywood.entities.PlywoodRunItemFacade ejbPlywoodRunItemFacade;
@EJB
private erp.production.plywood.entities.SawlineRunItemFacade ejbSawlineRunItemFacade;
@EJB
private erp.production.veneer.entities.VeneerRunItemFacade ejbVeneerRunItemFacade;
@EJB
private erp.production.lumber.entities.LumberRunItemFacade ejbLumberRunItemFacade;
@EJB
private erp.admin.entities.ErpUserFacade ejbUserFacade;
@EJB
private erp.common.plywood.entities.PlywoodProductFacade ejbPlywoodProductFacade;
@EJB
private erp.common.veneer.entities.VeneerProductFacade ejbVeneerProductFacade;
@EJB
private erp.common.lumber.entities.LumberProductFacade ejbLumberProductFacade;
@EJB
private erp.admin.entities.WorkCenterFacade ejbWorkCenterFacade;
@EJB
private erp.admin.entities.PlantFacade plantFacade;
@EJB
private erp.common.entities.ProductFacade prodFacade;
@EJB
private erp.production.common.entities.BundleFacade bundleFacade;
@EJB
private erp.admin.entities.ErpUserFacade userFacade;
@EJB
private erp.production.plywood.entities.SawLineBundleFacade sawLineBundleFacade;
private final int _sawlineItemDisplayRows = 40;
private PaginationHelper pagination;
private int selectedItemIndex;
private Date scheduledStartDate;
private Date scheduledStartTime;
private Date scheduledEndDate;
private Date scheduledEndTime;
private Date selectedDate;
private String selectedShift;
private Run selectedRun;
private Run filterRun;
private String runType;
private final int _displayWeeksBeforeCurrent = 1;
private final int _displayWeeksAfterCurrent = 1;
private Date beginningOfDisplay;
private Date endOfDisplay;
private List<Integer> displayWeeks;
private List<Date> displayDates;
private List<RunItem> selectedRunItems;
private List<RunItem> availableRunItems;
private List<SawlineRunItem> sawlineItemList;
private WorkCenter selectedWorkCenter;
private String workCenterId;
private String runItemType;
private PlywoodProduct plywoodProductFilter;
private LumberProduct lumberProductFilter;
private VeneerProduct veneerProductFilter;
// private Bundle createBundle;
private Run tmpAddRun;
private Date runDate;
private Grade addBundleGrade;
private int addBundlePieces;
private String addBundleWidth;
private Plant userPlant;
private boolean askPlant;
private List<Plant> userPlantList;
private FootageHelper footageHelper;
private Plant createPlant;
private Date runScheduleStart;
private Date runScheduleEnd;
private Shift currentShift;
private Date currentDate;
private VeneerRun tmpCreateRun;
private Date selectedRunDate;
private String backColor;
private int tmpCnt;
private Date reportStart;
private Date reportEnd;
private WorkCenter userWorkCenter;
//
private Date activeWeek;
private Shift activeShift;
private Date activeShiftDate;
private List<Run> createRunList;
private List<Date> activeDateList;
private List<RunItem> selectedRunItemsByWorkCenter;
private Date weekDate;
private RunItem editItem;
private List<Bundle> editItemList;
private Product selectedProduct;
private Product addProduct;
//
private String sessionThickness;
private Species sessionSpecies;
private Float sessionLength;
//
//
private WorkCenter sessionSource;
private Date sessionDayProduced;
private Shift sessionShift;
//
private Date reportDate;
private Map<PlywoodRun, List<SawlineRunItem>> sawLineMap;
private SawlineRunItem sawlineFilterItem;
private Date endDayProduced;
//STATIC VARIABLE;
private static final String _bundleWidth = "bundleWidth";
private static final String _bundleGrade = "bundleGrade";
private static final String _addBundles = "addBundles";
private static final String _addPieces = "addPieces";
private static final String _createRunSchedule = "createRunSchedule";
private static final String _weekOf = "Week of ";
private static final String _open = "OPEN";
private static final String _runReport = "runReport";
private static final String _runReportPlywood = "runReportPlywood";
private static final String _runReportLumber = "runReportLumber";
private static final String _bundleWidthPlywood = "bundleWidthPlywood";
private static final String _bundleGradePlywood = "bundleGradePlywood";
private static final String _editRunProduct = "editRunProduct";
private static String _sawlineReport = "sawlineReport";
private static final String _millCert = "MILL_CERT";
private static final String _shop = "SHOP";
private static final String _miscut = "MISCUT";
private static final String _onGrade = "ON_GRADE";
//
public RunController() {
}
public Run getSelected() {
if (current == null) {
current = new Run();
selectedItemIndex = -1;
}
return current;
}
private RunFacade getFacade() {
return ejbFacade;
}
private String getCurrentUser() {
Principal prin = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
return prin.getName();
}
private Date getTimestamp() {
return Calendar.getInstance().getTime();
}
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(10) {
@Override
public int getItemsCount() {
return getFacade().count();
}
@Override
public DataModel createPageDataModel() {
return new ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
}
};
}
return pagination;
}
public String prepareList() {
recreateModel();
return "RunList";
}
public String prepareView() {
current = (Run) getItems().getRowData();
selectedItemIndex = getItems().getRowIndex();
this.selectedRunItems = null;
this.availableRunItems = null;
this.selectedRunItemsByWorkCenter = null;
//current.setRunItemList(ejbRunItemFacade.findByRun(current));
return "RunView";
}
public String prepareCurrentView() {
selectedRunItems = null;
plywoodProductFilter = null;
veneerProductFilter = null;
lumberProductFilter = null;
this.selectedRunItemsByWorkCenter = null;
return "RunView";
}
public String prepareScheduleView() {
this.weekDate = new Date();
current = this.getSelectedRun();
if (getFilterRun().getRunDate() == null) {
getFilterRun().setRunDate(DateHelper.getToday());
}
this.selectedRunItems = null;
this.availableRunItems = null;
this.selectedRunItemsByWorkCenter = null;
//Need to retrieve all of the RunItems to make sure that they are populated
//current.setRunItemList(ejbRunItemFacade.findByRun(current));
return "RunView";
}
public String prepareScheduleRun() {
//Clear all search and model info
this.weekDate = new Date();
recreateModel();
initializeSearchVariables();
if (getFilterRun().getRunDate() == null) {
getFilterRun().setRunDate(DateHelper.getToday());
}
//If there is an authorized VeneerPlant, select the first in the list,
//otherwise display an error
if (!getAuthorizedPlants().isEmpty()) {
getFilterRun().setPlant(getAuthorizedPlants().get(0));
} else {
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_noAuthorizedPlants"));
return null;
}
getFilterRun().setWorkCenter(this.getFirstWorkCenterByPlant(getFilterRun().getPlant()));
return "RunSchedule";
}
public String submitScheduleRun() {
recreateModel();
return "RunSchedule";
}
public String preparePlantScheduleListing() {
return "PlantScheduleListing";
}
public String prepareCreate() {
selectedItemIndex = -1;
switch (getRunType()) {
case "P":
current = new PlywoodRun();
current.setRunType("P");
break;
case "V":
current = new VeneerRun();
current.setRunType("V");
((VeneerRun) current).setTestRun(Boolean.FALSE);
break;
case "L":
current = new LumberRun();
current.setRunType("L");
((LumberRun) current).setGradeStamped(Boolean.FALSE);
break;
}
current.setPlant(getFilterRun().getPlant());
current.setWarehouse(current.getPlant().getDefaultWarehouse());
current.setRunDate(selectedDate);
this.scheduledStartDate = selectedDate;
this.scheduledEndDate = selectedDate;
return "RunCreate";
}
public String create() {
current.setWorkCenter(this.filterRun.getWorkCenter());
current.setScheduledStart(buildDateFromDateAndTime(scheduledStartDate,
scheduledStartTime));
current.setScheduledEnd(buildDateFromDateAndTime(scheduledEndDate,
scheduledEndTime));
//Validations
try {
if (checkProductsExist(current) <= 0) {
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_invalidProductCombination"));
return null;
}
} catch (ProductTypeException pte) {
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_unknownProductTypeError"));
return null;
}
current.setLastEditedBy(getCurrentUser());
current.setLastEdited(getTimestamp());
current.setStatus("OPEN");
try {
if (current instanceof VeneerRun) {
ejbVeneerFacade.create((VeneerRun) current);
} else if (current instanceof LumberRun) {
ejbLumberFacade.create((LumberRun) current);
} else {
ejbFacade.create(current);
}
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runCreated"));
recreateModel();
return "RunSchedule";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_persistenceErrorOccured"));
JsfUtil.addErrorMessage(e.getMessage());
return null;
}
}
public String prepareEdit() {
//Set the selected run to the current selection
if (current == null) {
current = this.getSelectedRun();
}
//Need to break out the scheduled start date and time
scheduledStartTime = current.getScheduledStart();
scheduledStartDate = current.getScheduledStart();
scheduledEndTime = current.getScheduledEnd();
scheduledEndDate = current.getScheduledEnd();
return "RunEdit";
}
public String prepareRunEdit(Run run) {
//Set the selected run to the current selection
current = run;
//Need to break out the scheduled start date and time
scheduledStartTime = current.getScheduledStart();
scheduledStartDate = current.getScheduledStart();
scheduledEndTime = current.getScheduledEnd();
scheduledEndDate = current.getScheduledEnd();
this.selectedRunItems = null;
return "RunEdit";
}
public String update() {
current.setLastEditedBy(getCurrentUser());
current.setLastEdited(getTimestamp());
current.setScheduledStart(buildDateFromDateAndTime(scheduledStartDate,
scheduledStartTime));
current.setScheduledEnd(buildDateFromDateAndTime(scheduledEndDate,
scheduledEndTime));
//Validations
if (current.getScheduledStart().after(current.getScheduledEnd())) {
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_startDateAfterEndDate"));
return null;
}
//TODO This isn't working. Commented Out!
//if (ejbFacade.checkScheduledRunOverlap(current)) {
// JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_scheduleOverlap"));
// return null;
//}
//TODO NEED to
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runUpdated"));
return "RunView";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_persistenceErrorOccured"));
return null;
}
}
public String completeRun() {
//Set audit info
current.setLastEditedBy(getCurrentUser());
current.setLastEdited(getTimestamp());
current.setStatus("COMPLETE");
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runUpdated"));
return "RunSchedule";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_persistenceErrorOccured"));
return null;
}
}
public String uncompleteRun() {
//Set audit info
current.setLastEditedBy(getCurrentUser());
current.setLastEdited(getTimestamp());
current.setStatus("OPEN");
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runUpdated"));
return "RunSchedule";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_persistenceErrorOccured"));
return null;
}
}
public String destroy() {
performDestroy();
recreateModel();
return submitScheduleRun();
}
public String destroyAndView() {
performDestroy();
recreateModel();
updateCurrentItem();
if (selectedItemIndex >= 0) {
return "RunView";
} else {
// all items were removed - go back to list
recreateModel();
return "RunList";
}
}
private void performDestroy() {
try {
ejbRunItemFacade.removeByRun(current);
getFacade().remove(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runDeleted"));
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_PersistenceErrorOccured"));
}
}
private void updateCurrentItem() {
int count = getFacade().count();
if (selectedItemIndex >= count) {
// selected index cannot be bigger than number of items:
selectedItemIndex = count - 1;
// go to previous page if last page disappeared:
if (pagination.getPageFirstItem() >= count) {
pagination.previousPage();
}
}
if (selectedItemIndex >= 0) {
current = getFacade().findRange(new int[]{selectedItemIndex, selectedItemIndex + 1}).get(0);
}
}
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
private void recreateModel() {
items = null;
current = null;
scheduledStartTime = null;
scheduledEndTime = null;
scheduledStartDate = null;
scheduledEndDate = null;
selectedShift = null;
selectedDate = null;
selectedRun = null;
}
private void initializeSearchVariables() {
selectedDate = null;
scheduledStartDate = null;
scheduledEndDate = null;
scheduledStartTime = null;
scheduledEndTime = null;
selectedRun = null;
filterRun = null;
}
public String next() {
getPagination().nextPage();
recreateModel();
return "RunList";
}
public String previous() {
getPagination().previousPage();
recreateModel();
return "RunList";
}
/**
* @return the scheduledStartDate
*/
public Date getScheduledStartDate() {
return scheduledStartDate;
}
/**
* @param scheduledStartDate the scheduledStartDate to set
*/
public void setScheduledStartDate(Date scheduledStartDate) {
this.scheduledStartDate = scheduledStartDate;
}
/**
* @return the scheduledStartTime
*/
public Date getScheduledStartTime() {
if (scheduledStartTime == null && current != null && current.getShift() != null) {
scheduledStartTime = current.getShift().getScheduledStart();
}
return scheduledStartTime;
}
/**
* @param scheduledStartTime the scheduledStartTime to set
*/
public void setScheduledStartTime(Date scheduledStartTime) {
this.scheduledStartTime = scheduledStartTime;
}
/**
* @return the scheduledEndDate
*/
public Date getScheduledEndDate() {
return scheduledEndDate;
}
/**
* @param scheduledEndDate the scheduledEndDate to set
*/
public void setScheduledEndDate(Date scheduledEndDate) {
this.scheduledEndDate = scheduledEndDate;
}
/**
* @return the scheduledEndTime
*/
public Date getScheduledEndTime() {
if (scheduledEndTime == null && current != null && current.getShift() != null) {
scheduledEndTime = current.getShift().getScheduledEnd();
}
return scheduledEndTime;
}
/**
* @param scheduledEndTime the scheduledEndTime to set
*/
public void setScheduledEndTime(Date scheduledEndTime) {
this.scheduledEndTime = scheduledEndTime;
}
/**
* @return the selectedDate
*/
public Date getSelectedDate() {
if (selectedDate == null) {
selectedDate = DateHelper.getNowTimestamp();
}
return selectedDate;
}
/**
* @param selectedDate the selectedDate to set
*/
public void setSelectedDate(Date selectedDate) {
this.selectedDate = selectedDate;
}
/**
* @return the shift
*/
public String getSelectedShift() {
return selectedShift;
}
/**
* @param selectedShift
*/
public void setSelectedShift(String selectedShift) {
this.selectedShift = selectedShift;
}
/**
* @return the selectedRun
*/
public Run getSelectedRun() {
return selectedRun;
}
/**
* @param selectedRun the selectedRun to set
*/
public void setSelectedRun(Run selectedRun) {
this.selectedRun = selectedRun;
}
/**
* @return the filterRun
*/
public Run getFilterRun() {
if (filterRun == null) {
filterRun = new Run();
}
return filterRun;
}
/**
* @param filterRun the filterRun to set
*/
public void setFilterRun(Run filterRun) {
this.filterRun = filterRun;
}
/**
* @return the runType
*/
public String getRunType() {
return runType;
}
/**
* @param runType the runType to set
*/
public void setRunType(String runType) {
this.runType = runType;
}
public String goToPreviousWeek() {
Calendar cal = DateHelper.getCalendarInstance();
cal.setTime(getSelectedDate());
cal.add(Calendar.WEEK_OF_YEAR, -1);
selectedDate = cal.getTime();
displayWeeks = null;
displayDates = null;
beginningOfDisplay = null;
endOfDisplay = null;
return "RunSchedule";
}
public String goToNextWeek() {
Calendar cal = DateHelper.getCalendarInstance();
cal.setTime(getSelectedDate());
cal.add(Calendar.WEEK_OF_YEAR, 1);
selectedDate = cal.getTime();
displayWeeks = null;
displayDates = null;
beginningOfDisplay = null;
endOfDisplay = null;
return "RunSchedule";
}
public Date getBeginningOfDisplay() {
if (beginningOfDisplay == null) {
Date beginningOfWeek = DateHelper.getBeginningOfWeek(getSelectedDate());
Calendar cal = DateHelper.getCalendarInstance();
cal.setTime(beginningOfWeek);
cal.add(Calendar.WEEK_OF_YEAR, _displayWeeksBeforeCurrent * -1);
beginningOfDisplay = cal.getTime();
}
return beginningOfDisplay;
}
public Date getEndOfDisplay() {
if (endOfDisplay == null) {
Calendar cal = DateHelper.getCalendarInstance();
cal.setTime(DateHelper.getEndOfWeek(getSelectedDate()));
cal.add(Calendar.WEEK_OF_YEAR, _displayWeeksAfterCurrent);
endOfDisplay = cal.getTime();
}
return endOfDisplay;
}
public List<Date> getDisplayDates() {
if (displayDates == null) {
displayDates = new ArrayList<>();
Calendar cal = DateHelper.getCalendarInstance();
cal.setTime(getBeginningOfDisplay());
Calendar endCal = DateHelper.getCalendarInstance();
endCal.setTime(getEndOfDisplay());
while (!cal.after(endCal)) {
displayDates.add(cal.getTime());
cal.add(Calendar.DATE, 1);
}
}
return displayDates;
}
/**
* @return the displayWeeks
*/
public List<Integer> getDisplayWeeks() {
if (displayWeeks == null) {
displayWeeks = new ArrayList<>();
Calendar startCal = DateHelper.getCalendarInstance();
startCal.setTime(getBeginningOfDisplay());
Calendar endCal = DateHelper.getCalendarInstance();
endCal.setTime(getEndOfDisplay());
while (!startCal.after(endCal)) {
displayWeeks.add(startCal.get(Calendar.WEEK_OF_YEAR));
startCal.add(Calendar.WEEK_OF_YEAR, 1);
}
}
return displayWeeks;
}
public Date getDisplayDate(int week, int dayOfWeek) {
for (Date day : getDisplayDates()) {
Calendar cal = DateHelper.getCalendarInstance();
cal.setTime(day);
if (cal.get(Calendar.WEEK_OF_YEAR) == week && cal.get(Calendar.DAY_OF_WEEK) == dayOfWeek) {
return cal.getTime();
}
}
return null;
}
/**
* @param workCenter
* @return the selectedRunItems
*/
/* public List<RunItem> getRunItemsByWorkCenter(WorkCenter workCenter) {
if (selectedRunItems == null) {
if (current == null) {
selectedRunItems = new ArrayList<>();
} else {
try {
selectedRunItems = ejbFacade.buildRunItemList(current, workCenter);
} catch (RunTypeException e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_runTypeException"));
}
}
}
return selectedRunItems;
}*/
/**
* @param selectedRunItems the selectedRunItems to set
*/
public void setSelectedRunItems(List<RunItem> selectedRunItems) {
this.selectedRunItems = selectedRunItems;
}
/**
* @return the selectedWorkCenter
*/
public WorkCenter getSelectedWorkCenter() {
if (selectedWorkCenter == null) {
if (workCenterId != null) {
selectedWorkCenter = ejbWorkCenterFacade.find(workCenterId);
}
}
return selectedWorkCenter;
}
/**
* @param selectedWorkCenter the selectedWorkCenter to set
*/
public void setSelectedWorkCenter(WorkCenter selectedWorkCenter) {
this.selectedWorkCenter = selectedWorkCenter;
}
/**
* @return the workCenterId
*/
public String getWorkCenterId() {
return workCenterId;
}
/**
* @param workCenterId the workCenterId to set
*/
public void setWorkCenterId(String workCenterId) {
this.workCenterId = workCenterId;
}
/**
* @return the runItemType
*/
public String getRunItemType() {
return runItemType;
}
/**
* @param runItemType the runItemType to set
*/
public void setRunItemType(String runItemType) {
this.runItemType = runItemType;
}
/**
* @return the sawlineItemList
*/
public List<SawlineRunItem> getSawlineItemList() {
if (sawlineItemList == null) {
sawlineItemList = new ArrayList<>();
}
return sawlineItemList;
}
/**
* @param sawlineItemList the sawlineItemList to set
*/
public void setSawlineItemList(List<SawlineRunItem> sawlineItemList) {
this.sawlineItemList = sawlineItemList;
}
/**
* @return the plywoodProductFilter
*/
public PlywoodProduct getPlywoodProductFilter() {
if (plywoodProductFilter == null) {
plywoodProductFilter = new PlywoodProduct();
}
return plywoodProductFilter;
}
/**
* @param plywoodProductFilter the plywoodProductFilter to set
*/
public void setPlywoodProductFilter(PlywoodProduct plywoodProductFilter) {
this.plywoodProductFilter = plywoodProductFilter;
}
/**
* @return the lumberProductFilter
*/
public LumberProduct getLumberProductFilter() {
if (lumberProductFilter == null) {
lumberProductFilter = new LumberProduct();
}
return lumberProductFilter;
}
/**
* @param lumberProductFilter the lumberProductFilter to set
*/
public void setLumberProductFilter(LumberProduct lumberProductFilter) {
this.lumberProductFilter = lumberProductFilter;
}
/**
* @return the veneerProductFilter
*/
public VeneerProduct getVeneerProductFilter() {
if (veneerProductFilter == null) {
veneerProductFilter = new VeneerProduct();
}
return veneerProductFilter;
}
/**
* @param veneerProductFilter the veneerProductFilter to set
*/
public void setVeneerProductFilter(VeneerProduct veneerProductFilter) {
this.veneerProductFilter = veneerProductFilter;
}
/**
* @return the reportStart
*/
public Date getRunDate() {
if (this.runDate == null) {
this.runDate = new Date();
}
return runDate;
}
/**
* @param reportStart the reportStart to set
*/
public void setRunDate(Date runDate) {
this.runDate = runDate;
}
/**
* @return the addBundleGrade
*/
public Grade getAddBundleGrade() {
return addBundleGrade;
}
/**
* @param addBundleGrade the addBundleGrade to set
*/
public void setAddBundleGrade(Grade addBundleGrade) {
this.addBundleGrade = addBundleGrade;
}
/**
* @return the addBundlePieces
*/
public int getAddBundlePieces() {
return addBundlePieces;
}
/**
* @param addBundlePieces the addBundlePieces to set
*/
public void setAddBundlePieces(int addBundlePieces) {
this.addBundlePieces = addBundlePieces;
}
/**
* @return the tmpAddRun
*/
public Run getTmpAddRun() {
return tmpAddRun;
}
/**
* @param tmpAddRun the tmpAddRun to set
*/
public void setTmpAddRun(Run tmpAddRun) {
this.tmpAddRun = tmpAddRun;
}
/**
* @return the addBundleWidth
*/
public String getAddBundleWidth() {
return addBundleWidth;
}
/**
* @param addBundleWidth the addBundleWidth to set
*/
public void setAddBundleWidth(String addBundleWidth) {
this.addBundleWidth = addBundleWidth;
}
/**
* @return the userPlant
*/
public Plant getUserPlant() {
return userPlant;
}
/**
* @param userPlant the userPlant to set
*/
public void setUserPlant(Plant userPlant) {
this.userPlant = userPlant;
}
/**
* @return the askPlant
*/
public boolean isAskPlant() {
return askPlant;
}
/**
* @param askPlant the askPlant to set
*/
public void setAskPlant(boolean askPlant) {
this.askPlant = askPlant;
}
/**
* @return the userPlantList
*/
public List<Plant> getUserPlantList() {
return userPlantList;
}
/**
* @param userPlantList the userPlantList to set
*/
public void setUserPlantList(List<Plant> userPlantList) {
this.userPlantList = userPlantList;
}
/**
* @return the footageHelper
*/
public FootageHelper getFootageHelper() {
return footageHelper;
}
/**
* @param footageHelper the footageHelper to set
*/
public void setFootageHelper(FootageHelper footageHelper) {
this.footageHelper = footageHelper;
}
/**
* @return the createPlant
*/
public Plant getCreatePlant() {
return createPlant;
}
/**
* @param createPlant the createPlant to set
*/
public void setCreatePlant(Plant createPlant) {
this.createPlant = createPlant;
}
/**
* @return the runScheduleStart
*/
public Date getRunScheduleStart() {
return runScheduleStart;
}
/**
* @param runScheduleStart the runScheduleStart to set
*/
public void setRunScheduleStart(Date runScheduleStart) {
this.runScheduleStart = runScheduleStart;
}
/**
* @return the runScheduleEnd
*/
public Date getRunScheduleEnd() {
return runScheduleEnd;
}
/**
* @param runScheduleEnd the runScheduleEnd to set
*/
public void setRunScheduleEnd(Date runScheduleEnd) {
this.runScheduleEnd = runScheduleEnd;
}
/**
* @return the currentShift
*/
public Shift getCurrentShift() {
if (currentShift == null) {
currentShift = new Shift();
}
return currentShift;
}
/**
* @param currentShift the currentShift to set
*/
public void setCurrentShift(Shift currentShift) {
this.currentShift = currentShift;
}
/**
* @return the currentDate
*/
public Date getCurrentDate() {
return currentDate;
}
/**
* @param currentDate the currentDate to set
*/
public void setCurrentDate(Date currentDate) {
this.currentDate = currentDate;
}
/**
* @return the tmpCreateRun
*/
public VeneerRun getTmpCreateRun() {
if (tmpCreateRun == null) {
tmpCreateRun = new VeneerRun();
}
return tmpCreateRun;
}
/**
* @param tmpCreateRun the tmpCreateRun to set
*/
public void setTmpCreateRun(VeneerRun tmpCreateRun) {
this.tmpCreateRun = tmpCreateRun;
}
/**
* @return the selectedRunDate
*/
public Date getSelectedRunDate() {
return selectedRunDate;
}
/**
* @param selectedRunDate the selectedRunDate to set
*/
public void setSelectedRunDate(Date selectedRunDate) {
this.selectedRunDate = selectedRunDate;
}
/**
* @return the backColor
*/
public String getBackColor() {
return backColor;
}
/**
* @param backColor the backColor to set
*/
public void setBackColor(String backColor) {
this.backColor = backColor;
}
/**
* @return the tmpCnt
*/
public int getTmpCnt() {
return tmpCnt;
}
/**
* @param tmpCnt the tmpCnt to set
*/
public void setTmpCnt(int tmpCnt) {
this.tmpCnt = tmpCnt;
}
/**
* @return the activeWeek
*/
public Date getActiveWeek() {
return activeWeek;
}
/**
* @param activeWeek the activeWeek to set
*/
public void setActiveWeek(Date activeWeek) {
this.activeWeek = activeWeek;
}
/**
* @return the activeShift
*/
public Shift getActiveShift() {
return activeShift;
}
/**
* @param activeShift the activeShift to set
*/
public void setActiveShift(Shift activeShift) {
this.activeShift = activeShift;
}
public void setActiveShiftAndDate(Shift shift, Date day) {
this.activeShift = shift;
this.activeShiftDate = day;
}
/**
* @return the getActiveShiftDate
*/
public Date getActiveShiftDate() {
return activeShiftDate;
}
/**
* @param getActiveShiftDate the getActiveShiftDate to set
*/
public void setActiveShiftDate(Date getActiveShiftDate) {
this.activeShiftDate = getActiveShiftDate;
}
/**
* @return the createRunList
*/
public List<Run> getCreateRunList() {
if (createRunList == null) {
Run r = new Run();
r.setRunType(this.runType);
createRunList = ejbFacade.findRunsByFilter(r,
this.getRunReportWeekStarts().get(0),
this.getRunReportWeekStarts().get(2),
null, null, null);
}
return createRunList;
}
public List<Run> getFromRunList(Shift shift, Date date, WorkCenter work) {
List<Run> tmpList = new ArrayList();
for (Run r : this.getCreateRunList()) {
if (r.getShift().equals(shift)) {
if (DateHelper.sameDay(date, r.getRunDate())) {
if (r.getWorkCenter() != null && r.getWorkCenter().equals(work)) {
tmpList.add(r);
}
}
}
}
return tmpList;
}
/**
* @param createRunList the createRunList to set
*/
public void setCreateRunList(List<Run> createRunList) {
this.createRunList = createRunList;
}
/**
* @return the activeDateList
*/
public List<Date> getActiveDateList() {
if (activeDateList == null) {
activeDateList = new ArrayList();
}
return activeDateList;
}
/**
* @param activeDateList the activeDateList to set
*/
public void setActiveDateList(List<Date> activeDateList) {
this.activeDateList = activeDateList;
}
public boolean runReadyForWidth(Run run) {
System.out.println("here");
if (run.getProductThickness() != null) {
System.out.println("thick");
if (run.getProductLength() != null) {
System.out.println("length");
// if (run.getSpecies() != null) {
// System.out.println("specie");
return true;
//}
}
}
return false;
}
/**
* @return the selectedRunItemsByWorkCenter
*/
public List<RunItem> getSelectedRunItemsByWorkCenter() {
if (this.selectedRunItemsByWorkCenter == null) {
this.selectedRunItemsByWorkCenter = this.getItemsByRunAndWorkCenter(getSelected(), getSelected().getWorkCenter());
}
return selectedRunItemsByWorkCenter;
}
public String removeFromSelectedRunList(RunItem i) {
List<RunItem> tmpList = new ArrayList();
for (RunItem item : this.selectedRunItemsByWorkCenter) {
if (item.equals(i)) {
} else {
tmpList.add(item);
}
}
this.setSelectedRunItemsByWorkCenter(tmpList);
return "";
}
/**
* @param selectedRunItemsByWorkCenter the selectedRunItemsByWorkCenter to
* set
*/
public void setSelectedRunItemsByWorkCenter(List<RunItem> selectedRunItemsByWorkCenter) {
this.selectedRunItemsByWorkCenter = selectedRunItemsByWorkCenter;
}
/**
* @return the weekDate
*/
public Date getWeekDate() {
return weekDate;
}
/**
* @param weekDate the weekDate to set
*/
public void setWeekDate(Date weekDate) {
this.weekDate = weekDate;
}
/**
* @return the reportStart
*/
public Date getReportStart() {
return reportStart;
}
/**
* @param reportStart the reportStart to set
*/
public void setReportStart(Date reportStart) {
this.reportStart = reportStart;
}
/**
* @return the reportEnd
*/
public Date getReportEnd() {
return reportEnd;
}
/**
* @param reportEnd the reportEnd to set
*/
public void setReportEnd(Date reportEnd) {
this.reportEnd = reportEnd;
}
/**
* @return the userWorkCenter
*/
public WorkCenter getUserWorkCenter() {
return userWorkCenter;
}
/**
* @param userWorkCenter the userWorkCenter to set
*/
public void setUserWorkCenter(WorkCenter userWorkCenter) {
this.userWorkCenter = userWorkCenter;
}
/**
* @return the editItem
*/
public RunItem getEditItem() {
return editItem;
}
/**
* @param editItem the editItem to set
*/
public void setEditItem(RunItem editItem) {
this.editItem = editItem;
}
/**
* @return the editItemList
*/
public List<Bundle> getEditItemList() {
if (editItemList == null) {
editItemList = new ArrayList();
}
return editItemList;
}
/**
* @param editItemList the editItemList to set
*/
public void setEditItemList(List<Bundle> editItemList) {
this.editItemList = editItemList;
}
/**
* @return the selectedProduct
*/
public Product getSelectedProduct() {
if (selectedProduct == null) {
selectedProduct = new Product();
}
return selectedProduct;
}
/**
* @param selectedProduct the selectedProduct to set
*/
public void setSelectedProduct(Product selectedProduct) {
this.selectedProduct = selectedProduct;
}
/**
* @return the addProduct
*/
public Product getAddProduct() {
return addProduct;
}
/**
* @param addProduct the addProduct to set
*/
public void setAddProduct(Product addProduct) {
this.addProduct = addProduct;
}
/**
* @return the sessionSpecies
*/
public Species getSessionSpecies() {
return sessionSpecies;
}
/**
* @param sessionSpecies the sessionSpecies to set
*/
public void setSessionSpecies(Species sessionSpecies) {
this.sessionSpecies = sessionSpecies;
}
/**
* @return the sessionLength
*/
public Float getSessionLength() {
return sessionLength;
}
/**
* @param sessionLength the sessionLength to set
*/
public void setSessionLength(Float sessionLength) {
this.sessionLength = sessionLength;
}
/**
* @return the sessionThickness
*/
public String getSessionThickness() {
return sessionThickness;
}
/**
* @param sessionThickness the sessionThickness to set
*/
public void setSessionThickness(String sessionThickness) {
this.sessionThickness = sessionThickness;
}
/**
* @return the sessionSource
*/
public WorkCenter getSessionSource() {
return sessionSource;
}
/**
* @param sessionSource the sessionSource to set
*/
public void setSessionSource(WorkCenter sessionSource) {
this.sessionSource = sessionSource;
}
/**
* @return the sessionDayProduced
*/
public Date getSessionDayProduced() {
return sessionDayProduced;
}
/**
* @param sessionDayProduced the sessionDayProduced to set
*/
public void setSessionDayProduced(Date sessionDayProduced) {
this.sessionDayProduced = sessionDayProduced;
}
/**
* @return the sessionShift
*/
public Shift getSessionShift() {
return sessionShift;
}
/**
* @param sessionShift the sessionShift to set
*/
public void setSessionShift(Shift sessionShift) {
this.sessionShift = sessionShift;
}
/**
* @return the reportDate
*/
public Date getReportDate() {
return reportDate;
}
/**
* @param reportDate the reportDate to set
*/
public void setReportDate(Date reportDate) {
this.reportDate = reportDate;
}
/**
* @return the sawLineMap
*/
public Map<PlywoodRun, List<SawlineRunItem>> getSawLineMap() {
return sawLineMap;
}
/**
* @param sawLineMap the sawLineMap to set
*/
public void setSawLineMap(Map<PlywoodRun, List<SawlineRunItem>> sawLineMap) {
this.sawLineMap = sawLineMap;
}
/**
* @return the sawlineFilterItem
*/
public SawlineRunItem getSawlineFilterItem() {
if (sawlineFilterItem == null) {
sawlineFilterItem = new SawlineRunItem();
}
return sawlineFilterItem;
}
/**
* @param sawlineFilterItem the sawlineFilterItem to set
*/
public void setSawlineFilterItem(SawlineRunItem sawlineFilterItem) {
this.sawlineFilterItem = sawlineFilterItem;
}
/**
* @return the endDayProduced
*/
public Date getEndDayProduced() {
return endDayProduced;
}
/**
* @param endDayProduced the endDayProduced to set
*/
public void setEndDayProduced(Date endDayProduced) {
this.endDayProduced = endDayProduced;
}
/**
* @return the editItemList
*/
/**
* @return the tmpCreateRunSpecies
*/
@FacesConverter(forClass = Run.class)
@RequestScoped
public static class RunControllerConverter implements Converter {
@EJB
private erp.production.common.entities.RunFacade ejbFacade;
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
return ejbFacade.find(getKey(value));
}
java.lang.Long getKey(String value) {
java.lang.Long key;
key = Long.valueOf(value);
return key;
}
String getStringKey(java.lang.Long value) {
StringBuilder sb = new StringBuilder();
sb.append(value);
return sb.toString();
}
@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof Run) {
Run o = (Run) object;
return getStringKey(o.getRunId());
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + RunController.class.getName());
}
}
}
public String prepareComplete() {
//Validation for run items entered. Only want to do this for Veneer and
//Lumber. There is a chance that the dryers run a shift when layup or spreader
//do not.
if (current instanceof PlywoodRun) {
((PlywoodRun) current).setDryersRan(Boolean.FALSE);
}
List<RunItem> checkItems = ejbRunItemFacade.findByRun(current);
if (checkItems == null || checkItems.isEmpty() && !current.getRunType().equals("P")) {
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_runItemsRequired"));
return null;
}
return "RunComplete";
}
public List<Run> getRunsByDateAndShift(Date runDate, Shift shift) {
Run filter = new Run();
filter.setPlant(getFilterRun().getPlant());
filter.setRunDate(runDate);
filter.setShift(shift);
return ejbFacade.findRunsByFilter(filter,
null,
null,
null,
null,
null);
}
public List<Run> getRunsByDate(Date runDate) {
Run filter = new Run();
filter.setPlant(getFilterRun().getPlant());
filter.setRunDate(runDate);
filter.setStatus(filterRun.getStatus());
List<Run> runs = ejbFacade.findRunsByFilter(filter,
null,
null,
null,
null,
null);
Collections.sort(runs, new RunComparator());
return runs;
}
public List<Run> getRunsByDateAndWorkCenter(Date runDate, WorkCenter workcenter) {
Run filter = new Run();
filter.setPlant(getFilterRun().getPlant());
filter.setRunDate(runDate);
filter.setStatus(filterRun.getStatus());
filter.setWorkCenter(workcenter);
List<Run> runs = ejbFacade.findRunsByFilter(filter,
null,
null,
null,
null,
null);
Collections.sort(runs, new RunComparator());
return runs;
}
public long getRunCountByDateAndShift(Date runDate, Shift shift) {
Run filter = new Run();
filter.setShift(shift);
filter.setRunDate(runDate);
filter.setPlant(filterRun.getPlant());
return ejbFacade.findCountFilter(filter, null, null);
}
public long getRunCountByDate(Date runDate) {
Run filter = new Run();
filter.setRunDate(runDate);
filter.setPlant(filterRun.getPlant());
return ejbFacade.findCountFilter(filter, null, null);
}
public List<Shift> getDistinctShiftsByDateAndPlant(Date currentDate) {
Run filter = new Run();
filter.setRunDate(currentDate);
filter.setPlant(getFilterRun().getPlant());
filter.setStatus(getFilterRun().getStatus());
return ejbFacade.findDistinctShiftsByFilter(filter, null, null);
}
public List<Shift> getDistinctShiftsByPlant() {
Plant plant = getFilterRun().getPlant();
return ejbFacade.findDistinctShiftsByPlant(plant);
}
public List<Shift> getDistinctShiftsByPlantAndWorkCenter(Plant plant, WorkCenter workcenter) {
return ejbFacade.findDistinctShiftsByPlantAndWorkCenter(plant, workcenter);
}
public List<Shift> getDistinctRunShiftsByPlantAndWorkCenter(Plant plant, WorkCenter work, Date date) {
List<Shift> tmpShift = ejbFacade.findDistinctShiftsByPlantAndWorkCenter(plant, work);
List<Shift> tmpList = new ArrayList();
for (Shift shift : tmpShift) {
if (this.hasRunsForDateShiftAndWorkCenter(date, shift, work)) {
tmpList.add(shift);
}
}
return tmpList;
}
public List<Shift> getRunShiftsByDatePlantAndWorkCenter(Date date, Plant plant, WorkCenter workCenter) {
List<Shift> shiftList = ejbFacade.getRunShiftsByDatePlantAndWorkCenter(date, plant, workCenter);
return shiftList;
}
/**
* @return the authorizedPlants
*/
private List<Plant> getAuthorizedPlants() {
return ejbUserFacade.findAuthorizedPlants(getCurrentUser(), runType);
}
private Date buildDateFromDateAndTime(Date dateField, Date timeField) {
Calendar tmpDate = Calendar.getInstance();
tmpDate.set(DateHelper.getFieldFromDate(dateField, Calendar.YEAR),
DateHelper.getFieldFromDate(dateField, Calendar.MONTH),
DateHelper.getFieldFromDate(dateField, Calendar.DATE),
DateHelper.getFieldFromDate(timeField, Calendar.HOUR_OF_DAY),
DateHelper.getFieldFromDate(timeField, Calendar.MINUTE),
DateHelper.getFieldFromDate(timeField, Calendar.SECOND));
return tmpDate.getTime();
}
private int checkProductsExist(Run run) throws ProductTypeException {
if (run instanceof VeneerRun) {
VeneerRun localRun = (VeneerRun) run;
VeneerProduct venProd = new VeneerProduct();
venProd.setStatus("ACTIVE");
venProd.setPlant(localRun.getPlant());
venProd.setProductLength(localRun.getProductLength());
venProd.setThickness(localRun.getProductThickness());
venProd.setSpecies(localRun.getSpecies());
return ejbVeneerProductFacade.getFilterCount(venProd);
} else if (run instanceof LumberRun) {
LumberRun localRun = (LumberRun) run;
LumberProduct lumProd = new LumberProduct();
lumProd.setStatus("ACTIVE");
lumProd.setPlant(localRun.getPlant());
lumProd.setProductWidth(localRun.getProductWidth());
lumProd.setProductLength(localRun.getProductLength());
lumProd.setThickness(localRun.getProductThickness());
lumProd.setSpecies(localRun.getSpecies());
return ejbLumberProductFacade.getFilterCount(lumProd);
} else if (run instanceof PlywoodRun) {
//We aren't entering products for a plywood run since they
//have multiple production centers.
return 1;
} else {
throw new ProductTypeException();
}
}
public List<RunItem> getItemsByRunAndWorkCenter(Run run, WorkCenter workCenter) {
return ejbRunItemFacade.findByRunAndWorkCenter(run, workCenter);
}
public long getPieceCountByRunAndWorkCenter(Run run, WorkCenter workCenter) {
return ejbRunItemFacade.findPieceCountByRunAndWorkCenter(run, workCenter);
}
public long getPieceCountByRunAndWorkCenterList() {
long tmpCnt = 0;
if (this.selectedRunItemsByWorkCenter == null) {
return (long) 0;
} else {
for (RunItem item : this.selectedRunItemsByWorkCenter) {
tmpCnt += item.getPieceCount();
}
}
return tmpCnt;
}
public long getSurfaceByRunAndWorkCenter(Run run, WorkCenter workCenter) {
//System.out.println("WorkCenter=" + workCenter.getCenterId() + ", has a runType of=" + run.getRunType());
switch (run.getRunType()) {
case "P":
if (workCenter.getIsSawline()) {
return ejbSawlineRunItemFacade.findSurfaceByRunAndWorkCenter(run, workCenter);
}
return ejbPlywoodRunItemFacade.findSurfaceByRunAndWorkCenter(run, workCenter);
case "V":
return ejbVeneerRunItemFacade.findSurfaceByRunAndWorkCenter(run, workCenter);
default:
return 0;
}
}
public long getCorelineByRunAndWorkCenter(Run run, WorkCenter workCenter) {
switch (run.getRunType()) {
case "P":
if (workCenter.getIsSawline()) {
return ejbSawlineRunItemFacade.findCorelineByRunAndWorkCenter(run, workCenter);
}
return ejbPlywoodRunItemFacade.findCorelineByRunAndWorkCenter(run, workCenter);
default:
return 0;
}
}
public long getFootageByRunAndWorkCenter(Run run, WorkCenter workCenter) {
return ejbRunItemFacade.findFootageByRunAndWorkCenter(run, workCenter);
}
public long getFootageByRunAndWorkCenterList() {
long tmpFootage = 0;
if (this.selectedRunItemsByWorkCenter == null) {
return (long) 0;
} else {
for (RunItem items : this.selectedRunItemsByWorkCenter) {
tmpFootage += items.getFootage();
}
}
return tmpFootage;
}
public long getSurfaceByRunAndWorkCenterList() {
List<VeneerRunItem> tmpList = new ArrayList();
List<LumberRunItem> tmpList1 = new ArrayList();
List<PlywoodRunItem> tmpList2 = new ArrayList();
List<SawlineRunItem> tmpList3 = new ArrayList();
boolean saw = false;
long tmpFootage = 0;
if (this.selectedRunItemsByWorkCenter == null) {
return (long) 0;
} else {
for (RunItem items : this.selectedRunItemsByWorkCenter) {
switch (this.runType) {
case "V":
tmpList.add((VeneerRunItem) items);
break;
case "L":
tmpList1.add((LumberRunItem) items);
break;
case "P":
if (items.getRun().getWorkCenter().getIsSawline()) {
tmpList3.add((SawlineRunItem) items);
saw = true;
} else {
tmpList2.add((PlywoodRunItem) items);
}
break;
}
}
switch (this.runType) {
case "V":
for (VeneerRunItem tmp : tmpList) {
tmpFootage += tmp.getSurface();
}
break;
case "L":
for (LumberRunItem tmp : tmpList1) {
tmpFootage += 0;
}
break;
case "P":
if (saw) {
for (SawlineRunItem tmp : tmpList3) {
tmpFootage += tmp.getSurface();
}
}
for (PlywoodRunItem tmp : tmpList2) {
tmpFootage += tmp.getSurface();
}
break;
}
}
return tmpFootage;
}
public SelectItem[] getRunsByPlantAndStatus(Plant plant, String status) {
Run filter = new Run();
filter.setStatus("OPEN");
filter.setPlant(plant);
List<Run> runs = ejbFacade.findRunsByFilter(filter, null, null, null, null, null);
Collections.sort(runs, new RunComparator());
int size = runs.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Run x : runs) {
String selectDescription = x.getDescriptionWithDate();
selects[i++] = new SelectItem(x, selectDescription);
}
return selects;
}
public SelectItem[] getRunsByDatePlantAndStatus(Date reportStart, Plant plant, String status) {
Run filter = new Run();
filter.setStatus(status);
filter.setPlant(plant);
Date reportEnd = DateHelper.setEndOfDayTime(reportStart);
reportStart = DateHelper.setBeginningOfDayTime(reportStart);
List<Run> runs = ejbFacade.findRunsByFilter(filter, reportStart, reportEnd, null, null, null);
Collections.sort(runs, new RunComparator());
int size = runs.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Run x : runs) {
String selectDescription = x.getDescriptionWithDate();
selects[i++] = new SelectItem(x, selectDescription);
}
return selects;
}
public SelectItem[] getOpenRunsForPlant4ByDate() {
Date reportDate = this.runDate;
Plant plant = plantFacade.find("P4");
String status = "";
return getRunsByDatePlantAndStatus(reportDate, plant, status);
}
public boolean getWorkCenterProductionEntered(Run run, WorkCenter workCenter) {
List<RunItem> runItems = ejbRunItemFacade.findByRunAndWorkCenter(run, workCenter);
return runItems != null && !runItems.isEmpty();
}
/**
* @return the availableRunItems
*/
/* public List<RunItem> getAvailableRunItems() {
availableRunItems = new ArrayList<>();
if (this.getSelectedRun() != null) {
getProductFilter().setPlant(this.getSelectedRun().getPlant());
if (getProductFilter().getThickness() == null) {
getProductFilter().setThickness(current.getProductThickness());
}
//TODO Need to make this limit by product width, which is really only for lumber
List<Product> products = ejbProductFacade.findRangeByFilter(getProductFilter(),
0,
0,
null,
null);
for (Product product : products) {
RunItem item = new RunItem();
switch (this.getSelectedRun().getRunType()) {
case "P":
if (this.getSelectedWorkCenter().getIsSawline()) {
item = new SawlineRunItem(current, this.getSelectedWorkCenter(), product);
} else {
item = new PlywoodRunItem(current, this.getSelectedWorkCenter(), product);
}
break;
case "V":
item = new VeneerRunItem(current, this.getSelectedWorkCenter(), product);
break;
case "L":
item = new LumberRunItem(current, this.getSelectedWorkCenter(), product);
break;
}
item.setProduct(product);
item.setRun(this.selectedRun);
if (isInSelectedList(item) == false) {
availableRunItems.add(item);
}
}
}
Collections.sort(availableRunItems, new RunItemComparator());
return availableRunItems;
}
*/
/*
private boolean isInSelectedList(RunItem runItem) {
//need to increment thorugh the selected list and see if the same
//product is in there
boolean flag = false;
for (RunItem item : getSelectedRunItems()) {
if (item.getProduct().equals(runItem.getProduct())) {
flag = true;
}
}
return flag;
}
*/
/*
public void selectRunItem(RunItem runItem) {
getAvailableRunItems().remove(runItem);
switch (this.getRunType()) {
case "P":
if (this.getSelectedWorkCenter().getIsSawline()) {
SawlineRunItem sawlineItem = (SawlineRunItem) runItem;
getSelectedRunItems().add(sawlineItem);
} else {
PlywoodRunItem plywoodItem = (PlywoodRunItem) runItem;
getSelectedRunItems().add(plywoodItem);
}
break;
case "V":
VeneerRunItem veneerItem = (VeneerRunItem) runItem;
getSelectedRunItems().add(veneerItem);
break;
case "L":
LumberRunItem lumberItem = (LumberRunItem) runItem;
getSelectedRunItems().add(lumberItem);
break;
case "S":
SawlineRunItem sawItem = (SawlineRunItem) runItem;
getSelectedRunItems().add(sawItem);
break;
}
}
*/
/*
public void removeRunItem(RunItem runItem) {
List<RunItem> newItemList = new ArrayList<>();
for (RunItem item : getSelectedRunItems()) {
if (!itemMatches(item, runItem)) {
newItemList.add(item);
}
}
selectedRunItems = newItemList;
}
*/
/*
private boolean itemMatches(RunItem item1, RunItem item2) {
return item1.getRun().equals(item2.getRun())
&& item1.getWorkCenter().equals(item2.getWorkCenter())
&& item1.getProduct().equals(item2.getProduct());
}
*/
/**
* @param availableRunItems
*/
/* public void setAvailableRunItems(List<RunItem> availableRunItems) {
this.availableRunItems = availableRunItems;
}
*/
/**
* @return the selectedOrderItems
*/
public List<RunItem> getSelectedRunItems() {
if (selectedRunItems == null) {
selectedRunItems = new ArrayList<>();
}
return selectedRunItems;
}
public String updateWithRunItems() {
current.setLastEdited(getTimestamp());
current.setLastEditedBy(getCurrentUser());
try {
switch (current.getRunType()) {
case "P":
ejbPlywoodFacade.updateCurrentAndRunItems(current, current.getWorkCenter(), getSelectedRunItems());
break;
case "L":
ejbLumberFacade.updateCurrentAndRunItems(current, current.getWorkCenter(), getSelectedRunItems());
break;
case "V":
ejbVeneerFacade.updateCurrentAndRunItems(current, current.getWorkCenter(), getSelectedRunItems());
break;
}
this.selectedRunItemsByWorkCenter = this.selectedRunItems;
availableRunItems = null;
selectedRunItems = null;
setSawlineItemList(null);
plywoodProductFilter = null;
veneerProductFilter = null;
lumberProductFilter = null;
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runItemsCreated"));
return prepareCurrentView();
} catch (RunItemsRequiredException e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_runItemsRequired"));
return null;
}
}
public String updateWithSawlineRunItems() {
current.setLastEdited(getTimestamp());
current.setLastEditedBy(getCurrentUser());
try {
switch (current.getRunType()) {
case "P":
ejbPlywoodFacade.updateCurrentAndSawlineRunItems(current, getSelectedWorkCenter(), getSawlineItemList());
break;
default:
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_runTypeException"));
break;
}
availableRunItems = null;
selectedRunItems = null;
setSawlineItemList(null);
plywoodProductFilter = null;
veneerProductFilter = null;
lumberProductFilter = null;
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/messages").getString("Message_runItemsCreated"));
return prepareCurrentView();
} catch (RunItemsRequiredException e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/messages").getString("Message_runItemsRequired"));
return null;
}
}
public String prepareSawlineCreateMany() {
selectedItemIndex = -1;
return "SawlineRunItemCreateMany";
}
public String prepareCreateMany(Run run) {
if (!getEditItemList().isEmpty()) {
for (Bundle b : getEditItemList()) {
bundleFacade.edit(b);
}
editItemList = null;
editItem = null;
}
current = run;
selectedRunItems = null;
selectedRunItemsByWorkCenter = null;
if (current.getStatus().equals("COMPLETE")) {
return "RunView";
}
this.selectedWorkCenter = run.getWorkCenter();
if (selectedWorkCenter.getIsSawline()) {
//setSawlineItemList(ejbSawlineRunItemFacade.findByRunAndWorkCenter(current, selectedWorkCenter));
setSawlineItemList(sawLineBundleFacade.getSawlineBundlesFromRun(current));
if (getSawlineItemList().size() < _sawlineItemDisplayRows) {
for (int i = getSawlineItemList().size(); i < _sawlineItemDisplayRows; i++) {
getSawlineItemList().add(new SawlineRunItem(current, selectedWorkCenter));
}
}
return "SawlineRunItemCreateMany";
} else {
selectedRunItems = null;
selectedRunItems = getRunItemsFromBundleForRun(current);
//Set the product Filter to the run info.
defaultProductFilterInfo();
selectedItemIndex = -1;
return "RunItemCreateMany";
}
}
private void setWorkCenter(List<RunItem> items) {
WorkCenter center = this.selectedWorkCenter;
for (RunItem item : items) {
item.setWorkCenter(center);
}
}
public List<RunItem> getRunItemsFromBundleForRun(Run run) {
return bundleFacade.getRunItemsFromBundleForRun(run);
}
public long getBundleCountByRunAndProduct(Run run, Product prod) {
long count = bundleFacade.getCountByRunAndProduct(run, prod);
return count;
}
private void defaultProductFilterInfo() {
if (current.getRunType().equals("V")) {
getVeneerProductFilter().setThickness(current.getProductThickness());
getVeneerProductFilter().setSpecies(((VeneerRun) current).getSpecies());
getVeneerProductFilter().setProductLength(current.getProductLength());
} else if (current.getRunType().equals("L")) {
getLumberProductFilter().setThickness(current.getProductThickness());
getLumberProductFilter().setProductWidth(((LumberRun) current).getProductWidth());
getLumberProductFilter().setProductLength(current.getProductLength());
getLumberProductFilter().setSpecies(((LumberRun) current).getSpecies());
}
}
/**
* @return the availableRunItems
*/
public List<RunItem> getAvailableRunItems() {
availableRunItems = null;
switch (this.runType) {
case "P":
getPlywoodProductFilter().setPlant(current.getPlant());
getPlywoodProductFilter().setStatus("ACTIVE");
//TODO
//getPlywoodProductFilter().setProductLength(current.getProductLength());
//getPlywoodProductFilter().setThickness(current.getProductThickness());
List<PlywoodProduct> plyProducts = ejbPlywoodProductFacade.findProductsByFilter(getPlywoodProductFilter());
buildRunItemListFromPlywoodProducts(plyProducts, getSelectedRunItems());
break;
case "L":
getLumberProductFilter().setPlant(current.getPlant());
getLumberProductFilter().setStatus("ACTIVE");
getLumberProductFilter().setProductLength(current.getProductLength());
getLumberProductFilter().setThickness(current.getProductThickness());
getLumberProductFilter().setSpecies(((LumberRun) current).getSpecies());
List<LumberProduct> lumProducts = ejbLumberProductFacade.findProductsByFilter(getLumberProductFilter());
buildRunItemListFromLumberProducts(lumProducts, getSelectedRunItems());
break;
case "V":
getVeneerProductFilter().setPlant(current.getPlant());
getVeneerProductFilter().setStatus("ACTIVE");
//getVeneerProductFilter().setProductLength(current.getProductLength());
//getVeneerProductFilter().setThickness(current.getProductThickness());
//getVeneerProductFilter().setSpecies(((VeneerRun) current).getSpecies());
List<VeneerProduct> venProducts = ejbVeneerProductFacade.findProductsByFilter(getVeneerProductFilter(), Boolean.TRUE);
buildRunItemListFromVeneerProducts(venProducts, getSelectedRunItems());
break;
}
//Collections.sort(availableRunItems, new RunItemComparator());
return availableRunItems;
}
private void buildRunItemListFromPlywoodProducts(List<PlywoodProduct> productList, List<RunItem> selectedList) {
availableRunItems = new ArrayList<>();
for (PlywoodProduct prod : productList) {
boolean isInSelected = false;
for (RunItem sel : selectedList) {
if (sel.getProduct().equals(prod)) {
isInSelected = true;
}
}
if (!isInSelected) {
PlywoodRunItem newItem = new PlywoodRunItem();
newItem.setProduct(prod);
newItem.setWorkCenter(selectedWorkCenter);
newItem.setRun(current);
newItem.setItemType("P");
availableRunItems.add(newItem);
}
}
}
private void buildRunItemListFromVeneerProducts(List<VeneerProduct> productList, List<RunItem> selectedList) {
availableRunItems = new ArrayList<>();
for (VeneerProduct prod : productList) {
boolean isInSelected = false;
for (RunItem sel : selectedList) {
if (sel.getProduct().equals(prod)) {
isInSelected = true;
}
}
if (!isInSelected) {
VeneerRunItem newItem = new VeneerRunItem();
newItem.setProduct(prod);
newItem.setItemType("V");
newItem.setRun(current);
newItem.setWorkCenter(selectedWorkCenter);
availableRunItems.add(newItem);
}
}
}
private void buildRunItemListFromLumberProducts(List<LumberProduct> productList, List<RunItem> selectedList) {
availableRunItems = new ArrayList<>();
for (LumberProduct prod : productList) {
boolean isInSelected = false;
for (RunItem sel : selectedList) {
if (sel.getProduct().equals(prod)) {
isInSelected = true;
}
}
if (!isInSelected) {
LumberRunItem newItem = new LumberRunItem();
newItem.setProduct(prod);
newItem.setItemType("L");
newItem.setRun(current);
newItem.setWorkCenter(selectedWorkCenter);
availableRunItems.add(newItem);
}
}
}
public void selectRunItem(RunItem selectedItem) {
getSelectedRunItems().add(selectedItem);
}
public void getRunItem(RunItem runItem) {
List<RunItem> tmpList = new ArrayList();
for (RunItem run : getSelectedRunItems()) {
if (run.getBundle() == null) {
if (!run.getProduct().equals(runItem.getProduct())) {
tmpList.add(run);
}
} else {
if (!run.getBundle().getBundleId().equals(runItem.getBundle().getBundleId())) {
tmpList.add(run);
}
}
}
setSelectedRunItems(tmpList);
}
public SelectItem[] getActiveGradesFromProduct() {
List<Grade> tmpGrade = prodFacade.getDistinctGradeByStatus("ACTIVE");
SelectItem[] selects = new SelectItem[tmpGrade.size() + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Grade x : tmpGrade) {
selects[i++] = new SelectItem(x, x.getGradeDescription());
}
return selects;
}
public SelectItem[] getProductWidthSelectByLengthThicknessAndGrade() {
Float tmpLength = this.tmpAddRun.getProductLength();
String tmpThickness = this.tmpAddRun.getProductThickness();
Plant plant = plantFacade.find("P4");
if (this.addBundleGrade == null) {
SelectItem[] tmpSelects = new SelectItem[1];
tmpSelects[0] = new SelectItem("", "----");
return tmpSelects;
} else {
Grade tmpGrade = this.addBundleGrade;
List<String> widths = prodFacade.findWidthByLengthThicknessAndGrade(tmpLength, tmpThickness, tmpGrade, plant);
SelectItem[] selects = new SelectItem[widths.size() + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String width : widths) {
selects[i++] = new SelectItem(width, width);
}
return selects;
}
}
public SelectItem[] getDistinctGradesByPlant() {
Plant plant = plantFacade.find("P4");
List<Grade> tmpGrade = prodFacade.findDistinctGradeByPlant(plant);
SelectItem[] selects = new SelectItem[tmpGrade.size() + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Grade grade : tmpGrade) {
selects[i++] = new SelectItem(grade, grade.getGradeId());
}
return selects;
}
public void setUserPlant() {
if (this.userPlant != null) {
this.askPlant = false;
}
}
public String prepareBundles() {
this.runDate = new Date();
//this.createBundle = new Bundle();
this.tmpAddRun = new Run();
this.sessionLength = null;
this.sessionSpecies = null;
this.sessionThickness = null;
this.setSessionDayProduced(null);
this.setSessionShift(null);
this.setSessionSource(null);
int plantCount = userFacade.findAuthorizedPlantCount(getCurrentUser(), "V");
if (plantCount > 1) {
this.setAskPlant(true);
} else {
List<Plant> tmpPlant = userFacade.findAuthorizedPlants(this.getCurrentUser(), "ACTIVE");
this.setUserPlant(tmpPlant.get(0));
this.tmpAddRun.setWorkCenter(this.getFirstWorkCenterByPlant(getUserPlant()));
}
return _addBundles;
}
public SelectItem[] getUserPlantSelect() {
List<Plant> tmpPlant = userFacade.findAuthorizedPlants(this.getCurrentUser(), "ACTIVE");
SelectItem[] selects = new SelectItem[tmpPlant.size()];
int cnt = 0;
for (Plant plant : tmpPlant) {
selects[cnt++] = new SelectItem(plant, plant.getPlantName());
}
return selects;
}
public String createBundle(boolean b) {
if (this.addBundlePieces == 0 || this.addBundlePieces < 1) {
JsfUtil.addErrorMessage(ResourceBundle.getBundle("/messages").getString("Message_piecesGreaterThanZero"));
} else {
if (!this.runType.equals("P")) {
Bundle bundle = new VeneerBundle();
bundle.setBundleType(this.runType);
bundle.setRun(this.tmpAddRun);
bundle.setPieceCount(this.addBundlePieces);
bundle.setProduct(this.getAddProduct());
double tmpSurface = 0.0;
double tmpFootage = 0.0;
// use the footage helper here but just going to test
// TODO: use footage helper
tmpFootage = FootageHelper.calcSurface(bundle.getProduct(), this.addBundlePieces);
tmpSurface = FootageHelper.calcFootage(bundle.getProduct(), this.addBundlePieces);
bundle.setLastEditedBy(getCurrentUser());
bundle.setSurface((int) tmpSurface);
bundle.setFootage((int) tmpFootage);
bundle.setBundleId(null);
bundleFacade.create(bundle);
this.addBundlePieces = 0;
} else {
SawLineBundle bundle = new SawLineBundle();
bundle.setBundleType(this.runType);
bundle.setRun(this.tmpAddRun);
bundle.setPieceCount(this.addBundlePieces);
bundle.setProduct(this.getAddProduct());
bundle.setSource(this.sessionSource);
bundle.setSourceShift(this.sessionShift);
bundle.setDayProduced(this.sessionDayProduced);
double tmpSurface = 0.0;
double tmpFootage = 0.0;
// use the footage helper here but just going to test
// TODO: use footage helper
tmpFootage = FootageHelper.calcSurface(bundle.getProduct(), this.addBundlePieces);
tmpSurface = FootageHelper.calcFootage(bundle.getProduct(), this.addBundlePieces);
bundle.setLastEditedBy(getCurrentUser());
bundle.setSurface((int) tmpSurface);
bundle.setFootage((int) tmpFootage);
bundle.setBundleId(null);
bundleFacade.create(bundle);
this.addBundlePieces = 0;
}
}
// ejbFacade.edit(this.tmpAddRun);
if (b) {
return _bundleGradePlywood;
} else {
return _bundleWidth;
}
}
public List<Bundle> getBundlesByRun(Run run) {
List<Bundle> tmpBundles = bundleFacade.getBundlesByRun(run);
return tmpBundles;
}
public Product getProduct(float length, String thickness, Species species, Grade grade, String width) {
Product product = prodFacade.getProductByLengthThicknessSpeciesGradeAndWidth(length, thickness, species, grade, width, this.userPlant);
return product;
}
public void getPLantFromUser() {
List<Plant> plantList = userFacade.findAuthorizedPlants(this.getCurrentUser(), null);
}
public List<Shift> getRunShiftsByDate() {
Plant plant = this.getUserPlant();
Date tmpDate = this.runDate;
List<Shift> shiftList = ejbFacade.getRunShiftsByDateAndPlant(tmpDate, plant);
return shiftList;
}
public DataModel getRunByShiftDateAndWorkCenter(Shift shift, WorkCenter workcenter) {
switch (this.runType) {
case "V":
List<VeneerRun> vRuns = ejbFacade.findRunsByDateShiftAndWorkCenterVeneer(this.runDate, shift, workcenter);
return new ListDataModel(vRuns);
case "P":
List<PlywoodRun> pRuns = ejbFacade.findRunsByDateShiftAndWorkCenterPlywood(this.runDate, shift, workcenter);
return new ListDataModel(pRuns);
case "L":
List<LumberRun> lRuns = ejbFacade.findRunsByDateShiftAndWorkCenterLumber(this.runDate, shift, workcenter);
return new ListDataModel(lRuns);
}
return new ListDataModel(new ArrayList());
}
public String prepareBundleWidth(Run run) {
sessionLength = null;
sessionSpecies = null;
sessionThickness = null;
if (run == null) {
} else {
switch (this.runType) {
case "V":
VeneerRun vr = (VeneerRun) run;
this.tmpAddRun = (VeneerRun) vr;
break;
case "L":
LumberRun lr = (LumberRun) run;
this.tmpAddRun = lr;
break;
case "P":
PlywoodRun pr = (PlywoodRun) run;
this.tmpAddRun = (PlywoodRun) pr;
break;
}
}
return _bundleWidth;
}
public String prepareBundleWidthPlywood(Run run) {
sessionLength = (float) 96.0;
this.addBundleWidth = "48";
sessionSpecies = null;
sessionThickness = null;
sessionDayProduced = null;
sessionShift = null;
sessionSource = null;
if (run == null) {
} else {
switch (this.runType) {
case "V":
this.tmpAddRun = (VeneerRun) run;
break;
case "L":
this.tmpAddRun = (LumberRun) run;
break;
case "P":
this.tmpAddRun = (PlywoodRun) run;
break;
}
}
if (run.getProductThickness() != null) {
this.sessionThickness = run.getProductThickness();
return _bundleGradePlywood;
}
return _bundleWidthPlywood;
}
public List<String> getDistinctWidths() {
String[] widths = new String[4];
widths[0] = "54";
widths[1] = "27";
widths[2] = "RW";
widths[3] = "FT";
return Arrays.asList(widths);
}
public String prepareBundleGrade(String width) {
if (width.isEmpty()) {
return _bundleGrade;
} else {
this.addBundleWidth = width;
}
return _bundleGrade;
}
public String prepareBundleGradePlywood(String thick) {
String width = this.addBundleWidth;
this.sessionThickness = thick;
sessionDayProduced = null;
sessionShift = null;
sessionSource = null;
if (width.isEmpty()) {
return _bundleGradePlywood;
} else {
this.addBundleWidth = width;
}
return _bundleGradePlywood;
}
public List<Grade> getGradeListByPlant() {
Plant plant = this.getUserPlant();
List<Grade> tmpGrade = prodFacade.findDistinctGradeByPlant(plant);
return tmpGrade;
}
public String prepareCreateRun(Grade grade) {
this.addBundleGrade = grade;
Float tmpLength = (float) 0;
String tmpThick = "";
Species tmpSpecies = new Species();
switch (this.runType) {
case "V":
VeneerRun r = (VeneerRun) this.tmpAddRun;
if (r.getSpecies() == null) {
tmpSpecies = this.sessionSpecies;
} else {
tmpSpecies = r.getSpecies();
}
if (r.getProductThickness() == null || r.getProductThickness().isEmpty()) {
tmpThick = this.sessionThickness;
} else {
tmpThick = r.getProductThickness();
}
if (r.getProductLength() == null) {
tmpLength = this.sessionLength;
} else {
tmpLength = r.getProductLength();
}
break;
case "P":
PlywoodRun pr = (PlywoodRun) this.tmpAddRun;
if (pr.getProductThickness() == null || pr.getProductThickness().isEmpty()) {
tmpThick = this.sessionThickness;
} else {
tmpThick = pr.getProductThickness();
}
if (pr.getProductLength() == null) {
tmpLength = this.sessionLength;
} else {
tmpLength = pr.getProductLength();
}
tmpSpecies = null;
break;
case "L":
LumberRun lr = (LumberRun) this.tmpAddRun;
if (lr.getProductThickness() == null) {
tmpThick = this.sessionThickness;
} else {
tmpThick = lr.getProductThickness();
}
if (lr.getSpecies() == null) {
tmpSpecies = this.sessionSpecies;
} else {
tmpSpecies = lr.getSpecies();
}
if (lr.getProductLength() == null) {
tmpLength = this.sessionLength;
} else {
tmpLength = lr.getProductLength();
}
break;
}
try {
this.setAddProduct(this.getProduct(tmpLength,
tmpThick,
tmpSpecies, this.addBundleGrade,
this.addBundleWidth));
} catch (Exception e) {
JsfUtil.addErrorMessage("No Product Found!");
return _bundleGrade;
}
return _addPieces;
}
public void chooseRunFirst() {
JsfUtil.addErrorMessage("Please Choose Run First");
}
public void chooseWidthFirst() {
JsfUtil.addErrorMessage("Please Choose Width First");
}
public void chooseGradeFirst() {
JsfUtil.addErrorMessage("Please Choose Grade First");
}
public void convertRun() {
int max = 30000;
int cnt = 0;
int interval = 200;
int value = 1;
while (max > -200) {
value = max - interval;
List<Run> tmpList = ejbFacade.findWhereIdGreaterThanAndLess(value, max);
for (Run r : tmpList) {
System.out.println("Run id:" + r.getRunId());
ejbFacade.convertRun(r);
}
System.out.println("one int");
max -= interval;
++cnt;
}
}
public void cleanRunItems() {
List<Run> tmpRuns = ejbFacade.findWhereWorkCenterNotNull();
for (Run r : tmpRuns) {
ejbFacade.cleanRunItems(r);
}
}
public String refreshAddPage() {
return _addBundles;
}
public String setUserPlantFinal(Plant plant) {
System.out.println(plant);
this.askPlant = false;
this.setUserPlant(plant);
return _addBundles;
}
public SelectItem[] getWorkCenterByPlantSelect(Plant plant) {
List<WorkCenter> workList = ejbWorkCenterFacade.findWorkCenterByPlant(plant);
SelectItem[] selects = new SelectItem[workList.size() + 1];
selects[0] = new SelectItem("", "---");
int cnt = 1;
for (WorkCenter work : workList) {
selects[cnt++] = new SelectItem(work, work.getName());
}
return selects;
}
public SelectItem[] getWorkCenterByPlantSelectNoNull(Plant plant) {
List<WorkCenter> workList = ejbWorkCenterFacade.findWorkCenterByPlant(plant);
SelectItem[] selects = new SelectItem[workList.size()];
int cnt = 0;
for (WorkCenter work : workList) {
selects[cnt++] = new SelectItem(work, work.getName());
}
return selects;
}
public List<WorkCenter> getWorkCenterByPlant(Plant plant) {
List<WorkCenter> workList = ejbWorkCenterFacade.findWorkCenterByPlant(plant);
return workList;
}
public List<WorkCenter> getWorkCenterByPlantAndStatus(Plant plant, String status) {
List<WorkCenter> workList = ejbWorkCenterFacade.findWorkCentersByPlantAndStatus(plant, status);
return workList;
}
public List<PlywoodRun> getRunsByDateShiftAndWorkCenterPlywood(Date date, Shift shift, WorkCenter workcenter) {
List<PlywoodRun> tmpList = ejbFacade.findRunsByDateShiftAndWorkCenterPlywood(date, shift, workcenter);
return tmpList;
}
public List<VeneerRun> getRunsByDateShiftAndWorkCenterVeneer(Date date, Shift shift, WorkCenter workcenter) {
List<VeneerRun> tmpList = ejbFacade.findRunsByDateShiftAndWorkCenterVeneer(date, shift, workcenter);
return tmpList;
}
public List<LumberRun> getRunsByDateShiftAndWorkCenterLumber(Date date, Shift shift, WorkCenter workcenter) {
List<LumberRun> tmpList = ejbFacade.findRunsByDateShiftAndWorkCenterLumber(date, shift, workcenter);
return tmpList;
}
public List<Run> getRunsByDateShiftAndWorkCenter(Date date, Shift shift, WorkCenter workcenter) {
List<Run> tmpList = ejbFacade.findRunsByDateShiftAndWorkCenter(date, shift, workcenter);
return tmpList;
}
public List<Date> getDayByReportRange() {
Calendar tmpStart = new GregorianCalendar();
Calendar tmpEnd = new GregorianCalendar();
tmpStart.setTime(this.runScheduleStart);
tmpEnd.setTime(this.runScheduleEnd);
Date runDay = tmpStart.getTime();
Date endDay = tmpEnd.getTime();
List<Date> tmpDateList = new ArrayList();
while (runDay.compareTo(endDay) <= 0) {
tmpDateList.add(runDay);
Calendar tmpCal = new GregorianCalendar();
tmpCal.setTime(runDay);
tmpCal.add(Calendar.DATE, 1);
runDay = tmpCal.getTime();
}
return tmpDateList;
}
public WorkCenter getFirstWorkCenterByPlant(Plant plant) {
List<WorkCenter> tmpList = ejbWorkCenterFacade.findWorkCenterByPlant(plant);
WorkCenter work = tmpList.get(0);
return work;
}
public boolean hasRunsForDateShiftAndWorkCenter(Date date, Shift shift, WorkCenter workcenter) {
List<VeneerRun> vList = this.getRunsByDateShiftAndWorkCenterVeneer(date, shift, workcenter);
List<LumberRun> lList = this.getRunsByDateShiftAndWorkCenterLumber(date, shift, workcenter);
List<PlywoodRun> pList = this.getRunsByDateShiftAndWorkCenterPlywood(date, shift, workcenter);
switch (this.runType) {
case "V":
if (vList.size() > 0) {
return true;
} else {
return false;
}
case "P":
if (pList.size() > 0) {
return true;
} else {
return false;
}
case "L":
if (lList.size() > 0) {
return true;
} else {
return false;
}
}
return false;
}
public boolean hasRunsByDateAndWorkCenter(Date date, WorkCenter work) {
return ejbFacade.hasRunsByDateWorkCenterAndType(date, work, this.runType);
}
public boolean runHasProductBundles(Run run, Product prod) {
List<Bundle> tmpList = bundleFacade.getBundlesByRunAndProduct(run, prod);
if (tmpList.isEmpty()) {
return false;
} else {
return true;
}
}
public String prepareCreateSchedule() {
this.runScheduleStart = new Date();
this.runScheduleEnd = new Date();
this.getFilterRun().setWorkCenter(this.getFirstWorkCenterByPlant(this.filterRun.getPlant()));
this.userPlant = this.getFilterRun().getPlant();
this.activeWeek = null;
this.activeDateList = null;
this.activeShift = null;
this.createRunList = null;
return _createRunSchedule;
}
public void changeColor() {
if (this.backColor.equals("#e3e3e3")) {
this.backColor = "#939393";
} else {
this.backColor = "#e3e3e3";
}
}
public void setCurrent(Shift shift, Date day) {
this.selectedRunDate = day;
getTmpCreateRun().setShift(shift);
getTmpCreateRun().setRunDate(day);
getTmpCreateRun().setScheduledStart(day);
getTmpCreateRun().setScheduledEnd(day);
getTmpCreateRun().setPlant(this.filterRun.getPlant());
this.currentShift = shift;
this.currentDate = day;
}
public boolean isCurrent(Shift shift, Date day) {
if (this.getCurrentShift().equals(shift) && this.currentDate.equals(day)) {
return true;
} else {
return false;
}
}
public String buildRunSchedule() {
return _createRunSchedule;
}
public String createScheduledRun() {
this.getTmpCreateRun().setStatus("OPEN");
//ejbFacade.create(this.getTmpCreateRun());
this.selectedRunDate = null;
this.tmpCreateRun.setScheduledHours(null);
this.tmpCreateRun.setProductThickness(null);
this.tmpCreateRun.setProductLength(null);
this.tmpCreateRun.setSpecies(null);
return _createRunSchedule;
}
public void submitRunSchedule() {
for (Run run : this.getCreateRunList()) {
ejbFacade.create(run);
}
this.setCreateRunList(null);
}
public void setNextRunDate() {
if (this.runScheduleStart.compareTo(this.runScheduleEnd) == 0) {
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal1.setTime(this.runScheduleStart);
cal2.setTime(this.runScheduleEnd);
cal1.add(Calendar.DATE, 1);
cal2.add(Calendar.DATE, 1);
this.runScheduleStart = cal1.getTime();
this.runScheduleEnd = cal2.getTime();
} else {
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal1.setTime(this.runScheduleStart);
cal2.setTime(this.runScheduleStart);
cal1.add(Calendar.DATE, 1);
cal2.add(Calendar.DATE, 1);
this.runScheduleStart = cal1.getTime();
this.runScheduleEnd = cal2.getTime();
}
}
public void setPrevRunDate() {
if (this.runScheduleStart.compareTo(this.runScheduleEnd) == 0) {
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal1.setTime(this.runScheduleStart);
cal2.setTime(this.runScheduleEnd);
cal1.add(Calendar.DATE, -1);
cal2.add(Calendar.DATE, -1);
this.runScheduleStart = cal1.getTime();
this.runScheduleEnd = cal2.getTime();
} else {
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal1.setTime(this.runScheduleStart);
cal2.setTime(this.runScheduleStart);
cal1.add(Calendar.DATE, -1);
cal2.add(Calendar.DATE, -1);
this.runScheduleStart = cal1.getTime();
this.runScheduleEnd = cal2.getTime();
}
}
public boolean runHasBundlesByRunAndWorkCenter(Run run, WorkCenter workcenter) {
List<Run> tmpList = ejbFacade.findRunBundlesByRunAndWorkCenter(run, workcenter);
if (tmpList.size() > 0) {
return true;
} else {
return false;
}
}
public int getBundleCountByRun(Run run) {
return this.getBundlesByRun(run).size();
}
public String getDayOfWeek(Date day) {
return DateHelper.getDayOfWeek(day);
}
public List<Bundle> getBundlesByUserAndDate(Date date) {
String userName = this.getCurrentUser();
List<Bundle> tmpList = bundleFacade.findByUserAndDate(userName, date);
return tmpList;
}
public String getWeekLabel(Date date) {
Date start = DateHelper.getBeginningOfWeek(date);
Date end = DateHelper.getEndOfWeek(date);
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal1.setTime(start);
cal2.setTime(end);
return _weekOf + (cal1.get(Calendar.MONTH) + 1) + "/" + cal1.get(Calendar.DATE) + " - " + (cal2.get(Calendar.MONTH) + 1) + "/" + cal2.get(Calendar.DATE);
}
public List<Date> getRunReportWeekStarts() {
List<Date> tmpList = new ArrayList();
tmpList.add(DateHelper.getBeginningOfPrevWeek());
tmpList.add(DateHelper.getBeginningOfWeek(new Date()));
tmpList.add(DateHelper.getBeginningOfNextWeek());
return tmpList;
}
public void setPreviousWeek() {
this.weekDate = DateHelper.getDatePlusDays(this.weekDate, -7);
}
public void setNextWeek() {
this.weekDate = DateHelper.getDatePlusDays(this.weekDate, 7);
}
public List<Date> getDaysOfWeek(Date weekStart) {
if (weekStart == null) {
return new ArrayList();
}
weekStart = DateHelper.getBeginningOfWeek(weekStart);
Date tmpEnd = DateHelper.getEndOfWeek(weekStart);
List<Date> weekList = new ArrayList();
Calendar cal = new GregorianCalendar();
cal.setTime(weekStart);
int cnt = 0;
while (cnt <= 6) {
weekList.add(cal.getTime());
cal.add(Calendar.DATE, 1);
++cnt;
}
return weekList;
}
public boolean weekIsActive(Date week) {
if (getActiveWeek() == null) {
return false;
}
if (DateHelper.sameDay(getActiveWeek(), week)) {
return true;
} else {
return false;
}
}
public boolean shiftIsActive(Shift shift, Date day) {
if (this.activeShift.equals(shift)
&& DateHelper.sameDay(day, this.activeShiftDate)) {
return true;
} else {
return false;
}
}
public void addRun(Shift shift, Date date) {
Run createRun = new Run();
switch (this.runType) {
case "V":
createRun = (VeneerRun) new VeneerRun();
createRun.setRunType("V");
break;
case "L":
createRun = (LumberRun) new LumberRun();
createRun.setRunType("L");
break;
case "P":
createRun = (PlywoodRun) new PlywoodRun();
createRun.setRunType("P");
break;
}
createRun.setShift(shift);
createRun.setRunDate(date);
createRun.setWorkCenter(this.getFilterRun().getWorkCenter());
if (shift.isIsStartPrevDay()) {
Date tmpStart = DateHelper.getDatePlusDays(date, -1);
createRun.setScheduledStart(DateHelper.setDateAndTime(tmpStart, shift.getScheduledStart()));
} else {
createRun.setScheduledStart(DateHelper.setDateAndTime(date, shift.getScheduledStart()));
}
if (shift.isIsEndNextDay()) {
createRun.setScheduledEnd(DateHelper.getDatePlusDays(date, 1));
createRun.setScheduledEnd(DateHelper.setDateAndTime(createRun.getScheduledEnd(), shift.getScheduledEnd()));
} else {
createRun.setScheduledEnd(DateHelper.setDateAndTime(date, shift.getScheduledEnd()));
}
createRun.setPlant(this.getFilterRun().getPlant());
createRun.setStatus(_open);
createRun.setWorkCenter(filterRun.getWorkCenter());
createRun.setScheduledHours(BigDecimal.valueOf(DateHelper.calculateDifference(createRun.getScheduledStart(), createRun.getScheduledEnd())));
this.getCreateRunList().add(createRun);
ejbFacade.create(createRun);
}
public BigDecimal timeDifference(Date one, Date two) {
return BigDecimal.valueOf(DateHelper.calculateDifference(one, two));
}
public String updateRun(Run run) {
ejbFacade.edit(run);
return "createRunSchedule";
}
public void removeRun(Run run) {
ejbFacade.remove(run);
this.setCreateRunList(null);
}
public void setActiveDate(Date date) {
this.getActiveDateList().add(date);
}
public boolean dayIsActive(Date day) {
if (this.getActiveDateList() == null) {
return false;
}
for (Date date : this.getActiveDateList()) {
if (DateHelper.sameDay(date, day)) {
return true;
}
}
return false;
}
public void removeActiveDate(Date date) {
List<Date> tmpList = new ArrayList();
for (Date d : this.getActiveDateList()) {
if (!DateHelper.sameDay(date, d)) {
tmpList.add(d);
}
}
this.setActiveDateList(tmpList);
}
public List<Run> getTempRunsByShiftAndDate(Shift shift, Date date) {
List<Run> tmpList = new ArrayList();
for (Run run : this.getCreateRunList()) {
if (run.getShift().equals(shift)) {
if (DateHelper.sameDay(run.getRunDate(), date)) {
tmpList.add(run);
}
}
}
return tmpList;
}
public List<Run> getRunByShiftDateAndWorkCenter(Shift shift, Date date, WorkCenter workcenter) {
List<Run> tmpList = ejbFacade.findRunsByDateShiftAndWorkCenter(date, shift, workcenter);
return tmpList;
}
public List<Date> getDaysOfCurrentWeek() {
Date start = DateHelper.getBeginningOfWeek(new Date());
Calendar startCal = new GregorianCalendar();
startCal.setTime(start);
List<Date> week = new ArrayList();
int cnt = 0;
while (cnt < 7) {
week.add(startCal.getTime());
startCal.add(Calendar.DATE, 1);
++cnt;
}
for (Date day : week) {
System.out.println(day);
}
return week;
}
public List<Date> getReportDays() {
Calendar cal = new GregorianCalendar();
cal.setTime(this.reportStart);
List<Date> tmpList = new ArrayList();
while (cal.getTime().compareTo(this.reportEnd) <= 0) {
if (this.hasRunsByDateAndWorkCenter(cal.getTime(), userWorkCenter)) {
tmpList.add(cal.getTime());
}
cal.add(Calendar.DATE, 1);
}
return tmpList;
}
public String prepareRunReport() {
this.reportStart = DateHelper.getBeginningOfWeek(new Date());
this.reportEnd = DateHelper.getEndOfWeek(this.reportStart);
this.userPlant = userFacade.findSingleAuthorizedInventoryPlant(this.getCurrentUser(), this.runType);
switch (this.runType) {
case "V":
return _runReport;
case "P":
return _runReportPlywood;
case "L":
return _runReportLumber;
}
return _runReport;
}
public String submitRunReport() {
switch (this.runType) {
case "V":
return _runReport;
case "L":
return _runReportLumber;
case "P":
return _runReportPlywood;
}
return _runReport;
}
public void editItem(RunItem item) {
this.setEditItem(item);
List<Bundle> tmpList = bundleFacade.getBundlesByRunAndProduct(item.getRun(), item.getProduct());
this.setEditItemList(tmpList);
}
public boolean isEditItem(RunItem item) {
if (this.editItem == null) {
return false;
}
if (item.getRun().equals(editItem.getRun())) {
if (item.getProduct().equals(editItem.getProduct())) {
return true;
}
}
return false;
}
public String prepareEditRunProduct(Product prod, Run run) {
this.setSelectedProduct(prod);
List<Bundle> tmpList = bundleFacade.getBundlesByRunAndProduct(run, prod);
this.setEditItemList(tmpList);
this.setSelectedRun(run);
return _editRunProduct;
}
public String removeBundle(Bundle bundle) {
List<Bundle> tmpBundle = new ArrayList();
for (Bundle b : editItemList) {
if (!b.equals(bundle)) {
tmpBundle.add(b);
} else {
bundleFacade.remove(b);
}
}
this.setEditItemList(tmpBundle);
return _editRunProduct;
}
public String updateBundle(Bundle bundle) {
for (Bundle b : editItemList) {
if (b.equals(bundle)) {
bundleFacade.edit(b);
}
}
return _editRunProduct;
}
public String addBundleToSelectedRun() {
Run run = this.getSelected();
VeneerBundle bun = new VeneerBundle();
bun.setProduct(this.getSelectedProduct());
bun.setPieceCount(0);
bun.setRun(run);
bundleFacade.create(bun);
List<Bundle> tmpList = bundleFacade.getBundlesByRunAndProduct(run, this.getSelectedProduct());
this.setEditItemList(tmpList);
this.setSelectedRun(run);
bun = null;
return _editRunProduct;
}
public List<Grade> getDistinctGradeListByRun(Run run) {
List<Grade> tmpList = new ArrayList();
switch (run.getRunType()) {
case "V":
VeneerRun vr = (VeneerRun) run;
VeneerProduct vFilter = new VeneerProduct();
if (vr.getProductThickness() == null || run.getProductThickness().isEmpty()) {
vFilter.setThickness(sessionThickness);
} else {
vFilter.setThickness(vr.getProductThickness());
}
if (vr.getProductLength() == null) {
vFilter.setProductLength(sessionLength);
} else {
vFilter.setProductLength(vr.getProductLength());
}
if (vr.getSpecies() == null) {
vFilter.setSpecies(sessionSpecies);
} else {
vFilter.setSpecies(vr.getSpecies());
}
vFilter.setProductWidth(this.addBundleWidth);
vFilter.setPlant(this.tmpAddRun.getPlant());
tmpList = prodFacade.findDistinctGradeByFilterVeneer(vFilter);
break;
case "P":
PlywoodRun pr = (PlywoodRun) run;
PlywoodProduct pFilter = new PlywoodProduct();
if (pr.getProductThickness() == null || run.getProductThickness().isEmpty()) {
pFilter.setThickness(sessionThickness);
} else {
pFilter.setThickness(pr.getProductThickness());
}
if (pr.getProductLength() == null) {
pFilter.setProductLength(sessionLength);
} else {
pFilter.setProductLength(pr.getProductLength());
}
pFilter.setProductWidth(this.addBundleWidth);
pFilter.setPlant(this.tmpAddRun.getPlant());
tmpList = prodFacade.findDistinctGradeByFilterPlywood(pFilter);
break;
case "L":
LumberRun lr = (LumberRun) run;
LumberProduct lFilter = new LumberProduct();
if (lr.getProductThickness() == null || run.getProductThickness().isEmpty()) {
lFilter.setThickness(sessionThickness);
} else {
lFilter.setThickness(lr.getProductThickness());
}
if (lr.getProductLength() == null) {
lFilter.setProductLength(sessionLength);
} else {
lFilter.setProductLength(lr.getProductLength());
}
if (lr.getSpecies() == null) {
lFilter.setSpecies(sessionSpecies);
} else {
lFilter.setSpecies(lr.getSpecies());
}
lFilter.setProductWidth(this.addBundleWidth);
lFilter.setPlant(this.tmpAddRun.getPlant());
tmpList = prodFacade.findDistinctGradeByFilterLumber(lFilter);
break;
}
return tmpList;
}
public String removeRunItem(RunItem item) {
List<RunItem> tmpList = new ArrayList();
List<RunItem> selectedList = this.getSelectedRunItems();
for (RunItem it : selectedList) {
if (!it.getProduct().equals(item.getProduct())) {
tmpList.add(it);
}
}
this.setSelectedRunItems(tmpList);
return "RunItemCreateMany";
}
public String prepareSawlineReport() {
this.reportStart = DateHelper.getBeginningOfWeek(new Date());
this.reportEnd = DateHelper.getEndOfWeek(new Date());
this.userPlant = plantFacade.find("P3");
this.userWorkCenter = ejbWorkCenterFacade.find("P3-8FTSAWLINE");
//
this.setSawlineFilterItem(new SawlineRunItem());
//
Map<PlywoodRun, List<SawlineRunItem>> tmpMap = ejbFacade.getSawLineMap(reportStart, reportEnd, userPlant, userWorkCenter, getSawlineFilterItem() , this.endDayProduced);
this.setSawLineMap(tmpMap);
return _sawlineReport;
}
public String submitSawLineReport() {
Map<PlywoodRun, List<SawlineRunItem>> tmpMap = ejbFacade.getSawLineMap(reportStart, reportEnd, userPlant, userWorkCenter, getSawlineFilterItem() , this.endDayProduced);
this.setSawLineMap(tmpMap);
return _sawlineReport;
}
public List<PlywoodRun> getSawlineRunsByFilterFromMap() {
List<PlywoodRun> tmpRuns = new ArrayList();
tmpRuns.addAll(this.getSawLineMap().keySet());
return tmpRuns;
}
public Date getDayProducedFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
return tmpList.get(0).getDayProduced();
}
public WorkCenter getSourceFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
return tmpList.get(0).getSource();
}
public Shift getSourceShiftFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
return tmpList.get(0).getSourceShift();
}
public Integer getOnGradePiecesFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
Integer count = 0;
for (SawlineRunItem item : tmpList) {
Product tmpProduct = item.getProduct();
if (productOnGrade(tmpProduct)) {
count += item.getPieceCount();
}
}
return count;
}
public Integer getMillCertPiecesFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
Integer count = 0;
for (SawlineRunItem item : tmpList) {
Product tmpProduct = item.getProduct();
if (productMillCert(tmpProduct)) {
count += item.getPieceCount();
}
}
return count;
}
public Integer getShopPiecesFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
Integer count = 0;
for (SawlineRunItem item : tmpList) {
Product tmpProduct = item.getProduct();
if (productShop(tmpProduct)) {
count += item.getPieceCount();
}
}
return count;
}
public Integer getRejectPiecesFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
Integer count = 0;
for (SawlineRunItem item : tmpList) {
Product tmpProduct = item.getProduct();
if (productReject(tmpProduct)) {
count += item.getPieceCount();
}
}
return count;
}
public String plywoodProdType(Product prod) {
String millCert = "mill cert";
String shop = "shop";
String reject = "miscuts";
String blows = "blows";
String desc = prod.getDescription().toLowerCase();
if (desc.contains(millCert)) {
return _millCert;
} else if (desc.contains(shop)) {
return _shop;
} else if (desc.contains(reject) || desc.contains(blows)) {
return _miscut;
}
return _onGrade;
}
public boolean productOnGrade(Product product) {
return plywoodProdType(product).equals(_onGrade);
}
public boolean productMillCert(Product prod) {
return plywoodProdType(prod).equals(_millCert);
}
public boolean productShop(Product prod) {
return plywoodProdType(prod).equals(_shop);
}
public boolean productReject(Product prod) {
return plywoodProdType(prod).equals(_miscut);
}
public Integer getTotalPiecesFromMap(PlywoodRun run) {
List<SawlineRunItem> tmpList = this.getSawLineMap().get(run);
int count = 0;
for (SawlineRunItem item : tmpList) {
count += item.getPieceCount();
}
return count;
}
public float getOffGradeFromMap(PlywoodRun run) {
Integer total = getTotalPiecesFromMap(run);
Integer grade = getOnGradePiecesFromMap(run);
Integer off = total - grade;
float percent = (((float) off) / ((float) total));
return percent;
}
}
package erp.production.controller;
import erp.admin.entities.ErpUserFacade;
import erp.admin.entities.Plant;
import erp.production.veneer.entities.ScannerSummary;
import erp.util.controller.JsfUtil;
import erp.util.controller.PaginationHelper;
import erp.production.veneer.entities.ScannerSummaryFacade;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import erp.util.helpers.DateHelper;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.primefaces.model.chart.AxisType;
import org.primefaces.model.chart.DateAxis;
import org.primefaces.model.chart.LineChartModel;
import org.primefaces.model.chart.LineChartSeries;
@Named("scannerSummaryController")
@SessionScoped
public class ScannerSummaryController implements Serializable {
//EJBS
@EJB
private ErpUserFacade userFacade;
@EJB
private erp.production.veneer.entities.ScannerSummaryFacade ejbFacade;
@EJB
private erp.admin.entities.PlantFacade plantFacade;
//DATA MAPS
private Map<String, Map<String, ScannerSummary>> shiftData;
private Map<String, Map<String, ScannerSummary>> nonShiftData;
private Map<String, ScannerSummary> dailyData;
private Map<String, ScannerSummary> monthlyData;
private Map<String, ScannerSummary> tmpShiftProduction = new HashMap<>();
private Map<String, ScannerSummary> tmpMap = new HashMap<>();
//STATIC VARIABLES
private static final List<String> _nonProductionGradeListP4 = Arrays.asList("Core", "HW", "LWD", "None");
private static final List<String> _nonProductionGradeListP2 = Arrays.asList("Trash");
private static final String _scannerSummaryPage = "ScannerSummaryList";
private static final String _plant2DailyVeneer = "plant2DailyVeneer";
private static final List<String> nonProdGradeList = new ArrayList() {
{
add("Trash");
}
};
private static final String _trash = "Trash";
//NON-STATIC VARIABLES
private ScannerSummary current;
private DataModel items = null;
private List<ScannerSummary> itemList;
private ScannerSummary summaryFilter;
private int maxRows;
//DATE Objects
private Date reportStart;
private Date reportEnd;
private Date tmpReportStart;
private Date tmpReportEnd;
//
private DateHelper dHelper;
private PaginationHelper pagination;
private int selectedItemIndex;
private int shiftLabelSize;
private int groupCount;
private List<String> distinctShift;
private Plant lastShiftPlant;
private Date lastShiftDate;
//
private ScannerSummary gradesFilter;
private List<String> lastGradesList;
private LineChartModel testData;
//MAIN FUNCTIONS
public ScannerSummaryController() {
}
public ScannerSummary getSelected() {
if (current == null) {
current = new ScannerSummary();
selectedItemIndex = -1;
}
return current;
}
private ScannerSummaryFacade getFacade() {
return ejbFacade;
}
private void buildDataMaps() {
this.getShiftData();
this.getDailyData();
this.getMonthlyData();
}
public String outGradeAndShift() {
reportEnd = this.getMaxDateFromScannerTable();
this.lastShiftDate = new Date();
//this.buildDataMaps();
return _scannerSummaryPage;
}
public String plant2DailyVeneer() {
this.summaryFilter = null;
getSummaryFilter().setPlant(plantFacade.find("P2"));
//TODO:change this date this is a TEMP date
this.reportEnd = new Date();
return _plant2DailyVeneer;
}
public String submitFilter() {
return _plant2DailyVeneer;
}
//TABLE CELL FUNCTIONS
public long getCountByShiftAndGrade(String shift, String grade) {
this.reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
if (getShiftData().containsKey(shift)) {
if (getShiftData().get(shift).containsKey(grade)) {
return this.getShiftData().get(shift).get(grade).getPiececount();
}
}
return 0;
}
public long getFootageByShiftAndGrade(String shift, String grade) {
this.reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
if (this.getShiftData().containsKey(shift)) {
if (getShiftData().get(shift).containsKey(grade)) {
if (this.getShiftData().get(shift).get(grade).getFootage() == null) {
} else {
return this.getShiftData().get(shift).get(grade).getFootage();
}
}
}
return 0;
}
public long getSurfaceByShiftAndGrade(String shift, String grade) {
this.reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
if (this.getShiftData().containsKey(shift)) {
if (getShiftData().get(shift).containsKey(grade)) {
if (this.getShiftData().get(shift).get(grade).getSurface() == null) {
} else {
return this.getShiftData().get(shift).get(grade).getSurface();
}
}
}
return 0;
}
public long getDailyCountByGrade(String grade) {
this.reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
if (getDailyData().containsKey(grade)) {
return this.getDailyData().get(grade).getPiececount();
}
return 0;
}
public long getDailyFootageByGrade(String grade) {
this.reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
if (getDailyData().containsKey(grade)) {
if (this.getDailyData().get(grade).getFootage() != null) {
return this.getDailyData().get(grade).getFootage();
} else {
return 0;
}
} else {
return 0;
}
}
public long getDailySurfaceByGrade(String grade) {
this.reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
if (getDailyData().containsKey(grade)) {
if (this.getDailyData().get(grade).getSurface() != null) {
if (this.getDailyData().get(grade).getSurface() != null) {
return this.getDailyData().get(grade).getSurface();
} else {
return 0;
}
} else {
return 0;
}
} else {
return 0;
}
}
public long getMonthlyCountByGrade(String grade) {
this.reportStart = DateHelper.getSelectedBeginningOfMonth(reportEnd);
if (getMonthlyData().containsKey(grade)) {
if (this.getMonthlyData().get(grade).getPiececount() != null) {
return this.getMonthlyData().get(grade).getPiececount();
} else {
return 0;
}
}
return 0;
}
public long getMonthlyFootageByGrade(String grade) {
this.reportStart = DateHelper.getSelectedBeginningOfMonth(reportEnd);
if (getMonthlyData().containsKey(grade)) {
if (this.getMonthlyData().get(grade).getFootage() != null) {
return this.getMonthlyData().get(grade).getFootage();
} else {
return 0;
}
}
return 0;
}
public long getMonthlySurfaceByGrade(String grade) {
this.reportStart = DateHelper.getSelectedBeginningOfMonth(reportEnd);
if (getMonthlyData().containsKey(grade)) {
if (this.getMonthlyData().get(grade).getSurface() != null) {
return this.getMonthlyData().get(grade).getSurface();
} else {
return 0;
}
}
return 0;
}
public long getTotalPieceCountByShift(String shift, boolean production) {
if (getShiftData().containsKey(shift)) {
//this is getting set to actual shift list sub map
//when i was changing values to my tmp map is was making those changes
//to my live data
tmpShiftProduction.putAll(getShiftData().get(shift));
long sumPieceCount = 0;
if (production) {
tmpShiftProduction = this.stripNonProdGrades(tmpShiftProduction);
} else {
tmpShiftProduction = this.stripProdGrades(tmpShiftProduction);
}
for (ScannerSummary sum : tmpShiftProduction.values()) {
if (sum.getPiececount() != null) {
sumPieceCount += sum.getPiececount();
}
}
return sumPieceCount;
} else {
return 0;
}
}
public long getTotalFootageByShift(String shift, boolean production) {
if (getShiftData().containsKey(shift)) {
tmpShiftProduction.putAll(getShiftData().get(shift));
long sumPieceCount = 0;
if (production) {
tmpShiftProduction = this.stripNonProdGrades(tmpShiftProduction);
} else {
tmpShiftProduction = this.stripProdGrades(tmpShiftProduction);
}
for (ScannerSummary sum : tmpShiftProduction.values()) {
if (sum.getFootage() != null) {
sumPieceCount += sum.getFootage();
}
}
return sumPieceCount;
} else {
return 0;
}
}
public long getTotalSurfaceByShift(String shift, boolean production) {
if (getShiftData().containsKey(shift)) {
tmpShiftProduction.putAll(getShiftData().get(shift));
long sumPieceCount = 0;
if (production) {
tmpShiftProduction = this.stripNonProdGrades(tmpShiftProduction);
} else {
tmpShiftProduction = this.stripProdGrades(tmpShiftProduction);
}
for (ScannerSummary sum : tmpShiftProduction.values()) {
if (sum.getSurface() != null) {
sumPieceCount += sum.getSurface();
}
}
return sumPieceCount;
} else {
return 0;
}
}
public long getTotalPieceCountByDay(boolean production) {
tmpMap.putAll(getDailyData());
if (production) {
tmpMap = this.stripNonProdGrades(tmpMap);
} else {
tmpMap = this.stripProdGrades(tmpMap);
}
long tmpPieceCount = 0;
for (ScannerSummary sum : tmpMap.values()) {
if (sum.getPiececount() != null) {
tmpPieceCount += sum.getPiececount();
}
}
return tmpPieceCount;
}
public long getTotalSurfaceByDay(boolean production) {
tmpMap.putAll(getDailyData());
if (production) {
tmpMap = this.stripNonProdGrades(tmpMap);
} else {
tmpMap = this.stripProdGrades(tmpMap);
}
long tmpPieceCount = 0;
for (ScannerSummary sum : tmpMap.values()) {
if (sum.getSurface() != null) {
tmpPieceCount += sum.getSurface();
}
}
return tmpPieceCount;
}
public long getTotalFootageByDay(boolean production) {
tmpMap.putAll(getDailyData());
if (production) {
tmpMap = this.stripNonProdGrades(tmpMap);
} else {
tmpMap = this.stripProdGrades(tmpMap);
}
long tmpPieceCount = 0;
for (ScannerSummary sum : tmpMap.values()) {
if (sum.getFootage() != null) {
tmpPieceCount += sum.getFootage();
}
}
return tmpPieceCount;
}
public long getTotalPieceCountByMonth(boolean production) {
tmpMap.putAll(getMonthlyData());
if (production) {
tmpMap = this.stripNonProdGrades(tmpMap);
} else {
tmpMap = this.stripProdGrades(tmpMap);
}
long tmpSum = 0;
for (ScannerSummary sum : tmpMap.values()) {
if (sum.getPiececount() != null) {
tmpSum += sum.getPiececount();
}
}
return tmpSum;
}
public long getTotalSurfaceByMonth(boolean production) {
tmpMap.putAll(getMonthlyData());
if (production) {
tmpMap = this.stripNonProdGrades(tmpMap);
} else {
tmpMap = this.stripProdGrades(tmpMap);
}
long tmpSum = 0;
for (ScannerSummary sum : tmpMap.values()) {
if (sum.getSurface() != null) {
tmpSum += sum.getSurface();
}
}
return tmpSum;
}
public long getTotalFootageByMonth(boolean production) {
tmpMap.putAll(getMonthlyData());
if (production) {
tmpMap = this.stripNonProdGrades(tmpMap);
} else {
tmpMap = this.stripProdGrades(tmpMap);
}
long tmpSum = 0;
for (ScannerSummary sum : tmpMap.values()) {
if (sum.getFootage() != null) {
tmpSum += sum.getFootage();
}
}
return tmpSum;
}
public double getPercentageByShiftAndGrade(String shift, String grade, boolean production) {
long totalFootage = getTotalFootageByShift(shift, production);
long gradeFootage = getFootageByShiftAndGrade(shift, grade);
if (totalFootage == 0 || gradeFootage == 0) {
return 0;
} else {
return (double) gradeFootage / totalFootage;
}
}
public double getDailyPercentageByGrade(String grade, boolean production) {
long totalFootage = getTotalFootageByDay(production);
long gradeFootage = getDailyFootageByGrade(grade);
if (totalFootage == 0 || gradeFootage == 0) {
return 0;
} else {
return (double) gradeFootage / totalFootage;
}
}
public double getMonthlyPercentageByGrade(String grade, boolean production) {
long totalFootage = getTotalFootageByMonth(production);
long gradeFootage = getMonthlyFootageByGrade(grade);
if (totalFootage == 0 || gradeFootage == 0) {
return 0;
} else {
return (double) gradeFootage / totalFootage;
}
}
//OTHER FUNCTIONS
public Set<String> getGrades() {
return getShiftData().keySet();
}
private Map<String, ScannerSummary> stripNonProdGrades(Map<String, ScannerSummary> tmpMap) {
List<String> tmpList = new ArrayList();
tmpList.addAll(tmpMap.keySet());
for (String grade : tmpList) {
if (this.summaryFilter.getPlant().getPlantId().equals("P4")) {
if (_nonProductionGradeListP4.contains(grade)) {
tmpMap.remove(grade);
}
} else {
if (_nonProductionGradeListP2.contains(grade)) {
tmpMap.remove(grade);
}
}
}
return tmpMap;
}
private Map<String, ScannerSummary> stripProdGrades(Map<String, ScannerSummary> tmpMap) {
List<String> tmpList = new ArrayList();
tmpList.addAll(tmpMap.keySet());
for (String grade : tmpList) {
if (this.summaryFilter.getPlant().getPlantId().equals("P4")) {
if (!_nonProductionGradeListP4.contains(grade)) {
tmpMap.remove(grade);
}
} else {
if (!_nonProductionGradeListP2.contains(grade)) {
tmpMap.remove(grade);
}
}
}
return tmpMap;
}
private Double roundDoubles(Double numberToRound, int Places) {
BigDecimal bd = new BigDecimal(numberToRound);
bd = bd.setScale(Places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
public Map<String, Map<String, ScannerSummary>> getNonShiftData() {
return nonShiftData;
}
public void setNonShiftData(Map<String, Map<String, ScannerSummary>> nonShiftData) {
this.nonShiftData = nonShiftData;
}
//GET FUNCTIONS
//
public void preLoad() {
}
public Long getNetWidthByShift(String shift, String width) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(tmpReportStart);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(shift);
Long tmpResult = ejbFacade.getNetWidthByShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Long getNetWidthByDate(String width) {
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(null);
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(tmpReportStart);
Long tmpResult = ejbFacade.getNetWidthByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Long getNetWidthByMonth(String width) {
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(null);
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
Long tmpResult = ejbFacade.getNetWidthByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Double getShiftPercentageByWidth(String shift, String width) {
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(shift);
this.getSummaryFilter().setGrade(null);
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(tmpReportStart);
Double tmpResult = ejbFacade.getShiftPercentageByWidth(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Double getDayPercentageByWidth(String width) {
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(null);
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(tmpReportStart);
Double tmpResult = ejbFacade.getDayPercentageByWidth(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Double getMonthPercentageByWidth(String width) {
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(null);
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
Double tmpResult = ejbFacade.getMonthPercentageByWidth(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Long getFootageByGradeWidthAndShift(String grade, String width, String shift) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(shift);
this.getSummaryFilter().setGrade(grade);
Long tmpResult = ejbFacade.getFootageByGradeWidthAndShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Double getPercentageByGradeWidthAndShift(String grade, String width, String shift) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setShift(shift);
this.getSummaryFilter().setGrade(grade);
Double tmpResult = ejbFacade.getPercentageByGradeWidthAndShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.getSummaryFilter().setGrade(null);
return tmpResult;
}
public Long getFootageByDateWidthAndGrade(String width, String grade) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Long tmpResult = ejbFacade.getFootageByDateWidthAndGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getPercentageByDateWidthAndGrade(String width, String grade) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Double tmpResult = ejbFacade.getPercentageByDateWidthAndGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getFootageByMonthWidthAndGrade(String width, String grade) {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Long tmpResult = ejbFacade.getFootageByDateWidthAndGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getPercentageByMonthWidthAndGrade(String width, String grade) {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
this.getSummaryFilter().setWidth(width);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Double tmpResult = ejbFacade.getPercentageByDateWidthAndGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getTotalFootageByGradeAndShift(String grade, String shift) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(shift);
Long tmpResult = this.ejbFacade.getTotalFootageByGradeAndShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getTotalPercentageByGradeAndShift(String grade, String shift) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(shift);
Double tmpResult = this.ejbFacade.getTotalPercentageByGradeAndShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getTotalFootageByGrade(String grade) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Long tmpResult = this.ejbFacade.getTotalFootageByGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getTotalPercentageByGrade(String grade) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Double tmpResult = this.ejbFacade.getTotalPercentageByGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getMonthTotalFootageByGrade(String grade) {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Long tmpResult = this.ejbFacade.getTotalFootageByGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getMonthTotalPercentageByGrade(String grade) {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setShift(null);
Double tmpResult = this.ejbFacade.getTotalPercentageByGrade(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
private List<String> pruneNonProdGrades(List<String> gradeList) {
for (String grade : this.nonProdGradeList) {
if (gradeList.contains(grade)) {
gradeList.remove(grade);
}
}
return gradeList;
}
public List<String> getDistinctGradesByDate() {
List<String> tmpList;
this.getSummaryFilter().setShift(null);
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
tmpList = ejbFacade.getDistinctGradesByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return this.pruneNonProdGrades(tmpList);
}
public Plant getLastShiftPlant() {
if (this.lastShiftPlant == null) {
this.lastShiftPlant = plantFacade.find("3V");
}
return lastShiftPlant;
}
public void setLastShiftPlant(Plant lastShiftPlant) {
this.lastShiftPlant = lastShiftPlant;
}
public List<String> getDistinctWidthByGradeAndDate(String grade) {
this.getSummaryFilter().setGrade(grade);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
List<String> tmpList = this.ejbFacade.getDistinctWidthByGradeAndDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpList;
}
public Long getFootageByShift(String shift) {
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(shift);
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
Long tmpResult = ejbFacade.getFootageByShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getFootageByDate() {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
Long tmpResult = ejbFacade.getFootageByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getFootageByMonth() {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
Long tmpResult = ejbFacade.getFootageByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getTotalNonProductionFootageByShift(String shift) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setShift(shift);
Long tmpResult = ejbFacade.getTotalNonProductionFootageByShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getNonProductionPercentageByShift(String shift) {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
this.getSummaryFilter().setShift(shift);
Double tmpResult = ejbFacade.getNonProductionPercentageByShift(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getTotalNonProductionFootageByDate() {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
Long tmpResult = ejbFacade.getTotalNonProductionFootageByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getNonProductionPercentageByDate() {
this.tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(this.tmpReportStart);
Double tmpResult = ejbFacade.getNonProductionPercentageByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Long getTotalNonProductionFootageByMonth() {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
Long tmpResult = ejbFacade.getTotalNonProductionFootageByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
public Double getNonProductionPercentageByMonth() {
this.tmpReportStart = DateHelper.getSelectedBeginningOfMonth(this.reportEnd);
this.tmpReportEnd = DateHelper.getEndOfSelectedMonth(this.reportEnd);
Double tmpResult = ejbFacade.getNonProductionPercentageByDate(this.getSummaryFilter(), tmpReportStart, tmpReportEnd);
this.getSummaryFilter().setGrade(null);
this.getSummaryFilter().setWidth(null);
this.getSummaryFilter().setShift(null);
return tmpResult;
}
//
public List<String> getDistinctWidthByPlant(Plant plant) {
List<String> tmpList;
tmpList = ejbFacade.getDisntinctWidthByPlant(plant);
return tmpList;
}
public List<String> getDistinctShiftByPlant(Plant plant) {
Plant tmpPlant = plant;
if (this.distinctShift == null || !plant.getPlantId().equals(this.lastShiftPlant.getPlantId())) {
distinctShift = ejbFacade.getDistinctShiftByPlant(plant);
}
this.shiftLabelSize = this.distinctShift.size() * 4;
this.groupCount = this.distinctShift.size() + 2;
//
this.lastShiftPlant = plant;
//
return this.distinctShift;
}
public List<String> getDistinctShiftByPlantAndDateRange(Plant plant) {
Plant tmpPlant = plant;
this.tmpReportStart = DateHelper.setBeginningOfDayTime(this.reportEnd);
this.tmpReportEnd = DateHelper.setEndOfDayTime(tmpReportStart);
if (this.distinctShift == null || !plant.getPlantId().equals(getLastShiftPlant().getPlantId()) || !DateHelper.sameDay(tmpReportStart, this.lastShiftDate) ) {
distinctShift = ejbFacade.getDistinctShiftByPlantAndDateRange(plant, tmpReportStart, tmpReportEnd);
}
this.shiftLabelSize = this.distinctShift.size() * 4;
this.groupCount = this.distinctShift.size() + 2;
this.lastShiftPlant = plant;
this.lastShiftDate = tmpReportStart;
return this.distinctShift;
}
public List<String> getDistinctGradeList() {
return getFacade().getDistinctGrade();
}
public SelectItem[] getDistinctShiftSelect() {
List<String> shift = getFacade().getDistinctShift();
int size = shift.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : shift) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public SelectItem[] getPlantsWithScanners() {
List<Plant> tmpList = new ArrayList<>();
Plant tmpPlant = plantFacade.find("P2");
if (currentUserAuthForPlant(tmpPlant)) {
tmpList.add(tmpPlant);
}
tmpPlant = plantFacade.find("P4");
if (currentUserAuthForPlant(tmpPlant)) {
tmpList.add(tmpPlant);
}
int size = tmpList.size();
SelectItem[] selects = new SelectItem[size];
int i = 0;
for (Plant p : tmpList) {
selects[i++] = new SelectItem(p, p.getPlantName());
}
return selects;
}
public SelectItem[] getDistinctSpeciesSelect() {
List<String> list = getFacade().getDistinctSpecies();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : list) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public SelectItem[] getDistinctSourceSelect() {
List<String> list = getFacade().getDistinctSource();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : list) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public List<String> getDistinctGradesByFilter() {
getSummaryFilter().setGrade(null);
getSummaryFilter().setShift(null);
Date tmpEnd = DateHelper.setEndOfDayTime(reportEnd);
List<String> gradeList = getFacade().getDistinctGradesByFilter(getSummaryFilter(), reportEnd, tmpEnd);
if (this.summaryFilter.getPlant().getPlantId().equals("P4")) {
for (String grade : _nonProductionGradeListP4) {
if (gradeList.contains(grade)) {
gradeList.remove(grade);
if (!_nonProductionGradeListP4.contains(grade)) {
_nonProductionGradeListP4.add(grade);
}
}
}
} else {
for (String grade : _nonProductionGradeListP2) {
if (gradeList.contains(grade)) {
gradeList.remove(grade);
if (!_nonProductionGradeListP2.contains(grade)) {
_nonProductionGradeListP2.add(grade);
}
}
}
}
return gradeList;
}
public List<String> getNonProdGrades(Plant plant) {
if (this.summaryFilter.getPlant().getPlantId().equals("P4")) {
return this._nonProductionGradeListP4;
} else {
return this._nonProductionGradeListP2;
}
}
//BUILDING SELECTS
public SelectItem[] getDistinctWidthSelectByPlant(Plant plant) {
List<String> tmpList = new ArrayList();
tmpList = ejbFacade.getDisntinctWidthSelectByPlant(plant);
int size = tmpList.size();
SelectItem[] selects = new SelectItem[size + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String width : tmpList) {
selects[i++] = new SelectItem(width, width);
}
return selects;
}
public SelectItem[] getDistinctLengthSelectByPlant(Plant plant) {
List<Integer> tmpList = new ArrayList();
tmpList = ejbFacade.getDisntinctLengthSelectByPlant(plant);
int size = tmpList.size();
SelectItem[] selects = new SelectItem[size + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Integer length : tmpList) {
selects[i++] = new SelectItem(length, Integer.toString(length));
}
return selects;
}
public SelectItem[] getDistinctThicknessSelectByPlant(Plant plant) {
List<Double> tmpList = new ArrayList();
tmpList = ejbFacade.getDisntinctThicknessSelectByPlant(plant);
int size = tmpList.size();
SelectItem[] selects = new SelectItem[size + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Double thick : tmpList) {
selects[i++] = new SelectItem(thick, Double.toString(thick));
}
return selects;
}
public SelectItem[] getDistinctSpecieSelectByPlant(Plant plant) {
List<String> tmpList = new ArrayList();
tmpList = ejbFacade.getDisntinctSpecieSelectByPlant(plant);
int size = tmpList.size();
SelectItem[] selects = new SelectItem[size + 1];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String specie : tmpList) {
selects[i++] = new SelectItem(specie, specie);
}
return selects;
}
public SelectItem[] getDistinctGradeSelect() {
List<String> list = getFacade().getDistinctGrade();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : list) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public SelectItem[] getDistinctDryerSelect() {
List<String> list = getFacade().getDistinctDryer();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : list) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public SelectItem[] getDistinctWidthSelect() {
List<String> list = getFacade().getDistinctWidth();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : list) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public SelectItem[] getDistinctLengthSelect() {
List<Integer> list = getFacade().getDistinctLength();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Integer x : list) {
selects[i++] = new SelectItem(x, Integer.toString(x));
}
return selects;
}
public SelectItem[] getDistinctMoistureSelect() {
List<String> list = getFacade().getDistinctMoisture();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (String x : list) {
selects[i++] = new SelectItem(x, x);
}
return selects;
}
public SelectItem[] getDistinctThicknessSelect() {
List<Double> list = getFacade().getDistinctThickness();
int size = list.size() + 1;
SelectItem[] selects = new SelectItem[size];
selects[0] = new SelectItem("", "---");
int i = 1;
for (Double x : list) {
selects[i++] = new SelectItem(x, String.format("%.3f", x));
}
return selects;
}
private Date minusThreeMonths() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.MONTH, -3);
return c.getTime();
}
public String setReportFilter() {
this.shiftData = null;
this.dailyData = null;
this.monthlyData = null;
return _scannerSummaryPage;
}
public Date getReportStart() {
return reportStart;
}
public void setReportStart(Date reportStart) {
this.reportStart = reportStart;
}
public Date getReportEnd() {
return reportEnd;
}
public void setReportEnd(Date reportEnd) {
this.reportEnd = reportEnd;
}
public int getGroupCount() {
if (this.groupCount == 0) {
this.getDistinctShiftByPlantAndDateRange(getSummaryFilter().getPlant());
}
return this.groupCount;
}
public void setGroupCount(int groupCount) {
this.groupCount = groupCount;
}
public int getShiftLabelSize() {
if (shiftLabelSize == 0) {
this.getDistinctShiftByPlant(this.summaryFilter.getPlant());
};
return shiftLabelSize;
}
public List<String> getDistinctShift() {
return distinctShift;
}
public void setDistinctShift(List<String> distinctShift) {
this.distinctShift = distinctShift;
}
public void setShiftLabelSize(int shiftLabelSize) {
this.shiftLabelSize = shiftLabelSize;
}
private boolean currentUserAuthForPlant(Plant plant) {
List<Plant> authPlant = userFacade.findAuthorizedPlants(getCurrentUser(), null);
return authPlant.contains(plant);
}
private String getCurrentUser() {
Principal prin = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
return prin.getName();
}
private Date getMaxDateFromScannerTable() {
Date maxDate = this.ejbFacade.getMaxDateFromTable();
if (maxDate == null) {
maxDate = new Date();
}
return maxDate;
}
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(10) {
@Override
public int getItemsCount() {
return getFacade().count();
}
@Override
public DataModel createPageDataModel() {
return new ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
}
};
}
return pagination;
}
public String prepareList() {
recreateModel();
this.reportEnd = new Date();
this.reportStart = minusThreeMonths();
this.maxRows = 100;
return "summaryList";
}
public String prepareView() {
current = (ScannerSummary) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "View";
}
public String prepareCreate() {
current = new ScannerSummary();
selectedItemIndex = -1;
return "Create";
}
public String create() {
try {
getFacade().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle/hp").getString("ScannerSummaryCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle/hp").getString("PersistenceErrorOccured"));
return null;
}
}
public String prepareEdit() {
current = (ScannerSummary) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "Edit";
}
public String update() {
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle/hp").getString("ScannerSummaryUpdated"));
return "View";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle/hp").getString("PersistenceErrorOccured"));
return null;
}
}
public String destroy() {
current = (ScannerSummary) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
performDestroy();
recreatePagination();
recreateModel();
return "List";
}
public String destroyAndView() {
performDestroy();
recreateModel();
updateCurrentItem();
if (selectedItemIndex >= 0) {
return "View";
} else {
recreateModel();
return "List";
}
}
private void performDestroy() {
try {
getFacade().remove(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle/hp").getString("ScannerSummaryDeleted"));
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle/hp").getString("PersistenceErrorOccured"));
}
}
private void updateCurrentItem() {
int count = getFacade().count();
if (selectedItemIndex >= count) {
selectedItemIndex = count - 1;
if (pagination.getPageFirstItem() >= count) {
pagination.previousPage();
}
}
if (selectedItemIndex >= 0) {
current = getFacade().findRange(new int[]{selectedItemIndex, selectedItemIndex + 1}).get(0);
}
}
public List<ScannerSummary> getItemList() {
if (itemList == null) {
itemList = getFacade().getItemListLimitedBy(maxRows);
}
return itemList;
}
public List<ScannerSummary> getItemListLimitBy() {
return getFacade().getItemListLimitedBy(100);
}
public int getMaxRows() {
return maxRows;
}
public void setMaxRows(int maxRows) {
this.maxRows = maxRows;
}
public ScannerSummary getSummaryFilter() {
if (summaryFilter == null) {
summaryFilter = new ScannerSummary();
summaryFilter.setPlant(plantFacade.find("P4"));
}
return summaryFilter;
}
public void setSummaryFilter(ScannerSummary summaryFilter) {
this.summaryFilter = summaryFilter;
}
public void setItemList(List<ScannerSummary> itemList) {
this.itemList = itemList;
}
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
private void recreateModel() {
items = null;
}
private void recreatePagination() {
pagination = null;
}
public ScannerSummary getCurrent() {
return current;
}
public void setCurrent(ScannerSummary current) {
this.current = current;
}
public String next() {
getPagination().nextPage();
recreateModel();
return "List";
}
public String previous() {
getPagination().previousPage();
recreateModel();
return "List";
}
public SelectItem[] getItemsAvailableSelectMany() {
return JsfUtil.getSelectItems(ejbFacade.findAll(), false);
}
public SelectItem[] getItemsAvailableSelectOne() {
return JsfUtil.getSelectItems(ejbFacade.findAll(), true);
}
public ScannerSummary getScannerSummary(java.lang.Integer id) {
return ejbFacade.find(id);
}
private Map<String, Map<String, ScannerSummary>> getShiftData() {
reportStart = DateHelper.setBeginningOfDayTime(reportEnd);
reportEnd = DateHelper.setBeginningOfDayTime(reportEnd);
if (this.shiftData == null) {
this.shiftData = ejbFacade.getShiftProductionMap(getSummaryFilter(), reportStart, reportEnd);
}
return this.shiftData;
}
public Map<String, ScannerSummary> getDailyData() {
Date tmpReportStart = DateHelper.setBeginningOfDayTime(reportEnd);
reportEnd = DateHelper.setBeginningOfDayTime(reportEnd);
if (dailyData == null) {
dailyData = ejbFacade.getProductionMap(getSummaryFilter(), tmpReportStart, reportEnd);
}
return dailyData;
}
public Map<String, ScannerSummary> getMonthlyData() {
reportStart = DateHelper.getSelectedBeginningOfMonth(reportEnd);
reportEnd = DateHelper.setBeginningOfDayTime(reportEnd);
if (monthlyData == null) {
monthlyData = ejbFacade.getProductionMap(getSummaryFilter(), reportStart, reportEnd);
}
return monthlyData;
}
/**
* @return the gradesFilter
*/
public ScannerSummary getGradesFilter() {
if(this.gradesFilter == null) this.gradesFilter = new ScannerSummary();
return gradesFilter;
}
/**
* @param gradesFilter the gradesFilter to set
*/
public void setGradesFilter(ScannerSummary gradesFilter) {
this.gradesFilter = gradesFilter;
}
/**
* @return the lastGradesList
*/
public List<String> getLastGradesList() {
return lastGradesList;
}
/**
* @param lastGradesList the lastGradesList to set
*/
public void setLastGradesList(List<String> lastGradesList) {
this.lastGradesList = lastGradesList;
}
/**
* @return the lastShiftDate
*/
public Date getLastShiftDate() {
if(this.lastShiftDate == null) this.lastShiftDate = DateHelper.getDateMinusMonth(-5);
return lastShiftDate;
}
/**
* @param lastShiftDate the lastShiftDate to set
*/
public void setLastShiftDate(Date lastShiftDate) {
this.lastShiftDate = lastShiftDate;
}
@FacesConverter(forClass = ScannerSummary.class)
public static class ScannerSummaryControllerConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
ScannerSummaryController controller = (ScannerSummaryController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "scannerSummaryController");
return controller.getScannerSummary(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuilder sb = new StringBuilder();
sb.append(value);
return sb.toString();
}
@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof ScannerSummary) {
ScannerSummary o = (ScannerSummary) object;
return getStringKey(o.getSummaryId());
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + ScannerSummary.class.getName());
}
}
}
public LineChartModel getTestData()
{
if(this.testData == null)
{
this.createTestData();
}
return testData;
}
public void createTestData()
{
testData = new LineChartModel();
LineChartSeries series1 = new LineChartSeries();
series1.setLabel("Series 1");
series1.set("2014-01-01", 51);
series1.set("2014-01-06", 22);
series1.set("2014-01-12", 65);
series1.set("2014-01-18", 74);
series1.set("2014-01-24", 24);
series1.set("2014-01-30", 51);
LineChartSeries series2 = new LineChartSeries();
series2.setLabel("Series 3");
series2.set("2014-01-01", 32);
series2.set("2014-01-06", 73);
series2.set("2014-01-12", 24);
series2.set("2014-01-18", 12);
series2.set("2014-01-24", 74);
series2.set("2014-01-30", 62);
testData.addSeries(series1);
testData.addSeries(series2);
testData.setTitle("Zoom for Details");
testData.setZoom(true);
testData.getAxis(AxisType.Y).setLabel("Values");
DateAxis axis = new DateAxis("Dates");
axis.setTickAngle(-50);
axis.setMax("2014-02-01");
axis.setTickFormat("%b %#d, %y");
testData.getAxes().put(AxisType.X, axis);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment