Merged V4.1-BUG-FIX to HEAD

44674: Fix for ALF-17189 - The "Company Home" item in the top navigator menu and in the toolbar panel is invisible, if login as guest first then directly access the login page via URL.
   44701: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.1-BUG-FIX
      44700: Fix for ALF-10369 - support for OPTIONS requests for WebScript framework and Share proxy
   44709: ALF-17164 Fix version.properties which was wrong in sdk zip
   44710: ALF-14570 ("Check out" outboud rule works incorrect)
   44722: MNT-246: Need the ability to configure a proxy with Enterprise Sync.
      - RemoteConnectorServiceImpl will now use an http/https proxy if the standard system properties for Java network proxy configuration are found. See http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html (Section 2.1 and 2.2)
   44730: Merged V4.1 to V4.1-BUG-FIX
      44461: Merged PATCHES/V4.1.1 to V4.1
         44060: ALF-16962 / MNT-221 Links from a deleted user cause error in the "Links" page 
         44129: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap
         - Now we emulate the behaviour of ACLEntryAfterInvocationProvider in SolrQueryHTTPClient, thus limiting otherwise unconstrained SOLR queries to return a finite number of results
         - New solr subsystem parameter solr.query.maximumResultsFromUnlimitedQuery introduced
         - Its default value is ${system.acl.maxPermissionChecks}, thus providing backward compatibility with old behaviour (1000 results max)
         - When there are no other limits in the search parameters, this value will be used to limit the number of results
         - SolrJSONResultSet.getResultSetMetata().getLimitedBy() will return an appropriate LimitBy value, according to how the query was limited
         44130: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap
         - Improved calculation of SolrJSONResultSet.getResultSetMetata().getLimitedBy() to better emulate ACLEntryAfterInvocationProvider
         44141: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap
         - Correction to handling of limited queries (Share search works again!)
         44291: ALF-17094 / MNT-222 InvalidNodeRefException on user deletion in Share UI 
      44462: Merged PATCHES/V4.0.2 to V4.1
         44221: ALF-17038 / MNT-226: Out-of-order versions for existing data during migration from 3.4.9 to 4.0.2.19
            - Have been able to remove the need for any Comparators in the normal case.
              As Dave said, he thought it was ordered already. It is with "assoc.assoc_index ASC, assoc.id ASC".
              Required a bit of re factoring of Version2ServiceImpl to do it as they were referenced/used in a couple of other classes.
            - Modified all 43 Oracle sequences to include ORDER in the create statement.
              Probably only really was needed to do it on alf_child_assoc_seq to fix this issue, but it will stop similar issues in
              other clustered database setups. Did not change the upgrade scripts, as this will give us a clue that there will be
              existing data issues.
            - The name of a Comparator<Version> may be specified in the Alfresco global property:
              org.alfresco.repo.version.common.VersionLabelComparator and it will be used by BOTH Version2ServiceImpl and VersionServiceImpl.
              They in turn pass it on to Version2ServiceImpl instances when they create them.
            - A VersionLabelComparator already existed (still deprecated as we don't normally use it) and works:
              org.alfresco.repo.version.common.VersionLabelComparator.
            - Customers with out of sequence ids on Oracle RDBMS using a clustered database may 'correct on the fly' the order of their
              versions by setting the alfresco global property described above.
            - Have tested both with and without a comparator in development environment. Using break points and Collections.shuffle(version)
              in an expression was able to simulate out of order IDs.
            - New unit tests added to VersionHistoryImplTest and VersionServiceImplTest to test db ids out of order
         44336: ALF-15935: Fixed SecureContext errors when ticket has expired. MNT-180
      44467: Fixed compilation failure
      44520: ALF-16590: Improved fix after testing by Mark Lugert
      44563: Merged DEV to V4.1 (with corrections)
         44547: ALF-17132: Possible XSS - arbitrary url parameters re-sent to the browser
            Escaping of keys and values of request attributes
      44610: Merged PATCHES/V4.0.2 to V4.1
         44435: ALF-17183: Merged DEV to V4.0.2 (4.0.2.22)
            44429: MNT-232: Upgrade from 3.4.9 to 4.0.2 - FAILED
            - Initialize rootRefs in the property definition to prevent NPE.
         44591: Fix to CIFS reported user free space when disk quotas are not enabled. 
         44595: ALF-17184 / MNT-243 Minimal fix for disk size and user quotas.   (Bring values into line with API.)
         44601: ALF-17184 / MNT-243 - Implementation of file size on Abstract Tennant Routing Content Store.
         44608: ALF-15935 / MNT-180: Moved closeFile() call to closeConnection() cleanup method, always call closeFile()
         Do not check if file is marked as closed during cleanup, only open files should still be in the file table.
      44652: ALF-17117: Created article or publication cant be viewed on WQS site
      - Fixes by Dmitry Vaserin
      - Removed unnecessary outer read locks from getRelatedAssets and getRelatedAsset to prevent deadlock
      - Correct markup error when node doesn't have tags
      44653: ALF-17117: Created article or publication cant be viewed on WQS site
      - Missed file from previous checkin
      44682: ALF-17118 WQS: Impossible to upload document to publications space
         - Only first part to do with the transformation failure has been committed. 
   44731: Merged V4.1 to V4.1-BUG-FIX (RECORD ONLY)
      44441: Merge V4.1-BUG-FIX to V4.1
         44270: Merge V3.4-BUG-FIX to V4.1-BUG-FIX
            44266: BDE-111: harden generation of Windows installers
               - make sure build fails if installer generation fails
               - generate Windows unsigned installers in a place that is cleaned later, avoiding leftovers
      44598: Merged V4.1-BUG-FIX to V4.1
         44541: Fix for     ALF-17151   SOLR - add support to disable permission checks
         44577: Final part for     ALF-16558 SOLR tracking does not do incremental updates but one single chunk 
         - fixed code so SolrSearchers are held for as little time as possible
      44607: Merged V4.1-BUG-FIX to V4.1
         44603: ALF-14201: upgrade activiti to 5.7-20121211
         44606: ALF-14201: upgrade activiti to 5.7-20121211 in Maven poms


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44732 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2012-12-15 10:12:46 +00:00
parent b1537dd686
commit cfe1c63566
23 changed files with 627 additions and 221 deletions

View File

@@ -532,6 +532,9 @@
<property name="versionMigrator">
<ref bean="versionMigrator"/>
</property>
<property name="versionComparatorClass">
<value>${version.store.versionComparatorClass}</value>
</property>
</bean>
<bean id="versionNodeService" class="org.alfresco.repo.version.Node2ServiceImpl">

View File

@@ -4,3 +4,6 @@ inbound.display-label=Items are created or enter this folder
outbound.display-label=Items are deleted or leave this folder
update.display-label=Items are updated
inboundAndUpdate.display-label=Items are created, enter this folder or are updated
# Rule error messages
cannot.create.rule.checkout.outbound=Check out action cannot be performed for the rule type outbound!

View File

@@ -462,6 +462,11 @@ version.store.migrateVersionStore.cronExpression=* * * * * ? 2099
version.store.migrateVersionStore.limitPerJobCycle=-1
version.store.migrateVersionStore.runAsScheduledJob=false
# Optional Comparator<Version> class name to sort versions.
# Set to: org.alfresco.repo.version.common.VersionLabelComparator
# if upgrading from a version that used unordered sequences in a cluster.
version.store.versionComparatorClass=
# Folders for storing people
system.system_container.childname=sys:system
system.people_container.childname=sys:people

View File

@@ -59,6 +59,9 @@
<property name="includeGroupsForRoleAdmin">
<value>${solr.query.includeGroupsForRoleAdmin}</value>
</property>
<property name="maximumResultsFromUnlimitedQuery">
<value>${solr.query.maximumResultsFromUnlimitedQuery}</value>
</property>
</bean>

View File

@@ -2,3 +2,4 @@ solr.host=localhost
solr.port=8080
solr.port.ssl=8443
solr.query.includeGroupsForRoleAdmin=false
solr.query.maximumResultsFromUnlimitedQuery=${system.acl.maxPermissionChecks}

View File

@@ -40,7 +40,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MD4PasswordEncoder;
import org.alfresco.repo.security.authentication.MD4PasswordEncoderImpl;
import org.alfresco.repo.security.authentication.ntlm.NLTMAuthenticator;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -463,15 +462,47 @@ public abstract class CifsAuthenticatorBase extends CifsAuthenticator implements
AlfrescoClientInfo alfClient = (AlfrescoClientInfo) client;
if (alfClient.hasAuthenticationTicket())
{
boolean ticketFailed = false;
try
{
getAuthenticationService().validate(alfClient.getAuthenticationTicket());
}
catch (AuthenticationException e)
{
// Ticket no longer valid or maximum tickets exceeded
alfClient.setAuthenticationTicket(null);
getAuthenticationComponent().clearCurrentSecurityContext();
// Indicate the existing ticket is bad
ticketFailed = true;
// DEBUG
if ( logger.isDebugEnabled())
logger.debug("Failed to validate ticket, user=" + client.getUserName() + ", ticket=" + alfClient.getAuthenticationTicket());
}
// If the ticket did not validate then try and get a new ticket for the user
if ( ticketFailed == true) {
try {
String normalized = mapUserNameToPerson( client.getUserName(), false);
getAuthenticationComponent().setCurrentUser( normalized);
alfClient.setAuthenticationTicket(getAuthenticationService().getCurrentTicket());
}
catch ( AuthenticationException ex) {
// Cannot get a new ticket for the user
if ( logger.isErrorEnabled()) {
logger.error("Failed to get new ticket for user=" + client.getUserName());
logger.error( ex);
}
// Clear the ticket/security context
alfClient.setAuthenticationTicket(null);
getAuthenticationComponent().clearCurrentSecurityContext();
}
}
}
else
@@ -608,10 +639,10 @@ public abstract class CifsAuthenticatorBase extends CifsAuthenticator implements
// DEBUG
if (logger.isDebugEnabled())
{
logger.debug("Using " + (txService.isReadOnly() ? "ReadOnly" : "Write") + " transaction");
}
// if (logger.isDebugEnabled())
// {
// logger.debug("Using " + (txService.isReadOnly() ? "ReadOnly" : "Write") + " transaction");
// }
//
// the repository is read-only, we settle for a read-only transaction
if (txService.isReadOnly())

View File

@@ -137,7 +137,7 @@ public class ContentQuotaManager implements QuotaManager, Runnable {
// Check if content usage is enabled
if ( m_usageService.getEnabled() == false)
return 0L;
return -1L;
// Check if there is a live usage record for the user
@@ -150,7 +150,7 @@ public class ContentQuotaManager implements QuotaManager, Runnable {
// No quota details available
return 0L;
return -1L;
}
/**

View File

@@ -27,11 +27,13 @@ package org.alfresco.repo.bulkimport.impl;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.bulkimport.ContentDataFactory;
import org.alfresco.repo.content.ContentStore;
@@ -62,7 +64,6 @@ public class FilesystemContentDataFactory implements ContentDataFactory, Initial
private static final Log logger = LogFactory.getLog(FilesystemContentDataFactory.class);
private static final String PROTOCOL_DELIMITER = ContentStore.PROTOCOL_DELIMITER;
private static final String OS_FILE_SEPARATOR = System.getProperty("file.separator");
private MimetypeService mimetypeService;
private String defaultEncoding;
@@ -101,41 +102,36 @@ public class FilesystemContentDataFactory implements ContentDataFactory, Initial
*/
public ContentData createContentData(ContentStore store, File contentFile)
{
if(!contentIsInStore(contentFile, store))
try
{
throw new IllegalArgumentException("Can't create content URL : file '" + contentFile.getAbsolutePath() +
"' is not located within the store's tree ! The store's root is :'" + store.getRootLocation());
}
String rootLocation = new File(store.getRootLocation()).getCanonicalPath();
String contentLocation = contentFile.getCanonicalPath();
if (!contentLocation.startsWith(rootLocation + File.separator))
{
throw new IllegalArgumentException("Can't create content URL : file '" + contentLocation
+ "' is not located within the store's tree ! The store's root is :'" + rootLocation);
}
String relativeFilePath = contentLocation.substring(rootLocation.length() + File.separator.length());
String mimetype = mimetypeService.guessMimetype(contentFile.getName());
String encoding = defaultEncoding;
if (!contentFile.isDirectory())
{
encoding = guessEncoding(contentFile, mimetype);
}
String relativeFilePath = contentFile.getAbsolutePath().replace(store.getRootLocation() + OS_FILE_SEPARATOR, "");
String mimetype = mimetypeService.guessMimetype(contentFile.getName());
String encoding = defaultEncoding;
if(!contentFile.isDirectory())
ContentData contentData = new ContentData(storeProtocol + PROTOCOL_DELIMITER + relativeFilePath, mimetype,
contentFile.length(), encoding);
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, contentFile.getName());
contentProps.put(ContentModel.PROP_CONTENT, contentData);
return contentData;
}
catch (IOException e)
{
encoding = guessEncoding(contentFile, mimetype);
throw new AlfrescoRuntimeException(e.getMessage(), e);
}
ContentData contentData = new ContentData(storeProtocol + PROTOCOL_DELIMITER + relativeFilePath, mimetype, contentFile.length(), encoding);
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, contentFile.getName());
contentProps.put(ContentModel.PROP_CONTENT, contentData);
return contentData;
}
/**
* Check if file is in the store's tree, by checking if the file path starts
* with the store's configured root location.
*
* @param store The {@link ContentStore} in which the file should be
* @param contentFile The {@link File} to check
* @return boolean : whether or not the file is in the expected file tree
*/
private boolean contentIsInStore(File contentFile,ContentStore store)
{
File contentStoreFile = new File(store.getRootLocation());
return contentFile.getAbsolutePath().startsWith(contentStoreFile.getAbsolutePath());
}
/**

View File

@@ -288,21 +288,21 @@ public abstract class AbstractContentStore implements ContentStore
}
/**
* @return Returns <tt>Long.MAX_VALUE</tt> always
* @return Returns <tt>-1</tt> always
*/
@Override
public long getSpaceFree()
{
return Long.MAX_VALUE;
return -1;
}
/**
* @return Returns <tt>Long.MAX_VALUE</tt> always
* @return Returns <tt>-1</tt> always
*/
@Override
public long getSpaceTotal()
{
return Long.MAX_VALUE;
return -1;
}
/**

View File

@@ -269,21 +269,21 @@ public abstract class AbstractRoutingContentStore implements ContentStore
}
/**
* @return Returns <tt>Long.MAX_VALUE</tt> always
* @return Returns <tt>-1</tt> always
*/
@Override
public long getSpaceFree()
{
return Long.MAX_VALUE;
return -1L;
}
/**
* @return Returns <tt>Long.MAX_VALUE</tt> always
* @return Returns <tt>-1</tt> always
*/
@Override
public long getSpaceTotal()
{
return Long.MAX_VALUE;
return -1L;
}
/**

View File

@@ -21,6 +21,8 @@ package org.alfresco.repo.remoteconnector;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.StringTokenizer;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationException;
@@ -30,10 +32,15 @@ import org.alfresco.service.cmr.remoteconnector.RemoteConnectorResponse;
import org.alfresco.service.cmr.remoteconnector.RemoteConnectorServerException;
import org.alfresco.service.cmr.remoteconnector.RemoteConnectorService;
import org.alfresco.util.HttpClientHelper;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.ProxyHost;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.simple.JSONObject;
@@ -59,6 +66,31 @@ public class RemoteConnectorServiceImpl implements RemoteConnectorService
private static Log logger = LogFactory.getLog(RemoteConnectorServiceImpl.class);
private static final long MAX_BUFFER_RESPONSE_SIZE = 10*1024*1024;
private static ProxyHost httpProxyHost;
private static ProxyHost httpsProxyHost;
private static Credentials httpProxyCredentials;
private static Credentials httpsProxyCredentials;
private static AuthScope httpAuthScope;
private static AuthScope httpsAuthScope;
/**
* Initialise the HTTP Proxy Hosts and Params Factory
*/
static
{
// Create an HTTP Proxy Host if appropriate system property set
httpProxyHost = createProxyHost("http.proxyHost", "http.proxyPort", 80);
httpProxyCredentials = createProxyCredentials("http.proxyUser", "http.proxyPassword");
httpAuthScope = createProxyAuthScope(httpProxyHost);
// Create an HTTPS Proxy Host if appropriate system property set
httpsProxyHost = createProxyHost("https.proxyHost", "https.proxyPort", 443);
httpsProxyCredentials = createProxyCredentials("https.proxyUser", "https.proxyPassword");
httpsAuthScope = createProxyAuthScope(httpsProxyHost);
}
public RemoteConnectorServiceImpl()
{}
@@ -102,14 +134,49 @@ public class RemoteConnectorServiceImpl implements RemoteConnectorService
}
}
// Log what we're doing
if (logger.isDebugEnabled())
logger.debug("Performing " + request.getMethod() + " request to " + request.getURL());
// Grab our thread local HttpClient instance
// Remember - we must then clean it up!
HttpClient httpClient = HttpClientHelper.getHttpClient();
// The url should already be vetted by the RemoteConnectorRequest
URL url = new URL(request.getURL());
// Use the appropriate Proxy Host if required
if (httpProxyHost != null && url.getProtocol().equals("http") && requiresProxy(url.getHost()))
{
httpClient.getHostConfiguration().setProxyHost(httpProxyHost);
if (logger.isDebugEnabled())
logger.debug(" - using HTTP proxy host for: " + url);
if (httpProxyCredentials != null)
{
httpClient.getState().setProxyCredentials(httpAuthScope, httpProxyCredentials);
if (logger.isDebugEnabled())
logger.debug(" - using HTTP proxy credentials for proxy: " + httpProxyHost.getHostName());
}
}
else if (httpsProxyHost != null && url.getProtocol().equals("https") && requiresProxy(url.getHost()))
{
httpClient.getHostConfiguration().setProxyHost(httpsProxyHost);
if (logger.isDebugEnabled())
logger.debug(" - using HTTPS proxy host for: " + url);
if (httpsProxyCredentials != null)
{
httpClient.getState().setProxyCredentials(httpsAuthScope, httpsProxyCredentials);
if (logger.isDebugEnabled())
logger.debug(" - using HTTPS proxy credentials for proxy: " + httpsProxyHost.getHostName());
}
}
else
{
//host should not be proxied remove any configured proxies
httpClient.getHostConfiguration().setProxyHost(null);
httpClient.getState().clearProxyCredentials();
}
// Log what we're doing
if (logger.isDebugEnabled())
logger.debug("Performing " + request.getMethod() + " request to " + request.getURL());
// Perform the request, and wrap the response
int status = -1;
String statusText = null;
@@ -305,4 +372,97 @@ public class RemoteConnectorServiceImpl implements RemoteConnectorService
super.finalize();
}
}
/**
* Create proxy host for the given system host and port properties.
* If the properties are not set, no proxy will be created.
*
* @param hostProperty
* @param portProperty
* @param defaultPort
*
* @return ProxyHost if appropriate properties have been set, null otherwise
*/
private static ProxyHost createProxyHost(final String hostProperty, final String portProperty, final int defaultPort)
{
final String proxyHost = System.getProperty(hostProperty);
ProxyHost proxy = null;
if (proxyHost != null && proxyHost.length() != 0)
{
final String strProxyPort = System.getProperty(portProperty);
if (strProxyPort == null || strProxyPort.length() == 0)
{
proxy = new ProxyHost(proxyHost, defaultPort);
}
else
{
proxy = new ProxyHost(proxyHost, Integer.parseInt(strProxyPort));
}
if (logger.isDebugEnabled())
logger.debug("ProxyHost: " + proxy.toString());
}
return proxy;
}
/**
* Create the proxy credentials for the given proxy user and password properties.
* If the properties are not set, not credentials will be created.
* @param proxyUserProperty
* @param proxyPasswordProperty
* @return Credentials if appropriate properties have been set, null otherwise
*/
private static Credentials createProxyCredentials(final String proxyUserProperty, final String proxyPasswordProperty)
{
final String proxyUser = System.getProperty(proxyUserProperty);
final String proxyPassword = System.getProperty(proxyPasswordProperty);
Credentials creds = null;
if (StringUtils.isNotBlank(proxyUser))
{
creds = new UsernamePasswordCredentials(proxyUser, proxyPassword);
}
return creds;
}
/**
* Create suitable AuthScope for ProxyHost.
* If the ProxyHost is null, no AuthsScope will be created.
* @param proxyHost
* @return Authscope for provided ProxyHost, null otherwise.
*/
private static AuthScope createProxyAuthScope(final ProxyHost proxyHost)
{
AuthScope authScope = null;
if (proxyHost != null)
{
authScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
}
return authScope;
}
/**
* Return true unless the given target host is specified in the <code>http.nonProxyHosts</code> system property.
* See http://download.oracle.com/javase/1.4.2/docs/guide/net/properties.html
* @param targetHost Non-null host name to test
* @return true if not specified in list, false if it is specifed and therefore should be excluded from proxy
*/
private boolean requiresProxy(final String targetHost)
{
boolean requiresProxy = true;
final String nonProxyHosts = System.getProperty("http.nonProxyHosts");
if (nonProxyHosts != null)
{
StringTokenizer tokenizer = new StringTokenizer(nonProxyHosts, "|");
while (tokenizer.hasMoreTokens())
{
String pattern = tokenizer.nextToken();
pattern = pattern.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*");
if (targetHost.matches(pattern))
{
requiresProxy = false;
break;
}
}
}
return requiresProxy;
}
}

