@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects/" + subject.getId(); return JsonPointer.of(path); }
/** * Creates a response to a {@code RetrieveSubject} command. * * @param policyId the Policy ID of the retrieved subject. * @param label the Label of the PolicyEntry. * @param subject the retrieved Subject. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveSubjectResponse of(final String policyId, final Label label, final Subject subject, final DittoHeaders dittoHeaders) { return new RetrieveSubjectResponse(policyId, label, subject.getId().toString(), checkNotNull(subject, "Subject").toJson( dittoHeaders.getSchemaVersion().orElse(subject.getLatestSchemaVersion())), HttpStatusCode.OK, dittoHeaders); }
static Subjects substituteSubjects(final Subjects subjects, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm, final DittoHeaders dittoHeaders) { Subjects newSubjects = subjects; for (final Subject subject : subjects) { final String subjectId = subject.getId().toString(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, dittoHeaders); if (!subjectId.equals(substitutedSubjectId)) { final Subject newSubject = Subject.newInstance(substitutedSubjectId, subject.getType()); newSubjects = newSubjects.removeSubject(subjectId).setSubject(newSubject); } } return newSubjects; }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT_ID, subject.getId().toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT, subject.toJson(schemaVersion, thePredicate), predicate); }
/** * Returns all non hidden marked fields of this Subject. * * @return a JSON object representation of this Subject including only non hidden marked fields. */ @Override default JsonObject toJson() { return toJson(FieldType.notHidden()); }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectIssuerWithId} in the {@link Label} is replaced by the specified one. * * @param label the Label identifying the PolicyEntry to modify. * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to set. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ default PolicyBuilder setSubjectFor(final CharSequence label, final CharSequence subjectIssuerWithId, final SubjectType subjectType) { return setSubjectFor(label, Subject.newInstance(subjectIssuerWithId, subjectType)); }
public PolicyAssert hasSubjectTypeFor(final Label label, final SubjectId subjectId, final SubjectType expectedSubjectType) { isNotNull(); hasSubjectFor(label, subjectId); final Subject subject = actual.getEntryFor(label).get().getSubjects().getSubject(subjectId).get(); assertThat(subject.getType()).isEqualTo(expectedSubjectType) // .overridingErrorMessage( "Expected Label <%s> to contain for SubjectId <%s> SubjectType " + "\n<%s> but did not: \n<%s>", label, subjectId, expectedSubjectType, subject.getType()); return this; }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT_ID, subject.getId().toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT, subject.toJson(schemaVersion, thePredicate), predicate); }
@Override public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subject.toJson(schemaVersion, FieldType.regularOrSpecial())); }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code issuer} and {@code subject} in the {@link Label} is replaced by the specified one. * * @param label the Label identifying the PolicyEntry to modify. * @param issuer the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ default PolicyBuilder setSubjectFor(final CharSequence label, final SubjectIssuer issuer, final CharSequence subject, final SubjectType subjectType) { return setSubjectFor(label, Subject.newInstance(issuer, subject, subjectType)); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects/" + subject.getId(); return JsonPointer.of(path); }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT_ID, subject.getId().toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT, subject.toJson(schemaVersion, thePredicate), predicate); }
@Override public WithDittoHeaders apply(final ModifySubject modifySubject, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm) { requireNonNull(modifySubject); requireNonNull(substitutionAlgorithm); final String subjectId = modifySubject.getSubject().getId().toString(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, modifySubject); if (subjectId.equals(substitutedSubjectId)) { return modifySubject; } else { final Subject newSubject = Subject.newInstance(substitutedSubjectId, modifySubject.getSubject().getType()); return ModifySubject.of(modifySubject.getId(), modifySubject.getLabel(), newSubject, modifySubject.getDittoHeaders()); } } }
/** * Creates a response to a {@code RetrieveSubject} command. * * @param policyId the Policy ID of the retrieved subject. * @param label the Label of the PolicyEntry. * @param subject the retrieved Subject. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveSubjectResponse of(final String policyId, final Label label, final Subject subject, final DittoHeaders dittoHeaders) { return new RetrieveSubjectResponse(policyId, label, subject.getId().toString(), checkNotNull(subject, "Subject").toJson( dittoHeaders.getSchemaVersion().orElse(subject.getLatestSchemaVersion())), HttpStatusCode.OK, dittoHeaders); }
@Override public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subject.toJson(schemaVersion, FieldType.regularOrSpecial())); }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectId} in the {@link Label} is replaced by the specified one. Sets the subject type * to {@link SubjectType#GENERATED}. * * @param issuer the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped setSubject(final SubjectIssuer issuer, final CharSequence subject) { setSubjectFor(getLabel(), Subject.newInstance(issuer, subject)); return this; }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects/" + subject.getId(); return JsonPointer.of(path); }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT_ID, subject.getId().toString(), predicate); jsonObjectBuilder.set(JSON_SUBJECT, subject.toJson(schemaVersion, thePredicate), predicate); }
@Override public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(subjectCreated).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectIssuerWithId} in the {@link Label} is replaced by the specified one. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to set. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped setSubject(final CharSequence subjectIssuerWithId, final SubjectType subjectType) { setSubjectFor(getLabel(), Subject.newInstance(subjectIssuerWithId, subjectType)); return this; }