@Override public boolean createOrUpdateVehicleModelPart( String electronicShopID, String vehicleModelID, String sparePartID) { // check if we know that shop if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) { logger.warning("electronicShopID \"" + electronicShopID + "\" not known!"); return false; } // NOTE: напрактика само може да се добавя VehicleModelSparePart vmsp = new VehicleModelSparePart(); try { List<VehicleModel> vehicleModel = VehicleModel.queryGetByForeignID(vehicleModelID, 0, 1); if (vehicleModel.size() == 0) { logger.warning("vehicleModelID \"" + vehicleModelID + "\" not known!"); return false; } List<SparePart> sparePart = SparePart.queryGetByForeignID(sparePartID, 0, 1); if (sparePart.size() == 0) { logger.warning("sparePartID \"" + sparePartID + "\" not known!"); return false; } vmsp.setVehicleModelID(vehicleModel.get(0).getID()); vmsp.setSparePartID(sparePart.get(0).getID()); vmsp.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; }