Merged BRANCHES/DEV/BELARUS/HEAD_2010_09_21 to HEAD:

22696: Restores original fixes for ETHREEOH-3850, ETHREEOH-3834 that got lost during various merges back to HEAD, fixes ALF-4675 and ALF-3043

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22703 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2010-09-27 07:02:17 +00:00
parent 65ee784c6b
commit 67a9bf6d4a
4 changed files with 179 additions and 20 deletions

View File

@@ -51,6 +51,7 @@ import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.FacesHelper;
@@ -371,6 +372,27 @@ public class CreateWebContentWizard extends CreateContentWizard
}
}
this.getAvmSyncService().update(diffList, null, true, true, true, true, null, null);
for (final AVMDifference diff : diffList)
{
final String path = diff.getDestinationPath();
String storeId = AVMUtil.getStoreId(path);
String storePath = AVMUtil.getStoreRelativePath(path);
String storeName = AVMUtil.getStoreName(path);
String lockOwner = getAvmLockingService().getLockOwner(storeId, storePath);
Map<String, String> lockData = getAvmLockingService().getLockData(storeId, storePath);
String fromStoreName = lockData.get(WCMUtil.LOCK_KEY_STORE_NAME);
lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, storeName);
if (logger.isDebugEnabled())
{
logger.debug("modifying lock on " + path + ". chaging store from " + fromStoreName + " to " + storeName);
}
this.getAvmLockingService().modifyLock(storeId, AVMUtil.getStoreRelativePath(diff.getSourcePath()), lockOwner, storeId, AVMUtil.getStoreRelativePath(path), lockData);
}
if (this.startWorkflow)
{
final List<AVMNodeDescriptor> submitNodes = new ArrayList<AVMNodeDescriptor>(1 + this.getUploadedFiles().size() + this.getRenditions().size());

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.web.bean.wcm;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -25,6 +26,7 @@ import java.util.Set;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.web.app.Application;
import org.alfresco.web.forms.Form;
import org.alfresco.web.forms.FormInstanceData;
@@ -82,6 +84,32 @@ public class EditWebContentWizard extends CreateWebContentWizard
}
this.content = this.getAvmService().getContentReader(-1, this.createdPath).getContentString();
this.mimeType = MimetypeMap.MIMETYPE_XML;
// calculate which locks are present at init time
this.existingLocks = new HashSet<String>(4);
String lock = this.getAvmLockingService().getLockOwner(AVMUtil.getStoreId(this.createdPath),
AVMUtil.getStoreRelativePath(this.createdPath));
if (lock != null)
{
this.existingLocks.add(this.createdPath);
if (logger.isDebugEnabled())
logger.debug("Lock exists for xml instance " + this.createdPath + " at initialisation");
}
for (final Rendition r : this.formInstanceData.getRenditions())
{
String path = r.getPath();
lock = this.getAvmLockingService().getLockOwner(AVMUtil.getStoreId(path),
AVMUtil.getStoreRelativePath(path));
if (lock != null)
{
this.existingLocks.add(path);
if (logger.isDebugEnabled())
logger.debug("Lock exists for rendition " + path + " at initialisation");
}
}
}
@Override
@@ -143,6 +171,21 @@ public class EditWebContentWizard extends CreateWebContentWizard
if (logger.isDebugEnabled())
logger.debug("saving " + this.createdPath);
String storeId = AVMUtil.getStoreId(this.createdPath);
String storePath = AVMUtil.getStoreRelativePath(this.createdPath);
String storeName = AVMUtil.getStoreName(this.createdPath);
String lockOwner = this.getAvmLockingService().getLockOwner(storeId, storePath);
Map<String, String> lockData = this.getAvmLockingService().getLockData(storeId, storePath);
if (lockOwner != null)
{
if (logger.isDebugEnabled())
logger.debug("transferring lock from " + lockData.get(WCMUtil.LOCK_KEY_STORE_NAME) + " to " + storeName);
lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, AVMUtil.getStoreName(this.createdPath));
this.getAvmLockingService().modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData);
}
final ContentWriter writer = this.getAvmService().getContentWriter(this.createdPath, true);
this.content = XMLUtil.toString(this.getInstanceDataDocument(), false);
writer.putContent(this.content);
@@ -158,11 +201,51 @@ public class EditWebContentWizard extends CreateWebContentWizard
Utils.addErrorMessage("error regenerating rendition using " + rr.getRenderingEngineTemplate().getName() +
": " + rr.getException().getMessage(),
rr.getException());
// if the renditions were locked before the regenerate, move the lock back to main store
String path = rr.getPath();
if (rr.getLockOwner() != null)
{
this.existingLocks.add(path);
}
if (this.existingLocks.contains(path))
{
String renditionStoreId = AVMUtil.getStoreId(path);
String renditionStorePath = AVMUtil.getStoreRelativePath(path);
String renditionStoreName = AVMUtil.getCorrespondingMainStoreName(AVMUtil.getStoreName(path));
Map<String, String> renditionlockData = this.getAvmLockingService().getLockData(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
renditionlockData.put(WCMUtil.LOCK_KEY_STORE_NAME, renditionStoreName);
if (logger.isDebugEnabled())
logger.debug("transferring existing lock for " + path + " back to " + renditionStoreName);
this.getAvmLockingService().modifyLock(renditionStoreId, renditionStorePath, lockOwner, renditionStoreId, renditionStorePath, renditionlockData);
}
}
else
{
final Rendition r = rr.getRendition();
this.renditions.add(r);
String path = r.getPath();
if (rr.getLockOwner() != null)
{
this.existingLocks.add(path);
}
String renditionStoreId = AVMUtil.getStoreId(path);
String renditionStorePath = AVMUtil.getStoreRelativePath(path);
String renditionStoreName = AVMUtil.getCorrespondingMainStoreName(AVMUtil.getStoreName(path));
Map<String, String> renditionlockData = this.getAvmLockingService().getLockData(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
renditionlockData.put(WCMUtil.LOCK_KEY_STORE_NAME, renditionStoreName);
if (logger.isDebugEnabled())
logger.debug("transferring lock for " + path + " back to " + renditionStoreName);
this.getAvmLockingService().modifyLock(renditionStoreId, renditionStorePath, lockOwner, renditionStoreId, renditionStorePath, renditionlockData);
}
}
}

