/** * Creates and returns a {@link Request} based on the passed in * {@link JsonNode} * * @param type - Request class to instantiate. * @param node - {@link JsonNode} of actions metadata * @return a {@link Request} based on the passed in {@link JsonNode} */ protected static <T extends Request> T createRequest(Class<T> type, JsonNode node) { JsonTranslator tx = getLightblueFactory().getJsonTranslator(); return tx.parse(type, node); }
private synchronized void initializeMetadata() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (metadata == null) { LOGGER.debug("Initializing metadata"); JsonNode root; try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(MetadataConfiguration.FILENAME)) { root = JsonUtils.json(is); } LOGGER.debug("Config root:{}", root); JsonNode cfgClass = root.get("type"); if (cfgClass == null) { throw new IllegalStateException(MetadataConstants.ERR_CONFIG_NOT_FOUND + " - type"); } MetadataConfiguration cfg = (MetadataConfiguration) Class.forName(cfgClass.asText()).newInstance(); cfg.initializeFromJson(root); // Set validation flag for all metadata requests getJsonTranslator().setValidation(EntityMetadata.class,cfg.isValidateRequests()); getJsonTranslator().setValidation(EntitySchema.class,cfg.isValidateRequests()); getJsonTranslator().setValidation(EntityInfo.class,cfg.isValidateRequests()); metadata = cfg.createMetadata(datasources, getJSONParser(), this); } }
private synchronized void initializeMetadata(Factory factory) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (metadata == null) { LOGGER.debug("Initializing metadata"); MetadataConfiguration cfg = getMetadataConfiguration(); // Set validation flag for all metadata requests getJsonTranslator().setValidation(EntityMetadata.class, cfg.isValidateRequests()); getJsonTranslator().setValidation(EntitySchema.class, cfg.isValidateRequests()); getJsonTranslator().setValidation(EntityInfo.class, cfg.isValidateRequests()); metadata = cfg.createMetadata(datasources, getJSONParser(), this); factory.setHookResolver(new SimpleHookResolver(cfg.getHookConfigurationParsers(), this)); } }
private synchronized void initializeMetadata(Factory factory) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (metadata == null) { LOGGER.debug("Initializing metadata"); MetadataConfiguration cfg = getMetadataConfiguration(); // Set validation flag for all metadata requests getJsonTranslator().setValidation(EntityMetadata.class, cfg.isValidateRequests()); getJsonTranslator().setValidation(EntitySchema.class, cfg.isValidateRequests()); getJsonTranslator().setValidation(EntityInfo.class, cfg.isValidateRequests()); metadata = cfg.createMetadata(datasources, getJSONParser(), this); factory.setHookResolver(new SimpleHookResolver(cfg.getHookConfigurationParsers(), this)); } }
private synchronized void initializeFactory() throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException, NoSuchMethodException, InstantiationException { if (factory == null) { JsonNode root; try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(CrudConfiguration.FILENAME)) { root = JsonUtils.json(is); } // convert root to Configuration object CrudConfiguration configuration = new CrudConfiguration(); configuration.initializeFromJson(root); // Set validation flag for all crud requests getJsonTranslator().setValidation(Request.class,configuration.isValidateRequests()); Factory f = new Factory(); f.addFieldConstraintValidators(new DefaultFieldConstraintValidators()); // Add default interceptors new UIDInterceptor().register(f.getInterceptors()); // validate if (!configuration.isValid()) { throw new IllegalStateException(CrudConstants.ERR_CONFIG_NOT_VALID + " - " + CrudConfiguration.FILENAME); } for (ControllerConfiguration x : configuration.getControllers()) { ControllerFactory cfactory = x.getControllerFactory().newInstance(); CRUDController controller = cfactory.createController(x, datasources); f.addCRUDController(x.getBackend(), controller); } // Make sure we assign factory after it is initialized. (factory is volatile, there's a memory barrier here) factory = f; } }
private synchronized void initializeFactory() throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException, NoSuchMethodException, InstantiationException { if (factory == null) { LOGGER.debug("Initializing factory"); if(crudConfiguration==null) initializeCrudConfiguration(); // Set validation flag for all crud requests getJsonTranslator().setValidation(Request.class, crudConfiguration.isValidateRequests()); Factory f = new Factory(); f.setBulkParallelExecutions(crudConfiguration.getBulkParallelExecutions()); f.setMemoryIndexThreshold(crudConfiguration.getMemoryIndexThreshold()); f.addFieldConstraintValidators(new DefaultFieldConstraintValidators()); f.setMaxResultSetSizeForReadsB(crudConfiguration.getMaxResultSetSizeForReadsB()); f.setWarnResultSetSizeB(crudConfiguration.getWarnResultSetSizeB()); f.setMaxResultSetSizeForWritesB(crudConfiguration.getMaxResultSetSizeForWritesB()); f.setMaxExecutionContextSizeForCompositeFindB(crudConfiguration.getMaxExecutionContextSizeForCompositeFindB()); // Add default interceptors new UIDInterceptor().register(f.getInterceptors()); new GeneratedFieldInterceptor().register(f.getInterceptors()); for (ControllerConfiguration x : crudConfiguration.getControllers()) { ControllerFactory cfactory = x.getControllerFactory().newInstance(); CRUDController controller = cfactory.createController(x, datasources); injectDependencies(controller); f.addCRUDController(x.getBackend(), controller); } // Make sure we assign factory after it is initialized. (factory is volatile, there's a memory barrier here) factory = f; LOGGER.info("Initialized factory: {}", factory); } }
private synchronized void initializeFactory() throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException, NoSuchMethodException, InstantiationException { if (factory == null) { LOGGER.debug("Initializing factory"); if(crudConfiguration==null) initializeCrudConfiguration(); // Set validation flag for all crud requests getJsonTranslator().setValidation(Request.class, crudConfiguration.isValidateRequests()); Factory f = new Factory(); f.setBulkParallelExecutions(crudConfiguration.getBulkParallelExecutions()); f.setMemoryIndexThreshold(crudConfiguration.getMemoryIndexThreshold()); f.addFieldConstraintValidators(new DefaultFieldConstraintValidators()); f.setMaxResultSetSizeForReadsB(crudConfiguration.getMaxResultSetSizeForReadsB()); f.setWarnResultSetSizeB(crudConfiguration.getWarnResultSetSizeB()); f.setMaxResultSetSizeForWritesB(crudConfiguration.getMaxResultSetSizeForWritesB()); f.setMaxExecutionContextSizeForCompositeFindB(crudConfiguration.getMaxExecutionContextSizeForCompositeFindB()); // Add default interceptors new UIDInterceptor().register(f.getInterceptors()); new GeneratedFieldInterceptor().register(f.getInterceptors()); for (ControllerConfiguration x : crudConfiguration.getControllers()) { ControllerFactory cfactory = x.getControllerFactory().newInstance(); CRUDController controller = cfactory.createController(x, datasources); injectDependencies(controller); f.addCRUDController(x.getBackend(), controller); } // Make sure we assign factory after it is initialized. (factory is volatile, there's a memory barrier here) factory = f; LOGGER.info("Initialized factory: {}", factory); } }
getLightblueMetadataJson()); JsonTranslator tx = lightblueFactory.getJsonTranslator();