diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/DomainObjectCopier.java b/ccm-ldn-util/src/com/arsdigita/london/util/DomainObjectCopier.java index 770de4de9..ccb2c896c 100755 --- a/ccm-ldn-util/src/com/arsdigita/london/util/DomainObjectCopier.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/DomainObjectCopier.java @@ -42,7 +42,7 @@ import java.util.Iterator; * Recursively copies a domain object. * * @author Justin Ross <jross@redhat.com> - * @version $Id: DomainObjectCopier.java 1942 2009-05-29 07:53:23Z terry $ + * @version $Id: DomainObjectCopier.java 2086 2010-04-12 09:55:35Z pboy $ */ public class DomainObjectCopier extends DomainService { diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/Initializer.java b/ccm-ldn-util/src/com/arsdigita/london/util/Initializer.java index f1b470239..78a2defc6 100755 --- a/ccm-ldn-util/src/com/arsdigita/london/util/Initializer.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/Initializer.java @@ -31,7 +31,7 @@ import org.apache.log4j.Logger; * The CMS initializer. * * @author Justin Ross <jross@redhat.com> - * @version $Id: Initializer.java 1942 2009-05-29 07:53:23Z terry $ + * @version $Id: Initializer.java 2086 2010-04-12 09:55:35Z pboy $ */ public class Initializer extends CompoundInitializer { diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/Loader.java b/ccm-ldn-util/src/com/arsdigita/london/util/Loader.java index bc3a79488..f8bba53ab 100755 --- a/ccm-ldn-util/src/com/arsdigita/london/util/Loader.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/Loader.java @@ -27,7 +27,7 @@ import org.apache.log4j.Logger; * Loader. * * @author Justin Ross <jross@redhat.com> - * @version $Id: Loader.java 1942 2009-05-29 07:53:23Z terry $ + * @version $Id: Loader.java 2086 2010-04-12 09:55:35Z pboy $ */ public class Loader extends PackageLoader { diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkDelete.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkDelete.java new file mode 100644 index 000000000..696a5b279 --- /dev/null +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkDelete.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package com.arsdigita.london.util.cmd; + +import com.arsdigita.london.util.Program; +import com.arsdigita.london.util.Transaction; +import com.arsdigita.persistence.CompoundFilter; +import com.arsdigita.persistence.Filter; +import com.arsdigita.persistence.FilterFactory; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.domain.DomainObjectFactory; + +import com.arsdigita.cms.ContentBundle; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.ItemCollection; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.log4j.Logger; + +import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; + +import java.math.BigDecimal; + + +public class BulkDelete extends BulkUnpublish { + + private static final Logger s_log = Logger.getLogger(BulkDelete.class); + + protected boolean deleteFolderStructure; + + public BulkDelete() { + super("Bulk Delete", "1.0.0"); + + Options options = getOptions(); + + options.addOption( + OptionBuilder + .hasArg(false) + .withLongOpt( "deletefolderstructure" ) + .withDescription( "Also delete empty folders (folders containing only folders)" ) + .create( "e" ) ); + + } + + protected void doRun(CommandLine cmdLine) { + //delete(new OID(ContentItem.BASE_DATA_OBJECT_TYPE, 13890351)); + + super.ignoreErrors = cmdLine.hasOption("i"); + this.deleteFolderStructure = cmdLine.hasOption("e"); + + if( cmdLine.hasOption( "t" ) ) { + super.types = cmdLine.getOptionValues( "t" ); + + System.out.println( "Deleting items of type:" ); + for( int i = 0; i < super.types.length; i++ ) { + System.out.println( super.types[i] ); + } + } else { + super.types = null; + System.out.println( "Deleting items without item type restriction" ); + } + if (cmdLine.hasOption("f")) { + super.folderId = Integer.parseInt(cmdLine.getOptionValue("f")); + Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE, super.folderId)); + System.out.println( "Deleting items in folder: " + folder.getDisplayName()); + + //Unpublish first + List toProcess = getListToProcess(ContentPage.BASE_DATA_OBJECT_TYPE); + unpublish(toProcess); + //Delete + toProcess = getListToProcess(ContentBundle.BASE_DATA_OBJECT_TYPE); + delete(toProcess); + + if(deleteFolderStructure) { + System.out.println("Deleting empty folders"); + deleteFolderStructure(); + } + + } else { + System.err.println("No folder specified."); + } + + } + + public static void main(String[] args) { + new BulkDelete().run(args); + } + + protected void delete(List toProcess) { + final Iterator items = toProcess.iterator(); + while (items.hasNext()) { + final OID oid = (OID) items.next(); + delete(oid); + } + } + + protected void delete(final OID oid) { + final boolean ignoreErrors = super.ignoreErrors; + + Transaction txn = new Transaction() { + public void doRun() { + ContentItem item = (ContentItem) + DomainObjectFactory.newInstance(oid); + System.out.println("Deleting item " + oid + " " + item.getPath()); + if (s_log.isInfoEnabled()) { + s_log.info("Deleting item " + oid + " " + item.getPath()); + } + if(item instanceof ContentBundle) { + ContentBundle bundle = (ContentBundle) item; + ItemCollection instances = bundle.getInstances(); + while (instances.next()) { + instances.getContentItem().delete(); + } + } + item.delete(); + } + }; + try { + txn.run(); + } catch (Throwable ex) { + s_log.error("Cannot delete " + oid, ex); + if (!ignoreErrors) { + return; + } + } + } + + protected void deleteFolderStructure() { + final Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE, super.folderId)); + + Transaction txn = new Transaction() { + public void doRun() { + deleteFolderStructure(folder); + } + }; + try { + txn.run(); + } catch (Throwable ex) { + s_log.error("Error deleting folders ", ex); + if (!ignoreErrors) { + return; + } + } + } + + protected void deleteFolderStructure(Folder folder) { + final ItemCollection itemCollection = folder.getItems(true); + + while(itemCollection.next()) { + ContentItem contentItem = itemCollection.getContentItem(); + + if(contentItem instanceof Folder) { + deleteFolderStructure((Folder) contentItem); + if ( ((Folder) contentItem).isEmpty() ) { + contentItem.delete(); + } + } + } + + } +} diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java index b212cde31..8aba5119a 100755 --- a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkPublish.java @@ -89,6 +89,10 @@ public class BulkPublish extends Program { } + /** + * + * @param cmdLine + */ protected void doRun(CommandLine cmdLine) { final String[] types; final String[] exceptions; diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java deleted file mode 100755 index b0e9617dd..000000000 --- a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/BulkUnpublish.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package com.arsdigita.london.util.cmd; - -import com.arsdigita.london.util.Program; -import com.arsdigita.london.util.Transaction; -import com.arsdigita.persistence.CompoundFilter; -import com.arsdigita.persistence.Filter; -import com.arsdigita.persistence.FilterFactory; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.SessionManager; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.domain.DomainObjectFactory; - -import com.arsdigita.cms.ContentPage; -import com.arsdigita.cms.ContentItem; -import com.arsdigita.cms.Folder; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.log4j.Logger; - -import java.util.List; -import java.util.ArrayList; -import java.util.Iterator; - -public class BulkUnpublish extends Program { - - private static final Logger s_log = Logger.getLogger(BulkUnpublish.class); - - private int folderId; - private String[] types; - private boolean ignoreErrors; - - public BulkUnpublish(String name, String version) { - super(name, version, ""); - - Options options = getOptions(); - - options.addOption( - OptionBuilder - .hasArgs() - .withLongOpt( "types" ) - .withDescription( "Restrict operation to items of the specified content types" ) - .create( "t" ) ); - options.addOption( - OptionBuilder - .hasArg() - .withLongOpt( "restrictToFolderId" ) - .withDescription( "Restrict operation to items within the folder with the specified id" ) - .create( "f" ) ); - - options.addOption - (OptionBuilder - .hasArg(false) - .withLongOpt("ignore-errors") - .withDescription("Ignore any errors") - .create('i')); - } - - protected void doRun(CommandLine cmdLine) { - this.ignoreErrors = cmdLine.hasOption("i"); - - if( cmdLine.hasOption( "t" ) ) { - this.types = cmdLine.getOptionValues( "t" ); - - System.out.println( "Unpublishing live items of types:" ); - for( int i = 0; i < this.types.length; i++ ) { - System.out.println( this.types[i] ); - } - } else { - this.types = null; - System.out.println( "Unpublishing all live items" ); - } - if (cmdLine.hasOption("f")) { - this.folderId = Integer.parseInt(cmdLine.getOptionValue("f")); - Folder folder = new Folder(new OID(Folder.BASE_DATA_OBJECT_TYPE, this.folderId)); - System.out.println( "Unpublishing items in folder: " + folder.getDisplayName()); - } else { - this.folderId = -1; - } - - final List toProcess = getListToProcess(true); - unpublish(toProcess); - } - - public static void main(String[] args) { - new BulkUnpublish("Bulk Unpublish","1.0.0").run(args); - } - - protected List getListToProcess(boolean liveOnly) { - final List toProcess = new ArrayList(); - - new Transaction() { - public void doRun() { - DataCollection items = SessionManager.getSession() - .retrieve(ContentPage.BASE_DATA_OBJECT_TYPE); - items.addNotEqualsFilter("type.id", null); - if(liveOnly) items.addEqualsFilter("version", ContentItem.LIVE); - items.addOrder("title"); - - FilterFactory filterFactory = items.getFilterFactory(); - - if (this.folderId >= 0) { - Filter filter = filterFactory.simple(" ancestors like '%/" + this.folderId + "/%'"); - items.addFilter(filter); - } - if( null != this.types ) { - CompoundFilter or = filterFactory.or(); - - for( int i = 0; i < this.types.length; i++ ) { - or.addFilter( filterFactory.equals( "objectType", this.types[i] ) ); - } - - items.addFilter( or ); - } - - while (items.next()) { - ContentPage page = (ContentPage) DomainObjectFactory.newInstance(items.getDataObject()); - toProcess.add(page.getDraftVersion().getOID()); - } - } - }.run(); - - return toProcess; - } - - protected void unpublish(List toProcess) { - final Iterator items = toProcess.iterator(); - while (items.hasNext()) { - final OID oid = (OID) items.next(); - unpublish(oid); - } - } - - protected void unpublish(OID oid) { - Transaction txn = new Transaction() { - public void doRun() { - ContentPage item = (ContentPage) - DomainObjectFactory.newInstance(oid); - if (s_log.isInfoEnabled()) { - s_log.info("Processing item " + oid + " " + item.getPath()); - } - item.setLive(null); - } - }; - try { - txn.run(); - } catch (Throwable ex) { - s_log.error("Cannot unpublish " + oid, ex); - if (!this.ignoreErrors) { - return; - } - } - } -} diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/ui/parameters/URLParameter.java b/ccm-ldn-util/src/com/arsdigita/london/util/ui/parameters/URLParameter.java index 742bc5b5e..884c57821 100755 --- a/ccm-ldn-util/src/com/arsdigita/london/util/ui/parameters/URLParameter.java +++ b/ccm-ldn-util/src/com/arsdigita/london/util/ui/parameters/URLParameter.java @@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletRequest; * check URL form, doesn't actually return a * java.net.URL object. * - * @version $Id: URLParameter.java 755 2005-09-02 13:42:47Z sskracic $ + * @version $Id: URLParameter.java 2086 2010-04-12 09:55:35Z pboy $ */ public class URLParameter extends ParameterModel {