Example usage for org.apache.commons.lang SerializationUtils serialize

List of usage examples for org.apache.commons.lang SerializationUtils serialize

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils serialize.

Prototype

public static void serialize(Serializable obj, OutputStream outputStream) 

Source Link

Document

Serializes an Object to the specified stream.

The stream will be closed once the object is written.

Usage

From source file:com.ephesoft.dcma.batch.dao.impl.BatchInstancePluginPropertiesDao.java

/**
 * This method is to get the plugin properties.
 * /* ww  w .j a v  a 2  s.  c  om*/
 * @param batchInstanceIdentifier String.
 * @return {@link BatchPluginPropertyContainer}
 */
@Cacheable(cacheName = "pluginPropertiesCache", keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false")))
public BatchPluginPropertyContainer getPluginProperties(final String batchInstanceIdentifier) {
    String loggingPrefix = BatchConstants.LOG_AREA + batchInstanceIdentifier;
    if (IS_DEBUG_ENABLE) {
        LOGGER.debug(loggingPrefix
                + " : Executing getPluginProperties(String) API of BatchInstancePluginPropertiesDao.");
    }
    BatchPluginPropertyContainer container = null;
    final String localFolderLocation = batchInstanceDao
            .getSystemFolderForBatchInstanceId(batchInstanceIdentifier);
    boolean isContainerCreated = false;
    final String pathToPropertiesFolder = localFolderLocation + File.separator + "properties";
    final File file = new File(pathToPropertiesFolder);
    if (!file.exists()) {
        file.mkdir();
        if (IS_DEBUG_ENABLE) {
            LOGGER.debug(loggingPrefix + " : folder created " + pathToPropertiesFolder);
        }
    }
    final File serializedFile = new File(
            pathToPropertiesFolder + File.separator + batchInstanceIdentifier + '.' + EXTN);
    if (serializedFile.exists()) {
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(serializedFile);
            container = (BatchPluginPropertyContainer) SerializationUtils.deserialize(fileInputStream);
            isContainerCreated = true;
        } catch (Exception exception) {
            LOGGER.error(
                    loggingPrefix + " : Error during de-serializing the properties for this Batch instance: ",
                    exception);
            isContainerCreated = false;
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException exception) {
                LOGGER.error(loggingPrefix + " : Problem closing stream for file : " + serializedFile.getName(),
                        exception);
            }
        }
    }
    if (!isContainerCreated) {
        final List<BatchClassPluginConfig> batchClassPluginConfigs = batchClassPluginConfigDao
                .getAllPluginPropertiesForBatchInstance(batchInstanceIdentifier);
        // to lazily load KVPageProcess objects
        for (final BatchClassPluginConfig batchClassPluginConfig : batchClassPluginConfigs) {
            for (final KVPageProcess eachKvPageProcess : batchClassPluginConfig.getKvPageProcesses()) {
                if (IS_DEBUG_ENABLE && eachKvPageProcess != null) {
                    LOGGER.debug(loggingPrefix + " : Key pattern is " + eachKvPageProcess.getKeyPattern());
                }
            }
        }

        final List<BatchClassDynamicPluginConfig> batchClassDynamicPluginConfigs = batchClassDynamicPluginConfigDao
                .getAllDynamicPluginPropertiesForBatchInstance(batchInstanceIdentifier);
        container = new BatchPluginPropertyContainer(String.valueOf(batchInstanceIdentifier));
        container.populate(batchClassPluginConfigs);
        container.populateDynamicPluginConfigs(batchClassDynamicPluginConfigs);
        final List<DocumentType> documentTypes = documentTypeService
                .getDocTypeByBatchInstanceIdentifier(batchInstanceIdentifier);
        container.populateDocumentTypes(documentTypes, batchInstanceIdentifier);
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(serializedFile);
            SerializationUtils.serialize(container, fileOutputStream);
        } catch (Exception exception) {
            LOGGER.error(loggingPrefix + " : Error during serializing properties for this Batch instance.",
                    exception);
        } finally {
            try {
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException exception) {
                LOGGER.error(loggingPrefix + " : Problem closing stream for file " + serializedFile.getName(),
                        exception);
            }
        }
    }
    if (IS_DEBUG_ENABLE) {
        LOGGER.debug(loggingPrefix
                + " : Executed getPluginProperties(String) API of BatchInstancePluginPropertiesDao successfully.");
    }
    return container;
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for plugin.
 * //from ww w.j  a v a  2  s .c o m
 * @param service {@link BatchClassService}
 * @param pluginInfo {@link String}
 */
