diff --git a/dotCMS/src/main/java/com/dotcms/config/DotInitializationService.java b/dotCMS/src/main/java/com/dotcms/config/DotInitializationService.java index 54f86d200be7..7fa761c37c3b 100644 --- a/dotCMS/src/main/java/com/dotcms/config/DotInitializationService.java +++ b/dotCMS/src/main/java/com/dotcms/config/DotInitializationService.java @@ -2,6 +2,7 @@ import com.dotcms.api.system.event.PayloadVerifierFactoryInitializer; import com.dotcms.api.system.event.SystemEventProcessorFactoryInitializer; +import com.dotcms.publishing.PushPublishFiltersInitializer; import com.dotcms.rendering.velocity.events.ExceptionHandlersInitializer; import com.dotcms.system.event.local.business.LocalSystemEventSubscribersInitializer; import com.dotcms.util.ReflectionUtils; @@ -108,7 +109,7 @@ private Set getInternalInitializers() { new SystemEventProcessorFactoryInitializer(), new PayloadVerifierFactoryInitializer(), new LocalSystemEventSubscribersInitializer(), - new ExceptionHandlersInitializer()), + new ExceptionHandlersInitializer(), new PushPublishFiltersInitializer()); } // getInternalInitializers. diff --git a/dotCMS/src/main/java/com/dotcms/publisher/ajax/RemotePublishAjaxAction.java b/dotCMS/src/main/java/com/dotcms/publisher/ajax/RemotePublishAjaxAction.java index 8e1a743d86e7..27de32a2251b 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/ajax/RemotePublishAjaxAction.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/ajax/RemotePublishAjaxAction.java @@ -24,6 +24,7 @@ import com.dotcms.publishing.Publisher; import com.dotcms.publishing.PublisherConfig; import com.dotcms.publishing.PublisherConfig.DeliveryStrategy; +import com.dotmarketing.util.*; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileUploadException; @@ -43,12 +44,6 @@ import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.portlets.workflows.model.WorkflowActionFailureException; import com.dotmarketing.servlets.ajax.AjaxAction; -import com.dotmarketing.util.ConfigUtils; -import com.dotmarketing.util.FileUtil; -import com.dotmarketing.util.InodeUtils; -import com.dotmarketing.util.Logger; -import com.dotmarketing.util.UtilMethods; -import com.dotmarketing.util.WebKeys; import com.dotmarketing.util.json.JSONArray; import com.dotmarketing.util.json.JSONException; import com.dotmarketing.util.json.JSONObject; diff --git a/dotCMS/src/main/java/com/dotcms/publisher/bundle/bean/Bundle.java b/dotCMS/src/main/java/com/dotcms/publisher/bundle/bean/Bundle.java index cc5f032d3f21..c10cf745743d 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/bundle/bean/Bundle.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/bundle/bean/Bundle.java @@ -1,5 +1,7 @@ package com.dotcms.publisher.bundle.bean; +import com.dotmarketing.util.Config; + import java.util.Date; public class Bundle { diff --git a/dotCMS/src/main/java/com/dotcms/publisher/bundle/business/BundleFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/publisher/bundle/business/BundleFactoryImpl.java index 2023fb3334ae..53eccb68e713 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/bundle/business/BundleFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/bundle/business/BundleFactoryImpl.java @@ -28,6 +28,7 @@ public void saveBundle(Bundle bundle) throws DotDataException { dc.addParam(bundle.getExpireDate()); dc.addParam(bundle.getOwner()); dc.addParam(bundle.isForcePush()); + dc.addParam(bundle.getFilterKey()); dc.loadResult(); } @@ -163,6 +164,7 @@ public void updateBundle(Bundle bundle) throws DotDataException { dc.addParam(bundle.getPublishDate()); dc.addParam(bundle.getExpireDate()); dc.addParam(bundle.isForcePush()); + dc.addParam(bundle.getFilterKey()); dc.addParam(bundle.getId()); dc.loadResult(); diff --git a/dotCMS/src/main/java/com/dotcms/publisher/util/DependencyManager.java b/dotCMS/src/main/java/com/dotcms/publisher/util/DependencyManager.java index 722292a9a9e8..d2f07946e732 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/util/DependencyManager.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/util/DependencyManager.java @@ -8,6 +8,7 @@ import com.dotcms.publisher.pusher.PushPublisherConfig.AssetTypes; import com.dotcms.publishing.DotBundleException; import com.dotcms.publishing.PublisherConfig.Operation; +import com.dotcms.publishing.PublisherFilter; import com.dotmarketing.beans.ContainerStructure; import com.dotmarketing.beans.Host; import com.dotmarketing.beans.Identifier; @@ -76,7 +77,7 @@ * The Dependency Manager analyzes the type of each asset to push and includes * dependent information in the bundle. This way, it can be seen by users * exactly the same in both the sender and receiver servers. - * + * * @author Daniel Silva * @version 1.0 * @since Jan 11, 2013 @@ -84,31 +85,31 @@ */ public class DependencyManager { - private DependencySet hosts; - private DependencySet folders; - private DependencySet htmlPages; - private DependencySet templates; - private DependencySet structures; - private DependencySet containers; - private DependencySet contents; - private DependencySet links; - private DependencySet relationships; - private DependencySet workflows; - private DependencySet languages; - private DependencySet rules; - private DependencySet categories; - - private Set hostsSet; - private Set foldersSet; - private Set htmlPagesSet; - private Set templatesSet; - private Set structuresSet; - private Set containersSet; - private Set fileAssetContainersSet; - private Set contentsSet; - private Set linksSet; - private Set ruleSet; - private Set solvedStructures; + private final DependencySet hosts; + private final DependencySet folders; + private final DependencySet htmlPages; + private final DependencySet templates; + private final DependencySet contentTypes; + private final DependencySet containers; + private final DependencySet contents; + private final DependencySet links; + private final DependencySet relationships; + private final DependencySet workflows; + private final DependencySet languages; + private final DependencySet rules; + private final DependencySet categories; + + private final Set hostsSet; + private final Set foldersSet; + private final Set htmlPagesSet; + private final Set templatesSet; + private Set contentTypesSet; + private final Set containersSet; + private final Set fileAssetContainersSet; + private final Set contentsSet; + private final Set linksSet; + private final Set ruleSet; + private final Set solvedContentTypes; private User user; @@ -132,7 +133,7 @@ public DependencyManager(User user, PushPublisherConfig config) { folders = new DependencySet(config.getId(), "folder", config.isDownloading(), isPublish, config.isStatic()); htmlPages = new DependencySet(config.getId(), "htmlpage", config.isDownloading(), isPublish, config.isStatic()); templates = new DependencySet(config.getId(), "template", config.isDownloading(), isPublish, config.isStatic()); - structures = new DependencySet(config.getId(), "structure", config.isDownloading(), isPublish, config.isStatic()); + contentTypes = new DependencySet(config.getId(), "contenttype", config.isDownloading(), isPublish, config.isStatic()); containers = new DependencySet(config.getId(), "container", config.isDownloading(), isPublish, config.isStatic()); contents = new DependencySet(config.getId(), "content", config.isDownloading(), isPublish, config.isStatic()); relationships = new DependencySet(config.getId(), "relationship", config.isDownloading(), isPublish, config.isStatic()); @@ -147,13 +148,13 @@ public DependencyManager(User user, PushPublisherConfig config) { foldersSet = new HashSet<>(); htmlPagesSet = new HashSet<>(); templatesSet = new HashSet<>(); - structuresSet = new HashSet<>(); + contentTypesSet = new HashSet<>(); containersSet = new HashSet<>(); contentsSet = new HashSet<>(); fileAssetContainersSet = new HashSet<>(); linksSet = new HashSet<>(); this.ruleSet = new HashSet<>(); - solvedStructures = new HashSet<>(); + solvedContentTypes = new HashSet<>(); this.user = user; @@ -163,7 +164,7 @@ public DependencyManager(User user, PushPublisherConfig config) { * Initializes the main mechanism to search for dependencies. It starts with * the identification of the type of assets in the queue, and their * dependencies will be searched and found base on those types. - * + * * @throws DotSecurityException * The specified user does not have the required permissions to * perform the action. @@ -176,7 +177,15 @@ public DependencyManager(User user, PushPublisherConfig config) { public void setDependencies() throws DotSecurityException, DotDataException, DotBundleException { List assets = config.getAssets(); + + final PublisherFilter publisherFilter = APILocator.getPublisherAPI().createPublisherFilter(config.getId()); + Logger.info(this,publisherFilter.toString()); for (PublishQueueElement asset : assets) { + //Check if the asset.Type is in the excludeClasses filter, if it is, the asset is not added to the bundle + if(publisherFilter.doesExcludeClassesContainsType(asset.getType())){ + continue; + } + if(asset.getType().equals(PusheableAsset.CONTENT_TYPE.getType())) { try { Structure st = CacheLocator.getContentTypeCache().getStructureByInode(asset.getAsset()); @@ -184,8 +193,8 @@ public void setDependencies() throws DotSecurityException, DotDataException, Dot if(st == null) { Logger.warn(getClass(), "Structure id: "+ (asset.getAsset() != null ? asset.getAsset() : "N/A") +" does NOT have working or live version, not Pushed"); } else { - structures.add(asset.getAsset(), st.getModDate()); - structuresSet.add(asset.getAsset()); + contentTypes.add(asset.getAsset(), st.getModDate()); + contentTypesSet.add(asset.getAsset()); } } catch (Exception e) { @@ -217,11 +226,11 @@ public void setDependencies() throws DotSecurityException, DotDataException, Dot c = APILocator.getContainerAPI().getWorkingContainerById(asset.getAsset(), user, false); } - if(c instanceof FileAssetContainer){ - Logger.debug(getClass(), "FileAssetContainer id: "+ (asset.getAsset() != null ? asset.getAsset() : "N/A") +" will be ignored"); - fileAssetContainersSet.add(asset.getAsset()); - continue; - } + if(c instanceof FileAssetContainer){ + Logger.debug(getClass(), "FileAssetContainer id: "+ (asset.getAsset() != null ? asset.getAsset() : "N/A") +" will be ignored"); + fileAssetContainersSet.add(asset.getAsset()); + continue; + } if(c == null) { Logger.warn(getClass(), "Container id: "+ (asset.getAsset() != null ? asset.getAsset() : "N/A") +" does NOT have working or live version, not Pushed"); @@ -293,7 +302,7 @@ public void setDependencies() throws DotSecurityException, DotDataException, Dot if (language == null || !UtilMethods.isSet(language.getLanguage())) { Logger.warn(getClass(), "Language id: " + (asset.getAsset() != null ? asset.getAsset() - : "N/A") + : "N/A") + " is not present in the database, not Pushed"); } else { languages.add(asset.getAsset()); @@ -307,7 +316,7 @@ public void setDependencies() throws DotSecurityException, DotDataException, Dot } else { Logger.warn(getClass(), "Rule id: " + (asset.getAsset() != null ? asset.getAsset() - : "N/A") + : "N/A") + " is not present in the database, not Pushed."); } } @@ -318,29 +327,33 @@ public void setDependencies() throws DotSecurityException, DotDataException, Dot for(String id : contentIds){ List contentlets = APILocator.getContentletAPI().search("+identifier:"+id, 0, 0, "moddate", user, false); for(Contentlet con : contentlets){ - contents.add( con.getIdentifier(), con.getModDate()); - contentsSet.add(con.getIdentifier()); + if(!publisherFilter.doesExcludeQueryContainsContentletId(con.getIdentifier())) { + contents.add(con.getIdentifier(), con.getModDate()); + contentsSet.add(con.getIdentifier()); + } } } } - setHostDependencies(); - setFolderDependencies(); - setHTMLPagesDependencies(); - setTemplateDependencies(); - setContainerDependencies(); - setStructureDependencies(); - setLinkDependencies(); - setLanguageDependencies(); - setContentDependencies(); - setRuleDependencies(); + if(publisherFilter.isDependencies()){ + setHostDependencies(publisherFilter); + setFolderDependencies(publisherFilter); + setHTMLPagesDependencies(publisherFilter); + setTemplateDependencies(publisherFilter); + setContainerDependencies(publisherFilter); + setStructureDependencies(publisherFilter); + setLinkDependencies(publisherFilter); + setLanguageDependencies(publisherFilter); + setContentDependencies(publisherFilter); + setRuleDependencies(publisherFilter); + } config.setHostSet(hosts); config.setFolders(folders); config.setHTMLPages(htmlPages); config.setTemplates(templates); config.setContainers(containers); - config.setStructures(structures); + config.setStructures(contentTypes); config.setContents(contents); config.setLinks(links); config.setRelationships(relationships); @@ -357,35 +370,55 @@ public void setDependencies() throws DotSecurityException, DotDataException, Dot *
  • Folders
  • * */ - private void setLinkDependencies() { + private void setLinkDependencies(final PublisherFilter publisherFilter) { for(String linkId : linksSet) { try { Identifier ident=APILocator.getIdentifierAPI().find(linkId); - Folder ff = APILocator.getFolderAPI().findFolderByPath(ident.getParentPath(), ident.getHostId(), user, false); - folders.addOrClean( ff.getInode(), ff.getModDate()); - foldersSet.add(ff.getInode()); - Host hh=APILocator.getHostAPI().find(ident.getHostId(), user, false); - hosts.addOrClean( hh.getIdentifier(), hh.getModDate()); - hostsSet.add(hh.getIdentifier()); + // Folder Dependencies + if(!publisherFilter.doesExcludeDependencyClassesContainsType(PusheableAsset.FOLDER.getType())) { + final Folder folder = APILocator.getFolderAPI() + .findFolderByPath(ident.getParentPath(), ident.getHostId(), user, + false); + folders.addOrClean(folder.getInode(), folder.getModDate()); + foldersSet.add(folder.getInode()); + } - Link link = APILocator.getMenuLinkAPI().findWorkingLinkById(linkId, user, false); + // Host Dependencies + if(!publisherFilter.doesExcludeDependencyClassesContainsType(PusheableAsset.SITE.getType())) { + final Host host = APILocator.getHostAPI().find(ident.getHostId(), user, false); + hosts.addOrClean(host.getIdentifier(), host.getModDate()); + hostsSet.add(host.getIdentifier()); + } - if(link!=null) { + // Content Dependencies + if(!publisherFilter.doesExcludeDependencyClassesContainsType(PusheableAsset.CONTENTLET.getType())) { + final Link link = APILocator.getMenuLinkAPI() + .findWorkingLinkById(linkId, user, false); - if(link.getLinkType().equals(Link.LinkType.INTERNAL.toString())) { - Identifier id = APILocator.getIdentifierAPI().find(link.getInternalLinkIdentifier()); + if (link != null) { - // add file/content dependencies. will also work with htmlpages as content - if (InodeUtils.isSet(id.getInode()) && id.getAssetType().equals("contentlet")) { - List contentList = APILocator.getContentletAPI().search("+identifier:"+id.getId(), 0, 0, "moddate", user, false); + if (link.getLinkType().equals(Link.LinkType.INTERNAL.toString())) { + final Identifier id = APILocator.getIdentifierAPI() + .find(link.getInternalLinkIdentifier()); - for (Contentlet contentlet : contentList) { - contents.addOrClean(contentlet.getIdentifier(), contentlet.getModDate()); - contentsSet.add(contentlet.getIdentifier()); - } + // add file/content dependencies. will also work with htmlpages as content + if (InodeUtils.isSet(id.getInode()) && id.getAssetType() + .equals("contentlet")) { + final List contentList = APILocator.getContentletAPI() + .search("+identifier:" + id.getId(), 0, 0, "moddate", user, + false); + for (final Contentlet contentlet : contentList) { + if(!publisherFilter.doesExcludeDependencyQueryContainsContentletId(contentlet.getIdentifier())) { + contents.addOrClean(contentlet.getIdentifier(), + contentlet.getModDate()); + contentsSet.add(contentlet.getIdentifier()); + } + } + + } } } } @@ -408,58 +441,79 @@ private void setLinkDependencies() { *
  • Rules.
  • * */ - private void setHostDependencies () { + private void setHostDependencies (final PublisherFilter publisherFilter) { try { - for (String id : hostsSet) { - final Host h = APILocator.getHostAPI().find(id, user, false); + for (final String hostId : hostsSet) { + final Host host = APILocator.getHostAPI().find(hostId, user, false); // Template dependencies - final List