View File

@@ -19,12 +19,14 @@
package org.alfresco.repo.rendition.executer;
import java.io.IOException;
import java.util.Collection;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.transform.ContentTransformer;
import org.alfresco.repo.content.transform.TransformerDebug;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.rendition.RenditionServiceException;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NoTransformerException;
@@ -185,4 +187,27 @@ public abstract class AbstractTransformationRenderingEngine extends AbstractRend
return options;
}
/*
* @seeorg.alfresco.repo.rendition.executer.AbstractRenderingEngine#getParameterDefinitions()
*/
protected Collection<ParameterDefinition> getParameterDefinitions()
{
Collection<ParameterDefinition> paramList = super.getParameterDefinitions();
paramList.add(new ParameterDefinitionImpl(PARAM_TIMEOUT_MS, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_TIMEOUT_MS)));
paramList.add(new ParameterDefinitionImpl(PARAM_READ_LIMIT_TIME_MS, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_READ_LIMIT_TIME_MS)));
paramList.add(new ParameterDefinitionImpl(PARAM_MAX_SOURCE_SIZE_K_BYTES, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_MAX_SOURCE_SIZE_K_BYTES)));
paramList.add(new ParameterDefinitionImpl(PARAM_READ_LIMIT_K_BYTES, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_READ_LIMIT_K_BYTES)));
paramList.add(new ParameterDefinitionImpl(PARAM_MAX_PAGES, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_MAX_PAGES)));
paramList.add(new ParameterDefinitionImpl(PARAM_PAGE_LIMIT, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_PAGE_LIMIT)));
return paramList;
}
}

