Example usage for org.apache.commons.collections.bidimap DualHashBidiMap get

List of usage examples for org.apache.commons.collections.bidimap DualHashBidiMap get

Introduction

In this page you can find the example usage for org.apache.commons.collections.bidimap DualHashBidiMap get.

Prototype

public Object get(Object key) 

Source Link

Usage

From source file:eu.scape_project.archiventory.container.ZipContainerTest.java

/**
 * Test of init method, of class ZipContainer.
 *///  w w w .j av  a2s. c o  m
@Test
public void testInit() throws Exception {
    InputStream testFileStream = ZipContainer.class.getResourceAsStream("test.zip");
    if (testFileStream == null)
        fail();
    File tmpTestFile = File.createTempFile("test", ".zip");
    FileOutputStream fos = new FileOutputStream(tmpTestFile);
    IOUtils.copy(testFileStream, fos);
    fos.close();
    String containerFileName = "test.zip";
    InputStream containerFileStream = new FileInputStream(tmpTestFile);
    ZipContainer instance = new ZipContainer();
    instance.init(containerFileName, containerFileStream);
    DualHashBidiMap bidiIdentifierFilenameMap = instance.getBidiIdentifierFilenameMap();
    String key = instance.getExtractDirectoryName() + "test.zip/test.doc";
    assertTrue(bidiIdentifierFilenameMap.containsKey(key));
    String value = (String) bidiIdentifierFilenameMap.get(key);
    assertNotNull(value);
    File tmpFile = new File(value);
    assertTrue("File does not exist: " + tmpFile.getAbsolutePath(), tmpFile.exists());
}

From source file:eu.scape_project.archiventory.container.ZipContainerTest.java

/**
 * Test of init method, of class ZipContainer.
 *//*from w ww .  j av  a 2  s . co  m*/
@Test
public void testInitWithSubfolder() throws Exception {
    InputStream testFileStream = ZipContainer.class.getResourceAsStream("testsub.zip");
    if (testFileStream == null)
        fail();
    File tmpTestFile = File.createTempFile("testsub", ".zip");
    FileOutputStream fos = new FileOutputStream(tmpTestFile);
    IOUtils.copy(testFileStream, fos);
    fos.close();
    String containerFileName = "testsub.zip";
    InputStream containerFileStream = new FileInputStream(tmpTestFile);
    ZipContainer instance = new ZipContainer();
    instance.init(containerFileName, containerFileStream);
    DualHashBidiMap bidiIdentifierFilenameMap = instance.getBidiIdentifierFilenameMap();
    String key = instance.getExtractDirectoryName() + "testsub.zip/test/sub/test.doc";
    //String key = "/testsub.zip/test/sub/test.doc";
    assertTrue(bidiIdentifierFilenameMap.containsKey(key));
    String value = (String) bidiIdentifierFilenameMap.get(key);
    assertNotNull(value);
    File tmpFile = new File(value);
    assertTrue("File does not exist: " + tmpFile.getAbsolutePath(), tmpFile.exists());
}

From source file:eu.scape_project.archiventory.identifiers.Identification.java

/**
 * File list identification. Processing a bi-directional map of records
 * where each record has one temporary file and each temporary file has one
 * record key (strict 1:1 relationship).
 *
 * @param fileRecidBidiMap Input { "recordkey" <-> "tempfilename" }
 * @return Output { "recordkey": [ "tool/property/value" ] }
 * @throws IOException//from  ww  w  .  j  av  a 2  s  . c om
 */
public HashMap<String, List<String>> identifyFileList(DualHashBidiMap fileRecidBidiMap) throws IOException {
    HashMap<String, List<String>> resultMap = new HashMap<String, List<String>>();
    Iterator iter = fileRecidBidiMap.keySet().iterator();
    while (iter.hasNext()) {
        String recordKey = (String) iter.next();
        String tmpFileName = (String) fileRecidBidiMap.get(recordKey);
        File file = new File(tmpFileName);
        HashMap idRes = this.identify(file);
        String containerFileName = recordKey.substring(0, recordKey.indexOf("/"));
        String containerIdentifier = recordKey.substring(recordKey.indexOf("/") + 1);
        String outputKey = String.format(outputKeyFormat, containerFileName, containerIdentifier);
        List<String> valueLineList = new ArrayList<String>();
        for (Object k : idRes.keySet()) {
            String property = (String) k;
            String value = (String) idRes.get(k);
            String outputValue = String.format(outputValueFormat, tool, property, value);
            valueLineList.add(outputValue);

        }
        resultMap.put(outputKey, valueLineList);
    }
    return resultMap;
}

