Merged V1.4 to HEAD

svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3987 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4133 .
   Removed LicenseComponent reference from projects\repository\source\java\org\alfresco\repo\descriptor\DescriptorServiceImpl.java


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-10-17 22:42:59 +00:00
parent 4f1682e8d0
commit be167f60cf
106 changed files with 5379 additions and 2646 deletions

View File

@@ -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;
}
}
}

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}