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;
  }
Esempio 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);
 }
Esempio n. 5
0
 private PolicyResponse getWritePolicy(Metacard input, Map<String, Serializable> properties) {
   HashMap<String, Set<String>> operationPolicy = new HashMap<>();
   if (Requests.isLocal(properties) && input.getTags().contains(RegistryConstants.REGISTRY_TAG)) {
     Attribute attribute = input.getAttribute(RegistryObjectMetacardType.REGISTRY_BASE_URL);
     if (isRegistryDisabled()
         || (attribute != null
             && attribute.getValue() instanceof String
             && ((String) attribute.getValue()).startsWith(SystemBaseUrl.getBaseUrl()))) {
       operationPolicy.putAll(bypassAccessPolicy);
     } else {
       operationPolicy.putAll(writeAccessPolicy);
     }
   }
   return new PolicyResponseImpl(operationPolicy, new HashMap<>());
 }
Esempio n. 6
0
  private boolean checkPermissions(
      Attribute attr,
      KeyValueCollectionPermission securityPermission,
      Subject subject,
      String action) {
    Map<String, Set<String>> map = null;

    if (attr != null) {
      map = (Map<String, Set<String>>) attr.getValue();
    }
    if (map != null) {
      securityPermission = new KeyValueCollectionPermission(action, map);
    }
    return subject.isPermitted(securityPermission);
  }
Esempio n. 7
0
  private boolean attributeValueMatch(Attribute attribute, AttributeDescriptor descriptor) {

    switch (descriptor.getType().getAttributeFormat()) {
      case STRING:
      case XML:
      case GEOMETRY:
        return attributeValue.equals(attribute.getValue());
      case BOOLEAN:
        return Boolean.valueOf(attributeValue).equals(attribute.getValue());
      case DATE:
        try {
          SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
          dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
          String mappedDate = dateFormat.format(dateFormat.parse(attributeValue));
          String metacardDate = dateFormat.format((Date) attribute.getValue());
          return mappedDate.equals(metacardDate);
        } catch (ParseException e) {
          LOGGER.debug("Unable to parse date and perform comparison.", e);
          return false;
        }
      case SHORT:
        return Short.valueOf(attributeValue).equals(attribute.getValue());
      case INTEGER:
        return Integer.valueOf(attributeValue).equals(attribute.getValue());
      case LONG:
        return Long.valueOf(attributeValue).equals(attribute.getValue());
      case FLOAT:
        return Float.valueOf(attributeValue).equals(attribute.getValue());
      case DOUBLE:
        return Double.valueOf(attributeValue).equals(attribute.getValue());
      case BINARY:
      case OBJECT:
      default:
        LOGGER.debug("Unsupported Attribute Format was attempted for KML Style Mapping.");
        return false;
    }
  }