From source file:edu.jhuapl.openessence.datasource.jdbc.entry.JdbcOeDataEntrySource.java

/**
 * Executes INSERT SQL Statment using Spring's JdbcTemplate.
 *
 * @param tableName        table to insert values into
 * @param ignoreSpecialSql the flag to ignore specialSql definitions in the groovy def file. In general, set false
 *                         during add* and set true during update*
 * @param dimIds           DimensionIds that we will insert data for //todo ?? why is this needed?
 * @param editDims         editable DimensionIds that we will insert data for
 * @param values           values that correspond to the editable DimensionIds. These values get written into the
 *                         database//from ww  w  . j  a  v a2 s . co m
 * @return Map of the primary keys and values for the inserted record -- only for the Parent Record - children return
 *         null
 * @throws OeDataSourceAccessException if error occurs at database level
 * @throws OeDataSourceException       if error occurs during processing
 */
private Map editableInsertQuery(String tableName, boolean ignoreSpecialSql, List<String> dimIds,
        Map<String, Dimension> editDims, Map<String, Object> values)
        throws OeDataSourceAccessException, OeDataSourceException {

    List<String> generatedKeys = new ArrayList<String>();
    Set<String> tablePkIds;

    // insert on parent table
    if (tableName.equals(parentTableDetails.getTableName())) {

        // setup KeyHolder from pk_dimIds
        tablePkIds = parentTableDetails.getPks();

        // setup autogen to sqlcol map
        Map<String, Object> superEditCopy = new LinkedHashMap<String, Object>(superEditMap);
        Set<String> superEditKeys = superEditCopy.keySet();
        DualHashBidiMap bidimap = new DualHashBidiMap();
        superEditKeys.retainAll(tablePkIds);
        for (Map.Entry<String, Object> e : superEditCopy.entrySet()) {
            e.setValue(((DimensionBean) e.getValue()).getSqlCol());
            bidimap.put(e.getKey(), e.getValue());
        }

        // setup KeyHolder from pk_dimIds
        generatedKeys.addAll(tablePkIds); // NOTE: jdbc driver clears this and puts in the autoincs it finds.
        Map<String, Object> generatedKeyMap = new HashMap<String, Object>();
        for (String eachKey : generatedKeys) {
            generatedKeyMap.put(eachKey, null);
        }
        List<Map<String, Object>> keyMapList = new ArrayList<Map<String, Object>>();
        keyMapList.add(generatedKeyMap);
        KeyHolder keyHolder = new GeneratedKeyHolder(keyMapList);

        jdbcTemplate.update(new MultiTableInsertPreparedStatementCreator(tableName, ignoreSpecialSql, dimIds,
                editDims, values), keyHolder);

        Map<String, Object> keyMap = keyHolder.getKeys();

        // TODO: current implementation of getGeneratedKeys for PGSQL 8.4 returns ALL column/vals...we just want the pk's we know about
        // TODO: CHECK FOR WHAT HAPPENS WITH LOWER/UPPER CASE
        //http://archives.postgresql.org/pgsql-jdbc/2010-04/msg00061.php
        boolean isPostgreSql = isPostgreSqlDBMS();
        if (isPostgreSql) {
            // postgres' implementation of keyholder lowercases the key column
            DbKeyValMap dbkvm = new DbKeyValMap(bidimap);
            Set<String> kyids = dbkvm.keySet();
            for (String ky : kyids) {
                dbkvm.put(ky, keyMap.get(bidimap.get(ky)));
            }
            kyids.retainAll(tablePkIds);
            keyMap = dbkvm;
        }

        // -OR-
        // if table had no auto-gen keys but the INSERT suceedes, means the pks taken from the 'values' worked.
        // therefore, safe to use these as the "generated" PKs. retains the values that are designated "PK" dimensions
        //
        else if (keyMap == null || keyMap.size() == 0) {
            DbKeyValMap dbkvm = new DbKeyValMap(values);
            Set<String> kyids = dbkvm.keySet();
            kyids.retainAll(tablePkIds);
            keyMap = dbkvm;
        }

        // make sure got *ALL* pkIds/values configured in the ds def.
        List<Map> allkeys = getAllGeneratedKeys(tableName, tablePkIds, new DbKeyValMap(keyMap));

        return (allkeys.size() > 0 ? allkeys.get(0) : null);

    } else { // insert on child table.
        // don't need to know the returned PK ids & vals for children. just do typical INSERT
        jdbcTemplate.update(new MultiTableInsertPreparedStatementCreator(tableName, ignoreSpecialSql, dimIds,
                editDims, values));
        return null;
    }
}