View File

@@ -25,7 +25,6 @@ import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.transform.magick.ImageCropOptions;
import org.alfresco.repo.content.transform.magick.ImageResizeOptions;
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -421,19 +420,6 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
paramList.add(new ParameterDefinitionImpl(PARAM_COMMAND_OPTIONS, DataTypeDefinition.TEXT, false,
getParamDisplayLabel(PARAM_COMMAND_OPTIONS)));
paramList.add(new ParameterDefinitionImpl(PARAM_TIMEOUT_MS, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_TIMEOUT_MS)));
paramList.add(new ParameterDefinitionImpl(PARAM_READ_LIMIT_TIME_MS, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_READ_LIMIT_TIME_MS)));
paramList.add(new ParameterDefinitionImpl(PARAM_MAX_SOURCE_SIZE_K_BYTES, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_MAX_SOURCE_SIZE_K_BYTES)));
paramList.add(new ParameterDefinitionImpl(PARAM_READ_LIMIT_K_BYTES, DataTypeDefinition.LONG, false,
getParamDisplayLabel(PARAM_READ_LIMIT_K_BYTES)));
paramList.add(new ParameterDefinitionImpl(PARAM_MAX_PAGES, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_MAX_PAGES)));
paramList.add(new ParameterDefinitionImpl(PARAM_PAGE_LIMIT, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_PAGE_LIMIT)));
return paramList;
}
}

