use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.
the class TestBuilder method testDualBuilderUsageNoSecondInstance.
@Test
void testDualBuilderUsageNoSecondInstance() {
UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().delayInitialization();
assertNotNull(builder.build(), "We should get a first instance from a single builder.");
// And calling build() again should fail with an exception
assertThrows(IllegalStateException.class, builder::build);
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.
the class TestBuilder method testLoadMoreResources.
@Test
void testLoadMoreResources() {
UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().delayInitialization().withField("DeviceClass");
UserAgentAnalyzer uaa = builder.build();
assertNotNull(uaa, "We should get a first instance from a single builder.");
// Try to load something that does not yield any files.
// Optional --> error message and continue
uaa.loadResources("Bad resource string that is optional should only give a warning", true, true);
// NOT Optional --> fail with exception
assertThrows(InvalidParserConfigurationException.class, () -> uaa.loadResources("Bad resource string that is NOT optional should fail hard", true, false));
uaa.initializeMatchers();
assertThrows(IllegalStateException.class, () -> uaa.loadResources(DEFAULT_RESOURCES));
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.
the class UserAgentDissector method getPossibleOutput.
@Override
public List<String> getPossibleOutput() {
List<String> result = new ArrayList<>();
// First the standard fields in the standard order, then the non-standard fields alphabetically
final UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder();
extraResources.forEach(builder::addResources);
allPossibleFieldNames = builder.build().getAllPossibleFieldNamesSorted();
for (String fieldName : allPossibleFieldNames) {
ensureMappingsExistForFieldName(fieldName);
result.add(getFieldOutputType(fieldName) + ":" + fieldNameToDissectionName(fieldName));
}
return result;
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder in project yauaa by nielsbasjes.
the class ParseUserAgent method onSchedule.
// Called via the annotation
@SuppressWarnings("unused")
@OnScheduled
public void onSchedule(ProcessContext context) {
if (uaa == null) {
UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().hideMatcherLoadStats().dropTests();
extractFieldNames.clear();
for (PropertyDescriptor propertyDescriptor : supportedPropertyDescriptors) {
if (Boolean.TRUE.equals(context.getProperty(propertyDescriptor).asBoolean())) {
String name = propertyDescriptor.getName();
if (name.startsWith(PROPERTY_PREFIX)) {
// Should always pass
String fieldName = name.substring(PROPERTY_PREFIX.length());
builder.withField(fieldName);
extractFieldNames.add(fieldName);
}
}
}
uaa = builder.build();
}
}
Aggregations