private static Object createComplexFeatureDocument(final Feature feature) { final Document featureDocument = new Document(); final Object propertiesDocument = feature.getProperties() .map(FeaturesUpdateFactory::createComplexPropertiesRepresentations) .orElseGet(Document::new); featureDocument.append(PersistenceConstants.FIELD_PROPERTIES, propertiesDocument); return featureDocument; }
private static Object createComplexFeatureDocument(final Feature feature) { final Document featureDocument = new Document(); final Object propertiesDocument = feature.getProperties() .map(FeaturesUpdateFactory::createComplexPropertiesRepresentations) .orElseGet(Document::new); featureDocument.append(PersistenceConstants.FIELD_PROPERTIES, propertiesDocument); return featureDocument; }
private Result getModifyOrCreateResult(final Feature feature, final Context context, final long nextRevision, final ModifyFeatureProperties command) { return feature.getProperties() .map(properties -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
private Result getModifyOrCreateResult(final Feature feature, final Context context, final long nextRevision, final ModifyFeatureProperties command) { return feature.getProperties() .map(properties -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
private Result getModifyOrCreateResult(final Feature feature, final Context context, final long nextRevision, final ModifyFeatureProperty command) { return feature.getProperties() .filter(featureProperties -> featureProperties.contains(command.getPropertyPointer())) .map(featureProperties -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
private static List<Document> createPushes(final Feature feature) { final List<Document> result = feature.getProperties() .map(featureProperties -> createFlatFeaturesRepresentation(featureProperties, feature.getId())) .orElseGet(ArrayList::new); result.add(createDefaultFeatureDoc(feature.getId())); return result; }
private static List<Document> createPushes(final Feature feature) { final List<Document> result = feature.getProperties() .map(featureProperties -> createFlatFeaturesRepresentation(featureProperties, feature.getId())) .orElseGet(ArrayList::new); result.add(createDefaultFeatureDoc(feature.getId())); return result; }
private Result getModifyOrCreateResult(final Feature feature, final Context context, final long nextRevision, final ModifyFeatureProperty command) { return feature.getProperties() .filter(featureProperties -> featureProperties.contains(command.getPropertyPointer())) .map(featureProperties -> getModifyResult(context, nextRevision, command)) .orElseGet(() -> getCreateResult(context, nextRevision, command)); }
private Map<Feature, Set<JsonField>> calculateThresholdViolations(final Features features) { return features .stream() .map(feature -> { final Set<JsonField> exceededProps = calculateThresholdViolations( feature.getId(), feature.getProperties().orElse(FeatureProperties.newBuilder().build())); if (!exceededProps.isEmpty()) { return Collections.singletonMap(feature, exceededProps); } return null; }) .filter(Objects::nonNull) .collect(HashMap::new, Map::putAll, Map::putAll); }
private Result getFeatureProperties(final Feature feature, final String thingId, final RetrieveFeatureProperties command, @Nullable final Thing thing) { final String featureId = feature.getId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return feature.getProperties() .map(featureProperties -> RetrieveFeaturePropertiesResponse.of(thingId, featureId, featureProperties, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertiesNotFound(thingId, featureId, dittoHeaders))); }
private Result getFeatureProperties(final Feature feature, final String thingId, final RetrieveFeatureProperties command, @Nullable final Thing thing) { final String featureId = feature.getId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return feature.getProperties() .map(featureProperties -> RetrieveFeaturePropertiesResponse.of(thingId, featureId, featureProperties, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertiesNotFound(thingId, featureId, dittoHeaders))); }
private static Collection<ResourcePermissions> createEntriesForFeature(final Feature feature, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(); result.add(FeatureResourcePermissions.getInstance(feature, policyEnforcer)); final FeatureProperties featureProperties = feature.getProperties().orElseGet( ThingsModelFactory::emptyFeatureProperties); featureProperties.forEach(featureProperty -> result.addAll( createEntriesForFeatureProperty(feature.getId(), JsonFactory.newPointer(featureProperty.getKey()), featureProperty.getValue(), policyEnforcer))); return result; }
private static Collection<ResourcePermissions> createEntriesForFeature(final Feature feature, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(); result.add(FeatureResourcePermissions.getInstance(feature, policyEnforcer)); final FeatureProperties featureProperties = feature.getProperties().orElseGet( ThingsModelFactory::emptyFeatureProperties); featureProperties.forEach(featureProperty -> result.addAll( createEntriesForFeatureProperty(feature.getId(), JsonFactory.newPointer(featureProperty.getKey()), featureProperty.getValue(), policyEnforcer))); return result; }
private Result getRetrieveFeaturePropertyResult(final Feature feature, final Context context, final RetrieveFeatureProperty command, @Nullable final Thing thing) { return feature.getProperties() .map(featureProperties -> getRetrieveFeaturePropertyResult(featureProperties, context, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertiesNotFound(context.getThingId(), feature.getId(), command.getDittoHeaders()))); }
private Result getRetrieveFeaturePropertyResult(final Feature feature, final Context context, final RetrieveFeatureProperty command, @Nullable final Thing thing) { return feature.getProperties() .map(featureProperties -> getRetrieveFeaturePropertyResult(featureProperties, context, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertiesNotFound(context.getThingId(), feature.getId(), command.getDittoHeaders()))); }
/** * Returns a new {@code ImmutableFeatureFromCopyBuilder} which is initialised with the properties of the given * Feature. * * @param feature an existing Feature which provides the properties of the new Feature. * @return the new builder. * @throws NullPointerException if {@code feature} is {@code null}. */ public static ImmutableFeatureFromCopyBuilder of(final Feature feature) { checkNotNull(feature, "Feature"); final ImmutableFeatureFromCopyBuilder result = new ImmutableFeatureFromCopyBuilder(feature.getId()); result.properties(feature.getProperties().orElse(null)); result.definition(feature.getDefinition().orElse(null)); return result; }
/** * Returns a new {@code ImmutableFeatureFromCopyBuilder} which is initialised with the properties of the given * Feature. * * @param feature an existing Feature which provides the properties of the new Feature. * @return the new builder. * @throws NullPointerException if {@code feature} is {@code null}. */ public static ImmutableFeatureFromCopyBuilder of(final Feature feature) { checkNotNull(feature, "Feature"); final ImmutableFeatureFromCopyBuilder result = new ImmutableFeatureFromCopyBuilder(feature.getId()); result.properties(feature.getProperties().orElse(null)); result.definition(feature.getDefinition().orElse(null)); return result; }
private Result getDeleteFeaturePropertiesResult(final Feature feature, final Context context, final long nextRevision, final DeleteFeatureProperties command) { final DittoHeaders dittoHeaders = command.getDittoHeaders(); final String thingId = context.getThingId(); final String featureId = feature.getId(); return feature.getProperties() .map(featureProperties -> ResultFactory.newMutationResult(command, FeaturePropertiesDeleted.of(thingId, featureId, nextRevision, getEventTimestamp(), dittoHeaders), DeleteFeaturePropertiesResponse.of(thingId, featureId, dittoHeaders), this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertiesNotFound(thingId, featureId, dittoHeaders))); }
private Result getDeleteFeaturePropertiesResult(final Feature feature, final Context context, final long nextRevision, final DeleteFeatureProperties command) { final DittoHeaders dittoHeaders = command.getDittoHeaders(); final String thingId = context.getThingId(); final String featureId = feature.getId(); return feature.getProperties() .map(featureProperties -> ResultFactory.newMutationResult(command, FeaturePropertiesDeleted.of(thingId, featureId, nextRevision, getEventTimestamp(), dittoHeaders), DeleteFeaturePropertiesResponse.of(thingId, featureId, dittoHeaders), this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertiesNotFound(thingId, featureId, dittoHeaders))); }
private Result getDeleteFeaturePropertyResult(final Feature feature, final Context context, final long nextRevision, final DeleteFeatureProperty command) { final JsonPointer propertyPointer = command.getPropertyPointer(); final String thingId = context.getThingId(); final String featureId = command.getFeatureId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return feature.getProperties() .flatMap(featureProperties -> featureProperties.getValue(propertyPointer)) .map(featureProperty -> ResultFactory.newMutationResult(command, FeaturePropertyDeleted.of(thingId, featureId, propertyPointer, nextRevision, getEventTimestamp(), dittoHeaders), DeleteFeaturePropertyResponse.of(thingId, featureId, propertyPointer, dittoHeaders), this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertyNotFound(thingId, featureId, propertyPointer, dittoHeaders))); }