View File

@@ -71,11 +71,10 @@ public class SolrJSONResultSet implements ResultSet
* Detached result set based on that provided
* @param resultSet
*/
public SolrJSONResultSet(JSONObject json, SearchParameters searchParameters, NodeService nodeService)
public SolrJSONResultSet(JSONObject json, SearchParameters searchParameters, NodeService nodeService, LimitBy limitBy, int maxResults)
{
// Note all properties are returned as multi-valued from the WildcardField "*" definition in the SOLR schema.xml
this.nodeService = nodeService;
this.resultSetMetaData = new SimpleResultSetMetaData(LimitBy.UNLIMITED, PermissionEvaluationMode.EAGER, searchParameters);
try
{
JSONObject responseHeader = json.getJSONObject("responseHeader");
@@ -139,7 +138,10 @@ public class SolrJSONResultSet implements ResultSet
{
}
// We'll say we were unlimited if we got a number less than the limit
this.resultSetMetaData = new SimpleResultSetMetaData(
maxResults > 0 && numberFound < maxResults ? LimitBy.UNLIMITED : limitBy,
PermissionEvaluationMode.EAGER, searchParameters);
}

View File

@@ -99,6 +99,8 @@ public class SolrQueryHTTPClient implements BeanFactoryAware
private boolean includeGroupsForRoleAdmin = false;
private int maximumResultsFromUnlimitedQuery = Integer.MAX_VALUE;
public SolrQueryHTTPClient()
{
}
@@ -166,6 +168,15 @@ public class SolrQueryHTTPClient implements BeanFactoryAware
this.includeGroupsForRoleAdmin = includeGroupsForRoleAdmin;
}
/**
* @param maximumResultsFromUnlimitedQuery
* the maximum number of results to request from an otherwise unlimited query
*/
public void setMaximumResultsFromUnlimitedQuery(int maximumResultsFromUnlimitedQuery)
{
this.maximumResultsFromUnlimitedQuery = maximumResultsFromUnlimitedQuery;
}
public ResultSet executeQuery(SearchParameters searchParameters, String language)
{
if(repositoryState.isBootstrapping())
@@ -206,18 +217,29 @@ public class SolrQueryHTTPClient implements BeanFactoryAware
url.append("?wt=").append(encoder.encode("json", "UTF-8"));
url.append("&fl=").append(encoder.encode("DBID,score", "UTF-8"));
// Emulate old limiting behaviour and metadata
final LimitBy limitBy;
int maxResults = -1;
if (searchParameters.getMaxItems() >= 0)
{
url.append("&rows=").append(encoder.encode("" + searchParameters.getMaxItems(), "UTF-8"));
maxResults = searchParameters.getMaxItems();
limitBy = LimitBy.FINAL_SIZE;
}
else if(searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
else if(searchParameters.getLimitBy() == LimitBy.FINAL_SIZE && searchParameters.getLimit() >= 0)
{
url.append("&rows=").append(encoder.encode("" + searchParameters.getLimit(), "UTF-8"));
maxResults = searchParameters.getLimit();
limitBy = LimitBy.FINAL_SIZE;
}
else
{
url.append("&rows=").append(encoder.encode("" + Integer.MAX_VALUE, "UTF-8"));
maxResults = searchParameters.getMaxPermissionChecks();
if (maxResults < 0)
{
maxResults = maximumResultsFromUnlimitedQuery;
}
limitBy = LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS;
}
url.append("&rows=").append(String.valueOf(maxResults));
url.append("&df=").append(encoder.encode(searchParameters.getDefaultFieldName(), "UTF-8"));
url.append("&start=").append(encoder.encode("" + searchParameters.getSkipCount(), "UTF-8"));
@@ -401,7 +423,7 @@ public class SolrQueryHTTPClient implements BeanFactoryAware
Reader reader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
// TODO - replace with streaming-based solution e.g. SimpleJSON ContentHandler
JSONObject json = new JSONObject(new JSONTokener(reader));
SolrJSONResultSet results = new SolrJSONResultSet(json, searchParameters, nodeService);
SolrJSONResultSet results = new SolrJSONResultSet(json, searchParameters, nodeService, limitBy, maxResults);
if (s_logger.isDebugEnabled())
{
s_logger.debug("Sent :" + url);

View File

@@ -182,5 +182,33 @@ public abstract class AbstractTenantRoutingContentStore extends AbstractRoutingC
destroy();
}
@Override
public long getSpaceFree()
{
ContentStore x = getTenantContentStore();
if(x != null)
{
return x.getSpaceFree();
}
else
{
return -1;
}
}
@Override
public long getSpaceTotal()
{
ContentStore x = getTenantContentStore();
if(x != null)
{
return x.getSpaceTotal();
}
else
{
return -1;
}
}
protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot);
}

