use of com.sputnik.ouidb.model.Organization in project ouidb-to-json-publisher by jfisbein.
the class Runner method run.
private ExitCode run() throws IOException, GitAPIException {
ExitCode exitCode;
File ouiDBFile = getOuiDBFile();
try (Git git = getGitRepo()) {
Map<String, Organization> parsedDB = downloader.getParsedDB();
String json = converter.convertToJson(parsedDB);
FileWriter writer = new FileWriter(ouiDBFile);
IOUtils.write(json, writer);
writer.flush();
Status status = git.status().call();
if (!status.getModified().isEmpty()) {
exitCode = ExitCode.THERES_CHANGES;
File compressedGzFile = compressFileToGz(ouiDBFile);
File compressedBz2File = compressFileToBz2(ouiDBFile);
log.info("OUIDB file changed, uploading to git repo.");
git.add().addFilepattern(ouiDBFile.getName()).call();
git.add().addFilepattern(compressedGzFile.getName()).call();
git.add().addFilepattern(compressedBz2File.getName()).call();
git.commit().setMessage("Updated OUIDB json file").call();
git.push().call();
} else {
exitCode = ExitCode.NO_CHANGES;
log.info("No changes detected on OUIDB File, nothing to do.");
}
}
log.info("Done :-)");
return exitCode;
}
use of com.sputnik.ouidb.model.Organization in project ouidb-to-json-publisher by jfisbein.
the class OUIDBConverterTest method convertToJson.
@Test
void convertToJson() {
OUIDBConverter converter = new OUIDBConverter();
Map<String, Organization> db = generateDb(5);
String json = converter.convertToJson(db);
List<Map<String, Object>> parsedJson = gson.fromJson(json, new TypeToken<List<Map<String, Object>>>() {
}.getType());
assertThat(parsedJson).hasSize(db.size());
for (String prefix : db.keySet()) {
Organization org = db.get(prefix);
Optional<Map<String, Object>> jsonEntryOpt = parsedJson.stream().filter(m -> m.get("prefix").equals(prefix)).findFirst();
assertThat(jsonEntryOpt).isPresent();
Map<String, Object> jsonEntry = jsonEntryOpt.get();
Map<String, Object> jsonOrg = (Map<String, Object>) jsonEntry.get("organization");
assertThat(jsonOrg).containsEntry("name", org.getName());
Map<String, Object> jsonAddress = (Map<String, Object>) jsonOrg.get("address");
assertThat(jsonAddress).containsEntry("line1", org.getAddress().getLine1()).containsEntry("line2", org.getAddress().getLine2()).containsEntry("countryCode", org.getAddress().getCountryCode());
}
}
use of com.sputnik.ouidb.model.Organization in project ouidb-to-json-publisher by jfisbein.
the class OUIDBConverterTest method generateRandomOrganization.
private Organization generateRandomOrganization() {
Organization organization = new Organization(faker.company().name());
organization.setAddress(generateRandomAddress());
return organization;
}
use of com.sputnik.ouidb.model.Organization in project ouidb-to-json-publisher by jfisbein.
the class OUIDBDownloader method parseDb.
protected Map<String, Organization> parseDb(Reader db) throws IOException {
Map<String, Organization> response = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
try (BufferedReader reader = new BufferedReader(db)) {
String line;
int counter = 0;
Organization organization = null;
while ((line = reader.readLine()) != null) {
line = normalize(line);
if (line.contains("(hex)")) {
String[] split = StringUtils.splitByWholeSeparator(line, "(hex)");
String prefix = normalizePrefix(split[0]);
String organizationName = normalizeOrganizationName(split[1]);
counter = 0;
organization = new Organization(organizationName);
organization.setAddress(new Address());
response.put(prefix, organization);
} else if (counter < 3 && organization != null && !line.contains("(base 16)")) {
counter = fillAddress(line, counter, organization.getAddress());
}
}
}
if (response.isEmpty()) {
throw new NoRecordsFoundException("No records found");
}
return response;
}
use of com.sputnik.ouidb.model.Organization in project ouidb-to-json-publisher by jfisbein.
the class OUIDBDownloaderTest method parsedDB.
@Test
void parsedDB() throws IOException {
Map<String, Organization> db = new OUIDBDownloader().parseDb(new FileReader("src/test/resources/ouidb-test.txt"));
// All OUI parsed
assertThat(db).as("Missing some OUIs from parsed result").hasSize(9);
// Private
testOUI(db, "E4F14C", "Private", null, null, null);
// Normal
testOUI(db, "00093A", "Molex CMS", "5224 Katrine Avenue", "Downers Grove IL 60515", "US");
testOUI(db, "18BB26", "FN-Link Technology Limited", "A Building, HuiXin industial park, No 31, YongHe road, Fuyong town, Bao'an District", "Shenzhen Guangdong 518100", "CN");
// Normalize
testOUI(db, "001F18", "Hakusan.Mfg.Co. Ltd", "Tomin-Kougyou-Ikebukuro BLD.5F", "Tosima Ward Tokyo-Met. 171-0022", "JP");
testOUI(db, "001E61", "ITEC GmbH", "Lassnitzthal 300", "A-8200 Gleisdorf", "AT");
testOUI(db, "000037", "Oxford Metrics Limited", "Unit 8, 7 West Way", "United Kingdom", "GB");
testOUI(db, "1CB044", "Askey Computer Corp", "10F, No.119, JIANKANG Rd, ZHONGHE DIST", "NEW Taipei Taiwan 23585", "TW");
testOUI(db, "900372", "Longnan Junya Digital Technology Co. Ltd", "Champion Asia Road, Xinzhen industrial Park, Longnan national economic and technological development zone, Ganzhou city, JiangXi Province, China", "ganzhou jiangxi 341700", "CN");
// No addressLine 2
testOUI(db, "000057", "Scitex Corporation Ltd", "P.O. Box 330", null, "IL");
}
Aggregations