@Override public void update(BatteryInfo batteryInfo) { Set<Survey> existingSurveys = new HashSet<Survey>(); for (SurveyInfo surveyInfo : batteryInfo.getSurveys()) { existingSurveys.add(surveyService.findOne(surveyInfo.getSurveyId())); } Battery battery = batteryRepository.findOne(batteryInfo.getBatteryId()); battery.setName(batteryInfo.getName()); battery.setDescription(batteryInfo.getDescription()); battery.setDisabled(batteryInfo.isDisabled()); battery.setSurveys(existingSurveys); batteryRepository.update(battery); }
@Override public BatteryInfo create(BatteryInfo batteryInfo) { Battery battery = new Battery(); battery.setName(batteryInfo.getName()); battery.setDescription(batteryInfo.getDescription()); battery.setDisabled(batteryInfo.isDisabled()); if (batteryInfo.getSurveys() != null && batteryInfo.getSurveys().size() > 0) { List<Survey> surveyList = new ArrayList<Survey>(); for (SurveyInfo surveyInfo : batteryInfo.getSurveys()) { // if (surveyInfo.getIsIncludedInBattery()) { surveyList.add(surveyService.findOne(surveyInfo.getSurveyId())); // } } if (surveyList.size() > 0) { battery.setSurveys(new HashSet<Survey>(surveyList)); } } batteryRepository.create(battery); batteryInfo.setBatteryId(battery.getBatteryId()); return batteryInfo; }
@Transactional(readOnly = true) @Override public BatteryInfo getBattery(int batteryId) { BatteryInfo batteryInfo = null; Battery battery = batteryRepository.findOne(batteryId); if (battery != null) { batteryInfo = EditorsBatteryViewTransformer.transformBattery(battery); } return batteryInfo; }
@Transactional(readOnly = true) @Override public List<BatteryInfo> getBatteryItemList() { List<BatteryInfo> batteryInfoList = new ArrayList<BatteryInfo>(); List<Battery> batteryList = batteryRepository.findAll(); for (Battery battery : batteryList) { batteryInfoList.add(convertToBatteryItem(battery)); } return batteryInfoList; }
@Transactional(readOnly = true) @Override public List<DropDownObject> getBatteryList() { List<DropDownObject> dropDownObjectList = new ArrayList<DropDownObject>(); List<Battery> batteryList = batteryRepository.getBatteryList(); for (Battery battery : batteryList) { dropDownObjectList.add( new DropDownObject(battery.getBatteryId().toString(), battery.getName())); } return dropDownObjectList; }
@Transactional(readOnly = true) @Override public Set<BatteryDto> getBatteryDtoSet() { Set<BatteryDto> batteryDtoList = Sets.newTreeSet(); List<Battery> batteryList = batteryRepository.getBatteryList(); for (Battery battery : batteryList) { BatteryDto batterycDto = new BatteryDto(); batterycDto.setBatteryId(battery.getBatteryId()); batterycDto.setBatteryName(battery.getName()); batteryDtoList.add(batterycDto); } return batteryDtoList; }
@Transactional @Override public void delete(Integer batteryId) { batteryRepository.deleteById(batteryId); }