Search in sources :

Example 6 with UserAgentAnalyzerBuilder

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);
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with UserAgentAnalyzerBuilder

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));
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

Example 8 with UserAgentAnalyzerBuilder

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;
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) ArrayList(java.util.ArrayList)

Example 9 with UserAgentAnalyzerBuilder

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();
    }
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

UserAgentAnalyzerBuilder (nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)9 UserAgentAnalyzer (nl.basjes.parse.useragent.UserAgentAnalyzer)3 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1