logger.info("missingRemoteComponents:" + missingRemoteComponents);
Iterator missingRemoteComponentsIterator = missingRemoteComponents.iterator();
while(missingRemoteComponentsIterator.hasNext())
{
ContentVO missingRemoteContentVO = (ContentVO)missingRemoteComponentsIterator.next();
if(missingRemoteContentVO != null)
missingRemoteContentVO.setIsBranch(Boolean.FALSE);
logger.info("missingRemoteContentVO:" + missingRemoteContentVO + ":" + missingRemoteContentVO.getFullPath());
String fullPath = missingRemoteContentVO.getFullPath();
logger.info("fullPath:" + fullPath);
int siteNodeEnd = fullPath.indexOf(" - /");
String repositoryString = fullPath.substring(0, siteNodeEnd);
String restString = fullPath.substring(siteNodeEnd + 4);
restString = restString.substring(0, restString.lastIndexOf("/"));
if(restString.indexOf("/") > -1)
restString = restString.substring(restString.indexOf("/") + 1);
else
restString = "";
logger.info("repositoryString:" + repositoryString);
logger.info("restString:" + restString);
try
{
RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithName(repositoryString);
logger.info("repositoryVO:" + repositoryVO);
if(repositoryVO == null && components != null && components.size() > 0)
{
ContentVO contentVO = (ContentVO)components.get(0);
repositoryVO = RepositoryController.getController().getRepositoryVOWithId(contentVO.getRepositoryId());
logger.info("repositoryVO:" + repositoryVO);
}
if(repositoryVO != null)
{
LanguageVO languageVO = LanguageController.getController().getMasterLanguage(repositoryVO.getRepositoryId());
ContentVO parentContent = ContentController.getContentController().getContentVOWithPath(repositoryVO.getId(), restString, true, principal);
logger.info("parentContent:" + parentContent);
ContentVO newContentVO = ContentController.getContentController().create(parentContent.getId(), contentTypeDefinitionVO.getContentTypeDefinitionId(), parentContent.getRepositoryId(), missingRemoteContentVO);
logger.info("Now we want to create the version also on:" + newContentVO.getName());
ContentVersionVO contentVersionVO = new ContentVersionVO();
contentVersionVO.setVersionComment("deployment");
contentVersionVO.setVersionModifier(principal.getName());
logger.info("missingRemoteContentVO.getVersions():" + missingRemoteContentVO.getVersions());
if(missingRemoteContentVO.getVersions() != null && missingRemoteContentVO.getVersions().length > 0)
{
contentVersionVO.setVersionValue(missingRemoteContentVO.getVersions()[0]);
logger.info("Creating version on content: " + newContentVO.getId() + " in language: " + languageVO.getId());
ContentVersionController.getContentVersionController().create(newContentVO.getId(), languageVO.getId(), contentVersionVO, null);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
//Getting ready to handle deviating ones
List remoteComponents = (List)arguments.get("deviatingComponents");
logger.info("remoteComponents:" + remoteComponents);
Iterator remoteComponentsIterator = remoteComponents.iterator();
while(remoteComponentsIterator.hasNext())
{
ContentVO remoteContentVO = (ContentVO)remoteComponentsIterator.next();
logger.info("remoteContentVO:" + remoteContentVO + ":" + remoteContentVO.getFullPath());
if(remoteContentVO.getFullPath() != null && remoteContentVO.getFullPath().startsWith("deviatingRemoteVersionId="))
{
String remoteVersionId = remoteContentVO.getFullPath().substring(remoteContentVO.getFullPath().indexOf("=") + 1);
logger.info("Looking for version in remoteVersionId:" + remoteVersionId);
ContentVO contentVO = ContentControllerProxy.getController().getACContentVOWithId(principal, new Integer(remoteVersionId));
LanguageVO languageVO = LanguageController.getController().getMasterLanguage(contentVO.getRepositoryId());
ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentVO.getId(), languageVO.getId());
if(contentVersionVO != null)
{
if(remoteContentVO.getVersions() != null && remoteContentVO.getVersions().length > 0)
{
if(!contentVersionVO.getStateId().equals(0))
{
contentVersionVO = ContentStateController.changeState(contentVersionVO.getId(), ContentVersionVO.WORKING_STATE, "new working version: " + contentVersionVO.getVersionComment(), false, principal, contentVO.getId(), new ArrayList());
}
contentVersionVO.setVersionValue(remoteContentVO.getVersions()[0]);
logger.info("Updating :" + contentVersionVO.getContentName() + " with new latest versionValue:" + remoteContentVO.getVersions()[0].length());
contentVersionVO.setStateId(0);
if(remoteContentVO.getVersionComments().length > 0)
contentVersionVO.setVersionComment(remoteContentVO.getVersionComments()[0]);
ContentVersionController.getContentVersionController().update(contentVersionVO.getId(), contentVersionVO);
}
}
}
else
{
Iterator componentsIterator = components.iterator();
while(componentsIterator.hasNext())
{
ContentVO contentVO = (ContentVO)componentsIterator.next();
String fullPath = ContentController.getContentController().getContentPath(contentVO.getId(), true, true);
logger.info("fullPath:" + fullPath);
if(fullPath.equalsIgnoreCase(remoteContentVO.getFullPath()))
{
LanguageVO languageVO = LanguageController.getController().getMasterLanguage(contentVO.getRepositoryId());
ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentVO.getId(), languageVO.getId());
if(contentVersionVO != null)
{
if(remoteContentVO.getVersions() != null && remoteContentVO.getVersions().length > 0)
{
if(!contentVersionVO.getStateId().equals(0))
{
contentVersionVO = ContentStateController.changeState(contentVersionVO.getId(), ContentVersionVO.WORKING_STATE, "new working version: " + contentVersionVO.getVersionComment(), false, principal, contentVO.getId(), new ArrayList());
}
contentVersionVO.setVersionValue(remoteContentVO.getVersions()[0]);
logger.info("Updating :" + contentVersionVO.getContentName() + " with new latest versionValue:" + remoteContentVO.getVersions()[0].length());
contentVersionVO.setStateId(0);