cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in import strategy UUIDBinding.UPDATE_EXISTING??

nyronian
Champ in-the-making
Champ in-the-making
I have been trying to figure out why I cannot use the UPDATE_EXISTING import Strategy and I think I have tracked it down to a bug.

When I try to execute an import using the UPDATE_EXISTING Import Strategy, I get the following exception.

16:04:43,035 DEBUG [web.publish.PublishWebsiteRemote] Begin Execution of Import with Parms… {encoding=UTF-8, binding=U
PDATE_EXISTING, destination=workspace://SpacesStore/447abbd9-87d5-11dc-b0d3-b7b5a51138f9}
16:04:43,207 ERROR [[localhost].[/site].[Publish]] Servlet.service() for servlet Publish threw exception
org.alfresco.service.cmr.view.ImporterException: Failed to import package at line 35; column 16 due to error: Duplicate
child name not allowed: PrivacyPolicy
        at org.alfresco.repo.importer.view.ViewParser.parse(ViewParser.java:190)
        at org.alfresco.repo.importer.ImporterComponent.parserImport(ImporterComponent.java:360)
        at org.alfresco.repo.importer.ImporterComponent.importView(ImporterComponent.java:235)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodIntercep
tor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMe
thodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:238)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy52.importView(Unknown Source)
        at org.alfresco.repo.action.executer.ImporterActionExecuter.executeImpl(ImporterActionExecuter.java:185)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
        at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:472)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:399)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:387)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:545)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodIntercep
tor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMe
thodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy19.executeAction(Unknown Source)
        at com.tlhc.wc.web.publish.PublishWebsiteRemote.testACPImport(PublishWebsiteRemote.java:165)
        at com.tlhc.wc.servlet.PublishController.processRequest(PublishController.java:103)
        at com.tlhc.wc.servlet.PublishController.access$000(PublishController.java:23)
        at com.tlhc.wc.servlet.PublishController$ProcessDownloadContentWork.doWork(PublishController.java:86)
        at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:260)
        at com.tlhc.wc.servlet.PublishController.doPost(PublishController.java:47)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: Privac
yPolicy
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.setChildNameUnique(HibernateNodeDaoServiceImp
l.java:698)
        at sun.reflect.GeneratedMethodAccessor383.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.transaction.TransactionalDaoInterceptor.invoke(TransactionalDaoInterceptor.java:68)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy1.setChildNameUnique(Unknown Source)
        at org.alfresco.repo.node.db.DbNodeServiceImpl.setChildUniqueName(DbNodeServiceImpl.java:2022)
        at org.alfresco.repo.node.db.DbNodeServiceImpl.createNode(DbNodeServiceImpl.java:353)
        at sun.reflect.GeneratedMethodAccessor417.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.transaction.TransactionResourceInterceptor.invoke(TransactionResourceInterceptor.java:138)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy2.createNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor417.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxy
Factory.java:221)
        at $Proxy3.createNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor417.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:211)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy2.createNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor417.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
187)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.
java:80)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMe
thodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:238)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy2.createNode(Unknown Source)
        at org.alfresco.repo.importer.ImporterComponent$NodeImporter$CreateNewNodeImporterStrategy.importNode(ImporterCo
mponent.java:1265)
        at org.alfresco.repo.importer.ImporterComponent$NodeImporter.importNode(ImporterComponent.java:550)
        at org.alfresco.repo.importer.view.ViewParser.importNode(ViewParser.java:847)
        at org.alfresco.repo.importer.view.ViewParser.processEndType(ViewParser.java:811)
        at org.alfresco.repo.importer.view.ViewParser.processEndElement(ViewParser.java:791)
        at org.alfresco.repo.importer.view.ViewParser.parse(ViewParser.java:182)
        … 68 more

I traced this down as follows:

This is the ImporterComponent Class with the binding passed in.  It then creates the proper nodeImporter and sends it to viewParse.parse
   public void parserImport(NodeRef nodeRef, QName childAssocType, Reader viewReader, ImportPackageHandler streamHandler, ImporterBinding binding, ImporterProgress progress)
    {
        ParameterCheck.mandatory("Node Reference", nodeRef);
        ParameterCheck.mandatory("View Reader", viewReader);
        ParameterCheck.mandatory("Stream Handler", streamHandler);
       
        Importer nodeImporter = new NodeImporter(nodeRef, childAssocType, binding, streamHandler, progress);
        try
        {
            nodeImporter.start();
            viewParser.parse(viewReader, nodeImporter);
            nodeImporter.end();
        }
        catch(RuntimeException e)
        {
            nodeImporter.error(e);
            throw e;
        }
    }

