if (activeSession == null) {
printMerchantWarning("No active session to bill "+serviceType+" on "+triggerMatcher.group(1));
} else {
// Skip saving service if repairing the same item again (i.e. not enough material at first repair
if (!(TRIGNAME_REPAIR_EQ.equals(triggerName) && lastRepairedItem != null && lastRepairedItem.equals(triggerMatcher.group(1)))) {
MerchantService storeService = new MerchantService();
storeService.setMerchantSession(activeSession);
storeService.setServiceType(serviceType);
if (TRIGNAME_FEATHER_WEIGHT.equals(triggerName) || TRIGNAME_LABEL.equals(triggerName) ||
TRIGNAME_CLEARLABEL.equals(triggerName) || TRIGNAME_PROTECT_EQ.equals(triggerName) ||
TRIGNAME_REPAIR_EQ.equals(triggerName)) {
storeService.setItemShortDescription(getShortDescriptionFromItem(triggerMatcher.group(1)));
if (TRIGNAME_REPAIR_EQ.equals(triggerName))
lastRepairedItem = triggerMatcher.group(1);
} else if (TRIGNAME_BUY_MATERIALS.equals(triggerName)) {
Integer quantity = new Integer(triggerMatcher.group(1));
String materialName = triggerMatcher.group(4);
Integer price = new Integer(triggerMatcher.group(5));
storeService.setMaterialName(materialName);
storeService.setMaterialQuantity(quantity);
storeService.setMaterialPrice(price);
}
activeSession.getMerchantServices().add(storeService);
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
session.update(activeSession);