@Override public String asIdentifierString() { return entityId + ENTITY_ID_FROM_POLICY_TAG_SEPARATOR + policyTag.getRevision(); }
/** * Returns a new {@link PolicyTag}. * * @param id the ID of the modified Policy. * @param revision the revision of the modified Policy. * @return a new {@link PolicyTag}. */ public static PolicyTag of(final String id, final long revision) { return new PolicyTag(id, revision); }
@Override public JsonValue toJson() { return JsonFactory.newObjectBuilder() .set(JsonFields.ENTITY_ID, entityId) .set(JsonFields.POLICY_ID, policyTag.getId()) .set(JsonFields.POLICY_REV, policyTag.getRevision()) .build(); }
private static PolicyTag createElement(final PidWithSeqNr pidWithSeqNr) { final String id = pidWithSeqNr.getPersistenceId() .replaceFirst(PolicyPersistenceActor.PERSISTENCE_ID_PREFIX, ""); return PolicyTag.of(id, pidWithSeqNr.getSequenceNr()); } }
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! }
@Override public JsonObject toJson() { return JsonFactory.newObjectBuilder() .set(JsonFields.ENTITY_ID, entityId) .set(JsonFields.POLICY_ID, policyTag.getId()) .set(JsonFields.POLICY_REV, policyTag.getRevision()) .build(); }
private static PolicyTag createElement(final PidWithSeqNr pidWithSeqNr) { final String id = pidWithSeqNr.getPersistenceId() .replaceFirst(PolicyPersistenceActor.PERSISTENCE_ID_PREFIX, ""); return PolicyTag.of(id, pidWithSeqNr.getSequenceNr()); } }
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! }
@Override public Source<String, NotUsed> getOutdatedThingIds(final PolicyTag policyTag) { log.debug("Retrieving outdated Thing ids with policy tag: <{}>", policyTag); final String policyId = policyTag.getId(); final Bson filter = and(eq(FIELD_POLICY_ID, policyId), lt(FIELD_POLICY_REVISION, policyTag.getRevision())); final Publisher<Document> publisher = collection.find(filter).projection(new BsonDocument(FIELD_ID, new BsonInt32(1))); return Source.fromPublisher(publisher) .map(doc -> doc.getString(FIELD_ID)); }
@Override public String asIdentifierString() { return entityId + ENTITY_ID_FROM_POLICY_TAG_SEPARATOR + policyTag.getRevision(); }
/** * 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); }
/** * Returns a new {@link PolicyTag}. * * @param id the ID of the modified Policy. * @param revision the revision of the modified Policy. * @return a new {@link PolicyTag}. */ public static PolicyTag of(final String id, final long revision) { return new PolicyTag(id, revision); }
@Override public Source<String, NotUsed> getOutdatedThingIds(final PolicyTag policyTag) { log.debug("Retrieving outdated Thing ids with policy tag: <{}>", policyTag); final String policyId = policyTag.getId(); final Bson filter = and(eq(FIELD_POLICY_ID, policyId), lt(FIELD_POLICY_REVISION, policyTag.getRevision())); final Publisher<Document> publisher = collection.find(filter).projection(new BsonDocument(FIELD_ID, new BsonInt32(1))); return Source.fromPublisher(publisher) .map(doc -> doc.getString(FIELD_ID)); }
/** * 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 PolicyTag} from a JSON object. * * @param jsonObject the JSON object of which a new {@link PolicyTag} is to be created. * @return the {@link PolicyTag} 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 PolicyTag fromJson(final JsonObject jsonObject) { return new PolicyTag(jsonObject); }
log.debug("Currently no policy-id is available for the thing <{}>.", thingId); triggerSync = true; } else if (!policyReferenceTag.getPolicyTag().getId().equals(policyId)) { } 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,
/** * Creates a new {@link PolicyTag} from a JSON object. * * @param jsonObject the JSON object of which a new {@link PolicyTag} is to be created. * @return the {@link PolicyTag} 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 PolicyTag fromJson(final JsonObject jsonObject) { return new PolicyTag(jsonObject); }
log.debug("Currently no policy-id is available for the thing <{}>.", thingId); triggerSync = true; } else if (!policyReferenceTag.getPolicyTag().getId().equals(policyId)) { } 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,