View File

@@ -31,11 +31,14 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.DictionaryBootstrap;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.node.archive.NodeArchiveService;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -43,6 +46,7 @@ import org.alfresco.service.cmr.repository.MLText;
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.search.SearchService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.version.Version;
@@ -68,6 +72,11 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
protected NodeService nodeService;
protected PermissionService permissionService;
protected CheckOutCheckInService checkOutCheckInService;
protected VersionMigrator versionMigrator;
protected SearchService versionSearchService;
protected DictionaryService dictionaryService;
protected PolicyComponent policyComponent;
protected BehaviourFilter policyBehaviourFilter;
/*
* Data used by tests
@@ -158,6 +167,11 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
this.nodeService = (NodeService)applicationContext.getBean("nodeService");
this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
this.checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");
this.versionSearchService = (SearchService)this.applicationContext.getBean("versionSearchService");
this.versionMigrator = (VersionMigrator)this.applicationContext.getBean("versionMigrator");
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
this.policyBehaviourFilter = (BehaviourFilter)this.applicationContext.getBean("policyBehaviourFilter");
setVersionService((VersionService)applicationContext.getBean("versionService"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -34,7 +34,6 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.version.common.VersionHistoryImpl;
import org.alfresco.repo.version.common.VersionHistoryImpl.VersionComparatorAsc;
import org.alfresco.repo.version.common.VersionImpl;
import org.alfresco.repo.version.common.VersionUtil;
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
@@ -70,8 +69,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
private VersionServiceImpl version1Service = new VersionServiceImpl();
private VersionMigrator versionMigrator;
private static Comparator<Version> versionComparatorAsc = new VersionComparatorAsc();
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
@@ -779,9 +776,13 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
VersionHistory versionHistory = null;
// List of versions with current one last and root one first.
List<Version> versions = getAllVersions(versionHistoryRef);
Collections.sort(versions, versionComparatorAsc);
if (versionComparatorDesc != null)
{
Collections.sort(versions, Collections.reverseOrder(versionComparatorDesc));
}
// Build the version history object
boolean isRoot = true;
@@ -790,7 +791,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
if (isRoot == true)
{
versionHistory = new VersionHistoryImpl(version);
versionHistory = new VersionHistoryImpl(version, versionComparatorDesc);
isRoot = false;
}
else

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -22,12 +22,14 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.MLPropertyInterceptor;
import org.alfresco.repo.policy.BehaviourFilter;
@@ -98,6 +100,8 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
*/
protected SearchService searcher; // unused
protected Comparator<Version> versionComparatorDesc;
/**
* Sets the db node service, used as the version store implementation
*
@@ -126,6 +130,33 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
this.policyBehaviourFilter = policyBehaviourFilter;
}
/**
* Sets an optional comparator to sort a versions in descending order (eg. 2.1, 2.0, 1.1, 1.0).
* Really only needed in a 4.1.3 system (or above) that has been upgraded from an earlier system
* that used NON ordered sequence numbers in a cluster. Not something we really support but was
* the subject of MNT-226.
* @param versionComparatorClass the name of a comparator. For example
* "org.alfresco.repo.version.common.VersionLabelComparator".
*/
@SuppressWarnings("unchecked")
public void setVersionComparatorClass(String versionComparatorClass)
{
if (versionComparatorClass != null && versionComparatorClass.trim().length() != 0)
{
try
{
versionComparatorDesc = (Comparator<Version>) getClass().getClassLoader().
loadClass(versionComparatorClass.trim()).newInstance();
}
catch (Exception e)
{
throw new AlfrescoRuntimeException(
"Failed to create a Comparator<Version> using the class name "+
versionComparatorClass, e);
}
}
}
/**
* Register version label policy for the specified type
*
@@ -747,6 +778,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
{
VersionHistory versionHistory = null;
// List of versions with current one last and root one first.
ArrayList<NodeRef> versionHistoryNodeRefs = new ArrayList<NodeRef>();
NodeRef currentVersion;
@@ -793,7 +825,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl implements Ve
if (isRoot == true)
{
versionHistory = new VersionHistoryImpl(version);
versionHistory = new VersionHistoryImpl(version, versionComparatorDesc);
isRoot = false;
}
else

View File

@@ -21,6 +21,7 @@ package org.alfresco.repo.version;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -28,6 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import junit.framework.AssertionFailedError;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
@@ -296,6 +299,78 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
addToVersionHistory(versionableNode, version4);
}
/**
* Same as testGetVersionHistorySameWorkspace except that the order of
* of db ids is mixed up and a comparator is need to fix it (MNT-226).
*/
public void testIdsOutOfOrder()
{
if (versionService instanceof Version2ServiceImpl)
{
setOutOfOrderIdsVersionService("org.alfresco.repo.version.common.VersionLabelComparator");
testGetVersionHistorySameWorkspace();
}
}
/**
* Same as testIdsOutOfOrder but without the comparator so should fail.
*/
public void testIdsOutOfOrderFails()
{
if (versionService instanceof Version2ServiceImpl)
{
try
{
setOutOfOrderIdsVersionService("");
testGetVersionHistorySameWorkspace();
fail("Expected this to fail");
}
catch (AssertionFailedError e)
{
System.out.print("A test failed as EXPECTED: "+e.getMessage());
}
}
}
/**
* Sets the versionService to be one that has is db ids out of order
* so would normally have versions displayed in the wrong order.
* @param versionComparatorClass name of class to correct the situation.
*/
private void setOutOfOrderIdsVersionService(String versionComparatorClass)
{
Version2ServiceImpl versionService = new Version2ServiceImpl()
{
@Override
protected List<Version> getAllVersions(NodeRef versionHistoryRef)
{
List<Version> versions = super.getAllVersions(versionHistoryRef);
if (versions.size() > 1)
{
// Make sure the order changes
List<Version> copy = new ArrayList<Version>(versions);
do
{
Collections.shuffle(versions);
} while (versions.equals(copy));
}
return versions;
}
};
versionService.setNodeService(nodeService);
versionService.setDbNodeService(dbNodeService); // mtAwareNodeService
versionService.setSearcher(versionSearchService);
versionService.setDictionaryService(dictionaryService);
versionService.setPolicyComponent(policyComponent);
versionService.setPolicyBehaviourFilter(policyBehaviourFilter);
versionService.setPermissionService(permissionService);
versionService.setOnlyUseDeprecatedV1(false);
versionService.setVersionMigrator(versionMigrator);
versionService.setVersionComparatorClass(versionComparatorClass);
versionService.initialise();
setVersionService(versionService);
}
/**
* Adds another version to the version history then checks that getVersionHistory is returning
* the correct data.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -20,23 +20,22 @@ package org.alfresco.repo.version.common;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionDoesNotExistException;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionServiceException;
import org.alfresco.util.EqualsHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Version History implementation.
@@ -45,9 +44,8 @@ import org.apache.commons.logging.LogFactory;
*/
public class VersionHistoryImpl implements VersionHistory
{
private static Log logger = LogFactory.getLog(VersionHistoryImpl.class);
private static final long serialVersionUID = 3257001051558326840L;
/*
* Error message(s)
*/
@@ -65,28 +63,22 @@ public class VersionHistoryImpl implements VersionHistory
private HashMap<String, String> versionHistory = null;
/*
* Label to version object map
* Label to version object map - Iterators must be in the order entries were addded.
*/
private HashMap<String, Version> versionsByLabel = null;
private Map<String, Version> versionsByLabel = null;
/*
* Versions ordered by creation date (descending)
* Versions ordered by creation date (descending).
*/
private static Comparator<Version> versionComparatorDesc = new VersionComparatorDesc();
/**
* Root version
*/
private Version rootVersion;
private Comparator<Version> versionComparatorDesc;
/**
* Constructor, ensures the root version is set.
*
* @param rootVersion the root version, can not be null.
* @param versionComparatorDesc optional comparator of versions.
*/
public VersionHistoryImpl(Version rootVersion)
public VersionHistoryImpl(Version rootVersion, Comparator<Version> versionComparatorDesc)
{
if (rootVersion == null)
{
@@ -96,9 +88,9 @@ public class VersionHistoryImpl implements VersionHistory
}
this.versionHistory = new HashMap<String, String>();
this.versionsByLabel = new HashMap<String, Version>();
this.versionsByLabel = new LinkedHashMap<String, Version>();
this.versionComparatorDesc = versionComparatorDesc;
this.rootVersion = rootVersion;
addVersion(rootVersion, null);
}
@@ -109,7 +101,7 @@ public class VersionHistoryImpl implements VersionHistory
*/
public Version getRootVersion()
{
return this.rootVersion;
return versionsByLabel.values().iterator().next();
}
/**
@@ -119,10 +111,7 @@ public class VersionHistoryImpl implements VersionHistory
*/
public Version getHeadVersion()
{
Collection<Version> versions = versionsByLabel.values();
List<Version> sortedVersions = new ArrayList<Version>(versions);
Collections.sort(sortedVersions, versionComparatorDesc);
return sortedVersions.get(0);
return getAllVersions().iterator().next();
}
/**
@@ -135,9 +124,26 @@ public class VersionHistoryImpl implements VersionHistory
*/
public Collection<Version> getAllVersions()
{
Collection<Version> versions = versionsByLabel.values();
return sortDescending(versionsByLabel.values());
}
/**
* Sorts Versions into descending create date order (most recent first).
* @param versions <b>Must be in order addVersion was called</b>.
* @return
*/
private Collection<Version> sortDescending(Collection<Version> versions)
{
List<Version> sortedVersions = new ArrayList<Version>(versions);
Collections.sort(sortedVersions, versionComparatorDesc);
if (versionComparatorDesc == null)
{
Collections.reverse(sortedVersions);
}
else
{
Collections.sort(sortedVersions, versionComparatorDesc);
}
return sortedVersions;
}
@@ -158,7 +164,8 @@ public class VersionHistoryImpl implements VersionHistory
}
/**
* Gets the succeeding versions of a specified version.
* Gets the succeeding versions of a specified version. If there are multiple
* Versions they are sorted into descending create date order (most recent first).
*
* @param version the version object
* @return a collection containing the succeeding version, empty is none
@@ -173,26 +180,27 @@ public class VersionHistoryImpl implements VersionHistory
if (this.versionHistory.containsValue(versionLabel) == true)
{
for (String key : this.versionHistory.keySet())
for (Entry<String, Version> entry: versionsByLabel.entrySet())
{
String key = entry.getKey();
if (EqualsHelper.nullSafeEquals(this.versionHistory.get(key), versionLabel))
{
result.add(getVersion(key));
result.add(entry.getValue());
}
}
}
}
return result;
return sortDescending(result);
}
/**
* Gets a version with a specified version label. The version label is guarenteed
* Gets a version with a specified version label. The version label is guaranteed
* unique within the version history.
*
* @param versionLabel the version label
* @return the version object
* @throws VersionDoesNotExistException indicates requested version does not exisit
* @throws VersionDoesNotExistException indicates requested version does not exist
*/
public Version getVersion(String versionLabel)
{
@@ -211,7 +219,8 @@ public class VersionHistoryImpl implements VersionHistory
}
/**
* Add a version to the version history.
* Add a version to the version history, <b>in the order they were
* created</b>.
* <p>
* Used internally to build the version history tree.
*
@@ -230,75 +239,7 @@ public class VersionHistoryImpl implements VersionHistory
}
}
/**
* Version Comparator
*
* Note: Descending (last modified) date order
*/
public static class VersionComparatorDesc implements Comparator<Version>, Serializable
{
private static final long serialVersionUID = 6227528170880231770L;
public int compare(Version v1, Version v2)
{
int result = 0;
if ((null != v1) && (null != v2))
{
Serializable dbIdV1 = (null != v1.getVersionProperties()) ? (v1.getVersionProperties().get(ContentModel.PROP_NODE_DBID.getLocalName())) : (null);
Serializable dbIdV2 = (null != v2.getVersionProperties()) ? (v2.getVersionProperties().get(ContentModel.PROP_NODE_DBID.getLocalName())) : (null);
if ((null != dbIdV1) && (null != dbIdV2))
{
Long id1 = (dbIdV1 instanceof Integer) ? ((Integer) dbIdV1) : ((Long) dbIdV1);
Long id2 = (dbIdV2 instanceof Integer) ? ((Integer) dbIdV2) : ((Long) dbIdV2);
result = (id2).compareTo(id1);
}
else
{
logger.warn("DB Id of versioned node is missing!");
}
}
return result;
}
}
/**
* Version Comparator
*
* Note: Ascending (last modified) date order
*/
public static class VersionComparatorAsc implements Comparator<Version>, Serializable
{
private static final long serialVersionUID = 6227528170880231770L;
public int compare(Version v1, Version v2)
{
int result = 0;
if ((null != v1) && (null != v2))
{
Serializable dbIdV1 = (null != v1.getVersionProperties()) ? (v1.getVersionProperties().get(ContentModel.PROP_NODE_DBID.getLocalName())) : (null);
Serializable dbIdV2 = (null != v2.getVersionProperties()) ? (v2.getVersionProperties().get(ContentModel.PROP_NODE_DBID.getLocalName())) : (null);
if ((null != dbIdV1) && (null != dbIdV2))
{
Long id1 = (dbIdV1 instanceof Integer) ? ((Integer) dbIdV1) : ((Long) dbIdV1);
Long id2 = (dbIdV2 instanceof Integer) ? ((Integer) dbIdV2) : ((Long) dbIdV2);
result = (id1).compareTo(id2);
}
else
{
logger.warn("DB Id of versioned node is missing!");
}
}
return result;
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "deprecation" })
private void readObject(ObjectInputStream is) throws ClassNotFoundException, IOException
{
GetField fields = is.readFields();
@@ -306,21 +247,30 @@ public class VersionHistoryImpl implements VersionHistory
{
// This is a V2.2 class
// The old 'rootVersion' maps to the current 'rootVersion'
this.rootVersion = (Version) fields.get("rootVersion", null);;
// The old 'versions' maps to the current 'versionsByLabel'
this.versionsByLabel = (HashMap<String, Version>) fields.get("versions", new HashMap<String, Version>());
// The old 'versionHistory' maps to the current 'versionHistory'
this.versionHistory = (HashMap<String, String>) fields.get("versionHistory", new HashMap<String, String>());
// Need this comparator as versionsByLabel is not a LinkedHashMap in this version
this.versionComparatorDesc = new VersionLabelComparator();
}
else
else if (fields.defaulted("versionComparatorDesc"))
{
// This is a V3.1.0 to ... class
// This is a V3.1.0 class
// The old 'rootVersion' maps to the current 'rootVersion'
this.rootVersion = (Version) fields.get("rootVersion", null);
// The old 'versionsByLabel' maps to the current 'versionsByLabel'
this.versionsByLabel = (HashMap<String, Version>) fields.get("versionsByLabel", new HashMap<String, Version>());
// The old 'versionHistory' maps to the current 'versionHistory'
this.versionHistory = (HashMap<String, String>) fields.get("versionHistory", new HashMap<String, String>());
// Need this comparator as versionsByLabel is not a LinkedHashMap in this version
this.versionComparatorDesc = new VersionLabelComparator();
}
else
{
// This is a V4.1.3 (and 4.0.2 HF) class
// The old 'rootVersion' maps to the current 'rootVersion'
this.versionsByLabel = (Map<String, Version>) fields.get("versionsByLabel", new LinkedHashMap<String, Version>());
// The old 'versionHistory' maps to the current 'versionHistory'
this.versionHistory = (HashMap<String, String>) fields.get("versionHistory", new HashMap<String, String>());
this.versionComparatorDesc = (Comparator<Version>) fields.get("versionComparatorDesc", null);
}
}
}

