use of org.graylog2.contentpacks.model.entities.NativeEntityDescriptor in project graylog2-server by Graylog2.
the class ContentPackService method getUninstallDetails.
private ContentPackUninstallDetails getUninstallDetails(ContentPackV1 contentPack, ContentPackInstallation installation) {
final Entity rootEntity = EntityV1.createRoot(contentPack);
final ImmutableMap<String, ValueReference> parameters = installation.parameters();
final ImmutableGraph<Entity> dependencyGraph = buildEntityGraph(rootEntity, contentPack.entities(), parameters);
final Traverser<Entity> entityTraverser = Traverser.forGraph(dependencyGraph);
final Iterable<Entity> entitiesInOrder = entityTraverser.breadthFirst(rootEntity);
final Set<NativeEntityDescriptor> nativeEntityDescriptors = new HashSet<>();
entitiesInOrder.forEach((entity -> {
if (entity.equals(rootEntity)) {
return;
}
final Optional<NativeEntityDescriptor> nativeEntityDescriptorOptional = installation.entities().stream().filter(descriptor -> entity.id().equals(descriptor.contentPackEntityId())).findFirst();
if (nativeEntityDescriptorOptional.isPresent()) {
NativeEntityDescriptor nativeEntityDescriptor = nativeEntityDescriptorOptional.get();
if (contentPackInstallationPersistenceService.countInstallationOfEntityById(nativeEntityDescriptor.id()) <= 1) {
nativeEntityDescriptors.add(nativeEntityDescriptor);
}
}
}));
return ContentPackUninstallDetails.create(nativeEntityDescriptors);
}
use of org.graylog2.contentpacks.model.entities.NativeEntityDescriptor in project graylog2-server by Graylog2.
the class NotificationFacadeTest method loadNativeEntity.
@Test
@MongoDBFixtures("NotificationFacadeTest.json")
public void loadNativeEntity() {
final NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("content-pack-id"), ModelId.of("5d4d33753d27460ad18e0c4d"), ModelTypes.NOTIFICATION_V1, "title");
final Optional<NativeEntity<NotificationDto>> optionalNativeEntity = facade.loadNativeEntity(nativeEntityDescriptor);
assertThat(optionalNativeEntity).isPresent();
final NativeEntity<NotificationDto> nativeEntity = optionalNativeEntity.get();
assertThat(nativeEntity.entity()).isNotNull();
final NotificationDto notificationDto = nativeEntity.entity();
assertThat(notificationDto.id()).isEqualTo("5d4d33753d27460ad18e0c4d");
}
use of org.graylog2.contentpacks.model.entities.NativeEntityDescriptor in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() throws NotFoundException {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final NativeEntity<GrokPattern> nativeEntity = facade.createNativeEntity(grokPatternEntity, Collections.emptyMap(), Collections.emptyMap(), "admin");
final GrokPattern expectedGrokPattern = GrokPattern.create("1", "Test", "[a-z]+", null);
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create("1", "1", ModelTypes.GROK_PATTERN_V1, "Test");
assertThat(nativeEntity.descriptor().title()).isEqualTo(expectedDescriptor.title());
assertThat(nativeEntity.descriptor().type()).isEqualTo(expectedDescriptor.type());
assertThat(nativeEntity.entity()).isEqualTo(expectedGrokPattern);
assertThat(grokPatternService.load("1")).isEqualTo(expectedGrokPattern);
}
use of org.graylog2.contentpacks.model.entities.NativeEntityDescriptor in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method findExisting.
@Test
public void findExisting() throws ValidationException {
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test", "[a-z]+"));
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final Optional<NativeEntity<GrokPattern>> existingGrokPattern = facade.findExisting(grokPatternEntity, Collections.emptyMap());
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(grokPatternEntity.id(), "1", ModelTypes.GROK_PATTERN_V1, grokPattern.name(), false);
assertThat(existingGrokPattern).isPresent().get().satisfies(nativeEntity -> {
assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
assertThat(nativeEntity.entity()).isEqualTo(grokPattern);
});
}
use of org.graylog2.contentpacks.model.entities.NativeEntityDescriptor in project graylog2-server by Graylog2.
the class LookupCacheFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_CACHE_V1).data(objectMapper.convertValue(LookupCacheEntity.create(ValueReference.of("no-op-cache"), ValueReference.of("No-op cache"), ValueReference.of("No-op cache"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("type", "none"))), JsonNode.class)).build();
assertThat(cacheService.findAll()).isEmpty();
final NativeEntity<CacheDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
final NativeEntityDescriptor descriptor = nativeEntity.descriptor();
final CacheDto cacheDto = nativeEntity.entity();
assertThat(nativeEntity.descriptor().id()).isNotNull();
assertThat(descriptor.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
assertThat(cacheDto.name()).isEqualTo("no-op-cache");
assertThat(cacheDto.title()).isEqualTo("No-op cache");
assertThat(cacheDto.description()).isEqualTo("No-op cache");
assertThat(cacheDto.config().type()).isEqualTo("none");
assertThat(cacheService.findAll()).hasSize(1);
}
Aggregations