private static void createPatchForPlugin(final BatchClassService service, final String pluginInfo) {
    final StringTokenizer pluginTokens = new StringTokenizer(pluginInfo, DataAccessConstant.SEMI_COLON);
    while (pluginTokens.hasMoreTokens()) {
        String pluginToken = pluginTokens.nextToken();
        StringTokenizer pluginConfigTokens = new StringTokenizer(pluginToken, DataAccessConstant.COMMA);
        String batchClassIdentifier = null;
        String moduleId = null;
        String pluginId = null;
        try {
            batchClassIdentifier = pluginConfigTokens.nextToken();
            moduleId = pluginConfigTokens.nextToken();
            pluginId = pluginConfigTokens.nextToken();
            BatchClassPlugin createdPlugin = createPatch(batchClassIdentifier, moduleId, pluginId, service);
            if (createdPlugin != null) {
                BatchClass batchClass = service.getBatchClassByIdentifier(batchClassIdentifier);
                Module module = moduleService.getModulePropertiesForModuleId(Long.valueOf(moduleId));
                String key = batchClass.getName() + DataAccessConstant.COMMA + module.getName();
                ArrayList<BatchClassPlugin> pluginsList = batchClassNameVsPluginsMap.get(key);
                if (pluginsList == null) {
                    pluginsList = new ArrayList<BatchClassPlugin>();
                    batchClassNameVsPluginsMap.put(key, pluginsList);
                }
                pluginsList.add(createdPlugin);
            }

        } catch (NoSuchElementException e) {
            LOG.info("Incomplete data specifiedin properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "PluginUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(batchClassNameVsPluginsMap, new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for plugin config. 
 * //  www .j  a v a  2  s  . c o m
 * @param service {@link BatchClassService}
 * @param pluginConfigInfo {@link String}
 */
private static void createPatchForPluginConfig(BatchClassService service, final String pluginConfigInfo) {
    StringTokenizer pluginTokens = new StringTokenizer(pluginConfigInfo, DataAccessConstant.SEMI_COLON);
    while (pluginTokens.hasMoreTokens()) {
        String pluginToken = pluginTokens.nextToken();
        StringTokenizer pluginConfigTokens = new StringTokenizer(pluginToken, DataAccessConstant.COMMA);
        String pluginId = null;
        String pluginConfigId = null;
        try {
            pluginId = pluginConfigTokens.nextToken();
            pluginConfigId = pluginConfigTokens.nextToken();
            createPatch(pluginId, pluginConfigId, service);

        } catch (NoSuchElementException e) {
            LOG.error("Incomplete data specified in properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "PluginConfigUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(pluginNameVsBatchPluginConfigList,
                new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }
}

From source file:com.ephesoft.gxt.batchinstance.server.CopyTroubleshootingArtifacts.java

/**
 * This method copies the exported batch class to the download folder.
 * /*from w w  w .  j a va  2 s .  c  om*/
 * @param batchSchemaService {@link BatchSchemaService} instance of batch schema service
 * @param imageMagickBaseFolderParam {@link String} the parameter value of checkbox for image magick base folder
 * @param isSearchSampleNameParam {@link String} the parameter value of checkbox for lucene search classification
 * @param batchClass {@link BatchClass} the batch class of batch instance
 * @param tempFolderLocation {@link String} the temporary folder location
 * @throws IOException if an exception occurs while creating the serialized file.
 */
private void createExportedBatchClassFolder(final BatchSchemaService batchSchemaService,
        final String imageMagickBaseFolderParam, final String isSearchSampleNameParam,
        final BatchClass batchClass, final String tempFolderLocation) throws IOException {

    File copiedFolder = new File(tempFolderLocation);

    if (copiedFolder.exists()) {
        copiedFolder.delete();
    }

    copiedFolder.mkdirs();

    BatchClassUtil.copyModules(batchClass);
    BatchClassUtil.copyDocumentTypes(batchClass);
    BatchClassUtil.copyScannerConfig(batchClass);
    BatchClassUtil.exportEmailConfiguration(batchClass);
    BatchClassUtil.exportUserGroups(batchClass);
    BatchClassUtil.exportBatchClassField(batchClass);
    BatchClassUtil.exportCMISConfiguration(batchClass);

    File serializedExportFile = new File(EphesoftStringUtil.concatenate(tempFolderLocation, File.separator,
            batchClass.getIdentifier(), SERIALIZATION_EXT));

    try {
        SerializationUtils.serialize(batchClass, new FileOutputStream(serializedExportFile));

        File originalFolder = new File(EphesoftStringUtil.concatenate(batchSchemaService.getBaseSampleFDLock(),
                File.separator, batchClass.getIdentifier()));

        if (originalFolder.isDirectory()) {

            final String[] folderList = originalFolder.list();
            Arrays.sort(folderList);

            for (int i = 0; i < folderList.length; i++) {
                if (folderList[i].endsWith(SERIALIZATION_EXT)) {
                    // skip previous ser file since new is created.
                } else if (FilenameUtils.getName(folderList[i])
                        .equalsIgnoreCase(batchSchemaService.getTestKVExtractionFolderName())
                        || FilenameUtils.getName(folderList[i])
                                .equalsIgnoreCase(batchSchemaService.getTestTableFolderName())
                        || FilenameUtils.getName(folderList[i])
                                .equalsIgnoreCase(batchSchemaService.getFileboundPluginMappingFolderName())) {
                    // Skip this folder
                    continue;
                } else if (FilenameUtils.getName(folderList[i])
                        .equalsIgnoreCase(batchSchemaService.getImagemagickBaseFolderName())
                        && !EphesoftStringUtil.isNullOrEmpty(imageMagickBaseFolderParam)) {
                    FileUtils.copyDirectoryWithContents(new File(originalFolder, folderList[i]),
                            new File(copiedFolder, folderList[i]));
                } else if (FilenameUtils.getName(folderList[i])
                        .equalsIgnoreCase(batchSchemaService.getSearchSampleName())
                        && !EphesoftStringUtil.isNullOrEmpty(isSearchSampleNameParam)) {
                    FileUtils.copyDirectoryWithContents(new File(originalFolder, folderList[i]),
                            new File(copiedFolder, folderList[i]));
                } else if (!(FilenameUtils.getName(folderList[i])
                        .equalsIgnoreCase(batchSchemaService.getImagemagickBaseFolderName())
                        || FilenameUtils.getName(folderList[i])
                                .equalsIgnoreCase(batchSchemaService.getSearchSampleName()))) {
                    FileUtils.copyDirectoryWithContents(new File(originalFolder, folderList[i]),
                            new File(copiedFolder, folderList[i]));
                }
            }
        }

    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOGGER.error(EphesoftStringUtil.concatenate("Error occurred while creating the serializable file. ",
                e.getMessage()), e);
        foldersNotCopied.append(EphesoftStringUtil.concatenate(BATCH_CLASS_FOLDER, SEMI_COLON));
    } catch (IOException e) {
        // Unable to create the temporary export file(s)/folder(s)
        LOGGER.error(EphesoftStringUtil.concatenate("Error occurred while creating the serializable file.",
                e.getMessage()), e);
    }
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for module.
 * // w  w  w  .  jav  a 2  s .  co  m
 * @param service {@link BatchClassService}
 * @param moduleInfo {@link String}
 */
private static void createPatchForModule(BatchClassService service, String moduleInfo) {
    StringTokenizer moduleTokens = new StringTokenizer(moduleInfo, DataAccessConstant.SEMI_COLON);
    while (moduleTokens.hasMoreTokens()) {
        String moduleToken = moduleTokens.nextToken();
        StringTokenizer pluginConfigTokens = new StringTokenizer(moduleToken, DataAccessConstant.COMMA);
        String batchClassName = null;
        String moduleId = null;
        try {
            batchClassName = pluginConfigTokens.nextToken();
            moduleId = pluginConfigTokens.nextToken();
            BatchClassModule createdModule = createPatchForModule(batchClassName, moduleId, service);
            if (createdModule != null) {
                BatchClass batchClass = service.getBatchClassByIdentifier(batchClassName);
                ArrayList<BatchClassModule> bcmList = batchClassNameVsModulesMap.get(batchClass.getName());
                if (bcmList == null) {
                    bcmList = new ArrayList<BatchClassModule>();
                    batchClassNameVsModulesMap.put(batchClass.getName(), bcmList);
                }
                bcmList.add(createdModule);
            }

        } catch (NoSuchElementException e) {
            LOG.error("Incomplete data specified in properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "ModuleUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(batchClassNameVsModulesMap, new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }

}

From source file:com.ephesoft.dcma.gwt.uploadbatch.server.UploadBatchServiceImpl.java

/**
 * This method is used to serialize the BatchClassField that is to be used in Web scanner module
 * //  ww w  .  jav a2 s.  co  m
 * @param folderName
 * @param values
 */

@Override
public void serializeBatchClassField(String folderName, List<BatchClassFieldDTO> values) throws GWTException {
    FileOutputStream fileOutputStream = null;
    File serializedExportFile = null;
    ArrayList<BatchClassField> batchClassFieldList = new ArrayList<BatchClassField>();
    for (BatchClassFieldDTO batchClassFieldDTO : values) {
        BatchClassField batchClassField = new BatchClassField();
        batchClassField.setBatchClass(null);
        batchClassField.setDataType(batchClassFieldDTO.getDataType());
        batchClassField.setIdentifier(batchClassFieldDTO.getIdentifier());
        batchClassField.setName(batchClassFieldDTO.getName());
        batchClassField.setFieldOrderNumber(Integer.parseInt(batchClassFieldDTO.getFieldOrderNumber()));
        batchClassField.setDescription(batchClassFieldDTO.getDescription());
        batchClassField.setValidationPattern(batchClassFieldDTO.getValidationPattern());
        batchClassField.setSampleValue(batchClassFieldDTO.getSampleValue());
        batchClassField.setFieldOptionValueList(batchClassFieldDTO.getFieldOptionValueList());
        batchClassField.setValue(batchClassFieldDTO.getValue());
        batchClassFieldList.add(batchClassField);
    }
    try {
        BatchSchemaService batchSchemaService = this.getSingleBeanOfType(BatchSchemaService.class);
        String folderPath = batchSchemaService.getUploadBatchFolder() + File.separator + folderName;
        File currentBatchUploadFolder = new File(folderPath);
        if (!currentBatchUploadFolder.exists()) {
            currentBatchUploadFolder.mkdirs();
        }
        serializedExportFile = new File(folderPath + File.separator + BCF_SER_FILE_NAME + SERIALIZATION_EXT);
        fileOutputStream = new FileOutputStream(serializedExportFile);
        SerializationUtils.serialize(batchClassFieldList, fileOutputStream);
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.info("Error occurred while creating the serializable file." + e, e);
        throw new GWTException(e.getMessage());
    } finally {
        try {
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }

        } catch (Exception e) {
            if (serializedExportFile != null) {
                LOG.error("Problem closing stream for file :" + serializedExportFile.getName());
            }
        }
    }

}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for scanner config.
 * //ww w  .j  ava2 s  .c  o m
 * @param service {@link BatchClassService}
 * @param scannerConfigInfo {@link String}
 */
private static void createPatchForScannerConfig(BatchClassService service, String scannerConfigInfo) {
    String batchClassId = scannerConfigInfo.trim();
    BatchClass batchClass = service.getLoadedBatchClassByIdentifier(batchClassId);
    List<BatchClassScannerConfiguration> batchClassScannerConfigs = batchClass
            .getBatchClassScannerConfiguration();
    service.evict(batchClass);
    for (BatchClassScannerConfiguration scannerConfig : batchClassScannerConfigs) {
        if (scannerConfig.getParent() == null) {
            scannerConfig.setBatchClass(null);
            scannerConfig.setId(0);
            ScannerMasterConfiguration masterConfig = scannerConfig.getScannerMasterConfig();
            masterConfig.setId(0);
            scannerConfig.setScannerMasterConfig(masterConfig);
            for (BatchClassScannerConfiguration childScannerConfig : scannerConfig.getChildren()) {
                childScannerConfig.setParent(null);
                childScannerConfig.setBatchClass(null);
                childScannerConfig.setId(0);
                ScannerMasterConfiguration childMasterConfig = childScannerConfig.getScannerMasterConfig();
                childMasterConfig.setId(0);
                childScannerConfig.setScannerMasterConfig(childMasterConfig);
                LOG.info("Getting the child configs of parent scanner configs...");
            }
            LOG.info("Adding the parent scanner configs to the list...");
            batchClassScannerConfigList.add(scannerConfig);
        }
    }
    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "ScannerConfigUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize((Serializable) batchClassScannerConfigList,
                new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to create serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }

}

From source file:com.ephesoft.gxt.uploadbatch.server.UploadBatchServiceImpl.java

/**
 * This method is used to serialize the BatchClassField that is to be used in Web scanner module
 * /*from  w w  w .  jav  a2 s . com*/
 * @param folderName
 * @param values
 */

@Override
public void serializeBatchClassField(final String folderName, final List<BatchClassFieldDTO> values)
        throws UIException {
    FileOutputStream fileOutputStream = null;
    File serializedExportFile = null;
    final ArrayList<BatchClassField> batchClassFieldList = new ArrayList<BatchClassField>();
    for (final BatchClassFieldDTO batchClassFieldDTO : values) {
        final BatchClassField batchClassField = new BatchClassField();
        batchClassField.setBatchClass(null);
        batchClassField.setDataType(batchClassFieldDTO.getDataType());
        batchClassField.setIdentifier(batchClassFieldDTO.getIdentifier());
        batchClassField.setName(batchClassFieldDTO.getName());
        batchClassField.setFieldOrderNumber(batchClassFieldDTO.getFieldOrderNumber());
        batchClassField.setDescription(batchClassFieldDTO.getDescription());
        batchClassField.setValidationPattern(batchClassFieldDTO.getValidationPattern());
        batchClassField.setSampleValue(batchClassFieldDTO.getSampleValue());
        batchClassField.setFieldOptionValueList(batchClassFieldDTO.getFieldOptionValueList());
        batchClassField.setValue(batchClassFieldDTO.getValue());
        batchClassFieldList.add(batchClassField);
    }
    try {
        final BatchSchemaService batchSchemaService = this.getSingleBeanOfType(BatchSchemaService.class);
        final String folderPath = batchSchemaService.getUploadBatchFolder() + File.separator + folderName;
        final File currentBatchUploadFolder = new File(folderPath);
        if (!currentBatchUploadFolder.exists()) {
            currentBatchUploadFolder.mkdirs();
        }
        serializedExportFile = new File(folderPath + File.separator + BCF_SER_FILE_NAME + SERIALIZATION_EXT);
        fileOutputStream = new FileOutputStream(serializedExportFile);
        SerializationUtils.serialize(batchClassFieldList, fileOutputStream);
    } catch (final FileNotFoundException e) {
        // Unable to read serializable file
        log.info("Error occurred while creating the serializable file." + e, e);
        throw new UIException(e.getMessage());
    } finally {
        try {
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }

        } catch (final Exception e) {
            if (serializedExportFile != null)
                log.error("Problem closing stream for file :" + serializedExportFile.getName());
        }
    }

}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for batch class.
 * /*from   ww w  .j  ava 2  s .  c o m*/
 * @param service {@link BatchClassService}
 * @param batchClassInfo {@link String}
 */
private static void createPatchForBatchClass(BatchClassService service, String batchClassInfo) {
    StringTokenizer batchClassTokens = new StringTokenizer(batchClassInfo, DataAccessConstant.SEMI_COLON);
    while (batchClassTokens.hasMoreTokens()) {
        String batchClassName = batchClassTokens.nextToken();
        try {
            BatchClass createdBatchClass = createPatchForBatchClass(batchClassName, service);
            if (createdBatchClass != null) {
                batchClassNameVsBatchClassMap.put(createdBatchClass.getName(), createdBatchClass);
            }

        } catch (NoSuchElementException e) {
            LOG.error("Incomplete data specified in properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "BatchClassUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(batchClassNameVsBatchClassMap, new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }
}

From source file:gov.nih.nci.firebird.test.nes.NesTestDataLoader.java

private void serializeCache() {
    FileOutputStream fos = null;/*from  w  w w  . ja v a2  s.com*/
    try {
        fos = new FileOutputStream(getCacheFile());
        SerializationUtils.serialize(dataSource, fos);
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException(getCacheFile() + " not found", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}