mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Humongous merge. It is incomplete, however; faces-config-navigation.xml and ClientConfigElement
were both beyond me, and are just the raw conflict merge data. If Kev can't figure out how they should go together by tomorrow AM (for me) I'll dig back in. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.DbAccessControlEntry;
|
||||
import org.alfresco.repo.domain.DbPermission;
|
||||
import org.alfresco.repo.domain.hibernate.DbPermissionImpl;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.orm.hibernate3.HibernateCallback;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* Provides common functionality to change a permission type and/or name.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public abstract class AbstractPermissionChangePatch extends AbstractPatch
|
||||
{
|
||||
private HibernateHelper helper;
|
||||
|
||||
public AbstractPermissionChangePatch()
|
||||
{
|
||||
helper = new HibernateHelper();
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory)
|
||||
{
|
||||
this.helper.setSessionFactory(sessionFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to rename (move) a permission. This involves checking for the existence of the
|
||||
* new permission and then moving all the entries to point to the new permission.
|
||||
*
|
||||
* @param oldTypeQName the old permission type
|
||||
* @param oldName the old permission name
|
||||
* @param newTypeQName the new permission type
|
||||
* @param newName the new permission name
|
||||
* @return Returns the number of permission entries modified
|
||||
*/
|
||||
protected int renamePermission(QName oldTypeQName, String oldName, QName newTypeQName, String newName)
|
||||
{
|
||||
return helper.createAndUpdatePermission(oldTypeQName, oldName, newTypeQName, newName);
|
||||
}
|
||||
|
||||
/** Helper to get a permission entity */
|
||||
private static class GetPermissionCallback implements HibernateCallback
|
||||
{
|
||||
private QName typeQName;
|
||||
private String name;
|
||||
public GetPermissionCallback(QName typeQName, String name)
|
||||
{
|
||||
this.typeQName = typeQName;
|
||||
this.name = name;
|
||||
}
|
||||
public Object doInHibernate(Session session)
|
||||
{
|
||||
// flush any outstanding entities
|
||||
session.flush();
|
||||
|
||||
Query query = session.getNamedQuery(HibernateHelper.QUERY_GET_PERMISSION);
|
||||
query.setParameter("permissionTypeQName", typeQName)
|
||||
.setString("permissionName", name);
|
||||
return query.uniqueResult();
|
||||
}
|
||||
}
|
||||
|
||||
private static class HibernateHelper extends HibernateDaoSupport
|
||||
{
|
||||
private static final String QUERY_GET_PERMISSION = "permission.GetPermission";
|
||||
private static final String QUERY_GET_ENTRIES_TO_CHANGE = "permission.patch.GetAccessControlEntriesToChangePermissionOn";
|
||||
|
||||
public int createAndUpdatePermission(
|
||||
final QName oldTypeQName,
|
||||
final String oldName,
|
||||
final QName newTypeQName,
|
||||
final String newName)
|
||||
{
|
||||
if (oldTypeQName.equals(newTypeQName) && oldName.equals(newName))
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot move permission to itself: " + oldTypeQName + "-" + oldName);
|
||||
}
|
||||
|
||||
HibernateCallback getNewPermissionCallback = new GetPermissionCallback(newTypeQName, newName);
|
||||
DbPermission permission = (DbPermission) getHibernateTemplate().execute(getNewPermissionCallback);
|
||||
if (permission == null)
|
||||
{
|
||||
// create the permission
|
||||
permission = new DbPermissionImpl();
|
||||
permission.setTypeQname(newTypeQName);
|
||||
permission.setName(newName);
|
||||
// save
|
||||
getHibernateTemplate().save(permission);
|
||||
}
|
||||
final DbPermission newPermission = permission;
|
||||
// now update all entries that refer to the old permission
|
||||
HibernateCallback updateEntriesCallback = new HibernateCallback()
|
||||
{
|
||||
private static final int MAX_RESULTS = 1000;
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object doInHibernate(Session session)
|
||||
{
|
||||
int count = 0;
|
||||
while (true)
|
||||
{
|
||||
// flush any outstanding entities
|
||||
session.flush();
|
||||
|
||||
Query query = session.getNamedQuery(HibernateHelper.QUERY_GET_ENTRIES_TO_CHANGE);
|
||||
query.setParameter("oldTypeQName", oldTypeQName)
|
||||
.setParameter("oldName", oldName)
|
||||
.setMaxResults(MAX_RESULTS);
|
||||
List<DbAccessControlEntry> entries = (List<DbAccessControlEntry>) query.list();
|
||||
// if there are no results, then we're done
|
||||
if (entries.size() == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
for (DbAccessControlEntry entry : entries)
|
||||
{
|
||||
entry.setPermission(newPermission);
|
||||
count++;
|
||||
session.evict(entry);
|
||||
}
|
||||
// flush and evict all the entries
|
||||
session.flush();
|
||||
for (DbAccessControlEntry entry : entries)
|
||||
{
|
||||
session.evict(entry);
|
||||
}
|
||||
// next set of results
|
||||
}
|
||||
// done
|
||||
return count;
|
||||
}
|
||||
};
|
||||
int updateCount = (Integer) getHibernateTemplate().execute(updateEntriesCallback);
|
||||
// now delete the old permission
|
||||
HibernateCallback getOldPermissionCallback = new GetPermissionCallback(oldTypeQName, oldName);
|
||||
DbPermission oldPermission = (DbPermission) getHibernateTemplate().execute(getOldPermissionCallback);
|
||||
if (oldPermission != null)
|
||||
{
|
||||
getHibernateTemplate().delete(oldPermission);
|
||||
}
|
||||
// done
|
||||
return updateCount;
|
||||
}
|
||||
}
|
||||
}
|
@@ -54,6 +54,10 @@ public class ActionRuleDecouplingPatch extends AbstractPatch
|
||||
for (NodeRef origRuleNodeRef : resultSet.getNodeRefs())
|
||||
{
|
||||
// Check that this rule need updated
|
||||
if (!this.nodeService.exists(origRuleNodeRef))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Map<QName, Serializable> origProperties = this.nodeService.getProperties(origRuleNodeRef);
|
||||
if (origProperties.containsKey(RuleModel.PROP_EXECUTE_ASYNC) == false)
|
||||
{
|
||||
@@ -79,21 +83,21 @@ public class ActionRuleDecouplingPatch extends AbstractPatch
|
||||
Map<QName, Serializable> newProperties = this.nodeService.getProperties(newRuleNodeRef);
|
||||
|
||||
// Set the rule type, execute async and applyToChildren properties on the rule
|
||||
String ruleType = (String)origProperties.get(RuleModel.PROP_RULE_TYPE);
|
||||
Serializable ruleType = origProperties.get(RuleModel.PROP_RULE_TYPE);
|
||||
origProperties.remove(RuleModel.PROP_RULE_TYPE);
|
||||
newProperties.put(RuleModel.PROP_RULE_TYPE, ruleType);
|
||||
Boolean executeAsync = (Boolean)origProperties.get(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
|
||||
Serializable executeAsync = origProperties.get(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
|
||||
origProperties.remove(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
|
||||
newProperties.put(RuleModel.PROP_EXECUTE_ASYNC, executeAsync);
|
||||
Boolean applyToChildren = (Boolean)origProperties.get(RuleModel.PROP_APPLY_TO_CHILDREN);
|
||||
Serializable applyToChildren = origProperties.get(RuleModel.PROP_APPLY_TO_CHILDREN);
|
||||
origProperties.remove(RuleModel.PROP_APPLY_TO_CHILDREN);
|
||||
newProperties.put(RuleModel.PROP_APPLY_TO_CHILDREN, applyToChildren);
|
||||
origProperties.remove(QName.createQName(RuleModel.RULE_MODEL_URI, "owningNodeRef"));
|
||||
|
||||
// Move the action and description values from the composite action onto the rule
|
||||
String title = (String)origProperties.get(ActionModel.PROP_ACTION_TITLE);
|
||||
Serializable title = origProperties.get(ActionModel.PROP_ACTION_TITLE);
|
||||
origProperties.remove(ActionModel.PROP_ACTION_TITLE);
|
||||
String description = (String)origProperties.get(ActionModel.PROP_ACTION_DESCRIPTION);
|
||||
Serializable description = origProperties.get(ActionModel.PROP_ACTION_DESCRIPTION);
|
||||
origProperties.remove(ActionModel.PROP_ACTION_DESCRIPTION);
|
||||
newProperties.put(ContentModel.PROP_TITLE, title);
|
||||
newProperties.put(ContentModel.PROP_DESCRIPTION, description);
|
||||
|
@@ -16,33 +16,40 @@
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Roles defined in permissionsDefinition.xml moved from <b>cm:content</b> to <b>sys:base</b>.
|
||||
* This effects the data stored in the <b>node_perm_entry</b> table.
|
||||
* <p>
|
||||
* <b>WILL NOT EXECUTE ANYMORE</b>
|
||||
* This effects the data stored in the <b>permission</b> table.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ContentPermissionPatch extends AbstractPatch
|
||||
public class ContentPermissionPatch extends AbstractPermissionChangePatch
|
||||
{
|
||||
private static final String MSG_UPGRADE = "patch.contentPermission.upgrade";
|
||||
|
||||
public ContentPermissionPatch()
|
||||
{
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory)
|
||||
{
|
||||
}
|
||||
private static final String MSG_SUCCESS = "patch.contentPermission.result";
|
||||
|
||||
private static final QName TYPE_QNAME_OLD = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "content");
|
||||
private static final QName TYPE_QNAME_NEW = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "base");
|
||||
private static final String[] NAMES = new String[] {"Execute", "ReadContent", "WriteContent", "ExecuteContent"};
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
throw new PatchException(MSG_UPGRADE);
|
||||
int updateCount = 0;
|
||||
for (String permissionName : NAMES)
|
||||
{
|
||||
updateCount += super.renamePermission(
|
||||
ContentPermissionPatch.TYPE_QNAME_OLD,
|
||||
permissionName,
|
||||
ContentPermissionPatch.TYPE_QNAME_NEW,
|
||||
permissionName);
|
||||
}
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, updateCount);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
@@ -16,35 +16,42 @@
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* The roles defined in permissionsDefinition.xml moved from <b>cm:folder</b> to <b>cm:cmobject</b>.
|
||||
* This effects the data stored in the <b>node_perm_entry</b> table.
|
||||
* This effects the data stored in the <b>permission</b> table.
|
||||
* <p>
|
||||
* JIRA: {@link http://www.alfresco.org/jira/browse/AR-344 AR-344}
|
||||
* <p>
|
||||
* <b>WILL NOT EXECUTE ANYMORE</b>
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class PermissionDataPatch extends AbstractPatch
|
||||
public class PermissionDataPatch extends AbstractPermissionChangePatch
|
||||
{
|
||||
private static final String MSG_UPGRADE = "patch.updatePermissionData.upgrade";
|
||||
|
||||
public PermissionDataPatch()
|
||||
{
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory)
|
||||
{
|
||||
}
|
||||
private static final String MSG_SUCCESS = "patch.updatePermissionData.result";
|
||||
|
||||
private static final QName TYPE_QNAME_OLD = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "folder");
|
||||
private static final QName TYPE_QNAME_NEW = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "cmobject");
|
||||
private static final String[] NAMES = new String[] {"Coordinator", "Contributor", "Editor", "Guest"};
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
throw new PatchException(MSG_UPGRADE);
|
||||
int updateCount = 0;
|
||||
for (String permissionName : NAMES)
|
||||
{
|
||||
updateCount += super.renamePermission(
|
||||
PermissionDataPatch.TYPE_QNAME_OLD,
|
||||
permissionName,
|
||||
PermissionDataPatch.TYPE_QNAME_NEW,
|
||||
permissionName);
|
||||
}
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, updateCount);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,6 +31,7 @@ import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.ChildAssoc;
|
||||
import org.alfresco.repo.domain.Node;
|
||||
import org.alfresco.repo.node.db.NodeDaoService;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
@@ -51,6 +53,7 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
public class UniqueChildNamePatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.uniqueChildName.result";
|
||||
private static final String ERR_UNABLE_TO_FIX = "patch.uniqueChildName.err.unable_to_fix";
|
||||
private static final String MSG_COPY_OF = "patch.uniqueChildName.copyOf";
|
||||
/** the number of associations to process at a time */
|
||||
private static final int MAX_RESULTS = 1000;
|
||||
@@ -143,6 +146,7 @@ public class UniqueChildNamePatch extends AbstractPatch
|
||||
@SuppressWarnings("unused")
|
||||
List<QName> assocTypeQNames = getUsedAssocQNames();
|
||||
|
||||
boolean unableToFix = false;
|
||||
int fixed = 0;
|
||||
int processed = 0;
|
||||
// check loop through all associations, looking for duplicates
|
||||
@@ -185,8 +189,10 @@ public class UniqueChildNamePatch extends AbstractPatch
|
||||
String usedChildName = childName;
|
||||
processed++;
|
||||
boolean duplicate = false;
|
||||
int duplicateNumber = 0;
|
||||
while(true)
|
||||
{
|
||||
duplicateNumber++;
|
||||
try
|
||||
{
|
||||
// push the name back to the node
|
||||
@@ -195,11 +201,46 @@ public class UniqueChildNamePatch extends AbstractPatch
|
||||
}
|
||||
catch (DuplicateChildNodeNameException e)
|
||||
{
|
||||
// there was a duplicate, so adjust the name and change the node property
|
||||
duplicate = true;
|
||||
// assign a new name
|
||||
usedChildName = childName + I18NUtil.getMessage(MSG_COPY_OF, processed);
|
||||
// try again
|
||||
if (duplicateNumber == 10)
|
||||
{
|
||||
// Try removing the secondary parent associations
|
||||
writeLine(" Removing secondary parents of node " + childNode.getId());
|
||||
Collection<ChildAssoc> parentAssocs = childNode.getParentAssocs();
|
||||
for (ChildAssoc parentAssoc : parentAssocs)
|
||||
{
|
||||
if (!parentAssoc.getIsPrimary())
|
||||
{
|
||||
write(" - ").writeLine(parentAssoc);
|
||||
// remove it
|
||||
getSession().delete(parentAssoc);
|
||||
}
|
||||
}
|
||||
// flush to ensure the database gets the changes
|
||||
getSession().flush();
|
||||
// try again to be sure
|
||||
continue;
|
||||
}
|
||||
else if (duplicateNumber > 10)
|
||||
{
|
||||
// after 10 attempts, we have to admit defeat. Perhaps there is a larger issue.
|
||||
Collection<ChildAssoc> parentAssocs = childNode.getParentAssocs();
|
||||
write(" Unable to set child name '" + usedChildName + "' for node " + childNode.getId());
|
||||
writeLine(" with parent associations:");
|
||||
for (ChildAssoc parentAssoc : parentAssocs)
|
||||
{
|
||||
write(" - ").writeLine(parentAssoc);
|
||||
}
|
||||
duplicate = false;
|
||||
unableToFix = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there was a duplicate, so adjust the name and change the node property
|
||||
duplicate = true;
|
||||
// assign a new name
|
||||
usedChildName = childName + I18NUtil.getMessage(MSG_COPY_OF, processed, duplicateNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if duplicated, report it
|
||||
@@ -209,11 +250,11 @@ public class UniqueChildNamePatch extends AbstractPatch
|
||||
// get the node path
|
||||
NodeRef parentNodeRef = childAssoc.getParent().getNodeRef();
|
||||
Path path = nodeService.getPath(parentNodeRef);
|
||||
writeLine(" Changed duplicated child name:");
|
||||
writeLine(" Parent: " + parentNodeRef);
|
||||
writeLine(" Parent path: " + path);
|
||||
writeLine(" Duplicate name: " + childName);
|
||||
writeLine(" Replaced with: " + usedChildName);
|
||||
writeLine(" Changed duplicated child name:");
|
||||
writeLine(" Parent: " + parentNodeRef);
|
||||
writeLine(" Parent path: " + path);
|
||||
writeLine(" Duplicate name: " + childName);
|
||||
writeLine(" Replaced with: " + usedChildName);
|
||||
}
|
||||
}
|
||||
// clear the session to preserve memory
|
||||
@@ -222,10 +263,17 @@ public class UniqueChildNamePatch extends AbstractPatch
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, processed, fixed, logFile);
|
||||
return msg;
|
||||
// check if it was successful or not
|
||||
if (unableToFix)
|
||||
{
|
||||
throw new PatchException(ERR_UNABLE_TO_FIX, logFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, processed, fixed, logFile);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@@ -16,32 +16,27 @@
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
|
||||
/**
|
||||
* The permission 'Guest' has been renamed to 'Consumer'.
|
||||
* <p>
|
||||
* <b>WILL NOT EXECUTE ANYMORE</b>
|
||||
*
|
||||
* @author David Caruana
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class UpdateGuestPermissionPatch extends AbstractPatch
|
||||
public class UpdateGuestPermissionPatch extends AbstractPermissionChangePatch
|
||||
{
|
||||
private static final String MSG_UPGRADE = "patch.updateGuestPermission.upgrade";
|
||||
|
||||
public UpdateGuestPermissionPatch()
|
||||
{
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory)
|
||||
{
|
||||
}
|
||||
private static final String MSG_SUCCESS = "patch.updateGuestPermission.result";
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
throw new PatchException(MSG_UPGRADE);
|
||||
int updateCount = super.renamePermission(ContentModel.TYPE_CMOBJECT, "Guest", ContentModel.TYPE_CMOBJECT, "Consumer");
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, updateCount);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user