use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class LookupTableFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(LookupTableDto lookupTableDto, EntityDescriptorIds entityDescriptorIds) {
final String tableId = entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.id(), ModelTypes.LOOKUP_TABLE_V1)).orElseThrow(() -> new ContentPackException("Couldn't find lookup table entity " + lookupTableDto.id()));
final String cacheId = entityDescriptorIds.get(cacheDescriptor(lookupTableDto.cacheId())).orElseThrow(() -> new ContentPackException("Couldn't find lookup cache entity " + lookupTableDto.cacheId()));
final String adapterId = entityDescriptorIds.get(adapterDescriptor(lookupTableDto.dataAdapterId())).orElseThrow(() -> new ContentPackException("Couldn't find lookup data adapter entity " + lookupTableDto.dataAdapterId()));
final LookupTableEntity lookupTableEntity = LookupTableEntity.create(ValueReference.of(lookupTableDto.name()), ValueReference.of(lookupTableDto.title()), ValueReference.of(lookupTableDto.description()), ValueReference.of(cacheId), ValueReference.of(adapterId), ValueReference.of(lookupTableDto.defaultSingleValue()), ValueReference.of(lookupTableDto.defaultSingleValueType()), ValueReference.of(lookupTableDto.defaultMultiValue()), ValueReference.of(lookupTableDto.defaultMultiValueType()));
final JsonNode data = objectMapper.convertValue(lookupTableEntity, JsonNode.class);
return EntityV1.builder().id(ModelId.of(tableId)).type(ModelTypes.LOOKUP_TABLE_V1).data(data).build();
}
use of org.graylog2.contentpacks.model.entities.EntityV1 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.EntityV1 in project graylog2-server by Graylog2.
the class OutputFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(Output output, EntityDescriptorIds entityDescriptorIds) {
final OutputEntity outputEntity = OutputEntity.create(ValueReference.of(output.getTitle()), ValueReference.of(output.getType()), toReferenceMap(output.getConfiguration()));
final JsonNode data = objectMapper.convertValue(outputEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(output);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(output.getId(), ModelTypes.OUTPUT_V1))).type(ModelTypes.OUTPUT_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class OutputFacade method decode.
private NativeEntity<Output> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
final OutputEntity outputEntity = objectMapper.convertValue(entity.data(), OutputEntity.class);
final CreateOutputRequest createOutputRequest = CreateOutputRequest.create(outputEntity.title().asString(parameters), outputEntity.type().asString(parameters), toValueMap(outputEntity.configuration(), parameters), // Outputs are assigned to streams in StreamFacade
null);
try {
final Output output = outputService.create(createOutputRequest, username);
return NativeEntity.create(entity.id(), output.getId(), TYPE_V1, output.getTitle(), output);
} catch (ValidationException e) {
throw new IllegalArgumentException(e);
}
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class PipelineRuleFacade method findExisting.
private Optional<NativeEntity<RuleDao>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
final PipelineRuleEntity ruleEntity = objectMapper.convertValue(entity.data(), PipelineRuleEntity.class);
final String title = ruleEntity.title().asString(parameters);
final String source = ruleEntity.source().asString(parameters);
try {
final RuleDao ruleDao = ruleService.loadByName(title);
compareRuleSources(title, source, ruleDao.source());
return Optional.of(NativeEntity.create(entity.id(), ruleDao.id(), TYPE_V1, ruleDao.title(), ruleDao));
} catch (NotFoundException e) {
return Optional.empty();
}
}
Aggregations