Search in sources :

Example 1 with Message2RecipientNotFoundException

use of io.gravitee.rest.api.service.exceptions.Message2RecipientNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class CommandServiceImpl method send.

@Override
public void send(NewCommandEntity messageEntity) {
    if (messageEntity.getTo() == null || messageEntity.getTo().isEmpty()) {
        throw new Message2RecipientNotFoundException();
    }
    Command command = new Command();
    command.setId(UuidString.generateRandom());
    command.setEnvironmentId(GraviteeContext.getCurrentEnvironment());
    command.setFrom(node.id());
    command.setTo(messageEntity.getTo());
    command.setTags(convert(messageEntity.getTags()));
    long now = System.currentTimeMillis();
    command.setCreatedAt(new Date(now));
    command.setUpdatedAt(command.getCreatedAt());
    command.setExpiredAt(new Date(now + (messageEntity.getTtlInSeconds() * 1000)));
    if (messageEntity.getContent() != null) {
        command.setContent(messageEntity.getContent());
    }
    try {
        commandRepository.create(command);
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to create {}", command, ex);
        throw new TechnicalManagementException("An error occurs while trying create " + command, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Message2RecipientNotFoundException(io.gravitee.rest.api.service.exceptions.Message2RecipientNotFoundException) Command(io.gravitee.repository.management.model.Command) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Command (io.gravitee.repository.management.model.Command)1 Message2RecipientNotFoundException (io.gravitee.rest.api.service.exceptions.Message2RecipientNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 Date (java.util.Date)1