ViewParse.parse then sets the importer to the parserContext class which is then passed throughout the rest of the parsing
   public void parse(Reader viewReader, Importer importer)

            ParserContext parserContext = new ParserContext();
            parserContext.importer = importer;
            parserContext.dictionaryService = dictionaryService;
            parserContext.elementStack = new Stack<ElementContext>();
           
            try
            {
                for (int eventType = xpp.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xpp.next())
                {
                    switch (eventType)
                    {
                        case XmlPullParser.START_TAG:
                        {
                            if (xpp.getDepth() == 1)
                            {
                                processRoot(xpp, parserContext);
                            }
                            else
                            {
                                processStartElement(xpp, parserContext);
                            }
                            break;
                        }
                        case XmlPullParser.END_TAG:
                        {
                            processEndElement(xpp, parserContext);
                            break;
                        }
                    }…

You can then trace to processEndElement method, then to processEndType method then to importNode (note the stacktrace). 
   /**
     * Import node
     *
     * @param parserContext  parser context
     * @param node  node context
     */
    private void importNode(ParserContext parserContext, NodeContext node)
    {
        if (node.getNodeRef() == null)
        {
            // Import Node
            NodeRef nodeRef = node.getImporter().importNode(node);
            node.setNodeRef(nodeRef);
           
            // Maintain running list of "import" scoped ids
            String importId = node.getImportId();
            if (importId != null && importId.length() > 0)
            {
                createImportReference(parserContext, importId, nodeRef);
            }
        }
    }

Notice the code in importNode calls
node.getImporter().importNode();

This then creates a different import strategy and tries to import the node.  It seems to me it should call
parserContext.getImporter.importNode(…)

The only question I have that may mean it's not where the bug is, is why the node is null in the first place.  The node I am importing does exist so should it be a valid noderef by the time it hits importNode?
1 REPLY 1

nyronian
Champ in-the-making
Champ in-the-making
Ok, if anybody is interested, I found the problem with this.  There was no bug but the way I was calling for the import.

I was copying the "Execute Action" technique.

      Map<String, Serializable> params = new HashMap<String, Serializable>();
        params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, ownerNodeRef);
        params.put(ImporterActionExecuter.PARAM_ENCODING, "UTF-8");
        params.put(ImporterActionExecuter.PARAM_BINDING_OPTION, UUID_BINDING.UPDATE_EXISTING);
       
        // build the action to execute
        Action action = actionService.createAction(ImporterActionExecuter.NAME, params);
        action.setExecuteAsynchronously(false);
       
        // execute the action on the ACP file
        actionService.executeAction(action, acpNodeRef);

You cannot do this as the executeAction is not designed to pass in the UUID_BINDINGS.

You can call the importer with the following code and it works perfectly…..

    public void importFile(NodeRef file, NodeRef importDest)
    {
        if (this.nodeService.exists(file) == true)
        {
           // The node being passed in should be an Alfresco content package
           ContentReader reader = this.contentService.getReader(file, ContentModel.PROP_CONTENT);
           if (reader != null)
           {
               if (MimetypeMap.MIMETYPE_ACP.equals(reader.getMimetype()))
               {
                   // perform an import of an Alfresco ACP file (special format ZIP structure)
                   File zipFile = null;
                   try
                   {
                       // unfortunately a ZIP file can not be read directly from an input stream so we have to create
                       // a temporary file first
                       zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX_ACP);
                       reader.getContent(zipFile);
                      
                       ACPImportPackageHandler importHandler = new ACPImportPackageHandler(zipFile, "UTF-8");
                       ImporterBinding ib = new ImportBinding(UUID_BINDING.UPDATE_EXISTING);
                       ImporterProgressImpl progress = new ImporterProgressImpl();
                       services.getImporterService().importView(importHandler, new Location(importDest), ib, progress);
                   }
                   finally
                   {
                      // now the import is done, delete the temporary file
                      if (zipFile != null)
                      {
                         zipFile.delete();
                      }
                   }
               }
           }
        }
    }
   
   /**TLHC Used to pass Importer Binding **/
   private class ImportBinding implements ImporterBinding{

       private UUID_BINDING uuidBinding = null;

       /**
        * Construct
        *
        * @param uuidBinding
        */
       public ImportBinding(UUID_BINDING uuidBinding)
       {
           this.uuidBinding = uuidBinding;
       }
      
       /*
        *  (non-Javadoc)
        * @see org.alfresco.service.cmr.view.ImporterBinding#getUUIDBinding()
        */
       public UUID_BINDING getUUIDBinding()
       {
           return uuidBinding;
       }

       /*
        *  (non-Javadoc)
        * @see org.alfresco.service.cmr.view.ImporterBinding#allowReferenceWithinTransaction()
        */
       public boolean allowReferenceWithinTransaction()
       {
           return false;
       }

       /*
        *  (non-Javadoc)
        * @see org.alfresco.service.cmr.view.ImporterBinding#getValue(java.lang.String)
        */
       public String getValue(String key)
       {
           return null;
       }

       public QName[] getExcludedClasses()
       {
           return new QName[] {};
       }
      
   }