Map<Integer,List<Integer>> assetVersionsMap = new HashMap<Integer,List<Integer>>();
Map<String, AvailableServiceBinding> readAvailableServiceBindings = new HashMap<String, AvailableServiceBinding>();
Map<Integer,Language> languages = new HashMap<Integer,Language>();
Map<Integer,SiteNodeTypeDefinition> siteNodeTypeDefinitions = new HashMap<Integer,SiteNodeTypeDefinition>();
InfoGlueExportImpl master = getInfoGlueExportImpl(mainExportFile, encoding);
logger.info("master:" + master);
for(Language lang : master.getLanguages())
{
languages.put(lang.getId(), lang);
}
for(SiteNodeTypeDefinition siteNodeTypeDefinition : master.getSiteNodeTypeDefinitions())
{
siteNodeTypeDefinitions.put(siteNodeTypeDefinition.getId(), siteNodeTypeDefinition);
}
importFoundation(master, encoding, isCopyAction, replaceMap, categoryIdMap, repositoryIdMap);
processBean.updateProcess("Foundation imported in " + (t.getElapsedTime() / 1000) + " seconds");
createContent(archiveFolder, /*contentsFile, contentVersionsFile, */encoding, repositoryIdMap, master.getRepositories(), contentIdMap, contentTypeIdMap, allContents, languages, master.getContentTypeDefinitions(), categoryIdMap, allSmallAssets, assetVersionsMap, onlyLatestVersions, isCopyAction, replaceMap);
processBean.updateProcess("Content created in " + (t.getElapsedTime() / 1000) + " seconds");
CacheController.clearCastorCaches();
CacheController.clearCache("contentVersionCache");
CacheController.clearCache("contentCache");
processStructure(archiveFolder, /*siteNodeVersionsFile, siteNodesFile, */encoding, onlyLatestVersions, contentIdMap, siteNodeIdMap, replaceMap, repositoryIdMap, siteNodeVersionIdMap, allSiteNodes, readAvailableServiceBindings, master.getRepositories(), siteNodeTypeDefinitions);
processBean.updateProcess("Structure imported in " + (t.getElapsedTime() / 1000) + " seconds");
CacheController.clearCastorCaches();
CacheController.clearCache("siteNodeVersionCache");
CacheController.clearCache("siteNodeCache");
Database dbStructure = CastorDatabaseService.getDatabase();
try
{
dbStructure.begin();
for(SmallDigitalAssetImpl asset : allSmallAssets)
{
List<ContentVersion> assetRelatedContentVersions = new ArrayList<ContentVersion>();
List<Integer> versionIdsUsingAsset = assetVersionsMap.get(asset.getId());
for(Integer cvId : versionIdsUsingAsset)
{
ContentVersion cv = ContentVersionController.getContentVersionController().getContentVersionWithId(cvId, dbStructure);
assetRelatedContentVersions.add(cv);
}
File assetFile = new File(archiveFolder.getPath() + File.separator + asset.getId() + ".file");
//logger.info("assetFile:" + assetFile.exists());
if(assetFile.exists())
{
InputStream is = new FileInputStream(assetFile);
create(asset.getValueObject(), is, assetRelatedContentVersions, dbStructure);
}
else
{
logger.info("Missing file...:" + assetFile.getPath());
}
}
dbStructure.commit();
}
catch (Exception e)
{
dbStructure.rollback();
}
finally
{
dbStructure.close();
}
processBean.updateProcess("Assets imported in " + (t.getElapsedTime() / 1000) + " seconds");
CacheController.clearCastorCaches();
CacheController.clearCache("contentVersionCache");
CacheController.clearCache("contentCache");
//List allContentIds = new ArrayList();
Iterator allContentsIterator = allContents.iterator();
while(allContentsIterator.hasNext())
{
Content content = (Content)allContentsIterator.next();
allContentIds.add(content.getContentId());
}
//TEST
Map args = new HashMap();
args.put("globalKey", "infoglue");
PropertySet ps = PropertySetManager.getInstance("jdbc", args);
Map<String,String> repositoryProperties = master.getRepositoryProperties();
Iterator<String> repositoryPropertiesIterator = repositoryProperties.keySet().iterator();
while(repositoryPropertiesIterator.hasNext())
{
String key = repositoryPropertiesIterator.next();
String value = repositoryProperties.get(key);
String[] splittedString = key.split("_");
if(splittedString.length == 3)
{
String oldRepId = splittedString[1];
key = key.replaceAll(oldRepId, "" + repositoryIdMap.get(oldRepId));
if(value != null && !value.equals("null"))
{
try
{
if(key.indexOf("_WYSIWYGConfig") > -1 || key.indexOf("_StylesXML") > -1 || key.indexOf("_extraProperties") > -1)
ps.setData(key, value.getBytes("utf-8"));
else
ps.setString(key, value);
}
catch (Exception e)
{
logger.error("Error saving property " + key + ":" + e.getMessage());
}
}
}
}
Map<String,String> contentProperties = master.getContentProperties();
Iterator<String> contentPropertiesIterator = contentProperties.keySet().iterator();
while(contentPropertiesIterator.hasNext())
{
String key = contentPropertiesIterator.next();
String value = contentProperties.get(key);
String[] splittedString = key.split("_");
if(splittedString.length == 3)
{
String oldContentId = splittedString[1];
key = key.replaceAll(oldContentId, (String)contentIdMap.get(oldContentId));
try
{
if(value != null && !value.equals("null"))
ps.setString(key, value);
}
catch (Exception e)
{
logger.error("Error saving property " + key + ":" + e.getMessage());
}
}
}
Map<String,String> siteNodeProperties = master.getSiteNodeProperties();
Iterator<String> siteNodePropertiesIterator = siteNodeProperties.keySet().iterator();
while(siteNodePropertiesIterator.hasNext())
{
String key = siteNodePropertiesIterator.next();
String value = siteNodeProperties.get(key);
String[] splittedString = key.split("_");
if(splittedString.length == 3)
{
String oldSiteNodeId = splittedString[1];
key = key.replaceAll(oldSiteNodeId, (String)siteNodeIdMap.get(oldSiteNodeId));
try
{
if(value != null && !value.equals("null"))
ps.setString(key, value);
}
catch (Exception e)
{
logger.error("Error saving property " + key + ":" + e.getMessage());
}
}
}
processBean.updateProcess("Properties imported in " + (t.getElapsedTime() / 1000) + " seconds");
Database dbAccessRight = CastorDatabaseService.getDatabase();
try
{
dbAccessRight.begin();
Collection<AccessRight> accessRights = master.getAccessRights();
Iterator<AccessRight> accessRightsIterator = accessRights.iterator();
while(accessRightsIterator.hasNext())
{
AccessRight accessRight = accessRightsIterator.next();