Integer originalSiteNodeId = siteNode.getSiteNodeId();
logger.info("originalSiteNodeId:" + originalSiteNodeId);
SiteNodeTypeDefinition originalSiteNodeTypeDefinition = siteNode.getSiteNodeTypeDefinition();
SiteNodeTypeDefinition siteNodeTypeDefinition = null;
if(originalSiteNodeTypeDefinition != null)
{
logger.info("originalSiteNodeTypeDefinition:" + originalSiteNodeTypeDefinition);
siteNodeTypeDefinition = SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionWithName(siteNode.getSiteNodeTypeDefinition().getName(), db, false);
logger.info("siteNodeTypeDefinition:" + siteNodeTypeDefinition);
if(siteNodeTypeDefinition == null)
{
db.create(originalSiteNodeTypeDefinition);
siteNodeTypeDefinition = originalSiteNodeTypeDefinition;
}
siteNode.setSiteNodeTypeDefinition((SiteNodeTypeDefinitionImpl)siteNodeTypeDefinition);
}
String mappedMetaInfoContentId = "-1";
if(siteNode.getMetaInfoContentId() != null)
{
if(contentIdMap.containsKey(siteNode.getMetaInfoContentId().toString()))
mappedMetaInfoContentId = (String)contentIdMap.get(siteNode.getMetaInfoContentId().toString());
}
siteNode.setMetaInfoContentId(new Integer(mappedMetaInfoContentId));
siteNode.setName(substituteStrings(siteNode.getName(), replaceMap));
db.create(siteNode);
allSiteNodes.add(siteNode);
Integer newSiteNodeId = siteNode.getSiteNodeId();
logger.info(originalSiteNodeId + ":" + newSiteNodeId);
siteNodeIdMap.put(originalSiteNodeId.toString(), newSiteNodeId.toString());
Collection childSiteNodes = siteNode.getChildSiteNodes();
if(childSiteNodes != null)
{
Iterator childSiteNodesIterator = childSiteNodes.iterator();
while(childSiteNodesIterator.hasNext())
{
SiteNode childSiteNode = (SiteNode)childSiteNodesIterator.next();
childSiteNode.setRepository(siteNode.getRepository());
childSiteNode.setParentSiteNode((SiteNodeImpl)siteNode);
createStructure(childSiteNode, contentIdMap, siteNodeIdMap, siteNodeVersionIdMap, readAvailableServiceBindings, allSiteNodes, db, onlyLatestVersions, replaceMap);
}
}
Collection siteNodeVersions = siteNode.getSiteNodeVersions();
if(onlyLatestVersions.equalsIgnoreCase("true"))
{
logger.info("org siteNodeVersions:" + siteNodeVersions.size());
List selectedSiteNodeVersions = new ArrayList();
Iterator realSiteNodeVersionsIterator = siteNodeVersions.iterator();
while(realSiteNodeVersionsIterator.hasNext())
{
SiteNodeVersion siteNodeVersion = (SiteNodeVersion)realSiteNodeVersionsIterator.next();
Iterator selectedSiteNodeVersionsIterator = selectedSiteNodeVersions.iterator();
boolean addVersion = true;
while(selectedSiteNodeVersionsIterator.hasNext())
{
SiteNodeVersion currentSiteNodeVersion = (SiteNodeVersion)selectedSiteNodeVersionsIterator.next();
if(siteNodeVersion.getIsActive().booleanValue() && siteNodeVersion.getSiteNodeVersionId().intValue() > currentSiteNodeVersion.getSiteNodeVersionId().intValue())
{
logger.info("A later version was found... removing this one..");
selectedSiteNodeVersionsIterator.remove();
addVersion = true;
}
}
if(addVersion)
selectedSiteNodeVersions.add(siteNodeVersion);
}
siteNodeVersions = selectedSiteNodeVersions;
}
Iterator siteNodeVersionsIterator = siteNodeVersions.iterator();
while(siteNodeVersionsIterator.hasNext())
{
SiteNodeVersion siteNodeVersion = (SiteNodeVersion)siteNodeVersionsIterator.next();
Collection serviceBindings = siteNodeVersion.getServiceBindings();
siteNodeVersion.setOwningSiteNode((SiteNodeImpl)siteNode);
Integer oldSiteNodeVersionId = siteNodeVersion.getId();
db.create(siteNodeVersion);
Integer newSiteNodeVersionId = siteNodeVersion.getId();
siteNodeVersionIdMap.put(oldSiteNodeVersionId.toString(), newSiteNodeVersionId.toString());
Iterator serviceBindingsIterator = serviceBindings.iterator();
while(serviceBindingsIterator.hasNext())
{
ServiceBinding serviceBinding = (ServiceBinding)serviceBindingsIterator.next();
logger.info("serviceBinding:" + serviceBinding.getName());
ServiceDefinition originalServiceDefinition = serviceBinding.getServiceDefinition();
if(originalServiceDefinition == null)
{
logger.error("Skipping serviceBinding:" + serviceBinding.getName() + ":" + "serviceBinding:" + serviceBinding.getId() + " " + serviceBinding.getServiceDefinition());
continue;
}
String serviceDefinitionName = originalServiceDefinition.getName();
ServiceDefinition serviceDefinition = ServiceDefinitionController.getController().getServiceDefinitionWithName(serviceDefinitionName, db, false);
if(serviceDefinition == null)
{
db.create(originalServiceDefinition);
serviceDefinition = originalServiceDefinition;
//availableServiceBinding.getServiceDefinitions().add(serviceDefinition);
}
serviceBinding.setServiceDefinition((ServiceDefinitionImpl)serviceDefinition);
AvailableServiceBinding originalAvailableServiceBinding = serviceBinding.getAvailableServiceBinding();
String availableServiceBindingName = originalAvailableServiceBinding.getName();
logger.info("availableServiceBindingName:" + availableServiceBindingName);
logger.info("readAvailableServiceBindings:" + readAvailableServiceBindings.size() + ":" + readAvailableServiceBindings.containsKey(availableServiceBindingName));
AvailableServiceBinding availableServiceBinding = (AvailableServiceBinding)readAvailableServiceBindings.get(availableServiceBindingName);
logger.info("availableServiceBinding:" + availableServiceBinding);
if(availableServiceBinding == null)
{
availableServiceBinding = AvailableServiceBindingController.getController().getAvailableServiceBindingWithName(availableServiceBindingName, db, false);
logger.info("Read availableServiceBinding from database:" + availableServiceBindingName + "=" + availableServiceBinding);
readAvailableServiceBindings.put(availableServiceBindingName, availableServiceBinding);
logger.info("readAvailableServiceBindings:" + readAvailableServiceBindings.size() + ":" + readAvailableServiceBindings.containsKey(availableServiceBindingName));
}
if(availableServiceBinding == null)
{
logger.info("There was no availableServiceBinding registered under:" + availableServiceBindingName);
logger.info("originalAvailableServiceBinding:" + originalAvailableServiceBinding.getName() + ":" + originalAvailableServiceBinding.getIsInheritable());
db.create(originalAvailableServiceBinding);
availableServiceBinding = originalAvailableServiceBinding;
readAvailableServiceBindings.put(availableServiceBindingName, availableServiceBinding);
logger.info("Notifying:" + siteNodeTypeDefinition.getName() + " about the new availableServiceBinding " + availableServiceBinding.getName());
if(siteNodeTypeDefinition != null)
{
siteNodeTypeDefinition.getAvailableServiceBindings().add((AvailableServiceBindingImpl)availableServiceBinding);
serviceDefinition.getAvailableServiceBindings().add((AvailableServiceBindingImpl)availableServiceBinding);
availableServiceBinding.getSiteNodeTypeDefinitions().add((SiteNodeTypeDefinitionImpl)siteNodeTypeDefinition);
availableServiceBinding.getServiceDefinitions().add((ServiceDefinitionImpl)serviceDefinition);
}
}
else
{
if(siteNodeTypeDefinition != null && !siteNodeTypeDefinition.getAvailableServiceBindings().contains(availableServiceBinding))
{
siteNodeTypeDefinition.getAvailableServiceBindings().add((AvailableServiceBindingImpl)availableServiceBinding);
availableServiceBinding.getSiteNodeTypeDefinitions().add(siteNodeTypeDefinition);
}
}
serviceBinding.setAvailableServiceBinding((AvailableServiceBindingImpl)availableServiceBinding);