first pass at locking related ui work.

- adding lock icons to the ui
- using lock aware service for create and edit web content.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6027 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2007-06-20 07:08:59 +00:00
parent fcacf048c0
commit 4f5f15419f
14 changed files with 342 additions and 80 deletions

View File

@@ -39,7 +39,6 @@ import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
@@ -95,9 +94,6 @@ public class AVMEditBean
/** The ContentService bean reference */
protected ContentService contentService;
/** The NodeService bean reference */
protected NodeService nodeService;
/** The FilePickerBean reference */
protected FilePickerBean filePickerBean;
@@ -145,14 +141,6 @@ public class AVMEditBean
this.contentService = contentService;
}
/**
* @param nodeService The nodeService to set.
*/
public void setNodeService(final NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @return Returns the current AVM node context.
*/

View File

@@ -114,26 +114,26 @@ public class RegenerateRenditionsWizard
}
LOGGER.debug("updating " + diffList.size() + " renditions in staging");
this.avmSyncService.update(diffList, null, true, true, true, true, null, null);
final StringBuilder description = new StringBuilder();
String description = null;
final ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
if (this.regenerateScope.equals(REGENERATE_SCOPE_FORM))
{
description.append("regenerated all renditions for content authored using forms ").
append(StringUtils.arrayToDelimitedString(this.selectedForms, ", ")).
append(".");
description = MessageFormat.format("regenerate_renditions_snapshot_description_scope_form",
StringUtils.arrayToDelimitedString(this.selectedForms, ", "));
}
else if (this.regenerateScope.equals(REGENERATE_SCOPE_RENDERING_ENGINE_TEMPLATE))
{
description.append("regenerated all renditions generated by ").
append(StringUtils.arrayToDelimitedString(this.selectedRenderingEngineTemplates, ", ")).
append(".");
description = MessageFormat.format("regenerate_renditions_snapshot_description_scope_rendering_engine_template",
StringUtils.arrayToDelimitedString(this.selectedRenderingEngineTemplates, ", "));
}
else
{
description.append("regenerated all renditions in web project " + this.selectedWebProject.getName());
description = MessageFormat.format("regenerate_renditions_snapshot_description_scope_web_project",
this.selectedWebProject.getName());
}
this.avmService.createSnapshot(this.selectedWebProject.getStoreId(),
"regenerated renditions",
description.toString());
MessageFormat.format("regenerate_renditions_snapshot_short_description", diffList.size()),
description);
}
return outcome;
}

View File

@@ -178,8 +178,7 @@ public class RenderingEngineTemplateImpl
public String getOutputPathForRendition(final FormInstanceData formInstanceData, final String currentAVMPath)
{
final ServiceRegistry sr = this.getServiceRegistry();
final NodeService nodeService = sr.getNodeService();
final AVMService avmService = sr.getAVMService();
final AVMService avmService = this.getAVMService();
final String formInstanceDataAVMPath = formInstanceData.getPath();
@@ -253,7 +252,7 @@ public class RenderingEngineTemplateImpl
SAXException,
RenderingEngine.RenderingException
{
final AVMService avmService = this.getServiceRegistry().getAVMService();
final AVMService avmService = this.getAVMService();
final boolean isRegenerate = avmService.lookup(-1, renditionAvmPath) != null;
if (!isRegenerate)
{
@@ -330,7 +329,7 @@ public class RenderingEngineTemplateImpl
new PropertyValue(DataTypeDefinition.TEXT,
AVMUtil.getStoreRelativePath(formInstanceData.getPath())));
final AVMService avmService = this.getServiceRegistry().getAVMService();
final AVMService avmService = this.getAVMService();
avmService.setNodeProperties(rendition.getPath(), props);
}
@@ -555,6 +554,11 @@ public class RenderingEngineTemplateImpl
return new FormDataFunctions((AVMRemote)wac.getBean("avmRemote"));
}
private AVMService getAVMService()
{
return this.getServiceRegistry().getAVMService();
}
private ServiceRegistry getServiceRegistry()
{
final FacesContext fc = FacesContext.getCurrentInstance();
@@ -570,5 +574,6 @@ public class RenderingEngineTemplateImpl
{
return this.getClass().getName() + "{name : " + this.getName() + "}";
}
}

View File

