Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d2b5290
Remove empty lines.
Apr 6, 2016
f4dc5ff
Use `checkNotDefault()` method.
Apr 6, 2016
18b04be
Add command scheduler to command bus.
Apr 7, 2016
e0e8ecc
Fix command bus tests.
Apr 7, 2016
c4a6e1b
Add more tests.
Apr 7, 2016
637183f
Update protobuf plugin dependency.
Apr 7, 2016
76ce390
Merge branch 'master' into schedule-commands
Apr 8, 2016
82894c4
Make CommandScheduler an abstract class; add docs, tests;
Apr 8, 2016
3598407
Remove `delivery_time` field in command Schedule options, rename othe…
Apr 18, 2016
970ff8f
Improve an error msg.
Apr 18, 2016
292f893
Rename a constant.
Apr 18, 2016
96ade6e
Avoid circular dependency between CommandBus and CommandScheduler.
Apr 18, 2016
bfdcb38
Use mockito spy instead of mock to improve code coverage.
Apr 18, 2016
8689455
Merge branch 'master' into schedule-commands
Apr 18, 2016
2b42bcf
Add test API to aggregate.
Apr 18, 2016
754a161
Track commands which are scheduled already in scheduler.
Apr 18, 2016
b1f115d
Improve command schedule tests.
Apr 19, 2016
951b8b5
Rename aggregate methods for tests.
Apr 19, 2016
4aeca10
Fix tests.
Apr 19, 2016
1b2ecf6
Merge branch 'repos-post-events' into schedule-commands
Apr 19, 2016
9b9674f
Merge branch 'master' into schedule-commands
Apr 19, 2016
a2567ac
Merge branch 'master' into this one.
Apr 19, 2016
5be6343
0.3 version.
Apr 19, 2016
203390e
Update protobuf-plugin dep-cy.
Apr 19, 2016
5384729
Remove redundant tag in docs.
Apr 19, 2016
9193013
Minor changes.
Apr 19, 2016
e225e12
Remove redundant code.
Apr 19, 2016
f7d36d3
Merge branch 'master' into schedule-commands
Apr 19, 2016
cdb9a1e
Add a method to Responses.
Apr 20, 2016
e0e8215
Fix and add command bus tests.
Apr 20, 2016
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
2 changes: 1 addition & 1 deletion 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.2'
version = '0.3'
}

project.ext {
Expand Down
2 changes: 1 addition & 1 deletion client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
classpath group: 'org.spine3.tools', name: 'protobuf-plugin', version: '1.2', changing: true
classpath group: 'org.spine3.tools', name: 'protobuf-plugin', version: '1.3.1', changing: true
}
}

Expand Down
34 changes: 27 additions & 7 deletions client/src/main/java/org/spine3/base/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.common.base.Predicate;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Duration;
import com.google.protobuf.Message;
import com.google.protobuf.Timestamp;
import org.spine3.protobuf.EntityPackagesMap;
Expand All @@ -39,6 +40,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.protobuf.util.TimeUtil.getCurrentTime;
import static org.spine3.validate.Validate.isNotDefault;

/**
* Client-side utilities for working with commands.
Expand All @@ -48,11 +50,12 @@
public class Commands {

/**
* A substring which the {@code .proto} file containing commands must have in its name.
* A suffix which the {@code .proto} file containing commands must have in its name.
*/
public static final String COMMANDS_FILE_SUBSTRING = "commands";
public static final String FILE_NAME_SUFFIX = "commands";

private static final char PROTO_FILE_SEPARATOR = '/';
private static final char FILE_PATH_SEPARATOR = '/';
private static final char FILE_EXTENSION_SEPARATOR = '.';

private Commands() {}

Expand Down Expand Up @@ -193,13 +196,14 @@ public static String formatMessageTypeAndId(String format, Message commandMessag
* Checks if the file is for commands.
*
* @param file a descriptor of a {@code .proto} file to check
* @return {@code true} if the file name contains {@link #COMMANDS_FILE_SUBSTRING} substring, {@code false} otherwise
* @return {@code true} if the file name ends with the {@link #FILE_NAME_SUFFIX}, {@code false} otherwise
*/
public static boolean isCommandsFile(FileDescriptor file) {
final String fqn = file.getName();
final int startIndexOfFileName = fqn.lastIndexOf(PROTO_FILE_SEPARATOR) + 1;
final String fileName = fqn.substring(startIndexOfFileName);
final boolean isCommandsFile = fileName.contains(COMMANDS_FILE_SUBSTRING);
final int startIndexOfFileName = fqn.lastIndexOf(FILE_PATH_SEPARATOR) + 1;
final int endIndexOfFileName = fqn.lastIndexOf(FILE_EXTENSION_SEPARATOR);
final String fileName = fqn.substring(startIndexOfFileName, endIndexOfFileName);
final boolean isCommandsFile = fileName.endsWith(FILE_NAME_SUFFIX);
return isCommandsFile;
}

Expand All @@ -216,4 +220,20 @@ public static boolean isEntityFile(FileDescriptor file) {
final boolean isCommandForEntity = EntityPackagesMap.contains(protoPackage);
return isCommandForEntity;
}

/**
* Checks if the command is scheduled to be delivered later.
*
* @param command a command to check
* @return {@code true} if the command context has a scheduling option set, {@code false} otherwise
*/
public static boolean isScheduled(Command command) {
final Schedule schedule = command.getContext().getSchedule();
final Duration delay = schedule.getAfter();
if (isNotDefault(delay)) {
checkArgument(delay.getSeconds() > 0, "Command delay seconds must be a positive value.");
return true;
}
return false;
}
}
24 changes: 23 additions & 1 deletion client/src/main/java/org/spine3/base/Responses.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import com.google.protobuf.Empty;

import static org.spine3.protobuf.Messages.fromAny;

/**
* Utilities for working with {@link org.spine3.base.Response} objects.
*
Expand All @@ -47,6 +49,8 @@ public static Response ok() {
}

/**
* Checks if the response is OK.
*
* @return {@code true} if the passed response represents `ok` status,
* {@code false} otherwise
*/
Expand All @@ -56,13 +60,31 @@ public static boolean isOk(Response response) {
}

/**
* Checks if the response is `unsupported command`.
*
* @return {@code true} if the passed response represents `unsupported command` error,
* {@code false} otherwise
*/
public static boolean isUnsupportedCommand(Response response) {
if (response.getStatusCase() == Response.StatusCase.ERROR) {
final Error error = response.getError();
return error.getCode() == CommandValidationError.UNSUPPORTED_COMMAND.getNumber();
final boolean isUnsupported = error.getCode() == CommandValidationError.UNSUPPORTED_COMMAND.getNumber();
return isUnsupported;
}
return false;
}

/**
* Checks if the response is `invalid command`.
*
* @return {@code true} if the passed response represents `invalid command` error,
* {@code false} otherwise
*/
public static boolean isInvalidCommand(Response response) {
if (response.getStatusCase() == Response.StatusCase.FAILURE) {
final ValidationFailure failure = fromAny(response.getFailure().getInstance());
final boolean isInvalid = !failure.getConstraintViolationList().isEmpty();
return isInvalid;
}
return false;
}
Expand Down
Loading