From e11267a809053428607b1a92520ae9f393131afe Mon Sep 17 00:00:00 2001 From: tosmers Date: Mon, 15 Jun 2015 13:22:25 +0000 Subject: [PATCH] [UPDATE] Angefangen, das Problem mit den Initalizern beim unload zu beseitigen. git-svn-id: https://svn.libreccm.org/ccm/trunk@3484 8810af33-2d31-482b-a856-94f89814c4df --- .../AbstractContentTypeLoader.java | 1 - .../AbstractContentTypeUnloader.java | 6 +--- .../cms/contenttypes/ContentTypeHelper.java | 6 +++- .../contenttypes/ContentTypeHelperImpl.java | 7 ++++ .../contenttypes/XMLContentTypeHandler.java | 24 ++++++++++--- .../src/com/arsdigita/packaging/Load.java | 8 +++-- .../com/arsdigita/packaging/LoadCenter.java | 3 +- .../packaging/LoadCenterDelegate.java | 34 +++++++++++++------ .../src/com/arsdigita/packaging/Loader.java | 13 ++++--- .../src/com/arsdigita/packaging/Unload.java | 10 +++--- .../arsdigita/persistence/DataObjectImpl.java | 5 ++- 11 files changed, 78 insertions(+), 39 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java index 257509491..828b22361 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java @@ -107,7 +107,6 @@ public abstract class AbstractContentTypeLoader extends PackageLoader { * @param ctx The context to the unload-script */ private void createTypes(ScriptContext ctx) { - XMLContentTypeHandler handler = new XMLContentTypeHandler(); // Retrieve the content type definition file(s) String[] contentTypes = getTypes(); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeUnloader.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeUnloader.java index 51a936b18..28a4c8adc 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeUnloader.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeUnloader.java @@ -83,7 +83,7 @@ public abstract class AbstractContentTypeUnloader extends PackageLoader { * @param ctx The context to the unload-script */ private void sweepTypes(ScriptContext ctx) { - XMLContentTypeHandler handler = new XMLContentTypeHandler(); + XMLContentTypeHandler handler = new XMLContentTypeHandler(false); // Retrieve the content type definition file(s) String[] contentTypes = getTypes(); for (String contentType : contentTypes) { @@ -130,10 +130,6 @@ public abstract class AbstractContentTypeUnloader extends PackageLoader { for (Iterator it = types.iterator(); it.hasNext();) { final ContentType type = (ContentType) it.next(); section.removeContentType(type); - //section.removeNotAssociatedContentTypes(type); - // necessary?? - //type.getAuthoringKit().delete(); - //type.delete(); } } } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelper.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelper.java index c7b88d0ea..f074c7994 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelper.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelper.java @@ -24,6 +24,8 @@ import com.arsdigita.cms.ContentType; import java.math.BigDecimal; public interface ContentTypeHelper { + + public void setName(String name) ; /** @deprecated */ public void setLabel(String label) ; @@ -90,5 +92,7 @@ public interface ContentTypeHelper { String component, BigDecimal ordering) ; - public void saveType(); + public void saveType(); + + public void deleteType(); } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelperImpl.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelperImpl.java index 40e25f076..ece37f670 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelperImpl.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ContentTypeHelperImpl.java @@ -329,10 +329,17 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { m_type.save(); } + @Override public void saveType() { m_kit.save(); m_type.save(); } + + @Override + public void deleteType() { + m_kit.delete(); + m_type.delete(); + } /** * Generates the pedigree for this content type diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/XMLContentTypeHandler.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/XMLContentTypeHandler.java index e50f15d0f..0d0949633 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/XMLContentTypeHandler.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/XMLContentTypeHandler.java @@ -20,7 +20,6 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.cms.AuthoringKit; import com.arsdigita.cms.ContentType; -import com.arsdigita.cms.contenttypes.ContentTypeInitializer; import com.arsdigita.xml.XML; import org.apache.log4j.Logger; @@ -48,7 +47,16 @@ public class XMLContentTypeHandler extends DefaultHandler { private AuthoringKit m_authoringKit; private int m_nextOrder; private boolean m_including; - + private boolean create; + + public XMLContentTypeHandler() { + this.create = true; + } + + public XMLContentTypeHandler(boolean create) { + this.create = create; + } + public List getContentTypes() { return m_types; } @@ -135,9 +143,15 @@ public class XMLContentTypeHandler extends DefaultHandler { String qName, Attributes atts) { if (name.equals("content-type")) { // reset the helper - m_contentType.save(); - m_authoringKit.save(); - m_type.saveType(); + if (create) { + m_contentType.save(); + m_authoringKit.save(); + m_type.saveType(); + } else { + m_contentType.delete(); + m_authoringKit.delete(); + m_type.deleteType(); + } m_type = null; } } diff --git a/ccm-core/src/com/arsdigita/packaging/Load.java b/ccm-core/src/com/arsdigita/packaging/Load.java index e75cc86a5..cddbc17a4 100755 --- a/ccm-core/src/com/arsdigita/packaging/Load.java +++ b/ccm-core/src/com/arsdigita/packaging/Load.java @@ -657,7 +657,8 @@ class Load extends Command implements LoadCenter { boolean success = true; if (PackageLoader.exists(conn, "inits") && (line.hasOption("init") || all)) { - success = checkInitializerDependencies(loaders, "loader"); + success = checkInitializerDependencies(loaders, "loader", + LoadType.LOAD); } return success; } @@ -671,12 +672,13 @@ class Load extends Command implements LoadCenter { * @param loaders A list of loaders to the corresponding packages * to-be-loaded * @param sessionName Name of the session + * @param type The load-type * @return true on success, otherwise false */ @Override public boolean checkInitializerDependencies(final Loader[] loaders, - String sessionName) { - return delegate.checkInitializerDependencies(loaders, sessionName); + String sessionName, LoadType type) { + return delegate.checkInitializerDependencies(loaders, sessionName, type); } /** diff --git a/ccm-core/src/com/arsdigita/packaging/LoadCenter.java b/ccm-core/src/com/arsdigita/packaging/LoadCenter.java index 463bc755a..70f9a7d0b 100644 --- a/ccm-core/src/com/arsdigita/packaging/LoadCenter.java +++ b/ccm-core/src/com/arsdigita/packaging/LoadCenter.java @@ -99,9 +99,10 @@ public interface LoadCenter { * @param loaders A list of loaders to the corresponding packages * to-be-loaded * @param sessionName Name of the session + * @param type The load-type * @return true on success, otherwise false */ boolean checkInitializerDependencies(final Loader[] loaders, - String sessionName); + String sessionName, LoadType type); } diff --git a/ccm-core/src/com/arsdigita/packaging/LoadCenterDelegate.java b/ccm-core/src/com/arsdigita/packaging/LoadCenterDelegate.java index 27f53d3de..fa6cf3252 100644 --- a/ccm-core/src/com/arsdigita/packaging/LoadCenterDelegate.java +++ b/ccm-core/src/com/arsdigita/packaging/LoadCenterDelegate.java @@ -469,11 +469,12 @@ public class LoadCenterDelegate implements LoadCenter { * @param loaders A list of loaders to the corresponding packages * to-be-loaded * @param sessionName Name of the session + * @param type The load-type * @return true on success, otherwise false */ @Override public boolean checkInitializerDependencies(final Loader[] loaders, - String sessionName) { + String sessionName, LoadType type) { final List required = new ArrayList(); final List provided = new ArrayList(); addTo(required, InfoGetter.getRequiredInitializers(loaders)); @@ -482,15 +483,26 @@ public class LoadCenterDelegate implements LoadCenter { final Session boot = session(sessionName); final List missing = getMissing(boot, required); - final List conflicts = getConflicts(boot, provided); + final List existing = getExisting(boot, provided); if (!missing.isEmpty()) { System.err.println("required initializers: " + missing); return false; } - if (!conflicts.isEmpty()) { - System.err.println("conflicting initializers: " + conflicts); - return false; + + if (type==LoadType.LOAD) { + // Beim laden + if (!existing.isEmpty()) { + System.err.println("already existing initializers, " + + "thus conflicting: " + existing); + return false; + } + } else if (type==LoadType.UNLOAD) { + if (existing.isEmpty()) { + System.err.println("not existing initializers," + + "thus not unloadable: " + existing); + return false; + } } return true; } @@ -548,24 +560,24 @@ public class LoadCenterDelegate implements LoadCenter { /** * [SUPPORT] * Returns all initializers, provided by initializers in the given list, - * which have already been initialized, thus all conflicting initializers. + * which have already been initialized, thus all existing initializers. * * used in: checkInitializerDependencies * * @param ssn The session for the db-connection * @param inits List of initializers - * @return List of conflicting initializers + * @return List of existing initializers */ - private static List getConflicts(Session ssn, List inits) { - List conflicts = new ArrayList(); + private static List getExisting(Session ssn, List inits) { + List existing = new ArrayList(); for (Iterator it = inits.iterator(); it.hasNext(); ) { String init = (String) it.next(); OID oid = new OID(ssn.getMetadataRoot().getObjectType(INIT), init); if (ssn.retrieve(oid) != null) { - conflicts.add(init); + existing.add(init); } } - return conflicts; + return existing; } diff --git a/ccm-core/src/com/arsdigita/packaging/Loader.java b/ccm-core/src/com/arsdigita/packaging/Loader.java index 5fb9b496a..f485d609c 100755 --- a/ccm-core/src/com/arsdigita/packaging/Loader.java +++ b/ccm-core/src/com/arsdigita/packaging/Loader.java @@ -317,15 +317,18 @@ class Loader { final List required = m_info.getRequiredInitializers(); for (Iterator it = inits.iterator(); it.hasNext(); ) { String init = (String) it.next(); - OID oid = new OID(INIT, init); - DataObject dataObject = ssn.retrieve(oid); - DataAssociation da = + DataObject dataObject = ssn.retrieve(new OID(INIT, init)); + + DataAssociation da1 = (DataAssociation) dataObject.get("requirements"); for (Iterator reqIt = required.iterator(); reqIt.hasNext(); ) { String reqInit = (String) reqIt.next(); - da.remove(ssn.retrieve(new OID(INIT, reqInit))); + da1.remove(ssn.retrieve(new OID(INIT, reqInit))); } - ssn.delete(oid); + + DataAssociation da2 = + (DataAssociation) dataObject.get("inits"); + da2.remove(ssn.retrieve(new OID(INIT, init))); } if (txn.inTxn()) { diff --git a/ccm-core/src/com/arsdigita/packaging/Unload.java b/ccm-core/src/com/arsdigita/packaging/Unload.java index c19b43a6d..ce290a45c 100755 --- a/ccm-core/src/com/arsdigita/packaging/Unload.java +++ b/ccm-core/src/com/arsdigita/packaging/Unload.java @@ -305,16 +305,17 @@ class Unload extends Command implements LoadCenter { * @param loaders A list of loaders to the corresponding packages * to-be-loaded * @param sessionName Name of the session + * @param type The load-type * @return true on success, otherwise false */ @Override public boolean checkInitializerDependencies(final Loader[] loaders, - String sessionName) { - return delegate.checkInitializerDependencies(loaders, sessionName); + String sessionName, LoadType type) { + return delegate.checkInitializerDependencies(loaders, sessionName, type); } /** - * Unloads the initializers. needed? + * Unloads the initializers. * * @param ssn The session for the db-connection * @param unloaders The list of unloaders from the packages to be unloaded @@ -323,7 +324,8 @@ class Unload extends Command implements LoadCenter { private boolean unloadInits(Connection conn, Session ssn, Loader[] unloaders) { boolean passed = true; if (PackageLoader.exists(conn, "inits")) { - passed &= checkInitializerDependencies(unloaders, "unloader"); + passed &= checkInitializerDependencies(unloaders, "unloader", + LoadType.UNLOAD); if (!passed) { return false; } diff --git a/ccm-core/src/com/arsdigita/persistence/DataObjectImpl.java b/ccm-core/src/com/arsdigita/persistence/DataObjectImpl.java index 336eea0d0..b051fea0d 100755 --- a/ccm-core/src/com/arsdigita/persistence/DataObjectImpl.java +++ b/ccm-core/src/com/arsdigita/persistence/DataObjectImpl.java @@ -197,9 +197,8 @@ class DataObjectImpl implements DataObject { builder.append(((Property) properties.next()).getName()); } - throw new PersistenceException(String.format( - "no such property: %s for %s. Available properties: %s", - property.toString(), + throw new PersistenceException(String.format("no such property: %s for %s. Available properties: %s", + property, this.toString(), builder.toString())); }