@Override public void deleteContent(CopyToEnvironmentItem item) { PersistenceManagerService persistenceManagerService = _servicesManager.getService(PersistenceManagerService.class); String fullPath = SITE_ENVIRONMENT_ROOT_PATTERN.replaceAll(SITE_REPLACEMENT_PATTERN, item.getSite()); fullPath = fullPath.replaceAll(ENVIRONMENT_REPLACEMENT_PATTERN, WORK_AREA_REPOSITORY); fullPath = fullPath + item.getPath(); NodeRef nodeRef = persistenceManagerService.getNodeRef(fullPath); if (nodeRef != null) { // _dmContentService.deleteContent(site, path, true, true, null); // return; List<String> paths = new ArrayList<String>(); paths.add(item.getPath()); _dmContentService.generateDeleteActivity(item.getSite(), paths, item.getUser()); NodeRef parentNode = persistenceManagerService.getPrimaryParent(nodeRef).getParentRef(); persistenceManagerService.deleteNode(nodeRef); persistenceManagerService.deleteObjectState(nodeRef.getId()); List<FileInfo> children = persistenceManagerService.list(parentNode); while (children == null || children.size() < 1) { NodeRef helpNode = parentNode; parentNode = persistenceManagerService.getPrimaryParent(helpNode).getParentRef(); persistenceManagerService.deleteNode(helpNode); children = persistenceManagerService.list(parentNode); } } }
@Override public List<CopyToEnvironmentItem> processMandatoryDependencies( CopyToEnvironmentItem item, List<String> pathsToDeploy, Set<String> missingDependenciesPaths) throws DeploymentException { List<CopyToEnvironmentItem> mandatoryDependencies = new ArrayList<CopyToEnvironmentItem>(); String site = item.getSite(); String path = item.getPath(); if (item.getAction() == CopyToEnvironmentItem.Action.NEW || item.getAction() == CopyToEnvironmentItem.Action.MOVE) { String helpPath = path.replace("/" + _indexFile, ""); int idx = helpPath.lastIndexOf("/"); String parentPath = helpPath.substring(0, idx) + "/" + _indexFile; if (_contentRepository.isNew(site, parentPath) || _contentRepository.isRenamed(site, parentPath)) { String parentFullPath = _contentRepository.getFullPath(site, parentPath); if (!missingDependenciesPaths.contains(parentFullPath) && !pathsToDeploy.contains(parentFullPath)) { try { _deploymentDAL.cancelWorkflow(site, parentPath); } catch (DeploymentDALException e) { LOGGER.error( "Error while canceling workflow for path {0}, site {1}", e, site, parentPath); } missingDependenciesPaths.add(parentFullPath); CopyToEnvironmentItem parentItem = createMissingItem(site, parentPath, item); processItem(parentItem); mandatoryDependencies.add(parentItem); mandatoryDependencies.addAll( processMandatoryDependencies(parentItem, pathsToDeploy, missingDependenciesPaths)); } } List<String> dependentPaths = _contentRepository.getDependentPaths(site, path); for (String dependentPath : dependentPaths) { if (_contentRepository.isNew(site, dependentPath) || _contentRepository.isRenamed(site, dependentPath)) { String dependentFullPath = _contentRepository.getFullPath(site, dependentPath); if (!missingDependenciesPaths.contains(dependentFullPath) && !pathsToDeploy.contains(dependentFullPath)) { try { _deploymentDAL.cancelWorkflow(site, dependentPath); } catch (DeploymentDALException e) { LOGGER.error( "Error while canceling workflow for path {0}, site {1}", e, site, dependentPath); } missingDependenciesPaths.add(dependentFullPath); CopyToEnvironmentItem dependentItem = createMissingItem(site, dependentPath, item); processItem(dependentItem); mandatoryDependencies.add(dependentItem); mandatoryDependencies.addAll( processMandatoryDependencies( dependentItem, pathsToDeploy, missingDependenciesPaths)); } } } } return mandatoryDependencies; }
private CopyToEnvironmentItem createMissingItem( String site, String itemPath, CopyToEnvironmentItem item) { CopyToEnvironmentItem missingItem = new CopyToEnvironmentItem(); missingItem.setSite(site); missingItem.setEnvironment(item.getEnvironment()); missingItem.setPath(itemPath); missingItem.setScheduledDate(item.getScheduledDate()); missingItem.setState(item.getState()); if (_contentRepository.isNew(site, itemPath)) { missingItem.setAction(CopyToEnvironmentItem.Action.NEW); } if (_contentRepository.isRenamed(site, itemPath)) { String oldPath = _contentRepository.getOldPath(site, itemPath); missingItem.setOldPath(oldPath); missingItem.setAction(CopyToEnvironmentItem.Action.MOVE); } String contentTypeClass = _contentRepository.getContentTypeClass(site, itemPath); missingItem.setContentTypeClass(contentTypeClass); missingItem.setUser(item.getUser()); missingItem.setSubmissionComment(item.getSubmissionComment()); return missingItem; }
@Override public void processItem(CopyToEnvironmentItem item) throws DeploymentException { String liveEnvironment = _contentRepository.getLiveEnvironmentName(item.getSite()); boolean isLive = false; if (StringUtils.isNotEmpty(liveEnvironment)) { if (liveEnvironment.equals(item.getEnvironment())) { isLive = true; } } else if (LIVE_ENVIRONMENT.equalsIgnoreCase(item.getEnvironment()) || PRODUCTION_ENVIRONMENT.equalsIgnoreCase(item.getEnvironment())) { isLive = true; } if (item.getAction() == CopyToEnvironmentItem.Action.DELETE) { if (item.getOldPath() != null && item.getOldPath().length() > 0) { _contentRepository.deleteContent(item.getSite(), item.getEnvironment(), item.getOldPath()); _contentRepository.clearRenamed(item.getSite(), item.getPath()); } _contentRepository.deleteContent(item.getSite(), item.getEnvironment(), item.getPath()); if (isLive) { _contentRepository.deleteContent(item); } } else { _contentRepository.setSystemProcessing(item.getSite(), item.getPath(), true); if (isLive) { if (!_importModeEnabled) { _contentRepository.createNewVersion( item.getSite(), item.getPath(), item.getSubmissionComment(), true); } else { LOGGER.debug( "Import mode is ON. Create new version is skipped for [{0}] site \"{1}\"", item.getPath(), item.getSite()); } } if (item.getAction() == CopyToEnvironmentItem.Action.MOVE) { if (item.getOldPath() != null && item.getOldPath().length() > 0) { _contentRepository.deleteContent( item.getSite(), item.getEnvironment(), item.getOldPath()); if (isLive) { _contentRepository.clearRenamed(item.getSite(), item.getPath()); } } } _contentRepository.copyToEnvironment(item.getSite(), item.getEnvironment(), item.getPath()); if (isLive) { _contentRepository.stateTransition( item.getSite(), item.getPath(), TransitionEvent.DEPLOYMENT); } _contentRepository.setSystemProcessing(item.getSite(), item.getPath(), false); } }