当前位置: 首页>>代码示例>>Java>>正文


Java CommandHandler类代码示例

本文整理汇总了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;
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:26,代码来源:UserCommandHandler.java

示例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;
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:26,代码来源:UserCommandHandler.java

示例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()));
    }
}
 
开发者ID:dma-graveyard,项目名称:MaritimeCloudPortalTestbed,代码行数:20,代码来源:Organization.java

示例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);
}
 
开发者ID:dma-graveyard,项目名称:MaritimeCloudPortalTestbed,代码行数:20,代码来源:OrganizationCommandHandler.java

示例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)
    );
}
 
开发者ID:dma-graveyard,项目名称:MaritimeCloudPortalTestbed,代码行数:21,代码来源:User.java

示例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 
    }

}
 
开发者ID:dma-graveyard,项目名称:MaritimeCloudPortalTestbed,代码行数:25,代码来源:UserCommandHandler.java

示例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);
}
 
开发者ID:Qyotta,项目名称:axon-eventstore,代码行数:8,代码来源:MyTestAggregate.java

示例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);
}
 
开发者ID:Qyotta,项目名称:axon-eventstore,代码行数:8,代码来源:MyTestAggregate.java

示例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.");
    }
}
 
开发者ID:benwilcock,项目名称:cf-cqrs-microservice-sampler,代码行数:10,代码来源:ProductAggregate.java

示例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.");
    }
}
 
开发者ID:benwilcock,项目名称:cf-cqrs-microservice-sampler,代码行数:10,代码来源:ProductAggregate.java

示例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()));
}
 
开发者ID:feliciatucci,项目名称:cqrs-sample,代码行数:9,代码来源:ShoppingCart.java

示例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.");
    }
}
 
开发者ID:benwilcock,项目名称:axon-cqrs-sample,代码行数:11,代码来源:ToDoItem.java

示例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;
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:12,代码来源:RoleCommandHandler.java

示例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;
    }
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:29,代码来源:UserCommandHandler.java

示例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;
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:9,代码来源:ToDoCommandHandler.java


注:本文中的org.axonframework.commandhandling.annotation.CommandHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。