@Override public boolean createOrUpdateSparePartGroup( String electronicShopID, String sparePartGroupID, String description) { // check if we know that shop if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) { logger.warning("electronicShopID \"" + electronicShopID + "\" not known!"); return false; } List<SparePartGroup> spgl = SparePartGroup.queryGetByForeignID(sparePartGroupID, 0, 1); SparePartGroup spg; if (spgl.size() == 0) { spg = new SparePartGroup(); } else { spg = spgl.get(0); } try { spg.setForeignID(sparePartGroupID); spg.setDescription(description); spg.writeToDB(); } catch (RuntimeException e) { logger.log(Level.WARNING, "Can't write to DB!", e); return false; } return true; }
@Override public boolean createOrUpdateSparePart( String electronicShopID, String sparePartID, String name, String sparePartGroupID, String description, double deliveryPrice, String measuringUnit) { boolean flagNew = false; // check if we know that shop if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) { logger.warning("electronicShopID \"" + electronicShopID + "\" not known!"); return false; } List<SparePart> spl = SparePart.queryGetByForeignID(sparePartID, 0, 1); SparePart sp; if (spl.size() == 0) { sp = new SparePart(); flagNew = true; } else { sp = spl.get(0); } try { List<SparePartGroup> sparePartGroup = SparePartGroup.queryGetByForeignID(sparePartGroupID, 0, 1); if (sparePartGroup.size() == 0) { logger.warning("sparePartGroupID \"" + sparePartGroupID + "\" not known!"); return false; } sp.setForeignID(sparePartID); sp.setSparePartGroupID(sparePartGroup.get(0).getID()); sp.setName(name); sp.setDescription(description); sp.setDeliveryPrice(deliveryPrice); sp.setSalePrice(deliveryPrice); // <--- отначало продажната цена е същата като доставната !!! sp.setMeasuringUnit(measuringUnit); Transaction tr = DatastoreServiceFactory.getDatastoreService() .beginTransaction(TransactionOptions.Builder.withXG(true)); sp.writeToDB(); if (flagNew) { // добавяме нова част -> инициализираме записите за тази част във всички автосервизи SparePartAutoservice spa = new SparePartAutoservice(); spa.setQuantityAvailable(0); spa.setQuantityBad(0); spa.setQuantityMinimum(0); spa.setQuantityOrdered(0); spa.setQuantityReserved(0); spa.setQuantityRequested(0); spa.setSparePartID(sp.getID()); List<Autoservice> al = Autoservice.queryGetAll(0, 1000); for (Autoservice autoservice : al) { spa.setAutoserviceID(autoservice.getID()); spa.writeToDB(true); } } tr.commit(); } catch (RuntimeException e) { logger.log(Level.WARNING, "Can't write to DB!", e); return false; } return true; }