View File

@@ -24,9 +24,13 @@ import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
@@ -50,6 +54,7 @@ public class VersionHistoryImplTest extends TestCase
/**
* Data used in the tests
*/
private NodeRef nodeRef;
private Version rootVersion = null;
private Version childVersion1 = null;
private Version childVersion2 = null;
@@ -62,25 +67,20 @@ public class VersionHistoryImplTest extends TestCase
super.setUp();
// Create dummy node ref
NodeRef nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "test"), "test");
nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "test"), "test");
this.rootVersion = newVersion(nodeRef, "1");
this.childVersion1 = newVersion(nodeRef, "2");
this.childVersion2 = newVersion(nodeRef, "3");
}
private VersionImpl newVersion(NodeRef nodeRef, String label)
{
HashMap<String, Serializable> versionProperties1 = new HashMap<String, Serializable>();
versionProperties1.put(VersionModel.PROP_VERSION_LABEL, "1");
versionProperties1.put(VersionModel.PROP_VERSION_LABEL, label);
versionProperties1.put(VersionModel.PROP_CREATED_DATE, new Date());
versionProperties1.put("testProperty", "testValue");
this.rootVersion = new VersionImpl(versionProperties1, nodeRef);
HashMap<String, Serializable> versionProperties2 = new HashMap<String, Serializable>();
versionProperties2.put(VersionModel.PROP_VERSION_LABEL, "2");
versionProperties2.put(VersionModel.PROP_CREATED_DATE, new Date());
versionProperties2.put("testProperty", "testValue");
this.childVersion1 = new VersionImpl(versionProperties2, nodeRef);
HashMap<String, Serializable> versionProperties3 = new HashMap<String, Serializable>();
versionProperties3.put(VersionModel.PROP_VERSION_LABEL, "3");
versionProperties3.put(VersionModel.PROP_CREATED_DATE, new Date());
versionProperties3.put("testProperty", "testValue");
this.childVersion2 = new VersionImpl(versionProperties3, nodeRef);
return new VersionImpl(versionProperties1, nodeRef);
}
/**
@@ -98,7 +98,7 @@ public class VersionHistoryImplTest extends TestCase
*/
private VersionHistoryImpl testContructorImpl()
{
VersionHistoryImpl vh = new VersionHistoryImpl(this.rootVersion);
VersionHistoryImpl vh = new VersionHistoryImpl(this.rootVersion, null);
assertNotNull(vh);
return vh;
@@ -112,7 +112,7 @@ public class VersionHistoryImplTest extends TestCase
{
try
{
new VersionHistoryImpl(null);
new VersionHistoryImpl(null, null);
fail();
}
catch(VersionServiceException exception)
@@ -146,6 +146,42 @@ public class VersionHistoryImplTest extends TestCase
assertEquals(3, allVersions.size());
}
/**
* Test getAllVersions using a comparator to resort versions which are in the
* wrong order.
*/
public void testGetAllVersionsComparator()
{
String[] labels = new String[] { "1.0", "1.1", "1.2", "2.0", "2.1" };
List<Version> versions = new ArrayList<Version>(labels.length);
for (String label: labels)
{
versions.add(newVersion(nodeRef, label));
}
Collections.shuffle(versions);
Iterator<Version> itr = versions.iterator();
Version version = itr.next();
Version predecessor;
VersionHistoryImpl vh = new VersionHistoryImpl(version,
Collections.reverseOrder(new VersionLabelComparator()));
while (itr.hasNext())
{
predecessor = version;
version = itr.next();
vh.addVersion(version, predecessor);
}
Collection<Version> allVersions = vh.getAllVersions();
assertNotNull(allVersions);
assertEquals(labels.length, allVersions.size());
itr = allVersions.iterator();
for (String label: labels)
{
assertEquals(label, itr.next().getVersionLabel());
}
}
/**
* Test addVersion
*
@@ -210,7 +246,6 @@ public class VersionHistoryImplTest extends TestCase
/**
* Test getSuccessors
*/
@SuppressWarnings("unchecked")
public void testGetSuccessors()
{
VersionHistoryImpl vh = testAddVersionImpl();
@@ -237,6 +272,40 @@ public class VersionHistoryImplTest extends TestCase
assertTrue(versions3.isEmpty());
}
/**
* Test getSuccessors using a comparator to resort versions which are in the
* wrong order.
*/
public void testGetSuccessorsComparator()
{
rootVersion = newVersion(nodeRef, "1.0");
String[] labels = new String[] { "1.1", "1.2", "2.0", "2.1" };
List<Version> versions = new ArrayList<Version>(labels.length);
for (String label: labels)
{
versions.add(newVersion(nodeRef, label));
}
Collections.shuffle(versions);
Iterator<Version> itr = versions.iterator();
Version version = rootVersion;
VersionHistoryImpl vh = new VersionHistoryImpl(version,
Collections.reverseOrder(new VersionLabelComparator()));
while (itr.hasNext())
{
vh.addVersion(itr.next(), rootVersion);
}
Collection<Version> allVersions = vh.getSuccessors(rootVersion);
assertNotNull(allVersions);
assertEquals(labels.length, allVersions.size());
itr = allVersions.iterator();
for (String label: labels)
{
assertEquals(label, itr.next().getVersionLabel());
}
}
/**
* Test getVersion
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -28,7 +28,7 @@ import org.alfresco.util.VersionNumber;
*
* @author Yanick Pignot
*
* @deprecated see VersionHistory (getAllVersions, VersionComparatorAsc, VersionComparatorDesc)
* @deprecated See {@link VersionHistory}
*/
public class VersionLabelComparator implements Comparator<Version>
{