Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support boolean model #1409

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package io.aklivity.zilla.runtime.binding.asyncapi.internal.config.composite;

import static java.util.Map.entry;
import static org.agrona.LangUtil.rethrowUnchecked;

import java.io.StringReader;
Expand Down Expand Up @@ -60,6 +61,7 @@
import io.aklivity.zilla.runtime.engine.config.ModelConfig;
import io.aklivity.zilla.runtime.engine.config.NamespaceConfigBuilder;
import io.aklivity.zilla.runtime.model.avro.config.AvroModelConfig;
import io.aklivity.zilla.runtime.model.core.config.BooleanModelConfig;
import io.aklivity.zilla.runtime.model.core.config.DoubleModelConfig;
import io.aklivity.zilla.runtime.model.core.config.FloatModelConfig;
import io.aklivity.zilla.runtime.model.core.config.Int32ModelConfig;
Expand All @@ -71,30 +73,31 @@

public abstract class AsyncapiCompositeGenerator
{
public static final Map<String, ModelConfig> MODELS = Map.of(
"string", StringModelConfig.builder().build(),
"string:%s".formatted(StringPattern.DATE.format),
public static final Map<String, ModelConfig> MODELS = Map.ofEntries(
entry("boolean", BooleanModelConfig.builder().build()),
entry("integer", Int32ModelConfig.builder().build()),
entry("integer:%s".formatted(Int32ModelConfig.INT_32),
Int32ModelConfig.builder().build()),
entry("integer:%s".formatted(Int64ModelConfig.INT_64),
Int64ModelConfig.builder().build()),
entry("number", FloatModelConfig.builder().build()),
entry("number:%s".formatted(FloatModelConfig.FLOAT),
FloatModelConfig.builder().build()),
entry("number:%s".formatted(DoubleModelConfig.DOUBLE),
DoubleModelConfig.builder().build()),
entry("string", StringModelConfig.builder().build()),
entry("string:%s".formatted(StringPattern.DATE.format),
StringModelConfig.builder()
.pattern(StringPattern.DATE.pattern)
.build(),
"string:%s".formatted(StringPattern.DATE_TIME.format),
.build()),
entry("string:%s".formatted(StringPattern.DATE_TIME.format),
StringModelConfig.builder()
.pattern(StringPattern.DATE_TIME.pattern)
.build(),
"string:%s".formatted(StringPattern.EMAIL.format),
.build()),
entry("string:%s".formatted(StringPattern.EMAIL.format),
StringModelConfig.builder()
.pattern(StringPattern.EMAIL.pattern)
.build(),
"integer", Int32ModelConfig.builder().build(),
"integer:%s".formatted(Int32ModelConfig.INT_32),
Int32ModelConfig.builder().build(),
"integer:%s".formatted(Int64ModelConfig.INT_64),
Int64ModelConfig.builder().build(),
"number", FloatModelConfig.builder().build(),
"number:%s".formatted(FloatModelConfig.FLOAT),
FloatModelConfig.builder().build(),
"number:%s".formatted(DoubleModelConfig.DOUBLE),
DoubleModelConfig.builder().build()
.build())
);

public final AsyncapiCompositeConfig generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import io.aklivity.zilla.runtime.engine.config.GuardedConfigBuilder;
import io.aklivity.zilla.runtime.engine.config.ModelConfig;
import io.aklivity.zilla.runtime.engine.config.NamespaceConfigBuilder;
import io.aklivity.zilla.runtime.model.core.config.BooleanModelConfig;
import io.aklivity.zilla.runtime.model.core.config.DoubleModelConfig;
import io.aklivity.zilla.runtime.model.core.config.FloatModelConfig;
import io.aklivity.zilla.runtime.model.core.config.Int32ModelConfig;
Expand Down Expand Up @@ -487,6 +488,7 @@ private <C> StringModelConfigBuilder<C> injectStringPattern(
}

private static final Map<String, ModelConfig> MODELS = Map.of(
"boolean", BooleanModelConfig.builder().build(),
"integer", Int32ModelConfig.builder().build(),
"integer:int32", Int32ModelConfig.builder().build(),
"integer:int64", Int64ModelConfig.builder().build(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021-2024 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.config;

import java.util.function.Function;

import io.aklivity.zilla.runtime.engine.config.ModelConfig;

public class BooleanModelConfig extends ModelConfig
{
public static final String BOOLEAN = "boolean";

public BooleanModelConfig()
{
super(BOOLEAN);
}

public static <T> BooleanModelConfigBuilder<T> builder(
Function<ModelConfig, T> mapper)
{
return new BooleanModelConfigBuilder<>(mapper::apply);
}

public static BooleanModelConfigBuilder<BooleanModelConfig> builder()
{
return new BooleanModelConfigBuilder<>(BooleanModelConfig.class::cast);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2021-2024 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.config;

import java.util.function.Function;

import io.aklivity.zilla.runtime.engine.config.ConfigBuilder;

public class BooleanModelConfigBuilder<T> extends ConfigBuilder<T, BooleanModelConfigBuilder<T>>
{
private final Function<BooleanModelConfig, T> mapper;

BooleanModelConfigBuilder(
Function<BooleanModelConfig, T> mapper)
{
this.mapper = mapper;
}

@Override
@SuppressWarnings("unchecked")
protected Class<BooleanModelConfigBuilder<T>> thisType()
{
return (Class<BooleanModelConfigBuilder<T>>) getClass();
}

@Override
public T build()
{
return mapper.apply(new BooleanModelConfig());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2021-2024 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.internal;

import org.agrona.DirectBuffer;

import io.aklivity.zilla.runtime.engine.EngineContext;
import io.aklivity.zilla.runtime.engine.model.ConverterHandler;
import io.aklivity.zilla.runtime.engine.model.function.ValueConsumer;

public class BooleanConverterHandler implements ConverterHandler
{
private final BooleanValidatorHandler handler;

public BooleanConverterHandler(
EngineContext context)
{
this.handler = new BooleanValidatorHandler(context);
}

@Override
public int convert(
long traceId,
long bindingId,
DirectBuffer data,
int index,
int length,
ValueConsumer next)
{
boolean valid = handler.validate(traceId, bindingId, FLAGS_COMPLETE, data, index, length, next);

if (valid)
{
next.accept(data, index, length);
}
return valid ? length : VALIDATION_FAILURE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021-2024 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.internal;

import java.net.URL;

import io.aklivity.zilla.runtime.engine.EngineContext;
import io.aklivity.zilla.runtime.engine.model.Model;
import io.aklivity.zilla.runtime.engine.model.ModelContext;

public class BooleanModel implements Model
{
public static final String NAME = "boolean";

@Override
public String name()
{
return NAME;
}

@Override
public ModelContext supply(
EngineContext context)
{
return new BooleanModelContext(context);
}

@Override
public URL type()
{
return getClass().getResource("schema/boolean.schema.patch.json");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021-2024 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.internal;

import io.aklivity.zilla.runtime.engine.EngineContext;
import io.aklivity.zilla.runtime.engine.config.ModelConfig;
import io.aklivity.zilla.runtime.engine.model.ConverterHandler;
import io.aklivity.zilla.runtime.engine.model.ModelContext;
import io.aklivity.zilla.runtime.engine.model.ValidatorHandler;

public class BooleanModelContext implements ModelContext
{
private final EngineContext context;

public BooleanModelContext(
EngineContext context)
{
this.context = context;
}

@Override
public ConverterHandler supplyReadConverterHandler(
ModelConfig config)
{
return supply(config);
}

@Override
public ConverterHandler supplyWriteConverterHandler(
ModelConfig config)
{
return supply(config);
}

@Override
public ValidatorHandler supplyValidatorHandler(
ModelConfig config)
{
return new BooleanValidatorHandler(context);
}

private BooleanConverterHandler supply(
ModelConfig config)
{
return new BooleanConverterHandler(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021-2024 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.internal;

import static io.aklivity.zilla.runtime.model.core.internal.BooleanModel.NAME;

import java.net.URL;

import io.aklivity.zilla.runtime.engine.Configuration;
import io.aklivity.zilla.runtime.engine.model.Model;
import io.aklivity.zilla.runtime.engine.model.ModelFactorySpi;

public class BooleanModelFactorySpi implements ModelFactorySpi
{
@Override
public String type()
{
return NAME;
}

@Override
public URL schema()
{
return getClass().getResource("schema/boolean.schema.patch.json");
}

@Override
public Model create(
Configuration config)
{
return new BooleanModel();
}
}
Loading