Merge V1.4 to HEAD

- Ignored Enterprise-specific changes
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3701 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3703 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3704 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3705 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3707 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3876 .
   svn revert root\projects\web-client\source\web\jsp\admin\admin-console.jsp


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3879 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-09-21 23:35:51 +00:00
parent 89f39cd176
commit d2bce74f0b
103 changed files with 3569 additions and 1172 deletions

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.dictionary.M2Model;
import org.alfresco.repo.domain.hibernate.ChildAssocImpl;
import org.alfresco.repo.domain.hibernate.NodeImpl;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
@@ -161,6 +162,9 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
// downgrade integrity checks
IntegrityChecker.setWarnInTransaction();
}
@Override

View File

@@ -27,6 +27,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.DictionaryComponent;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.M2Model;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
@@ -160,6 +161,7 @@ public class PerformanceNodeServiceTest extends TestCase
{
public Object doWork()
{
IntegrityChecker.setWarnInTransaction();
buildNodeChildren(rootNodeRef, 1, testDepth, testChildCount);
return null;
}

View File

@@ -29,6 +29,7 @@ import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.StoreArchiveMap;
import org.alfresco.repo.node.archive.RestoreNodeReport.RestoreStatus;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.ServiceRegistry;
@@ -37,7 +38,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService;
@@ -114,6 +114,9 @@ public class ArchiveAndRestoreTest extends TestCase
txn = transactionService.getUserTransaction();
txn.begin();
// downgrade integrity checks
IntegrityChecker.setWarnInTransaction();
try
{
authenticationComponent.setSystemUserAsCurrentUser();

View File

@@ -40,7 +40,6 @@ import org.alfresco.repo.domain.Store;
import org.alfresco.repo.node.AbstractNodeServiceImpl;
import org.alfresco.repo.node.StoreArchiveMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
@@ -1461,15 +1460,12 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
nodeToMove.setStore(store);
NodeRef newNodeRef = nodeToMove.getNodeRef();
String txnId = AlfrescoTransactionSupport.getTransactionId();
// update old status
NodeStatus oldNodeStatus = nodeDaoService.getNodeStatus(oldNodeRef, true);
oldNodeStatus.setNode(null);
oldNodeStatus.getTransaction().setChangeTxnId(txnId);
// create the new status
NodeStatus newNodeStatus = nodeDaoService.getNodeStatus(newNodeRef, true);
newNodeStatus.setNode(nodeToMove);
newNodeStatus.getTransaction().setChangeTxnId(txnId);
}
}

View File

@@ -17,6 +17,7 @@
package org.alfresco.repo.node.db;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -30,6 +31,8 @@ import org.alfresco.repo.node.BaseNodeServiceTest;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -47,6 +50,7 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
{
private TransactionService txnService;
private NodeDaoService nodeDaoService;
private DictionaryService dictionaryService;
protected NodeService getNodeService()
{
@@ -59,6 +63,7 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
super.onSetUpInTransaction();
txnService = (TransactionService) applicationContext.getBean("transactionComponent");
nodeDaoService = (NodeDaoService) applicationContext.getBean("nodeDaoService");
dictionaryService = (DictionaryService) applicationContext.getBean("dictionaryService");
}
/**
@@ -258,18 +263,34 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
/**
* Checks that the string_value retrieval against a property type is working
*/
public void testGetContentDataStringValues() throws Exception
public void testGetContentDataValues() throws Exception
{
ContentData contentData = new ContentData("abc", MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null);
// put this in as a random property
final DataTypeDefinition contentDataType = dictionaryService.getDataType(DataTypeDefinition.CONTENT);
ContentData contentDataSingle = new ContentData("url-single", MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null);
ContentData contentDataMultiple = new ContentData("url-multiple", MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null);
// put this in as a random single property
nodeService.setProperty(
rootNodeRef,
QName.createQName(NAMESPACE, "random"),
contentData);
QName.createQName(NAMESPACE, "random-single"),
contentDataSingle);
// create a collection of mixed types
ArrayList<Serializable> collection = new ArrayList<Serializable>(3);
collection.add("abc");
collection.add(new Integer(123));
collection.add(contentDataMultiple);
nodeService.setProperty(
rootNodeRef,
QName.createQName(NAMESPACE, "random-multiple"),
collection);
// get a list of all content values
List<String> contentDataStrings = nodeDaoService.getContentDataStrings();
assertNotNull(contentDataStrings);
assertTrue("ContentData not represented as a String in results",
contentDataStrings.contains(contentData.toString()));
List<Serializable> allContentDatas = nodeDaoService.getPropertyValuesByActualType(contentDataType);
assertTrue("At least two instances expected", allContentDatas.size() >= 2);
assertTrue("Single content data not present in results",
allContentDatas.contains(contentDataSingle));
assertTrue("Multi-valued buried content data not present in results",
allContentDatas.contains(contentDataMultiple));
}
}

View File