@@ -32,8 +32,10 @@ import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMAppModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.Pair;
@@ -101,11 +103,11 @@ public class RenditionImpl
public FormInstanceData getPrimaryFormInstanceData()
throws FileNotFoundException
{
final AVMService avmService = this.getServiceRegistry().getAVMService();
final NodeService nodeService = this.getServiceRegistry().getNodeService();
final AVMService avmService = this.getAVMService();
final String fidAVMStoreRelativePath = (String)
nodeService.getProperty(this.nodeRef,
WCMAppModel.PROP_PRIMARY_FORM_INSTANCE_DATA);
avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
WCMAppModel.PROP_PRIMARY_FORM_INSTANCE_DATA).getValue(DataTypeDefinition.TEXT);
String avmStore = AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond();
avmStore = avmStore.substring(0, avmStore.indexOf(':'));
final String path = avmStore + ':' + fidAVMStoreRelativePath;
@@ -113,7 +115,7 @@ public class RenditionImpl
{
throw new FileNotFoundException("unable to find primary form instance data " + path);
}
return new FormInstanceDataImpl(AVMNodeConverter.ToNodeRef(-1, path));
return new FormInstanceDataImpl(-1, path);
}
/** the rendering engine template that generated this rendition */
@@ -121,20 +123,36 @@ public class RenditionImpl
{
if (this.renderingEngineTemplate == null)
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
final NodeRef retNodeRef = (NodeRef)
nodeService.getProperty(this.nodeRef,
WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE);
final AVMService avmService = this.getAVMService();
PropertyValue pv =
avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE);
if (pv == null)
{
LOGGER.debug("property " + WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE +
" not set on " + this.getPath());
return null;
}
final NodeRef retNodeRef = (NodeRef)pv.getValue(DataTypeDefinition.NODE_REF);
if (retNodeRef == null)
{
LOGGER.debug("unable to locate parent rendering engine template of rendition " +
this.getPath());
return null;
}
pv = avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES);
if (pv == null)
{
LOGGER.debug("property " + WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES +
" not set on " + this.getPath());
return null;
}
final NodeRef rpNodeRef = (NodeRef)
nodeService.getProperty(this.nodeRef,
WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES);
final NodeRef rpNodeRef = (NodeRef)pv.getValue(DataTypeDefinition.NODE_REF);
if (rpNodeRef == null)
{
LOGGER.debug("unable to locate parent rendering engine template properties of rendition " +
@@ -169,7 +187,7 @@ public class RenditionImpl
public OutputStream getOutputStream()
{
final AVMService avmService = this.getServiceRegistry().getAVMService();
final AVMService avmService = this.getAVMService();
final Pair<Integer, String> p = AVMNodeConverter.ToAVMVersionPath(this.nodeRef);
return (avmService.lookup(p.getFirst(), p.getSecond()) == null
? avmService.createFile(AVMNodeConverter.SplitBase(p.getSecond())[0],
@@ -194,6 +212,11 @@ public class RenditionImpl
this.getRenderingEngineTemplate().render(formInstanceData, this);
}
private AVMService getAVMService()
{
return this.getServiceRegistry().getAVMService();
}
private ServiceRegistry getServiceRegistry()
{
final FacesContext fc = FacesContext.getCurrentInstance();

View File

@@ -25,6 +25,7 @@
package org.alfresco.web.ui.repo.component;
import java.io.IOException;
import java.text.MessageFormat;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -38,6 +39,7 @@ import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.SelfRenderingComponent;
import org.alfresco.web.ui.repo.WebResources;
import org.springframework.util.StringUtils;
/**
* @author Kevin Roast
@@ -79,16 +81,17 @@ public class UILockIcon extends SelfRenderingComponent
*/
public Object saveState(FacesContext context)
{
Object values[] = new Object[7];
// standard component attributes are saved by the super class
values[0] = super.saveState(context);
values[1] = this.lockImage;
values[2] = this.lockOwnerImage;
values[3] = this.align;
values[4] = this.width;
values[5] = this.height;
values[6] = this.value;
return (values);
return new Object[]
{
// standard component attributes are saved by the super class
super.saveState(context),
this.lockImage,
this.lockOwnerImage,
this.align,
this.width,
this.height,
this.value
};
}
/**
@@ -100,14 +103,10 @@ public class UILockIcon extends SelfRenderingComponent
{
return;
}
ResponseWriter out = context.getResponseWriter();
// get the value and see if the image is locked
NodeService nodeService = getNodeService(context);
boolean locked = false;
boolean lockedOwner = false;
String lockUser = null;
Object val = getValue();
NodeRef ref = null;
if (val instanceof NodeRef)
@@ -115,15 +114,26 @@ public class UILockIcon extends SelfRenderingComponent
ref = (NodeRef)val;
if (nodeService.exists(ref) && nodeService.hasAspect(ref, ContentModel.ASPECT_LOCKABLE) == true)
{
String lockerUser = (String)nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER);
if (lockerUser != null)
{
locked = true;
lockedOwner = (lockerUser.equals(Application.getCurrentUser(context).getUserName()));
}
lockUser = (String)nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER);
}
}
final boolean locked = lockUser != null;
final boolean lockedOwner = locked && (lockUser.equals(Application.getCurrentUser(context).getUserName()));
this.encodeBegin(context, locked, lockedOwner, new String[] { lockUser });
}
protected void encodeBegin(final FacesContext context,
final boolean locked,
final boolean lockedOwner,
final String[] lockUser)
throws IOException
{
if (isRendered() == false)
{
return;
}
ResponseWriter out = context.getResponseWriter();
String msg = null;
if (locked == true)
@@ -157,15 +167,14 @@ public class UILockIcon extends SelfRenderingComponent
}
else
{
String lockingUser = (String)nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER);
msg = Application.getMessage(context, MSG_LOCKED_USER);
msg = MessageFormat.format(Application.getMessage(context, MSG_LOCKED_USER), lockUser.length);
if (getLockedUserTooltip() != null)
{
msg = getLockedUserTooltip();
}
StringBuilder buf = new StringBuilder(32);
msg = buf.append(msg).append(" '")
.append(lockingUser)
.append(StringUtils.arrayToDelimitedString(lockUser, ", "))
.append("'").toString();
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.ui.wcm.component;
import java.io.IOException;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.locking.AVMLock;
import org.alfresco.service.cmr.avm.locking.AVMLockingService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.bean.wcm.WebProject;
import org.alfresco.web.ui.repo.component.UILockIcon;
/**
* @author Ariel Backenroth
*/
public class UIAVMLockIcon extends UILockIcon
{
// ------------------------------------------------------------------------------
// Component implementation
/**
* @see javax.faces.component.UIComponent#getFamily()
*/
public String getFamily()
{
return "org.alfresco.faces.AVMLockIcon";
}
/**
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
*/
public void encodeBegin(FacesContext context) throws IOException
{
if (isRendered() == false)
{
return;
}
// get the value and see if the image is locked
final AVMService avmService = Repository.getServiceRegistry(context).getAVMService();
final AVMLockingService avmLockingService = Repository.getServiceRegistry(context).getAVMLockingService();
boolean locked = false;
boolean lockedOwner = false;
Object val = getValue();
List<String> lockUser = null;
final String avmPath = (val instanceof NodeRef
? AVMNodeConverter.ToAVMVersionPath((NodeRef)val).getSecond()
: (val instanceof String
? (String)val
: null));
if (avmPath != null)
{
if (avmService.lookup(-1, avmPath) != null)
{
final WebProject webProject = new WebProject(avmPath);
final AVMLock lock = avmLockingService.getLock(webProject.getStoreId(), avmPath.substring(avmPath.indexOf("/")));
if (lock != null)
{
locked = true;
final User currentUser = Application.getCurrentUser(context);
lockUser = lock.getOwners();
lockedOwner = (webProject.isManager(currentUser) ||
lockUser.contains(currentUser.getUserName()));
}
}
}
this.encodeBegin(context,
locked,
lockedOwner,
lockUser == null ? new String[0] : (String[])lockUser.toArray(new String[lockUser.size()]));
}
}

View File

@@ -719,6 +719,10 @@ public class UIUserSandboxes extends SelfRenderingComponent
out.write("</a></td><td>");
out.write(linkPrefix);
out.write(name);
UIAVMLockIcon lockIcon = (UIAVMLockIcon)fc.getApplication().createComponent("org.alfresco.faces.AVMLockIcon");
lockIcon.setId("lock_" + FacesHelper.makeLegalId(name));
lockIcon.setValue(sourcePath);
Utils.encodeRecursive(fc, lockIcon);
out.write("</a>");
}
else

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.ui.wcm.tag;
import org.alfresco.web.ui.repo.tag.LockIconTag;
/**
* @author Ariel Backenroth
*/
public class AVMLockIconTag extends LockIconTag
{
/**
* @see javax.faces.webapp.UIComponentTag#getComponentType()
*/
public String getComponentType()
{
return "org.alfresco.faces.AVMLockIcon";
}
}