View File

@@ -45,25 +45,30 @@ public interface FormInstanceData
private final String path;
private final Rendition r;
private final Exception e;
private final String lockOwner; // existing lock owner otherwise null
public RegenerateResult(final RenderingEngineTemplate ret,
final String path,
final Rendition r)
final Rendition r,
final String lockOwner)
{
this.ret = ret;
this.r = r;
this.e = null;
this.path = path;
this.lockOwner = lockOwner;
}
public RegenerateResult(final RenderingEngineTemplate ret,
final String path,
final Exception e)
final Exception e,
final String lockOwner)
{
this.ret = ret;
this.e = e;
this.r = null;
this.path = path;
this.lockOwner = lockOwner;
}
public RenderingEngineTemplate getRenderingEngineTemplate()
@@ -85,6 +90,11 @@ public interface FormInstanceData
{
return this.e;
}
public String getLockOwner()
{
return this.lockOwner;
}
}
/////////////////////////////////////////////////////////////////////////////

View File

@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
@@ -39,6 +40,8 @@ import org.alfresco.service.cmr.avm.locking.AVMLockingService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wcm.AVMUtil;
@@ -188,7 +191,6 @@ import org.xml.sax.SAXException;
new HashSet<RenderingEngineTemplate>(this.getForm().getRenderingEngineTemplates());
final List<RegenerateResult> result = new LinkedList<RegenerateResult>();
// regenerate existing renditions
boolean renditionLockedBefore = false;
String path = null;
for (final Rendition r : this.getRenditions())
@@ -213,6 +215,8 @@ import org.xml.sax.SAXException;
{
continue;
}
String lockOwner = null;
try
{
if (logger.isDebugEnabled())
@@ -220,13 +224,10 @@ import org.xml.sax.SAXException;
logger.debug("regenerating rendition " + r + " using template " + ret);
}
renditionLockedBefore = false;
path = r.getPath();
String lockOwner = avmLockService.getLockOwner(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
lockOwner = avmLockService.getLockOwner(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
if (lockOwner != null)
{
renditionLockedBefore = true;
if (logger.isDebugEnabled())
{
logger.debug("Lock already exists for " + path);
@@ -235,14 +236,14 @@ import org.xml.sax.SAXException;
ret.render(this, r);
allRets.remove(ret);
result.add(new RegenerateResult(ret, path, r));
result.add(new RegenerateResult(ret, path, r, lockOwner));
}
catch (Exception e)
{
result.add(new RegenerateResult(ret, path, e));
result.add(new RegenerateResult(ret, path, e, lockOwner));
// remove lock if there wasn't one before
if (renditionLockedBefore == false)
if (lockOwner == null)
{
avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
@@ -254,13 +255,19 @@ import org.xml.sax.SAXException;
}
}
// get current username for lock checks
String username = Application.getCurrentUser(FacesContext.getCurrentInstance()).getUserName();
// render all renditions for newly added templates
for (final RenderingEngineTemplate ret : allRets)
{
String lockOwner = null;
String currentLockStore = null;
boolean lockModified = false;
try
{
renditionLockedBefore = false;
path = ret.getOutputPathForRendition(this, originalParentAvmPath, getName());
path = ret.getOutputPathForRendition(this, originalParentAvmPath, getName().replaceAll("(.+)\\..*", "$1"));
if (logger.isDebugEnabled())
{
@@ -268,33 +275,70 @@ import org.xml.sax.SAXException;
" at " + path + " using template " + ret);
}
String lockOwner = avmLockService.getLockOwner(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
String storeId = AVMUtil.getStoreId(path);
String storePath = AVMUtil.getStoreRelativePath(path);
String storeName = AVMUtil.getStoreName(path);
lockOwner = avmLockService.getLockOwner(storeId, storePath);
Map<String, String> lockData = avmLockService.getLockData(storeId, storePath);
currentLockStore = lockData.get(WCMUtil.LOCK_KEY_STORE_NAME);
if (lockOwner != null)
{
renditionLockedBefore = true;
if (logger.isDebugEnabled())
{
logger.debug("Lock already exists for " + path);
}
if (currentLockStore.equals(storeName) == false)
{
if (lockOwner.equals(username))
{
lockModified = true;
// lock already exists on path, check it's owned by the current user
if (logger.isDebugEnabled())
{
logger.debug("transferring lock from " + currentLockStore + " to " + storeName + " for path: " + path);
}
lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, storeName);
avmLockService.modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData);
}
}
}
result.add(new RegenerateResult(ret, path, ret.render(this, path)));
result.add(new RegenerateResult(ret, path, ret.render(this, path), lockOwner));
}
catch (Exception e)
{
result.add(new RegenerateResult(ret, path, e));
result.add(new RegenerateResult(ret, path, e, lockOwner));
String storeId = AVMUtil.getStoreId(path);
String storePath = AVMUtil.getStoreRelativePath(path);
String storeName = AVMUtil.getStoreName(path);
// remove lock if there wasn't one before
if (renditionLockedBefore == false)
if (lockOwner == null)
{
avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
// remove lock if there wasn't one before
avmLockService.removeLock(storeId, storePath);
if (logger.isDebugEnabled())
{
logger.debug("Removed lock for " + path + " as it failed to generate");
}
}
else if (lockModified)
{
if (logger.isDebugEnabled())
{
logger.debug("transferring lock from " + storeName + " to " + currentLockStore + " for path: " + path);
}
Map<String, String> lockData = avmLockService.getLockData(storeId, storePath);
lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, currentLockStore);
avmLockService.modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData);
}
}
}
return result;