Search in sources :

Example 91 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class PatternValidatorTest method validateWithErrors.

private void validateWithErrors(final String value, final int expectedErrors) {
    final Optional<AttributeValidationReport> reportOptional = VALIDATOR.validate(new AttributeImpl("test", value));
    assertThat(reportOptional.get().getAttributeValidationViolations(), hasSize(expectedErrors));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport)

Example 92 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class RangeValidatorTest method testWithinSmallDecimalRange.

@Test
public void testWithinSmallDecimalRange() {
    final RangeValidator validator = new RangeValidator(new BigDecimal("1.2457515"), new BigDecimal("1.2487595"), new BigDecimal("1E-7"));
    validateNoErrors(new AttributeImpl("", 1.2457515), validator);
    validateNoErrors(new AttributeImpl("", 1.2487595), validator);
    validateNoErrors(new AttributeImpl("", 1.246), validator);
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) RangeValidator(ddf.catalog.validation.impl.validator.RangeValidator) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 93 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class SolrMetacardClientImpl method createMetacard.

public MetacardImpl createMetacard(SolrDocument doc) throws MetacardCreationException {
    MetacardType metacardType = resolver.getMetacardType(doc);
    MetacardImpl metacard = new MetacardImpl(metacardType);
    for (String solrFieldName : doc.getFieldNames()) {
        if (!resolver.isPrivateField(solrFieldName)) {
            Collection<Object> fieldValues = doc.getFieldValues(solrFieldName);
            Attribute attr = new AttributeImpl(resolver.resolveFieldName(solrFieldName), resolver.getDocValues(solrFieldName, fieldValues));
            metacard.setAttribute(attr);
        }
    }
    return metacard;
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 94 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class Jpeg2000ThumbnailConverterTest method testConversion.

@Test
public void testConversion() throws IOException, StopProcessingException, PluginExecutionException {
    IIORegistry.getDefaultInstance().registerServiceProvider(jpeg2000ThumbnailConverter);
    List<Result> resultList = new ArrayList<>();
    Metacard metacard = new MetacardImpl();
    byte[] j2kbytes = new byte[0];
    resultList.add(new ResultImpl(metacard));
    QueryResponseImpl queryResponse = new QueryResponseImpl(null, resultList, 1);
    // there are two possible byte signatures, so test an example of each one
    for (String image : new String[] { "/Bretagne2.j2k", "/Cevennes2.jp2" }) {
        URL imageResource = Jpeg2000ThumbnailConverterTest.class.getResource(image);
        if (imageResource == null) {
            fail("The Image Resource came back null. Was the resources folder removed?");
        }
        String imageResourcePath = new File(imageResource.getFile()).getAbsolutePath();
        j2kbytes = Files.readAllBytes(Paths.get(imageResourcePath));
        metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, j2kbytes));
        jpeg2000ThumbnailConverter.process(queryResponse);
        // verify the plugin converted the j2k/jp2 image
        assertTrue(!Arrays.equals(j2kbytes, metacard.getThumbnail()));
    }
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ImageIO.write(ImageIO.read(new ByteArrayInputStream(j2kbytes)), "gif", output);
    metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, output.toByteArray()));
    jpeg2000ThumbnailConverter.process(queryResponse);
    // verify the plugin ignored  the non-j2k
    assertTrue(Arrays.equals(output.toByteArray(), metacard.getThumbnail()));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) URL(java.net.URL) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Test(org.junit.Test)

Example 95 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestExpirationDatePlugin method createMockMetacardsWithNoExpirationDate.

private List<Metacard> createMockMetacardsWithNoExpirationDate(int number) {
    List<Metacard> mockMetacards = new ArrayList(number);
    for (int i = 0; i < number; i++) {
        Metacard mockMetacard = new MetacardImpl();
        Attribute id = new AttributeImpl(Metacard.ID, Integer.toString(i));
        mockMetacard.setAttribute(id);
        Attribute title = new AttributeImpl(Metacard.TITLE, Integer.toString(i));
        mockMetacard.setAttribute(title);
        Attribute createdDate = new AttributeImpl(Core.METACARD_CREATED, CREATED_DATE.toDate());
        mockMetacard.setAttribute(createdDate);
        mockMetacards.add(mockMetacard);
    }
    return mockMetacards;
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

AttributeImpl (ddf.catalog.data.impl.AttributeImpl)181 Metacard (ddf.catalog.data.Metacard)109 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)49 Serializable (java.io.Serializable)30 Date (java.util.Date)30 Attribute (ddf.catalog.data.Attribute)29 List (java.util.List)23 HashMap (java.util.HashMap)20 IOException (java.io.IOException)18 InputStream (java.io.InputStream)17 Result (ddf.catalog.data.Result)15 HashSet (java.util.HashSet)15 PolicyResponse (ddf.catalog.plugin.PolicyResponse)14 ResultImpl (ddf.catalog.data.impl.ResultImpl)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11 Set (java.util.Set)11 ContentItem (ddf.catalog.content.data.ContentItem)10 QueryResponse (ddf.catalog.operation.QueryResponse)10