blob: 1ab989e310421d06e8c47a140c271d3821864328 [file] [log] [blame]
/*
*
* Copyright (c) 2011 - 2016 - Loetz GmbH & Co KG, 69115 Heidelberg, Germany
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Initial contribution:
* Loetz GmbH & Co. KG
*
*/
package org.eclipse.osbp.abstractstatemachine;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import jpos.BaseControl;
import jpos.CashDrawer;
import jpos.CashDrawerConst;
import jpos.CashDrawerControl114;
import jpos.JposException;
import jpos.LineDisplay;
import jpos.LineDisplayConst;
import jpos.LineDisplayControl114;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
import jpos.POSPrinterControl114;
import jpos.config.JposEntry.Prop;
import jpos.config.JposEntryRegistry;
import jpos.config.simple.SimpleEntry;
import jpos.epson.EpsonLineDisplayConst;
import jpos.epson.EpsonPOSPrinterConst;
import jpos.events.ErrorEvent;
import jpos.events.ErrorListener;
import jpos.events.OutputCompleteEvent;
import jpos.events.OutputCompleteListener;
import jpos.events.StatusUpdateEvent;
import jpos.events.StatusUpdateListener;
import jpos.loader.simple.SimpleServiceManager;
import jpos.util.DefaultProperties;
import jpos.util.JposProperties;
import jpos.util.JposPropertiesConst;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.osbp.preferences.ProductConfiguration;
import org.eclipse.osbp.ui.api.datamart.IDataMart;
import org.eclipse.osbp.ui.api.message.MessageEvent;
import org.eclipse.osbp.ui.api.message.MessageEvent.EventType;
import org.eclipse.osbp.ui.api.pos.IZVTTransactionData;
import org.eclipse.osbp.ui.api.statemachine.IPeripheral;
import org.eclipse.osbp.ui.api.statemachine.IStateMachine;
import org.osgi.framework.FrameworkUtil;
/**
* PeripheralService is a bridge between javaPOS and the state machine participant.
*/
public abstract class AbstractPeripheralService extends AbstractStateMachineParticipant
implements IPeripheral, IPeripheral.Command, StatusUpdateListener,
ErrorListener, OutputCompleteListener {
/** The devices. */
protected Map<String, BaseControl> devices = new HashMap<>();
private boolean slipNotificationsEnabled = false;
private boolean devicesInit = false;
private int windowsCreated = 0;
private String ptIP;
private Integer ptPort;
/*
* (non-Javadoc)
*
* @see
* foodmartdialogdslplugin.AbstractStateMachineParticipant#setStatemachine
* (org.eclipse.osbp.ui.api.abstractstatemachine.IStateMachine)
*/
@Override
public void setStatemachine(IStateMachine statemachine) {
super.setStatemachine(statemachine);
statemachine.registerPeripheral(this);
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().setStatemachine(statemachine);
}
}
/*
* (non-Javadoc)
*
* @see foodmartdialogdslplugin.AbstractStateMachineParticipant#init()
*/
@Override
public void init() {
initDevices();
}
/* (non-Javadoc)
* @see org.eclipse.osbp.ui.api.statemachine.IPeripheral#initDevices()
*/
@Override
public void initDevices() {
if(!devicesInit) {
// load all names of configured devices, instantiate and cache it
String configFile = ProductConfiguration.getJavaPosConfiguration();
try {
new URL(configFile);
System.setProperty(
JposPropertiesConst.JPOS_POPULATOR_FILE_URL_PROP_NAME,
configFile);
} catch (MalformedURLException e) {
System.setProperty(
JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME,
configFile);
}
System.setProperty(
JposPropertiesConst.JPOS_REG_POPULATOR_CLASS_PROP_NAME,
"jpos.config.simple.xml.SimpleXmlRegPopulator");
System.setProperty(
JposPropertiesConst.JPOS_SERVICE_MANAGER_CLASS_PROP_NAME,
"jpos.loader.simple.SimpleServiceManager");
JposProperties jposProperties = new DefaultProperties();
jposProperties.loadJposProperties();
SimpleServiceManager serviceManager = new SimpleServiceManager(
jposProperties);
serviceManager.getEntryRegistry().load();
JposEntryRegistry props = serviceManager.getEntryRegistry();
Enumeration<?> propsIterator = props.getEntries();
while (propsIterator.hasMoreElements()) {
SimpleEntry deviceEntry = (SimpleEntry) propsIterator.nextElement();
Prop category = deviceEntry.getProp("deviceCategory");
String deviceClassName = "jpos." + category.getValueAsString();
try {
Class<?> deviceClass = Class.forName(deviceClassName);
Constructor<?> ctor = deviceClass.getConstructor();
BaseControl device = (BaseControl) ctor.newInstance();
try {
// Open the device.
device.open(deviceEntry.getLogicalName());
// Get the exclusive control right for the opened device.
// Then the device is disabled from other application.
device.claim(1000);
// Enable the device.
device.setDeviceEnabled(true);
// add status listener
if (device instanceof CashDrawer) {
((CashDrawer) device).addStatusUpdateListener(this);
}
if (device instanceof POSPrinter) {
((POSPrinter) device).addStatusUpdateListener(this);
((POSPrinter) device).addErrorListener(this);
((POSPrinter) device).addOutputCompleteListener(this);
// Even if using any printers, 0.01mm unit makes it
// possible to print neatly.
((POSPrinter) device)
.setMapMode(POSPrinterConst.PTR_MM_METRIC);
// Output by the high quality mode
((POSPrinter) device).setRecLetterQuality(true);
// 2mm spaces
((POSPrinter) device).printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|200uF");
}
} catch (JposException ex) {
LOGGER.error("device init error: {}", ex);
}
devices.put(deviceEntry.getLogicalName(), device);
} catch (Exception e) {
LOGGER.error("Error creating instance of specified device class:"
+ deviceClassName);
}
}
if(getPTIP() != null) {
if(POSServiceBinder.getPosService() != null) {
if(!POSServiceBinder.getPosService().openZVTChannel(getPTIP(), getPTPort())) {
LOGGER.error("could not open ZVT socket");
}
}
}
devicesInit = true;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.osbp.ui.api.abstractstatemachine.IPeripheral#releaseDevices()
*/
@Override
public void releaseDevices() {
if(devicesInit) {
for (String deviceName : devices.keySet()) {
try {
if (devices.get(deviceName) instanceof LineDisplay) {
try {
if(windowsCreated > 0) {
((LineDisplay) devices.get(deviceName)).destroyWindow();
}
} catch (JposException e) {}
((LineDisplay) devices.get(deviceName)).clearText();
}
devices.get(deviceName).setDeviceEnabled(false);
if (devices.get(deviceName) instanceof CashDrawer) {
((CashDrawer) devices.get(deviceName))
.removeStatusUpdateListener(this);
}
if (devices.get(deviceName) instanceof POSPrinter) {
((POSPrinter) devices.get(deviceName))
.removeStatusUpdateListener(this);
}
devices.get(deviceName).release();
devices.get(deviceName).close();
} catch (JposException e) {
LOGGER.error("Error releasing device:" + deviceName);
}
}
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().closeZVTChannel();
}
windowsCreated = 0;
devicesInit = false;
}
}
// line display code
/**
* Sets the display line.
*
* @param displayLine
* the new display line
*/
public void setDisplayLine(String displayLine) {
String[] parts = displayLine.split("\\|");
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
if (parts.length > 1) {
((LineDisplay) devices.get(device)).displayText(
parts[0], new Integer(parts[1].trim()));
} else {
((LineDisplay) devices.get(device)).displayText(
parts[0], LineDisplayConst.DISP_DT_NORMAL);
}
} catch (JposException e) {
LOGGER.error("error displayLine for device:" + device
+ " and text:" + displayLine + " {}", e);
} catch (Exception ex) {
LOGGER.error("general error displayLine for device:"
+ device + " text:" + displayLine + " {}", ex);
}
}
}
}
/**
* Registers a bitmap.
*
* @param registerBitmap
* encodes a pipe separated tuple bitmapNumber, bitmapFilename
*/
public void setRegisterBitmap(String registerBitmap) {
String[] parts = registerBitmap.split("\\|");
String path = null;
File file = null;
try {
// get absolute physical path of bundle
file = FileLocator.getBundleFile(FrameworkUtil.getBundle(this.getClass()));
} catch (IOException e) {
LOGGER.error("jpos error setRegisterBitmap:" + registerBitmap + " {}", e);
return;
}
if(file != null) {
path = file.getAbsolutePath()+"/"+parts[1];
}
if(path != null) {
for (String device : devices.keySet()) {
try {
if (devices.get(device) instanceof LineDisplay) {
if (((LineDisplayControl114) devices.get(device))
.getCapBitmap() == true) {
((LineDisplayControl114) devices.get(device))
.setBitmap(new Integer(parts[0]), parts[1],
LineDisplayConst.DISP_BM_ASIS,
LineDisplayConst.DISP_BM_LEFT,
LineDisplayConst.DISP_BM_TOP);
}
}
if (devices.get(device) instanceof POSPrinter) {
if (((POSPrinterControl114) devices.get(device))
.getCapRecBitmap() == true) {
int lineWidth = ((POSPrinterControl114) devices
.get(device)).getRecLineWidth();
((POSPrinterControl114) devices.get(device)).setBitmap(
new Integer(parts[0]),
POSPrinterConst.PTR_S_RECEIPT, path,
lineWidth / 2, POSPrinterConst.PTR_BM_CENTER);
}
}
} catch (JposException e) {
LOGGER.error("jpos error setRegisterBitmap for device:"
+ device + " and:" + registerBitmap + " {}", e);
} catch (Exception ex) {
LOGGER.error("general error registerBitmap for device:"
+ device + " text:" + registerBitmap + " {}", ex);
}
}
}
}
/**
* Sets the display bitmap.
*
* @param displayBitmap
* the new display bitmap
*/
public void setDisplayBitmap(Integer displayBitmap) {
String text = String.format("\\u%03db|%dB", displayBitmap,
displayBitmap);
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
int[] pram2 = new int[1];
Object pram3 = new Object();
((LineDisplayControl114) devices.get(device))
.directIO(EpsonLineDisplayConst.DISP_DI_GRAPHIC,
pram2, pram3);
((LineDisplayControl114) devices.get(device)).createWindow(
0, 0, 64, 256, 64, 256);
((LineDisplayControl114) devices.get(device)).displayText(
text, LineDisplayConst.DISP_DT_NORMAL);
} catch (JposException e) {
LOGGER.error("jpos error setDisplayBitmap for device:"
+ device + " and:" + displayBitmap + " {}", e);
}
}
}
}
/**
* Sets the device brightness.
*
* @param deviceBrightness
* the new device brightness
*/
public void setDeviceBrightness(Integer deviceBrightness) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setDeviceBrightness(deviceBrightness);
} catch (JposException e) {
LOGGER.error("jpos error deviceBrightness for device:"
+ device + " and:" + deviceBrightness + " {}", e);
}
}
}
}
/**
* Sets the blink rate.
*
* @param blinkRate
* the new blink rate
*/
public void setBlinkRate(Integer blinkRate) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setBlinkRate(blinkRate);
} catch (JposException e) {
LOGGER.error("jpos error blinkRate for device:" + device
+ " and:" + blinkRate + " {}", e);
}
}
}
}
/**
* Sets the cursor type.
*
* @param cursorType
* see: LineDisplayConst
*/
public void setCursorType(Integer cursorType) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setCursorType(cursorType);
} catch (JposException e) {
LOGGER.error("jpos error cursorType for device:" + device
+ " and:" + cursorType + " {}", e);
}
}
}
}
/**
* Sets the marquee format.
*
* @param marqueeFormat
* the new marquee format
*/
public void setMarqueeFormat(Integer marqueeFormat) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setMarqueeFormat(marqueeFormat);
} catch (JposException e) {
LOGGER.error("jpos error marqueeFormat for device:"
+ device + " and:" + marqueeFormat + " {}", e);
}
}
}
}
/**
* Sets the marquee repeat wait.
*
* @param marqueeRepeatWait
* the new marquee repeat wait
*/
public void setMarqueeRepeatWait(Integer marqueeRepeatWait) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setMarqueeRepeatWait(marqueeRepeatWait);
} catch (JposException e) {
LOGGER.error("jpos error marqueeRepeatWait for device:"
+ device + " and:" + marqueeRepeatWait + " {}", e);
}
}
}
}
/**
* Sets the marquee type.
*
* @param marqueeType
* the new marquee type
*/
public void setMarqueeType(Integer marqueeType) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setMarqueeType(marqueeType);
} catch (JposException e) {
LOGGER.error("jpos error marqueeType for device:" + device
+ " and:" + marqueeType + " {}", e);
}
}
}
}
/**
* Sets the marquee unit wait.
*
* @param marqueeUnitWait
* the new marquee unit wait
*/
public void setMarqueeUnitWait(Integer marqueeUnitWait) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setMarqueeUnitWait(marqueeUnitWait);
} catch (JposException e) {
LOGGER.error("jpos error marqueeUnitWait for device:"
+ device + " and:" + marqueeUnitWait + " {}", e);
}
}
}
}
/**
* wraps: createWindow(int viewportRow, int viewportColumn, int
* viewportHeight , int viewportWidth, int windowHeight, int windowWidth);.
*
* @param createWindow
* the new creates the window
*/
public void setCreateWindow(String createWindow) {
String[] parts = createWindow.split("\\|");
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device)).createWindow(
new Integer(parts[0].trim()),
new Integer(parts[1].trim()),
new Integer(parts[2].trim()),
new Integer(parts[3].trim()),
new Integer(parts[4].trim()),
new Integer(parts[5].trim()));
windowsCreated ++;
} catch (JposException e) {
LOGGER.error("jpos error createWindow for device:" + device
+ " and:" + createWindow + " {}", e);
} catch (Exception ex) {
LOGGER.error("general error createWindow for device:"
+ device + " text:" + createWindow + " {}", ex);
}
}
}
}
/**
* Sets the destroy window.
*
* @param destroyWindow
* the new destroy window
*/
public void setDestroyWindow(String destroyWindow) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
if(windowsCreated > 0) {
((LineDisplayControl114) devices.get(device)).destroyWindow();
windowsCreated --;
}
} catch (JposException e) {
LOGGER.error("jpos error destroyWindow for device:"
+ device + " {}", e);
}
}
}
}
/**
* Sets the scroll.
*
* @param scroll
* encodes a pipe separated tuple: direction, units
*/
public void setScroll(String scroll) {
String[] parts = scroll.split("\\|");
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device)).scrollText(
new Integer(parts[0].trim()),
new Integer(parts[1].trim()));
} catch (JposException e) {
LOGGER.error("jpos error scroll for device:" + device
+ " and:" + scroll + " {}", e);
} catch (Exception ex) {
LOGGER.error("general error scroll for device:" + device
+ " text:" + scroll + " {}", ex);
}
}
}
}
/**
* Sets the inter character wait.
*
* @param interCharacterWait
* the new inter character wait
*/
public void setInterCharacterWait(Integer interCharacterWait) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
((LineDisplayControl114) devices.get(device))
.setInterCharacterWait(interCharacterWait);
} catch (JposException e) {
LOGGER.error("jpos error interCharacterWait for device:"
+ device + " and:" + interCharacterWait + " {}", e);
}
}
}
}
/**
* Sets the display at.
*
* @param displayTextAt
* encodes a pipe separated quadruple: row, column, text,
* attribute
*/
public void setDisplayTextAt(String displayTextAt) {
String[] parts = displayTextAt.split("\\|");
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
if (parts.length > 3) {
((LineDisplayControl114) devices.get(device))
.displayTextAt(new Integer(parts[0].trim()),
new Integer(parts[1].trim()), parts[2],
new Integer(parts[3].trim()));
} else {
((LineDisplayControl114) devices.get(device))
.displayTextAt(new Integer(parts[0].trim()),
new Integer(parts[1].trim()), parts[2],
LineDisplayConst.DISP_DT_NORMAL);
}
} catch (JposException e) {
LOGGER.error("jpos error displayTextAt for device:"
+ device + " and:" + displayTextAt + " {}", e);
} catch (Exception ex) {
LOGGER.error("general error displayTextAt for device:"
+ device + " text:" + displayTextAt + " {}", ex);
}
}
}
}
/**
* clears the display.
*
* @param clearDisplay is nt used
*/
public void setClearDisplay(String clearDisplay) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof LineDisplay) {
try {
if(windowsCreated > 0) {
((LineDisplayControl114) devices.get(device)).destroyWindow();
windowsCreated --;
}
((LineDisplayControl114) devices.get(device)).clearText();
} catch (JposException e) {
LOGGER.error("jpos error clearDisplay for device:" + device
+ " {}", e);
}
}
}
}
/**
* opens the drawer.
*
* @param openDrawer is ignored
*/
public void setOpenDrawer(Integer openDrawer) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof CashDrawer) {
try {
((CashDrawerControl114) devices.get(device)).openDrawer();
} catch (JposException e) {
LOGGER.error("jpos error openDrawer for device:" + device
+ " {}", e);
}
}
}
}
/**
* prints to receipt printer in normal mode.
*
* @param printNormal text to print
*/
public void setPrintNormal(String printNormal) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof POSPrinter) {
try {
((POSPrinterControl114) devices.get(device)).printNormal(
POSPrinterConst.PTR_S_RECEIPT, printNormal);
} catch (JposException e) {
LOGGER.error("jpos error printNormal for device:" + device
+ " {}", e);
}
}
}
}
/**
* prints footer, feeds paper and cuts.
*
* @param footer the text to print as footer
*/
public void setPrintCut(String footer) {
for (String device : devices.keySet()) {
if (devices.get(device) instanceof POSPrinter) {
try {
if (!footer.isEmpty()) {
((POSPrinterControl114) devices.get(device))
.printNormal(POSPrinterConst.PTR_S_RECEIPT,
footer);
}
// Feed the receipt to the cutter position automatically,
// and cut.
((POSPrinterControl114) devices.get(device)).printNormal(
POSPrinterConst.PTR_S_RECEIPT,
"\u001b|"
+ (((POSPrinterControl114) devices
.get(device))
.getRecLinesToPaperCut()) + "lF");
if (((POSPrinterControl114) devices.get(device))
.getCapRecPapercut() == true)
((POSPrinterControl114) devices.get(device))
.cutPaper(100);
} catch (JposException e) {
LOGGER.error("jpos error printCut for device:" + device
+ " {}", e);
}
}
}
}
/**
* print a pre-loaded bitmap.
*
* @param printBitmap the bitmap-id to print
*/
public void setPrintBitmap(Integer printBitmap) {
String text = String.format("\u001b|%dB", printBitmap);
for (String device : devices.keySet()) {
if (devices.get(device) instanceof POSPrinter) {
try {
if (((POSPrinterControl114) devices.get(device)).getCapRecBitmap() == true) {
int []pram2 = new int[1];
pram2[0] = EpsonPOSPrinterConst.PTR_DI_BITMAP_PRINTING_MULTI_TONE;
((POSPrinterControl114) devices.get(device)).directIO(EpsonPOSPrinterConst.PTR_DI_SET_BITMAP_PRINTING_TYPE, pram2, "");
((POSPrinterControl114) devices.get(device)).printNormal(
POSPrinterConst.PTR_S_RECEIPT, text);
pram2[0] = EpsonPOSPrinterConst.PTR_DI_BITMAP_PRINTING_NORMAL;
((POSPrinterControl114) devices.get(device)).directIO(EpsonPOSPrinterConst.PTR_DI_SET_BITMAP_PRINTING_TYPE, pram2, "");
}
} catch (JposException e) {
LOGGER.error("jpos error setPrintBitmap for device:"
+ device + " and:" + printBitmap + " {}", e);
}
}
}
}
/**
* prints a barcode.
*
* @param data the barcode with pipe encoded barcode-type from jpos.POSPrinterConst
*/
public void setPrintBarcode(String data) {
String[] parts = data.split("\\|");
for (String device : devices.keySet()) {
if (devices.get(device) instanceof POSPrinter) {
try {
if (((POSPrinterControl114) devices.get(device)).getCapRecBarCode() == true) {
// 5mm spaces
((POSPrinterControl114) devices.get(device)).printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|500uF");
((POSPrinterControl114) devices.get(device)).printBarCode(POSPrinterConst.PTR_S_RECEIPT, parts[0], new Integer(parts[1].trim()),
1000, ((POSPrinterControl114) devices.get(device)).getRecLineWidth(), POSPrinterConst.PTR_BC_CENTER,
POSPrinterConst.PTR_BC_TEXT_BELOW);
// 2mm spaces
((POSPrinterControl114) devices.get(device)).printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|200uF");
}
} catch (JposException e) {
LOGGER.error("jpos error setPrintBitmap for device:"
+ device + " and:" + data + " {}", e);
}
}
}
}
public void setSlipNotificationsEnabled(boolean slipNotificationsEnabled) {
this.slipNotificationsEnabled = slipNotificationsEnabled;
}
public boolean isSlipNotificationsEnabled() {
return slipNotificationsEnabled;
}
@Override
public void statusUpdateOccurred(StatusUpdateEvent e) {
Object source = e.getSource();
if (source instanceof CashDrawer) {
switch (e.getStatus()) {
case CashDrawerConst.CASH_SUE_DRAWERCLOSED: // Drawer is closed.
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "drawerOpen"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.TRIGGER, "onDrawerClosed"));
}
break;
case CashDrawerConst.CASH_SUE_DRAWEROPEN: // Drawer is opened.
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "drawerOpen"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.TRIGGER, "onDrawerOpened"));
}
break;
}
}
if (source instanceof POSPrinter) {
switch (e.getStatus()) {
case POSPrinterConst.PTR_SUE_COVER_OPEN:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "coverOpen"));
}
break;
case POSPrinterConst.PTR_SUE_COVER_OK:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "coverOpen"));
}
break;
case POSPrinterConst.PTR_SUE_REC_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "receiptEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_REC_PAPEROK:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "receiptEmpty"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "receiptNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_REC_NEAREMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "receiptNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_EMPTY:
if (statemachine != null && slipNotificationsEnabled) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "slipEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_PAPEROK:
if (statemachine != null && slipNotificationsEnabled) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "slipEmpty"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "slipNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_NEAREMPTY:
if (statemachine != null && slipNotificationsEnabled) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "slipNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "journalEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_PAPEROK:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "journalEmpty"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "journalNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_NEAREMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "journalNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_REC_CARTRIDGE_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "receiptCartridgeEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_REC_CARTRIDGE_NEAREMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "receiptCartridgeNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_REC_HEAD_CLEANING:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "receiptHeadCleaning"));
}
break;
case POSPrinterConst.PTR_SUE_REC_CARTDRIGE_OK:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "receiptCartridgeEmpty"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "receiptHeadCleaning"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "receiptCartridgeNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_CARTRIDGE_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "slipCartridgeEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_CARTRIDGE_NEAREMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "slipCartridgeNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_HEAD_CLEANING:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "slipHeadCleaning"));
}
break;
case POSPrinterConst.PTR_SUE_SLP_CARTDRIGE_OK:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "slipCartridgeEmpty"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "slipHeadCleaning"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "slipCartridgeNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_CARTRIDGE_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGEOPEN, "journalCartridgeEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_CARTRIDGE_NEAREMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "journalCartridgeNearEmpty"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_HEAD_CLEANING:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSOPEN, "journalHeadCleaning"));
}
break;
case POSPrinterConst.PTR_SUE_JRN_CARTDRIGE_OK:
if (statemachine != null) {
statemachine.processEvent(statemachine,
new MessageEvent(EventType.MESSAGECLOSE, "journalCartridgeEmpty"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "journalHeadCleaning"));
statemachine.processEvent(statemachine,
new MessageEvent(EventType.STATUSCLOSE, "journalCartridgeNearEmpty"));
}
break;
}
}
}
@Override
public void errorOccurred(ErrorEvent e) {
switch (e.getErrorCodeExtended()) {
case POSPrinterConst.JPOS_EPTR_COVER_OPEN:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorCoverOpen"));
}
break;
case POSPrinterConst.JPOS_EPTR_JRN_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorJournalEmpty"));
}
break;
case POSPrinterConst.JPOS_EPTR_REC_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorReceiptEmpty"));
}
break;
case POSPrinterConst.JPOS_EPTR_SLP_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorSlipEmpty"));
}
break;
case POSPrinterConst.JPOS_EPTR_BADFORMAT:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorBadFormat"));
}
break;
case POSPrinterConst.JPOS_EPTR_JRN_CARTRIDGE_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorJournalCartdridgeEmpty"));
}
break;
case POSPrinterConst.JPOS_EPTR_REC_CARTRIDGE_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorReceiptCartdridgeEmpty"));
}
break;
case POSPrinterConst.JPOS_EPTR_SLP_CARTRIDGE_EMPTY:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorSlipCartdridgeEmpty"));
}
break;
case POSPrinterConst.JPOS_EPTR_JRN_CARTRIDGE_REMOVED:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorJournalCartdridgeRemoved"));
}
break;
case POSPrinterConst.JPOS_EPTR_REC_CARTRIDGE_REMOVED:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorReceiptCartdridgeRemoved"));
}
break;
case POSPrinterConst.JPOS_EPTR_SLP_CARTRIDGE_REMOVED:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorSlipCartdridgeRemoved"));
}
break;
case POSPrinterConst.JPOS_EPTR_JRN_HEAD_CLEANING:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorJournalHeadCleaning"));
}
break;
case POSPrinterConst.JPOS_EPTR_REC_HEAD_CLEANING:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorReceiptHeadCleaning"));
}
break;
case POSPrinterConst.JPOS_EPTR_SLP_HEAD_CLEANING:
if (statemachine != null) {
statemachine.processEvent(statemachine, new MessageEvent(EventType.ERROR,
"errorSlipHeadCleaning"));
}
break;
default:
break;
}
}
@Override
public void outputCompleteOccurred(OutputCompleteEvent e) {
// TODO Auto-generated method stub
}
public String getPTIP() {
return ptIP;
}
public void setPTIP(String ptIP) {
this.ptIP = ptIP;
}
public Integer getPTPort() {
return ptPort;
}
public void setPTPort(Integer ptPort) {
this.ptPort = ptPort;
}
public void setPaymentTerminalOpen(String connectionParameters) {
String[] parts = connectionParameters.split("\\|");
setPTIP(parts[0]);
setPTPort(Integer.parseInt(parts[1]));
if(POSServiceBinder.getPosService() != null) {
if(!POSServiceBinder.getPosService().openZVTChannel(getPTIP(), getPTPort())) {
LOGGER.error("could not open ZVT socket");
}
}
}
public void setClosePaymentTerminal(String close) {
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().closeZVTChannel();
}
}
public void setPaymentTerminalAcknowledge(String dummey) {
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().zvtAcknowledge();
}
}
public void setPaymentTerminalBalanceRequest(String request) {
if(POSServiceBinder.getPosService() != null) {
// zvt.balanceRequest();
}
}
public void setPaymentTerminalPrepaidTopUp(Double amount) {
if(POSServiceBinder.getPosService() != null) {
// zvt.prepaidTopUp(amount);
}
}
public void setPaymentTerminalReversal(String reversal) {
String[] parts = reversal.split("\\|");
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().zvtReversal(parts[0], parts[1]);
}
}
public void setPaymentTerminalRegistration(String registration) {
String[] parts = registration.split("\\|");
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().zvtRegistration(parts[0], parts[1]);
}
}
public void setPaymentTerminalAuthorization(Double amount) {
if(POSServiceBinder.getPosService() != null) {
POSServiceBinder.getPosService().zvtAuthorization(amount);
}
}
public String getPaymentTerminalResponse() {
if(POSServiceBinder.getPosService() != null) {
return POSServiceBinder.getPosService().getZvtResponse();
}
return null;
}
public IZVTTransactionData getPaymentTerminalTransaction() {
if(POSServiceBinder.getPosService() != null) {
return POSServiceBinder.getPosService().getZvtTransactionData();
}
return null;
}
public void setPrintReport(String reportParameters) {
if(statemachine.getReportProvider() != null) {
String[] parts = reportParameters.split("\\|");
String reportName = parts[0];
Map<String, String> filterMap = new HashMap<>();
// the filter is optional
if(parts.length > 1 ) {
String storageKey = parts[1];
String filterName = null;
String filterValue = null;
for(String attribute : statemachine.getStorageAttributes(parts[1])) {
if("filterName".equals(attribute)) {
filterName = (String)statemachine.getStorage(storageKey, attribute);
}
if("filterValue".equals(attribute)) {
filterValue = (String)statemachine.getStorage(storageKey, attribute);
}
if(filterName != null && filterValue != null) {
// TODO: as soon as report supports cube datamarts, the slicerSingleSelectDecorator must be added
filterMap.put(filterName, filterValue);
filterName = null;
filterValue = null;
}
}
}
statemachine.getReportProvider().printReportAsPdf(reportName, statemachine.getUser(), statemachine.getDslMetadataService(), filterMap);
}
}
}