public static GeometryElement marshalFrom(Attribute attribute)
      throws CatalogTransformerException {
    GeometryElement element = new GeometryElement();
    element.setName(attribute.getName());
    if (attribute.getValue() != null) {
      for (Serializable value : attribute.getValues()) {
        if (!(value instanceof String)) {
          continue;
        }
        String wkt = (String) value;
        WKTReader wktReader = new WKTReader(geometryFactory);
        Geometry jtsGeometry = null;
        try {
          jtsGeometry = wktReader.read(wkt);
        } catch (ParseException e) {
          throw new CatalogTransformerException(
              "Could not transform Metacard to XML.  Invalid WKT.", e);
        }

        JTSToGML311GeometryConverter converter = new JTSToGML311GeometryConverter();

        @SuppressWarnings("unchecked")
        JAXBElement<AbstractGeometryType> gmlElement =
            (JAXBElement<AbstractGeometryType>) converter.createElement(jtsGeometry);

        GeometryElement.Value geoValue = new GeometryElement.Value();
        geoValue.setGeometry(gmlElement);
        ((GeometryElement) element).getValue().add(geoValue);
      }
    }
    return element;
  }
Exemplo n.º 2
0
  @Override
  public Optional<AttributeValidationReport> validate(final Attribute attribute) {
    Preconditions.checkArgument(attribute != null, "The attribute cannot be null.");

    final String name = attribute.getName();

    for (final Serializable value : attribute.getValues()) {
      final BigDecimal bdValue;
      if (value instanceof Number) {
        bdValue = new BigDecimal(value.toString());
      } else {
        continue;
      }

      if (!checkRange(bdValue)) {
        final String violationMessage =
            String.format(
                "%s must be between %s and %s", name, min.toPlainString(), max.toPlainString());
        final AttributeValidationReportImpl report = new AttributeValidationReportImpl();
        report.addViolation(
            new ValidationViolationImpl(
                Collections.singleton(name), violationMessage, Severity.ERROR));
        return Optional.of(report);
      }
    }

    return Optional.empty();
  }
 private Map<String, Set<String>> buildSecurityMap(Metacard metacard) {
   Map<String, Set<String>> securityMap = new HashMap<>();
   if (metacard != null) {
     for (String metacardAttribute : metacardAttributes) {
       Attribute attribute = metacard.getAttribute(metacardAttribute);
       if (attribute != null) {
         securityMap.put(metacardAttribute, new HashSet<>(listAsStrings(attribute.getValues())));
       }
     }
   }
   return securityMap;
 }
 @Before
 public void setup() {
   wkt = "POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))";
   locationKlvProcessor = new LocationKlvProcessor();
   klvHandler = mock(GeoBoxHandler.class);
   Attribute attribute = mock(Attribute.class);
   when(attribute.getValues()).thenReturn(Collections.singletonList(wkt));
   when(klvHandler.asAttribute()).thenReturn(Optional.of(attribute));
   when(klvHandler.getAttributeName()).thenReturn(AttributeNameConstants.CORNER);
   metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
   klvConfiguration = new KlvProcessor.Configuration();
   handlers = Collections.singletonMap(AttributeNameConstants.CORNER, klvHandler);
 }