mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged DEV/SWIFT to HEAD
26012: OpenCMIS server bug fixes: PWC properties update and document version delete 26205: - integrated the CMIS Client API project into the build - made the local CMIS client use the Alfresco OpenCMIS Extension - updated OpenCMIS 26300: expose all non-child associations through OpenCMIS and check relationship source and target instead of the relationship type 26356: OpenCMIS update 26378: added more CMIS client examples 26380: added helper methods for CMIS client 26500: - fixed CMIS date aspect property encoding - fixed CMIS rendition filter handling 26519: OpenCMIS update 26523: fixed CMISConnectionManager 26596: renamed CMIS JavaScript root objects (cmis -> cmisserver, cmisclient -> cmis) 26651: removed the cmis-client-api project and replaced it with a jar in 3rd-party 26652: - corrected CMIS samples 26656: - removed cmis-client-api from build 26658: - removed the last bit of cmis-client-api 26663: - added CMIS samples (browser and upload) 26742: CMIS webscripts samples update 26743: CMIS webscripts samples update 26939: removed duplicate commons-fileupload 26942: updated commons-lang to 2.6 26943: updated OpenCMIS (browser binding is now included in the server framework) 26953: refactored OpenCMIS client integration 26974: Update classpath for Florian - OpenCMIS browser bindings are now rolled into the main jar, no need for their own one 26975: removed outdated CMIS browser binding demo page 27048: port of the Spring Surf CMIS browser plus a few new features (create folder, create document, delete object) 27077: bug fix: CMIS id for associations 27079: OpenCMIS update 27085: added check if CMIS is supported 27086: OpenCMIS client bindings update (force JAX-WS RI) 27138: clean up 27764: CMIS default connection handling 27879: OpenCMIS client: moved server definitions to separate config file 27880: OpenCMIS client: removed test repositories from configuration 27918: changed CMIS server configuration tag name to match Spring Surf configuration 27920: enabled relationships in CMIS browser 27924: Updated Spring Surf and added the Spring Surf CMIS framework [Merge note: Kept most recent HEAD jars where conflicts occured] 27926: Updated Spring Surf source jars [Merge note: Kept most recent HEAD jars where conflicts occured] git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28219 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -33,27 +32,38 @@ import org.apache.chemistry.opencmis.client.api.Session;
|
||||
import org.apache.chemistry.opencmis.client.api.SessionFactory;
|
||||
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
|
||||
import org.apache.chemistry.opencmis.commons.SessionParameter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.extensions.config.ConfigService;
|
||||
|
||||
public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectionManager, InitializingBean
|
||||
/**
|
||||
* Connection manager base class.
|
||||
*/
|
||||
public abstract class AbstractCMISConnectionManagerImpl extends CMISHelper implements CMISConnectionManager
|
||||
{
|
||||
public static final String SERVER_NAME = "name";
|
||||
public static final String SERVER_DESCRIPTION = "description";
|
||||
public static final String LOCAL_CONNECTION_ID = "local";
|
||||
public static final String DEFAULT_CONNECTION_ID = "default";
|
||||
public static final char RESERVED_ID_CHAR = '$';
|
||||
|
||||
protected ConfigService configService;
|
||||
protected AuthenticationService authenticationService;
|
||||
|
||||
protected SessionFactory sessionFactory;
|
||||
protected final SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
|
||||
|
||||
protected LinkedHashMap<String, CMISConnection> sharedConnections;
|
||||
protected LinkedHashMap<String, CMISConnection> userConnections;
|
||||
protected int userConnectionsCapacity = 1000;
|
||||
protected int sharedConnectionsCapacity = 1000;
|
||||
protected int sharedConnectionsCapacity = 100;
|
||||
|
||||
protected Map<String, CMISServer> servers;
|
||||
|
||||
protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
// --- set up ---
|
||||
|
||||
public void setConfigService(ConfigService configService)
|
||||
{
|
||||
this.configService = configService;
|
||||
}
|
||||
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
@@ -70,28 +80,12 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
this.sharedConnectionsCapacity = sharedConnectionsCapacity;
|
||||
}
|
||||
|
||||
public void setServers(List<Map<String, String>> serverList)
|
||||
{
|
||||
servers = new HashMap<String, CMISServer>();
|
||||
|
||||
for (Map<String, String> serverData : serverList)
|
||||
{
|
||||
CMISServer server = createServerDefinition(serverData);
|
||||
if (server != null)
|
||||
{
|
||||
servers.put(server.getName(), server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
public void init()
|
||||
{
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
sessionFactory = SessionFactoryImpl.newInstance();
|
||||
|
||||
// create shared connection LRU cache
|
||||
sharedConnections = new LinkedHashMap<String, CMISConnection>(sharedConnectionsCapacity,
|
||||
(int) Math.ceil(sharedConnectionsCapacity / 0.75) + 1, true)
|
||||
{
|
||||
@@ -104,6 +98,7 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
}
|
||||
};
|
||||
|
||||
// create user connection LRU cache
|
||||
userConnections = new LinkedHashMap<String, CMISConnection>(userConnectionsCapacity,
|
||||
(int) Math.ceil(userConnectionsCapacity / 0.75) + 1, true)
|
||||
{
|
||||
@@ -115,15 +110,33 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
return size() > userConnectionsCapacity;
|
||||
}
|
||||
};
|
||||
|
||||
// get predefined server definitions
|
||||
CMISServersConfigElement cmisServersConfig = (CMISServersConfigElement) configService.getConfig("CMIS")
|
||||
.getConfigElement("cmis-servers");
|
||||
if (cmisServersConfig != null && cmisServersConfig.getServerDefinitions() != null)
|
||||
{
|
||||
servers = cmisServersConfig.getServerDefinitions();
|
||||
} else
|
||||
{
|
||||
servers = new HashMap<String, CMISServer>();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// --- connections ---
|
||||
|
||||
@Override
|
||||
public CMISConnection createUserConnection(CMISServer server, String connectionId)
|
||||
{
|
||||
if (connectionId == null || connectionId.length() == 0 || connectionId.indexOf(RESERVED_ID_CHAR) > -1)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid connection id!");
|
||||
}
|
||||
|
||||
String currentUser = authenticationService.getCurrentUserName();
|
||||
if (currentUser == null)
|
||||
{
|
||||
@@ -142,7 +155,7 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
throw new IllegalStateException("Connection id is already in use!");
|
||||
}
|
||||
|
||||
connection = createConnection(server, userConnectionId);
|
||||
connection = createConnection(server, userConnectionId, false);
|
||||
|
||||
userConnections.put(userConnectionId, connection);
|
||||
} finally
|
||||
@@ -161,6 +174,12 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
@Override
|
||||
public CMISConnection createSharedConnection(CMISServer server, String connectionId)
|
||||
{
|
||||
if (connectionId == null || connectionId.length() == 0 || connectionId.indexOf(RESERVED_ID_CHAR) > -1
|
||||
|| DEFAULT_CONNECTION_ID.equals(connectionId))
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid connection id!");
|
||||
}
|
||||
|
||||
CMISConnection connection;
|
||||
|
||||
lock.writeLock().lock();
|
||||
@@ -171,9 +190,9 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
throw new IllegalStateException("Connection id is already in use!");
|
||||
}
|
||||
|
||||
connection = createConnection(server, connectionId);
|
||||
connection = createConnection(server, connectionId, true);
|
||||
|
||||
sharedConnections.put(connection.getId(), connection);
|
||||
sharedConnections.put(connection.getInternalId(), connection);
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
@@ -182,23 +201,42 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
return connection;
|
||||
}
|
||||
|
||||
protected CMISConnection createConnection(CMISServer server, String connectionId)
|
||||
protected CMISConnection createConnection(CMISServer server, String connectionId, boolean isShared)
|
||||
{
|
||||
if (connectionId == null || connectionId.length() == 0 || connectionId.indexOf(RESERVED_ID_CHAR) > -1)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid connection id!");
|
||||
}
|
||||
|
||||
Session session = createSession(server.getParameters());
|
||||
String username = server.getParameters().get(SessionParameter.USER);
|
||||
|
||||
return new CMISConnectionImpl(this, connectionId, session, server, username, false);
|
||||
return new CMISConnectionImpl(this, connectionId, session, server, username, false, isShared);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract CMISConnection getConnection();
|
||||
|
||||
public Collection<CMISConnection> getUserConnections()
|
||||
public CMISConnection getConnection(String connectionId)
|
||||
{
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
CMISConnection connection = sharedConnections.get(connectionId);
|
||||
if (connection != null)
|
||||
{
|
||||
return connection;
|
||||
}
|
||||
|
||||
String currentUser = authenticationService.getCurrentUserName();
|
||||
if (currentUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String userConnectionId = createUserConnectionId(currentUser, connectionId);
|
||||
return userConnections.get(userConnectionId);
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<CMISConnection> getUserConnections()
|
||||
{
|
||||
String currentUser = authenticationService.getCurrentUserName();
|
||||
if (currentUser == null)
|
||||
@@ -213,16 +251,17 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
|
||||
for (CMISConnection conn : userConnections.values())
|
||||
{
|
||||
int idx = conn.getId().indexOf(RESERVED_ID_CHAR);
|
||||
int idx = conn.getInternalId().indexOf(RESERVED_ID_CHAR);
|
||||
if (idx > -1)
|
||||
{
|
||||
if (currentUser.equals(conn.getId().substring(idx + 1)))
|
||||
if (currentUser.equals(conn.getInternalId().substring(idx + 1)))
|
||||
{
|
||||
result.add(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(result);
|
||||
return Collections.unmodifiableList(result);
|
||||
} finally
|
||||
{
|
||||
@@ -230,43 +269,15 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
}
|
||||
}
|
||||
|
||||
public CMISConnection getUserConnections(String connectionId)
|
||||
{
|
||||
String currentUser = authenticationService.getCurrentUserName();
|
||||
if (currentUser == null)
|
||||
{
|
||||
throw new IllegalStateException("No current user!");
|
||||
}
|
||||
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
String userConnectionId = createUserConnectionId(currentUser, connectionId);
|
||||
return userConnections.get(userConnectionId);
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<CMISConnection> getSharedConnections()
|
||||
public List<CMISConnection> getSharedConnections()
|
||||
{
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
return Collections.unmodifiableCollection(sharedConnections.values());
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
List<CMISConnection> result = new ArrayList<CMISConnection>(sharedConnections.values());
|
||||
|
||||
public CMISConnection getSharedConnection(String connectionId)
|
||||
{
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
return sharedConnections.get(connectionId);
|
||||
Collections.sort(result);
|
||||
return Collections.unmodifiableList(result);
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
@@ -275,7 +286,7 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
|
||||
public void removeConnection(CMISConnection connection)
|
||||
{
|
||||
if (connection == null || connection.getId() == null)
|
||||
if (connection == null || connection.getInternalId() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -283,19 +294,12 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
if (connection.isLocal())
|
||||
if (connection.isShared())
|
||||
{
|
||||
userConnections.remove(LOCAL_CONNECTION_ID);
|
||||
sharedConnections.remove(connection.getInternalId());
|
||||
} else
|
||||
{
|
||||
int idx = connection.getId().indexOf(RESERVED_ID_CHAR);
|
||||
if (idx == -1)
|
||||
{
|
||||
sharedConnections.remove(connection.getId());
|
||||
} else
|
||||
{
|
||||
userConnections.remove(connection.getId());
|
||||
}
|
||||
userConnections.remove(connection.getInternalId());
|
||||
}
|
||||
} finally
|
||||
{
|
||||
@@ -314,25 +318,23 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<CMISServer> getServerDefinitions()
|
||||
// --- servers ---
|
||||
|
||||
public List<CMISServer> getServerDefinitions()
|
||||
{
|
||||
return servers == null ? null : servers.values();
|
||||
return servers == null ? null : Collections.unmodifiableList(new ArrayList<CMISServer>(servers.values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMISServer getServerDefinition(String serverName)
|
||||
{
|
||||
return servers == null ? null : servers.get(serverName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMISServer createServerDefinition(String serverName, Map<String, String> parameters)
|
||||
{
|
||||
return new CMISServerImpl(serverName, null, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMISServer createServerDefinition(CMISServer server, String username, String password)
|
||||
{
|
||||
if (server == null)
|
||||
@@ -347,7 +349,6 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
return new CMISServerImpl(server.getName(), server.getDescription(), parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMISServer createServerDefinition(CMISServer server, String username, String password, String repositoryId)
|
||||
{
|
||||
if (server == null)
|
||||
@@ -384,7 +385,6 @@ public abstract class AbstractCMISConnectionManagerImpl implements CMISConnectio
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Repository> getRepositories(CMISServer server)
|
||||
{
|
||||
if (server == null)
|
||||
|
@@ -23,17 +23,24 @@ import org.apache.chemistry.opencmis.client.api.Session;
|
||||
/**
|
||||
* Represents a CMIS connection.
|
||||
*/
|
||||
public interface CMISConnection
|
||||
public interface CMISConnection extends Comparable<CMISConnection>
|
||||
{
|
||||
/**
|
||||
* Gets connection id.
|
||||
* Gets the connection id.
|
||||
*
|
||||
* @return connection id
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Gets OpenCMIS Session.
|
||||
* Gets the internal connection id.
|
||||
*
|
||||
* @return connection id
|
||||
*/
|
||||
String getInternalId();
|
||||
|
||||
/**
|
||||
* Gets the OpenCMIS Session.
|
||||
*
|
||||
* @return OpenCMIS session
|
||||
*/
|
||||
@@ -54,9 +61,19 @@ public interface CMISConnection
|
||||
String getUserName();
|
||||
|
||||
/**
|
||||
* Indicates if the connection is a local or a remote connection.
|
||||
* Indicates if the connection is shared by multiple users.
|
||||
*/
|
||||
boolean isLocal();
|
||||
boolean isShared();
|
||||
|
||||
/**
|
||||
* Indicates if the connection is the default connection.
|
||||
*/
|
||||
boolean isDefault();
|
||||
|
||||
/**
|
||||
* Indicates is the repository supports queries.
|
||||
*/
|
||||
boolean supportsQuery();
|
||||
|
||||
/**
|
||||
* Releases the CMIS session and removes the connection from connection
|
||||
|
@@ -19,19 +19,22 @@
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import org.apache.chemistry.opencmis.client.api.Session;
|
||||
import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
|
||||
|
||||
public class CMISConnectionImpl implements CMISConnection
|
||||
{
|
||||
private AbstractCMISConnectionManagerImpl connectionManager;
|
||||
|
||||
private String id;
|
||||
private String internalId;
|
||||
private Session session;
|
||||
private CMISServer server;
|
||||
private String username;
|
||||
private boolean isLocal;
|
||||
private boolean isDefault;
|
||||
private boolean isShared;
|
||||
|
||||
public CMISConnectionImpl(AbstractCMISConnectionManagerImpl connectionManager, String id, Session session,
|
||||
CMISServer server, String username, boolean isLocal)
|
||||
CMISServer server, String username, boolean isDefault, boolean isShared)
|
||||
{
|
||||
if (connectionManager == null)
|
||||
{
|
||||
@@ -49,47 +52,75 @@ public class CMISConnectionImpl implements CMISConnection
|
||||
}
|
||||
|
||||
this.connectionManager = connectionManager;
|
||||
this.id = id;
|
||||
this.internalId = id;
|
||||
int x = id.indexOf(AbstractCMISConnectionManagerImpl.RESERVED_ID_CHAR);
|
||||
this.id = (x > -1 ? id.substring(0, x) : id);
|
||||
this.session = session;
|
||||
this.server = server;
|
||||
this.username = username;
|
||||
this.isLocal = isLocal;
|
||||
this.isDefault = isDefault;
|
||||
this.isShared = isShared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getInternalId()
|
||||
{
|
||||
return internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMISServer getServer()
|
||||
{
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserName()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocal()
|
||||
public boolean isDefault()
|
||||
{
|
||||
return isLocal;
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public boolean isShared()
|
||||
{
|
||||
return isShared;
|
||||
}
|
||||
|
||||
public boolean supportsQuery()
|
||||
{
|
||||
if (session == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (session.getRepositoryInfo().getCapabilities() == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return session.getRepositoryInfo().getCapabilities().getQueryCapability() != CapabilityQuery.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
connectionManager.removeConnection(this);
|
||||
session = null;
|
||||
}
|
||||
|
||||
public int compareTo(CMISConnection conn)
|
||||
{
|
||||
return id.compareTo(conn.getId());
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -31,6 +30,12 @@ public interface CMISConnectionManager
|
||||
{
|
||||
// --- connections ---
|
||||
|
||||
/**
|
||||
* Creates a new default connection that is only visible to the current
|
||||
* user.
|
||||
*/
|
||||
CMISConnection createDefaultConnection(CMISServer server);
|
||||
|
||||
/**
|
||||
* Creates a new connection that is only visible to the current user.
|
||||
*/
|
||||
@@ -47,33 +52,27 @@ public interface CMISConnectionManager
|
||||
CMISConnection getConnection();
|
||||
|
||||
/**
|
||||
* Returns all user connections.
|
||||
* Returns a specific connection or <code>null</code> if the connection id
|
||||
* is unknown.
|
||||
*/
|
||||
Collection<CMISConnection> getUserConnections();
|
||||
CMISConnection getConnection(String connectionId);
|
||||
|
||||
/**
|
||||
* Returns a specific user connection or <code>null</code> if the connection
|
||||
* id is unknown.
|
||||
* Returns all user connections.
|
||||
*/
|
||||
CMISConnection getUserConnections(String connectionId);
|
||||
List<CMISConnection> getUserConnections();
|
||||
|
||||
/**
|
||||
* Returns all shared connections.
|
||||
*/
|
||||
Collection<CMISConnection> getSharedConnections();
|
||||
|
||||
/**
|
||||
* Returns a specific shared connection or <code>null</code> if the
|
||||
* connection id is unknown.
|
||||
*/
|
||||
CMISConnection getSharedConnection(String connectionId);
|
||||
List<CMISConnection> getSharedConnections();
|
||||
|
||||
// --- servers ---
|
||||
|
||||
/**
|
||||
* Returns all configured server definitions.
|
||||
*/
|
||||
Collection<CMISServer> getServerDefinitions();
|
||||
List<CMISServer> getServerDefinitions();
|
||||
|
||||
/**
|
||||
* Gets a server definitions by name.
|
||||
|
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
||||
import org.apache.chemistry.opencmis.client.api.Document;
|
||||
import org.apache.chemistry.opencmis.client.api.Session;
|
||||
import org.apache.chemistry.opencmis.commons.data.ContentStream;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
|
||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* WebScript for CMIS links.
|
||||
*/
|
||||
public class CMISContentStreamWebScript extends AbstractWebScript
|
||||
{
|
||||
public static final String DOC_ID = "id";
|
||||
public static final String STREAM_ID = "stream";
|
||||
public static final String CONNECTION = "conn";
|
||||
|
||||
private CMISConnectionManager connectionManager;
|
||||
|
||||
public void setConnectionManager(CMISConnectionManager connectionManager)
|
||||
{
|
||||
this.connectionManager = connectionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
|
||||
{
|
||||
CMISConnection conn = null;
|
||||
|
||||
String docId = req.getParameter(DOC_ID);
|
||||
String streamId = req.getParameter(STREAM_ID);
|
||||
|
||||
String connectionId = req.getParameter(CONNECTION);
|
||||
|
||||
if (connectionId != null)
|
||||
{
|
||||
conn = connectionManager.getConnection(connectionId);
|
||||
} else
|
||||
{
|
||||
conn = connectionManager.getConnection();
|
||||
}
|
||||
|
||||
if (conn == null)
|
||||
{
|
||||
throw new WebScriptException(500, "Invalid connection!");
|
||||
}
|
||||
|
||||
Session session = conn.getSession();
|
||||
|
||||
// get object
|
||||
CmisObject object;
|
||||
try
|
||||
{
|
||||
object = session.getObject(docId);
|
||||
} catch (CmisBaseException e)
|
||||
{
|
||||
if (e instanceof CmisObjectNotFoundException)
|
||||
{
|
||||
throw new WebScriptException(404, "Object not found!", e);
|
||||
} else
|
||||
{
|
||||
throw new WebScriptException(500, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(object instanceof Document))
|
||||
{
|
||||
throw new WebScriptException(404, "Object is not a document!");
|
||||
}
|
||||
|
||||
// get document content
|
||||
Document document = (Document) object;
|
||||
ContentStream stream = streamId == null ? document.getContentStream() : document.getContentStream(streamId);
|
||||
|
||||
// stream content
|
||||
if (stream.getMimeType() != null)
|
||||
{
|
||||
res.setContentType(stream.getMimeType());
|
||||
}
|
||||
long length = stream.getLength();
|
||||
if (length != -1)
|
||||
{
|
||||
res.setHeader("Content-Length", Long.toString(length));
|
||||
}
|
||||
FileCopyUtils.copy(stream.getStream(), res.getOutputStream());
|
||||
}
|
||||
}
|
83
source/java/org/alfresco/repo/cmis/client/CMISHelper.java
Normal file
83
source/java/org/alfresco/repo/cmis/client/CMISHelper.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.alfresco.repo.jscript.ScriptableHashMap;
|
||||
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
||||
import org.apache.chemistry.opencmis.client.api.Document;
|
||||
import org.apache.chemistry.opencmis.client.api.Folder;
|
||||
import org.apache.chemistry.opencmis.client.api.Policy;
|
||||
import org.apache.chemistry.opencmis.client.api.Relationship;
|
||||
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
|
||||
import org.springframework.extensions.surf.util.InputStreamContent;
|
||||
|
||||
public class CMISHelper
|
||||
{
|
||||
/**
|
||||
* Creates a properties map.
|
||||
*/
|
||||
public ScriptableHashMap<String, Object> createMap()
|
||||
{
|
||||
return new ScriptableHashMap<String, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ContentStream object.
|
||||
*/
|
||||
public ContentStreamImpl createContentStream(String filename, long length, String mimetype, InputStream stream)
|
||||
{
|
||||
return new ContentStreamImpl(filename, length < 0 ? null : BigInteger.valueOf(length), mimetype, stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ContentStream object.
|
||||
*/
|
||||
public ContentStreamImpl createContentStream(String filename, InputStreamContent content)
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
throw new IllegalArgumentException("No content!");
|
||||
}
|
||||
|
||||
return createContentStream(filename, content.getSize(), content.getMimetype(), content.getInputStream());
|
||||
}
|
||||
|
||||
public boolean isDocument(CmisObject object)
|
||||
{
|
||||
return (object instanceof Document);
|
||||
}
|
||||
|
||||
public boolean isFolder(CmisObject object)
|
||||
{
|
||||
return (object instanceof Folder);
|
||||
}
|
||||
|
||||
public boolean isPolicy(CmisObject object)
|
||||
{
|
||||
return (object instanceof Policy);
|
||||
}
|
||||
|
||||
public boolean isRelationship(CmisObject object)
|
||||
{
|
||||
return (object instanceof Relationship);
|
||||
}
|
||||
}
|
@@ -21,6 +21,7 @@ package org.alfresco.repo.cmis.client;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
|
||||
import org.alfresco.opencmis.AlfrescoLocalCmisServiceFactory;
|
||||
import org.alfresco.opencmis.CMISConnector;
|
||||
import org.apache.chemistry.opencmis.client.api.Session;
|
||||
@@ -40,6 +41,12 @@ public class CMISLocalConnectionManagerImpl extends AbstractCMISConnectionManage
|
||||
AlfrescoLocalCmisServiceFactory.setCmisConnector(connector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMISConnection createDefaultConnection(CMISServer server)
|
||||
{
|
||||
throw new IllegalStateException("Local connection cannot be changed!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a local connection.
|
||||
*/
|
||||
@@ -49,7 +56,7 @@ public class CMISLocalConnectionManagerImpl extends AbstractCMISConnectionManage
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
CMISConnection connection = getUserConnections(LOCAL_CONNECTION_ID);
|
||||
CMISConnection connection = getConnection(DEFAULT_CONNECTION_ID);
|
||||
if (connection != null)
|
||||
{
|
||||
return connection;
|
||||
@@ -60,13 +67,14 @@ public class CMISLocalConnectionManagerImpl extends AbstractCMISConnectionManage
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.put(SessionParameter.BINDING_TYPE, BindingType.LOCAL.value());
|
||||
parameters.put(SessionParameter.LOCAL_FACTORY, AlfrescoLocalCmisServiceFactory.class.getName());
|
||||
parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, AlfrescoObjectFactoryImpl.class.getName());
|
||||
parameters.put(SessionParameter.USER, currentUser);
|
||||
|
||||
CMISServer server = createServerDefinition("local", parameters);
|
||||
CMISServer server = createServerDefinition("default", parameters);
|
||||
Session session = createSession(server.getParameters());
|
||||
connection = new CMISConnectionImpl(this, LOCAL_CONNECTION_ID, session, server, currentUser, true);
|
||||
String userConnectionId = createUserConnectionId(currentUser, DEFAULT_CONNECTION_ID);
|
||||
|
||||
String userConnectionId = createUserConnectionId(currentUser, LOCAL_CONNECTION_ID);
|
||||
connection = new CMISConnectionImpl(this, userConnectionId, session, server, currentUser, true, false);
|
||||
|
||||
userConnections.put(userConnectionId, connection);
|
||||
|
||||
|
@@ -18,21 +18,54 @@
|
||||
*/
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.chemistry.opencmis.client.api.Session;
|
||||
import org.apache.chemistry.opencmis.commons.SessionParameter;
|
||||
|
||||
/**
|
||||
* CMIS Connection manager with a remote default connection.
|
||||
*/
|
||||
public class CMISRemoteConnectionManagerImpl extends AbstractCMISConnectionManagerImpl implements CMISConnectionManager
|
||||
{
|
||||
private CMISServer defaultServer;
|
||||
|
||||
/**
|
||||
* Sets the remote server details.
|
||||
*/
|
||||
public void setDefaultServer(Map<String, String> defaultServerProperties)
|
||||
@Override
|
||||
public CMISConnection createDefaultConnection(CMISServer server)
|
||||
{
|
||||
defaultServer = createServerDefinition(defaultServerProperties);
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
CMISConnection connection = getConnection();
|
||||
if (connection != null)
|
||||
{
|
||||
throw new IllegalStateException("Connection id is already in use!");
|
||||
}
|
||||
|
||||
if (server == null)
|
||||
{
|
||||
throw new IllegalStateException("Server definition must be set!");
|
||||
}
|
||||
|
||||
String currentUser = authenticationService.getCurrentUserName();
|
||||
|
||||
if (!server.getParameters().containsKey(SessionParameter.USER))
|
||||
{
|
||||
Map<String, String> parameters = new HashMap<String, String>(server.getParameters());
|
||||
parameters.put(SessionParameter.USER, currentUser);
|
||||
server = createServerDefinition(server.getName(), parameters);
|
||||
}
|
||||
|
||||
String userConnectionId = createUserConnectionId(currentUser, DEFAULT_CONNECTION_ID);
|
||||
Session session = createSession(server.getParameters());
|
||||
connection = new CMISConnectionImpl(this, userConnectionId, session, server, currentUser, true, false);
|
||||
|
||||
userConnections.put(userConnectionId, connection);
|
||||
|
||||
return connection;
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,28 +74,6 @@ public class CMISRemoteConnectionManagerImpl extends AbstractCMISConnectionManag
|
||||
@Override
|
||||
public CMISConnection getConnection()
|
||||
{
|
||||
lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
CMISConnection connection = getUserConnections(LOCAL_CONNECTION_ID);
|
||||
if (connection != null)
|
||||
{
|
||||
return connection;
|
||||
}
|
||||
|
||||
String currentUser = authenticationService.getCurrentUserName();
|
||||
|
||||
if (defaultServer == null)
|
||||
{
|
||||
throw new IllegalStateException("No default server defined!");
|
||||
}
|
||||
|
||||
CMISServer server = createServerDefinition(defaultServer, currentUser, null);
|
||||
|
||||
return createUserConnection(server, LOCAL_CONNECTION_ID);
|
||||
} finally
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
return getConnection(DEFAULT_CONNECTION_ID);
|
||||
}
|
||||
}
|
||||
|
@@ -44,19 +44,16 @@ public class CMISServerImpl implements CMISServer
|
||||
this.parameters = new HashMap<String, String>(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParameters()
|
||||
{
|
||||
return Collections.unmodifiableMap(parameters);
|
||||
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* CMIS server configuration element.
|
||||
*/
|
||||
public class CMISServersConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final String CONFIG_ELEMENT_ID = "cmis-servers";
|
||||
|
||||
private final Map<String, CMISServer> serverDefintions = new HashMap<String, CMISServer>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CMISServersConfigElement(Element element)
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
|
||||
for (Element childElement : ((List<Element>) element.elements("server")))
|
||||
{
|
||||
Map<String, String> parameters = new LinkedHashMap<String, String>();
|
||||
String name = null;
|
||||
String description = null;
|
||||
|
||||
for (Element parameterElement : ((List<Element>) childElement.elements("parameter")))
|
||||
{
|
||||
String key = parameterElement.attributeValue("key");
|
||||
String value = parameterElement.attributeValue("value");
|
||||
if (key != null && value != null)
|
||||
{
|
||||
if (key.equals("name"))
|
||||
{
|
||||
name = value;
|
||||
} else if (key.equals("description"))
|
||||
{
|
||||
description = value;
|
||||
} else
|
||||
{
|
||||
parameters.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
serverDefintions.put(name, new CMISServerImpl(name, description, parameters));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
if (configElement instanceof CMISServersConfigElement)
|
||||
{
|
||||
serverDefintions.putAll(((CMISServersConfigElement) configElement).getServerDefinitions());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, CMISServer> getServerDefinitions()
|
||||
{
|
||||
return serverDefintions;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.client;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
|
||||
/**
|
||||
* CMIS server configurations reader.
|
||||
*/
|
||||
public class CMISServersConfigElementReader implements ConfigElementReader
|
||||
{
|
||||
@Override
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
ConfigElement configElement = null;
|
||||
if (element != null)
|
||||
{
|
||||
configElement = new CMISServersConfigElement(element);
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user