本文整理汇总了Java中org.axonframework.commandhandling.annotation.CommandHandler类的典型用法代码示例。如果您正苦于以下问题:Java CommandHandler类的具体用法?Java CommandHandler怎么用?Java CommandHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandHandler类属于org.axonframework.commandhandling.annotation包,在下文中一共展示了CommandHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRegisterUserAggregate
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public UserIdentifier handleRegisterUserAggregate(RegisterUserCommand command) {
if (log.isDebugEnabled()) {
log.debug("Handling: " + command.getClass().getSimpleName());
}
UserIdentifier id = command.getUserId();
UserAggregate u = new UserAggregate(
id,
UserConstants.SITE_SOURCE,
command.getUsername(),
passwordEncryptor.encryptPassword(command.getPassword()),
command.getEmail(),
command.getFirstName(),
command.getLastName(),
command.getProfilePictureUrl(),
command.getGender(),
Collections.singletonList(PlatformConstants.DEFAULT_USER_ROLE)
);
// persist user aggregate
userAggregateRepository.add(u);
return id;
}
示例2: handleCreateUserAggregate
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public UserIdentifier handleCreateUserAggregate(CreateUserCommand command) {
if (log.isDebugEnabled()) {
log.debug("Handling: " + command.getClass().getSimpleName());
}
UserIdentifier id = command.getUserId();
UserAggregate u = new UserAggregate(
id,
UserConstants.SITE_SOURCE,
command.getUsername(),
passwordEncryptor.encryptPassword(command.getPassword()),
command.getEmail(),
command.getFirstName(),
command.getLastName(),
command.getProfilePictureUrl(),
command.getGender(),
command.getRoles()
);
// persist user aggregate
userAggregateRepository.add(u);
return id;
}
示例3: handle
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void handle(AddOrganizationAlias command) {
AliasService aliasService = ApplicationServiceRegistry.aliasService();
if (aliasService.isDefined(AliasGroups.USERS_AND_ORGANIZATIONS.name(), command.getAlias())) {
if (aliasService.isIdentical(AliasGroups.USERS_AND_ORGANIZATIONS.name(), command.getAlias(), command.getOrganizationId().identifier())) {
// idempotent, ok to register same alias and instance twice
return;
}
// alias already in use by other target -> action denied
//apply(new OrganizationAliasRegistrationDenied(command.getOrganizationId(), command.getServiceInstanceId(), command.getAlias()));
return;
}
if (aliasService.hasTarget(AliasGroups.USERS_AND_ORGANIZATIONS.name(), command.getOrganizationId().identifier())) {
apply(new OrganizationAliasAdded(command.getOrganizationId(), command.getAlias()));
} else {
// there's a first time for everything
apply(new OrganizationPrimaryAliasAdded(command.getOrganizationId(), command.getAlias()));
}
}
示例4: handle
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void handle(AuthorizeMembershipToOrganizationCreator command) {
Organization organization = repository.load(command.getOrganizationId());
if (organization.isDeleted()) {
throw new IllegalArgumentException("Organization exists no more. " + command.getOrganizationId());
}
Membership membership = new Membership(
command.getMembershipId(),
command.getOrganizationId(),
command.getUsername(),
"",
Membership.ApplicationType.CREATOR
);
membershipRepository.add(membership);
}
示例5: User
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public User(RegisterUser command) {
this();
assertValidEmailAddress(command.getEmailAddress());
assertValidUsername(command.getPrefferedUsername());
assertPasswordComply(command.getPrefferedUsername(), command.getPassword());
String emailVerificationCode = new UnconfirmedEmailAddress(command.getEmailAddress()).activationCode().toString();
// HACK: FIXME: TODO:
// supply hardcoded code in odrer to auto-create users for test and demo without reading mails
emailVerificationCode = a_HACK_TEST_useStaticVerificationCode(command.getEmailAddress(), emailVerificationCode);
apply(new UserRegistered(
command.getUserId(),
command.getPrefferedUsername(),
command.getEmailAddress(),
asEncryptedValue(command.getPassword()),
emailVerificationCode)
);
}
示例6: handle
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void handle(SendResetPasswordInstructions command) {
try {
// lookup userId by email
InternalUserEntry userView = internalUserQueryRepository.findByEmailAddressIgnoreCase(command.getEmailAddress());
if (userView == null) {
// silently ignore errors like user not found
return;
}
// lookup user aggregate
UserId userId = new UserId(userView.getUserId());
User user = userAggregateRepository.load(userId);
if (!user.isDeleted()) {
user.registerResetPasswordKey(generateResetPasswordKey());
}
} catch (AggregateNotFoundException e) {
// we silently ignore errors like user not found
}
}
示例7: onCommand
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void onCommand(@SuppressWarnings("unused") final ChangeTestAggregate command, final MetaData metaData) {
if (timesChanged == 5000) {
throw new IllegalStateException("More than 5000 changes");
}
apply(new TestAggregateChanged(aggregateId), metaData);
}
示例8: onCommand
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void onCommand(final ChangeTestAggregate command, final MetaData metaData) {
if (!command.getAggregateId().equals(aggregateId)) {
throw new IllegalStateException("Maximum number of events reached ;)"); //$NON-NLS-1$
}
apply(new TestAggregateChanged(command.getAggregateId()), metaData);
}
示例9: markSaleable
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void markSaleable(MarkProductAsSaleableCommand command) {
LOG.debug("Command: 'MarkProductAsSaleableCommand' received.");
if (!this.isSaleable()) {
apply(new ProductSaleableEvent(id));
} else {
throw new IllegalStateException("This ProductAggregate (" + this.getId() + ") is already Saleable.");
}
}
示例10: markUnsaleable
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void markUnsaleable(MarkProductAsUnsaleableCommand command) {
LOG.debug("Command: 'MarkProductAsUnsaleableCommand' received.");
if (this.isSaleable()) {
apply(new ProductUnsaleableEvent(id));
} else {
throw new IllegalStateException("This ProductAggregate (" + this.getId() + ") is already off-sale.");
}
}
示例11: ShoppingCart
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public ShoppingCart(AddItemCommand command) {
id=command.getItemId();
//put here the business logic
//....
apply(new ItemAddedEvent(command.getItemId()));
}
示例12: markCompleted
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public void markCompleted(MarkCompletedCommand command) {
System.out.println("Command: 'MarkCompleted' received.");
System.out.println("Event: 'ToDoItemCompleted' applying...");
if(!this.isComplete()){
apply(new ToDoItemCompletedEvent(id));
} else {
throw new IllegalStateException("This ToDoItem ("+this.getId()+") is already Done.");
}
}
示例13: handleCreateRoleAggregate
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public RoleIdentifier handleCreateRoleAggregate(CreateRoleCommand command) {
if (log.isDebugEnabled()) {
log.debug("Handling: " + command.getClass().getSimpleName());
}
RoleIdentifier id = command.getRoleId();
RoleAggregate u = new RoleAggregate(id, command.getName(), command.getRights());
roleAggregateRepository.add(u);
return id;
}
示例14: handleAuthenticateUser
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public UserDetailsExtended handleAuthenticateUser(AuthenticateUserCommand command) {
if (log.isDebugEnabled()) {
log.debug("Handling: " + command.getClass().getSimpleName());
}
User user = userRepository.findByUsername(command.getUsername());
if (user == null) {
return null;
}
boolean success = passwordEncryptor.checkPassword(command.getPassword(), user.getPassword());
if (log.isDebugEnabled()) {
log.debug("Authentication successful: " + success);
}
// if we wanted other event listeners to know that the user was authenticated, we could mark it like so
// A UserAuthenticatedEvent would get dispatched
// if (success) {
// onUser(user.getUserIdentifier()).userAuthenticated();
// }
return success ? new Principal(user.getId(), user.getUserIdentifier(), user.getUsername(), user.getName(),
user.getFirstName(), user.getLastName(), user.getProfilePictureUrl(), user.getGender(),
user.getPassword(), user.getAuthorities(), user.getNonExpired(), user.getNonLocked(), user.getCredentialsNonExpired(),
user.getEnabled()) : null;
}
示例15: handleCreateToDoItem
import org.axonframework.commandhandling.annotation.CommandHandler; //导入依赖的package包/类
@CommandHandler
public ToDoIdentifier handleCreateToDoItem(CreateToDoItemCommand command) {
ToDoIdentifier id = command.getTodoId();
ToDoItemAggregate tdi = new ToDoItemAggregate(id, command.getDescription(), command.getUsername());
repository.add(tdi);
return id;
}