public void moveSiteNode(SiteNodeVO siteNodeVO, Integer newParentSiteNodeId, InfoGluePrincipal principal) throws ConstraintException, SystemException
{
Database db = CastorDatabaseService.getDatabase();
ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
SiteNode siteNode = null;
SiteNode newParentSiteNode = null;
SiteNode oldParentSiteNode = null;
Map<String,String> pageUrls = new HashMap<String, String>();
beginTransaction(db);
try
{
//Validation that checks the entire object
siteNodeVO.validate();
if(newParentSiteNodeId == null)
{
logger.warn("You must specify the new parent-siteNode......");
throw new ConstraintException("SiteNode.parentSiteNodeId", "3403");
}
if(siteNodeVO.getId().intValue() == newParentSiteNodeId.intValue())
{
logger.warn("You cannot have the siteNode as it's own parent......");
throw new ConstraintException("SiteNode.parentSiteNodeId", "3401");
}
siteNode = getSiteNodeWithId(siteNodeVO.getSiteNodeId(), db);
oldParentSiteNode = siteNode.getParentSiteNode();
newParentSiteNode = getSiteNodeWithId(newParentSiteNodeId, db);
if(oldParentSiteNode.getId().intValue() == newParentSiteNodeId.intValue())
{
logger.warn("You cannot specify the same node as it originally was located in......");
throw new ConstraintException("SiteNode.parentSiteNodeId", "3404");
}
SiteNode tempSiteNode = newParentSiteNode.getParentSiteNode();
while(tempSiteNode != null)
{
if(tempSiteNode.getId().intValue() == siteNode.getId().intValue())
{
logger.warn("You cannot move the node to a child under it......");
throw new ConstraintException("SiteNode.parentSiteNodeId", "3402");
}
tempSiteNode = tempSiteNode.getParentSiteNode();
}
pageUrls = RedirectController.getController().getNiceURIMapBeforeMove(db, siteNodeVO.getRepositoryId(), siteNodeVO.getSiteNodeId(), principal);
logger.info("Setting the new Parent siteNode:" + siteNode.getSiteNodeId() + " " + newParentSiteNode.getSiteNodeId());