Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# core-java
The Java implementation of the framework core.

[![codecov.io](https://codecov.io/github/SpineEventEngine/core-java/coverage.svg?branch=master)](https://codecov.io/github/SpineEventEngine/core-java?branch=master)
[![license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)

The Java implementation of the framework core.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {
apply plugin: 'jacoco'

group = 'org.spine3'
version = '0.4.2'
version = '0.4.4-SNAPSHOT'
}

project.ext {
Expand All @@ -24,7 +24,7 @@ project.ext {
PROTOBUF_VERSION = '3.0.0-beta-3';
PROTOBUF_DEPENDENCY = "com.google.protobuf:protoc:${project.PROTOBUF_VERSION}";
MAVEN_REPOSITORY_URL = 'http://maven.teamdev.com/repository/spine';
SPINE_PROTOBUF_PLUGIN_VERSION = "1.4.3"
SPINE_PROTOBUF_PLUGIN_VERSION = "1.4.4"
GRPC_VERSION = '0.14.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.spine3.server.failure;
package org.spine3.base;

import com.google.common.base.Throwables;
import com.google.protobuf.Any;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.Timestamp;
import com.google.protobuf.util.TimeUtil;
import org.spine3.base.Failure;

/**
* Abstract base for throwable business failures.
Expand Down
187 changes: 187 additions & 0 deletions client/src/main/java/org/spine3/base/Mismatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright 2016, TeamDev Ltd. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.spine3.base;

import com.google.protobuf.Any;
import com.google.protobuf.Message;

import javax.annotation.Nullable;

import static org.spine3.protobuf.Values.pack;
import static org.spine3.protobuf.Messages.toAny;


/**
* Factories for constructing {@link ValueMismatch} instances for different types of attributes.
*/
public class Mismatch {

private Mismatch() {
}

/**
* Creates a {@link ValueMismatch} instance for a string attribute.
*
* @param expected the value expected by a command, or {@code null} if the command expects not populated field
* @param actual the value found in an entity, or {@code null} if the value is not set
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(@Nullable String expected, @Nullable String actual, String requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();
if (expected != null) {
builder.setExpected(pack(expected));
}

if (actual != null) {
builder.setActual(pack(actual));
}

builder.setRequested(pack(requested));
builder.setVersion(version);

return builder.build();
}

/**
* Creates a {@link ValueMismatch} instance for a integer attribute.
*
* @param expected the value expected by a command
* @param actual the value actual in an entity
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(int expected, int actual, int requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();
builder.setExpected(pack(expected));
builder.setActual(pack(actual));
builder.setRequested(pack(requested));
builder.setVersion(version);

return builder.build();
}

/**
* Creates a {@link ValueMismatch} instance for a long integer attribute.
*
* @param expected the value expected by a command
* @param actual the value actual in an entity
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(long expected, long actual, long requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();
builder.setExpected(pack(expected));
builder.setActual(pack(actual));
builder.setRequested(pack(requested));
builder.setVersion(version);

return builder.build();
}

/**
* Creates a {@link ValueMismatch} instance for a float attribute.
*
* @param expected the value expected by a command
* @param actual the value actual in an entity
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(float expected, float actual, float requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();
builder.setExpected(pack(expected));
builder.setActual(pack(actual));
builder.setRequested(pack(requested));
builder.setVersion(version);

return builder.build();
}

/**
* Creates a {@link ValueMismatch} instance for a double attribute.
*
* @param expected the value expected by a command
* @param actual the value actual in an entity
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(double expected, double actual, double requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();
builder.setExpected(pack(expected));
builder.setActual(pack(actual));
builder.setRequested(pack(requested));
builder.setVersion(version);

return builder.build();
}

/**
* Creates a {@link ValueMismatch} instance for a boolean attribute.
*
* @param expected the value expected by a command
* @param actual the value actual in an entity
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(boolean expected, boolean actual, boolean requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();
builder.setExpected(pack(expected));
builder.setActual(pack(actual));
builder.setRequested(pack(requested));
builder.setVersion(version);

return builder.build();
}

/**
* Creates a {@link ValueMismatch} instance for a Message attribute.
*
* @param expected the value expected by a command, or {@code null} if the command expects not populated field
* @param actual the value actual in an entity, or {@code null} if the value is not set
* @param requested the value requested as new one in the original command
* @param version the current version of the entity
* @return info on the mismatch
*/
public static ValueMismatch of(@Nullable Message expected, @Nullable Message actual, Message requested, int version) {
final ValueMismatch.Builder builder = ValueMismatch.newBuilder();

if (expected != null) {
builder.setExpected(toAny(expected));
}

if (actual != null) {
builder.setActual(toAny(actual));
}

final Any requestedAny = toAny(requested);

builder.setRequested(requestedAny);
builder.setVersion(version);

return builder.build();
}
}
61 changes: 55 additions & 6 deletions client/src/main/java/org/spine3/protobuf/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.spine3.protobuf;

import com.google.protobuf.Any;
import com.google.protobuf.BoolValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.FloatValue;
Expand All @@ -37,7 +38,7 @@ public class Values {
private Values() {}

/**
* Creates a new StringValue wrapping the passed string.
* Creates a new {@code StringValue} wrapping the passed string.
*
* @param value the value to wrap
* @return a new StringValue instance
Expand All @@ -50,7 +51,15 @@ public static StringValue newStringValue(String value) {
}

/**
* Creates a new DoubleValue wrapping the passed number.
* Packs the passed value into {@link Any}.
*/
public static Any pack(String value) {
final Any result = Any.pack(newStringValue(value));
return result;
}

/**
* Creates a new {@code DoubleValue} wrapping the passed number.
*
* @param value the value to wrap
* @return a new DoubleValue instance
Expand All @@ -63,7 +72,15 @@ public static DoubleValue newDoubleValue(double value) {
}

/**
* Creates a new FloatValue wrapping the passed number.
* Packs the passed value into {@link Any}.
*/
public static Any pack(double value) {
final Any result = Any.pack(newDoubleValue(value));
return result;
}

/**
* Creates a new {@code FloatValue} wrapping the passed number.
*
* @param value the value to wrap
* @return a new FloatValue instance
Expand All @@ -76,7 +93,15 @@ public static FloatValue newFloatValue(float value) {
}

/**
* Creates a new Int32Value wrapping the passed number.
* Packs the passed value into {@link Any}.
*/
public static Any pack(float value) {
final Any result = Any.pack(newFloatValue(value));
return result;
}

/**
* Creates a new {@code Int32Value} wrapping the passed number.
*
* @param value the value to wrap
* @return a new Int32Value instance
Expand All @@ -89,7 +114,15 @@ public static Int32Value newIntegerValue(int value) {
}

/**
* Creates a new Int64Value wrapping the passed number.
* Packs the passed value into {@link Any}.
*/
public static Any pack(int value) {
final Any result = Any.pack(newIntegerValue(value));
return result;
}

/**
* Creates a new {@code Int64Value} wrapping the passed number.
*
* @param value the value to wrap
* @return a new Int64Value instance
Expand All @@ -102,7 +135,15 @@ public static Int64Value newLongValue(long value) {
}

/**
* Creates a new BoolValue wrapping the passed value.
* Packs the passed value into {@link Any}.
*/
public static Any pack(long value) {
final Any result = Any.pack(newLongValue(value));
return result;
}

/**
* Creates a new {@code BoolValue} wrapping the passed value.
*
* @param value the value to wrap
* @return a new BoolValue instance
Expand All @@ -113,4 +154,12 @@ public static BoolValue newBoolValue(boolean value) {
.build();
return result;
}

/**
* Packs the passed value into {@link Any}.
*/
public static Any pack(boolean value) {
final Any result = Any.pack(newBoolValue(value));
return result;
}
}
18 changes: 18 additions & 0 deletions client/src/main/proto/spine/base/failure.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ message Failure {
// Additional information on the failure.
map<string, google.protobuf.Value> attributes = 4;
}

// A failure to handle a command because an entity contains a value different than requested in a command.
message ValueMismatch {
// An expected value.
// This field is not populated if the command expects to initialize the attribute.
google.protobuf.Any expected = 1;

// An actual value in the entity.
// This field is not populated if the entity does not have the attribute set.
google.protobuf.Any actual = 2;

// An optional attribute that may contain a value requested as the replacement
// for the `expected` value in the failed command.
google.protobuf.Any requested = 3;

// A version of the entity, which generated the failure.
int32 version = 4;
}
Loading