Schema changes and ID-based node storage

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2727 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-04-28 12:54:29 +00:00
parent 2b251c922b
commit 7edcb18bc0
64 changed files with 2798 additions and 2820 deletions

View File

@@ -1,127 +1,48 @@
/*
* 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.ArrayList;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl;
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;
/**
* 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.
*
* @author Derek Hulley
*/
public class ContentPermissionPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.contentPermission.result";
private HibernateHelper helper;
public ContentPermissionPatch()
{
helper = new HibernateHelper();
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.helper.setSessionFactory(sessionFactory);
}
@Override
protected String applyInternal() throws Exception
{
List<String> createdNames = helper.createPermissionReferences();
int updatedEntries = helper.updatePermissionEntries();
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, createdNames, updatedEntries);
// done
return msg;
}
private static class HibernateHelper extends HibernateDaoSupport
{
private static final String TYPE_URI_OLD = "http://www.alfresco.org/model/content/1.0";
private static final String TYPE_NAME_OLD = "content";
private static final String TYPE_URI_NEW = "http://www.alfresco.org/model/system/1.0";
private static final String TYPE_NAME_NEW = "base";
private static final String[] NAMES = new String[] {"Execute", "ReadContent", "WriteContent", "ExecuteContent"};
private static final String QUERY_UPDATE_PERM_ENTRY_TYPE = "permission.patch.UpdatePermissionEntryType";
public List<String> createPermissionReferences()
{
List<String> createdNames = new ArrayList<String>(4);
for (String name : NAMES)
{
// create permission references as required, double checking for their existence first
PermissionReference ref = new PermissionReferenceImpl();
ref.setTypeUri(TYPE_URI_NEW);
ref.setTypeName(TYPE_NAME_NEW);
ref.setName(name);
// it acts as its own key
PermissionReference found = (PermissionReference) getHibernateTemplate().get(
PermissionReferenceImpl.class,
ref);
if (found == null)
{
// it was not found, so create it
getHibernateTemplate().save(ref);
createdNames.add(QName.createQName(TYPE_URI_NEW, TYPE_NAME_NEW).toString() + "/" + name);
}
}
return createdNames;
}
public int updatePermissionEntries()
{
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
// flush any outstanding entities
session.flush();
Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_TYPE);
query.setString("typeNameNew", TYPE_NAME_NEW)
.setString("typeNameOld", TYPE_NAME_OLD)
.setString("typeUriNew", TYPE_URI_NEW)
.setString("typeUriOld", TYPE_URI_OLD)
.setParameterList("names", NAMES);
int updateCount = query.executeUpdate();
return new Integer(updateCount);
}
};
Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
// done
return updateCount.intValue();
}
}
}
/*
* 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 org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.service.cmr.admin.PatchException;
import org.hibernate.SessionFactory;
/**
* 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>
*
* @author Derek Hulley
*/
public class ContentPermissionPatch extends AbstractPatch
{
private static final String MSG_UPGRADE = "patch.contentPermission.upgrade";
public ContentPermissionPatch()
{
}
public void setSessionFactory(SessionFactory sessionFactory)
{
}
@Override
protected String applyInternal() throws Exception
{
throw new PatchException(MSG_UPGRADE);
}
}

View File

@@ -64,7 +64,7 @@ public class GuestPersonPermissionPatch extends AbstractPatch
{
NodeRef personRef = personService.getPerson(guestId);
permissionService.setInheritParentPermissions(personRef, false);
permissionService.deletePermission(personRef, guestId, PermissionService.CONSUMER, true);
permissionService.deletePermission(personRef, guestId, PermissionService.CONSUMER);
permissionService.setPermission(personRef, guestId, PermissionService.READ, true);
}

View File

