Java Code Examples for com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema#putProperty()
The following examples show how to use
com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema#putProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FhirMetadataRetrieval.java From syndesis with Apache License 2.0 | 6 votes |
private static String newPatchSpecification(Integer operationNumber) { final JsonSchemaFactory factory = new JsonSchemaFactory(); final ObjectSchema patchSchema = factory.objectSchema(); patchSchema.set$schema("http://json-schema.org/schema#"); patchSchema.setTitle("Patch"); patchSchema.putProperty("id", factory.stringSchema()); for (int i = 1; i <= operationNumber; i++) { final ObjectSchema operation = factory.objectSchema(); operation.putProperty("op", factory.stringSchema()); operation.putProperty("path", factory.stringSchema()); operation.putProperty("value", factory.stringSchema()); patchSchema.putProperty(String.valueOf(i), operation); } final String schema; try { schema = JsonUtils.writer().writeValueAsString(patchSchema); } catch (JsonProcessingException e) { throw new SyndesisServerException(e); } return schema; }
Example 2
Source File: ODataMetaDataRetrieval.java From syndesis with Apache License 2.0 | 6 votes |
private SyndesisMetadata genReadToShape(ODataMetadata odataMetadata, Map<String, List<PropertyPair>> enrichedProperties) { // // Need to add a KEY_PREDICATE to the json schema to allow identification // of the entity to be patched. // ObjectSchema entityInSchema = createEntitySchema(); entityInSchema.putProperty(KEY_PREDICATE, factory.stringSchema()); DataShape.Builder inDataShapeBuilder = new DataShape.Builder() .kind(DataShapeKinds.JSON_SCHEMA) .type(entityInSchema.getTitle()) .name("Entity Properties") .specification(serializeSpecification(entityInSchema)); ObjectSchema entityOutSchema = createEntitySchema(); populateEntitySchema(odataMetadata, entityOutSchema); DataShape.Builder outDataShapeBuilder = new DataShape.Builder() .kind(DataShapeKinds.JSON_SCHEMA) .type(entityOutSchema.getTitle()); applyEntitySchemaSpecification(entityOutSchema, outDataShapeBuilder); return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder); }
Example 3
Source File: ODataMetaDataRetrieval.java From syndesis with Apache License 2.0 | 6 votes |
private SyndesisMetadata genDeleteDataShape(Map<String, List<PropertyPair>> enrichedProperties, String actionId) { // // Need to add a KEY_PREDICATE to the json schema to allow identification // of the entity to be patched. // ObjectSchema entitySchema = createEntitySchema(); entitySchema.putProperty(KEY_PREDICATE, factory.stringSchema()); DataShape.Builder inDataShapeBuilder = new DataShape.Builder() .kind(DataShapeKinds.JSON_SCHEMA) .type(entitySchema.getTitle()) .name("Entity Properties") .specification(serializeSpecification(entitySchema)); DataShape.Builder outDataShapeBuilder = new DataShape.Builder() .kind(DataShapeKinds.JSON_INSTANCE) .description("OData " + actionId) .name(actionId); return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder); }
Example 4
Source File: GoogleSheetsMetaDataHelper.java From syndesis with Apache License 2.0 | 6 votes |
public static JsonSchema createSchema(String range, String majorDimension, boolean split, String ... columnNames) { ObjectSchema spec = new ObjectSchema(); spec.setTitle("VALUE_RANGE"); spec.putProperty("spreadsheetId", new JsonSchemaFactory().stringSchema()); RangeCoordinate coordinate = RangeCoordinate.fromRange(range); if (ObjectHelper.equal(RangeCoordinate.DIMENSION_ROWS, majorDimension)) { createSchemaFromRowDimension(spec, coordinate, columnNames); } else if (ObjectHelper.equal(RangeCoordinate.DIMENSION_COLUMNS, majorDimension)) { createSchemaFromColumnDimension(spec, coordinate); } if (split) { spec.set$schema(JSON_SCHEMA_ORG_SCHEMA); return spec; } else { ArraySchema arraySpec = new ArraySchema(); arraySpec.set$schema(JSON_SCHEMA_ORG_SCHEMA); arraySpec.setItemsSchema(spec); return arraySpec; } }
Example 5
Source File: MongoDBMetadataRetrieval.java From syndesis with Apache License 2.0 | 6 votes |
public static String buildFilterJsonSpecification(String filter) { final JsonSchemaFactory factory = new JsonSchemaFactory(); final ObjectSchema builderIn = new ObjectSchema(); List<String> parameters = FilterUtil.extractParameters(filter); builderIn.setTitle("Filter parameters"); for(String param:parameters){ builderIn.putProperty(param,factory.stringSchema()); } String jsonSpecification = null; try { jsonSpecification = MAPPER.writeValueAsString(builderIn); } catch (JsonProcessingException e) { LOGGER.error("Issue while processing filter parameters", e); } return jsonSpecification; }
Example 6
Source File: HttpRequestWrapperProcessorTest.java From syndesis with Apache License 2.0 | 5 votes |
public HttpRequestWrapperProcessorTest() { final ObjectSchema parameters = new ObjectSchema(); parameters.putProperty("param1", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); parameters.putProperty("param2", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); schema.putProperty("parameters", parameters); final ObjectSchema body = new ObjectSchema(); body.putProperty("body1", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); body.putProperty("body2", JsonSchema.minimalForFormat(JsonFormatTypes.STRING)); schema.putProperty("body", body); }
Example 7
Source File: ODataMetaDataRetrieval.java From syndesis with Apache License 2.0 | 5 votes |
private SyndesisMetadata genPatchDataShape(ODataMetadata odataMetadata, Map<String, List<PropertyPair>> enrichedProperties, String actionId) { ObjectSchema entitySchema = createEntitySchema(); populateEntitySchema(odataMetadata, entitySchema); // // Need to add a KEY_PREDICATE to the json schema to allow identification // of the entity to be patched. // entitySchema.putProperty(KEY_PREDICATE, factory.stringSchema()); DataShape.Builder inDataShapeBuilder = new DataShape.Builder() .kind(DataShapeKinds.NONE) .type(entitySchema.getTitle()) .name("Entity Properties"); if (! entitySchema.getProperties().isEmpty()) { applyEntitySchemaSpecification(entitySchema, inDataShapeBuilder); } DataShape.Builder outDataShapeBuilder = new DataShape.Builder() .kind(DataShapeKinds.JSON_INSTANCE) .description("OData " + actionId) .name(actionId); return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder); }
Example 8
Source File: SqlMetadataRetrieval.java From syndesis with Apache License 2.0 | 4 votes |
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity"}) public SyndesisMetadata adaptForSql(final String actionId, final Map<String, Object> properties, final MetaData metadata) { final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); @SuppressWarnings("unchecked") final SqlStatementMetaData sqlStatementMetaData = (SqlStatementMetaData) metadata.getPayload(); if (sqlStatementMetaData != null) { enrichedProperties.put(QUERY, Collections.singletonList(new PropertyPair(sqlStatementMetaData.getSqlStatement()))); // build the input and output schemas final JsonSchema specIn; final ObjectSchema builderIn = new ObjectSchema(); builderIn.setTitle("SQL_PARAM_IN"); if (sqlStatementMetaData.isVerifiedBatchUpdateMode()) { ArraySchema arraySpec = new ArraySchema(); arraySpec.set$schema(JSON_SCHEMA_ORG_SCHEMA); arraySpec.setItemsSchema(builderIn); specIn = arraySpec; } else { builderIn.set$schema(JSON_SCHEMA_ORG_SCHEMA); specIn = builderIn; } for (SqlParam inParam: sqlStatementMetaData.getInParams()) { builderIn.putProperty(inParam.getName(), schemaFor(inParam.getJdbcType())); } final ObjectSchema builderOut = new ObjectSchema(); builderOut.setTitle("SQL_PARAM_OUT"); for (SqlParam outParam: sqlStatementMetaData.getOutParams()) { builderOut.putProperty(outParam.getName(), schemaFor(outParam.getJdbcType())); } final ArraySchema outputSpec = new ArraySchema(); outputSpec.set$schema(JSON_SCHEMA_ORG_SCHEMA); outputSpec.setItemsSchema(builderOut); try { DataShape.Builder inDataShapeBuilder = new DataShape.Builder().type(builderIn.getTitle()); if (builderIn.getProperties().isEmpty()) { inDataShapeBuilder.kind(DataShapeKinds.NONE); } else { inDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA) .name("SQL Parameter") .description(String.format("Parameters of SQL [%s]", sqlStatementMetaData.getSqlStatement())) .specification(JsonUtils.writer().writeValueAsString(specIn)); if (specIn.isObjectSchema()) { inDataShapeBuilder.putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_ELEMENT); } if (specIn.isArraySchema()) { inDataShapeBuilder.putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_COLLECTION); } } DataShape.Builder outDataShapeBuilder = new DataShape.Builder().type(builderOut.getTitle()); if (builderOut.getProperties().isEmpty()) { outDataShapeBuilder.kind(DataShapeKinds.NONE); } else { outDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA) .name("SQL Result") .description(String.format("Result of SQL [%s]", sqlStatementMetaData.getSqlStatement())) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_COLLECTION) .specification(JsonUtils.writer().writeValueAsString(outputSpec)); } return new SyndesisMetadata(enrichedProperties, inDataShapeBuilder.build(), outDataShapeBuilder.build()); } catch (JsonProcessingException e) { throw new IllegalStateException(e); } } else { return new SyndesisMetadata(enrichedProperties, null, null); } }
Example 9
Source File: SqlMetadataRetrieval.java From syndesis with Apache License 2.0 | 4 votes |
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity"}) public SyndesisMetadata adaptForStoredSql(final String actionId, final Map<String, Object> properties, final MetaData metadata) { final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); // list of stored procedures in the database @SuppressWarnings("unchecked") final Map<String, StoredProcedureMetadata> procedureMap = (Map<String, StoredProcedureMetadata>) metadata.getPayload(); if (isPresentAndNonNull(properties, PATTERN) && FROM_PATTERN.equalsIgnoreCase(ConnectorOptions.extractOption(properties, PATTERN))) { enrichedProperties.put(PROCEDURE_NAME, obtainFromProcedureList(procedureMap)); } else { enrichedProperties.put(PROCEDURE_NAME, obtainToProcedureList(procedureMap)); } // metadata for the named procedure if (isPresentAndNonNull(properties, PROCEDURE_NAME)) { final List<PropertyPair> ppList = new ArrayList<>(); final String procedureName = ConnectorOptions.extractOption(properties, PROCEDURE_NAME); final StoredProcedureMetadata storedProcedure = procedureMap.get(procedureName); ppList.add(new PropertyPair(storedProcedure.getTemplate(), PROCEDURE_TEMPLATE)); enrichedProperties.put(PROCEDURE_TEMPLATE, ppList); // build the input and output schemas final ObjectSchema builderIn = new ObjectSchema(); builderIn.set$schema(JSON_SCHEMA_ORG_SCHEMA); builderIn.setTitle(procedureName + "_IN"); final ObjectSchema builderOut = new ObjectSchema(); builderOut.setTitle(procedureName + "_OUT"); builderOut.set$schema(JSON_SCHEMA_ORG_SCHEMA); if (storedProcedure.getColumnList() != null && !storedProcedure.getColumnList().isEmpty()) { for (final StoredProcedureColumn column : storedProcedure.getColumnList()) { if (column.getMode().equals(ColumnMode.IN) || column.getMode().equals(ColumnMode.INOUT)) { builderIn.putProperty(column.getName(), schemaFor(column.getJdbcType())); } if (column.getMode().equals(ColumnMode.OUT) || column.getMode().equals(ColumnMode.INOUT)) { builderOut.putProperty(column.getName(), schemaFor(column.getJdbcType())); } } } try { DataShape.Builder inDataShapeBuilder = new DataShape.Builder().type(builderIn.getTitle()); if (builderIn.getProperties().isEmpty()) { inDataShapeBuilder.kind(DataShapeKinds.NONE); } else { inDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA) .name(procedureName + " Parameter") .description(String.format("Parameters of Stored Procedure '%s'", procedureName)) .specification(JsonUtils.writer().writeValueAsString(builderIn)); } DataShape.Builder outDataShapeBuilder = new DataShape.Builder().type(builderOut.getTitle()); if (builderOut.getProperties().isEmpty()) { outDataShapeBuilder.kind(DataShapeKinds.NONE); } else { outDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA) .name(procedureName + " Return") .description(String.format("Return value of Stored Procedure '%s'", procedureName)) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_ELEMENT) .specification(JsonUtils.writer().writeValueAsString(builderOut)); } return new SyndesisMetadata(enrichedProperties, inDataShapeBuilder.build(), outDataShapeBuilder.build()); } catch (JsonProcessingException e) { throw new IllegalStateException(e); } } return new SyndesisMetadata(enrichedProperties, null, null); }
Example 10
Source File: GoogleSheetsMetaDataHelper.java From syndesis with Apache License 2.0 | 4 votes |
/** * Create dynamic json schema from row dimension. If split only a single object "ROW" holding 1-n column values is * created. Otherwise each row results in a separate object with 1-n column values as property. */ private static void createSchemaFromRowDimension(ObjectSchema spec, RangeCoordinate coordinate, String ... columnNames) { for (int i = coordinate.getColumnStartIndex(); i < coordinate.getColumnEndIndex(); i++) { spec.putProperty(CellCoordinate.getColumnName(i, coordinate.getColumnStartIndex(), columnNames), new JsonSchemaFactory().stringSchema()); } }
Example 11
Source File: GoogleSheetsMetaDataHelper.java From syndesis with Apache License 2.0 | 4 votes |
/** * Create dynamic json schema from column dimension. If split only a single object "COLUMN" holding 1-n row values is * created. Otherwise each column results in a separate object with 1-n row values as property. */ private static void createSchemaFromColumnDimension(ObjectSchema spec, RangeCoordinate coordinate) { for (int i = coordinate.getRowStartIndex() + 1; i <= coordinate.getRowEndIndex(); i++) { spec.putProperty("#" + i, new JsonSchemaFactory().stringSchema()); } }
Example 12
Source File: KuduMetadataRetrieval.java From syndesis with Apache License 2.0 | 4 votes |
private static ObjectSchema createSpec(KuduMetaData kuduMetaData) { // build the input and output schemas ObjectSchema spec = new ObjectSchema(); spec.set$schema(JSON_SCHEMA_ORG_SCHEMA); spec.setTitle("KUDU_INSERT"); Map<String, Object> options = new HashMap<>(); options.put("host", kuduMetaData.getHost()); options.put("port", kuduMetaData.getPort()); KuduClient client = KuduSupport.createConnection(options); try { KuduTable table = client.openTable(kuduMetaData.getTableName()); Iterator<ColumnSchema> columns = table.getSchema().getColumns().iterator(); while (columns.hasNext()) { ColumnSchema column = columns.next(); switch (column.getType().getName()) { case "string": spec.putProperty(column.getName(), new JsonSchemaFactory().stringSchema()); break; case "bool": spec.putProperty(column.getName(), new JsonSchemaFactory().booleanSchema()); break; case "float": case "double": case "int8": case "int16": case "int32": case "int64": spec.putProperty(column.getName(), new JsonSchemaFactory().integerSchema()); break; default: throw new SyndesisServerException("The column schema type " + column.getType().getName() + " for column " + column.getName() + " is not supported at the moment"); } } } catch (KuduException e) { throw new SyndesisServerException("Unable to connect to kudu schema " + kuduMetaData.getTableName(), e); } return spec; }