@@ -16,6 +16,7 @@
*/
package org.alfresco.repo.node.db;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
@@ -24,6 +25,7 @@ import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeAssoc;
import org.alfresco.repo.domain.NodeStatus;
import org.alfresco.repo.domain.Store;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -76,11 +78,12 @@ public interface NodeDaoService
* <code>null</code> is returned.
*
* @param nodeRef the node reference
* @param create true to create the entity if it doesn't exist
* @param create true if the node status is to be updated in the transaction, i.e.
* the current transaction must be assigned to the status
* @return Returns the node status if the node exists or once existed, otherwise
* returns <code>null</code> if <code>create == false</code>
*/
public NodeStatus getNodeStatus(NodeRef nodeRef, boolean create);
public NodeStatus getNodeStatus(NodeRef nodeRef, boolean update);
/**
* Sets the current transaction ID on the node status. Note that the node
@@ -224,10 +227,10 @@ public interface NodeDaoService
public void deleteNodeAssoc(NodeAssoc assoc);
/**
* Fetch all content data strings. These are all string values that begin
* with <b>contentUrl=</b>.
* Fetch all property values for the given type definition. This will also dig out values that
* were persisted as type <b>d:any</b>.
*
* @return Returns the string values for content data
* @return Returns the values for the given type definition
*/
public List<String> getContentDataStrings();
public List<Serializable> getPropertyValuesByActualType(DataTypeDefinition actualDataTypeDefinition);
}

View File

@@ -22,10 +22,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import java.util.zip.CRC32;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -35,6 +33,7 @@ import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeAssoc;
import org.alfresco.repo.domain.NodeKey;
import org.alfresco.repo.domain.NodeStatus;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.domain.Server;
import org.alfresco.repo.domain.Store;
import org.alfresco.repo.domain.StoreKey;
@@ -48,19 +47,25 @@ import org.alfresco.repo.domain.hibernate.StoreImpl;
import org.alfresco.repo.domain.hibernate.TransactionImpl;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionAwareSingleton;
import org.alfresco.repo.transaction.TransactionalDao;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.repository.AssociationExistsException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.repository.datatype.TypeConverter;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.ObjectDeletedException;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
@@ -83,7 +88,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
private static final String QUERY_GET_NODE_ASSOCS_TO_AND_FROM = "node.GetNodeAssocsToAndFrom";
private static final String QUERY_GET_TARGET_ASSOCS = "node.GetTargetAssocs";
private static final String QUERY_GET_SOURCE_ASSOCS = "node.GetSourceAssocs";
private static final String QUERY_GET_CONTENT_DATA_STRINGS = "node.GetContentDataStrings";
private static final String QUERY_GET_NODES_WITH_PROPERTY_VALUES_BY_ACTUAL_TYPE = "node.GetNodesWithPropertyValuesByActualType";
private static final String QUERY_GET_SERVER_BY_IPADDRESS = "server.getServerByIpAddress";
private static Log logger = LogFactory.getLog(HibernateNodeDaoServiceImpl.class);
@@ -91,9 +96,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
/** a uuid identifying this unique instance */
private final String uuid;
private final ReadLock serverReadLock;
private final WriteLock serverWriteLock;
private Server server;
private static TransactionAwareSingleton<Long> serverIdSingleton = new TransactionAwareSingleton<Long>();
/**
*
@@ -101,10 +104,6 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
public HibernateNodeDaoServiceImpl()
{
this.uuid = GUID.generate();
ReentrantReadWriteLock serverReadWriteLock = new ReentrantReadWriteLock();
serverReadLock = serverReadWriteLock.readLock();
serverWriteLock = serverReadWriteLock.writeLock();
}
/**
@@ -137,21 +136,16 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
*/
private Server getServer()
{
// get readlock
serverReadLock.lock();
try
Long serverId = serverIdSingleton.get();
Server server = null;
if (serverId != null)
{
server = (Server) getSession().get(ServerImpl.class, serverId);
if (server != null)
{
return server;
}
}
finally
{
serverReadLock.unlock();
}
// get the write lock
serverWriteLock.lock();
try
{
final String ipAddress = InetAddress.getLocalHost().getHostAddress();
@@ -185,16 +179,15 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
}
}
}
// push the value into the singleton
serverIdSingleton.put(server.getId());
return server;
}
catch (Exception e)
{
throw new AlfrescoRuntimeException("Failed to create server instance", e);
}
finally
{
serverWriteLock.unlock();
}
}
private static final String RESOURCE_KEY_TRANSACTION_ID = "hibernate.transaction.id";
@@ -307,7 +300,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
/**
* Fetch the node status, if it exists
*/
public NodeStatus getNodeStatus(NodeRef nodeRef, boolean create)
public NodeStatus getNodeStatus(NodeRef nodeRef, boolean update)
{
NodeKey nodeKey = new NodeKey(nodeRef);
NodeStatus status = null;
@@ -325,13 +318,18 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
throw e;
}
// create if necessary
if (status == null && create)
if (status == null && update)
{
status = new NodeStatusImpl();
status.setKey(nodeKey);
status.setTransaction(getCurrentTransaction());
getHibernateTemplate().save(status);
}
else if (status != null && update)
{
// update the transaction
status.setTransaction(getCurrentTransaction());
}
// done
return status;
}
@@ -934,18 +932,62 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
getSession().flush();
}
@SuppressWarnings("unchecked")
public List<String> getContentDataStrings()
public List<Serializable> getPropertyValuesByActualType(DataTypeDefinition actualDataTypeDefinition)
{
// get the in-database string representation of the actual type
QName typeQName = actualDataTypeDefinition.getName();
final String actualTypeString = PropertyValue.getActualTypeString(typeQName);
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
Query query = session.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CONTENT_DATA_STRINGS);
return query.list();
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_NODES_WITH_PROPERTY_VALUES_BY_ACTUAL_TYPE)
.setString("actualTypeString", actualTypeString);
return query.scroll(ScrollMode.FORWARD_ONLY);
}
};
List<String> queryResults = (List) getHibernateTemplate().execute(callback);
return queryResults;
ScrollableResults results = (ScrollableResults) getHibernateTemplate().execute(callback);
// Loop through, extracting content URLs
List<Serializable> convertedValues = new ArrayList<Serializable>(1000);
TypeConverter converter = DefaultTypeConverter.INSTANCE;
while(results.next())
{
Node node = (Node) results.get()[0];
// loop through all the node properties
Map<QName, PropertyValue> properties = node.getProperties();
for (PropertyValue propertyValue : properties.values())
{
// ignore nulls
if (propertyValue == null)
{
continue;
}
// Get the actual value(s) as a collection
Collection<Serializable> values = propertyValue.getCollection(DataTypeDefinition.ANY);
// attempt to convert instance in the collection
for (Serializable value : values)
{
// ignore nulls (null entries in collections)
if (value == null)
{
continue;
}
try
{
Serializable convertedValue = (Serializable) converter.convert(actualDataTypeDefinition, value);
// it converted, so add it
convertedValues.add(convertedValue);
}
catch (Throwable e)
{
// The value can't be converted - forget it
}
}
}
// evict all data from the session
getSession().clear();
}
return convertedValues;
}
}

