Search in sources :

Example 26 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project OpenAttestation by OpenAttestation.

the class RelationalPatchTest method createMapper.

@BeforeClass
public static void createMapper() {
    mapper = new ObjectMapper();
    mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy());
}
Also used : PropertyNamingStrategy(org.codehaus.jackson.map.PropertyNamingStrategy) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 27 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project quickstarts by jboss-switchyard.

the class DozerTransformationTest method testTransformJavaToJson.

@Test
public void testTransformJavaToJson() throws Exception {
    Order testOrder = new Order().setItem("BUTTER").setQuantity(100);
    String result = submitOrder.expectedOutputType(TO_TYPE).sendInOut(testOrder).getContent(String.class);
    // parse the reference and returned JSON strings and compare for equality
    ObjectMapper mapper = new ObjectMapper();
    OrderAck expected = mapper.readValue(_testKit.readResourceString(ORDER_ACK_JSON), OrderAck.class);
    OrderAck returned = mapper.readValue(result, OrderAck.class);
    Assert.assertEquals(expected, returned);
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 28 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project quickstarts by jboss-switchyard.

the class JsonTransformationTest method testTransformJavaToXML.

@Test
public void testTransformJavaToXML() throws Exception {
    Order testOrder = new Order().setOrderId("PO-19838-XYZ").setItemId("BUTTER").setQuantity(100);
    String result = submitOrder.expectedOutputType(TO_TYPE).sendInOut(testOrder).getContent(String.class);
    // parse the reference and returned JSON strings and compare for equality
    ObjectMapper mapper = new ObjectMapper();
    OrderAck expected = mapper.readValue(_testKit.readResourceString(ORDER_ACK_JSON), OrderAck.class);
    OrderAck returned = mapper.readValue(result, OrderAck.class);
    Assert.assertEquals(expected, returned);
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 29 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project pinot by linkedin.

the class AvroSchemaToPinotSchema method execute.

@Override
public boolean execute() throws Exception {
    Schema schema = null;
    if (_avroSchemaFileName != null) {
        schema = AvroUtils.getPinotSchemaFromAvroSchemaFile(_avroSchemaFileName, buildFieldTypesMap(), _timeUnit);
    } else if (_avroDataFileName != null) {
        schema = AvroUtils.extractSchemaFromAvro(new File(_avroDataFileName));
    } else {
        LOGGER.error("Error: Missing required argument, please specify either -avroSchemaFileName, or -avroDataFileName");
        return false;
    }
    if (schema == null) {
        LOGGER.error("Error: Could not read avro schema from file.");
        return false;
    }
    String avroFileName = _avroSchemaFileName;
    if (avroFileName == null) {
        avroFileName = _avroDataFileName;
    }
    // Remove extension
    String schemaName = avroFileName.replaceAll("\\..*", "");
    schema.setSchemaName(schemaName);
    if (_pinotSchemaFileName == null) {
        _pinotSchemaFileName = schemaName + ".json";
        LOGGER.info("Using {} as the Pinot schema file name", _pinotSchemaFileName);
    }
    ObjectMapper objectMapper = new ObjectMapper();
    String schemaString = objectMapper.defaultPrettyPrintingWriter().writeValueAsString(schema);
    PrintWriter printWriter = new PrintWriter(_pinotSchemaFileName);
    printWriter.println(schemaString);
    printWriter.close();
    return true;
}
Also used : Schema(com.linkedin.pinot.common.data.Schema) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PrintWriter(java.io.PrintWriter)

Example 30 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project pinot by linkedin.

the class CreateSegmentCommand method execute.

@Override
public boolean execute() throws Exception {
    LOGGER.info("Executing command: {}", toString());
    // Load generator config if exist.
    final SegmentGeneratorConfig segmentGeneratorConfig;
    if (_generatorConfigFile != null) {
        segmentGeneratorConfig = new ObjectMapper().readValue(new File(_generatorConfigFile), SegmentGeneratorConfig.class);
    } else {
        segmentGeneratorConfig = new SegmentGeneratorConfig();
    }
    // Load config from segment generator config.
    String configDataDir = segmentGeneratorConfig.getDataDir();
    if (_dataDir == null) {
        if (configDataDir == null) {
            throw new RuntimeException("Must specify dataDir.");
        }
        _dataDir = configDataDir;
    } else {
        if (configDataDir != null && !configDataDir.equals(_dataDir)) {
            LOGGER.warn("Find dataDir conflict in command line and config file, use config in command line: {}", _dataDir);
        }
    }
    FileFormat configFormat = segmentGeneratorConfig.getFormat();
    if (_format == null) {
        if (configFormat == null) {
            throw new RuntimeException("Format cannot be null in config file.");
        }
        _format = configFormat;
    } else {
        if (configFormat != _format && configFormat != FileFormat.AVRO) {
            LOGGER.warn("Find format conflict in command line and config file, use config in command line: {}", _format);
        }
    }
    String configOutDir = segmentGeneratorConfig.getOutDir();
    if (_outDir == null) {
        if (configOutDir == null) {
            throw new RuntimeException("Must specify outDir.");
        }
        _outDir = configOutDir;
    } else {
        if (configOutDir != null && !configOutDir.equals(_outDir)) {
            LOGGER.warn("Find outDir conflict in command line and config file, use config in command line: {}", _outDir);
        }
    }
    if (segmentGeneratorConfig.isOverwrite()) {
        _overwrite = true;
    }
    String configTableName = segmentGeneratorConfig.getTableName();
    if (_tableName == null) {
        if (configTableName == null) {
            throw new RuntimeException("Must specify tableName.");
        }
        _tableName = configTableName;
    } else {
        if (configTableName != null && !configTableName.equals(_tableName)) {
            LOGGER.warn("Find tableName conflict in command line and config file, use config in command line: {}", _tableName);
        }
    }
    String configSegmentName = segmentGeneratorConfig.getSegmentName();
    if (_segmentName == null) {
        if (configSegmentName == null) {
            throw new RuntimeException("Must specify segmentName.");
        }
        _segmentName = configSegmentName;
    } else {
        if (configSegmentName != null && !configSegmentName.equals(_segmentName)) {
            LOGGER.warn("Find segmentName conflict in command line and config file, use config in command line: {}", _segmentName);
        }
    }
    // Filter out all input files.
    File dir = new File(_dataDir);
    if (!dir.exists() || !dir.isDirectory()) {
        throw new RuntimeException("Data directory " + _dataDir + " not found.");
    }
    File[] files = dir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(_format.toString().toLowerCase());
        }
    });
    if ((files == null) || (files.length == 0)) {
        throw new RuntimeException("Data directory " + _dataDir + " does not contain " + _format.toString().toUpperCase() + " files.");
    }
    // Make sure output directory does not already exist, or can be overwritten.
    File outDir = new File(_outDir);
    if (outDir.exists()) {
        if (!_overwrite) {
            throw new IOException("Output directory " + _outDir + " already exists.");
        } else {
            FileUtils.deleteDirectory(outDir);
        }
    }
    // Set other generator configs from command line.
    segmentGeneratorConfig.setDataDir(_dataDir);
    segmentGeneratorConfig.setFormat(_format);
    segmentGeneratorConfig.setOutDir(_outDir);
    segmentGeneratorConfig.setOverwrite(_overwrite);
    segmentGeneratorConfig.setTableName(_tableName);
    segmentGeneratorConfig.setSegmentName(_segmentName);
    if (_schemaFile != null) {
        if (segmentGeneratorConfig.getSchemaFile() != null && !segmentGeneratorConfig.getSchemaFile().equals(_schemaFile)) {
            LOGGER.warn("Find schemaFile conflict in command line and config file, use config in command line: {}", _schemaFile);
        }
        segmentGeneratorConfig.setSchemaFile(_schemaFile);
    }
    if (_readerConfigFile != null) {
        if (segmentGeneratorConfig.getReaderConfigFile() != null && !segmentGeneratorConfig.getReaderConfigFile().equals(_readerConfigFile)) {
            LOGGER.warn("Find readerConfigFile conflict in command line and config file, use config in command line: {}", _readerConfigFile);
        }
        segmentGeneratorConfig.setReaderConfigFile(_readerConfigFile);
    }
    if (_enableStarTreeIndex) {
        segmentGeneratorConfig.setEnableStarTreeIndex(true);
    }
    if (_starTreeIndexSpecFile != null) {
        if (segmentGeneratorConfig.getStarTreeIndexSpecFile() != null && !segmentGeneratorConfig.getStarTreeIndexSpecFile().equals(_starTreeIndexSpecFile)) {
            LOGGER.warn("Find starTreeIndexSpecFile conflict in command line and config file, use config in command line: {}", _starTreeIndexSpecFile);
        }
        segmentGeneratorConfig.setStarTreeIndexSpecFile(_starTreeIndexSpecFile);
    }
    ExecutorService executor = Executors.newFixedThreadPool(_numThreads);
    int cnt = 0;
    for (final File file : files) {
        final int segCnt = cnt;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    SegmentGeneratorConfig config = new SegmentGeneratorConfig(segmentGeneratorConfig);
                    config.setInputFilePath(file.getAbsolutePath());
                    config.setSegmentName(_segmentName + "_" + segCnt);
                    config.loadConfigFiles();
                    final SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
                    driver.init(config);
                    driver.build();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
        cnt += 1;
    }
    executor.shutdown();
    return executor.awaitTermination(1, TimeUnit.HOURS);
}
Also used : IOException(java.io.IOException) FileFormat(com.linkedin.pinot.core.data.readers.FileFormat) IOException(java.io.IOException) SegmentIndexCreationDriverImpl(com.linkedin.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl) FilenameFilter(java.io.FilenameFilter) SegmentGeneratorConfig(com.linkedin.pinot.core.indexsegment.generator.SegmentGeneratorConfig) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)356 IOException (java.io.IOException)75 Test (org.junit.Test)58 JsonNode (org.codehaus.jackson.JsonNode)47 ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)43 Test (org.testng.annotations.Test)37 Map (java.util.Map)33 List (java.util.List)25 StringWriter (java.io.StringWriter)22 File (java.io.File)21 JSONObject (org.json.JSONObject)18 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)15 Version (org.codehaus.jackson.Version)14 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 JsonFactory (org.codehaus.jackson.JsonFactory)13 JSONObject (org.codehaus.jettison.json.JSONObject)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)11