Ejemplo n.º 1
0
	@Override
	public void importTower(Sheet sheet) {
		
		boolean isFirst = Boolean.TRUE;
		for(Iterator<Row> it = sheet.rowIterator(); it.hasNext(); ) {
			try {
				
				Row row = it.next();
				if(isFirst) {
					isFirst = Boolean.FALSE;
					continue;
				}

				Manufacturer manufacturer = manufacturerService.findOrCreateByNameAndCategory(
						row.getCell(MANUFACTURER).getStringCellValue().trim(),
						CategoryEnum.TOWER
				);
				
				Tower tower = new Tower(manufacturer);
				
				tower.setName(row.getCell(NAME).getStringCellValue().trim());
				tower.setPrice(BigDecimal.valueOf(row.getCell(PRICE).getNumericCellValue()));
				tower.setWatts(String.valueOf(row.getCell(WATTS).getNumericCellValue()));
				tower.setCode("0000000000");
				
				tower = this.save(tower);
				
				System.out.println(tower.toString());
			} catch (ServiceException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
Ejemplo n.º 2
0
	@Override
	public Tower save(Tower tower) throws ServiceException {
		tower = this.repository.save(tower);
		tower.setCode(StringUtils.formatString(tower.getId(), 10, "G"));
		return this.repository.save(tower);
	}