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);
}
}
Aggregations