/** * Returns a new {@link PolicyReferenceTag}. * * @param entityId the ID of the entity referencing the policy. * @param policyTag the {@link PolicyTag}. * @return a new {@link PolicyReferenceTag}. */ public static PolicyReferenceTag of(final String entityId, final PolicyTag policyTag) { return new PolicyReferenceTag(entityId, policyTag); }
private void processPolicyReferenceTag(final PolicyReferenceTag policyReferenceTag) { final String elementIdentifier = policyReferenceTag.asIdentifierString(); LogUtil.enhanceLogWithCorrelationId(log, "policies-tags-sync-" + elementIdentifier); log.debug("Forwarding PolicyReferenceTag '{}'", elementIdentifier); forwardJsonifiableToShardRegion(policyReferenceTag, unused -> policyReferenceTag.getEntityId()); }
private void processPolicyReferenceTag(final PolicyReferenceTag policyReferenceTag) { LogUtil.enhanceLogWithCorrelationId(log, "policies-tags-sync-" + policyReferenceTag.asIdentifierString()); "policy-revision <{}>: <{}>.", new Object[]{thingId, sequenceNumber, policyId, policyRevision, policyReferenceTag.asIdentifierString()}); log.debug("Currently no policy-id is available for the thing <{}>.", thingId); triggerSync = true; } else if (!policyReferenceTag.getPolicyTag().getId().equals(policyId)) { log.debug("Policy-Reference-Tag has different policy-id than the current policy-id <{}> for the " + "thing <{}>: <{}>.", policyId, thingId, policyReferenceTag.asIdentifierString()); } else if (policyReferenceTag.getPolicyTag().getRevision() > policyRevision) { log.info("The Policy-Reference-Tag has a revision which is greater " + "than the current policy-revision <{}> for thing <{}>: <{}>.", policyRevision, thingId, policyReferenceTag.asIdentifierString()); triggerSync = true; } else { log.debug("The Policy-Reference-Tag has a revision which is less than or equal to " + "the current policy-revision <{}> for thing <{}>: <{}>.", policyRevision, thingId, policyReferenceTag.asIdentifierString());
private static Source<Object, NotUsed> toPolicyReferenceTags(final PolicyTag policyTag, final ThingsSearchUpdaterPersistence searchUpdaterPersistence) { return searchUpdaterPersistence.getOutdatedThingIds(policyTag) .map(thingId -> PolicyReferenceTag.of(thingId, policyTag)); } }
private static void addPoliciesStrategies(final MappingStrategiesBuilder builder) { builder .add(PolicyErrorRegistry.newInstance()) .add(PolicyCommandRegistry.newInstance()) .add(PolicyCommandResponseRegistry.newInstance()) .add(PolicyEventRegistry.newInstance()) .add(SudoCommandRegistry.newInstance()) .add(SudoCommandResponseRegistry.newInstance()) .add(StreamingRegistry.newInstance()) .add(Policy.class, (Function<JsonObject, Jsonifiable<?>>) PoliciesModelFactory::newPolicy) .add(PolicyTag.class, jsonObject -> PolicyTag.fromJson(jsonObject)) // do not replace with lambda! .add(BatchedEntityIdWithRevisions.typeOf(PolicyTag.class), BatchedEntityIdWithRevisions.deserializer(jsonObject -> PolicyTag.fromJson(jsonObject))) .add(PolicyReferenceTag.class, jsonObject -> PolicyReferenceTag.fromJson(jsonObject)); // do not replace with lambda! }
private void processPolicyReferenceTag(final PolicyReferenceTag policyReferenceTag) { LogUtil.enhanceLogWithCorrelationId(log, "policies-tags-sync-" + policyReferenceTag.asIdentifierString()); "policy-revision <{}>: <{}>.", new Object[]{thingId, sequenceNumber, policyId, policyRevision, policyReferenceTag.asIdentifierString()}); log.debug("Currently no policy-id is available for the thing <{}>.", thingId); triggerSync = true; } else if (!policyReferenceTag.getPolicyTag().getId().equals(policyId)) { log.debug("Policy-Reference-Tag has different policy-id than the current policy-id <{}> for the " + "thing <{}>: <{}>.", policyId, thingId, policyReferenceTag.asIdentifierString()); } else if (policyReferenceTag.getPolicyTag().getRevision() > policyRevision) { log.info("The Policy-Reference-Tag has a revision which is greater " + "than the current policy-revision <{}> for thing <{}>: <{}>.", policyRevision, thingId, policyReferenceTag.asIdentifierString()); triggerSync = true; } else { log.debug("The Policy-Reference-Tag has a revision which is less than or equal to " + "the current policy-revision <{}> for thing <{}>: <{}>.", policyRevision, thingId, policyReferenceTag.asIdentifierString());
private static Source<Object, NotUsed> toPolicyReferenceTags(final PolicyTag policyTag, final ThingsSearchUpdaterPersistence searchUpdaterPersistence) { return searchUpdaterPersistence.getOutdatedThingIds(policyTag) .map(thingId -> PolicyReferenceTag.of(thingId, policyTag)); } }
private static void addPoliciesStrategies(final MappingStrategiesBuilder builder) { builder.add(PolicyErrorRegistry.newInstance()) .add(PolicyCommandRegistry.newInstance()) .add(PolicyCommandResponseRegistry.newInstance()) .add(PolicyEventRegistry.newInstance()) .add(SudoCommandRegistry.newInstance()) .add(SudoCommandResponseRegistry.newInstance()) .add(StreamingRegistry.newInstance()) .add(Policy.class, (Function<JsonObject, Jsonifiable<?>>) PoliciesModelFactory::newPolicy) .add(PolicyTag.class, jsonObject -> PolicyTag.fromJson(jsonObject)) // do not replace with lambda! .add(BatchedEntityIdWithRevisions.typeOf(PolicyTag.class), BatchedEntityIdWithRevisions.deserializer(jsonObject -> PolicyTag.fromJson(jsonObject))) .add(PolicyReferenceTag.class, jsonObject -> PolicyReferenceTag.fromJson(jsonObject)); // do not replace with lambda! }
private void processPolicyReferenceTag(final PolicyReferenceTag policyReferenceTag) { final String elementIdentifier = policyReferenceTag.asIdentifierString(); LogUtil.enhanceLogWithCorrelationId(log, "policies-tags-sync-" + elementIdentifier); log.debug("Forwarding PolicyReferenceTag '{}'", elementIdentifier); forwardJsonifiableToShardRegion(policyReferenceTag, unused -> policyReferenceTag.getEntityId()); }
/** * Returns a new {@link PolicyReferenceTag}. * * @param entityId the ID of the entity referencing the policy. * @param policyTag the {@link PolicyTag}. * @return a new {@link PolicyReferenceTag}. */ public static PolicyReferenceTag of(final String entityId, final PolicyTag policyTag) { return new PolicyReferenceTag(entityId, policyTag); }
/** * Creates a new {@link PolicyReferenceTag} from a JSON object. * * @param jsonObject the JSON object of which a new {@link PolicyReferenceTag} is to be created. * @return the {@link PolicyReferenceTag} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws IllegalArgumentException if {@code jsonObject} is empty. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} is not valid JSON. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the * expected format. */ public static PolicyReferenceTag fromJson(final JsonObject jsonObject) { final String extractedEntityId = jsonObject.getValueOrThrow(JsonFields.ENTITY_ID); final String extractedPolicyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final long extractedPolicyRev = jsonObject.getValueOrThrow(JsonFields.POLICY_REV); final PolicyTag extractedPolicyTag = PolicyTag.of(extractedPolicyId, extractedPolicyRev); return new PolicyReferenceTag(extractedEntityId, extractedPolicyTag); }
/** * Creates a new {@link PolicyReferenceTag} from a JSON object. * * @param jsonObject the JSON object of which a new {@link PolicyReferenceTag} is to be created. * @return the {@link PolicyReferenceTag} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws IllegalArgumentException if {@code jsonObject} is empty. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} is not valid JSON. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the * expected format. */ public static PolicyReferenceTag fromJson(final JsonObject jsonObject) { final String extractedEntityId = jsonObject.getValueOrThrow(JsonFields.ENTITY_ID); final String extractedPolicyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final long extractedPolicyRev = jsonObject.getValueOrThrow(JsonFields.POLICY_REV); final PolicyTag extractedPolicyTag = PolicyTag.of(extractedPolicyId, extractedPolicyRev); return new PolicyReferenceTag(extractedEntityId, extractedPolicyTag); }