@Override public FromScratch setFeatureProperties(final String featureId, final FeatureProperties featureProperties) { checkNotNull(featureId, "ID of the Feature to set the properties for"); checkNotNull(featureProperties, "FeatureProperties to be set"); invokeOnFeaturesBuilder(fb -> fb.set(fb.get(featureId) .map(feature -> feature.setProperties(featureProperties)) .orElseGet(() -> ThingsModelFactory.newFeature(featureId, featureProperties)))); return this; }
@Override public FromScratch setFeatureProperties(final String featureId, final FeatureProperties featureProperties) { checkNotNull(featureId, "ID of the Feature to set the properties for"); checkNotNull(featureProperties, "FeatureProperties to be set"); invokeOnFeaturesBuilder(fb -> fb.set(fb.get(featureId) .map(feature -> feature.setProperties(featureProperties)) .orElseGet(() -> ThingsModelFactory.newFeature(featureId, featureProperties)))); return this; }
@Override public Features setProperties(final String featureId, final FeatureProperties properties) { checkNotNull(properties, "properties to be set"); Feature feature = getFeatureOrNull(featureId); if (null != feature) { feature = feature.setProperties(properties); } else { feature = ThingsModelFactory.newFeature(featureId, properties); } return setFeature(feature); }
/** * Enforce size restrictions on the features and build a new instance that satisfies the thresholds. * * @param features the features. * @return The features with content that satisfies the thresholds. */ public Features enforceRestrictions(@Nonnull final Features features) { // check if features exceed limits final Map<Feature, Set<JsonField>> exceededFeatures = calculateThresholdViolations(features); if (!exceededFeatures.isEmpty()) { log.warning("Properties of following features exceed size restrictions: <{}>", exceededFeatures.keySet() .stream() .map(Feature::getId) .collect(Collectors.toList())); final FeaturesBuilder builder = features.toBuilder(); exceededFeatures.forEach((feature, jsonFields) -> { final FeatureProperties newProps = fixViolations( feature.getId(), jsonFields, feature.getProperties().orElse(FeatureProperties.newBuilder().build())); builder.set(feature.setProperties(newProps)); }); return builder.build(); } return features; }
@Override public Features setProperties(final String featureId, final FeatureProperties properties) { checkNotNull(properties, "properties to be set"); Feature feature = getFeatureOrNull(featureId); if (null != feature) { feature = feature.setProperties(properties); } else { feature = ThingsModelFactory.newFeature(featureId, properties); } return setFeature(feature); }
/** * Enforce size restrictions on the features and build a new instance that satisfies the thresholds. * * @param features the features. * @return The features with content that satisfies the thresholds. */ public Features enforceRestrictions(@Nonnull final Features features) { // check if features exceed limits final Map<Feature, Set<JsonField>> exceededFeatures = calculateThresholdViolations(features); if (!exceededFeatures.isEmpty()) { log.warning("Properties of following features exceed size restrictions: <{}>", exceededFeatures.keySet() .stream() .map(Feature::getId) .collect(Collectors.toList())); final FeaturesBuilder builder = features.toBuilder(); exceededFeatures.forEach((feature, jsonFields) -> { final FeatureProperties newProps = fixViolations( feature.getId(), jsonFields, feature.getProperties().orElse(FeatureProperties.newBuilder().build())); builder.set(feature.setProperties(newProps)); }); return builder.build(); } return features; }
/** * Enforce size restrictions on the feature and build a new instance that satisfies the thresholds. * * @param feature the feature. * @return The feature with content that satisfies the thresholds. */ public Feature enforceRestrictions(final Feature feature) { final Set<JsonField> exceededProps = calculateThresholdViolations( feature.getId(), feature.getProperties().orElse(FeatureProperties.newBuilder().build())); if (!exceededProps.isEmpty()) { log.warning("Feature <{}> exceeds size restriction for properties: <{}>", feature.getId(), exceededProps.stream() .map(JsonField::getKey) .map(CharSequence::toString) .collect(Collectors.toList())); final FeatureProperties newProps = fixViolations( feature.getId(), exceededProps, feature.getProperties().orElse(FeatureProperties.newBuilder().build())); return feature.setProperties(newProps); } return feature; }
/** * Enforce size restrictions on the feature and build a new instance that satisfies the thresholds. * * @param feature the feature. * @return The feature with content that satisfies the thresholds. */ public Feature enforceRestrictions(final Feature feature) { final Set<JsonField> exceededProps = calculateThresholdViolations( feature.getId(), feature.getProperties().orElse(FeatureProperties.newBuilder().build())); if (!exceededProps.isEmpty()) { log.warning("Feature <{}> exceeds size restriction for properties: <{}>", feature.getId(), exceededProps.stream() .map(JsonField::getKey) .map(CharSequence::toString) .collect(Collectors.toList())); final FeatureProperties newProps = fixViolations( feature.getId(), exceededProps, feature.getProperties().orElse(FeatureProperties.newBuilder().build())); return feature.setProperties(newProps); } return feature; }