/** * Returns a new immutable {@link PolicyEntry} based on the given JSON object. * * @param label the Label for the PolicyEntry to create. * @param jsonObject the JSON object representation of a PolicyEntry. * @return the new Policy entry. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.model.base.exceptions.DittoJsonException if {@code jsonObject} cannot be parsed. */ public static PolicyEntry newPolicyEntry(final CharSequence label, final JsonObject jsonObject) { return ImmutablePolicyEntry.fromJson(label, jsonObject); }
/** * Returns a new immutable {@link PolicyEntry} with the given authorization subject and permissions. * * @param label the Label of the PolicyEntry to create. * @param subjects the Subjects contained in the PolicyEntry to create. * @param resources the Resources of the PolicyEntry to create. * @return the new Policy entry. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ public static PolicyEntry newPolicyEntry(final CharSequence label, final Iterable<Subject> subjects, final Iterable<Resource> resources) { return ImmutablePolicyEntry.of(Label.of(label), newSubjects(subjects), newResources(resources)); }
/** * Returns a new {@code PolicyEntry} object of the given Subjects and Resources. * * @param label the Label of the PolicyEntry to create. * @param subjects the Subjects contained in the PolicyEntry to create. * @param resources the Resources of the PolicyEntry to create. * @return a new {@code PolicyEntry} object. * @throws NullPointerException if any argument is {@code null}. */ public static PolicyEntry of(final Label label, final Subjects subjects, final Resources resources) { checkNotNull(subjects, "subjects"); checkNotNull(resources, "resources"); return new ImmutablePolicyEntry(label, subjects, resources); }
/** * Creates a new {@code PolicyEntry} object from the specified JSON object. * * @param label the Label for the PolicyEntry to create. * @param jsonObject a JSON object which provides the data for the Policy entry to be created. If there are more * than one entries in the given JSON object, it'll take the first in the object. * @return a new Policy entry which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code label} or {@code jsonObject} is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. * @throws DittoJsonException if {@code jsonObject} * <ul> * <li>is empty or</li> * <li>contains only a field with the schema version.</li> * </ul> */ public static PolicyEntry fromJson(final CharSequence label, final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); final Label lbl = Label.of(label); try { final JsonObject subjectsJsonObject = jsonObject.getValueOrThrow(JsonFields.SUBJECTS); final Subjects subjectsFromJson = PoliciesModelFactory.newSubjects(subjectsJsonObject); final JsonObject resourcesJsonObject = jsonObject.getValueOrThrow(JsonFields.RESOURCES); final Resources resourcesFromJson = PoliciesModelFactory.newResources(resourcesJsonObject); return of(lbl, subjectsFromJson, resourcesFromJson); } catch (final JsonMissingFieldException e) { throw new DittoJsonException(e); } }
/** * Returns a new immutable {@link PolicyEntry} based on the given JSON value. * * @param label the Label for the PolicyEntry to create. * @param jsonValue the JSON value representation of a PolicyEntry. * @return the new Policy entry. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. * @throws org.eclipse.ditto.model.base.exceptions.DittoJsonException if {@code jsonObject} cannot be parsed. * @throws PolicyIdInvalidException if the parsed policy ID did not comply to {@link Policy#ID_REGEX}. */ public static PolicyEntry newPolicyEntry(final CharSequence label, final JsonValue jsonValue) { final JsonObject jsonObject = wrapJsonRuntimeException(jsonValue::asObject); return ImmutablePolicyEntry.fromJson(label, jsonObject); }
/** * Returns a new immutable {@link PolicyEntry} based on the given JSON string. * * @param label the Label for the PolicyEntry to create. * @param jsonString the JSON object representation as String of a PolicyEntry. * @return the new Policy entry. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.model.base.exceptions.DittoJsonException if {@code jsonObject} cannot be parsed. */ public static PolicyEntry newPolicyEntry(final CharSequence label, final String jsonString) { final JsonObject jsonObject = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); return ImmutablePolicyEntry.fromJson(label, jsonObject); }
.build()); return ImmutablePolicyEntry.fromJson(jsonField.getKey(), jsonValue.asObject()); };