View File

@@ -88,6 +88,8 @@ public class IntegrityChecker
/** key against which the set of events is stored in the current transaction */
private static final String KEY_EVENT_SET = "IntegrityChecker.EventSet";
/** key to store the local flag to disable integrity errors, i.e. downgrade to warnings */
private static final String KEY_WARN_IN_TRANSACTION = "IntegrityChecker.WarnInTransaction";
private PolicyComponent policyComponent;
private DictionaryService dictionaryService;
@@ -97,6 +99,36 @@ public class IntegrityChecker
private int maxErrorsPerTransaction;
private boolean traceOn;
/**
* Downgrade violations to warnings within the current transaction. This is temporary and
* is <u>dependent on there being a current transaction</u> active against the
* current thread. When set, this will override the global
* {@link #setFailOnViolation(boolean) failure behaviour}.
*/
public static void setWarnInTransaction()
{
AlfrescoTransactionSupport.bindResource(KEY_WARN_IN_TRANSACTION, Boolean.TRUE);
}
/**
* @return Returns true if the current transaction should only warn on violations.
* If <code>false</code>, the global setting will take effect.
*
* @see #setWarnInTransaction()
*/
public static boolean isWarnInTransaction()
{
Boolean warnInTransaction = (Boolean) AlfrescoTransactionSupport.getResource(KEY_WARN_IN_TRANSACTION);
if (warnInTransaction == null || warnInTransaction == Boolean.FALSE)
{
return false;
}
else
{
return true;
}
}
/**
*/
public IntegrityChecker()
@@ -572,7 +604,8 @@ public class IntegrityChecker
}
sb.append("\n").append(failure);
}
if (failOnViolation)
boolean warnOnly = IntegrityChecker.isWarnInTransaction();
if (failOnViolation && !warnOnly)
{
logger.error(sb.toString());
throw new IntegrityException(failures);

View File

@@ -198,6 +198,18 @@ public class IntegrityTest extends TestCase
assertNotNull("Static IntegrityChecker not created", integrityChecker);
}
public void testTemporaryDowngrading() throws Exception
{
assertEquals("Per-transaction override not correct", false, IntegrityChecker.isWarnInTransaction());
// create bad node
NodeRef nodeRef = createNode("abc", TEST_TYPE_WITH_PROPERTIES, null);
// switch it off
IntegrityChecker.setWarnInTransaction();
assertEquals("Per-transaction override not correct", true, IntegrityChecker.isWarnInTransaction());
// now, only warnings should occur
checkIntegrityNoFailure();
}
public void testCreateWithoutProperties() throws Exception
{
NodeRef nodeRef = createNode("abc", TEST_TYPE_WITH_PROPERTIES, null);