/** * Returns a new {@code Subject} with the specified {@code subjectId} and {@code subjectType}. * * @param subjectId the ID of the new Subject to create. * @param subjectType the SubjectType of the new Subject to create. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final SubjectId subjectId, final SubjectType subjectType) { return PoliciesModelFactory.newSubject(subjectId, subjectType); }
private static Subject createSubjectForPut(final String jsonString, final CharSequence subjectId) { final JsonObject jsonObject = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); final String subjectTypeString = jsonObject.getValueOrThrow(Subject.JsonFields.TYPE); final SubjectType subjectType = PoliciesModelFactory.newSubjectType(subjectTypeString); return PoliciesModelFactory.newSubject(SubjectId.newInstance(subjectId), subjectType); }
/** * Returns a new {@code Subject} object with the given {@code subjectId} and * subject type {@link SubjectType#GENERATED}. * * @param subjectId the ID of the new Subject. * @return a new {@code Subject} object. * @throws NullPointerException if {@code subjectId} is {@code null}. */ static Subject newInstance(final SubjectId subjectId) { return PoliciesModelFactory.newSubject(subjectId); }
/** * Returns the retrieved Subject. * * @return the retrieved Subject. */ public Subject getSubject() { return PoliciesModelFactory.newSubject(subjectId, subject); }
/** * Returns the retrieved Subject. * * @return the retrieved Subject. */ public Subject getSubject() { return PoliciesModelFactory.newSubject(subjectId, subject); }
/** * Returns a new {@code Subject} with the specified {@code issuer}, {@code subject} and * subject type {@link SubjectType#GENERATED}. * * @param issuer the character sequence for the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final SubjectIssuer issuer, final CharSequence subject) { return PoliciesModelFactory.newSubject(SubjectId.newInstance(issuer, subject)); }
/** * Returns a new {@code Subject} with the specified {@code issuer}, {@code subject} and {@code subjectType}. * * @param issuer the character sequence for the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @param subjectType the SubjectType of the new Subject to create. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final SubjectIssuer issuer, final CharSequence subject, final SubjectType subjectType) { return PoliciesModelFactory.newSubject(SubjectId.newInstance(issuer, subject), subjectType); }
/** * Returns a new {@code Subject} with the specified {@code subjectIssuerWithId} and {@code subjectType}. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to create. * @param subjectType the SubjectType of the new Subject to create. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final CharSequence subjectIssuerWithId, final SubjectType subjectType) { return PoliciesModelFactory.newSubject(SubjectId.newInstance(subjectIssuerWithId), subjectType); }
/** * Creates a new {@code Subjects} from the specified JSON object. * * @param jsonObject the JSON object of which a new Subjects instance is to be created. * @return the {@code Subjects} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'Subjects' format. */ public static ImmutableSubjects fromJson(final JsonObject jsonObject) { final Function<JsonField, Subject> toSubject = jsonField -> { final JsonValue jsonValue = jsonField.getValue(); if (!jsonValue.isObject()) { throw new JsonParseException(MessageFormat.format("<{0}> is not a JSON object!", jsonValue)); } return PoliciesModelFactory.newSubject(jsonField.getKey(), jsonValue.asObject()); }; final List<Subject> theSubjects = jsonObject.stream() .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey())) .map(toSubject) .collect(Collectors.toList()); return of(theSubjects); }
/** * Creates a response to a {@code ModifySubject} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected format. */ public static ModifySubjectResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<ModifySubjectResponse>(TYPE, jsonObject) .deserialize((statusCode) -> { final String policyId = jsonObject.getValueOrThrow(PolicyModifyCommandResponse.JsonFields.JSON_POLICY_ID); final Label label = PoliciesModelFactory.newLabel(jsonObject.getValueOrThrow(JSON_LABEL)); final Optional<String> extractedSubjectId = jsonObject.getValue(JSON_SUBJECT_ID); final Subject extractedSubjectCreated = jsonObject.getValue(JSON_SUBJECT) .map(JsonValue::asObject) .map(obj -> extractedSubjectId.map(s -> PoliciesModelFactory.newSubject(s, obj)) .orElse(null)) .orElse(null); return new ModifySubjectResponse(policyId, label, extractedSubjectCreated, statusCode, dittoHeaders); }); }
/** * Creates a response to a {@code ModifySubject} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected format. */ public static ModifySubjectResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<ModifySubjectResponse>(TYPE, jsonObject) .deserialize((statusCode) -> { final String policyId = jsonObject.getValueOrThrow(PolicyModifyCommandResponse.JsonFields.JSON_POLICY_ID); final Label label = PoliciesModelFactory.newLabel(jsonObject.getValueOrThrow(JSON_LABEL)); final Optional<String> extractedSubjectId = jsonObject.getValue(JSON_SUBJECT_ID); final Subject extractedSubjectCreated = jsonObject.getValue(JSON_SUBJECT) .map(JsonValue::asObject) .map(obj -> extractedSubjectId.map(s -> PoliciesModelFactory.newSubject(s, obj)) .orElse(null)) .orElse(null); return new ModifySubjectResponse(policyId, label, extractedSubjectCreated, statusCode, dittoHeaders); }); }
/** * Creates a command for modifying {@code Subject} of a {@code Policy}'s {@code PolicyEntry} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static ModifySubject fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifySubject>(TYPE, jsonObject).deserialize(() -> { final String policyId = jsonObject.getValueOrThrow(PolicyModifyCommand.JsonFields.JSON_POLICY_ID); final Label label = PoliciesModelFactory.newLabel(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectId = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final JsonObject subjectJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECT); final Subject subject = PoliciesModelFactory.newSubject(subjectId, subjectJsonObject); return of(policyId, label, subject, dittoHeaders); }); }
/** * Creates a new {@code SubjectModified} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectModified instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectModified} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected 'SubjectModified' format. */ public static SubjectModified fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectModified>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectId = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final JsonObject subjectJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECT); final Subject extractedModifiedSubject = PoliciesModelFactory.newSubject(subjectId, subjectJsonObject); return of(policyId, label, extractedModifiedSubject, revision, timestamp, dittoHeaders); }); }
/** * Creates a new {@code SubjectCreated} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectCreated instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectCreated} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected 'SubjectCreated' format. */ public static SubjectCreated fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectCreated>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectId = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final JsonObject subjectJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECT); final Subject extractedCreatedSubject = PoliciesModelFactory.newSubject(subjectId, subjectJsonObject); return of(policyId, label, extractedCreatedSubject, revision, timestamp, dittoHeaders); }); }
/** * Creates a new {@code SubjectCreated} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectCreated instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectCreated} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected 'SubjectCreated' format. */ public static SubjectCreated fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectCreated>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectId = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final JsonObject subjectJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECT); final Subject extractedCreatedSubject = PoliciesModelFactory.newSubject(subjectId, subjectJsonObject); return of(policyId, label, extractedCreatedSubject, revision, timestamp, dittoHeaders); }); }
/** * Creates a new {@code SubjectModified} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectModified instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectModified} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected 'SubjectModified' format. */ public static SubjectModified fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectModified>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectId = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final JsonObject subjectJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECT); final Subject extractedModifiedSubject = PoliciesModelFactory.newSubject(subjectId, subjectJsonObject); return of(policyId, label, extractedModifiedSubject, revision, timestamp, dittoHeaders); }); }
/** * Creates a command for modifying {@code Subject} of a {@code Policy}'s {@code PolicyEntry} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static ModifySubject fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifySubject>(TYPE, jsonObject).deserialize(() -> { final String policyId = jsonObject.getValueOrThrow(PolicyModifyCommand.JsonFields.JSON_POLICY_ID); final Label label = PoliciesModelFactory.newLabel(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectId = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final JsonObject subjectJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECT); final Subject subject = PoliciesModelFactory.newSubject(subjectId, subjectJsonObject); return of(policyId, label, subject, dittoHeaders); }); }