use of org.graylog2.contentpacks.model.constraints.Constraint in project graylog2-server by Graylog2.
the class InputFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(InputWithExtractors inputWithExtractors, EntityDescriptorIds entityDescriptorIds) {
final Input input = inputWithExtractors.input();
// TODO: Create independent representation of entity?
final Map<String, ValueReference> staticFields = input.getStaticFields().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, kv -> ValueReference.of(kv.getValue())));
final ReferenceMap configuration = toReferenceMap(input.getConfiguration());
final List<ExtractorEntity> extractors = inputWithExtractors.extractors().stream().map(this::encodeExtractor).collect(Collectors.toList());
final InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), configuration, staticFields, ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractors);
final JsonNode data = objectMapper.convertValue(inputEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(input);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(input.getId(), ModelTypes.INPUT_V1))).type(ModelTypes.INPUT_V1).data(data).constraints(ImmutableSet.copyOf(constraints)).build();
}
use of org.graylog2.contentpacks.model.constraints.Constraint in project graylog2-server by Graylog2.
the class ContentPackService method checkConstraintsV1.
private Set<ConstraintCheckResult> checkConstraintsV1(ContentPackV1 contentPackV1) {
Set<Constraint> requiredConstraints = contentPackV1.constraints();
final Set<ConstraintCheckResult> fulfilledConstraints = new HashSet<>();
for (ConstraintChecker constraintChecker : constraintCheckers) {
fulfilledConstraints.addAll(constraintChecker.checkConstraints(requiredConstraints));
}
return fulfilledConstraints;
}
use of org.graylog2.contentpacks.model.constraints.Constraint in project graylog2-server by Graylog2.
the class PluginVersionConstraintChecker method checkConstraints.
@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
for (Constraint constraint : requestedConstraints) {
if (constraint instanceof PluginVersionConstraint) {
final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
final Requirement requiredVersion = versionConstraint.version();
boolean result = false;
for (Semver pluginVersion : pluginVersions) {
if (requiredVersion.isSatisfiedBy(pluginVersion)) {
result = true;
}
}
ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, result);
fulfilledConstraints.add(constraintCheckResult);
}
}
return fulfilledConstraints.build();
}
use of org.graylog2.contentpacks.model.constraints.Constraint 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.constraints.Constraint in project graylog2-server by Graylog2.
the class LookupDataAdapterFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(DataAdapterDto dataAdapterDto, EntityDescriptorIds entityDescriptorIds) {
// TODO: Create independent representation of entity?
final Map<String, Object> configuration = objectMapper.convertValue(dataAdapterDto.config(), TypeReferences.MAP_STRING_OBJECT);
final LookupDataAdapterEntity lookupDataAdapterEntity = LookupDataAdapterEntity.create(ValueReference.of(dataAdapterDto.name()), ValueReference.of(dataAdapterDto.title()), ValueReference.of(dataAdapterDto.description()), toReferenceMap(configuration));
final JsonNode data = objectMapper.convertValue(lookupDataAdapterEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(dataAdapterDto);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1))).type(ModelTypes.LOOKUP_ADAPTER_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
Aggregations