@Test public void testDecodeAssetsText() throws Exception { List<Asset> decodedAssets; logger.debug(m_testCvs); decodedAssets = m_importAssetServlet.decodeAssetsText(m_testCvs); Assert.assertEquals(5, decodedAssets.size()); for (Asset decodedAsset : decodedAssets) { logger.debug("decodedAsset:'{}'", decodedAsset); } }
public List<Asset> decodeAssetsText(String text) throws AssetException { CSVReader csvReader = null; StringReader stringReader = null; String[] line; List<Asset> list = new ArrayList<Asset>(); text = text.trim(); int count = 0; try { stringReader = new StringReader(text); csvReader = new CSVReader(stringReader); while ((line = csvReader.readNext()) != null) { count++; try { logger.debug("asset line is:'{}'", (Object)line); if (line.length <= 37) { logger.error("csv test row length was not at least 37 line length: '{}' line was:'{}', line length", line.length, line); throw new NoSuchElementException(); } if (line[0].equals("Node Label")) { logger.debug("line was header. line:'{}'", (Object)line); continue; } final Asset asset = new Asset(); asset.setNodeId(WebSecurityUtils.safeParseInt(line[1])); asset.setCategory(Util.decode(line[2])); asset.setManufacturer(Util.decode(line[3])); asset.setVendor(Util.decode(line[4])); asset.setModelNumber(Util.decode(line[5])); asset.setSerialNumber(Util.decode(line[6])); asset.setDescription(Util.decode(line[7])); asset.setCircuitId(Util.decode(line[8])); asset.setAssetNumber(Util.decode(line[9])); asset.setOperatingSystem(Util.decode(line[10])); asset.setRack(Util.decode(line[11])); asset.setSlot(Util.decode(line[12])); asset.setPort(Util.decode(line[13])); asset.setRegion(Util.decode(line[14])); asset.setDivision(Util.decode(line[15])); asset.setDepartment(Util.decode(line[16])); asset.setAddress1(Util.decode(line[17])); asset.setAddress2(Util.decode(line[18])); asset.setCity(Util.decode(line[19])); asset.setState(Util.decode(line[20])); asset.setZip(Util.decode(line[21])); asset.setBuilding(Util.decode(line[22])); asset.setFloor(Util.decode(line[23])); asset.setRoom(Util.decode(line[24])); asset.setVendorPhone(Util.decode(line[25])); asset.setVendorFax(Util.decode(line[26])); asset.setDateInstalled(Util.decode(line[27])); asset.setLease(Util.decode(line[28])); asset.setLeaseExpires(Util.decode(line[29])); asset.setSupportPhone(Util.decode(line[30])); asset.setMaintContract(Util.decode(line[31])); asset.setVendorAssetNumber(Util.decode(line[32])); asset.setMaintContractExpires(Util.decode(line[33])); asset.setDisplayCategory(Util.decode(line[34])); asset.setNotifyCategory(Util.decode(line[35])); asset.setPollerCategory(Util.decode(line[36])); if (line.length > 37) { asset.setThresholdCategory(Util.decode(line[37])); asset.setUsername(Util.decode(line[38])); asset.setPassword(Util.decode(line[39])); asset.setEnable(Util.decode(line[40])); asset.setConnection(Util.decode(line[41])); asset.setAutoenable(Util.decode(line[42])); asset.setComments(Util.decode(line[43])); } if (line.length > 44) { asset.setCpu(Util.decode(line[44])); asset.setRam(Util.decode(line[45])); asset.setStoragectrl(Util.decode(line[46])); asset.setHdd1(Util.decode(line[47])); asset.setHdd2(Util.decode(line[48])); asset.setHdd3(Util.decode(line[49])); asset.setHdd4(Util.decode(line[50])); asset.setHdd5(Util.decode(line[51])); asset.setHdd6(Util.decode(line[52])); asset.setNumpowersupplies(Util.decode(line[53])); asset.setInputpower(Util.decode(line[54])); asset.setAdditionalhardware(Util.decode(line[55])); asset.setAdmin(Util.decode(line[56])); asset.setSnmpcommunity(Util.decode(line[57])); asset.setRackunitheight(Util.decode(line[58])); } if (line.length > 59) { asset.setCountry(Util.decode(line[59])); asset.setLongitude(Util.decode(line[60])); asset.setLatitude(Util.decode(line[61])); } list.add(asset); logger.debug("decoded asset:'{}'", (Object)asset); } catch (NoSuchElementException e) { errors.add("Ignoring malformed import for entry " + count + ", not enough values."); } catch (NumberFormatException e) { logger.error("NodeId parsing to int faild, ignoreing malformed import for entry number '{}' exception message:'{}'", count, e.getMessage()); errors.add("Ignoring malformed import for entry " + count + ", node id not a number."); } } } catch (IOException e) { logger.error("An error occurred reading the CSV input. Message:'{}'", e.getMessage()); throw new AssetException("An error occurred reading the CSV input.", e); } finally { IOUtils.closeQuietly(stringReader); IOUtils.closeQuietly(csvReader); } if (list.size() == 0) { logger.error("No asset information was found, list size was 0"); throw new AssetException("No asset information was found."); } return list; }
ImportAssetsServlet extends HttpServlet { public List<Asset> decodeAssetsText(String text) throws AssetException { CSVReader csvReader = null; StringReader stringReader = null; String[] line; List<Asset> list = new ArrayList<Asset>(); text = text.trim(); int count = 0; try { stringReader = new StringReader(text); csvReader = new CSVReader(stringReader); while ((line = csvReader.readNext()) != null) { count++; try { logger.debug("asset line is:'{}'", (Object)line); if (line.length <= 37) { logger.error("csv test row length was not at least 37 line length: '{}' line was:'{}', line length", line.length, line); throw new NoSuchElementException(); } if (line[0].equals("Node Label")) { logger.debug("line was header. line:'{}'", (Object)line); continue; } final Asset asset = new Asset(); asset.setNodeId(WebSecurityUtils.safeParseInt(line[1])); asset.setCategory(Util.decode(line[2])); asset.setManufacturer(Util.decode(line[3])); asset.setVendor(Util.decode(line[4])); asset.setModelNumber(Util.decode(line[5])); asset.setSerialNumber(Util.decode(line[6])); asset.setDescription(Util.decode(line[7])); asset.setCircuitId(Util.decode(line[8])); asset.setAssetNumber(Util.decode(line[9])); asset.setOperatingSystem(Util.decode(line[10])); asset.setRack(Util.decode(line[11])); asset.setSlot(Util.decode(line[12])); asset.setPort(Util.decode(line[13])); asset.setRegion(Util.decode(line[14])); asset.setDivision(Util.decode(line[15])); asset.setDepartment(Util.decode(line[16])); asset.setAddress1(Util.decode(line[17])); asset.setAddress2(Util.decode(line[18])); asset.setCity(Util.decode(line[19])); asset.setState(Util.decode(line[20])); asset.setZip(Util.decode(line[21])); asset.setBuilding(Util.decode(line[22])); asset.setFloor(Util.decode(line[23])); asset.setRoom(Util.decode(line[24])); asset.setVendorPhone(Util.decode(line[25])); asset.setVendorFax(Util.decode(line[26])); asset.setDateInstalled(Util.decode(line[27])); asset.setLease(Util.decode(line[28])); asset.setLeaseExpires(Util.decode(line[29])); asset.setSupportPhone(Util.decode(line[30])); asset.setMaintContract(Util.decode(line[31])); asset.setVendorAssetNumber(Util.decode(line[32])); asset.setMaintContractExpires(Util.decode(line[33])); asset.setDisplayCategory(Util.decode(line[34])); asset.setNotifyCategory(Util.decode(line[35])); asset.setPollerCategory(Util.decode(line[36])); if (line.length > 37) { asset.setThresholdCategory(Util.decode(line[37])); asset.setUsername(Util.decode(line[38])); asset.setPassword(Util.decode(line[39])); asset.setEnable(Util.decode(line[40])); asset.setConnection(Util.decode(line[41])); asset.setAutoenable(Util.decode(line[42])); asset.setComments(Util.decode(line[43])); } if (line.length > 44) { asset.setCpu(Util.decode(line[44])); asset.setRam(Util.decode(line[45])); asset.setStoragectrl(Util.decode(line[46])); asset.setHdd1(Util.decode(line[47])); asset.setHdd2(Util.decode(line[48])); asset.setHdd3(Util.decode(line[49])); asset.setHdd4(Util.decode(line[50])); asset.setHdd5(Util.decode(line[51])); asset.setHdd6(Util.decode(line[52])); asset.setNumpowersupplies(Util.decode(line[53])); asset.setInputpower(Util.decode(line[54])); asset.setAdditionalhardware(Util.decode(line[55])); asset.setAdmin(Util.decode(line[56])); asset.setSnmpcommunity(Util.decode(line[57])); asset.setRackunitheight(Util.decode(line[58])); } if (line.length > 59) { asset.setCountry(Util.decode(line[59])); asset.setLongitude(Util.decode(line[60])); asset.setLatitude(Util.decode(line[61])); } list.add(asset); logger.debug("decoded asset:'{}'", (Object)asset); } catch (NoSuchElementException e) { errors.add("Ignoring malformed import for entry " + count + ", not enough values."); } catch (NumberFormatException e) { logger.error("NodeId parsing to int faild, ignoreing malformed import for entry number '{}' exception message:'{}'", count, e.getMessage()); errors.add("Ignoring malformed import for entry " + count + ", node id not a number."); } } } catch (IOException e) { logger.error("An error occurred reading the CSV input. Message:'{}'", e.getMessage()); throw new AssetException("An error occurred reading the CSV input.", e); } finally { IOUtils.closeQuietly(stringReader); IOUtils.closeQuietly(csvReader); } if (list.size() == 0) { logger.error("No asset information was found, list size was 0"); throw new AssetException("No asset information was found."); } return list; } }
ImportAssetsServlet extends HttpServlet { public List<Asset> decodeAssetsText(String text) throws AssetException { CSVReader csvReader = null; StringReader stringReader = null; String[] line; List<Asset> list = new ArrayList<Asset>(); text = text.trim(); int count = 0; try { stringReader = new StringReader(text); csvReader = new CSVReader(stringReader); while ((line = csvReader.readNext()) != null) { count++; try { logger.debug("asset line is:'{}'", (Object)line); if (line.length <= 37) { logger.error("csv test row length was not at least 37 line length: '{}' line was:'{}', line length", line.length, line); throw new NoSuchElementException(); } if (line[0].equals("Node Label")) { logger.debug("line was header. line:'{}'", (Object)line); continue; } final Asset asset = new Asset(); asset.setNodeId(WebSecurityUtils.safeParseInt(line[1])); asset.setCategory(Util.decode(line[2])); asset.setManufacturer(Util.decode(line[3])); asset.setVendor(Util.decode(line[4])); asset.setModelNumber(Util.decode(line[5])); asset.setSerialNumber(Util.decode(line[6])); asset.setDescription(Util.decode(line[7])); asset.setCircuitId(Util.decode(line[8])); asset.setAssetNumber(Util.decode(line[9])); asset.setOperatingSystem(Util.decode(line[10])); asset.setRack(Util.decode(line[11])); asset.setSlot(Util.decode(line[12])); asset.setPort(Util.decode(line[13])); asset.setRegion(Util.decode(line[14])); asset.setDivision(Util.decode(line[15])); asset.setDepartment(Util.decode(line[16])); asset.setAddress1(Util.decode(line[17])); asset.setAddress2(Util.decode(line[18])); asset.setCity(Util.decode(line[19])); asset.setState(Util.decode(line[20])); asset.setZip(Util.decode(line[21])); asset.setBuilding(Util.decode(line[22])); asset.setFloor(Util.decode(line[23])); asset.setRoom(Util.decode(line[24])); asset.setVendorPhone(Util.decode(line[25])); asset.setVendorFax(Util.decode(line[26])); asset.setDateInstalled(Util.decode(line[27])); asset.setLease(Util.decode(line[28])); asset.setLeaseExpires(Util.decode(line[29])); asset.setSupportPhone(Util.decode(line[30])); asset.setMaintContract(Util.decode(line[31])); asset.setVendorAssetNumber(Util.decode(line[32])); asset.setMaintContractExpires(Util.decode(line[33])); asset.setDisplayCategory(Util.decode(line[34])); asset.setNotifyCategory(Util.decode(line[35])); asset.setPollerCategory(Util.decode(line[36])); if (line.length > 37) { asset.setThresholdCategory(Util.decode(line[37])); asset.setUsername(Util.decode(line[38])); asset.setPassword(Util.decode(line[39])); asset.setEnable(Util.decode(line[40])); asset.setConnection(Util.decode(line[41])); asset.setAutoenable(Util.decode(line[42])); asset.setComments(Util.decode(line[43])); } if (line.length > 44) { asset.setCpu(Util.decode(line[44])); asset.setRam(Util.decode(line[45])); asset.setStoragectrl(Util.decode(line[46])); asset.setHdd1(Util.decode(line[47])); asset.setHdd2(Util.decode(line[48])); asset.setHdd3(Util.decode(line[49])); asset.setHdd4(Util.decode(line[50])); asset.setHdd5(Util.decode(line[51])); asset.setHdd6(Util.decode(line[52])); asset.setNumpowersupplies(Util.decode(line[53])); asset.setInputpower(Util.decode(line[54])); asset.setAdditionalhardware(Util.decode(line[55])); asset.setAdmin(Util.decode(line[56])); asset.setSnmpcommunity(Util.decode(line[57])); asset.setRackunitheight(Util.decode(line[58])); } if (line.length > 59) { asset.setCountry(Util.decode(line[59])); asset.setLongitude(Util.decode(line[60])); asset.setLatitude(Util.decode(line[61])); } list.add(asset); logger.debug("decoded asset:'{}'", (Object)asset); } catch (NoSuchElementException e) { errors.add("Ignoring malformed import for entry " + count + ", not enough values."); } catch (NumberFormatException e) { logger.error("NodeId parsing to int faild, ignoreing malformed import for entry number '{}' exception message:'{}'", count, e.getMessage()); errors.add("Ignoring malformed import for entry " + count + ", node id not a number."); } } } catch (IOException e) { logger.error("An error occurred reading the CSV input. Message:'{}'", e.getMessage()); throw new AssetException("An error occurred reading the CSV input.", e); } finally { IOUtils.closeQuietly(stringReader); IOUtils.closeQuietly(csvReader); } if (list.size() == 0) { logger.error("No asset information was found, list size was 0"); throw new AssetException("No asset information was found."); } return list; }  }
ImportAssetsServlet extends HttpServlet { public List<Asset> decodeAssetsText(String text) throws AssetException { CSVReader csvReader = null; StringReader stringReader = null; String[] line; List<Asset> list = new ArrayList<Asset>(); text = text.trim(); int count = 0; try { stringReader = new StringReader(text); csvReader = new CSVReader(stringReader); while ((line = csvReader.readNext()) != null) { count++; try { logger.debug("asset line is:'{}'", (Object)line); if (line.length <= 37) { logger.error("csv test row length was not at least 37 line length: '{}' line was:'{}', line length", line.length, line); throw new NoSuchElementException(); } if (line[0].equals("Node Label")) { logger.debug("line was header. line:'{}'", (Object)line); continue; } final Asset asset = new Asset(); asset.setNodeId(WebSecurityUtils.safeParseInt(line[1])); asset.setCategory(Util.decode(line[2])); asset.setManufacturer(Util.decode(line[3])); asset.setVendor(Util.decode(line[4])); asset.setModelNumber(Util.decode(line[5])); asset.setSerialNumber(Util.decode(line[6])); asset.setDescription(Util.decode(line[7])); asset.setCircuitId(Util.decode(line[8])); asset.setAssetNumber(Util.decode(line[9])); asset.setOperatingSystem(Util.decode(line[10])); asset.setRack(Util.decode(line[11])); asset.setSlot(Util.decode(line[12])); asset.setPort(Util.decode(line[13])); asset.setRegion(Util.decode(line[14])); asset.setDivision(Util.decode(line[15])); asset.setDepartment(Util.decode(line[16])); asset.setAddress1(Util.decode(line[17])); asset.setAddress2(Util.decode(line[18])); asset.setCity(Util.decode(line[19])); asset.setState(Util.decode(line[20])); asset.setZip(Util.decode(line[21])); asset.setBuilding(Util.decode(line[22])); asset.setFloor(Util.decode(line[23])); asset.setRoom(Util.decode(line[24])); asset.setVendorPhone(Util.decode(line[25])); asset.setVendorFax(Util.decode(line[26])); asset.setDateInstalled(Util.decode(line[27])); asset.setLease(Util.decode(line[28])); asset.setLeaseExpires(Util.decode(line[29])); asset.setSupportPhone(Util.decode(line[30])); asset.setMaintContract(Util.decode(line[31])); asset.setVendorAssetNumber(Util.decode(line[32])); asset.setMaintContractExpires(Util.decode(line[33])); asset.setDisplayCategory(Util.decode(line[34])); asset.setNotifyCategory(Util.decode(line[35])); asset.setPollerCategory(Util.decode(line[36])); if (line.length > 37) { asset.setThresholdCategory(Util.decode(line[37])); asset.setUsername(Util.decode(line[38])); asset.setPassword(Util.decode(line[39])); asset.setEnable(Util.decode(line[40])); asset.setConnection(Util.decode(line[41])); asset.setAutoenable(Util.decode(line[42])); asset.setComments(Util.decode(line[43])); } if (line.length > 44) { asset.setCpu(Util.decode(line[44])); asset.setRam(Util.decode(line[45])); asset.setStoragectrl(Util.decode(line[46])); asset.setHdd1(Util.decode(line[47])); asset.setHdd2(Util.decode(line[48])); asset.setHdd3(Util.decode(line[49])); asset.setHdd4(Util.decode(line[50])); asset.setHdd5(Util.decode(line[51])); asset.setHdd6(Util.decode(line[52])); asset.setNumpowersupplies(Util.decode(line[53])); asset.setInputpower(Util.decode(line[54])); asset.setAdditionalhardware(Util.decode(line[55])); asset.setAdmin(Util.decode(line[56])); asset.setSnmpcommunity(Util.decode(line[57])); asset.setRackunitheight(Util.decode(line[58])); } if (line.length > 59) { asset.setCountry(Util.decode(line[59])); asset.setLongitude(Util.decode(line[60])); asset.setLatitude(Util.decode(line[61])); } list.add(asset); logger.debug("decoded asset:'{}'", (Object)asset); } catch (NoSuchElementException e) { errors.add("Ignoring malformed import for entry " + count + ", not enough values."); } catch (NumberFormatException e) { logger.error("NodeId parsing to int faild, ignoreing malformed import for entry number '{}' exception message:'{}'", count, e.getMessage()); errors.add("Ignoring malformed import for entry " + count + ", node id not a number."); } } } catch (IOException e) { logger.error("An error occurred reading the CSV input. Message:'{}'", e.getMessage()); throw new AssetException("An error occurred reading the CSV input.", e); } finally { IOUtils.closeQuietly(stringReader); IOUtils.closeQuietly(csvReader); } if (list.size() == 0) { logger.error("No asset information was found, list size was 0"); throw new AssetException("No asset information was found."); } return list; }  void init(); void doPost(HttpServletRequest request, HttpServletResponse response); List<Asset> decodeAssetsText(String text); List<Integer> getCurrentAssetNodesList(); }
ImportAssetsServlet extends HttpServlet { public List<Asset> decodeAssetsText(String text) throws AssetException { CSVReader csvReader = null; StringReader stringReader = null; String[] line; List<Asset> list = new ArrayList<Asset>(); text = text.trim(); int count = 0; try { stringReader = new StringReader(text); csvReader = new CSVReader(stringReader); while ((line = csvReader.readNext()) != null) { count++; try { logger.debug("asset line is:'{}'", (Object)line); if (line.length <= 37) { logger.error("csv test row length was not at least 37 line length: '{}' line was:'{}', line length", line.length, line); throw new NoSuchElementException(); } if (line[0].equals("Node Label")) { logger.debug("line was header. line:'{}'", (Object)line); continue; } final Asset asset = new Asset(); asset.setNodeId(WebSecurityUtils.safeParseInt(line[1])); asset.setCategory(Util.decode(line[2])); asset.setManufacturer(Util.decode(line[3])); asset.setVendor(Util.decode(line[4])); asset.setModelNumber(Util.decode(line[5])); asset.setSerialNumber(Util.decode(line[6])); asset.setDescription(Util.decode(line[7])); asset.setCircuitId(Util.decode(line[8])); asset.setAssetNumber(Util.decode(line[9])); asset.setOperatingSystem(Util.decode(line[10])); asset.setRack(Util.decode(line[11])); asset.setSlot(Util.decode(line[12])); asset.setPort(Util.decode(line[13])); asset.setRegion(Util.decode(line[14])); asset.setDivision(Util.decode(line[15])); asset.setDepartment(Util.decode(line[16])); asset.setAddress1(Util.decode(line[17])); asset.setAddress2(Util.decode(line[18])); asset.setCity(Util.decode(line[19])); asset.setState(Util.decode(line[20])); asset.setZip(Util.decode(line[21])); asset.setBuilding(Util.decode(line[22])); asset.setFloor(Util.decode(line[23])); asset.setRoom(Util.decode(line[24])); asset.setVendorPhone(Util.decode(line[25])); asset.setVendorFax(Util.decode(line[26])); asset.setDateInstalled(Util.decode(line[27])); asset.setLease(Util.decode(line[28])); asset.setLeaseExpires(Util.decode(line[29])); asset.setSupportPhone(Util.decode(line[30])); asset.setMaintContract(Util.decode(line[31])); asset.setVendorAssetNumber(Util.decode(line[32])); asset.setMaintContractExpires(Util.decode(line[33])); asset.setDisplayCategory(Util.decode(line[34])); asset.setNotifyCategory(Util.decode(line[35])); asset.setPollerCategory(Util.decode(line[36])); if (line.length > 37) { asset.setThresholdCategory(Util.decode(line[37])); asset.setUsername(Util.decode(line[38])); asset.setPassword(Util.decode(line[39])); asset.setEnable(Util.decode(line[40])); asset.setConnection(Util.decode(line[41])); asset.setAutoenable(Util.decode(line[42])); asset.setComments(Util.decode(line[43])); } if (line.length > 44) { asset.setCpu(Util.decode(line[44])); asset.setRam(Util.decode(line[45])); asset.setStoragectrl(Util.decode(line[46])); asset.setHdd1(Util.decode(line[47])); asset.setHdd2(Util.decode(line[48])); asset.setHdd3(Util.decode(line[49])); asset.setHdd4(Util.decode(line[50])); asset.setHdd5(Util.decode(line[51])); asset.setHdd6(Util.decode(line[52])); asset.setNumpowersupplies(Util.decode(line[53])); asset.setInputpower(Util.decode(line[54])); asset.setAdditionalhardware(Util.decode(line[55])); asset.setAdmin(Util.decode(line[56])); asset.setSnmpcommunity(Util.decode(line[57])); asset.setRackunitheight(Util.decode(line[58])); } if (line.length > 59) { asset.setCountry(Util.decode(line[59])); asset.setLongitude(Util.decode(line[60])); asset.setLatitude(Util.decode(line[61])); } list.add(asset); logger.debug("decoded asset:'{}'", (Object)asset); } catch (NoSuchElementException e) { errors.add("Ignoring malformed import for entry " + count + ", not enough values."); } catch (NumberFormatException e) { logger.error("NodeId parsing to int faild, ignoreing malformed import for entry number '{}' exception message:'{}'", count, e.getMessage()); errors.add("Ignoring malformed import for entry " + count + ", node id not a number."); } } } catch (IOException e) { logger.error("An error occurred reading the CSV input. Message:'{}'", e.getMessage()); throw new AssetException("An error occurred reading the CSV input.", e); } finally { IOUtils.closeQuietly(stringReader); IOUtils.closeQuietly(csvReader); } if (list.size() == 0) { logger.error("No asset information was found, list size was 0"); throw new AssetException("No asset information was found."); } return list; }  void init(); void doPost(HttpServletRequest request, HttpServletResponse response); List<Asset> decodeAssetsText(String text); List<Integer> getCurrentAssetNodesList();  }