Skip to content

Conversation

@dmdashenkov
Copy link
Contributor

@dmdashenkov dmdashenkov commented May 31, 2021

In this PR we move the validation codegen from an example repository to this new dedicated repository.

Validation logic is now split into model — a language-agnostic base, which assembles validation rules, and java — a Java-specific implementation, which generates Java code based on model.

@dmdashenkov dmdashenkov self-assigned this May 31, 2021
@dmdashenkov dmdashenkov marked this pull request as ready for review May 31, 2021 16:06
@dmdashenkov
Copy link
Contributor Author

@armiol, @alexander-yevsyukov, PTAL.

As there are many changed files, in this PR we will only migrate the codebase from kanban and split it into a language-agnostic and a Java-specific part. In further PRs, we're going to add integration tests, along with usage instructions.

Copy link
Collaborator

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmdashenkov please see my comments.
Also, I am not sure which version this artifact has. I was looking for version.gradle.kts, but found none.

// Represents a repeated `Value`.
ListValue list_value = 8;

// Represents a repeated `Value`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListValue is indeed a repeated element, but this is MapValue. Therefore, I would assume it represents the values of Protobuf map<.., ..> collection.

@NotNull
private static Value primitiveValue(Type type) {
PrimitiveType primitiveType = type.getPrimitive();
if (primitiveType == PrimitiveType.PT_UNKNOWN || primitiveType == PrimitiveType.UNRECOGNIZED) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My IDEA tells me this line exceeds the max width.

Perhaps, a static import is missing?

.setBytesValue(ByteString.EMPTY)
.vBuild();
}
throw Exceptions.newIllegalStateException(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would import this method statically.


@Subscribe
void on(SimpleRuleAdded event) {
Rule roc = Rule
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am having hard time imagining why this is roc :)

I would understand if that's a rot ("rule of thumb"), but with "roc" you got me here and in the next method as well.

* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

@CheckReturnValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the package.

BTW, do we really want to re-use this package for events, projections etc generated from Proto definitions? I would go for ... .event, ... .command — as we usually do for Bounded contexts.

@dmdashenkov
Copy link
Contributor Author

@alexander-yevsyukov, PTAL.

Copy link
Collaborator

@alexander-yevsyukov alexander-yevsyukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments.

@React
public EitherOf2<SimpleRuleAdded, Nothing> whenever(@External FieldOptionDiscovered event) {
Option option = event.getOption();
if (isRequired(option)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please invert the if condition. It would reduce the nesting.

.stream()
.filter(f -> f.getName().equals(event.getField()))
.findAny()
.orElseThrow(() -> newIllegalArgumentException(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract creation on this and previous exception. It would make this complex method more readable.

@SuppressWarnings({"DuplicateStringLiteralInspection", "RedundantSuppression"})
// Duplication in generated code.
SimpleRule rule = SimpleRule.newBuilder()
.setErrorMessage("Field must be set.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap this block to the left, please.

.setOtherValue(defaultValue)
.vBuild();
return SimpleRuleAdded.newBuilder()
.setType(field.getDeclaringType())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap this block to the left, please.

*/
final class RequiredRulePolicy extends Policy<FieldOptionDiscovered> {

@NotNull
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do without this annotation?

public final class SpineOptionsProvider implements OptionsProvider {

@Override
public void dumpTo(@NotNull ExtensionRegistry registry) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use annotations from Checker Framework.

Copy link
Collaborator

@alexander-yevsyukov alexander-yevsyukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmdashenkov please see my comment, as per our discussion.

import static io.spine.util.Exceptions.newIllegalStateException;

/**
* A factory of {@link Value}s representing default states of Protobuf message fields.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed vocally, let's expand this documentation piece.

In particular, we need to describe the difference between this factory and io.spine.protobuf.Messages (which on the surface looks more promising, equipped with some caching strategy).

@dmdashenkov dmdashenkov requested a review from armiol June 8, 2021 10:12
@dmdashenkov
Copy link
Contributor Author

dmdashenkov commented Jun 8, 2021

@armiol, PTAL.

Copy link
Collaborator

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmdashenkov LGTM.

@dmdashenkov dmdashenkov merged commit 4d14dc5 into master Jun 8, 2021
@dmdashenkov dmdashenkov deleted the introduce-validation-code branch June 8, 2021 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants