Search in sources :

Example 26 with Schema

use of com.predic8.schema.Schema in project service-proxy by membrane.

the class NamespaceInfo method writeInfo.

public void writeInfo(Model m) {
    try {
        FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/membrane.namespaces");
        OutputStream oo = o.openOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(oo);
        try {
            Properties p = new Properties();
            int i = 1;
            for (MainInfo mi : m.getMains()) {
                String key = "schema" + (i++);
                p.put(key + "-targetNamespace", mi.getAnnotation().targetNamespace());
                p.put(key + "-outputPackage", mi.getAnnotation().outputPackage());
                p.put(key + "-outputName", mi.getAnnotation().outputName());
            }
            p.store(bos, "Autogenerated by " + getClass().getName());
        } finally {
            bos.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : MainInfo(com.predic8.membrane.annot.model.MainInfo) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileObject(javax.tools.FileObject) IOException(java.io.IOException) Properties(java.util.Properties) BufferedOutputStream(java.io.BufferedOutputStream)

Example 27 with Schema

use of com.predic8.schema.Schema in project service-proxy by membrane.

the class ApiManagementConfiguration method updateAfterLocationChange.

public void updateAfterLocationChange() throws IOException {
    if (!isLocalFile(location)) {
        log.info("Loading configuration from [" + location + "]");
        if (location.startsWith("etcd")) {
            handleEtcd(location);
        } else {
            try {
                parseAndConstructConfiguration(getResolver().resolve(location));
            } catch (ResourceRetrievalException e) {
                log.error("Could not retrieve resource");
                return;
            }
        }
        return;
    } else {
        if (location.isEmpty())
            location = "api.yaml";
        final String newLocation = ResolverMap.combine(getCurrentDir(), location);
        log.info("Loading configuration from [" + newLocation + "]");
        InputStream is = null;
        try {
            is = getResolver().resolve(newLocation);
        } catch (ResourceRetrievalException e) {
            log.error("Could not retrieve resource");
            return;
        }
        parseAndConstructConfiguration(is);
        try {
            getResolver().observeChange(newLocation, new Consumer<InputStream>() {

                @Override
                public void call(InputStream inputStream) {
                    log.info("Loading configuration from [" + newLocation + "]");
                    if (!getContextLost()) {
                        try {
                            parseAndConstructConfiguration(inputStream);
                            getResolver().observeChange(newLocation, this);
                        } catch (ResourceRetrievalException ignored) {
                        } catch (IOException ignored) {
                        }
                    }
                }
            });
        } catch (Exception warn) {
            URL url = null;
            try {
                url = new URL(newLocation);
            } catch (MalformedURLException ignored) {
            }
            String schema = "";
            if (url != null) {
                schema = url.getProtocol();
            }
            log.warn("Could not observe AMC location for " + schema);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) IOException(java.io.IOException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) URISyntaxException(java.net.URISyntaxException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) URL(java.net.URL)

Example 28 with Schema

use of com.predic8.schema.Schema in project service-proxy by membrane.

the class JSONSchemaValidationTest method validate.

private void validate(String schema, String json, boolean success) throws IOException, Exception {
    final StringBuffer sb = new StringBuffer();
    FailureHandler fh = new FailureHandler() {

        @Override
        public void handleFailure(String message, Exchange exc) {
            sb.append(message);
            sb.append("\n");
        }
    };
    JSONValidator jsonValidator = new JSONValidator(new ResolverMap(), schema, fh);
    Request request = new Request.Builder().body(IOUtils.toByteArray(getClass().getResourceAsStream(json))).build();
    Exchange exchange = new Exchange(null);
    jsonValidator.validateMessage(exchange, request, "request");
    if (success)
        Assert.assertTrue(sb.toString(), sb.length() == 0);
    else
        Assert.assertTrue("No error occurred, but expected one.", sb.length() != 0);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) FailureHandler(com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor.FailureHandler) Request(com.predic8.membrane.core.http.Request) ResolverMap(com.predic8.membrane.core.resolver.ResolverMap)

Example 29 with Schema

use of com.predic8.schema.Schema in project service-proxy by membrane.

the class ValidatorInterceptorTest method createSchemaValidatorInterceptor.

private ValidatorInterceptor createSchemaValidatorInterceptor(String schema) throws Exception {
    ValidatorInterceptor interceptor = new ValidatorInterceptor();
    interceptor.setResourceResolver(new ResolverMap());
    interceptor.setSchema(schema);
    interceptor.init();
    return interceptor;
}
Also used : ResolverMap(com.predic8.membrane.core.resolver.ResolverMap)

Example 30 with Schema

use of com.predic8.schema.Schema in project core by s4.

the class AbstractPE method setKeyValue.

private void setKeyValue(Object event, CompoundKeyInfo compoundKeyInfo) {
    if (compoundKeyInfo == null) {
        return;
    }
    keyValue = new ArrayList<Object>();
    Schema schema = schemaContainer.getSchema(event.getClass());
    // get the value for each keyInfo
    for (KeyInfo keyInfo : compoundKeyInfo.getKeyInfoList()) {
        Object value = null;
        Object record = event;
        List<?> list = null;
        Property property = null;
        for (KeyPathElement keyPathElement : keyInfo.getKeyPath()) {
            if (keyPathElement instanceof KeyPathElementIndex) {
                record = list.get(((KeyPathElementIndex) keyPathElement).getIndex());
                schema = property.getComponentProperty().getSchema();
            } else {
                String keyPathElementName = ((KeyPathElementName) keyPathElement).getKeyName();
                property = schema.getProperties().get(keyPathElementName);
                value = null;
                try {
                    value = property.getGetterMethod().invoke(record);
                } catch (Exception e) {
                    Logger.getLogger("s4").error(e);
                    return;
                }
                if (value == null) {
                    Logger.getLogger("s4").error("Value for " + keyPathElementName + " is null!");
                    return;
                }
                if (property.getType().isPrimitive() || property.isNumber() || property.getType().equals(String.class)) {
                    keyValue.add(value);
                    if (saveKeyRecord) {
                        if (keyRecord == null) {
                            keyRecord = new ArrayList<Object>();
                        }
                        keyRecord.add(record);
                    }
                    continue;
                } else if (property.isList()) {
                    try {
                        list = (List) property.getGetterMethod().invoke(record);
                    } catch (Exception e) {
                        Logger.getLogger("s4").error(e);
                        return;
                    }
                } else {
                    try {
                        record = property.getGetterMethod().invoke(record);
                    } catch (Exception e) {
                        Logger.getLogger("s4").error(e);
                        return;
                    }
                    schema = property.getSchema();
                }
            }
        }
    }
}
Also used : KeyInfo(io.s4.dispatcher.partitioner.KeyInfo) CompoundKeyInfo(io.s4.dispatcher.partitioner.CompoundKeyInfo) Schema(io.s4.schema.Schema) KeyPathElementIndex(io.s4.dispatcher.partitioner.KeyInfo.KeyPathElementIndex) KeyPathElementName(io.s4.dispatcher.partitioner.KeyInfo.KeyPathElementName) ArrayList(java.util.ArrayList) List(java.util.List) Property(io.s4.schema.Schema.Property) KeyPathElement(io.s4.dispatcher.partitioner.KeyInfo.KeyPathElement)

Aggregations

Schema (org.h2.schema.Schema)35 CreateSchema (org.h2.command.ddl.CreateSchema)16 DropSchema (org.h2.command.ddl.DropSchema)16 ValueString (org.h2.value.ValueString)16 Column (org.h2.table.Column)10 IndexColumn (org.h2.table.IndexColumn)10 Table (org.h2.table.Table)10 Expression (org.h2.expression.Expression)8 ExpressionColumn (org.h2.expression.ExpressionColumn)8 ValueExpression (org.h2.expression.ValueExpression)8 Schema (io.s4.schema.Schema)7 ArrayList (java.util.ArrayList)7 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)7 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)7 CreateTable (org.h2.command.ddl.CreateTable)7 RangeTable (org.h2.table.RangeTable)7 Property (io.s4.schema.Schema.Property)6 CreateLinkedTable (org.h2.command.ddl.CreateLinkedTable)6 DropTable (org.h2.command.ddl.DropTable)6 TruncateTable (org.h2.command.ddl.TruncateTable)6