private static void setViewAttributes(String location, DataStructureSchemaModel result, JsonObject structure, String type, DataStructureViewModel view) { view.setLocation(location); view.setName(structure.get("name").getAsString()); view.setType(type); view.setQuery(structure.get("columns").getAsJsonArray().get(0).getAsJsonObject().get("query").getAsString()); view.setCreatedAt(result.getCreatedAt()); view.setCreatedBy(result.getCreatedBy()); view.setHash(result.getHash()); }
private static void setTableAttributes(String location, DataStructureSchemaModel result, JsonObject structure, String type, DataStructureTableModel table) { table.setLocation(location); table.setName(structure.get("name").getAsString()); table.setType(type); table.setCreatedAt(result.getCreatedAt()); table.setCreatedBy(result.getCreatedBy()); table.setHash(result.getHash()); JsonElement columnElement = structure.get("columns"); if (columnElement.isJsonObject()) { JsonObject column = columnElement.getAsJsonObject(); DataStructureTableColumnModel columnModel = new DataStructureTableColumnModel(); setColumnAttributes(column, columnModel); table.getColumns().add(columnModel); } else if (columnElement.isJsonArray()) { JsonArray columns = columnElement.getAsJsonArray(); for (int j=0; j<columns.size(); j++) { JsonObject column = columns.get(j).getAsJsonObject(); DataStructureTableColumnModel columnModel = new DataStructureTableColumnModel(); setColumnAttributes(column, columnModel); table.getColumns().add(columnModel); } } else { throw new IllegalArgumentException(format("Error in parsing columns of table [{0}] in schema [{1}]", table.getName(), location)); } }
/** * Synchronize schema. * * @param schemaModel * the schema model * @throws SynchronizationException * the synchronization exception */ private void synchronizeSchema(DataStructureSchemaModel schemaModel) throws SynchronizationException { try { if (!dataStructuresCoreService.existsSchema(schemaModel.getLocation())) { dataStructuresCoreService.createSchema(schemaModel.getLocation(), schemaModel.getName(), schemaModel.getHash()); DATA_STRUCTURE_SCHEMA_MODELS.put(schemaModel.getName(), schemaModel); addDataStructureModelsFromSchema(schemaModel); logger.info("Synchronized a new Schema file [{}] from location: {}", schemaModel.getName(), schemaModel.getLocation()); } else { DataStructureSchemaModel existing = dataStructuresCoreService.getSchema(schemaModel.getLocation()); if (!schemaModel.equals(existing)) { dataStructuresCoreService.updateSchema(schemaModel.getLocation(), schemaModel.getName(), schemaModel.getHash()); DATA_STRUCTURE_SCHEMA_MODELS.put(schemaModel.getName(), schemaModel); addDataStructureModelsFromSchema(schemaModel); logger.info("Synchronized a modified Schema file [{}] from location: {}", schemaModel.getName(), schemaModel.getLocation()); } } SCHEMA_SYNCHRONIZED.add(schemaModel.getLocation()); } catch (DataStructuresException e) { throw new SynchronizationException(e); } }