Search in sources :

Example 41 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class AttributeImplTest method testDeserializationCorruption.

/**
     * Tests what happens when someone tries to manually change the serialized object after it has
     * been serialized. The expected outcome is that it will be detected that the object is corrupt.
     * The original serialized object's name field was "id", it was manually changed, then saved
     * again.
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
@Test(expected = StreamCorruptedException.class)
public void testDeserializationCorruption() throws IOException, ClassNotFoundException {
    String fileLocation = "src/test/resources/tamperedAttributeImpl.ser";
    Serializer<Attribute> serializer = new Serializer<Attribute>();
    Attribute readAttribute1 = serializer.deserialize(fileLocation);
    readAttribute1.getName();
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 42 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class AttributeImplTest method testSerializationMultiple.

@Test
public void testSerializationMultiple() throws IOException, ClassNotFoundException {
    toTest = new AttributeImpl("id", UUID.randomUUID().toString());
    toTest.addValue(UUID.randomUUID().toString());
    toTest.addValue(UUID.randomUUID().toString());
    toTest.addValue(UUID.randomUUID().toString());
    toTest.addValue(UUID.randomUUID().toString());
    Attribute read = serializationLoop(toTest);
    assertEquals(toTest.getName(), read.getName());
    assertEquals(toTest.getValue(), read.getValue());
    assertEquals(toTest.getValues(), read.getValues());
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 43 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RequiredAttributesMetacardValidator method validateMetacard.

@Override
public Optional<MetacardValidationReport> validateMetacard(final Metacard metacard) {
    Preconditions.checkArgument(metacard != null, "The metacard cannot be null.");
    final MetacardType metacardType = metacard.getMetacardType();
    if (metacardTypeName.equals(metacardType.getName())) {
        final Set<ValidationViolation> violations = new HashSet<>();
        for (final String attributeName : requiredAttributes) {
            final Attribute attribute = metacard.getAttribute(attributeName);
            if (attribute != null) {
                final AttributeDescriptor descriptor = metacardType.getAttributeDescriptor(attributeName);
                if (descriptor.isMultiValued()) {
                    if (attribute.getValues().size() == 0) {
                        addRequiredAttributeViolation(attributeName, violations);
                    }
                } else if (attribute.getValue() == null) {
                    addRequiredAttributeViolation(attributeName, violations);
                }
            } else {
                addRequiredAttributeViolation(attributeName, violations);
            }
        }
        if (violations.size() > 0) {
            return getReport(violations);
        }
    }
    return Optional.empty();
}
Also used : ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) HashSet(java.util.HashSet)

Example 44 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class GetRecordsResponseConverter method unmarshal.

/**
     * Parses GetRecordsResponse XML of this form:
     * <p>
     * <pre>
     * {@code
     *  <csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw">
     *      <csw:SearchStatus status="subset" timestamp="2013-05-01T02:13:36+0200"/>
     *      <csw:SearchResults elementSet="full" nextRecord="11"
     *          numberOfRecordsMatched="479" numberOfRecordsReturned="10"
     *          recordSchema="csw:Record">
     *          <csw:Record xmlns:csw="http://www.opengis.net/cat/csw">
     *          ...
     *          </csw:Record>
     *          <csw:Record xmlns:csw="http://www.opengis.net/cat/csw">
     *          ...
     *          </csw:Record>
     *  }
     * </pre>
     */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    if (transformProvider == null) {
        throw new ConversionException("Unable to locate Converter for outputSchema: " + CswConstants.CSW_OUTPUT_SCHEMA);
    }
    CswRecordCollection cswRecords = new CswRecordCollection();
    List<Metacard> metacards = cswRecords.getCswRecords();
    XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        if (reader.getNodeName().contains("SearchResults")) {
            setSearchResults(reader, cswRecords);
            // <csw:Record> into a Metacard
            while (reader.hasMoreChildren()) {
                // move down to the <csw:Record> tag
                reader.moveDown();
                String name = reader.getNodeName();
                LOGGER.debug("node name = {}", name);
                Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class, transformProvider);
                metacards.add(metacard);
                // move back up to the <SearchResults> parent of the
                // <csw:Record> tags
                reader.moveUp();
            }
        }
        reader.moveUp();
    }
    LOGGER.debug("Unmarshalled {} metacards", metacards.size());
    if (LOGGER.isTraceEnabled()) {
        int index = 1;
        for (Metacard m : metacards) {
            LOGGER.trace("metacard {}: ", index);
            LOGGER.trace("    id = {}", m.getId());
            LOGGER.trace("    title = {}", m.getTitle());
            // Some CSW services return an empty bounding box, i.e., no lower
            // and/or upper corner positions
            Attribute boundingBoxAttr = m.getAttribute("BoundingBox");
            if (boundingBoxAttr != null) {
                LOGGER.trace("    bounding box = {}", boundingBoxAttr.getValue());
            }
            index++;
        }
    }
    return cswRecords;
}
Also used : ConversionException(javax.measure.converter.ConversionException) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 45 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class GmdConverter method addCRSInformation.

protected void addCRSInformation(MetacardImpl metacard, XstreamPathValueTracker pathValueTracker) {
    Attribute attribute = metacard.getAttribute(Location.COORDINATE_REFERENCE_SYSTEM_CODE);
    if (attribute != null && CollectionUtils.isNotEmpty(attribute.getValues())) {
        attribute.getValues().forEach(serializable -> {
            if (serializable instanceof String) {
                String[] crsSplit = ((String) serializable).split(":", 2);
                if (crsSplit.length == 2) {
                    pathValueTracker.add(new Path(GmdConstants.CRS_CODE_PATH), crsSplit[1]);
                    pathValueTracker.add(new Path(GmdConstants.CRS_AUTHORITY_PATH), crsSplit[0]);
                }
            }
        });
    }
}
Also used : Path(com.thoughtworks.xstream.io.path.Path) Attribute(ddf.catalog.data.Attribute)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7