Search in sources :

Example 6 with NewOrganization

use of io.gravitee.am.service.model.NewOrganization in project gravitee-access-management by gravitee-io.

the class OrganizationCommandHandler method handle.

@Override
public Single<OrganizationReply> handle(OrganizationCommand command) {
    OrganizationPayload organizationPayload = command.getPayload();
    NewOrganization newOrganization = new NewOrganization();
    newOrganization.setHrids(organizationPayload.getHrids());
    newOrganization.setName(organizationPayload.getName());
    newOrganization.setDescription(organizationPayload.getDescription());
    newOrganization.setDomainRestrictions(organizationPayload.getDomainRestrictions());
    return organizationService.createOrUpdate(organizationPayload.getId(), newOrganization, null).map(organization -> new OrganizationReply(command.getId(), CommandStatus.SUCCEEDED)).doOnSuccess(reply -> logger.info("Organization [{}] handled with id [{}].", organizationPayload.getName(), organizationPayload.getId())).doOnError(error -> logger.error("Error occurred when handling organization [{}] with id [{}].", organizationPayload.getName(), organizationPayload.getId(), error)).onErrorReturn(throwable -> new OrganizationReply(command.getId(), CommandStatus.ERROR));
}
Also used : NewOrganization(io.gravitee.am.service.model.NewOrganization) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) Component(org.springframework.stereotype.Component) Logger(org.slf4j.Logger) OrganizationService(io.gravitee.am.service.OrganizationService) CommandHandler(io.gravitee.cockpit.api.command.CommandHandler) OrganizationCommand(io.gravitee.cockpit.api.command.organization.OrganizationCommand) LoggerFactory(org.slf4j.LoggerFactory) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) NewOrganization(io.gravitee.am.service.model.NewOrganization) Single(io.reactivex.Single) Command(io.gravitee.cockpit.api.command.Command) OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply)

Aggregations

NewOrganization (io.gravitee.am.service.model.NewOrganization)6 Single (io.reactivex.Single)6 Organization (io.gravitee.am.model.Organization)5 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)5 TestObserver (io.reactivex.observers.TestObserver)5 Collections (java.util.Collections)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Before (org.junit.Before)5 Test (org.junit.Test)5 RunWith (org.junit.runner.RunWith)5 Mock (org.mockito.Mock)5 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 EventType (io.gravitee.am.common.audit.EventType)4 Status (io.gravitee.am.common.audit.Status)4 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)4 Entrypoint (io.gravitee.am.model.Entrypoint)4 ReferenceType (io.gravitee.am.model.ReferenceType)4 Audit (io.gravitee.am.reporter.api.audit.model.Audit)4 OrganizationRepository (io.gravitee.am.repository.management.api.OrganizationRepository)4