@@ -16,108 +16,35 @@
*/
package org.alfresco.repo.admin.patch.impl;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl;
import org.alfresco.service.namespace.NamespaceService;
import org.hibernate.Query;
import org.hibernate.Session;
import org.alfresco.service.cmr.admin.PatchException;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* 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.
* <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
{
private static final String MSG_SUCCESS = "patch.updatePermissionData.result";
private HibernateHelper helper;
private static final String MSG_UPGRADE = "patch.updatePermissionData.upgrade";
public PermissionDataPatch()
{
helper = new HibernateHelper();
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.helper.setSessionFactory(sessionFactory);
}
@Override
protected String applyInternal() throws Exception
{
List<String> createdNames = helper.createPermissionReferences();
int updatedEntries = helper.updatePermissionEntries();
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, createdNames, updatedEntries);
// done
return msg;
}
private static class HibernateHelper extends HibernateDaoSupport
{
private static final String TYPE_NAME_OLD = "folder";
private static final String TYPE_NAME_NEW = "cmobject";
private static final String[] NAMES = new String[] {"Coordinator", "Contributor", "Editor", "Guest"};
private static final String QUERY_UPDATE_PERM_ENTRY_TYPENAME = "permission.patch.UpdatePermissionEntryTypeName";
public List<String> createPermissionReferences()
{
List<String> createdNames = new ArrayList<String>(4);
for (String name : NAMES)
{
// create permission references as required, double checking for their existence first
PermissionReference ref = new PermissionReferenceImpl();
ref.setTypeUri(NamespaceService.CONTENT_MODEL_1_0_URI);
ref.setTypeName(TYPE_NAME_NEW);
ref.setName(name);
// it acts as its own key
PermissionReference found = (PermissionReference) getHibernateTemplate().get(
PermissionReferenceImpl.class,
ref);
if (found == null)
{
// it was not found, so create it
getHibernateTemplate().save(ref);
createdNames.add(name);
}
}
return createdNames;
}
public int updatePermissionEntries()
{
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
// flush any outstanding entities
session.flush();
Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_TYPENAME);
query.setString("typeNameNew", TYPE_NAME_NEW)
.setString("typeNameOld", TYPE_NAME_OLD);
int updateCount = query.executeUpdate();
return new Integer(updateCount);
}
};
Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
// done
return updateCount.intValue();
}
throw new PatchException(MSG_UPGRADE);
}
}

View File

@@ -62,7 +62,7 @@ public class SpacesRootPermissionPatch extends AbstractPatch
protected String applyInternal() throws Exception
{
NodeRef rootNodeRef = nodeService.getRootNode(spacesBootstrap.getStoreRef());
permissionService.deletePermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER, true);
permissionService.deletePermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER);
permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true);
return I18NUtil.getMessage(MSG_SUCCESS);

View File

@@ -1,123 +1,47 @@
/*
* 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.ArrayList;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl;
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;
/**
* The permission 'Guest' has been renamed to 'Consumer'.
*
* @author David Caruana
*/
public class UpdateGuestPermissionPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.updateGuestPermission.result";
private HibernateHelper helper;
public UpdateGuestPermissionPatch()
{
helper = new HibernateHelper();
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.helper.setSessionFactory(sessionFactory);
}
@Override
protected String applyInternal() throws Exception
{
List<String> createdNames = helper.createPermissionReferences();
int updatedPermEntries = helper.updatePermissionEntries();
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, createdNames, updatedPermEntries);
// done
return msg;
}
private static class HibernateHelper extends HibernateDaoSupport
{
private static final String NAME_OLD = "Guest";
private static final String NAME_NEW = "Consumer";
private static final String[] NAMES = new String[] {"Consumer"};
private static final String QUERY_UPDATE_PERM_ENTRY_NAME = "permission.patch.UpdatePermissionName";
public List<String> createPermissionReferences()
{
List<String> createdNames = new ArrayList<String>(4);
for (String name : NAMES)
{
// create permission references as required, double checking for their existence first
PermissionReference ref = new PermissionReferenceImpl();
ref.setTypeUri(ContentModel.TYPE_CMOBJECT.getNamespaceURI());
ref.setTypeName(ContentModel.TYPE_CMOBJECT.getLocalName());
ref.setName(name);
// it acts as its own key
PermissionReference found = (PermissionReference) getHibernateTemplate().get(
PermissionReferenceImpl.class,
ref);
if (found == null)
{
// it was not found, so create it
getHibernateTemplate().save(ref);
createdNames.add(name);
}
}
return createdNames;
}
public int updatePermissionEntries()
{
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
// flush any outstanding entities
session.flush();
Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_NAME);
query.setString("nameNew", NAME_NEW)
.setString("nameOld", NAME_OLD);
int updateCount = query.executeUpdate();
return new Integer(updateCount);
}
};
Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
// done
return updateCount.intValue();
}
}
}
/*
* 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 org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.service.cmr.admin.PatchException;
import org.hibernate.SessionFactory;
/**
* The permission 'Guest' has been renamed to 'Consumer'.
* <p>
* <b>WILL NOT EXECUTE ANYMORE</b>
*
* @author David Caruana
*/
public class UpdateGuestPermissionPatch extends AbstractPatch
{
private static final String MSG_UPGRADE = "patch.updateGuestPermission.upgrade";
public UpdateGuestPermissionPatch()
{
}
public void setSessionFactory(SessionFactory sessionFactory)
{
}
@Override
protected String applyInternal() throws Exception
{
throw new PatchException(MSG_UPGRADE);
}
}