use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class PipelineFacade method delete.
@Override
public void delete(PipelineDao nativeEntity) {
final Set<PipelineConnections> pipelineConnections = connectionsService.loadByPipelineId(nativeEntity.id());
for (PipelineConnections connections : pipelineConnections) {
final Set<String> pipelineIds = connections.pipelineIds().stream().filter(pipelineId -> !pipelineId.equals(nativeEntity.id())).collect(Collectors.toSet());
if (pipelineIds.isEmpty()) {
LOG.trace("Removing pipeline connections for stream {}", connections.streamId());
connectionsService.delete(connections.streamId());
} else {
final PipelineConnections newConnections = connections.toBuilder().pipelineIds(pipelineIds).build();
LOG.trace("Saving updated pipeline connections: {}", newConnections);
connectionsService.save(newConnections);
}
}
pipelineService.delete(nativeEntity.id());
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method decode.
private NativeEntity<Configuration> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
final Configuration configuration = Configuration.create(configurationEntity.collectorId().asString(parameters), configurationEntity.title().asString(parameters), configurationEntity.color().asString(parameters), configurationEntity.template().asString(parameters));
final Configuration savedConfiguration = configurationService.save(configuration);
return NativeEntity.create(entity.id(), savedConfiguration.id(), TYPE_V1, configuration.name(), savedConfiguration);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class UrlWhitelistFacade method createNativeEntity.
@Override
public NativeEntity<WhitelistEntry> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
if (!(entity instanceof EntityV1)) {
throw new IllegalArgumentException("Unsupported entity version: " + entity.getClass());
}
final WhitelistEntry whitelistEntry = objectMapper.convertValue(((EntityV1) entity).data(), WhitelistEntry.class);
urlWhitelistService.addEntry(whitelistEntry);
return NativeEntity.create(entity.id(), whitelistEntry.id(), TYPE_V1, createTitle(whitelistEntry), whitelistEntry);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class DashboardV1Facade method createNativeEntity.
@Override
public NativeEntity<ViewDTO> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
ensureV1(entity);
final User user = Optional.ofNullable(userService.load(username)).orElseThrow(() -> new IllegalStateException("Cannot load user <" + username + "> from db"));
return decode((EntityV1) entity, parameters, nativeEntities, user);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class NotificationFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final EntityV1 entityV1 = createTestEntity();
final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
when(userService.load("kmerz")).thenReturn(kmerzUser);
final NativeEntity<NotificationDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), ImmutableMap.of(), "kmerz");
assertThat(nativeEntity).isNotNull();
final NotificationDto notificationDto = nativeEntity.entity();
assertThat(notificationDto.title()).isEqualTo("title");
assertThat(notificationDto.description()).isEqualTo("descriptions");
assertThat(notificationDto.config().type()).isEqualTo("http-notification-v1");
}
Aggregations