diff --git a/source/java/org/alfresco/repo/admin/patch/AbstractPatch.java b/source/java/org/alfresco/repo/admin/patch/AbstractPatch.java index 3caabb87a5..7c536ee7b9 100644 --- a/source/java/org/alfresco/repo/admin/patch/AbstractPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/AbstractPatch.java @@ -228,12 +228,12 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher public void setRequiresTransaction(boolean requiresTransaction) { - this.requiresTransaction = requiresTransaction; + this.requiresTransaction = requiresTransaction; } public boolean requiresTransaction() { - return requiresTransaction; + return requiresTransaction; } /** @@ -441,17 +441,17 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher } String report = applyInternal(); - if ((tenantAdminService != null) && tenantAdminService.isEnabled() && applyToTenants) + if ((tenantAdminService != null) && tenantAdminService.isEnabled() && applyToTenants) { if(logger.isDebugEnabled()) { logger.debug("call applyInternal for all tennants"); } - final List tenants = tenantAdminService.getAllTenants(); - - BatchProcessWorkProvider provider = new BatchProcessWorkProvider() - { - Iterator i = tenants.iterator(); + final List tenants = tenantAdminService.getAllTenants(); + + BatchProcessWorkProvider provider = new BatchProcessWorkProvider() + { + Iterator i = tenants.iterator(); @Override public int getTotalEstimatedWorkSize() @@ -471,10 +471,10 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher } return chunk; } - }; + }; - BatchProcessor batchProcessor = new BatchProcessor( - "AbstractPatch Processor for " + id, + BatchProcessor batchProcessor = new BatchProcessor( + "AbstractPatch Processor for " + id, transactionHelper, provider, // collection of tenants 10, // worker threads, @@ -482,9 +482,9 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher applicationEventPublisher, logger, 1000); - - BatchProcessWorker worker = new BatchProcessWorker() - { + + BatchProcessWorker worker = new BatchProcessWorker() + { @Override public String getIdentifier(Tenant entry) { @@ -515,17 +515,17 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher { } - }; - - // Now do the work + }; + + // Now do the work int numberOfInvocations = batchProcessor.process(worker, true); - if(logger.isDebugEnabled()) + if (logger.isDebugEnabled()) { logger.debug("batch worker finished processing id:" + id); } - if(batchProcessor.getTotalErrors() > 0) + if (batchProcessor.getTotalErrors() > 0) { report = report + "\n" + " and failure during update of tennants total success: " + batchProcessor.getSuccessfullyProcessedEntries() + " number of errors: " +batchProcessor.getTotalErrors() + " lastError" + batchProcessor.getLastError(); } @@ -536,7 +536,7 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher } // done? - return report; + return report; } /** @@ -547,8 +547,8 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher * @throws PatchException if the patch failed to be applied */ public String applyAsync() throws PatchException - { - return apply(true); + { + return apply(true); } /** @@ -558,14 +558,13 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher */ public synchronized String apply() throws PatchException { - return apply(false); + return apply(false); } private String apply(boolean async) { - - if(!async) - { + if (!async) + { // Do we bug out of patch execution if (deferred) { @@ -577,8 +576,8 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher { throw new AlfrescoRuntimeException("The patch has already been executed: \n" + " patch: " + this); } - } - + } + // check properties checkProperties(); @@ -593,22 +592,22 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher { public String doWork() throws Exception { - if(requiresTransaction()) - { + if(requiresTransaction()) + { // execute in a transaction - RetryingTransactionCallback patchWork = new RetryingTransactionCallback() - { - public String execute() throws Exception - { - return applyImpl(); - } - }; - return transactionService.getRetryingTransactionHelper().doInTransaction(patchWork, false, true); - } - else - { - return applyImpl(); - } + RetryingTransactionCallback patchWork = new RetryingTransactionCallback() + { + public String execute() throws Exception + { + return applyImpl(); + } + }; + return transactionService.getRetryingTransactionHelper().doInTransaction(patchWork, false, true); + } + else + { + return applyImpl(); + } } }; startTime = System.currentTimeMillis(); @@ -735,16 +734,18 @@ public abstract class AbstractPatch implements Patch, ApplicationEventPublisher * Should the patch be deferred? And not run at bootstrap. * @param deferred */ - public void setDeferred(boolean deferred) { - this.deferred = deferred; - } + public void setDeferred(boolean deferred) + { + this.deferred = deferred; + } - /* - * - */ - public boolean isDeferred() { - return deferred; - } + /* + * + */ + public boolean isDeferred() + { + return deferred; + } private int getReportingInterval(long soFar, long toGo) { diff --git a/source/java/org/alfresco/repo/admin/patch/impl/SharedFolderPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/SharedFolderPatch.java index c78a00abe8..6ee5d2fea9 100644 --- a/source/java/org/alfresco/repo/admin/patch/impl/SharedFolderPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/impl/SharedFolderPatch.java @@ -48,15 +48,14 @@ import org.springframework.extensions.surf.util.I18NUtil; * The first use-case is when there is a child called cm:shared and we want to patch a folder with app:shared * * @author mrogers - * */ public class SharedFolderPatch extends GenericBootstrapPatch { - private JobLockService jobLockService; - + private JobLockService jobLockService; + private long LOCK_TIME_TO_LIVE=10000; private long LOCK_REFRESH_TIME=5000; - + private String renamePath; private Log logger = LogFactory.getLog(SharedFolderPatch.class); @@ -103,9 +102,9 @@ public class SharedFolderPatch extends GenericBootstrapPatch } } - @Override - protected String applyInternal() throws Exception - { + @Override + protected String applyInternal() throws Exception + { StoreRef storeRef = importerBootstrap.getStoreRef(); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); if (getRenamePath() != null) @@ -123,25 +122,25 @@ public class SharedFolderPatch extends GenericBootstrapPatch } else if (results.size() == 1) { - if(logger.isDebugEnabled()) - { - logger.debug("There is an existing node in the way path:" + getRenamePath()); - } - // A node already exists that we must rename. - NodeRef existingNodeRef = results.get(0); - - // get the path of the parent node e.g. company_home - LinkedList folderElements = new LinkedList(Arrays.asList(getRenamePath().split("/"))); - folderElements.removeLast(); - + if(logger.isDebugEnabled()) + { + logger.debug("There is an existing node in the way path:" + getRenamePath()); + } + // A node already exists that we must rename. + NodeRef existingNodeRef = results.get(0); + + // get the path of the parent node e.g. company_home + LinkedList folderElements = new LinkedList(Arrays.asList(getRenamePath().split("/"))); + folderElements.removeLast(); + StringBuffer parentPath = new StringBuffer(); - - for(String folder : folderElements) - { - parentPath.append("/"); - parentPath.append(folder); - } - + + for(String folder : folderElements) + { + parentPath.append("/"); + parentPath.append(folder); + } + List parentResults = searchService.selectNodes( rootNodeRef, parentPath.toString(), @@ -151,52 +150,56 @@ public class SharedFolderPatch extends GenericBootstrapPatch if(parentResults.size()==1) { - + NodeRef parentNodeRef = parentResults.get(0); - if(logger.isDebugEnabled()) - { - logger.debug("Found the parent node - doing a move parentNodeRef:" + parentNodeRef); - } - - // rename the existing node - nodeService.moveNode(existingNodeRef, parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName( NamespaceService.APP_MODEL_1_0_URI, "shared")); + if(logger.isDebugEnabled()) + { + logger.debug("Found the parent node - doing a move parentNodeRef:" + parentNodeRef); + } + + // rename the existing node + nodeService.moveNode(existingNodeRef, parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName( NamespaceService.APP_MODEL_1_0_URI, "shared")); return I18NUtil.getMessage(MSG_RENAMED, renamePath); } else { // Something has gone horribly wrong if we get here - we have multiple parents, or none despite finding the node earlier - throw new PatchException(ERR_MULTIPLE_FOUND, parentPath.toString()); + throw new PatchException(ERR_MULTIPLE_FOUND, parentPath.toString()); } } } // Else run the normal GenericBootstrapPatch implementation - if(logger.isDebugEnabled()) - { - logger.debug("Node does not already exist, Running the Generic Bootstrap Patch"); - } - return super.applyInternal(); - } + if(logger.isDebugEnabled()) + { + logger.debug("Node does not already exist, Running the Generic Bootstrap Patch"); + } + return super.applyInternal(); + } - public void setRenamePath(String renamePath) { - this.renamePath = renamePath; - } + public void setRenamePath(String renamePath) + { + this.renamePath = renamePath; + } - public String getRenamePath() { - return renamePath; - } - - public void setJobLockService(JobLockService jobLockService) { - this.jobLockService = jobLockService; - } + public String getRenamePath() + { + return renamePath; + } + + public void setJobLockService(JobLockService jobLockService) + { + this.jobLockService = jobLockService; + } - public JobLockService getJobLockService() { - return jobLockService; - } + public JobLockService getJobLockService() + { + return jobLockService; + } -/** + /** * Job to initiate the {@link SharedFolderPatch} if it has been deferred * * @author Mark Rogers