mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
REPO-1296 EOL spring-social and publishing channels (#68)
* removed spring-social libs and publishing channels code * move deprecated models to alfresco/models/deprecated
This commit is contained in:
File diff suppressed because one or more lines are too long
32
pom.xml
32
pom.xml
@@ -567,38 +567,6 @@
|
||||
<version>${dependency.webscripts.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Social -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.social</groupId>
|
||||
<artifactId>spring-social-core</artifactId>
|
||||
<version>1.0.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.social</groupId>
|
||||
<artifactId>spring-social-linkedin</artifactId>
|
||||
<version>1.0.0-20110711</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.social</groupId>
|
||||
<artifactId>spring-social-facebook</artifactId>
|
||||
<version>1.1.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.social</groupId>
|
||||
<artifactId>spring-social-facebook-web</artifactId>
|
||||
<version>1.1.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.social</groupId>
|
||||
<artifactId>spring-social-web</artifactId>
|
||||
<version>1.1.4.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.social</groupId>
|
||||
<artifactId>spring-social-twitter</artifactId>
|
||||
<version>1.1.2.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Chemistry -->
|
||||
<dependency>
|
||||
<groupId>org.apache.chemistry.opencmis</groupId>
|
||||
|
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.node.encryption.MetadataEncryptor;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelType;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractChannelType implements ChannelType, ChannelTypePublishingOperations
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private ChannelService channelService;
|
||||
private MetadataEncryptor encryptor;
|
||||
private boolean hidden = false;
|
||||
|
||||
public void setChannelService(ChannelService channelService)
|
||||
{
|
||||
this.channelService = channelService;
|
||||
channelService.register(this);
|
||||
}
|
||||
|
||||
protected ChannelService getChannelService()
|
||||
{
|
||||
return channelService;
|
||||
}
|
||||
|
||||
public void setEncryptor(MetadataEncryptor encryptor)
|
||||
{
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
protected MetadataEncryptor getEncryptor()
|
||||
{
|
||||
return encryptor;
|
||||
}
|
||||
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
return nodeService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
String title = I18NUtil.getMessage("publishing.channel-type." + getId() + ".title");
|
||||
return title == null ? getId() : title;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getMaximumStatusLength()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthUrlPair getAuthorisationUrls(Channel channel, String callbackUrl)
|
||||
{
|
||||
// Returning a null as the authorisation request URL here to indicate that we should use our own
|
||||
// credential-gathering mechanism.
|
||||
return new AuthUrlPair(null, callbackUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AuthStatus acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders,
|
||||
Map<String, String[]> callbackParams)
|
||||
{
|
||||
ParameterCheck.mandatory("channel", channel);
|
||||
ParameterCheck.mandatory("callbackHeaders", callbackHeaders);
|
||||
ParameterCheck.mandatory("callbackParams", callbackParams);
|
||||
if (!getId().equals(channel.getChannelType().getId()))
|
||||
{
|
||||
throw new IllegalArgumentException("Supplied channel is of the incorrect type. Expected " + getId()
|
||||
+ "; Received " + channel.getChannelType().getId());
|
||||
}
|
||||
|
||||
AuthStatus result = internalAcceptAuthorisation(channel, callbackHeaders, callbackParams);
|
||||
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
props.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.valueOf(AuthStatus.AUTHORISED.equals(result)));
|
||||
channelService.updateChannel(channel, props);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
|
||||
Map<String, String[]> callbackParams)
|
||||
{
|
||||
AuthStatus result = AuthStatus.UNAUTHORISED;
|
||||
String[] username = callbackParams.get("username");
|
||||
String[] password = callbackParams.get("password");
|
||||
if (username != null && password != null)
|
||||
{
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
props.put(PublishingModel.PROP_CHANNEL_USERNAME, username[0]);
|
||||
props.put(PublishingModel.PROP_CHANNEL_PASSWORD, password[0]);
|
||||
channelService.updateChannel(channel, props);
|
||||
// TODO: BJR: 20110707: Should test the connection here
|
||||
result = AuthStatus.AUTHORISED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Resource getIcon(String sizeSuffix)
|
||||
{
|
||||
String className = this.getClass().getCanonicalName();
|
||||
className = className.replaceAll("\\.", "\\/");
|
||||
StringBuilder iconPath = new StringBuilder(className);
|
||||
iconPath.append(sizeSuffix).append('.').append(getIconFileExtension());
|
||||
Resource resource = new ClassPathResource(iconPath.toString());
|
||||
return resource.exists() ? resource : null;
|
||||
}
|
||||
|
||||
public String getIconFileExtension()
|
||||
{
|
||||
return "png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<QName> getSupportedContentTypes()
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedMimeTypes()
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusUpdate(Channel channel, String status)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> channelProperties)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> channelProperties)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
String url = null;
|
||||
if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, PublishingModel.ASPECT_ASSET))
|
||||
{
|
||||
url = (String)nodeService.getProperty(node, PublishingModel.PROP_ASSET_URL);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden()
|
||||
{
|
||||
return hidden;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHidden(boolean hidden)
|
||||
{
|
||||
this.hidden = hidden;
|
||||
}
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.connect.support.OAuth1ConnectionFactory;
|
||||
import org.springframework.social.oauth1.AuthorizedRequestToken;
|
||||
import org.springframework.social.oauth1.OAuth1Operations;
|
||||
import org.springframework.social.oauth1.OAuth1Parameters;
|
||||
import org.springframework.social.oauth1.OAuthToken;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*
|
||||
* @param <A> The API type, e.g. Twitter, Flickr, LinkedIn, etc.
|
||||
*/
|
||||
public abstract class AbstractOAuth1ChannelType<A> extends AbstractChannelType
|
||||
{
|
||||
private OAuth1ConnectionFactory<A> connectionFactory;
|
||||
|
||||
protected Connection<A> getConnectionForChannel(NodeRef channelNode)
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
Connection<A> connection = null;
|
||||
if (nodeService.exists(channelNode)
|
||||
&& nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL))
|
||||
{
|
||||
String tokenValue = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, nodeService
|
||||
.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE));
|
||||
String tokenSecret = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, nodeService
|
||||
.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET));
|
||||
Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||
|
||||
if (danceComplete)
|
||||
{
|
||||
OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
|
||||
connection = connectionFactory.createConnection(token);
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthUrlPair getAuthorisationUrls(Channel channel, String callbackUrl)
|
||||
{
|
||||
ParameterCheck.mandatory("channel", channel);
|
||||
ParameterCheck.mandatory("callbackUrl", callbackUrl);
|
||||
if (!getId().equals(channel.getChannelType().getId()))
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid channel type: " + channel.getChannelType().getId());
|
||||
}
|
||||
|
||||
NodeService nodeService = getNodeService();
|
||||
OAuth1Operations oauthOperations = getOAuth1Operations();
|
||||
OAuthToken requestToken = oauthOperations.fetchRequestToken(callbackUrl, null);
|
||||
|
||||
NodeRef channelNodeRef = channel.getNodeRef();
|
||||
nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_SECRET,
|
||||
getEncryptor().encrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, requestToken.getSecret()));
|
||||
nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_VALUE,
|
||||
getEncryptor().encrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, requestToken.getValue()));
|
||||
|
||||
String authUrl = oauthOperations.buildAuthorizeUrl(requestToken.getValue(), getOAuth1Parameters(callbackUrl));
|
||||
return new AuthUrlPair(authUrl, callbackUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
|
||||
Map<String, String[]> callbackParams)
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
AuthStatus authorised = AuthStatus.UNAUTHORISED;
|
||||
String[] verifier = callbackParams.get(getOAuthVerifierParamName());
|
||||
if (verifier != null)
|
||||
{
|
||||
OAuth1Operations oauthOperations = getOAuth1Operations();
|
||||
NodeRef channelNodeRef = channel.getNodeRef();
|
||||
|
||||
Map<QName, Serializable> currentProps = nodeService.getProperties(channelNodeRef);
|
||||
String tokenValue = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, currentProps
|
||||
.get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE));
|
||||
String tokenSecret = (String) getEncryptor().decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, currentProps
|
||||
.get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET));
|
||||
OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
|
||||
OAuthToken accessToken = oauthOperations.exchangeForAccessToken(new AuthorizedRequestToken(token, verifier[0]), null);
|
||||
|
||||
Map<QName, Serializable> newProps = new HashMap<QName, Serializable>();
|
||||
newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue());
|
||||
newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret());
|
||||
newProps = getEncryptor().encrypt(newProps);
|
||||
getChannelService().updateChannel(channel, newProps);
|
||||
authorised = AuthStatus.AUTHORISED;
|
||||
}
|
||||
return authorised;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to add additonal parameters onto the URL that the user is redirected to
|
||||
* to authorise access to their account. By default, no parameters are added, but this may be useful to
|
||||
* specify things such as the permissions being sought, and so on.
|
||||
* @param callbackUrl String
|
||||
* @return Do not return null. If no parameters are to be added, return {@link OAuth1Parameters#NONE}
|
||||
*/
|
||||
protected OAuth1Parameters getOAuth1Parameters(String callbackUrl)
|
||||
{
|
||||
return OAuth1Parameters.NONE;
|
||||
}
|
||||
|
||||
protected String getOAuthVerifierParamName()
|
||||
{
|
||||
return "oauth_verifier";
|
||||
}
|
||||
|
||||
private OAuth1Operations getOAuth1Operations()
|
||||
{
|
||||
return connectionFactory.getOAuthOperations();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param connectionFactory the connectionFactory to set
|
||||
*/
|
||||
public void setConnectionFactory(OAuth1ConnectionFactory<A> connectionFactory)
|
||||
{
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
}
|
@@ -1,454 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import static org.alfresco.model.ContentModel.ASSOC_CONTAINS;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASPECT_PUBLISHED;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASSOC_SOURCE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_CHANNEL;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_CHANNEL_TYPE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_CHANNEL_TYPE_ID;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeUtils;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelType;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.alfresco.util.collections.Filter;
|
||||
import org.alfresco.util.collections.Function;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ChannelHelper
|
||||
{
|
||||
public static final String NAME = "channelHelper";
|
||||
|
||||
private NodeService nodeService;
|
||||
private DictionaryService dictionaryService;
|
||||
private FileFolderService fileFolderService;
|
||||
private PermissionService permissionService;
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private PublishingEventHelper eventHelper;
|
||||
|
||||
public ChannelHelper()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public ChannelHelper(ServiceRegistry serviceRegistry, PublishingEventHelper eventHelper)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.eventHelper = eventHelper;
|
||||
}
|
||||
|
||||
public NodeRef createChannelNode(NodeRef parent, ChannelType channelType, String channelName,
|
||||
Map<QName, Serializable> props)
|
||||
{
|
||||
QName channelQName = getChannelQName(channelName);
|
||||
QName channelNodeType = channelType.getChannelNodeType();
|
||||
ChildAssociationRef channelAssoc =
|
||||
nodeService.createNode(parent, ASSOC_CONTAINS, channelQName, channelNodeType, props);
|
||||
NodeRef channelNode = channelAssoc.getChildRef();
|
||||
// Allow any user to read Channel permissions.
|
||||
permissionService.setPermission(channelNode, PermissionService.ALL_AUTHORITIES, PermissionService.READ_ASSOCIATIONS, true);
|
||||
return channelNode;
|
||||
}
|
||||
|
||||
public Channel buildChannelObject(NodeRef nodeRef, ChannelService channelService)
|
||||
{
|
||||
if (nodeRef == null || nodeService.exists(nodeRef) == false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
|
||||
String channelTypeId = (String) props.get(PROP_CHANNEL_TYPE_ID);
|
||||
ChannelType channelType = channelService.getChannelType(channelTypeId);
|
||||
String name = (String) props.get(ContentModel.PROP_NAME);
|
||||
return new ChannelImpl(serviceRegistry, (AbstractChannelType) channelType, nodeRef, name, this, eventHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a noderef from the editorial space (e.g. the doclib), this returns the corresponding noderef published to the specified channel.
|
||||
* @param source NodeRef
|
||||
* @param channelNode NodeRef
|
||||
* @return NodeRef
|
||||
*/
|
||||
public NodeRef mapSourceToEnvironment(NodeRef source, final NodeRef channelNode)
|
||||
{
|
||||
return mapSourceToEnvironment(source, channelNode, nodeService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a noderef from the editorial space (e.g. the doclib), this returns the corresponding noderef published to the specified channel.
|
||||
* @param source NodeRef
|
||||
* @param channelNode NodeRef
|
||||
* @param nodeService NodeService
|
||||
* @return NodeRef
|
||||
*/
|
||||
public static NodeRef mapSourceToEnvironment(NodeRef source, final NodeRef channelNode, final NodeService nodeService)
|
||||
{
|
||||
if (source == null || channelNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(source, ASSOC_SOURCE);
|
||||
Function<? super AssociationRef, Boolean> acceptor = new Filter<AssociationRef>()
|
||||
{
|
||||
public Boolean apply(AssociationRef assoc)
|
||||
{
|
||||
NodeRef publishedNode = assoc.getSourceRef();
|
||||
NodeRef parent = nodeService.getPrimaryParent(publishedNode).getParentRef();
|
||||
return channelNode.equals(parent);
|
||||
}
|
||||
};
|
||||
AssociationRef assoc = CollectionUtils.findFirst(sourceAssocs, acceptor);
|
||||
return assoc == null ? null : assoc.getSourceRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a published noderef, this returns the corresponding source noderef in the editorial space (doclib).
|
||||
* @param publishedNode NodeRef
|
||||
* @return NodeRef
|
||||
*/
|
||||
public NodeRef mapEnvironmentToSource(NodeRef publishedNode)
|
||||
{
|
||||
return mapEnvironmentToSource(publishedNode, nodeService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a published noderef, this returns the corresponding source noderef in the editorial space (doclib).
|
||||
* @param publishedNode NodeRef
|
||||
* @param nodeService NodeService
|
||||
* @return NodeRef
|
||||
*/
|
||||
public static NodeRef mapEnvironmentToSource(NodeRef publishedNode, NodeService nodeService)
|
||||
{
|
||||
List<AssociationRef> assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_SOURCE);
|
||||
return NodeUtils.getSingleAssocNode(assocs, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the {@link Channel} NodeRef and {@link ChannelType} id for a given node, if such a Channel exists.
|
||||
* @param node NodeRef
|
||||
* @return a {@link Pair} containing the Channel {@link NodeRef} and ChannelType Id.
|
||||
*/
|
||||
public Pair<NodeRef, String> findChannelAndType(NodeRef node)
|
||||
{
|
||||
Pair<NodeRef, String> result = getChannelAndTypeIfChannel(node);
|
||||
if (result == null)
|
||||
{
|
||||
result = getChannelAndType(node);
|
||||
if (result == null)
|
||||
{
|
||||
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(node);
|
||||
if (parentAssoc != null)
|
||||
{
|
||||
NodeRef parent = parentAssoc.getParentRef();
|
||||
if (parent != null)
|
||||
{
|
||||
result = findChannelAndType(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Map<QName, Serializable> getChannelProperties(NodeRef channel)
|
||||
{
|
||||
return nodeService.getProperties(channel);
|
||||
}
|
||||
|
||||
public AssociationRef createMapping(NodeRef source, NodeRef publishedNode)
|
||||
{
|
||||
AssociationRef assoc = nodeService.createAssociation(publishedNode, source, ASSOC_SOURCE);
|
||||
return assoc;
|
||||
}
|
||||
|
||||
public boolean canPublish(NodeRef nodeToPublish, ChannelType type)
|
||||
{
|
||||
if (type.canPublish() == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
FileInfo file = fileFolderService.getFileInfo(nodeToPublish);
|
||||
ContentData contentData = file.getContentData();
|
||||
String mimetype = contentData == null ? null : contentData.getMimetype();
|
||||
boolean isContentTypeSupported = isContentTypeSupported(file.getType(), type);
|
||||
boolean isMimetypeSupported = isMimetypeSupported(mimetype, type);
|
||||
return isContentTypeSupported && isMimetypeSupported;
|
||||
}
|
||||
|
||||
private boolean isMimetypeSupported(String mimetype, ChannelType type)
|
||||
{
|
||||
Set<String> supportedMimetypes = type.getSupportedMimeTypes();
|
||||
if (supportedMimetypes == null || supportedMimetypes.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return supportedMimetypes.contains(mimetype);
|
||||
}
|
||||
|
||||
private boolean isContentTypeSupported(QName contentType, ChannelType type)
|
||||
{
|
||||
Set<QName> supportedContentTypes = type.getSupportedContentTypes();
|
||||
if (supportedContentTypes == null || supportedContentTypes.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
for (QName supportedType : supportedContentTypes)
|
||||
{
|
||||
if (contentType.equals(supportedType)
|
||||
|| dictionaryService.isSubClass(contentType, supportedType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private QName getChannelQName(String channelName)
|
||||
{
|
||||
return QName.createQName(NamespaceService.APP_MODEL_1_0_URI, channelName);
|
||||
}
|
||||
|
||||
private Pair<NodeRef, String> getChannelAndTypeIfChannel(NodeRef node)
|
||||
{
|
||||
QName type = nodeService.getType(node);
|
||||
if (dictionaryService.isSubClass(type, TYPE_DELIVERY_CHANNEL))
|
||||
{
|
||||
String channelTypeId = (String) nodeService.getProperty(node, PROP_CHANNEL_TYPE_ID);
|
||||
if (channelTypeId == null)
|
||||
{
|
||||
TypeDefinition typeDef = dictionaryService.getType(type);
|
||||
PropertyDefinition channelTypeProp = typeDef.getProperties().get(PROP_CHANNEL_TYPE_ID);
|
||||
if (channelTypeProp !=null)
|
||||
{
|
||||
channelTypeId = channelTypeProp.getDefaultValue();
|
||||
}
|
||||
}
|
||||
return new Pair<NodeRef, String>(node, channelTypeId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Channel> getAllChannels(NodeRef channelContainer, final ChannelService channelService)
|
||||
{
|
||||
List<ChildAssociationRef> channelAssocs = getChannelAssocs(channelContainer);
|
||||
return CollectionUtils.transform(channelAssocs, getChannelTransformer(channelService, false));
|
||||
}
|
||||
|
||||
|
||||
public List<Channel> getChannelsForTypes(final NodeRef containerNode, List<ChannelType> types, final ChannelService channelService, final boolean checkPermissions)
|
||||
{
|
||||
return CollectionUtils.transformFlat(types, new Function<ChannelType, List<Channel>>()
|
||||
{
|
||||
public List<Channel> apply(ChannelType channelType)
|
||||
{
|
||||
return getChannelsByType(containerNode, channelType.getId(), channelService, checkPermissions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<Channel> getChannelsByType(NodeRef containerNode, String channelTypeId, ChannelService channelService, boolean checkPermissions)
|
||||
{
|
||||
List<ChildAssociationRef> channelAssocs = getChannelAssocsByType(containerNode, channelTypeId);
|
||||
return CollectionUtils.transform(channelAssocs, getChannelTransformer(channelService, checkPermissions));
|
||||
}
|
||||
|
||||
public List<Channel> filterAuthorisedChannels(Collection<Channel> channels)
|
||||
{
|
||||
return CollectionUtils.filter(channels, new Filter<Channel>()
|
||||
{
|
||||
@Override
|
||||
public Boolean apply(Channel value)
|
||||
{
|
||||
return value.isAuthorised();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<ChannelType> getReleventChannelTypes(final NodeRef nodeToPublish, Collection<ChannelType> channelTypes)
|
||||
{
|
||||
return CollectionUtils.filter(channelTypes, new Filter<ChannelType>()
|
||||
{
|
||||
public Boolean apply(ChannelType type)
|
||||
{
|
||||
return canPublish(nodeToPublish, type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<ChannelType> getStatusUpdateChannelTypes(Collection<ChannelType> channelTypes)
|
||||
{
|
||||
return CollectionUtils.filter(channelTypes, new Filter<ChannelType>()
|
||||
{
|
||||
public Boolean apply(ChannelType type)
|
||||
{
|
||||
return type.canPublishStatusUpdates();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addPublishedAspect(NodeRef publishedNode, NodeRef channelNode)
|
||||
{
|
||||
nodeService.addAspect(publishedNode, ASPECT_PUBLISHED, null);
|
||||
}
|
||||
|
||||
private List<ChildAssociationRef> getChannelAssocs(NodeRef channelContainer)
|
||||
{
|
||||
if (channelContainer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Collection<QName> channelNodeTypes = dictionaryService.getSubTypes(TYPE_DELIVERY_CHANNEL, true);
|
||||
HashSet<QName> childNodeTypeQNames = new HashSet<QName>(channelNodeTypes);
|
||||
return nodeService.getChildAssocs(channelContainer, childNodeTypeQNames);
|
||||
}
|
||||
|
||||
private List<ChildAssociationRef> getChannelAssocsByType(NodeRef channelContainer, String channelTypeId)
|
||||
{
|
||||
if (channelContainer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return nodeService.getChildAssocsByPropertyValue(channelContainer, PROP_CHANNEL_TYPE_ID, channelTypeId);
|
||||
}
|
||||
|
||||
private Pair<NodeRef, String> getChannelAndType(NodeRef node)
|
||||
{
|
||||
NodeRef channel = (NodeRef) nodeService.getProperty(node, PROP_CHANNEL);
|
||||
if (channel != null)
|
||||
{
|
||||
String channelType = (String) nodeService.getProperty(node, PROP_CHANNEL_TYPE);
|
||||
return new Pair<NodeRef, String>(channel, channelType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Function<ChildAssociationRef, Channel> getChannelTransformer(final ChannelService channelService, final boolean checkPermissions)
|
||||
{
|
||||
return new Function<ChildAssociationRef, Channel>()
|
||||
{
|
||||
public Channel apply(ChildAssociationRef value)
|
||||
{
|
||||
NodeRef channelNode = value.getChildRef();
|
||||
if (checkPermissions && hasPublishPermissions(channelNode)==false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return buildChannelObject(channelNode, channelService);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean hasPublishPermissions(NodeRef channelNode)
|
||||
{
|
||||
AccessStatus access = permissionService.hasPermission(channelNode, PermissionService.ADD_CHILDREN);
|
||||
return AccessStatus.ALLOWED == access;
|
||||
}
|
||||
|
||||
public boolean isChannelAuthorised(NodeRef channelNode)
|
||||
{
|
||||
Boolean isAuthorised = Boolean.FALSE;
|
||||
if (nodeService.exists(channelNode))
|
||||
{
|
||||
isAuthorised = (Boolean)nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||
}
|
||||
return isAuthorised;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService the dictionaryService to set
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileFolderService the fileFolderService to set
|
||||
*/
|
||||
public void setFileFolderService(FileFolderService fileFolderService)
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permissionService the permissionService to set
|
||||
*/
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
public void setEventHelper(PublishingEventHelper eventHelper)
|
||||
{
|
||||
this.eventHelper = eventHelper;
|
||||
}
|
||||
}
|
@@ -1,413 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASPECT_PUBLISHED;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASSOC_LAST_PUBLISHING_EVENT;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.NAMESPACE;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeUtils;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.publishing.NodeSnapshot;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelType;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ChannelImpl implements Channel
|
||||
{
|
||||
private static final String PERMISSIONS_ERR_ACCESS_DENIED = "permissions.err_access_denied";
|
||||
private final NodeRef nodeRef;
|
||||
private final AbstractChannelType channelType;
|
||||
private final String name;
|
||||
private final ChannelHelper channelHelper;
|
||||
private final NodeService nodeService;
|
||||
private final DictionaryService dictionaryService;
|
||||
private final PublishingEventHelper eventHelper;
|
||||
|
||||
|
||||
public ChannelImpl(ServiceRegistry serviceRegistry, AbstractChannelType channelType, NodeRef nodeRef, String name,
|
||||
ChannelHelper channelHelper, PublishingEventHelper eventHelper)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.channelType = channelType;
|
||||
this.name = name;
|
||||
this.channelHelper = channelHelper;
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
this.dictionaryService = serviceRegistry.getDictionaryService();
|
||||
this.eventHelper = eventHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return nodeRef.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public ChannelType getChannelType()
|
||||
{
|
||||
return channelType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<QName, Serializable> getProperties()
|
||||
{
|
||||
return channelHelper.getChannelProperties(nodeRef);
|
||||
}
|
||||
|
||||
public void publishEvent(PublishingEvent event)
|
||||
{
|
||||
NodeRef eventNode = eventHelper.getPublishingEventNode(event.getId());
|
||||
for (PublishingPackageEntry entry : event.getPackage().getEntries())
|
||||
{
|
||||
if (entry.isPublish())
|
||||
{
|
||||
publishEntry(entry, eventNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
unpublishEntry(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unpublishEntry(final PublishingPackageEntry entry)
|
||||
{
|
||||
final NodeRef channelNode = getNodeRef();
|
||||
if (channelHelper.hasPublishPermissions(channelNode))
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
NodeRef unpublishedNode = channelHelper.mapSourceToEnvironment(entry.getNodeRef(), channelNode);
|
||||
if (NodeUtils.exists(unpublishedNode, nodeService))
|
||||
{
|
||||
unpublish(unpublishedNode);
|
||||
// Need to set as temporary to delete node instead of archiving.
|
||||
nodeService.addAspect(unpublishedNode, ContentModel.ASPECT_TEMPORARY, null);
|
||||
nodeService.deleteNode(unpublishedNode);
|
||||
}
|
||||
return unpublishedNode;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public NodeRef publishEntry(final PublishingPackageEntry entry, final NodeRef eventNode)
|
||||
{
|
||||
NodeRef publishedNode;
|
||||
//We decouple the permissions needed to publish from the permissions needed to do what's
|
||||
//necessary to actually do the publish. If that makes sense...
|
||||
//For example, a user may be able to publish to a channel even if they do not have permission
|
||||
//to add an aspect to a published node (which is a necessary part of the publishing process).
|
||||
if (channelHelper.hasPublishPermissions(getNodeRef()))
|
||||
{
|
||||
publishedNode = AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
NodeRef publishedNode = channelHelper.mapSourceToEnvironment(entry.getNodeRef(), getNodeRef());
|
||||
if (publishedNode == null)
|
||||
{
|
||||
publishedNode = publishNewNode(getNodeRef(), entry.getSnapshot());
|
||||
}
|
||||
else
|
||||
{
|
||||
updatePublishedNode(publishedNode, entry);
|
||||
}
|
||||
eventHelper.linkToLastEvent(publishedNode, eventNode);
|
||||
publish(publishedNode);
|
||||
return publishedNode;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AccessDeniedException(PERMISSIONS_ERR_ACCESS_DENIED);
|
||||
}
|
||||
return publishedNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new node under the root of the specified channel. The type,
|
||||
* aspects and properties of the node are determined by the supplied
|
||||
* snapshot.
|
||||
*
|
||||
* @param channel NodeRef
|
||||
* @param snapshot NodeSnapshot
|
||||
* @return the newly published node.
|
||||
*/
|
||||
private NodeRef publishNewNode(NodeRef channel, NodeSnapshot snapshot)
|
||||
{
|
||||
ParameterCheck.mandatory("channel", channel);
|
||||
ParameterCheck.mandatory("snapshot", snapshot);
|
||||
|
||||
NodeRef publishedNode = createPublishedNode(channel, snapshot);
|
||||
addAspects(publishedNode, snapshot.getAspects());
|
||||
NodeRef source = snapshot.getNodeRef();
|
||||
channelHelper.createMapping(source, publishedNode);
|
||||
return publishedNode;
|
||||
}
|
||||
|
||||
private void updatePublishedNode(NodeRef publishedNode, PublishingPackageEntry entry)
|
||||
{
|
||||
NodeSnapshot snapshot = entry.getSnapshot();
|
||||
Set<QName> newAspects = snapshot.getAspects();
|
||||
removeUnwantedAspects(publishedNode, newAspects);
|
||||
|
||||
Map<QName, Serializable> snapshotProps = snapshot.getProperties();
|
||||
removeUnwantedProperties(publishedNode, snapshotProps);
|
||||
|
||||
// Add new properties
|
||||
Map<QName, Serializable> newProps= new HashMap<QName, Serializable>(snapshotProps);
|
||||
newProps.remove(ContentModel.PROP_NODE_UUID);
|
||||
nodeService.setProperties(publishedNode, snapshotProps);
|
||||
|
||||
// Add new aspects
|
||||
addAspects(publishedNode, newAspects);
|
||||
|
||||
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(publishedNode, ASSOC_LAST_PUBLISHING_EVENT, RegexQNamePattern.MATCH_ALL);
|
||||
for (ChildAssociationRef assoc : assocs)
|
||||
{
|
||||
nodeService.removeChildAssociation(assoc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishedNode NodeRef
|
||||
* @param snapshotProps Map<QName, Serializable>
|
||||
*/
|
||||
private void removeUnwantedProperties(NodeRef publishedNode, Map<QName, Serializable> snapshotProps)
|
||||
{
|
||||
Map<QName, Serializable> publishProps = nodeService.getProperties(publishedNode);
|
||||
Set<QName> propsToRemove = new HashSet<QName>(publishProps.keySet());
|
||||
propsToRemove.removeAll(snapshotProps.keySet());
|
||||
|
||||
//We want to retain the published asset id and URL in the updated node...
|
||||
snapshotProps.put(PublishingModel.PROP_ASSET_ID, nodeService.getProperty(publishedNode,
|
||||
PublishingModel.PROP_ASSET_ID));
|
||||
snapshotProps.put(PublishingModel.PROP_ASSET_URL, nodeService.getProperty(publishedNode,
|
||||
PublishingModel.PROP_ASSET_URL));
|
||||
|
||||
for (QName propertyToRemove : propsToRemove)
|
||||
{
|
||||
nodeService.removeProperty(publishedNode, propertyToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishedNode NodeRef
|
||||
* @param newAspects Set<QName>
|
||||
*/
|
||||
private void removeUnwantedAspects(NodeRef publishedNode, Set<QName> newAspects)
|
||||
{
|
||||
Set<QName> aspectsToRemove = nodeService.getAspects(publishedNode);
|
||||
aspectsToRemove.removeAll(newAspects);
|
||||
aspectsToRemove.remove(ASPECT_PUBLISHED);
|
||||
aspectsToRemove.remove(PublishingModel.ASPECT_ASSET);
|
||||
for (QName publishedAssetAspect : dictionaryService.getSubAspects(PublishingModel.ASPECT_ASSET, true))
|
||||
{
|
||||
aspectsToRemove.remove(publishedAssetAspect);
|
||||
}
|
||||
|
||||
for (QName aspectToRemove : aspectsToRemove)
|
||||
{
|
||||
nodeService.removeAspect(publishedNode, aspectToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAspects(NodeRef publishedNode, Collection<QName> aspects)
|
||||
{
|
||||
Set<QName> currentAspects = nodeService.getAspects(publishedNode);
|
||||
for (QName aspect : aspects)
|
||||
{
|
||||
if (currentAspects.contains(aspect) == false)
|
||||
{
|
||||
nodeService.addAspect(publishedNode, aspect, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NodeRef createPublishedNode(NodeRef root, NodeSnapshot snapshot)
|
||||
{
|
||||
QName type = snapshot.getType();
|
||||
Map<QName, Serializable> actualProps = getPropertiesToPublish(snapshot);
|
||||
String name = (String) actualProps.get(ContentModel.PROP_NAME);
|
||||
if (name == null)
|
||||
{
|
||||
name = GUID.generate();
|
||||
}
|
||||
QName assocName = QName.createQName(NAMESPACE, name);
|
||||
ChildAssociationRef publishedAssoc = nodeService.createNode(root, PublishingModel.ASSOC_PUBLISHED_NODES, assocName, type, actualProps);
|
||||
NodeRef publishedNode = publishedAssoc.getChildRef();
|
||||
return publishedNode;
|
||||
}
|
||||
|
||||
private Map<QName, Serializable> getPropertiesToPublish(NodeSnapshot snapshot)
|
||||
{
|
||||
Map<QName, Serializable> properties = snapshot.getProperties();
|
||||
// Remove the Node Ref Id
|
||||
Map<QName, Serializable> actualProps = new HashMap<QName, Serializable>(properties);
|
||||
actualProps.remove(ContentModel.PROP_NODE_UUID);
|
||||
return actualProps;
|
||||
}
|
||||
|
||||
|
||||
private void publish(NodeRef nodeToPublish)
|
||||
{
|
||||
if (channelHelper.canPublish(nodeToPublish, channelType))
|
||||
{
|
||||
channelHelper.addPublishedAspect(nodeToPublish, nodeRef);
|
||||
channelType.publish(nodeToPublish, getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
private void unpublish(NodeRef nodeToUnpublish)
|
||||
{
|
||||
if (channelType.canUnpublish())
|
||||
{
|
||||
channelType.unpublish(nodeToUnpublish, getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void sendStatusUpdate(String status, String nodeUrl)
|
||||
{
|
||||
if (channelType.canPublishStatusUpdates())
|
||||
{
|
||||
int urlLength = nodeUrl == null ? 0 : nodeUrl.length();
|
||||
int maxLength = channelType.getMaximumStatusLength() - urlLength;
|
||||
if (maxLength > 0)
|
||||
{
|
||||
int endpoint = Math.min(maxLength, status.length());
|
||||
status = status.substring(0, endpoint );
|
||||
}
|
||||
String msg = nodeUrl == null ? status : status + nodeUrl;
|
||||
channelType.sendStatusUpdate(this, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getUrl(NodeRef publishedNode)
|
||||
{
|
||||
NodeRef mappedNode = channelHelper.mapSourceToEnvironment(publishedNode, nodeRef);
|
||||
return channelType.getNodeUrl(mappedNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isAuthorised()
|
||||
{
|
||||
return channelHelper.isChannelAuthorised(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean canPublish()
|
||||
{
|
||||
return channelType.canPublish() &&
|
||||
isAuthorised() &&
|
||||
channelHelper.hasPublishPermissions(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return channelType.canPublish() &&
|
||||
isAuthorised() &&
|
||||
channelHelper.hasPublishPermissions(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return channelType.canPublish() &&
|
||||
isAuthorised() &&
|
||||
channelHelper.hasPublishPermissions(nodeRef);
|
||||
}
|
||||
}
|
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_CHANNEL_TYPE_ID;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.encryption.MetadataEncryptor;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelType;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.alfresco.util.collections.Filter;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ChannelServiceImpl implements ChannelService
|
||||
{
|
||||
public static final String NAME = "ChannelService";
|
||||
|
||||
private final Map<String, ChannelType> channelTypes = new TreeMap<String, ChannelType>();
|
||||
private NodeService nodeService;
|
||||
private DictionaryService dictionaryService;
|
||||
private ChannelHelper channelHelper;
|
||||
private PublishingRootObject rootObject;
|
||||
private MetadataEncryptor encryptor;
|
||||
|
||||
/**
|
||||
* @param nodeService
|
||||
* the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService
|
||||
* the dictionaryService to set
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rootObject the rootObject to set
|
||||
*/
|
||||
public void setPublishingRootObject(PublishingRootObject rootObject)
|
||||
{
|
||||
this.rootObject = rootObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channelHelper the channelHelper to set
|
||||
*/
|
||||
public void setChannelHelper(ChannelHelper channelHelper)
|
||||
{
|
||||
this.channelHelper = channelHelper;
|
||||
}
|
||||
|
||||
public void setEncryptor(MetadataEncryptor encryptor)
|
||||
{
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void register(AbstractChannelType channelType)
|
||||
{
|
||||
ParameterCheck.mandatory("channelType", channelType);
|
||||
String id = channelType.getId();
|
||||
if (channelTypes.containsKey(id))
|
||||
{
|
||||
throw new IllegalArgumentException("Channel type " + id + " is already registered!");
|
||||
}
|
||||
channelTypes.put(id, channelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<ChannelType> getChannelTypes()
|
||||
{
|
||||
List<ChannelType> result = new ArrayList<ChannelType>();
|
||||
for (ChannelType channelType : channelTypes.values())
|
||||
{
|
||||
if (!channelType.isHidden())
|
||||
{
|
||||
result.add(channelType);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Channel createChannel(String channelTypeId, String name, Map<QName, Serializable> properties)
|
||||
{
|
||||
NodeRef channelContainer = getChannelContainer();
|
||||
ChannelType channelType = channelTypes.get(channelTypeId);
|
||||
if (channelType == null)
|
||||
{
|
||||
String message = "Channel Type: " + channelTypeId + " does not exist!";
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
Map<QName, Serializable> actualProps = new HashMap<QName, Serializable>();
|
||||
if (properties != null)
|
||||
{
|
||||
actualProps.putAll(properties);
|
||||
}
|
||||
actualProps.put(ContentModel.PROP_NAME, name);
|
||||
actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId());
|
||||
actualProps.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.FALSE);
|
||||
actualProps = encryptor.encrypt(actualProps);
|
||||
NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps);
|
||||
return channelHelper.buildChannelObject(channelNode, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void deleteChannel(Channel channel)
|
||||
{
|
||||
nodeService.deleteNode(channel.getNodeRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<Channel> getChannels()
|
||||
{
|
||||
NodeRef channelContainer = getChannelContainer();
|
||||
return channelHelper.getAllChannels(channelContainer, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Channel getChannelByName(String channelName)
|
||||
{
|
||||
NodeRef node = getChannelNodeByName(channelName);
|
||||
return channelHelper.buildChannelObject(node, this);
|
||||
}
|
||||
|
||||
private NodeRef getChannelNodeByName(String channelName)
|
||||
{
|
||||
ParameterCheck.mandatory("channelName", channelName);
|
||||
|
||||
NodeRef channelContainer = getChannelContainer();
|
||||
if (channelContainer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
NodeRef child = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName);
|
||||
if (child != null)
|
||||
{
|
||||
QName type = nodeService.getType(child);
|
||||
if (dictionaryService.isSubClass(type, TYPE_DELIVERY_CHANNEL))
|
||||
{
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<Channel> getRelevantPublishingChannels(NodeRef nodeToPublish)
|
||||
{
|
||||
NodeRef containerNode = getChannelContainer();
|
||||
List<ChannelType> types = channelHelper.getReleventChannelTypes(nodeToPublish, channelTypes.values());
|
||||
List<Channel> channels = channelHelper.getChannelsForTypes(containerNode, types, this, true);
|
||||
return channelHelper.filterAuthorisedChannels(channels);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<Channel> getPublishingChannels(boolean filterByPublishPermission)
|
||||
{
|
||||
final NodeRef containerNode = getChannelContainer();
|
||||
if (containerNode != null)
|
||||
{
|
||||
List<ChannelType> types = CollectionUtils.filter(channelTypes.values(), new Filter<ChannelType>()
|
||||
{
|
||||
public Boolean apply(ChannelType type)
|
||||
{
|
||||
return type.canPublish();
|
||||
}
|
||||
});
|
||||
return channelHelper.getChannelsForTypes(containerNode, types, this, filterByPublishPermission);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<Channel> getStatusUpdateChannels(boolean filterByPublishPermission)
|
||||
{
|
||||
final NodeRef containerNode = getChannelContainer();
|
||||
if (containerNode != null)
|
||||
{
|
||||
List<ChannelType> types = channelHelper.getStatusUpdateChannelTypes(channelTypes.values());
|
||||
return channelHelper.getChannelsForTypes(containerNode, types, this, filterByPublishPermission);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<Channel> getAuthorisedStatusUpdateChannels()
|
||||
{
|
||||
return channelHelper.filterAuthorisedChannels(getStatusUpdateChannels(false));
|
||||
}
|
||||
|
||||
private NodeRef getChannelContainer()
|
||||
{
|
||||
return rootObject.getChannelContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public ChannelType getChannelType(String id)
|
||||
{
|
||||
return channelTypes.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void renameChannel(Channel channel, String newName)
|
||||
{
|
||||
NodeRef channelNode = channel.getNodeRef();
|
||||
if (channelNode != null && nodeService.exists(channelNode))
|
||||
{
|
||||
NodeRef channelContainer = getChannelContainer();
|
||||
nodeService.setProperty(channelNode, ContentModel.PROP_NAME, newName);
|
||||
nodeService.moveNode(channelNode, channelContainer, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.APP_MODEL_1_0_URI, newName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void updateChannel(Channel channel, Map<QName, Serializable> properties)
|
||||
{
|
||||
Map<QName, Serializable> actualProps = new HashMap<QName, Serializable>(properties);
|
||||
actualProps.remove(ContentModel.PROP_NODE_UUID);
|
||||
NodeRef editorialNode = new NodeRef(channel.getId());
|
||||
actualProps = encryptor.encrypt(actualProps);
|
||||
for (Map.Entry<QName, Serializable> entry : actualProps.entrySet())
|
||||
{
|
||||
nodeService.setProperty(editorialNode, entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Channel getChannelById(String id)
|
||||
{
|
||||
if (id != null && NodeRef.isNodeRef(id))
|
||||
{
|
||||
NodeRef node = new NodeRef(id);
|
||||
return channelHelper.buildChannelObject(node, this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public interface ChannelTypePublishingOperations
|
||||
{
|
||||
void publish(NodeRef nodeToPublish, Map<QName, Serializable> channelProperties);
|
||||
void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> channelProperties);
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class Environment
|
||||
{
|
||||
private final NodeRef nodeRef;
|
||||
private final PublishingQueueImpl queue;
|
||||
private final NodeRef channelsContainer;
|
||||
|
||||
public Environment(NodeRef nodeRef, PublishingQueueImpl queue, NodeRef channelsContainer)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.queue = queue;
|
||||
this.channelsContainer = channelsContainer;
|
||||
}
|
||||
|
||||
public PublishingQueueImpl getPublishingQueue()
|
||||
{
|
||||
return queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelsContainer
|
||||
*/
|
||||
public NodeRef getChannelsContainer()
|
||||
{
|
||||
return channelsContainer;
|
||||
}
|
||||
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
}
|
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.MarshalException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.PropertyException;
|
||||
import javax.xml.bind.UnmarshalException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConversionException;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class JaxbHttpMessageConverter extends AbstractXmlHttpMessageConverter<Object>
|
||||
{
|
||||
private static Log log = LogFactory.getLog(JaxbHttpMessageConverter.class);
|
||||
private JAXBContext defaultJaxbContext = null;
|
||||
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class<?>, JAXBContext>();
|
||||
|
||||
public JaxbHttpMessageConverter()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a JAXB message converter, specifying the Java packages it should use to find JAXB classes
|
||||
* @param packagesToInclude A colon-separated list of package names.
|
||||
* @see JAXBContext#newInstance(String)
|
||||
*/
|
||||
public JaxbHttpMessageConverter(String packagesToInclude)
|
||||
{
|
||||
super();
|
||||
try
|
||||
{
|
||||
defaultJaxbContext = JAXBContext.newInstance(packagesToInclude);
|
||||
}
|
||||
catch (JAXBException e)
|
||||
{
|
||||
log.error("Failed to instantiate JAXB context with supplied context path " + packagesToInclude, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(Class<?> clazz, MediaType mediaType)
|
||||
{
|
||||
return (clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class))
|
||||
&& canRead(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class<?> clazz, MediaType mediaType)
|
||||
{
|
||||
return AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) != null && canWrite(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supports(Class<?> clazz)
|
||||
{
|
||||
// should not be called, since we override canRead/Write
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canWrite(MediaType mediaType)
|
||||
{
|
||||
return super.canWrite(mediaType) || MediaType.TEXT_XML.equals(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Unmarshaller unmarshaller = createUnmarshaller(clazz);
|
||||
if (clazz.isAnnotationPresent(XmlRootElement.class))
|
||||
{
|
||||
return unmarshaller.unmarshal(source);
|
||||
}
|
||||
else
|
||||
{
|
||||
JAXBElement<?> jaxbElement = unmarshaller.unmarshal(source, clazz);
|
||||
return jaxbElement.getValue();
|
||||
}
|
||||
}
|
||||
catch (UnmarshalException ex)
|
||||
{
|
||||
throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> clazz = ClassUtils.getUserClass(o);
|
||||
Marshaller marshaller = createMarshaller(clazz);
|
||||
setCharset(headers.getContentType(), marshaller);
|
||||
marshaller.marshal(o, result);
|
||||
}
|
||||
catch (MarshalException ex)
|
||||
{
|
||||
throw new HttpMessageNotWritableException("Could not marshal [" + o + "]: " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void setCharset(MediaType contentType, Marshaller marshaller) throws PropertyException
|
||||
{
|
||||
if (contentType != null && contentType.getCharSet() != null)
|
||||
{
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, contentType.getCharSet().name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Marshaller} for the given class.
|
||||
*
|
||||
* @param clazz
|
||||
* the class to create the marshaller for
|
||||
* @return the {@code Marshaller}
|
||||
* @throws HttpMessageConversionException
|
||||
* in case of JAXB errors
|
||||
*/
|
||||
protected final Marshaller createMarshaller(Class<?> clazz)
|
||||
{
|
||||
try
|
||||
{
|
||||
JAXBContext jaxbContext = getJaxbContext(clazz);
|
||||
return jaxbContext.createMarshaller();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new HttpMessageConversionException("Could not create Marshaller for class [" + clazz + "]: "
|
||||
+ ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Unmarshaller} for the given class.
|
||||
*
|
||||
* @param clazz
|
||||
* the class to create the unmarshaller for
|
||||
* @return the {@code Unmarshaller}
|
||||
* @throws HttpMessageConversionException
|
||||
* in case of JAXB errors
|
||||
*/
|
||||
protected final Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException
|
||||
{
|
||||
try
|
||||
{
|
||||
JAXBContext jaxbContext = getJaxbContext(clazz);
|
||||
return jaxbContext.createUnmarshaller();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new HttpMessageConversionException("Could not create Unmarshaller for class [" + clazz + "]: "
|
||||
+ ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link JAXBContext} for the given class.
|
||||
*
|
||||
* @param clazz
|
||||
* the class to return the context for
|
||||
* @return the {@code JAXBContext}
|
||||
* @throws HttpMessageConversionException
|
||||
* in case of JAXB errors
|
||||
*/
|
||||
protected final JAXBContext getJaxbContext(Class<?> clazz)
|
||||
{
|
||||
Assert.notNull(clazz, "'clazz' must not be null");
|
||||
JAXBContext result = null;
|
||||
if (defaultJaxbContext != null)
|
||||
{
|
||||
result = defaultJaxbContext;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = jaxbContexts.get(clazz);
|
||||
if (result == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = JAXBContext.newInstance(clazz);
|
||||
jaxbContexts.putIfAbsent(clazz, result);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext for class [" + clazz
|
||||
+ "]: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* For test purposes only.
|
||||
*
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class MockChannelType extends AbstractChannelType
|
||||
{
|
||||
public final static String ID = "MockChannelType";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
public Map<String, String> getCapabilities()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return PublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
public QName getContentRootNodeType()
|
||||
{
|
||||
return ContentModel.TYPE_FOLDER;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void sendStatusUpdate(Channel channel, String status)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getSupportedMimeTypes()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<QName> getSupportedContentTypes()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthUrlPair getAuthorisationUrls(Channel channel, String callbackUrl)
|
||||
{
|
||||
return new AuthUrlPair("", "");
|
||||
}
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.MutablePublishingEvent;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class MutablePublishingEventImpl extends PublishingEventImpl implements MutablePublishingEvent
|
||||
{
|
||||
/**
|
||||
* @param event PublishingEventImpl
|
||||
*/
|
||||
public MutablePublishingEventImpl(PublishingEventImpl event)
|
||||
{
|
||||
super(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setScheduledTime(Calendar time)
|
||||
{
|
||||
this.scheduledTime.setTimeInMillis(time.getTimeInMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setComment(String comment)
|
||||
{
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodeRefMapper
|
||||
{
|
||||
public NodeRef mapSourceNodeRef(NodeRef node)
|
||||
{
|
||||
StringBuilder nodeId = new StringBuilder(node.getId());
|
||||
if (nodeId.length() == 36)
|
||||
{
|
||||
for (int index = 35; index >= 0; --index)
|
||||
{
|
||||
int srcChar = nodeId.charAt(index);
|
||||
if (srcChar == '-')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int destChar = srcCharToDestChar(srcChar);
|
||||
if (destChar != srcChar)
|
||||
{
|
||||
nodeId.setCharAt(index, (char)destChar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeId.append('f');
|
||||
}
|
||||
return new NodeRef(node.getStoreRef(), nodeId.toString());
|
||||
}
|
||||
|
||||
public NodeRef mapDestinationNodeRef(NodeRef node)
|
||||
{
|
||||
StringBuilder nodeId = new StringBuilder(node.getId());
|
||||
if (node.getId().endsWith("f"))
|
||||
{
|
||||
nodeId.deleteCharAt(nodeId.length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastDestCharIndex = nodeId.length();
|
||||
int lastDestChar = 0;
|
||||
for (int index = nodeId.length() - 1; index >= 0; --index)
|
||||
{
|
||||
int destChar = nodeId.charAt(index);
|
||||
if (destChar == '-')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (isDestChar(destChar))
|
||||
{
|
||||
lastDestCharIndex = index;
|
||||
lastDestChar = destChar;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastDestCharIndex < nodeId.length())
|
||||
{
|
||||
int srcChar = destCharToSrcChar(lastDestChar);
|
||||
nodeId.setCharAt(lastDestCharIndex, (char)srcChar);
|
||||
}
|
||||
}
|
||||
return new NodeRef(node.getStoreRef(), nodeId.toString());
|
||||
}
|
||||
|
||||
private int srcCharToDestChar(int ch)
|
||||
{
|
||||
int result = ch;
|
||||
if (ch >= '0' && ch <= '9')
|
||||
{
|
||||
result = (ch - '0') + 'A';
|
||||
}
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
{
|
||||
result = (ch - 'a') + 10 + 'A';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int destCharToSrcChar(int ch)
|
||||
{
|
||||
int result = ch;
|
||||
if (ch >= 'A' && ch <= 'J') //'J' is the 10th uppercase character
|
||||
{
|
||||
result = ch - 'A' + '0';
|
||||
}
|
||||
else if (ch >= 'K' && ch <= 'P') //'P' is the 16th uppercase character
|
||||
{
|
||||
result = ch - 'K' + 'a';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isDestChar(int ch)
|
||||
{
|
||||
return (ch >= 'A' && ch <= 'P');
|
||||
}
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodeSnapshotFactory
|
||||
{
|
||||
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.NodeSnapshot;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface NodeSnapshotSerializer
|
||||
{
|
||||
void serialize(Collection<NodeSnapshot> snapshots, OutputStream output) throws Exception;
|
||||
|
||||
List<NodeSnapshot> deserialize(InputStream input) throws Exception;
|
||||
}
|
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
|
||||
import org.alfresco.service.cmr.publishing.NodeSnapshot;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodeSnapshotTransferImpl implements NodeSnapshot
|
||||
{
|
||||
private final TransferManifestNormalNode transferNode;
|
||||
|
||||
/**
|
||||
* @param transferNode TransferManifestNormalNode
|
||||
*/
|
||||
public NodeSnapshotTransferImpl(TransferManifestNormalNode transferNode)
|
||||
{
|
||||
this.transferNode = transferNode;
|
||||
}
|
||||
|
||||
public List<ChildAssociationRef> getAllParentAssocs()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return transferNode.getParentAssocs();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<QName> getAspects()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return transferNode.getAspects();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return transferNode.getNodeRef();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public List<AssociationRef> getOutboundPeerAssociations()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return transferNode.getTargetAssocs();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ChildAssociationRef
|
||||
*/
|
||||
public ChildAssociationRef getPrimaryParentAssoc()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return transferNode.getPrimaryParentAssoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Path
|
||||
*/
|
||||
public Path getPrimaryPath()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return transferNode.getParentPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<QName, Serializable> getProperties()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return transferNode.getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public QName getType()
|
||||
{
|
||||
if (transferNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return transferNode.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getVersion()
|
||||
{
|
||||
return (String) getProperties().get(ContentModel.PROP_VERSION_LABEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the transferNode
|
||||
*/
|
||||
public TransferManifestNormalNode getTransferNode()
|
||||
{
|
||||
return transferNode;
|
||||
}
|
||||
}
|
@@ -1,378 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItem;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.publishing.PublishingDetails;
|
||||
import org.alfresco.service.cmr.publishing.PublishingService;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.RuleServiceException;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* This class defines an action that publishes or unpublishes the acted-upon
|
||||
* node to a specified publishing channel.
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishContentActionExecuter extends ActionExecuterAbstractBase
|
||||
{
|
||||
public final static String NAME = "publish-content";
|
||||
|
||||
/**
|
||||
* A single-valued, optional text parameter that names the publishing
|
||||
* channel to which the specified content is to be published. Although this
|
||||
* is optional, one of either "publishChannelName" or "publishChannelId"
|
||||
* MUST be specified. If both are specified then "publishChannelId" takes
|
||||
* precedence.
|
||||
*
|
||||
* @see PublishContentActionExecuter#PARAM_PUBLISH_CHANNEL_ID
|
||||
*/
|
||||
public final static String PARAM_PUBLISH_CHANNEL_NAME = "publishChannelName";
|
||||
|
||||
/**
|
||||
* A single-valued, optional text parameter that identifies the publishing
|
||||
* channel to which the specified content is to be published. Although this
|
||||
* is optional, one of either "publishChannelName" or "publishChannelId"
|
||||
* MUST be specified. If both are specified then "publishChannelId" takes
|
||||
* precedence.
|
||||
*
|
||||
* @see PublishContentActionExecuter#PARAM_PUBLISH_CHANNEL_NAME
|
||||
*/
|
||||
public final static String PARAM_PUBLISH_CHANNEL_ID = "publishChannelId";
|
||||
|
||||
/**
|
||||
* A single-valued, optional boolean parameter that indicates whether the
|
||||
* node being acted on should be unpublished (true) or published (false, the
|
||||
* default).
|
||||
*/
|
||||
public final static String PARAM_UNPUBLISH = "unpublish";
|
||||
|
||||
/**
|
||||
* A single-valued, optional text parameter that specifies the text of a
|
||||
* status update that is to be sent to the specified channels upon
|
||||
* successful publication
|
||||
*
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES
|
||||
*/
|
||||
public final static String PARAM_STATUS_UPDATE = "statusUpdate";
|
||||
|
||||
/**
|
||||
* A single-valued, optional boolean parameter that specifies whether a link
|
||||
* to the published content should be appended (in shortened form) to the
|
||||
* status update. Defaults to true if not set.
|
||||
*
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE
|
||||
*/
|
||||
public final static String PARAM_INCLUDE_LINK_IN_STATUS_UPDATE = "includeLinkInStatusUpdate";
|
||||
|
||||
/**
|
||||
* A single-valued, optional NodeRef parameter that specifies which published node should be
|
||||
* referenced by the status update. This is only relevant if the "includeLinkInStatusUpdate" is
|
||||
* true AND the node being acted upon is a folder AND the "unpublish" parameter value is false.
|
||||
* If the node being acted on is not a folder then
|
||||
* the link appended to the status update will always be a link to the published node. If the "unpublish"
|
||||
* parameter is set to true then no link is appended to the status update.
|
||||
* @see PublishContentActionExecuter#PARAM_INCLUDE_LINK_IN_STATUS_UPDATE
|
||||
* @see PublishContentActionExecuter#PARAM_UNPUBLISH
|
||||
*/
|
||||
public final static String PARAM_NODE_TO_LINK_STATUS_UPDATE_TO = "nodeToLinkStatusUpdateTo";
|
||||
|
||||
/**
|
||||
* A multi-valued, optional text parameter that identifies by name the
|
||||
* publishing channels to which the status update (if any) should be sent.
|
||||
* If both this parameter and the "statusUpdateChannelIds" parameter are
|
||||
* given values then they are combined.
|
||||
*
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_IDS
|
||||
*/
|
||||
public final static String PARAM_STATUS_UPDATE_CHANNEL_NAMES = "statusUpdateChannelNames";
|
||||
|
||||
/**
|
||||
* A multi-valued, optional text parameter that identifies the publishing
|
||||
* channels to which the status update (if any) should be sent. If both this
|
||||
* parameter and the "statusUpdateChannelNames" parameter are given
|
||||
* values then they are combined.
|
||||
*
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE
|
||||
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES
|
||||
*/
|
||||
public final static String PARAM_STATUS_UPDATE_CHANNEL_IDS = "statusUpdateChannelIds";
|
||||
|
||||
/**
|
||||
* A single-valued, optional datetime parameter that specifies when the
|
||||
* publish should happen.
|
||||
*/
|
||||
public final static String PARAM_SCHEDULED_TIME = "scheduledTime";
|
||||
|
||||
/**
|
||||
* A single-valued, optional text parameter that is stored on the publishing
|
||||
* event that is created by this action.
|
||||
*/
|
||||
public final static String PARAM_COMMENT = "comment";
|
||||
|
||||
private static final String MSG_CHANNEL_NOT_FOUND = "publishing.channelNotFound";
|
||||
private static final String MSG_NEITHER_CHANNEL_NAME_NOR_ID_SPECIFIED = "publishing.neitherNameNorIdSpecified";
|
||||
|
||||
private PublishingService publishingService;
|
||||
private ChannelService channelService;
|
||||
private NodeService nodeService;
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
public void setPublishingService(PublishingService publishingService)
|
||||
{
|
||||
this.publishingService = publishingService;
|
||||
}
|
||||
|
||||
public void setChannelService(ChannelService channelService)
|
||||
{
|
||||
this.channelService = channelService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
Boolean isUnpublish = (Boolean) action.getParameterValue(PARAM_UNPUBLISH);
|
||||
boolean unpublish = ((isUnpublish != null) && isUnpublish);
|
||||
String publishChannelId = (String) action.getParameterValue(PARAM_PUBLISH_CHANNEL_ID);
|
||||
String publishChannelName = (String) action.getParameterValue(PARAM_PUBLISH_CHANNEL_NAME);
|
||||
String statusUpdate = (String) action.getParameterValue(PARAM_STATUS_UPDATE);
|
||||
List<String> statusUpdateChannelNames = buildStringList(action
|
||||
.getParameterValue(PARAM_STATUS_UPDATE_CHANNEL_NAMES));
|
||||
List<String> statusUpdateChannelIds = buildStringList(action.getParameterValue(PARAM_STATUS_UPDATE_CHANNEL_IDS));
|
||||
Boolean includeLinkInStatusUpdate = (Boolean) action.getParameterValue(PARAM_INCLUDE_LINK_IN_STATUS_UPDATE);
|
||||
boolean appendLink = ((includeLinkInStatusUpdate == null) || includeLinkInStatusUpdate);
|
||||
Date scheduledTime = (Date) action.getParameterValue(PARAM_SCHEDULED_TIME);
|
||||
String comment = (String) action.getParameterValue(PARAM_COMMENT);
|
||||
|
||||
Channel publishChannel = publishChannelId == null ? channelService.getChannelByName(publishChannelName)
|
||||
: channelService.getChannelById(publishChannelId);
|
||||
if (publishChannel != null)
|
||||
{
|
||||
PublishingDetails details = publishingService.createPublishingDetails();
|
||||
details.setPublishChannelId(publishChannel.getId());
|
||||
List<NodeRef> nodes = setNodes(actionedUponNodeRef, unpublish, details);
|
||||
if (statusUpdateChannelNames != null)
|
||||
{
|
||||
for (String statusUpdateChannelName : statusUpdateChannelNames)
|
||||
{
|
||||
Channel statusUpdateChannel = channelService.getChannelByName(statusUpdateChannelName);
|
||||
if (statusUpdateChannel != null)
|
||||
{
|
||||
details.addStatusUpdateChannels(statusUpdateChannel.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (statusUpdateChannelIds != null)
|
||||
{
|
||||
for (String statusUpdateChannelId : statusUpdateChannelIds)
|
||||
{
|
||||
Channel statusUpdateChannel = channelService.getChannelById(statusUpdateChannelId);
|
||||
if (statusUpdateChannel != null)
|
||||
{
|
||||
details.addStatusUpdateChannels(statusUpdateChannel.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!unpublish && !details.getStatusUpdateChannels().isEmpty())
|
||||
{
|
||||
details.setStatusMessage(statusUpdate);
|
||||
if (appendLink)
|
||||
{
|
||||
NodeRef nodeToLinkTo = (NodeRef) action.getParameterValue(PARAM_NODE_TO_LINK_STATUS_UPDATE_TO);
|
||||
if (nodeToLinkTo == null)
|
||||
{
|
||||
//No node has been specified explicitly as being the one to link to
|
||||
//We'll make an assumption if only one node is being published...
|
||||
if (nodes.size() == 1)
|
||||
{
|
||||
nodeToLinkTo = nodes.get(0);
|
||||
}
|
||||
}
|
||||
if ((nodeToLinkTo != null) && nodes.contains(nodeToLinkTo))
|
||||
{
|
||||
details.setStatusNodeToLinkTo(nodeToLinkTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scheduledTime != null)
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(scheduledTime);
|
||||
details.setSchedule(cal);
|
||||
}
|
||||
details.setComment(comment);
|
||||
publishingService.scheduleNewEvent(details);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException(MSG_CHANNEL_NOT_FOUND,
|
||||
new Object[] { publishChannelId == null ? publishChannelName : publishChannelId });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the node(s) to publish or unpublish on the supplied publishing details.
|
||||
* If the actionedUponNode is a folder then it will include all content nodes within that folder.
|
||||
* @param actionedUponNodeRef NodeRef
|
||||
* @param unpublish boolean
|
||||
* @param details PublishingDetails
|
||||
*/
|
||||
private List<NodeRef> setNodes(NodeRef actionedUponNodeRef, boolean unpublish, PublishingDetails details)
|
||||
{
|
||||
List<NodeRef> nodes = new ArrayList<NodeRef>();
|
||||
QName nodeType = nodeService.getType(actionedUponNodeRef);
|
||||
if (dictionaryService.isSubClass(nodeType, ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef);
|
||||
for (ChildAssociationRef childRef : children)
|
||||
{
|
||||
NodeRef child = childRef.getChildRef();
|
||||
if (dictionaryService.isSubClass(nodeService.getType(child), ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
nodes.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nodes.add(actionedUponNodeRef);
|
||||
}
|
||||
|
||||
if (unpublish)
|
||||
{
|
||||
details.addNodesToUnpublish(nodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
details.addNodesToPublish(nodes);
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private List<String> buildStringList(Serializable parameterValue)
|
||||
{
|
||||
List<String> result = null;
|
||||
if (parameterValue != null && String.class.isAssignableFrom(parameterValue.getClass()))
|
||||
{
|
||||
String[] split = ((String)parameterValue).split(",");
|
||||
result = Arrays.asList(split);
|
||||
}
|
||||
else if (parameterValue != null && Iterable.class.isAssignableFrom(parameterValue.getClass()))
|
||||
{
|
||||
result = new ArrayList<String>();
|
||||
Iterable<?> iter = (Iterable<?>)parameterValue;
|
||||
for (Object obj : iter)
|
||||
{
|
||||
if (obj != null && String.class.isAssignableFrom(obj.getClass()))
|
||||
{
|
||||
result.add((String)obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_PUBLISH_CHANNEL_NAME, DataTypeDefinition.TEXT, false,
|
||||
getParamDisplayLabel(PARAM_PUBLISH_CHANNEL_NAME), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_PUBLISH_CHANNEL_ID, DataTypeDefinition.TEXT, false,
|
||||
getParamDisplayLabel(PARAM_PUBLISH_CHANNEL_ID), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_UNPUBLISH, DataTypeDefinition.BOOLEAN, false,
|
||||
getParamDisplayLabel(PARAM_UNPUBLISH), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_STATUS_UPDATE, DataTypeDefinition.TEXT, false,
|
||||
getParamDisplayLabel(PARAM_STATUS_UPDATE), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_INCLUDE_LINK_IN_STATUS_UPDATE, DataTypeDefinition.BOOLEAN,
|
||||
false, getParamDisplayLabel(PARAM_INCLUDE_LINK_IN_STATUS_UPDATE), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_STATUS_UPDATE_CHANNEL_NAMES, DataTypeDefinition.TEXT, false,
|
||||
getParamDisplayLabel(PARAM_STATUS_UPDATE_CHANNEL_NAMES), true));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_STATUS_UPDATE_CHANNEL_IDS, DataTypeDefinition.TEXT, false,
|
||||
getParamDisplayLabel(PARAM_STATUS_UPDATE_CHANNEL_IDS), true));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_SCHEDULED_TIME, DataTypeDefinition.DATETIME, false,
|
||||
getParamDisplayLabel(PARAM_SCHEDULED_TIME), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_NODE_TO_LINK_STATUS_UPDATE_TO, DataTypeDefinition.NODE_REF, false,
|
||||
getParamDisplayLabel(PARAM_NODE_TO_LINK_STATUS_UPDATE_TO), false));
|
||||
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_COMMENT, DataTypeDefinition.TEXT, false,
|
||||
getParamDisplayLabel(PARAM_COMMENT), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkMandatoryProperties(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition)
|
||||
{
|
||||
super.checkMandatoryProperties(ruleItem, ruleItemDefinition);
|
||||
String publishChannelName = (String) ruleItem.getParameterValue(PARAM_PUBLISH_CHANNEL_NAME);
|
||||
String publishChannelId = (String) ruleItem.getParameterValue(PARAM_PUBLISH_CHANNEL_ID);
|
||||
if (publishChannelId == null && publishChannelName == null)
|
||||
{
|
||||
throw new RuleServiceException(MSG_NEITHER_CHANNEL_NAME_NOR_ID_SPECIFIED);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* This ActionExecuter adds a publish event to the publish event queue.
|
||||
*
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishEventAction extends ActionExecuterAbstractBase
|
||||
{
|
||||
private PublishingEventProcessor processor;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void executeImpl(Action action, NodeRef eventNode)
|
||||
{
|
||||
processor.processEventNode(eventNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* @param processor the processor to set
|
||||
*/
|
||||
public void setPublishingEventProcessor(PublishingEventProcessor processor)
|
||||
{
|
||||
this.processor = processor;
|
||||
}
|
||||
}
|
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.NodePublishStatus;
|
||||
import org.alfresco.service.cmr.publishing.PublishingDetails;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.PublishingQueue;
|
||||
import org.alfresco.service.cmr.publishing.PublishingService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishServiceImpl implements PublishingService
|
||||
{
|
||||
public static final String NAME = "PublishingService";
|
||||
|
||||
private PublishingEventHelper publishingEventHelper;
|
||||
private PublishingRootObject rootObject;
|
||||
|
||||
/**
|
||||
* @param rootObject the rootObject to set
|
||||
*/
|
||||
public void setPublishingRootObject(PublishingRootObject rootObject)
|
||||
{
|
||||
this.rootObject = rootObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishingEventHelper the publishingEventHelper to set
|
||||
*/
|
||||
public void setPublishingEventHelper(PublishingEventHelper publishingEventHelper)
|
||||
{
|
||||
this.publishingEventHelper = publishingEventHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingEvent getPublishingEvent(String id)
|
||||
{
|
||||
return publishingEventHelper.getPublishingEvent(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<PublishingEvent> getPublishEventsForNode(NodeRef publishedNode)
|
||||
{
|
||||
NodeRef queueNode = rootObject.getPublishingQueue().getNodeRef();
|
||||
List<NodeRef> eventNodes = publishingEventHelper.getEventNodesForPublishedNode(queueNode, publishedNode);
|
||||
return publishingEventHelper.getPublishingEvents(eventNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<PublishingEvent> getUnpublishEventsForNode(NodeRef unpublishedNode)
|
||||
{
|
||||
NodeRef queueNode = rootObject.getPublishingQueue().getNodeRef();
|
||||
List<NodeRef> eventNodes = publishingEventHelper.getEventNodesForUnpublishedNode(queueNode, unpublishedNode);
|
||||
return publishingEventHelper.getPublishingEvents(eventNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void cancelPublishingEvent(String id)
|
||||
{
|
||||
ParameterCheck.mandatory("id", id);
|
||||
publishingEventHelper.cancelEvent(id);
|
||||
}
|
||||
|
||||
private PublishingQueue getPublishingQueue()
|
||||
{
|
||||
return rootObject.getPublishingQueue();
|
||||
}
|
||||
|
||||
public Map<NodeRef, NodePublishStatus> checkPublishStatus(String channelId, Collection<NodeRef> nodes)
|
||||
{
|
||||
// Map<NodeRef, NodePublishStatus> results = new HashMap<NodeRef, NodePublishStatus>();
|
||||
// for (NodeRef node : nodes)
|
||||
// {
|
||||
// if(node!=null && results.containsKey(node)==false)
|
||||
// {
|
||||
// results.put(node, environmentHelper.checkNodeStatus(node, channelId));
|
||||
// }
|
||||
// }
|
||||
// return results;
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<NodeRef, NodePublishStatus> checkPublishStatus(String channelId, NodeRef... nodes)
|
||||
{
|
||||
// return checkPublishStatus(channelId, Arrays.asList(nodes));
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
public PublishingDetails createPublishingDetails()
|
||||
{
|
||||
return getPublishingQueue().createPublishingDetails();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String scheduleNewEvent(PublishingDetails publishingDetails)
|
||||
{
|
||||
return getPublishingQueue().scheduleNewEvent(publishingDetails);
|
||||
}
|
||||
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.repo.action.constraint.BaseParameterConstraint;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
|
||||
/**
|
||||
* Action parameter constraint that constrains to list of publishing channels
|
||||
*
|
||||
* @see PublishContentActionExecuter
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingChannelParameterConstraint extends BaseParameterConstraint
|
||||
{
|
||||
public static final String NAME = "ac-publishing-channels";
|
||||
|
||||
private ChannelService channelService;
|
||||
|
||||
public void setChannelService(ChannelService channelService)
|
||||
{
|
||||
this.channelService = channelService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
|
||||
*/
|
||||
protected Map<String, String> getAllowableValuesImpl()
|
||||
{
|
||||
List<Channel> channels = channelService.getPublishingChannels(false);
|
||||
Map<String, String> result = new TreeMap<String, String>();
|
||||
for (Channel channel : channels)
|
||||
{
|
||||
result.put(channel.getId(), channel.getName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,222 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.PublishingDetails;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingDetailsImpl implements PublishingDetails
|
||||
{
|
||||
private final Set<NodeRef> nodesToPublish = new HashSet<NodeRef>();
|
||||
private final Set<NodeRef> nodesToUnpublish= new HashSet<NodeRef>();
|
||||
private final Set<String> statusChannels = new HashSet<String>();
|
||||
|
||||
private NodeRef nodeToLinkTo = null;
|
||||
private String message = null;
|
||||
private Calendar schedule = null;
|
||||
private String comment = null;
|
||||
private String publishChannelId = null;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails addNodesToPublish(NodeRef... nodesToAdd)
|
||||
{
|
||||
return addNodesToPublish(Arrays.asList(nodesToAdd));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails addNodesToUnpublish(NodeRef... nodesToRemove)
|
||||
{
|
||||
return addNodesToUnpublish(Arrays.asList(nodesToRemove));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PublishingDetails addNodesToUnpublish(Collection<NodeRef> nodesToRemove)
|
||||
{
|
||||
this.nodesToUnpublish.addAll(nodesToRemove);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails addNodesToPublish(Collection<NodeRef> nodesToAdd)
|
||||
{
|
||||
this.nodesToPublish.addAll(nodesToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails setPublishChannelId(String publishChannelId)
|
||||
{
|
||||
this.publishChannelId = publishChannelId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails setComment(String comment)
|
||||
{
|
||||
this.comment = comment;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails setSchedule(Calendar schedule)
|
||||
{
|
||||
this.schedule = schedule;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails setStatusMessage(String message)
|
||||
{
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails setStatusNodeToLinkTo(NodeRef nodeToLinkTo)
|
||||
{
|
||||
this.nodeToLinkTo = nodeToLinkTo;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails addStatusUpdateChannels(Collection<String> channelIds)
|
||||
{
|
||||
statusChannels.addAll(channelIds);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails addStatusUpdateChannels(String... channelIds)
|
||||
{
|
||||
return addStatusUpdateChannels(Arrays.asList(channelIds));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<NodeRef> getNodesToPublish()
|
||||
{
|
||||
return nodesToPublish;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<NodeRef> getNodesToUnpublish()
|
||||
{
|
||||
return nodesToUnpublish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statusChannels
|
||||
*/
|
||||
public Set<String> getStatusChannels()
|
||||
{
|
||||
return statusChannels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment
|
||||
*/
|
||||
public String getComment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public String getStatusMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nodeToLinkTo
|
||||
*/
|
||||
public NodeRef getNodeToLinkTo()
|
||||
{
|
||||
return nodeToLinkTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the publishChannelId
|
||||
*/
|
||||
public String getPublishChannelId()
|
||||
{
|
||||
return publishChannelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the schedule
|
||||
*/
|
||||
public Calendar getSchedule()
|
||||
{
|
||||
return schedule;
|
||||
}
|
||||
|
||||
public Set<String> getStatusUpdateChannels()
|
||||
{
|
||||
return statusChannels;
|
||||
}
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.PublishingEventFilter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingEventFilterImpl implements PublishingEventFilter
|
||||
{
|
||||
private Set<String> ids = Collections.emptySet();
|
||||
private Set<NodeRef> publishedNodes = Collections.emptySet();
|
||||
private Set<NodeRef> unpublishedNodes = Collections.emptySet();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingEventFilter setIds(String... ids)
|
||||
{
|
||||
if (ids != null && ids.length > 0)
|
||||
{
|
||||
this.ids = new HashSet<String>(Arrays.asList(ids));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PublishingEventFilter setIds(Collection<String> ids)
|
||||
{
|
||||
if (ids != null && ids.isEmpty() == false)
|
||||
{
|
||||
this.ids = new HashSet<String>(ids);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<String> getIds()
|
||||
{
|
||||
return Collections.unmodifiableSet(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingEventFilter setPublishedNodes(NodeRef... publishedNodes)
|
||||
{
|
||||
if (publishedNodes != null && publishedNodes.length > 0)
|
||||
{
|
||||
this.publishedNodes = new HashSet<NodeRef>(Arrays.asList(publishedNodes));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingEventFilter setPublishedNodes(Collection<NodeRef> publishedNodes)
|
||||
{
|
||||
if (publishedNodes != null && publishedNodes.isEmpty() == false)
|
||||
{
|
||||
this.publishedNodes = new HashSet<NodeRef>(publishedNodes);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<NodeRef> getPublishedNodes()
|
||||
{
|
||||
return Collections.unmodifiableSet(publishedNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingEventFilter setUnpublishedNodes(NodeRef... unpublishedNodes)
|
||||
{
|
||||
if (unpublishedNodes != null && unpublishedNodes.length > 0)
|
||||
{
|
||||
this.unpublishedNodes = new HashSet<NodeRef>(Arrays.asList(unpublishedNodes));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingEventFilter setUnpublishedNodes(Collection<NodeRef> unpublishedNodes)
|
||||
{
|
||||
if (unpublishedNodes != null && unpublishedNodes.isEmpty() == false)
|
||||
{
|
||||
this.unpublishedNodes = new HashSet<NodeRef>(unpublishedNodes);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<NodeRef> getUnpublishedNodes()
|
||||
{
|
||||
return Collections.unmodifiableSet(unpublishedNodes);
|
||||
}
|
||||
}
|
@@ -1,694 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASSOC_LAST_PUBLISHING_EVENT;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASSOC_PUBLISHING_EVENT;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.NAMESPACE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_COMMENT;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_PAYLOAD;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_STATUS;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME_ZONE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_WORKFLOW_ID;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_CHANNEL_NAMES;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_MESSAGE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_NODE_REF;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_WF_PUBLISHING_EVENT;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.PROP_WF_SCHEDULED_PUBLISH_DATE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT;
|
||||
import static org.alfresco.util.collections.CollectionUtils.filter;
|
||||
import static org.alfresco.util.collections.CollectionUtils.isEmpty;
|
||||
import static org.alfresco.util.collections.CollectionUtils.toListOfStrings;
|
||||
import static org.alfresco.util.collections.CollectionUtils.transform;
|
||||
import static org.alfresco.util.collections.CollectionUtils.transformFlat;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeUtils;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.repo.transfer.TransferContext;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
|
||||
import org.alfresco.repo.version.VersionModel;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.cmr.publishing.NodeSnapshot;
|
||||
import org.alfresco.service.cmr.publishing.PublishingDetails;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEventFilter;
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackage;
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
|
||||
import org.alfresco.service.cmr.publishing.Status;
|
||||
import org.alfresco.service.cmr.publishing.StatusUpdate;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.transfer.TransferDefinition;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
import org.alfresco.service.cmr.version.VersionType;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.collections.Filter;
|
||||
import org.alfresco.util.collections.Function;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingEventHelper
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(PublishingEventHelper.class);
|
||||
public static final String WORKFLOW_DEFINITION_NAME = "publishWebContent";
|
||||
|
||||
private NodeService nodeService;
|
||||
private ContentService contentService;
|
||||
private VersionService versionService;
|
||||
private WorkflowService workflowService;
|
||||
private NodeSnapshotSerializer serializer;
|
||||
private PermissionService permissionService;
|
||||
private TransferManifestNodeFactory transferManifestNodeFactory;
|
||||
private List<QName> excludedAspects = new ArrayList<QName>();
|
||||
|
||||
private String workflowEngineId;
|
||||
private TransferDefinition excludedAspectsTransferDefinition;
|
||||
|
||||
/**
|
||||
* @param nodeService
|
||||
* the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentService
|
||||
* the contentService to set
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param transferManifestNodeFactory the transferManifestNodeFactory to set
|
||||
*/
|
||||
public void setTransferManifestNodeFactory(TransferManifestNodeFactory transferManifestNodeFactory)
|
||||
{
|
||||
this.transferManifestNodeFactory = transferManifestNodeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param versionService the versionService to set
|
||||
*/
|
||||
public void setVersionService(VersionService versionService)
|
||||
{
|
||||
this.versionService = versionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workflowService the workflowService to set
|
||||
*/
|
||||
public void setWorkflowService(WorkflowService workflowService)
|
||||
{
|
||||
this.workflowService = workflowService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workflowEngineId the workflowEngineId to set
|
||||
*/
|
||||
public void setWorkflowEngineId(String workflowEngineId)
|
||||
{
|
||||
this.workflowEngineId = workflowEngineId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param serializer the serializer to set
|
||||
*/
|
||||
public void setSerializer(NodeSnapshotSerializer serializer)
|
||||
{
|
||||
this.serializer = serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permissionService the permissionService to set
|
||||
*/
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
public PublishingEvent getPublishingEvent(NodeRef eventNode) throws AlfrescoRuntimeException
|
||||
{
|
||||
if (eventNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<QName, Serializable> props = nodeService.getProperties(eventNode);
|
||||
String statusStr = (String) props.get(PROP_PUBLISHING_EVENT_STATUS);
|
||||
Status status = Status.valueOf(statusStr);
|
||||
String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL);
|
||||
Date createdTime = (Date) props.get(ContentModel.PROP_CREATED);
|
||||
String creator = (String) props.get(ContentModel.PROP_CREATOR);
|
||||
Date modifiedTime = (Date) props.get(ContentModel.PROP_MODIFIED);
|
||||
String modifier = (String) props.get(ContentModel.PROP_MODIFIER);
|
||||
String comment = (String) props.get(PROP_PUBLISHING_EVENT_COMMENT);
|
||||
Calendar scheduledTime = getScheduledTime(props);
|
||||
PublishingPackage publishingPackage = getPublishingPackage(eventNode, channel);
|
||||
|
||||
StatusUpdate statusUpdate = buildStatusUpdate(props);
|
||||
return new PublishingEventImpl(eventNode.toString(),
|
||||
status, channel,
|
||||
publishingPackage, createdTime,
|
||||
creator,modifiedTime, modifier,
|
||||
scheduledTime, comment, statusUpdate);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private StatusUpdate buildStatusUpdate(Map<QName, Serializable> props)
|
||||
{
|
||||
String message = (String) props.get(PROP_STATUS_UPDATE_MESSAGE);
|
||||
Collection<String> channelNames = (Collection<String>) props.get(PROP_STATUS_UPDATE_CHANNEL_NAMES);
|
||||
if (channelNames == null || channelNames.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String nodeId = (String) props.get(PROP_STATUS_UPDATE_NODE_REF);
|
||||
NodeRef nodeToLinkTo = nodeId==null ? null : new NodeRef(nodeId);
|
||||
return new StatusUpdateImpl(message, nodeToLinkTo, channelNames);
|
||||
}
|
||||
|
||||
public List<PublishingEvent> getPublishingEvents(List<NodeRef> eventNodes)
|
||||
{
|
||||
return transform(eventNodes, new Function<NodeRef, PublishingEvent>()
|
||||
{
|
||||
public PublishingEvent apply(NodeRef eventNode)
|
||||
{
|
||||
return getPublishingEvent(eventNode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public NodeRef createNode(NodeRef queueNode, PublishingDetails details) throws Exception
|
||||
{
|
||||
checkChannelAccess(details.getPublishChannelId());
|
||||
Set<String> statusChannelIds = details.getStatusUpdateChannels();
|
||||
if (isEmpty(statusChannelIds) == false)
|
||||
for (String statusChannelId : statusChannelIds)
|
||||
{
|
||||
checkChannelAccess(statusChannelId);
|
||||
}
|
||||
String name = GUID.generate();
|
||||
Map<QName, Serializable> props = buildPublishingEventProperties(details, name);
|
||||
ChildAssociationRef newAssoc = nodeService.createNode(queueNode,
|
||||
ASSOC_PUBLISHING_EVENT,
|
||||
QName.createQName(NAMESPACE, name),
|
||||
TYPE_PUBLISHING_EVENT, props);
|
||||
NodeRef eventNode = newAssoc.getChildRef();
|
||||
serializePublishNodes(eventNode, details);
|
||||
return eventNode;
|
||||
}
|
||||
|
||||
private void checkChannelAccess(String channelId)
|
||||
{
|
||||
NodeRef channelNode = new NodeRef(channelId);
|
||||
AccessStatus accessStatus = permissionService.hasPermission(channelNode, PermissionService.ADD_CHILDREN);
|
||||
if (AccessStatus.ALLOWED != accessStatus)
|
||||
{
|
||||
throw new AccessDeniedException("You do not have access to channel: " + channelId);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<QName, Serializable> buildPublishingEventProperties(PublishingDetails details, String name)
|
||||
{
|
||||
Calendar schedule = details.getSchedule();
|
||||
if (schedule == null)
|
||||
{
|
||||
schedule = Calendar.getInstance();
|
||||
}
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
props.put(ContentModel.PROP_NAME, name);
|
||||
props.put(PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name());
|
||||
props.put(PROP_PUBLISHING_EVENT_TIME, schedule.getTime());
|
||||
props.put(PublishingModel.PROP_PUBLISHING_EVENT_TIME_ZONE, schedule.getTimeZone().getID());
|
||||
props.put(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL, details.getPublishChannelId());
|
||||
props.put(PublishingModel.PROP_PUBLISHING_EVENT_STATUS, PublishingModel.PROPVAL_PUBLISHING_EVENT_STATUS_SCHEDULED);
|
||||
String comment = details.getComment();
|
||||
if (comment != null)
|
||||
{
|
||||
props.put(PROP_PUBLISHING_EVENT_COMMENT, comment);
|
||||
}
|
||||
Collection<String> publshStrings = mapNodesToStrings(details.getNodesToPublish());
|
||||
props.put(PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, (Serializable) publshStrings);
|
||||
Collection<String> unpublshStrings = mapNodesToStrings(details.getNodesToUnpublish());
|
||||
props.put(PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH, (Serializable) unpublshStrings);
|
||||
String message = details.getStatusMessage();
|
||||
Set<String> statusChannels = details.getStatusUpdateChannels();
|
||||
if (message != null && isEmpty(statusChannels) == false)
|
||||
{
|
||||
props.put(PROP_STATUS_UPDATE_MESSAGE, message);
|
||||
NodeRef statusNode = details.getNodeToLinkTo();
|
||||
if (statusNode != null)
|
||||
{
|
||||
props.put(PROP_STATUS_UPDATE_NODE_REF, statusNode.toString());
|
||||
}
|
||||
props.put(PROP_STATUS_UPDATE_CHANNEL_NAMES, (Serializable) statusChannels);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
private List<String> mapNodesToStrings(Collection<NodeRef> nodes)
|
||||
{
|
||||
return toListOfStrings(nodes);
|
||||
}
|
||||
|
||||
public List<NodeRef> findPublishingEventNodes(final NodeRef queue, PublishingEventFilter filter)
|
||||
{
|
||||
List<NodeRef> eventNodes;
|
||||
Set<NodeRef> publishedNodes = filter.getPublishedNodes();
|
||||
if (isEmpty(publishedNodes) == false)
|
||||
{
|
||||
eventNodes= getEventNodesForPublishedNodes(queue, publishedNodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventNodes = getAllPublishingEventNodes(queue);
|
||||
}
|
||||
Set<String> ids = filter.getIds();
|
||||
if (isEmpty(ids) == false)
|
||||
{
|
||||
eventNodes = filterEventNodesById(eventNodes, ids);
|
||||
}
|
||||
return eventNodes;
|
||||
}
|
||||
|
||||
private List<NodeRef> filterEventNodesById(Collection<NodeRef> eventNodes, final Collection<String> ids)
|
||||
{
|
||||
return filter(eventNodes, new Filter<NodeRef>()
|
||||
{
|
||||
public Boolean apply(NodeRef node)
|
||||
{
|
||||
return ids.contains(node.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<NodeRef> getAllPublishingEventNodes(final NodeRef queue)
|
||||
{
|
||||
List<ChildAssociationRef> assocs =
|
||||
nodeService.getChildAssocs(queue, ASSOC_PUBLISHING_EVENT, RegexQNamePattern.MATCH_ALL);
|
||||
return transform(assocs, NodeUtils.toChildRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to publish at least one of the specified <code>publishedNodes</code>.
|
||||
* @param queue NodeRef
|
||||
* @param publishedNodes NodeRef..
|
||||
*/
|
||||
public List<NodeRef> getEventNodesForPublishedNodes(final NodeRef queue, NodeRef... publishedNodes)
|
||||
{
|
||||
return getEventNodesForPublishedNodes(queue, Arrays.asList(publishedNodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to publish at least one of the specified <code>publishedNodes</code>.
|
||||
* @param queue NodeRef
|
||||
*/
|
||||
public List<NodeRef> getEventNodesForPublishedNodes(final NodeRef queue, Collection<NodeRef> publishedNodes)
|
||||
{
|
||||
return getEventNodesForNodeProperty(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, publishedNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to unpublish at least one of the specified <code>unpublishedNodes</code>.
|
||||
* @param queue NodeRef
|
||||
*/
|
||||
public List<NodeRef> getEventNodesForUnpublishedNodes(final NodeRef queue, Collection<NodeRef> unpublishedNodes)
|
||||
{
|
||||
return getEventNodesForNodeProperty(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, unpublishedNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to publish the specified <code>publishedNode</code>.
|
||||
* @param queue NodeRef
|
||||
* @param publishedNode NodeRef
|
||||
*/
|
||||
public List<NodeRef> getEventNodesForPublishedNode(final NodeRef queue, NodeRef publishedNode)
|
||||
{
|
||||
Function<NodeRef, List<NodeRef>> transformer = eventNodeForNodePropertyFinder(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH);
|
||||
return transformer.apply(publishedNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to unpublish the specified <code>unpublishedNode</code>.
|
||||
* @param queue NodeRef
|
||||
* @param unpublishedNode NodeRef
|
||||
*/
|
||||
public List<NodeRef> getEventNodesForUnpublishedNode(final NodeRef queue, NodeRef unpublishedNode)
|
||||
{
|
||||
Function<NodeRef, List<NodeRef>> transformer = eventNodeForNodePropertyFinder(queue, PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH);
|
||||
return transformer.apply(unpublishedNode);
|
||||
}
|
||||
|
||||
private List<NodeRef> getEventNodesForNodeProperty(final NodeRef queue, final QName propertyKey, Collection<NodeRef> publishedNodes)
|
||||
{
|
||||
Function<NodeRef, List<NodeRef>> transformer = eventNodeForNodePropertyFinder(queue, propertyKey);
|
||||
return transformFlat(publishedNodes, transformer);
|
||||
}
|
||||
|
||||
private Function<NodeRef, List<NodeRef>> eventNodeForNodePropertyFinder(final NodeRef queue,
|
||||
final QName propertyKey)
|
||||
{
|
||||
return new Function<NodeRef, List<NodeRef>>()
|
||||
{
|
||||
public List<NodeRef> apply(NodeRef publishedNode)
|
||||
{
|
||||
String nodeString = publishedNode.toString();
|
||||
List<ChildAssociationRef> assocs =
|
||||
nodeService.getChildAssocsByPropertyValue(queue, propertyKey, nodeString);
|
||||
return transform(assocs, NodeUtils.toChildRef());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public List<PublishingEvent> findPublishingEvents(NodeRef queue, PublishingEventFilter filter)
|
||||
{
|
||||
List<NodeRef> eventNodes = findPublishingEventNodes(queue, filter);
|
||||
return getPublishingEvents(eventNodes);
|
||||
}
|
||||
|
||||
public PublishingEvent getPublishingEvent(String id)
|
||||
{
|
||||
NodeRef eventNode = getPublishingEventNode(id);
|
||||
return getPublishingEvent(eventNode);
|
||||
}
|
||||
|
||||
public NodeRef getPublishingEventNode(String id)
|
||||
{
|
||||
if (id != null && NodeRef.isNodeRef(id))
|
||||
{
|
||||
NodeRef eventNode = new NodeRef(id);
|
||||
if (nodeService.exists(eventNode) && TYPE_PUBLISHING_EVENT.equals(nodeService.getType(eventNode)))
|
||||
{
|
||||
return eventNode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String startPublishingWorkflow(NodeRef eventNode, Calendar scheduledTime)
|
||||
{
|
||||
//Set parameters
|
||||
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
|
||||
parameters.put(PROP_WF_PUBLISHING_EVENT, eventNode);
|
||||
parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
|
||||
parameters.put(PROP_WF_SCHEDULED_PUBLISH_DATE, scheduledTime);
|
||||
|
||||
//Start workflow
|
||||
WorkflowPath path = workflowService.startWorkflow(getPublshingWorkflowDefinitionId(), parameters);
|
||||
String instanceId = path.getInstance().getId();
|
||||
|
||||
//Set the Workflow Id on the event node.
|
||||
nodeService.setProperty(eventNode, PROP_PUBLISHING_EVENT_WORKFLOW_ID, instanceId);
|
||||
|
||||
//End the start task.
|
||||
//TODO Replace with endStartTask() call after merge to HEAD.
|
||||
WorkflowTask startTask = workflowService.getStartTask(instanceId);
|
||||
workflowService.endTask(startTask.getId(), null);
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
private String getPublshingWorkflowDefinitionId()
|
||||
{
|
||||
String definitionName = workflowEngineId + "$" + WORKFLOW_DEFINITION_NAME;
|
||||
WorkflowDefinition definition = workflowService.getDefinitionByName(definitionName);
|
||||
if (definition == null)
|
||||
{
|
||||
String msg = "The Web publishing workflow definition does not exist! Definition name: " + definitionName;
|
||||
throw new AlfrescoRuntimeException(msg);
|
||||
}
|
||||
return definition.getId();
|
||||
}
|
||||
|
||||
public Calendar getScheduledTime(NodeRef eventNode)
|
||||
{
|
||||
if (eventNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getScheduledTime(nodeService.getProperties(eventNode));
|
||||
}
|
||||
|
||||
public Calendar getScheduledTime(Map<QName, Serializable> eventProperties)
|
||||
{
|
||||
Date time = (Date) eventProperties.get(PROP_PUBLISHING_EVENT_TIME);
|
||||
String timezone= (String) eventProperties.get(PROP_PUBLISHING_EVENT_TIME_ZONE);
|
||||
Calendar scheduledTime = Calendar.getInstance();
|
||||
scheduledTime.setTime(time);
|
||||
scheduledTime.setTimeZone(TimeZone.getTimeZone(timezone));
|
||||
return scheduledTime;
|
||||
}
|
||||
|
||||
private void serializePublishNodes(NodeRef eventNode, PublishingDetails details) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
NodeRef channelNode = new NodeRef(details.getPublishChannelId());
|
||||
List<NodeSnapshot> snapshots = createPublishSnapshots(details.getNodesToPublish());
|
||||
snapshots.addAll(createUnpublishSnapshots(details.getNodesToUnpublish(), channelNode));
|
||||
ContentWriter contentWriter = contentService.getWriter(eventNode,
|
||||
PROP_PUBLISHING_EVENT_PAYLOAD, true);
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
OutputStream os = contentWriter.getContentOutputStream();
|
||||
serializer.serialize(snapshots, os);
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.warn("Failed to serialize publishing package", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private List<NodeSnapshot> createUnpublishSnapshots(Set<NodeRef> nodes, final NodeRef channelNode)
|
||||
{
|
||||
return transform(nodes, new Function<NodeRef, NodeSnapshot>()
|
||||
{
|
||||
public NodeSnapshot apply(NodeRef node)
|
||||
{
|
||||
return createUnpublishSnapshot(node, channelNode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PublishingPackage getPublishingPackage(NodeRef eventNode, String channelId) throws AlfrescoRuntimeException
|
||||
{
|
||||
Map<NodeRef, PublishingPackageEntry> entries = getPublishingPackageEntries(eventNode);
|
||||
return new PublishingPackageImpl(entries);
|
||||
}
|
||||
|
||||
|
||||
private List<NodeSnapshot> createPublishSnapshots(final Collection<NodeRef> nodes)
|
||||
{
|
||||
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<List<NodeSnapshot>>()
|
||||
{
|
||||
public List<NodeSnapshot> doWork() throws Exception
|
||||
{
|
||||
return transform(nodes, new Function<NodeRef, NodeSnapshot>()
|
||||
{
|
||||
public NodeSnapshot apply(NodeRef node)
|
||||
{
|
||||
return createPublishSnapshot(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
private NodeSnapshotTransferImpl createPublishSnapshot(NodeRef node)
|
||||
{
|
||||
if (!nodeService.hasAspect(node, ContentModel.ASPECT_VERSIONABLE))
|
||||
{
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
|
||||
props.put(ContentModel.PROP_AUTO_VERSION, true);
|
||||
props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
|
||||
versionService.ensureVersioningEnabled(node, props);
|
||||
}
|
||||
versionService.createVersion(node, null);
|
||||
TransferManifestNormalNode payload = (TransferManifestNormalNode) transferManifestNodeFactory.createTransferManifestNode(node, excludedAspectsTransferDefinition, new TransferContext());
|
||||
NodeSnapshotTransferImpl snapshot = new NodeSnapshotTransferImpl(payload);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<NodeRef, PublishingPackageEntry> getPublishingPackageEntries(NodeRef eventNode)
|
||||
{
|
||||
List<String> idsToUnpublish = (List<String>) nodeService.getProperty(eventNode, PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH);
|
||||
List<NodeRef> nodesToUnpublish = NodeUtils.toNodeRefs(idsToUnpublish);
|
||||
ContentReader contentReader = contentService.getReader(eventNode, PROP_PUBLISHING_EVENT_PAYLOAD);
|
||||
InputStream input = contentReader.getContentInputStream();
|
||||
try
|
||||
{
|
||||
List<NodeSnapshot> snapshots = serializer.deserialize(input);
|
||||
Map<NodeRef, PublishingPackageEntry> entries = new HashMap<NodeRef, PublishingPackageEntry>(snapshots.size());
|
||||
for (NodeSnapshot snapshot : snapshots)
|
||||
{
|
||||
NodeRef node = snapshot.getNodeRef();
|
||||
boolean isPublish = false == nodesToUnpublish.contains(node);
|
||||
PublishingPackageEntryImpl entry = new PublishingPackageEntryImpl(isPublish, node, snapshot);
|
||||
entries.put(node, entry);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
String msg ="Failed to deserialize publishing package for PublishingEvent: " +eventNode;
|
||||
throw new AlfrescoRuntimeException(msg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private NodeSnapshot createUnpublishSnapshot(NodeRef source, NodeRef channelNode)
|
||||
{
|
||||
NodeRef lastEvent = getLastPublishEvent(source, channelNode);
|
||||
if (lastEvent == null)
|
||||
{
|
||||
String msg = "Cannot create unpublish snapshot as last publishing event does not exist! Source node: "+ source + " channelId: "+channelNode;
|
||||
throw new AlfrescoRuntimeException(msg);
|
||||
}
|
||||
Map<NodeRef, PublishingPackageEntry> entries = getPublishingPackageEntries(lastEvent);
|
||||
PublishingPackageEntry entry = entries.get(source);
|
||||
return entry.getSnapshot();
|
||||
}
|
||||
|
||||
public NodeRef getLastPublishEvent(NodeRef source, NodeRef channelNode)
|
||||
{
|
||||
NodeRef publishedNode = ChannelHelper.mapSourceToEnvironment(source, channelNode, nodeService);
|
||||
if (publishedNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<AssociationRef> assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_LAST_PUBLISHING_EVENT);
|
||||
return NodeUtils.getSingleAssocNode(assocs, true);
|
||||
}
|
||||
|
||||
public void cancelEvent(String id)
|
||||
{
|
||||
NodeRef eventNode = getPublishingEventNode(id);
|
||||
if (eventNode != null)
|
||||
{
|
||||
Map<QName,Serializable> eventProps = nodeService.getProperties(eventNode);
|
||||
String status = (String)eventProps.get(PublishingModel.PROP_PUBLISHING_EVENT_STATUS);
|
||||
//If this event has not started to be processed yet then we can stop the associated workflow and
|
||||
//delete the event...
|
||||
if (PublishingModel.PROPVAL_PUBLISHING_EVENT_STATUS_SCHEDULED.equals(status))
|
||||
{
|
||||
//Get hold of the process id
|
||||
String processId = (String)eventProps.get(PublishingModel.PROP_PUBLISHING_EVENT_WORKFLOW_ID);
|
||||
if (processId != null)
|
||||
{
|
||||
workflowService.cancelWorkflow(processId);
|
||||
}
|
||||
nodeService.deleteNode(eventNode);
|
||||
}
|
||||
|
||||
//Otherwise, if the current event is being processed now we just set its status to "CANCELLED REQUESTED"
|
||||
else if (PublishingModel.PROPVAL_PUBLISHING_EVENT_STATUS_IN_PROGRESS.equals(status))
|
||||
{
|
||||
nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, PublishingModel.PROPVAL_PUBLISHING_EVENT_STATUS_CANCEL_REQUESTED);
|
||||
}
|
||||
|
||||
//Otherwise this event has already been processed or has already been cancelled. Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
public AssociationRef linkToLastEvent(NodeRef publishedNode, NodeRef eventNode)
|
||||
{
|
||||
List<AssociationRef> assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_LAST_PUBLISHING_EVENT);
|
||||
if (isEmpty(assocs) == false)
|
||||
{
|
||||
// Remove old association.
|
||||
AssociationRef assoc = assocs.get(0);
|
||||
nodeService.removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
|
||||
}
|
||||
return nodeService.createAssociation(publishedNode, eventNode, ASSOC_LAST_PUBLISHING_EVENT);
|
||||
}
|
||||
|
||||
public PublishingDetails createPublishingDetails()
|
||||
{
|
||||
return new PublishingDetailsImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of excluded aspects, assumes the fully qualified name. Replaces any exising excluded aspects.
|
||||
*/
|
||||
public void setExcludedAspects(Collection<String> excludedAspects)
|
||||
{
|
||||
this.excludedAspects.clear();
|
||||
|
||||
for (String aspect : excludedAspects)
|
||||
{
|
||||
this.excludedAspects.add(QName.createQName(aspect));
|
||||
}
|
||||
this.excludedAspectsTransferDefinition = new TransferDefinition();
|
||||
excludedAspectsTransferDefinition.setExcludedAspects(this.excludedAspects);
|
||||
}
|
||||
}
|
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.MutablePublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackage;
|
||||
import org.alfresco.service.cmr.publishing.Status;
|
||||
import org.alfresco.service.cmr.publishing.StatusUpdate;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingEventImpl implements PublishingEvent
|
||||
{
|
||||
private final String id;
|
||||
private final Status status;
|
||||
private final String channelId;
|
||||
private final PublishingPackage publishingPackage;
|
||||
private final Date createdTime;
|
||||
private final String creator;
|
||||
private final Date modifiedTime;
|
||||
private final String modifier;
|
||||
private final StatusUpdate statusUpdate;
|
||||
protected final Calendar scheduledTime;
|
||||
protected String comment;
|
||||
|
||||
public PublishingEventImpl(String id,
|
||||
Status status, String channelName,
|
||||
PublishingPackage publishingPackage,Date createdTime,
|
||||
String creator, Date modifiedTime,
|
||||
String modifier, Calendar scheduledTime, String comment,
|
||||
StatusUpdate statusUpdate)
|
||||
{
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
this.channelId = channelName;
|
||||
this.publishingPackage = publishingPackage;
|
||||
this.createdTime = createdTime;
|
||||
this.creator = creator;
|
||||
this.modifiedTime = modifiedTime;
|
||||
this.modifier = modifier;
|
||||
this.scheduledTime = scheduledTime;
|
||||
this.comment = comment;
|
||||
this.statusUpdate = statusUpdate;
|
||||
}
|
||||
|
||||
public PublishingEventImpl(PublishingEvent event)
|
||||
{
|
||||
this(event.getId(),
|
||||
event.getStatus(), event.getChannelId(),
|
||||
event.getPackage(), event.getCreatedTime(),
|
||||
event.getCreator(), event.getModifiedTime(),
|
||||
event.getModifier(), event.getScheduledTime(), event.getComment(),
|
||||
event.getStatusUpdate());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Status getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getChannelId()
|
||||
{
|
||||
return channelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Calendar getScheduledTime()
|
||||
{
|
||||
return (Calendar) scheduledTime.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingPackage getPackage()
|
||||
{
|
||||
return publishingPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Date getCreatedTime()
|
||||
{
|
||||
return new Date(createdTime.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getCreator()
|
||||
{
|
||||
return creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Date getModifiedTime()
|
||||
{
|
||||
return new Date(modifiedTime.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getModifier()
|
||||
{
|
||||
return modifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getComment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public StatusUpdate getStatusUpdate()
|
||||
{
|
||||
return statusUpdate;
|
||||
}
|
||||
|
||||
public MutablePublishingEvent edit()
|
||||
{
|
||||
return new MutablePublishingEventImpl(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int compareTo(PublishingEvent event)
|
||||
{
|
||||
if (event == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
Date eventTime = event.getCreatedTime();
|
||||
if (eventTime == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return (int)(createdTime.getTime() - eventTime.getTime());
|
||||
}
|
||||
|
||||
}
|
@@ -1,207 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.Status;
|
||||
import org.alfresco.service.cmr.publishing.StatusUpdate;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.urlshortening.UrlShortener;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingEventProcessor
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(PublishingEventProcessor.class);
|
||||
|
||||
private PublishingEventHelper eventHelper;
|
||||
private ChannelService channelService;
|
||||
private NodeService nodeService;
|
||||
private BehaviourFilter behaviourFilter;
|
||||
private UrlShortener urlShortener;
|
||||
private TransactionService transactionService;
|
||||
|
||||
public void processEventNode(NodeRef eventNode)
|
||||
{
|
||||
ParameterCheck.mandatory("eventNode", eventNode);
|
||||
try
|
||||
{
|
||||
updateEventStatus(eventNode, Status.IN_PROGRESS);
|
||||
final PublishingEvent event = eventHelper.getPublishingEvent(eventNode);
|
||||
String channelName = event.getChannelId();
|
||||
final ChannelImpl channel = (ChannelImpl) channelService.getChannelById(channelName);
|
||||
if (channel == null)
|
||||
{
|
||||
fail(eventNode, "No channel found");
|
||||
}
|
||||
else
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
try
|
||||
{
|
||||
behaviourFilter.disableBehaviour();
|
||||
channel.publishEvent(event);
|
||||
sendStatusUpdate(channel, event.getStatusUpdate());
|
||||
}
|
||||
finally
|
||||
{
|
||||
behaviourFilter.enableBehaviour();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, false, true);
|
||||
updateEventStatus(eventNode, Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("Caught exception while processing publishing event " + eventNode, e);
|
||||
fail(eventNode, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendStatusUpdate(Channel publishChannel, StatusUpdate update)
|
||||
{
|
||||
if (update == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String message = update.getMessage();
|
||||
String nodeUrl = getNodeUrl(publishChannel, update);
|
||||
Set<String> channels = update.getChannelIds();
|
||||
for (String channelId : channels)
|
||||
{
|
||||
Channel channel = channelService.getChannelById(channelId);
|
||||
if (channel != null)
|
||||
{
|
||||
channel.sendStatusUpdate(message, nodeUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishChannel Channel
|
||||
* @param update StatusUpdate
|
||||
* @return String
|
||||
*/
|
||||
private String getNodeUrl(Channel publishChannel, StatusUpdate update)
|
||||
{
|
||||
NodeRef node = update.getNodeToLinkTo();
|
||||
String nodeUrl = null;
|
||||
if (node!= null)
|
||||
{
|
||||
nodeUrl = publishChannel.getUrl(node);
|
||||
if (nodeUrl != null)
|
||||
{
|
||||
nodeUrl = " " + urlShortener.shortenUrl(nodeUrl);
|
||||
}
|
||||
}
|
||||
return nodeUrl;
|
||||
}
|
||||
|
||||
public void fail(NodeRef eventNode, String msg)
|
||||
{
|
||||
log.error("Failed to process publishing event " + eventNode + ": " + msg);
|
||||
updateEventStatus(eventNode, Status.FAILED);
|
||||
}
|
||||
|
||||
private void updateEventStatus(final NodeRef eventNode, final Status status)
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, status.name());
|
||||
return null;
|
||||
}
|
||||
}, false, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param channelService the channelService to set
|
||||
*/
|
||||
public void setChannelService(ChannelService channelService)
|
||||
{
|
||||
this.channelService = channelService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param eventHelper the Publishing Event Helper to set
|
||||
*/
|
||||
public void setPublishingEventHelper(PublishingEventHelper eventHelper)
|
||||
{
|
||||
this.eventHelper = eventHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param behaviourFilter the behaviourFilter to set
|
||||
*/
|
||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||
{
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param urlShortener the urlShortener to set
|
||||
*/
|
||||
public void setUrlShortener(UrlShortener urlShortener)
|
||||
{
|
||||
this.urlShortener = urlShortener;
|
||||
}
|
||||
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/1.0";
|
||||
public static final String PREFIX = "pub";
|
||||
|
||||
public static final String WF_NAMESPACE = "http://www.alfresco.org/model/publishingworkflow/1.0";
|
||||
public static final String WF_PREFIX = "pubwf";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
public static final QName TYPE_DELIVERY_SERVER = QName.createQName(NAMESPACE, "DeliveryServer");
|
||||
public static final QName TYPE_ENVIRONMENT= QName.createQName(NAMESPACE, "Environment");
|
||||
public static final QName TYPE_PUBLISHING_QUEUE = QName.createQName(NAMESPACE, "PublishingQueue");
|
||||
public static final QName TYPE_CHANNEL_CONTAINER = QName.createQName(NAMESPACE, "SiteChannelContainer");
|
||||
public static final QName TYPE_PUBLISHING_EVENT = QName.createQName(NAMESPACE, "PublishingEvent");
|
||||
public static final QName TYPE_PUBLISHING_CONNECTION = QName.createQName(NAMESPACE, "Connection");
|
||||
|
||||
public static final QName ASPECT_CHANNEL_INFO= QName.createQName(NAMESPACE, "channelInfo");
|
||||
public static final QName ASPECT_PUBLISHED = QName.createQName(NAMESPACE, "published");
|
||||
public static final QName ASPECT_OAUTH1_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "OAuth1DeliveryChannelAspect");
|
||||
public static final QName ASPECT_OAUTH2_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "OAuth2DeliveryChannelAspect");
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
|
||||
public static final QName PROP_CHANNEL = QName.createQName(NAMESPACE, "channel");
|
||||
public static final QName PROP_CHANNEL_TYPE = QName.createQName(NAMESPACE, "channelType");
|
||||
public static final QName PROP_CHANNEL_TYPE_ID = QName.createQName(NAMESPACE, "channelTypeId");
|
||||
public static final QName PROP_PUBLISHING_EVENT_STATUS= QName.createQName(NAMESPACE, "publishingEventStatus");
|
||||
public static final QName PROP_PUBLISHING_EVENT_TIME = QName.createQName(NAMESPACE, "publishingEventTime");
|
||||
public static final QName PROP_PUBLISHING_EVENT_TIME_ZONE = QName.createQName(NAMESPACE, "publishingEventTimeZone");
|
||||
public static final QName PROP_PUBLISHING_EVENT_COMMENT = QName.createQName(NAMESPACE, "publishingEventComment");
|
||||
public static final QName PROP_PUBLISHING_EVENT_CHANNEL= QName.createQName(NAMESPACE, "publishingEventChannel");
|
||||
public static final QName PROP_PUBLISHING_EVENT_WORKFLOW_ID= QName.createQName(NAMESPACE, "publishingEventWorkflowId");
|
||||
public static final QName PROP_PUBLISHING_EVENT_PAYLOAD = QName.createQName(NAMESPACE, "publishingEventPayload");
|
||||
public static final QName PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH = QName.createQName(NAMESPACE, "publishingEventNodesToPublish");
|
||||
public static final QName PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH = QName.createQName(NAMESPACE, "publishingEventNodesToUnpublish");
|
||||
public static final QName PROP_STATUS_UPDATE_CHANNEL_NAMES = QName.createQName(NAMESPACE, "statusUpdateChannelNames");
|
||||
public static final QName PROP_STATUS_UPDATE_NODE_REF = QName.createQName(NAMESPACE, "statusUpdateNodeRef");
|
||||
public static final QName PROP_STATUS_UPDATE_MESSAGE = QName.createQName(NAMESPACE, "statusUpdateMessage");
|
||||
public static final QName PROP_AUTHORISATION_COMPLETE = QName.createQName(NAMESPACE, "authorisationComplete");
|
||||
public static final QName PROP_OAUTH1_TOKEN_VALUE = QName.createQName(NAMESPACE, "oauth1TokenValue");
|
||||
public static final QName PROP_OAUTH1_TOKEN_SECRET = QName.createQName(NAMESPACE, "oauth1TokenSecret");
|
||||
public static final QName PROP_CHANNEL_USERNAME = QName.createQName(NAMESPACE, "channelUsername");
|
||||
public static final QName PROP_CHANNEL_PASSWORD = QName.createQName(NAMESPACE, "channelPassword");
|
||||
public static final QName PROP_OAUTH2_TOKEN = QName.createQName(NAMESPACE, "oauth2Token");
|
||||
public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId");
|
||||
public static final QName PROP_ASSET_URL = QName.createQName(NAMESPACE, "assetUrl");
|
||||
|
||||
// Publishing Connection Properties
|
||||
public static final QName PROP_ACCOUNT_ID= QName.createQName(NAMESPACE, "accountId");
|
||||
public static final QName PROP_PROVIDER_ID= QName.createQName(NAMESPACE, "providerId");
|
||||
public static final QName PROP_PROVIDER_ACCOUNT_ID= QName.createQName(NAMESPACE, "providerAccountId");
|
||||
public static final QName PROP_ACCESS_TOKEN= QName.createQName(NAMESPACE, "accessToken");
|
||||
public static final QName PROP_ACCESS_SECRET= QName.createQName(NAMESPACE, "secret");
|
||||
public static final QName PROP_REFRESH_TOKEN= QName.createQName(NAMESPACE, "refreshToken");
|
||||
|
||||
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_SCHEDULED = "SCHEDULED";
|
||||
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_IN_PROGRESS = "IN_PROGRESS";
|
||||
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_CANCEL_REQUESTED = "CANCEL_REQUESTED";
|
||||
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_COMPLETED = "COMPLETED";
|
||||
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_FAILED = "FAILED";
|
||||
|
||||
|
||||
public static final QName ASSOC_PUBLISHING_QUEUE = QName.createQName(NAMESPACE, "publishingQueueAssoc");
|
||||
public static final QName ASSOC_PUBLISHING_EVENT = QName.createQName(NAMESPACE, "publishingEventAssoc");
|
||||
public static final QName ASSOC_SOURCE = QName.createQName(NAMESPACE, "source");
|
||||
public static final QName ASSOC_LAST_PUBLISHING_EVENT= QName.createQName(NAMESPACE, "lastPublishingEvent");
|
||||
public static final QName ASSOC_PUBLISHED_NODES = QName.createQName(NAMESPACE, "publishedNodes");
|
||||
|
||||
// Workflow Properties
|
||||
public static final QName PROP_WF_PUBLISHING_EVENT= QName.createQName(WF_NAMESPACE, "publishingEvent");
|
||||
public static final QName PROP_WF_SCHEDULED_PUBLISH_DATE= QName.createQName(WF_NAMESPACE, "scheduledPublishDate");
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.NodeSnapshot;
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
// Package protected
|
||||
class PublishingPackageEntryImpl implements PublishingPackageEntry
|
||||
{
|
||||
private final boolean publish;
|
||||
private final NodeRef nodeRef;
|
||||
private final NodeSnapshot snapshot;
|
||||
|
||||
public PublishingPackageEntryImpl(boolean publish, NodeRef nodeRef, NodeSnapshot snapshot)
|
||||
{
|
||||
this.publish = publish;
|
||||
this.nodeRef = nodeRef;
|
||||
this.snapshot= snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isPublish()
|
||||
{
|
||||
return publish;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public NodeSnapshot getSnapshot()
|
||||
{
|
||||
return snapshot;
|
||||
}
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackage;
|
||||
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingPackageImpl implements PublishingPackage
|
||||
{
|
||||
private final Map<NodeRef, PublishingPackageEntry> entries;
|
||||
private final Set<NodeRef> nodesToPublish;
|
||||
private final Set<NodeRef> nodesToUnpublish;
|
||||
|
||||
public PublishingPackageImpl(Map<NodeRef, PublishingPackageEntry> entries)
|
||||
{
|
||||
Set<NodeRef> toPublish = new HashSet<NodeRef>();
|
||||
Set<NodeRef> toUnpublish = new HashSet<NodeRef>();
|
||||
for (PublishingPackageEntry entry : entries.values())
|
||||
{
|
||||
NodeRef node = entry.getNodeRef();
|
||||
if (entry.isPublish())
|
||||
{
|
||||
toPublish.add(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
toUnpublish.add(node);
|
||||
}
|
||||
}
|
||||
HashMap<NodeRef, PublishingPackageEntry> entryMap = new HashMap<NodeRef, PublishingPackageEntry>(entries);
|
||||
this.entries = Collections.unmodifiableMap(entryMap);
|
||||
this.nodesToPublish = Collections.unmodifiableSet(toPublish);
|
||||
this.nodesToUnpublish = Collections.unmodifiableSet(toUnpublish);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Collection<PublishingPackageEntry> getEntries()
|
||||
{
|
||||
return entries.values();
|
||||
}
|
||||
|
||||
public Map<NodeRef,PublishingPackageEntry> getEntryMap()
|
||||
{
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<NodeRef> getNodesToPublish()
|
||||
{
|
||||
return nodesToPublish;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<NodeRef> getNodesToUnpublish()
|
||||
{
|
||||
return nodesToUnpublish;
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.PublishingQueue;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingQueueFactory
|
||||
{
|
||||
PublishingQueue createPublishingQueueObject(String siteId);
|
||||
|
||||
PublishingQueue createPublishingQueueObject(NodeRef environmentNodeRef);
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.publishing.PublishingDetails;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEvent;
|
||||
import org.alfresco.service.cmr.publishing.PublishingEventFilter;
|
||||
import org.alfresco.service.cmr.publishing.PublishingQueue;
|
||||
import org.alfresco.service.cmr.publishing.StatusUpdate;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingQueueImpl implements PublishingQueue
|
||||
{
|
||||
private final static String MSG_FAILED_TO_CREATE_PUBLISHING_EVENT = "publishing-create-event-failed";
|
||||
private final NodeRef nodeRef;
|
||||
private final PublishingEventHelper publishingEventHelper;
|
||||
|
||||
public PublishingQueueImpl(NodeRef nodeRef, PublishingEventHelper publishingEventHelper)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.publishingEventHelper = publishingEventHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PublishingDetails createPublishingDetails()
|
||||
{
|
||||
return publishingEventHelper.createPublishingDetails();
|
||||
}
|
||||
|
||||
public StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, String... channelNames)
|
||||
{
|
||||
return createStatusUpdate(message, nodeToLinkTo, Arrays.asList(channelNames));
|
||||
}
|
||||
|
||||
public StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, Collection<String> channelNames)
|
||||
{
|
||||
return new StatusUpdateImpl(message, nodeToLinkTo, channelNames);
|
||||
}
|
||||
|
||||
public List<PublishingEvent> getPublishingEvents(PublishingEventFilter filter)
|
||||
{
|
||||
return publishingEventHelper.findPublishingEvents(nodeRef, filter);
|
||||
}
|
||||
|
||||
public PublishingEventFilter createPublishingEventFilter()
|
||||
{
|
||||
return new PublishingEventFilterImpl();
|
||||
}
|
||||
|
||||
public String scheduleNewEvent(PublishingDetails publishingDetails)
|
||||
{
|
||||
try
|
||||
{
|
||||
NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingDetails);
|
||||
publishingEventHelper.startPublishingWorkflow(eventNode, publishingDetails.getSchedule());
|
||||
return eventNode.toString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(MSG_FAILED_TO_CREATE_PUBLISHING_EVENT, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nodeRef
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
}
|
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import static org.alfresco.model.ContentModel.ASSOC_CONTAINS;
|
||||
import static org.alfresco.model.ContentModel.TYPE_FOLDER;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.ASSOC_PUBLISHING_QUEUE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.NAMESPACE;
|
||||
import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_QUEUE;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.node.NodeUtils;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
/**
|
||||
* Returns a properly configured Environment. The factory is multi-tenancy enabled, returning the correct Environment object for the current domain.
|
||||
*
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PublishingRootObject
|
||||
{
|
||||
public static final String NAME = "publishingRootObject";
|
||||
protected static final QName CHANNELS_QNAME = QName.createQName(NAMESPACE, "channels");
|
||||
|
||||
private NodeService nodeService;
|
||||
private PublishingEventHelper publishingEventHelper;
|
||||
private NamespaceService namespaceService;
|
||||
private SearchService searchService;
|
||||
private TransactionService transactionService;
|
||||
private PermissionService permissionService;
|
||||
|
||||
private StoreRef publishingStore;
|
||||
private String publishingRootPath;
|
||||
|
||||
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the approprieate {@link Environment} for the current domain.
|
||||
* @throws BeansException
|
||||
*/
|
||||
public Environment getEnvironment() throws BeansException
|
||||
{
|
||||
return createEnvironment();
|
||||
}
|
||||
|
||||
public NodeRef getChannelContainer()
|
||||
{
|
||||
return getEnvironment().getChannelsContainer();
|
||||
}
|
||||
|
||||
public PublishingQueueImpl getPublishingQueue()
|
||||
{
|
||||
return getEnvironment().getPublishingQueue();
|
||||
}
|
||||
|
||||
private Environment createEnvironment()
|
||||
{
|
||||
return AuthenticationUtil.runAs(new RunAsWork<Environment>()
|
||||
{
|
||||
public Environment doWork() throws Exception
|
||||
{
|
||||
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
txnHelper.setForceWritable(true);
|
||||
boolean requiresNew = false;
|
||||
if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE)
|
||||
{
|
||||
//We can be in a read-only transaction, so force a new transaction
|
||||
requiresNew = true;
|
||||
}
|
||||
|
||||
return txnHelper.doInTransaction(new RetryingTransactionCallback<Environment>()
|
||||
{
|
||||
public Environment execute() throws Exception
|
||||
{
|
||||
NodeRef environmentNode = getEnvironmentNode();
|
||||
PublishingQueueImpl queue = createPublishingQueue(environmentNode);
|
||||
NodeRef channelsContainer = getChannelsContainer(environmentNode);
|
||||
return new Environment(environmentNode, queue, channelsContainer);
|
||||
}
|
||||
}, false,requiresNew);
|
||||
}
|
||||
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
private NodeRef getChannelsContainer(NodeRef environmentNode)
|
||||
{
|
||||
List<ChildAssociationRef> childAssocs =
|
||||
nodeService.getChildAssocs(environmentNode,ASSOC_CONTAINS, CHANNELS_QNAME);
|
||||
NodeRef channels = NodeUtils.getSingleChildAssocNode(childAssocs, true);
|
||||
if (channels == null)
|
||||
{
|
||||
// No channels container.
|
||||
channels = nodeService.createNode(environmentNode,
|
||||
ASSOC_CONTAINS,
|
||||
CHANNELS_QNAME,
|
||||
TYPE_FOLDER).getChildRef();
|
||||
}
|
||||
return channels;
|
||||
}
|
||||
|
||||
private PublishingQueueImpl createPublishingQueue(NodeRef environmentNode)
|
||||
{
|
||||
NodeRef queueNode = getPublishingQueueNode(environmentNode);
|
||||
return new PublishingQueueImpl(queueNode, publishingEventHelper);
|
||||
}
|
||||
|
||||
private NodeRef getPublishingQueueNode(NodeRef environmentNode)
|
||||
{
|
||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(environmentNode, ASSOC_PUBLISHING_QUEUE, RegexQNamePattern.MATCH_ALL);
|
||||
NodeRef queueNode = NodeUtils.getSingleChildAssocNode(childAssocs, true);
|
||||
if (queueNode == null)
|
||||
{
|
||||
// No publishing queue
|
||||
queueNode = nodeService.createNode(environmentNode,
|
||||
ASSOC_PUBLISHING_QUEUE,
|
||||
QName.createQName(NAMESPACE, "publishingQueue"),
|
||||
TYPE_PUBLISHING_QUEUE).getChildRef();
|
||||
permissionService.setPermission(queueNode, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN, true);
|
||||
}
|
||||
return queueNode;
|
||||
}
|
||||
|
||||
private NodeRef getEnvironmentNode()
|
||||
{
|
||||
return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
||||
{
|
||||
public NodeRef execute() throws Exception
|
||||
{
|
||||
return findEnvrionmentNode();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
private NodeRef findEnvrionmentNode()
|
||||
{
|
||||
NodeRef rootNode = nodeService.getRootNode(publishingStore);
|
||||
List<NodeRef> refs = searchService.selectNodes(rootNode, publishingRootPath, null, namespaceService, false);
|
||||
if (refs.size() != 1)
|
||||
{
|
||||
String msg = "Invalid publishing root path: " + publishingRootPath + " - found: " + refs.size();
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishingStore the publishingStore to set
|
||||
*/
|
||||
public void setPublishingStore(String publishingStore)
|
||||
{
|
||||
this.publishingStore = new StoreRef(publishingStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishingRootPath the publishingRootPath to set
|
||||
*/
|
||||
public void setPublishingRootPath(String publishingRootPath)
|
||||
{
|
||||
this.publishingRootPath = publishingRootPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService the namespaceService to set
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishingEventHelper the publishingEventHelper to set
|
||||
*/
|
||||
public void setPublishingEventHelper(PublishingEventHelper publishingEventHelper)
|
||||
{
|
||||
this.publishingEventHelper = publishingEventHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param searchService the searchService to set
|
||||
*/
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permissionService the permissionService to set
|
||||
*/
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
}
|
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestDeletedNode;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestHeader;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
|
||||
import org.alfresco.repo.transfer.manifest.TransferManifestProcessor;
|
||||
import org.alfresco.repo.transfer.manifest.XMLTransferManifestReader;
|
||||
import org.alfresco.repo.transfer.manifest.XMLTransferManifestWriter;
|
||||
import org.alfresco.service.cmr.publishing.NodeSnapshot;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class StandardNodeSnapshotSerializer implements NodeSnapshotSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<NodeSnapshot> deserialize(InputStream input) throws Exception
|
||||
{
|
||||
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
|
||||
SAXParser parser = saxParserFactory.newSAXParser();
|
||||
NodeSnapshotDeserializer processor = new NodeSnapshotDeserializer();
|
||||
|
||||
XMLTransferManifestReader xmlReader = new XMLTransferManifestReader(processor);
|
||||
parser.parse(input, xmlReader);
|
||||
return processor.getSnapshots();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void serialize(Collection<NodeSnapshot> snapshots, OutputStream output) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
TransferManifestHeader header = new TransferManifestHeader();
|
||||
header.setCreatedDate(new Date());
|
||||
header.setNodeCount(snapshots.size());
|
||||
header.setReadOnly(false);
|
||||
header.setSync(false);
|
||||
|
||||
Writer writer = new OutputStreamWriter(output, "UTF-8");
|
||||
|
||||
XMLTransferManifestWriter transferManifestWriter = new XMLTransferManifestWriter();
|
||||
transferManifestWriter.startTransferManifest(writer);
|
||||
transferManifestWriter.writeTransferManifestHeader(header);
|
||||
|
||||
// Iterate over NodesToPublish and Serialize.
|
||||
for (NodeSnapshot snapshot: snapshots)
|
||||
{
|
||||
if (snapshot instanceof NodeSnapshotTransferImpl)
|
||||
{
|
||||
NodeSnapshotTransferImpl snapshotImpl = (NodeSnapshotTransferImpl)snapshot;
|
||||
transferManifestWriter.writeTransferManifestNode(snapshotImpl.getTransferNode());
|
||||
}
|
||||
}
|
||||
transferManifestWriter.endTransferManifest();
|
||||
writer.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to serialize node snapshots.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
*
|
||||
*/
|
||||
public static class NodeSnapshotDeserializer implements TransferManifestProcessor
|
||||
{
|
||||
private List<NodeSnapshot> snapshots = new ArrayList<NodeSnapshot>();
|
||||
|
||||
|
||||
/**
|
||||
* @return the snapshots
|
||||
*/
|
||||
public List<NodeSnapshot> getSnapshots()
|
||||
{
|
||||
return snapshots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void endTransferManifest()
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void processTransferManifestNode(TransferManifestNormalNode node)
|
||||
{
|
||||
NodeSnapshotTransferImpl snapshot = new NodeSnapshotTransferImpl(node);
|
||||
snapshots.add(snapshot);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void processTransferManifestNode(TransferManifestDeletedNode node)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void processTransferManifiestHeader(TransferManifestHeader header)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void startTransferManifest()
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.repo.action.constraint.BaseParameterConstraint;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
|
||||
/**
|
||||
* Action parameter constraint that constrains value to a list of publishing channels that support status updates
|
||||
*
|
||||
* @see PublishContentActionExecuter
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class StatusUpdateChannelParameterConstraint extends BaseParameterConstraint
|
||||
{
|
||||
public static final String NAME = "ac-status-update-channels";
|
||||
|
||||
private ChannelService channelService;
|
||||
|
||||
public void setChannelService(ChannelService channelService)
|
||||
{
|
||||
this.channelService = channelService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
|
||||
*/
|
||||
protected Map<String, String> getAllowableValuesImpl()
|
||||
{
|
||||
List<Channel> channels = channelService.getStatusUpdateChannels(false);
|
||||
Map<String, String> result = new TreeMap<String, String>();
|
||||
for (Channel channel : channels)
|
||||
{
|
||||
result.put(channel.getId(), channel.getName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.StatusUpdate;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class StatusUpdateImpl implements StatusUpdate
|
||||
{
|
||||
private final String message;
|
||||
private final NodeRef nodeToLinkTo;
|
||||
private final Set<String> channelNames;
|
||||
|
||||
public StatusUpdateImpl(String message, NodeRef nodeToLinkTo, Collection<String> channelNames)
|
||||
{
|
||||
this.message = message;
|
||||
this.nodeToLinkTo = nodeToLinkTo;
|
||||
this.channelNames = Collections.unmodifiableSet(new HashSet<String>(channelNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<String> getChannelIds()
|
||||
{
|
||||
return channelNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public NodeRef getNodeToLinkTo()
|
||||
{
|
||||
return nodeToLinkTo;
|
||||
}
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.facebook;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.publishing.AbstractChannelType;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.facebook.api.Facebook;
|
||||
import org.springframework.social.oauth2.AccessGrant;
|
||||
import org.springframework.social.oauth2.GrantType;
|
||||
import org.springframework.social.oauth2.OAuth2Operations;
|
||||
import org.springframework.social.oauth2.OAuth2Parameters;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FacebookChannelType extends AbstractChannelType
|
||||
{
|
||||
public final static String ID = "facebook";
|
||||
public final static String DEFAULT_REDIRECT_URI = "https://www.alfresco.com/stand-alone-auth-return.html";
|
||||
|
||||
private FacebookPublishingHelper publishingHelper;
|
||||
private String redirectUri = DEFAULT_REDIRECT_URI;
|
||||
|
||||
public void setPublishingHelper(FacebookPublishingHelper facebookPublishingHelper)
|
||||
{
|
||||
this.publishingHelper = facebookPublishingHelper;
|
||||
}
|
||||
|
||||
public void setRedirectUri(String redirectUri)
|
||||
{
|
||||
this.redirectUri = redirectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return FacebookPublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusUpdate(Channel channel, String status)
|
||||
{
|
||||
Connection<Facebook> connection = publishingHelper.getFacebookConnectionForChannel(channel.getNodeRef());
|
||||
connection.updateStatus(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthUrlPair getAuthorisationUrls(Channel channel, String callbackUrl)
|
||||
{
|
||||
ParameterCheck.mandatory("channel", channel);
|
||||
if (!ID.equals(channel.getChannelType().getId()))
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid channel type: " + channel.getChannelType().getId());
|
||||
}
|
||||
|
||||
NodeRef channelRef = channel.getNodeRef();
|
||||
StringBuilder authStateBuilder = new StringBuilder(channelRef.getStoreRef().getProtocol()).append('.').append(
|
||||
channelRef.getStoreRef().getIdentifier()).append('.').append(channelRef.getId());
|
||||
OAuth2Operations oauthOperations = publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
OAuth2Parameters params = new OAuth2Parameters();
|
||||
params.setRedirectUri(redirectUri);
|
||||
params.setScope("publish_stream,offline_access,user_photos,user_videos");
|
||||
params.setState(authStateBuilder.toString());
|
||||
String authRequestUrl = oauthOperations.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, params);
|
||||
return new AuthUrlPair(authRequestUrl, redirectUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
|
||||
Map<String, String[]> callbackParams)
|
||||
{
|
||||
AuthStatus authorised = AuthStatus.UNAUTHORISED;
|
||||
|
||||
String accessToken = null;
|
||||
if (callbackParams.containsKey("access_token"))
|
||||
{
|
||||
//We have been given the access token directly.
|
||||
accessToken = callbackParams.get("access_token")[0];
|
||||
}
|
||||
else if (callbackParams.containsKey("code"))
|
||||
{
|
||||
//We have been passed an authorisation code that needs to be exchanged for a token
|
||||
OAuth2Operations oauthOps = publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
AccessGrant grant = oauthOps.exchangeForAccess(callbackParams.get("code")[0], redirectUri, null);
|
||||
accessToken = grant.getAccessToken();
|
||||
}
|
||||
if (accessToken != null)
|
||||
{
|
||||
Map<QName,Serializable> channelProps = new HashMap<QName, Serializable>();
|
||||
channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken);
|
||||
channelProps = getEncryptor().encrypt(channelProps);
|
||||
getChannelService().updateChannel(channel, channelProps);
|
||||
authorised = AuthStatus.AUTHORISED;
|
||||
}
|
||||
return authorised;
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.facebook;
|
||||
|
||||
import org.alfresco.repo.node.encryption.MetadataEncryptor;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.facebook.api.Facebook;
|
||||
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
|
||||
import org.springframework.social.oauth2.AccessGrant;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FacebookPublishingHelper
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private FacebookConnectionFactory connectionFactory;
|
||||
private MetadataEncryptor encryptor;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setConnectionFactory(FacebookConnectionFactory connectionFactory)
|
||||
{
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public FacebookConnectionFactory getConnectionFactory()
|
||||
{
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
public void setEncryptor(MetadataEncryptor encryptor)
|
||||
{
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
public Connection<Facebook> getFacebookConnectionForChannel(NodeRef channelNode)
|
||||
{
|
||||
Connection<Facebook> connection = null;
|
||||
if (nodeService.exists(channelNode)
|
||||
&& nodeService.hasAspect(channelNode, FacebookPublishingModel.ASPECT_DELIVERY_CHANNEL))
|
||||
{
|
||||
String tokenValue = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH2_TOKEN, nodeService.getProperty(
|
||||
channelNode, PublishingModel.PROP_OAUTH2_TOKEN));
|
||||
Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||
|
||||
if (danceComplete)
|
||||
{
|
||||
AccessGrant token = new AccessGrant(tokenValue);
|
||||
connection = connectionFactory.createConnection(token);
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.facebook;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface FacebookPublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/facebook/1.0";
|
||||
public static final String PREFIX = "facebook";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect");
|
||||
}
|
@@ -1,226 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.filestore.FileContentReader;
|
||||
import org.alfresco.repo.publishing.AbstractOAuth1ChannelType;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.MediaOperations;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.PhotoInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.oauth1.OAuth1Parameters;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrChannelType extends AbstractOAuth1ChannelType<Flickr>
|
||||
{
|
||||
public final static String ID = "flickr";
|
||||
private final static Set<String> DEFAULT_SUPPORTED_MIME_TYPES = CollectionUtils.unmodifiableSet(
|
||||
MimetypeMap.MIMETYPE_IMAGE_GIF,
|
||||
MimetypeMap.MIMETYPE_IMAGE_JPEG,
|
||||
MimetypeMap.MIMETYPE_IMAGE_PNG);
|
||||
private static Log log = LogFactory.getLog(FlickrChannelType.class);
|
||||
|
||||
private ContentService contentService;
|
||||
private TaggingService taggingService;
|
||||
private FlickrPublishingHelper flickrHelper;
|
||||
private Set<String> supportedMimeTypes = DEFAULT_SUPPORTED_MIME_TYPES;
|
||||
|
||||
public void setSupportedMimeTypes(Set<String> mimeTypes)
|
||||
{
|
||||
supportedMimeTypes = Collections.unmodifiableSet(new TreeSet<String>(mimeTypes));
|
||||
}
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
public void setFlickrHelper(FlickrPublishingHelper flickrHelper)
|
||||
{
|
||||
this.flickrHelper = flickrHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return FlickrPublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedMimeTypes()
|
||||
{
|
||||
return supportedMimeTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> channelProperties)
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
ContentReader reader = contentService.getReader(nodeToPublish, ContentModel.PROP_CONTENT);
|
||||
if (reader.exists())
|
||||
{
|
||||
File contentFile;
|
||||
boolean deleteContentFileOnCompletion = false;
|
||||
if (FileContentReader.class.isAssignableFrom(reader.getClass()))
|
||||
{
|
||||
// Grab the content straight from the content store if we can...
|
||||
contentFile = ((FileContentReader) reader).getFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
// ...otherwise copy it to a temp file and use the copy...
|
||||
File tempDir = TempFileProvider.getLongLifeTempDir("flickr");
|
||||
contentFile = TempFileProvider.createTempFile("flickr", "", tempDir);
|
||||
reader.getContent(contentFile);
|
||||
deleteContentFileOnCompletion = true;
|
||||
}
|
||||
try
|
||||
{
|
||||
Resource res = new FileSystemResource(contentFile);
|
||||
Connection<Flickr> connection = flickrHelper.getConnectionFromChannelProps(channelProperties);
|
||||
|
||||
String name = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_NAME);
|
||||
String title = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
title = name;
|
||||
}
|
||||
String description = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_DESCRIPTION);
|
||||
if (description == null || description.length() == 0)
|
||||
{
|
||||
description = title;
|
||||
}
|
||||
List<String> tags = taggingService.getTags(nodeToPublish);
|
||||
String[] tagArray = tags.toArray(new String[tags.size()]);
|
||||
|
||||
MediaOperations mediaOps = connection.getApi().mediaOperations();
|
||||
String id = mediaOps.postPhoto(res, title, description, tagArray);
|
||||
|
||||
//Store info onto the published node...
|
||||
nodeService.addAspect(nodeToPublish, FlickrPublishingModel.ASPECT_ASSET, null);
|
||||
log.info("Posted image " + name + " to Flickr with id " + id);
|
||||
nodeService.setProperty(nodeToPublish, PublishingModel.PROP_ASSET_ID, id);
|
||||
|
||||
PhotoInfo photoInfo = mediaOps.getPhoto(id);
|
||||
String url = photoInfo.getPrimaryUrl();
|
||||
log.info("Photo url = " + url);
|
||||
nodeService.setProperty(nodeToPublish, PublishingModel.PROP_ASSET_URL, url);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (deleteContentFileOnCompletion)
|
||||
{
|
||||
contentFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> channelProperties)
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
if (nodeService.hasAspect(nodeToUnpublish, FlickrPublishingModel.ASPECT_ASSET))
|
||||
{
|
||||
String assetId = (String) nodeService.getProperty(nodeToUnpublish, PublishingModel.PROP_ASSET_ID);
|
||||
if (assetId != null)
|
||||
{
|
||||
Connection<Flickr> connection = flickrHelper.getConnectionFromChannelProps(channelProperties);
|
||||
MediaOperations mediaOps = connection.getApi().mediaOperations();
|
||||
mediaOps.deletePhoto(assetId);
|
||||
nodeService.removeAspect(nodeToUnpublish, FlickrPublishingModel.ASPECT_ASSET);
|
||||
nodeService.removeAspect(nodeToUnpublish, PublishingModel.ASPECT_ASSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuth1Parameters getOAuth1Parameters(String callbackUrl)
|
||||
{
|
||||
OAuth1Parameters oAuth1Parameters = new OAuth1Parameters();
|
||||
oAuth1Parameters.setCallbackUrl(callbackUrl);
|
||||
oAuth1Parameters.set("perms", "delete");
|
||||
return oAuth1Parameters;
|
||||
}
|
||||
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.node.encryption.MetadataEncryptor;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.connect.FlickrConnectionFactory;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.oauth1.OAuthToken;
|
||||
|
||||
/**
|
||||
* A utility class to support the {@link FlickrChannelType}.
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrPublishingHelper
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private FlickrConnectionFactory connectionFactory;
|
||||
private MetadataEncryptor encryptor;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setConnectionFactory(FlickrConnectionFactory connectionFactory)
|
||||
{
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public void setEncryptor(MetadataEncryptor encryptor)
|
||||
{
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
public FlickrConnectionFactory getConnectionFactory()
|
||||
{
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
public Connection<Flickr> getConnectionFromChannelProps(Map<QName,Serializable> channelProperties)
|
||||
{
|
||||
Connection<Flickr> connection = null;
|
||||
String tokenValue = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, channelProperties
|
||||
.get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE));
|
||||
String tokenSecret = (String) encryptor.decrypt(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, channelProperties
|
||||
.get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET));
|
||||
Boolean danceComplete = (Boolean) channelProperties.get(PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||
|
||||
if (danceComplete)
|
||||
{
|
||||
OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
|
||||
connection = connectionFactory.createConnection(token);
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
public Connection<Flickr> getConnectionForPublishNode(NodeRef publishNode)
|
||||
{
|
||||
Connection<Flickr> connection = null;
|
||||
NodeRef channelNode = nodeService.getPrimaryParent(publishNode).getParentRef();
|
||||
if (nodeService.exists(channelNode)
|
||||
&& nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL))
|
||||
{
|
||||
connection = getConnectionFromChannelProps(nodeService.getProperties(channelNode));
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.flickr;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
*
|
||||
*/
|
||||
public interface FlickrPublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/flickr/1.0";
|
||||
public static final String PREFIX = "flickr";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api;
|
||||
|
||||
import org.springframework.social.ApiBinding;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface Flickr extends ApiBinding
|
||||
{
|
||||
boolean test();
|
||||
|
||||
/**
|
||||
* API for performing operations on albums, photos, and videos.
|
||||
*/
|
||||
MediaOperations mediaOperations();
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 7938720115597007302L;
|
||||
private String code;
|
||||
|
||||
public FlickrException(String errorCode, String message)
|
||||
{
|
||||
super(message);
|
||||
this.code = errorCode;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api;
|
||||
|
||||
import org.springframework.social.support.URIBuilder;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface FlickrHelper
|
||||
{
|
||||
String getRestEndpoint();
|
||||
|
||||
String getUploadEndpoint();
|
||||
|
||||
void addStandardParams(URIBuilder uriBuilder);
|
||||
|
||||
void addStandardParams(MultiValueMap<String, String> params);
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface MediaOperations
|
||||
{
|
||||
|
||||
String postPhoto(Resource photo, String title, String description, String... tags) throws FlickrException;
|
||||
|
||||
PhotoInfo getPhoto(String id) throws FlickrException;
|
||||
|
||||
void deletePhoto(String id) throws FlickrException;
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PhotoInfo
|
||||
{
|
||||
String getId();
|
||||
String getPrimaryUrl();
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface UserOperations
|
||||
{
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl;
|
||||
|
||||
import org.springframework.social.MissingAuthorizationException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
class AbstractFlickrOperations
|
||||
{
|
||||
|
||||
private final boolean isAuthorized;
|
||||
|
||||
public AbstractFlickrOperations(boolean isAuthorized)
|
||||
{
|
||||
this.isAuthorized = isAuthorized;
|
||||
}
|
||||
|
||||
protected void requireAuthorization()
|
||||
{
|
||||
if (!isAuthorized)
|
||||
{
|
||||
throw new MissingAuthorizationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,217 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.social.ExpiredAuthorizationException;
|
||||
import org.springframework.social.InsufficientPermissionException;
|
||||
import org.springframework.social.InternalServerErrorException;
|
||||
import org.springframework.social.InvalidAuthorizationException;
|
||||
import org.springframework.social.MissingAuthorizationException;
|
||||
import org.springframework.social.NotAuthorizedException;
|
||||
import org.springframework.social.OperationNotPermittedException;
|
||||
import org.springframework.social.ResourceNotFoundException;
|
||||
import org.springframework.social.RevokedAuthorizationException;
|
||||
import org.springframework.social.UncategorizedApiException;
|
||||
import org.springframework.social.facebook.api.NotAFriendException;
|
||||
import org.springframework.social.facebook.api.ResourceOwnershipException;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
class FlickrErrorHandler extends DefaultResponseErrorHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException
|
||||
{
|
||||
Map<String, String> errorDetails = extractErrorDetailsFromResponse(response);
|
||||
if (errorDetails == null)
|
||||
{
|
||||
handleUncategorizedError(response, errorDetails);
|
||||
}
|
||||
|
||||
handleFlickrError(response.getStatusCode(), errorDetails);
|
||||
|
||||
// if not otherwise handled, do default handling and wrap with
|
||||
// UncategorizedApiException
|
||||
handleUncategorizedError(response, errorDetails);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse response) throws IOException
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody()));
|
||||
return super.hasError(response) || (reader.ready() && reader.readLine().startsWith("{\"error\":"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Examines the error data returned from Facebook and throws the most
|
||||
* applicable exception.
|
||||
*
|
||||
* @param errorDetails
|
||||
* a Map containing a "type" and a "message" corresponding to the
|
||||
* Graph API's error response structure.
|
||||
*/
|
||||
void handleFlickrError(HttpStatus statusCode, Map<String, String> errorDetails)
|
||||
{
|
||||
// Can't trust the type to be useful. It's often OAuthException, even
|
||||
// for things not OAuth-related.
|
||||
// Can rely only on the message (which itself isn't very consistent).
|
||||
String message = errorDetails.get("message");
|
||||
|
||||
if (statusCode == HttpStatus.OK)
|
||||
{
|
||||
if (message.contains("Some of the aliases you requested do not exist"))
|
||||
{
|
||||
throw new ResourceNotFoundException(message);
|
||||
}
|
||||
}
|
||||
else if (statusCode == HttpStatus.BAD_REQUEST)
|
||||
{
|
||||
if (message.contains("Unknown path components"))
|
||||
{
|
||||
throw new ResourceNotFoundException(message);
|
||||
}
|
||||
else if (message.equals("An access token is required to request this resource."))
|
||||
{
|
||||
throw new MissingAuthorizationException();
|
||||
}
|
||||
else if (message.equals("An active access token must be used to query information about the current user."))
|
||||
{
|
||||
throw new MissingAuthorizationException();
|
||||
}
|
||||
else if (message.startsWith("Error validating access token"))
|
||||
{
|
||||
if (message.contains("Session has expired at unix time"))
|
||||
{
|
||||
throw new ExpiredAuthorizationException();
|
||||
}
|
||||
else if (message
|
||||
.contains("The session has been invalidated because the user has changed the password."))
|
||||
{
|
||||
throw new RevokedAuthorizationException();
|
||||
}
|
||||
else if (message.contains("The session is invalid because the user logged out."))
|
||||
{
|
||||
throw new RevokedAuthorizationException();
|
||||
}
|
||||
else if (message.contains("has not authorized application"))
|
||||
{
|
||||
// Per https://developers.facebook.com/blog/post/500/, this
|
||||
// could be in the message when the user removes the
|
||||
// application.
|
||||
// In reality,
|
||||
// "The session has been invalidated because the user has changed the password."
|
||||
// is what you get in that case.
|
||||
// Leaving this check in place in case there FB does return
|
||||
// this message (could be a bug in FB?)
|
||||
throw new RevokedAuthorizationException();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidAuthorizationException(message);
|
||||
}
|
||||
}
|
||||
else if (message.equals("Error validating application."))
|
||||
{ // Access token with incorrect app ID
|
||||
throw new InvalidAuthorizationException(message);
|
||||
}
|
||||
else if (message.equals("Invalid access token signature."))
|
||||
{ // Access token that fails signature validation
|
||||
throw new InvalidAuthorizationException(message);
|
||||
}
|
||||
}
|
||||
else if (statusCode == HttpStatus.UNAUTHORIZED)
|
||||
{
|
||||
throw new NotAuthorizedException(message);
|
||||
}
|
||||
else if (statusCode == HttpStatus.FORBIDDEN)
|
||||
{
|
||||
if (message.contains("Requires extended permission"))
|
||||
{
|
||||
String requiredPermission = message.split(": ")[1];
|
||||
throw new InsufficientPermissionException(requiredPermission);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new OperationNotPermittedException(message);
|
||||
}
|
||||
}
|
||||
else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
{
|
||||
if (message.equals("User must be an owner of the friendlist"))
|
||||
{ // watch for pattern in similar message in other resources
|
||||
throw new ResourceOwnershipException(message);
|
||||
}
|
||||
else if (message.equals("The member must be a friend of the current user."))
|
||||
{
|
||||
throw new NotAFriendException(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InternalServerErrorException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleUncategorizedError(ClientHttpResponse response, Map<String, String> errorDetails)
|
||||
{
|
||||
try
|
||||
{
|
||||
super.handleError(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (errorDetails != null)
|
||||
{
|
||||
throw new UncategorizedApiException(errorDetails.get("message"), e);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UncategorizedApiException("No error details from Facebook", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempts to extract Facebook error details from the response. Returns
|
||||
* null if the response doesn't match the expected JSON error response.
|
||||
*/
|
||||
private Map<String, String> extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.alfresco.repo.publishing.JaxbHttpMessageConverter;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.FlickrHelper;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.MediaOperations;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||
import org.springframework.social.oauth1.AbstractOAuth1ApiBinding;
|
||||
import org.springframework.social.support.ClientHttpRequestFactorySelector;
|
||||
import org.springframework.social.support.URIBuilder;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrTemplate extends AbstractOAuth1ApiBinding implements Flickr, FlickrHelper
|
||||
{
|
||||
private static final String DEFAULT_ENDPOINT = "https://api.flickr.com/services/";
|
||||
|
||||
private static String endpoint = DEFAULT_ENDPOINT;
|
||||
|
||||
private String consumerKey;
|
||||
private MediaOperations mediaOperations;
|
||||
|
||||
public FlickrTemplate()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
public FlickrTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret)
|
||||
{
|
||||
super(consumerKey, consumerSecret, accessToken, accessTokenSecret);
|
||||
this.consumerKey = consumerKey;
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initSubApis()
|
||||
{
|
||||
mediaOperations = new MediaTemplate(this, getRestTemplate(), isAuthorized());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequestFactory(ClientHttpRequestFactory requestFactory)
|
||||
{
|
||||
// Wrap the request factory with a BufferingClientHttpRequestFactory so
|
||||
// that the error handler can do repeat reads on the response.getBody()
|
||||
super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(requestFactory));
|
||||
}
|
||||
|
||||
public static void setEndpoint(String endpoint)
|
||||
{
|
||||
FlickrTemplate.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public MediaOperations mediaOperations()
|
||||
{
|
||||
return mediaOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<HttpMessageConverter<?>> getMessageConverters()
|
||||
{
|
||||
List<HttpMessageConverter<?>> messageConverters = super.getMessageConverters();
|
||||
messageConverters.add(new ByteArrayHttpMessageConverter());
|
||||
messageConverters.add(new SourceHttpMessageConverter<Source>());
|
||||
messageConverters.add(new JaxbHttpMessageConverter("org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml"));
|
||||
return messageConverters;
|
||||
}
|
||||
|
||||
// private helpers
|
||||
private void initialize()
|
||||
{
|
||||
getRestTemplate().setErrorHandler(new FlickrErrorHandler());
|
||||
// Wrap the request factory with a BufferingClientHttpRequestFactory so
|
||||
// that the error handler can do repeat reads on the response.getBody()
|
||||
super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(getRestTemplate().getRequestFactory()));
|
||||
initSubApis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
{
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
params.add("method", "flickr.test.login");
|
||||
addStandardParams(params);
|
||||
URI uri = URIBuilder.fromUri(getRestEndpoint()).queryParams(params).build();
|
||||
getRestTemplate().getForObject(uri, String.class);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStandardParams(URIBuilder uriBuilder)
|
||||
{
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
addStandardParams(params);
|
||||
uriBuilder.queryParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStandardParams(MultiValueMap<String, String> params)
|
||||
{
|
||||
params.set("api_key", consumerKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRestEndpoint()
|
||||
{
|
||||
return endpoint + "rest/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploadEndpoint()
|
||||
{
|
||||
return endpoint + "upload/";
|
||||
}
|
||||
}
|
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl;
|
||||
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.FlickrException;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.FlickrHelper;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.MediaOperations;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.PhotoInfo;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.FlickrError;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.FlickrPayload;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.FlickrResponse;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.Photo;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml.PhotoId;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.social.support.URIBuilder;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
class MediaTemplate extends AbstractFlickrOperations implements MediaOperations
|
||||
{
|
||||
private final RestTemplate restTemplate;
|
||||
private FlickrHelper helper;
|
||||
|
||||
public MediaTemplate(FlickrHelper helper, RestTemplate restTemplate, boolean isAuthorizedForUser)
|
||||
{
|
||||
super(isAuthorizedForUser);
|
||||
this.restTemplate = restTemplate;
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
public String postPhoto(Resource photo, String title, String description, String... tags)
|
||||
{
|
||||
String id = null;
|
||||
requireAuthorization();
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
|
||||
URIBuilder uriBuilder = URIBuilder.fromUri(helper.getUploadEndpoint());
|
||||
|
||||
parts.set("photo", photo);
|
||||
if (description != null)
|
||||
{
|
||||
uriBuilder.queryParam("description", description);
|
||||
parts.set("description", description);
|
||||
}
|
||||
if (title != null)
|
||||
{
|
||||
uriBuilder.queryParam("title", title);
|
||||
parts.set("title", title);
|
||||
}
|
||||
if (tags.length > 0)
|
||||
{
|
||||
StringBuilder tagBuilder = new StringBuilder();
|
||||
for (String tag : tags)
|
||||
{
|
||||
tagBuilder.append(tag).append(' ');
|
||||
}
|
||||
String tagsString = tagBuilder.toString();
|
||||
uriBuilder.queryParam("tags", tagsString);
|
||||
parts.set("tags", tagsString);
|
||||
}
|
||||
helper.addStandardParams(uriBuilder);
|
||||
FlickrResponse response = restTemplate.postForObject(uriBuilder.build(), parts, FlickrResponse.class);
|
||||
FlickrPayload payload = response.payload;
|
||||
checkError(payload);
|
||||
if (PhotoId.class.isAssignableFrom(payload.getClass()))
|
||||
{
|
||||
id = ((PhotoId)payload).id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public PhotoInfo getPhoto(String id)
|
||||
{
|
||||
Photo result = null;
|
||||
requireAuthorization();
|
||||
URIBuilder uriBuilder = URIBuilder.fromUri(helper.getRestEndpoint());
|
||||
helper.addStandardParams(uriBuilder);
|
||||
uriBuilder.queryParam("method", "flickr.photos.getInfo");
|
||||
uriBuilder.queryParam("photo_id", id);
|
||||
FlickrResponse response = restTemplate.getForObject(uriBuilder.build(), FlickrResponse.class);
|
||||
FlickrPayload payload = response.payload;
|
||||
checkError(payload);
|
||||
if (Photo.class.isAssignableFrom(payload.getClass()))
|
||||
{
|
||||
result = (Photo)payload;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void deletePhoto(String id)
|
||||
{
|
||||
requireAuthorization();
|
||||
MultiValueMap<String, String> parts = new LinkedMultiValueMap<String, String>();
|
||||
helper.addStandardParams(parts);
|
||||
parts.add("method", "flickr.photos.delete");
|
||||
parts.add("photo_id", id);
|
||||
FlickrResponse response = restTemplate.postForObject(helper.getRestEndpoint(), parts, FlickrResponse.class);
|
||||
FlickrPayload payload = response.payload;
|
||||
checkError(payload);
|
||||
}
|
||||
|
||||
private void checkError(FlickrPayload payload) throws FlickrException
|
||||
{
|
||||
if (payload != null && FlickrError.class.isAssignableFrom(payload.getClass()))
|
||||
{
|
||||
FlickrError error = (FlickrError) payload;
|
||||
throw new FlickrException(error.code, error.msg);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl;
|
||||
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.UserOperations;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
class UserTemplate extends AbstractFlickrOperations implements UserOperations
|
||||
{
|
||||
|
||||
public UserTemplate(boolean isAuthorized)
|
||||
{
|
||||
super(isAuthorized);
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
|
||||
@XmlRootElement(name = "err")
|
||||
public class FlickrError implements FlickrPayload
|
||||
{
|
||||
@XmlAttribute
|
||||
public String code;
|
||||
|
||||
@XmlAttribute
|
||||
public String msg;
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface FlickrPayload
|
||||
{
|
||||
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlRootElement(name = "rsp")
|
||||
public class FlickrResponse
|
||||
{
|
||||
@XmlAttribute
|
||||
public String stat = "ok";
|
||||
@XmlAnyElement(lax = true)
|
||||
public FlickrPayload payload;
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "FlickrResponse[stat=" + stat + ", payload=" + payload + "]";
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.PhotoInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlRootElement(name = "photo")
|
||||
public class Photo implements FlickrPayload, PhotoInfo
|
||||
{
|
||||
@XmlAttribute
|
||||
public String id;
|
||||
|
||||
@XmlElement(name = "urls")
|
||||
public UrlList urlList = new UrlList();
|
||||
|
||||
public static class UrlList
|
||||
{
|
||||
@XmlElement(name = "url")
|
||||
public List<PhotoUrl> urls = new ArrayList<PhotoUrl>();
|
||||
}
|
||||
|
||||
public static class PhotoUrl
|
||||
{
|
||||
@XmlAttribute
|
||||
public String type;
|
||||
@XmlValue
|
||||
public String url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryUrl()
|
||||
{
|
||||
return urlList.urls.isEmpty() ? null : urlList.urls.get(0).url;
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.api.impl.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlRootElement(name = "photoid")
|
||||
public class PhotoId implements FlickrPayload
|
||||
{
|
||||
@XmlValue
|
||||
public String id;
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.connect;
|
||||
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
import org.springframework.social.ApiException;
|
||||
import org.springframework.social.connect.ApiAdapter;
|
||||
import org.springframework.social.connect.ConnectionValues;
|
||||
import org.springframework.social.connect.UserProfile;
|
||||
import org.springframework.social.connect.UserProfileBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrAdapter implements ApiAdapter<Flickr>
|
||||
{
|
||||
|
||||
public boolean test(Flickr flickr)
|
||||
{
|
||||
try
|
||||
{
|
||||
flickr.test();
|
||||
return true;
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setConnectionValues(Flickr flickr, ConnectionValues values)
|
||||
{
|
||||
}
|
||||
|
||||
public UserProfile fetchUserProfile(Flickr flickr)
|
||||
{
|
||||
return new UserProfileBuilder().setName("Brian").setFirstName("Brian").setLastName(
|
||||
"Brian").setEmail("Brian").setUsername("Brian").build();
|
||||
}
|
||||
|
||||
public void updateStatus(Flickr flickr, String message)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.connect;
|
||||
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.connect.FlickrAdapter;
|
||||
import org.springframework.social.connect.support.OAuth1ConnectionFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrConnectionFactory extends OAuth1ConnectionFactory<Flickr>
|
||||
{
|
||||
|
||||
public FlickrConnectionFactory(String consumerKey, String consumerSecret)
|
||||
{
|
||||
super("flickr", new FlickrServiceProvider(consumerKey, consumerSecret), new FlickrAdapter());
|
||||
}
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.connect;
|
||||
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.impl.FlickrTemplate;
|
||||
import org.springframework.social.oauth1.AbstractOAuth1ServiceProvider;
|
||||
import org.springframework.social.oauth1.OAuth1Template;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class FlickrServiceProvider extends AbstractOAuth1ServiceProvider<Flickr>
|
||||
{
|
||||
|
||||
public FlickrServiceProvider(String consumerKey, String consumerSecret)
|
||||
{
|
||||
super(consumerKey, consumerSecret, new OAuth1Template(consumerKey, consumerSecret,
|
||||
"http://www.flickr.com/services/oauth/request_token", "http://www.flickr.com/services/oauth/authorize",
|
||||
"http://www.flickr.com/services/oauth/access_token"));
|
||||
}
|
||||
|
||||
public Flickr getApi(String accessToken, String secret)
|
||||
{
|
||||
return new FlickrTemplate(getConsumerKey(), getConsumerSecret(), accessToken, secret);
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
/**
|
||||
* Flickr service provider connection repository and API adapter implementations.
|
||||
*/
|
||||
@PackageMarker
|
||||
package org.alfresco.repo.publishing.flickr.springsocial.connect;
|
||||
import org.alfresco.util.PackageMarker;
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin;
|
||||
|
||||
import static org.alfresco.repo.publishing.linkedin.LinkedInPublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
|
||||
import org.alfresco.repo.publishing.AbstractOAuth1ChannelType;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.AlfrescoLinkedIn;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.social.connect.Connection;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LinkedInChannelType extends AbstractOAuth1ChannelType<AlfrescoLinkedIn>
|
||||
{
|
||||
private final static Log log = LogFactory.getLog(LinkedInChannelType.class);
|
||||
public final static String ID = "linkedin";
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumStatusLength()
|
||||
{
|
||||
return 700;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusUpdate(Channel channel, String status)
|
||||
{
|
||||
NodeRef channelNode = new NodeRef(channel.getId());
|
||||
Connection<AlfrescoLinkedIn> connection = getConnectionForChannel(channelNode);
|
||||
if (log.isInfoEnabled())
|
||||
{
|
||||
log.info("Posting update to LinkedIn channel " + channel.getName() + ": " + status);
|
||||
}
|
||||
connection.getApi().shareComment(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.linkedin;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface LinkedInPublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/linkedin/1.0";
|
||||
public static final String PREFIX = "linkedin";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface Activity
|
||||
{
|
||||
public String getContentType();
|
||||
|
||||
public void setContentType(String value);
|
||||
|
||||
public String getBody();
|
||||
|
||||
public void setBody(String value);
|
||||
|
||||
public String getLocale();
|
||||
|
||||
public void setLocale(String value);
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api;
|
||||
|
||||
import org.springframework.social.linkedin.api.LinkedIn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface AlfrescoLinkedIn extends LinkedIn
|
||||
{
|
||||
void postNetworkUpdate(String update);
|
||||
|
||||
void shareComment(String comment);
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface Share
|
||||
{
|
||||
public String getComment();
|
||||
|
||||
public void setComment(String comment);
|
||||
|
||||
public ShareVisibility getVisibility();
|
||||
|
||||
public void setVisibility(ShareVisibility visibility);
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface ShareVisibility
|
||||
{
|
||||
ShareVisibilityCode getCode();
|
||||
void setCode(ShareVisibilityCode code);
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlEnum
|
||||
public enum ShareVisibilityCode
|
||||
{
|
||||
|
||||
@XmlEnumValue("anyone")
|
||||
ANYONE("anyone"),
|
||||
|
||||
@XmlEnumValue("connections-only")
|
||||
CONNECTIONS_ONLY("connections-only");
|
||||
|
||||
private final String value;
|
||||
|
||||
ShareVisibilityCode(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String value()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ShareVisibilityCode fromValue(String value)
|
||||
{
|
||||
for (ShareVisibilityCode validCode : ShareVisibilityCode.values())
|
||||
{
|
||||
if (validCode.value.equals(value))
|
||||
{
|
||||
return validCode;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(value);
|
||||
}
|
||||
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.publishing.JaxbHttpMessageConverter;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.Activity;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.AlfrescoLinkedIn;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.Share;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.impl.xml.JaxbActivityImpl;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.impl.xml.JaxbShareImpl;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.social.linkedin.api.impl.LinkedInTemplate;
|
||||
import org.springframework.social.support.URIBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class AlfrescoLinkedInTemplate extends LinkedInTemplate implements AlfrescoLinkedIn
|
||||
{
|
||||
private static String JAXB_CONTEXT_PATH = "org.alfresco.repo.publishing.linkedin.springsocial.api.impl.xml:"
|
||||
+ "org.alfresco.repo.publishing.linkedin.springsocial.api";
|
||||
|
||||
public AlfrescoLinkedInTemplate(String consumerKey, String consumerSecret, String accessToken,
|
||||
String accessTokenSecret)
|
||||
{
|
||||
super(consumerKey, consumerSecret, accessToken, accessTokenSecret);
|
||||
}
|
||||
|
||||
protected List<HttpMessageConverter<?>> getMessageConverters()
|
||||
{
|
||||
List<HttpMessageConverter<?>> messageConverters = super.getMessageConverters();
|
||||
messageConverters.add(new JaxbHttpMessageConverter(JAXB_CONTEXT_PATH));
|
||||
return messageConverters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postNetworkUpdate(String update)
|
||||
{
|
||||
if (update == null || update.trim().length() == 0)
|
||||
return;
|
||||
|
||||
URIBuilder uriBuilder = URIBuilder.fromUri("http://api.linkedin.com/v1/people/~/person-activities");
|
||||
|
||||
Activity activity = new JaxbActivityImpl();
|
||||
activity.setBody(update);
|
||||
|
||||
HttpEntity<?> entity = buildEntity(activity);
|
||||
getRestTemplate().postForObject(uriBuilder.build(), entity, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shareComment(String comment)
|
||||
{
|
||||
if (comment == null || comment.trim().length() == 0)
|
||||
return;
|
||||
|
||||
URIBuilder uriBuilder = URIBuilder.fromUri("http://api.linkedin.com/v1/people/~/shares");
|
||||
|
||||
Share share = new JaxbShareImpl();
|
||||
share.setComment(comment);
|
||||
|
||||
HttpEntity<?> entity = buildEntity(share);
|
||||
getRestTemplate().postForLocation(uriBuilder.build(), entity);
|
||||
}
|
||||
|
||||
private HttpEntity<?> buildEntity(Object body)
|
||||
{
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.TEXT_XML);
|
||||
|
||||
return new HttpEntity<Object>(body, headers);
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api.impl.xml;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.Activity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {"contentType", "body"})
|
||||
@XmlRootElement(name = "activity")
|
||||
public class JaxbActivityImpl implements Activity
|
||||
{
|
||||
@XmlElement(name = "content-type")
|
||||
protected String contentType = "linkedin-html";
|
||||
@XmlElement(required = true)
|
||||
protected String body;
|
||||
@XmlAttribute(required = true)
|
||||
protected String locale = Locale.getDefault().toString();
|
||||
|
||||
public String getContentType()
|
||||
{
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String value)
|
||||
{
|
||||
this.contentType = value;
|
||||
}
|
||||
|
||||
public String getBody()
|
||||
{
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String value)
|
||||
{
|
||||
this.body = value;
|
||||
}
|
||||
|
||||
public String getLocale()
|
||||
{
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(String value)
|
||||
{
|
||||
this.locale = value;
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api.impl.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.Share;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.ShareVisibility;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.ShareVisibilityCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = { "comment", "visibility" })
|
||||
@XmlRootElement(name = "share")
|
||||
public class JaxbShareImpl implements Share
|
||||
{
|
||||
@XmlElement(required = true, name = "comment")
|
||||
protected String comment;
|
||||
|
||||
@XmlElement(required = true, name = "visibility")
|
||||
protected JaxbShareVisibilityImpl visibility = new JaxbShareVisibilityImpl(ShareVisibilityCode.ANYONE);
|
||||
|
||||
public String getComment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment)
|
||||
{
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public ShareVisibility getVisibility()
|
||||
{
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public void setVisibility(ShareVisibility visibility)
|
||||
{
|
||||
this.visibility = new JaxbShareVisibilityImpl(visibility.getCode());
|
||||
}
|
||||
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.api.impl.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.ShareVisibility;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.ShareVisibilityCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = { "code" })
|
||||
@XmlRootElement(name = "visibility")
|
||||
public class JaxbShareVisibilityImpl implements ShareVisibility
|
||||
{
|
||||
@XmlElement(required = true)
|
||||
protected ShareVisibilityCode code;
|
||||
|
||||
public JaxbShareVisibilityImpl()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public JaxbShareVisibilityImpl(ShareVisibilityCode code)
|
||||
{
|
||||
super();
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ShareVisibilityCode getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(ShareVisibilityCode value)
|
||||
{
|
||||
this.code = value;
|
||||
}
|
||||
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.connect;
|
||||
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.AlfrescoLinkedIn;
|
||||
import org.springframework.social.connect.ApiAdapter;
|
||||
import org.springframework.social.connect.ConnectionValues;
|
||||
import org.springframework.social.connect.UserProfile;
|
||||
import org.springframework.social.connect.UserProfileBuilder;
|
||||
import org.springframework.social.linkedin.api.LinkedInProfile;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LinkedInAdapter implements ApiAdapter<AlfrescoLinkedIn>
|
||||
{
|
||||
public boolean test(AlfrescoLinkedIn linkedin) {
|
||||
try {
|
||||
linkedin.getUserProfile();
|
||||
return true;
|
||||
} catch (HttpClientErrorException e) {
|
||||
// TODO: Have api throw more specific exception and trigger off of that.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setConnectionValues(AlfrescoLinkedIn linkedin, ConnectionValues values) {
|
||||
LinkedInProfile profile = linkedin.getUserProfile();
|
||||
values.setProviderUserId(profile.getId());
|
||||
values.setDisplayName(profile.getFirstName() + " " + profile.getLastName());
|
||||
values.setProfileUrl(profile.getPublicProfileUrl());
|
||||
values.setImageUrl(profile.getProfilePictureUrl());
|
||||
}
|
||||
|
||||
public UserProfile fetchUserProfile(AlfrescoLinkedIn linkedin) {
|
||||
LinkedInProfile profile = linkedin.getUserProfile();
|
||||
return new UserProfileBuilder().setName(profile.getFirstName() + " " + profile.getLastName()).build();
|
||||
}
|
||||
|
||||
public void updateStatus(AlfrescoLinkedIn linkedin, String message) {
|
||||
// not supported yet
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.connect;
|
||||
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.AlfrescoLinkedIn;
|
||||
import org.springframework.social.connect.support.OAuth1ConnectionFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LinkedInConnectionFactory extends OAuth1ConnectionFactory<AlfrescoLinkedIn>{
|
||||
|
||||
public LinkedInConnectionFactory(String consumerKey, String consumerSecret) {
|
||||
super("linkedin", new LinkedInServiceProvider(consumerKey, consumerSecret), new LinkedInAdapter());
|
||||
}
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.linkedin.springsocial.connect;
|
||||
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.AlfrescoLinkedIn;
|
||||
import org.alfresco.repo.publishing.linkedin.springsocial.api.impl.AlfrescoLinkedInTemplate;
|
||||
import org.springframework.social.oauth1.AbstractOAuth1ServiceProvider;
|
||||
import org.springframework.social.oauth1.OAuth1Template;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LinkedInServiceProvider extends AbstractOAuth1ServiceProvider<AlfrescoLinkedIn> {
|
||||
|
||||
public LinkedInServiceProvider(String consumerKey, String consumerSecret) {
|
||||
super(consumerKey, consumerSecret, new OAuth1Template(consumerKey, consumerSecret,
|
||||
"https://api.linkedin.com/uas/oauth/requestToken",
|
||||
"https://www.linkedin.com/uas/oauth/authorize",
|
||||
"https://www.linkedin.com/uas/oauth/authenticate",
|
||||
"https://api.linkedin.com/uas/oauth/accessToken"));
|
||||
}
|
||||
|
||||
public AlfrescoLinkedIn getApi(String accessToken, String secret) {
|
||||
return new AlfrescoLinkedInTemplate(getConsumerKey(), getConsumerSecret(), accessToken, secret);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import com.benfante.jslideshare.SlideShareAPI;
|
||||
import com.benfante.jslideshare.SlideShareErrorException;
|
||||
import com.benfante.jslideshare.SlideShareException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface SlideShareApi extends SlideShareAPI
|
||||
{
|
||||
String deleteSlideshow(String username, String password, String id) throws SlideShareException,
|
||||
SlideShareErrorException;
|
||||
}
|
@@ -1,314 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.benfante.jslideshare.DocumentParser;
|
||||
import com.benfante.jslideshare.DocumentParserResult;
|
||||
import com.benfante.jslideshare.SlideShareConnector;
|
||||
import com.benfante.jslideshare.SlideShareErrorException;
|
||||
import com.benfante.jslideshare.SlideShareException;
|
||||
import com.benfante.jslideshare.messages.Group;
|
||||
import com.benfante.jslideshare.messages.Slideshow;
|
||||
import com.benfante.jslideshare.messages.SlideshowInfo;
|
||||
import com.benfante.jslideshare.messages.Tag;
|
||||
import com.benfante.jslideshare.messages.User;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SlideShareApiImpl implements SlideShareApi
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(SlideShareApiImpl.class);
|
||||
|
||||
public static final String URL_GET_SLIDESHOW = "URL_GET_SLIDESHOW";
|
||||
public static final String URL_GET_SLIDESHOW_INFO = "URL_GET_SLIDESHOW_INFO";
|
||||
public static final String URL_GET_SLIDESHOW_BY_USER = "URL_GET_SLIDESHOW_BY_USER";
|
||||
public static final String URL_GET_SLIDESHOW_BY_TAG = "URL_GET_SLIDESHOW_BY_TAG";
|
||||
public static final String URL_GET_SLIDESHOW_BY_GROUP = "URL_GET_SLIDESHOW_BY_GROUP";
|
||||
public static final String URL_UPLOAD_SLIDESHOW = "URL_UPLOAD_SLIDESHOW";
|
||||
public static final String URL_DELETE_SLIDESHOW = "URL_DELETE_SLIDESHOW";
|
||||
|
||||
private static Map<String, String> DEFAULT_API_URLS = new TreeMap<String, String>();
|
||||
|
||||
static
|
||||
{
|
||||
DEFAULT_API_URLS.put(URL_GET_SLIDESHOW, "https://www.slideshare.net/api/2/get_slideshow");
|
||||
DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_INFO, "https://www.slideshare.net/api/2/get_slideshow");
|
||||
DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_USER, "https://www.slideshare.net/api/2/get_slideshow_by_user");
|
||||
DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_TAG, "https://www.slideshare.net/api/2/get_slideshow_by_tag");
|
||||
DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_GROUP, "https://www.slideshare.net/api/2/get_slideshow_from_group");
|
||||
DEFAULT_API_URLS.put(URL_UPLOAD_SLIDESHOW, "https://www.slideshare.net/api/2/upload_slideshow");
|
||||
DEFAULT_API_URLS.put(URL_DELETE_SLIDESHOW, "https://www.slideshare.net/api/2/delete_slideshow");
|
||||
}
|
||||
|
||||
private Map<String, String> apiUrls = new TreeMap<String, String>(DEFAULT_API_URLS);
|
||||
|
||||
protected SlideShareConnector connector;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
public SlideShareApiImpl()
|
||||
{
|
||||
}
|
||||
|
||||
public SlideShareApiImpl(SlideShareConnector connector)
|
||||
{
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
public SlideShareConnector getConnector()
|
||||
{
|
||||
return connector;
|
||||
}
|
||||
|
||||
public void setConnector(SlideShareConnector connector)
|
||||
{
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
public void setApiUrls(Map<String, String> urls)
|
||||
{
|
||||
if (urls == null || !urls.keySet().containsAll(DEFAULT_API_URLS.keySet()))
|
||||
{
|
||||
throw new IllegalArgumentException("Specified URL set is missing one or more values. Expected "
|
||||
+ DEFAULT_API_URLS.keySet() + "; Received " + (urls == null ? urls : urls.keySet()));
|
||||
}
|
||||
}
|
||||
|
||||
public Slideshow getSlideshow(String id) throws SlideShareException, SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshow with id=" + id);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "slideshow_id", id);
|
||||
return sendMessage(URL_GET_SLIDESHOW, parameters).getSlideShow();
|
||||
}
|
||||
|
||||
public SlideshowInfo getSlideshowInfo(String id, String url) throws SlideShareException, SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshowInfo with id=" + id + ", url=" + url);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "slideshow_id", id);
|
||||
addParameter(parameters, "slideshow_url", url);
|
||||
return sendGetMessage(URL_GET_SLIDESHOW_INFO, parameters).getSlideShowInfo();
|
||||
}
|
||||
|
||||
public User getSlideshowByUser(String username) throws SlideShareException, SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshowByUser with username=" + username);
|
||||
return getSlideshowByUser(username, -1, -1);
|
||||
}
|
||||
|
||||
public User getSlideshowByUser(String username, int offset, int limit) throws SlideShareException,
|
||||
SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshowByUser with username=" + username + ", offset=" + offset + ", limit=" + limit);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "username_for", username);
|
||||
addLimits(parameters, offset, limit);
|
||||
return sendMessage(URL_GET_SLIDESHOW_BY_USER, parameters).getUser();
|
||||
}
|
||||
|
||||
public Tag getSlideshowByTag(String tag) throws SlideShareException, SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshowByTag with tag=" + tag);
|
||||
return getSlideshowByTag(tag, -1, -1);
|
||||
}
|
||||
|
||||
public Tag getSlideshowByTag(String tag, int offset, int limit) throws SlideShareException,
|
||||
SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshowByTag with tag=" + tag + ", offset=" + offset + ", limit=" + limit);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "tag", tag);
|
||||
addLimits(parameters, offset, limit);
|
||||
return sendMessage(URL_GET_SLIDESHOW_BY_TAG, parameters).getTag();
|
||||
}
|
||||
|
||||
public Group getSlideshowByGroup(String groupName) throws SlideShareException, SlideShareErrorException
|
||||
{
|
||||
logger.info("Called getSlideshowByGroup with groupName=" + groupName);
|
||||
return getSlideshowByGroup(groupName, -1, -1);
|
||||
}
|
||||
|
||||
public Group getSlideshowByGroup(String groupName, int offset, int limit) throws SlideShareException,
|
||||
SlideShareErrorException
|
||||
{
|
||||
logger
|
||||
.info("Called getSlideshowByGrop with groupName=" + groupName + ", offset=" + offset + ", limit="
|
||||
+ limit);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "group_name", groupName);
|
||||
addLimits(parameters, offset, limit);
|
||||
return sendMessage(URL_GET_SLIDESHOW_BY_GROUP, parameters).getGroup();
|
||||
}
|
||||
|
||||
public String uploadSlideshow(String username, String password, String title, File src, String description,
|
||||
String tags, boolean makeSrcPublic, boolean makeSlideshowPrivate, boolean generateSecretUrl,
|
||||
boolean allowEmbeds, boolean shareWithContacts) throws SlideShareException, SlideShareErrorException
|
||||
{
|
||||
logger.info("Called uploadSlideshow with username=" + username + ", password=XXX, title=" + title
|
||||
+ ", description=" + description + ", tags=" + tags + ", makeSrcPublic=" + makeSrcPublic
|
||||
+ ", makeSlideshowPrivate=" + makeSlideshowPrivate + ", generateSecretUrl=" + generateSecretUrl
|
||||
+ ", allowEmbeds=" + allowEmbeds + ", shareWithContacts=" + shareWithContacts);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "username", username);
|
||||
addParameter(parameters, "password", password);
|
||||
addParameter(parameters, "slideshow_title", title);
|
||||
addParameter(parameters, "slideshow_description", description);
|
||||
addParameter(parameters, "slideshow_tags", tags);
|
||||
addParameter(parameters, "make_src_public", makeSrcPublic);
|
||||
addParameter(parameters, "make_slideshow_private", makeSlideshowPrivate);
|
||||
addParameter(parameters, "generate_secret_url", generateSecretUrl);
|
||||
addParameter(parameters, "allow_embeds", allowEmbeds);
|
||||
addParameter(parameters, "share_with_contacts", shareWithContacts);
|
||||
Map<String, File> files = new HashMap<String, File>();
|
||||
files.put("slideshow_srcfile", src);
|
||||
return sendMessage(URL_UPLOAD_SLIDESHOW, parameters, files).getSlideShowId();
|
||||
}
|
||||
|
||||
public String deleteSlideshow(String username, String password, String id) throws SlideShareException,
|
||||
SlideShareErrorException
|
||||
{
|
||||
logger.info("Called deleteSlideshow with username=" + username + ", password=XXX, id=" + id);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
addParameter(parameters, "username", username);
|
||||
addParameter(parameters, "password", password);
|
||||
addParameter(parameters, "slideshow_id", id);
|
||||
return sendGetMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId();
|
||||
}
|
||||
|
||||
private Map<String, String> addParameter(Map<String, String> parameters, String name, String value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
parameters.put(name, value);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Map<String, String> addParameter(Map<String, String> parameters, String name, boolean value)
|
||||
{
|
||||
parameters.put(name, value ? "Y" : "N");
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Map<String, String> addLimits(Map<String, String> parameters, int offset, int limit)
|
||||
{
|
||||
if (offset >= 0)
|
||||
{
|
||||
parameters.put("offset", Integer.toString(offset));
|
||||
}
|
||||
if (limit >= 0)
|
||||
{
|
||||
parameters.put("limit", Integer.toString(limit));
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private DocumentParserResult sendMessage(String url, Map<String, String> parameters)
|
||||
throws SlideShareErrorException
|
||||
{
|
||||
addCredentials(parameters);
|
||||
DocumentParserResult result;
|
||||
try
|
||||
{
|
||||
InputStream response = connector.sendMessage(apiUrls.get(url), parameters);
|
||||
result = DocumentParser.parse(response);
|
||||
}
|
||||
catch (IOException iOException)
|
||||
{
|
||||
throw new SlideShareErrorException(-1, "Error sending a message to the url " + apiUrls.get(url), iOException);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DocumentParserResult sendGetMessage(String url, Map<String, String> parameters)
|
||||
throws SlideShareErrorException
|
||||
{
|
||||
addCredentials(parameters);
|
||||
DocumentParserResult result;
|
||||
try
|
||||
{
|
||||
InputStream response = connector.sendGetMessage(apiUrls.get(url), parameters);
|
||||
result = DocumentParser.parse(response);
|
||||
}
|
||||
catch (IOException iOException)
|
||||
{
|
||||
throw new SlideShareErrorException(-1, "Error sending a message to the url " + apiUrls.get(url), iOException);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DocumentParserResult sendMessage(String url, Map<String, String> parameters, Map<String, File> files)
|
||||
throws SlideShareErrorException
|
||||
{
|
||||
addCredentials(parameters);
|
||||
DocumentParserResult result;
|
||||
try
|
||||
{
|
||||
InputStream response = connector.sendMultiPartMessage(apiUrls.get(url), parameters, files);
|
||||
result = DocumentParser.parse(response);
|
||||
}
|
||||
catch (IOException iOException)
|
||||
{
|
||||
throw new SlideShareErrorException(-1, "Error sending a multipart message to the url " + apiUrls.get(url), iOException);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addCredentials(Map<String, String> parameters)
|
||||
{
|
||||
if (username != null && password != null)
|
||||
{
|
||||
addParameter(parameters, "username", username);
|
||||
addParameter(parameters, "password", password);
|
||||
}
|
||||
}
|
||||
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@@ -1,284 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
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.publishing.AbstractChannelType;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.benfante.jslideshare.SlideShareAPI;
|
||||
import com.benfante.jslideshare.messages.SlideshowInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SlideShareChannelType extends AbstractChannelType
|
||||
{
|
||||
public final static String ID = "slideshare";
|
||||
|
||||
private final static Log log = LogFactory.getLog(SlideShareChannelType.class);
|
||||
|
||||
private final static int STATUS_QUEUED = 0;
|
||||
// private final static int STATUS_CONVERTING = 1;
|
||||
private final static int STATUS_SUCCEEDED = 2;
|
||||
private final static int STATUS_FAILED = 3;
|
||||
private final static int STATUS_TIMED_OUT = 10;
|
||||
private static final String ERROR_SLIDESHARE_CONVERSION_FAILED = "publish.slideshare.conversionFailed";
|
||||
private static final String ERROR_SLIDESHARE_CONVERSION_TIMED_OUT = "publish.slideshare.conversionTimedOut";
|
||||
|
||||
private SlideSharePublishingHelper publishingHelper;
|
||||
private ContentService contentService;
|
||||
private TaggingService taggingService;
|
||||
|
||||
private long timeoutMilliseconds = 60L * 60L * 1000L; // 1 hour default
|
||||
|
||||
public void setPublishingHelper(SlideSharePublishingHelper publishingHelper)
|
||||
{
|
||||
this.publishingHelper = publishingHelper;
|
||||
}
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
public void setTimeoutMilliseconds(long timeoutMilliseconds)
|
||||
{
|
||||
this.timeoutMilliseconds = timeoutMilliseconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return SlideSharePublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedMimeTypes()
|
||||
{
|
||||
return publishingHelper.getAllowedMimeTypes().keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
Pair<String, String> usernamePassword = publishingHelper
|
||||
.getSlideShareCredentialsFromChannelProperties(properties);
|
||||
if (usernamePassword == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("publish.failed.no_credentials_found");
|
||||
}
|
||||
SlideShareAPI api = publishingHelper
|
||||
.getSlideShareApi(usernamePassword.getFirst(), usernamePassword.getSecond());
|
||||
|
||||
ContentReader reader = contentService.getReader(nodeToPublish, ContentModel.PROP_CONTENT);
|
||||
if (reader.exists())
|
||||
{
|
||||
File contentFile;
|
||||
String mime = reader.getMimetype();
|
||||
|
||||
String extension = publishingHelper.getAllowedMimeTypes().get(mime);
|
||||
if (extension == null)
|
||||
extension = "";
|
||||
|
||||
boolean deleteContentFileOnCompletion = false;
|
||||
|
||||
// SlideShare seems to work entirely off file extension, so we
|
||||
// always copy onto the
|
||||
// file system and upload from there.
|
||||
File tempDir = TempFileProvider.getLongLifeTempDir("slideshare");
|
||||
contentFile = TempFileProvider.createTempFile("slideshare", extension, tempDir);
|
||||
reader.getContent(contentFile);
|
||||
deleteContentFileOnCompletion = true;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
String name = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_NAME);
|
||||
String title = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
title = name;
|
||||
}
|
||||
String description = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_DESCRIPTION);
|
||||
if (description == null || description.length() == 0)
|
||||
{
|
||||
description = title;
|
||||
}
|
||||
|
||||
List<String> tagList = taggingService.getTags(nodeToPublish);
|
||||
StringBuilder tags = new StringBuilder();
|
||||
for (String tag : tagList)
|
||||
{
|
||||
tags.append(tag);
|
||||
tags.append(' ');
|
||||
}
|
||||
|
||||
String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title,
|
||||
contentFile, description, tags.toString(), false, false, false, false, false);
|
||||
|
||||
String url = null;
|
||||
int status = STATUS_QUEUED;
|
||||
boolean finished = false;
|
||||
long timeoutTime = System.currentTimeMillis() + timeoutMilliseconds;
|
||||
// Fetch the slideshow info every 30 seconds until we timeout
|
||||
while (!finished)
|
||||
{
|
||||
SlideshowInfo slideInfo = api.getSlideshowInfo(assetId, "");
|
||||
if (slideInfo != null)
|
||||
{
|
||||
if (url == null)
|
||||
{
|
||||
url = slideInfo.getUrl();
|
||||
if (log.isInfoEnabled())
|
||||
{
|
||||
log.info("SlideShare has provided a URL for asset " + assetId + ": " + url);
|
||||
}
|
||||
}
|
||||
status = slideInfo.getStatus();
|
||||
}
|
||||
finished = (status == STATUS_FAILED || status == STATUS_SUCCEEDED);
|
||||
|
||||
if (!finished)
|
||||
{
|
||||
if (System.currentTimeMillis() < timeoutTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(30000L);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = STATUS_TIMED_OUT;
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status == STATUS_SUCCEEDED)
|
||||
{
|
||||
if (log.isInfoEnabled())
|
||||
{
|
||||
log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL "
|
||||
+ url);
|
||||
}
|
||||
nodeService.addAspect(nodeToPublish, SlideSharePublishingModel.ASPECT_ASSET, null);
|
||||
nodeService.setProperty(nodeToPublish, PublishingModel.PROP_ASSET_ID, assetId);
|
||||
nodeService.setProperty(nodeToPublish, PublishingModel.PROP_ASSET_URL, url);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException(status == STATUS_FAILED ? ERROR_SLIDESHARE_CONVERSION_FAILED
|
||||
: ERROR_SLIDESHARE_CONVERSION_TIMED_OUT);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (deleteContentFileOnCompletion)
|
||||
{
|
||||
contentFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
if (nodeService.hasAspect(nodeToUnpublish, SlideSharePublishingModel.ASPECT_ASSET))
|
||||
{
|
||||
String assetId = (String) nodeService.getProperty(nodeToUnpublish, PublishingModel.PROP_ASSET_ID);
|
||||
if (assetId != null)
|
||||
{
|
||||
Pair<String, String> usernamePassword = publishingHelper
|
||||
.getSlideShareCredentialsFromChannelProperties(properties);
|
||||
if (usernamePassword == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("publish.failed.no_credentials_found");
|
||||
}
|
||||
SlideShareApi api = publishingHelper.getSlideShareApi(usernamePassword.getFirst(), usernamePassword
|
||||
.getSecond());
|
||||
|
||||
api.deleteSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), assetId);
|
||||
nodeService.removeAspect(nodeToUnpublish, SlideSharePublishingModel.ASPECT_ASSET);
|
||||
nodeService.removeAspect(nodeToUnpublish, PublishingModel.ASPECT_ASSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,236 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||
import org.apache.commons.httpclient.methods.multipart.StringPart;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.benfante.jslideshare.SlideShareConnector;
|
||||
import com.benfante.jslideshare.SlideShareErrorException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SlideShareConnectorImpl implements SlideShareConnector
|
||||
{
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SlideShareConnectorImpl.class);
|
||||
|
||||
private String apiKey;
|
||||
private String sharedSecret;
|
||||
private HttpClient httpClient;
|
||||
|
||||
public SlideShareConnectorImpl()
|
||||
{
|
||||
httpClient = new HttpClient();
|
||||
httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
|
||||
}
|
||||
|
||||
public SlideShareConnectorImpl(String apiKey, String sharedSecret)
|
||||
{
|
||||
this();
|
||||
this.apiKey = apiKey;
|
||||
this.sharedSecret = sharedSecret;
|
||||
}
|
||||
|
||||
public String getApiKey()
|
||||
{
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey)
|
||||
{
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getSharedSecret()
|
||||
{
|
||||
return sharedSecret;
|
||||
}
|
||||
|
||||
public void setSharedSecret(String sharedSecret)
|
||||
{
|
||||
this.sharedSecret = sharedSecret;
|
||||
}
|
||||
|
||||
|
||||
public InputStream sendMessage(String url, Map<String, String> parameters) throws IOException,
|
||||
SlideShareErrorException
|
||||
{
|
||||
PostMethod method = new PostMethod(url);
|
||||
method.addParameter("api_key", this.apiKey);
|
||||
Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator();
|
||||
while (entryIt.hasNext())
|
||||
{
|
||||
Map.Entry<String, String> entry = entryIt.next();
|
||||
method.addParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
Date now = new Date();
|
||||
String ts = Long.toString(now.getTime() / 1000);
|
||||
String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase();
|
||||
method.addParameter("ts", ts);
|
||||
method.addParameter("hash", hash);
|
||||
logger.debug("Sending POST message to " + method.getURI().getURI() + " with parameters "
|
||||
+ Arrays.toString(method.getParameters()));
|
||||
int statusCode = httpClient.executeMethod(method);
|
||||
if (statusCode != HttpStatus.SC_OK)
|
||||
{
|
||||
logger.debug("Server replied with a " + statusCode + " HTTP status code ("
|
||||
+ HttpStatus.getStatusText(statusCode) + ")");
|
||||
throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode));
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(method.getResponseBodyAsString());
|
||||
}
|
||||
InputStream result = new ByteArrayInputStream(method.getResponseBody());
|
||||
method.releaseConnection();
|
||||
return result;
|
||||
}
|
||||
|
||||
public InputStream sendMultiPartMessage(String url, Map<String, String> parameters, Map<String, File> files)
|
||||
throws IOException, SlideShareErrorException
|
||||
{
|
||||
PostMethod method = new PostMethod(url);
|
||||
List<Part> partList = new ArrayList<Part>();
|
||||
partList.add(createStringPart("api_key", this.apiKey));
|
||||
Date now = new Date();
|
||||
String ts = Long.toString(now.getTime() / 1000);
|
||||
String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase();
|
||||
partList.add(createStringPart("ts", ts));
|
||||
partList.add(createStringPart("hash", hash));
|
||||
Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator();
|
||||
while (entryIt.hasNext())
|
||||
{
|
||||
Map.Entry<String, String> entry = entryIt.next();
|
||||
partList.add(createStringPart(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
Iterator<Map.Entry<String, File>> entryFileIt = files.entrySet().iterator();
|
||||
while (entryFileIt.hasNext())
|
||||
{
|
||||
Map.Entry<String, File> entry = entryFileIt.next();
|
||||
partList.add(createFilePart(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
MultipartRequestEntity requestEntity = new MultipartRequestEntity(partList.toArray(new Part[partList.size()]),
|
||||
method.getParams());
|
||||
method.setRequestEntity(requestEntity);
|
||||
logger.debug("Sending multipart POST message to " + method.getURI().getURI() + " with parts " + partList);
|
||||
int statusCode = httpClient.executeMethod(method);
|
||||
if (statusCode != HttpStatus.SC_OK)
|
||||
{
|
||||
logger.debug("Server replied with a " + statusCode + " HTTP status code ("
|
||||
+ HttpStatus.getStatusText(statusCode) + ")");
|
||||
throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode));
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(method.getResponseBodyAsString());
|
||||
}
|
||||
InputStream result = new ByteArrayInputStream(method.getResponseBody());
|
||||
method.releaseConnection();
|
||||
return result;
|
||||
}
|
||||
|
||||
public InputStream sendGetMessage(String url, Map<String, String> parameters) throws IOException,
|
||||
SlideShareErrorException
|
||||
{
|
||||
GetMethod method = new GetMethod(url);
|
||||
NameValuePair[] params = new NameValuePair[parameters.size() + 3];
|
||||
int i = 0;
|
||||
params[i++] = new NameValuePair("api_key", this.apiKey);
|
||||
Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator();
|
||||
while (entryIt.hasNext())
|
||||
{
|
||||
Map.Entry<String, String> entry = entryIt.next();
|
||||
params[i++] = new NameValuePair(entry.getKey(), entry.getValue());
|
||||
}
|
||||
Date now = new Date();
|
||||
String ts = Long.toString(now.getTime() / 1000);
|
||||
String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase();
|
||||
params[i++] = new NameValuePair("ts", ts);
|
||||
params[i++] = new NameValuePair("hash", hash);
|
||||
method.setQueryString(params);
|
||||
logger.debug("Sending GET message to " + method.getURI().getURI() + " with parameters "
|
||||
+ Arrays.toString(params));
|
||||
int statusCode = httpClient.executeMethod(method);
|
||||
if (statusCode != HttpStatus.SC_OK)
|
||||
{
|
||||
logger.debug("Server replied with a " + statusCode + " HTTP status code ("
|
||||
+ HttpStatus.getStatusText(statusCode) + ")");
|
||||
throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode));
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(method.getResponseBodyAsString());
|
||||
}
|
||||
InputStream result = new ByteArrayInputStream(method.getResponseBody());
|
||||
method.releaseConnection();
|
||||
return result;
|
||||
}
|
||||
|
||||
private StringPart createStringPart(String name, String value)
|
||||
{
|
||||
StringPart stringPart = new StringPart(name, value);
|
||||
stringPart.setContentType(null);
|
||||
stringPart.setTransferEncoding(null);
|
||||
stringPart.setCharSet("UTF-8");
|
||||
return stringPart;
|
||||
}
|
||||
|
||||
private FilePart createFilePart(String name, File value) throws FileNotFoundException
|
||||
{
|
||||
FilePart filePart = new FilePart(name, value);
|
||||
filePart.setTransferEncoding(null);
|
||||
filePart.setCharSet(null);
|
||||
return filePart;
|
||||
}
|
||||
|
||||
}
|
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.node.encryption.MetadataEncryptor;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
import com.benfante.jslideshare.SlideShareAPI;
|
||||
import com.benfante.jslideshare.SlideShareConnector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SlideSharePublishingHelper
|
||||
{
|
||||
private final static Map<String,String> DEFAULT_MIME_TYPES = new TreeMap<String,String>();
|
||||
static
|
||||
{
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_PPT, ".ppt");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_PDF, ".pdf");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION, ".odp");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_OPENXML_PRESENTATION, ".pptx");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_IWORK_KEYNOTE, "");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_IWORK_PAGES, "");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_TEXT_PLAIN, ".txt");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT, ".odt");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_TEXT_CSV, ".csv");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_EXCEL, ".xls");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING, ".docx");
|
||||
DEFAULT_MIME_TYPES.put(MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET, ".ods");
|
||||
}
|
||||
|
||||
private Map<String, String> allowedMimeTypes = Collections.unmodifiableMap(DEFAULT_MIME_TYPES);
|
||||
private SlideShareConnector slideshareConnector;
|
||||
private MetadataEncryptor encryptor;
|
||||
|
||||
public void setSlideshareConnector(SlideShareConnector slideshareConnector)
|
||||
{
|
||||
this.slideshareConnector = slideshareConnector;
|
||||
}
|
||||
|
||||
public Map<String, String> getAllowedMimeTypes()
|
||||
{
|
||||
return allowedMimeTypes;
|
||||
}
|
||||
|
||||
public void setAllowedMimeTypes(Map<String, String> allowedMimeTypes)
|
||||
{
|
||||
this.allowedMimeTypes = Collections.unmodifiableMap(allowedMimeTypes);
|
||||
}
|
||||
|
||||
public void setEncryptor(MetadataEncryptor encryptor)
|
||||
{
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
public SlideShareAPI getSlideShareApi()
|
||||
{
|
||||
return createApiObject();
|
||||
}
|
||||
|
||||
private SlideShareApiImpl createApiObject()
|
||||
{
|
||||
return new SlideShareApiImpl(slideshareConnector);
|
||||
}
|
||||
|
||||
public Pair<String, String> getSlideShareCredentialsFromChannelProperties(Map<QName, Serializable> channelProperties)
|
||||
{
|
||||
Pair<String, String> result = null;
|
||||
String username = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME,
|
||||
channelProperties.get(PublishingModel.PROP_CHANNEL_USERNAME));
|
||||
String password = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD,
|
||||
channelProperties.get(PublishingModel.PROP_CHANNEL_PASSWORD));
|
||||
if (username != null && password != null)
|
||||
{
|
||||
result = new Pair<String, String>(username, password);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public SlideShareApi getSlideShareApi(String username, String password)
|
||||
{
|
||||
SlideShareApiImpl api = createApiObject();
|
||||
api.setUsername(username);
|
||||
api.setPassword(password);
|
||||
return api;
|
||||
}
|
||||
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface SlideSharePublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/slideshare/1.0";
|
||||
public static final String PREFIX = "slideshare";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
}
|
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.twitter;
|
||||
|
||||
import org.alfresco.repo.publishing.AbstractOAuth1ChannelType;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.twitter.api.Twitter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class TwitterChannelType extends AbstractOAuth1ChannelType<Twitter>
|
||||
{
|
||||
private final static Log log = LogFactory.getLog(TwitterChannelType.class);
|
||||
public final static String ID = "twitter";
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return TwitterPublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumStatusLength()
|
||||
{
|
||||
return 140;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusUpdate(Channel channel, String status)
|
||||
{
|
||||
Connection<Twitter> connection = getConnectionForChannel(channel.getNodeRef());
|
||||
if (log.isInfoEnabled())
|
||||
{
|
||||
log.info("Posting update to Twitter channel " + channel.getName() + ": " + status);
|
||||
}
|
||||
connection.getApi().timelineOperations().updateStatus(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.twitter;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface TwitterPublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/twitter/1.0";
|
||||
public static final String PREFIX = "twitter";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
}
|
@@ -1,335 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.youtube;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.filestore.FileContentReader;
|
||||
import org.alfresco.repo.publishing.AbstractChannelType;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.google.gdata.client.media.ResumableGDataFileUploader;
|
||||
import com.google.gdata.client.uploader.ProgressListener;
|
||||
import com.google.gdata.client.uploader.ResumableHttpFileUploader;
|
||||
import com.google.gdata.client.youtube.YouTubeService;
|
||||
import com.google.gdata.data.media.MediaFileSource;
|
||||
import com.google.gdata.data.media.mediarss.MediaCategory;
|
||||
import com.google.gdata.data.media.mediarss.MediaDescription;
|
||||
import com.google.gdata.data.media.mediarss.MediaKeywords;
|
||||
import com.google.gdata.data.media.mediarss.MediaTitle;
|
||||
import com.google.gdata.data.youtube.VideoEntry;
|
||||
import com.google.gdata.data.youtube.YouTubeMediaGroup;
|
||||
import com.google.gdata.data.youtube.YouTubeNamespace;
|
||||
import com.google.gdata.util.ServiceException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class YouTubeChannelType extends AbstractChannelType
|
||||
{
|
||||
private final static Log log = LogFactory.getLog(YouTubeChannelType.class);
|
||||
private final static Set<String> DEFAULT_SUPPORTED_MIME_TYPES = CollectionUtils.unmodifiableSet(
|
||||
MimetypeMap.MIMETYPE_VIDEO_MPG, MimetypeMap.MIMETYPE_VIDEO_MP4, MimetypeMap.MIMETYPE_VIDEO_FLV,
|
||||
MimetypeMap.MIMETYPE_VIDEO_3GP, MimetypeMap.MIMETYPE_VIDEO_AVI, MimetypeMap.MIMETYPE_VIDEO_QUICKTIME,
|
||||
MimetypeMap.MIMETYPE_VIDEO_WMV);
|
||||
|
||||
public static final String RESUMABLE_UPLOAD_URL = "http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads";
|
||||
|
||||
/** Time interval at which upload task will notify about the progress */
|
||||
private static final int PROGRESS_UPDATE_INTERVAL = 1000;
|
||||
|
||||
/** Max size for each upload chunk */
|
||||
private static final int DEFAULT_CHUNK_SIZE = 10000000;
|
||||
|
||||
private Set<String> supportedMimeTypes = DEFAULT_SUPPORTED_MIME_TYPES;
|
||||
|
||||
public final static String ID = "youtube";
|
||||
private YouTubePublishingHelper youTubeHelper;
|
||||
private ContentService contentService;
|
||||
private TaggingService taggingService;
|
||||
|
||||
public void setYouTubeHelper(YouTubePublishingHelper youTubeHelper)
|
||||
{
|
||||
this.youTubeHelper = youTubeHelper;
|
||||
}
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
public void setSupportedMimeTypes(Set<String> supportedMimeTypes)
|
||||
{
|
||||
this.supportedMimeTypes = Collections.unmodifiableSet(new TreeSet<String>(supportedMimeTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return YouTubePublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedMimeTypes()
|
||||
{
|
||||
return supportedMimeTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
YouTubeService service = youTubeHelper.getYouTubeServiceFromChannelProperties(properties);
|
||||
if (service != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
uploadVideo(service, nodeToPublish);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.error("Failed to send asset to YouTube", ex);
|
||||
throw new AlfrescoRuntimeException("exception.publishing.youtube.publishFailed", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
YouTubeService service = youTubeHelper.getYouTubeServiceFromChannelProperties(properties);
|
||||
if (service != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
removeVideo(service, nodeToUnpublish);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.error("Failed to remove asset from YouTube", ex);
|
||||
throw new AlfrescoRuntimeException("exception.publishing.youtube.unpublishFailed", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeVideo(YouTubeService service, NodeRef nodeRef) throws MalformedURLException, IOException,
|
||||
ServiceException
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
if (nodeService.hasAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET))
|
||||
{
|
||||
String youtubeId = (String) nodeService.getProperty(nodeRef, PublishingModel.PROP_ASSET_ID);
|
||||
if (youtubeId != null)
|
||||
{
|
||||
String videoEntryUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads/" + youtubeId;
|
||||
VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class);
|
||||
videoEntry.delete();
|
||||
nodeService.removeAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET);
|
||||
nodeService.removeAspect(nodeRef, PublishingModel.ASPECT_ASSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadVideo(YouTubeService service, NodeRef nodeRef) throws IOException, ServiceException,
|
||||
InterruptedException
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
|
||||
if (reader.exists())
|
||||
{
|
||||
File contentFile;
|
||||
boolean deleteContentFileOnCompletion = false;
|
||||
if (FileContentReader.class.isAssignableFrom(reader.getClass()))
|
||||
{
|
||||
// Grab the content straight from the content store if we can...
|
||||
contentFile = ((FileContentReader) reader).getFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
// ...otherwise copy it to a temp file and use the copy...
|
||||
File tempDir = TempFileProvider.getLongLifeTempDir("youtube");
|
||||
contentFile = TempFileProvider.createTempFile("youtube", "", tempDir);
|
||||
reader.getContent(contentFile);
|
||||
deleteContentFileOnCompletion = true;
|
||||
}
|
||||
MediaFileSource ms = new MediaFileSource(contentFile, reader.getMimetype());
|
||||
|
||||
String videoName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||
String videoTitle = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
|
||||
if (videoTitle == null || videoTitle.length() == 0)
|
||||
{
|
||||
videoTitle = videoName;
|
||||
}
|
||||
String videoDescription = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
|
||||
if (videoDescription == null || videoDescription.length() == 0)
|
||||
{
|
||||
videoDescription = videoTitle;
|
||||
}
|
||||
|
||||
VideoEntry newEntry = new VideoEntry();
|
||||
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
|
||||
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Tech"));
|
||||
mg.setTitle(new MediaTitle());
|
||||
mg.getTitle().setPlainTextContent(videoTitle);
|
||||
mg.setKeywords(new MediaKeywords());
|
||||
List<String> tags = taggingService.getTags(nodeRef);
|
||||
for (String tag : tags)
|
||||
{
|
||||
mg.getKeywords().addKeyword(tag);
|
||||
}
|
||||
mg.setDescription(new MediaDescription());
|
||||
mg.getDescription().setPlainTextContent(videoDescription);
|
||||
|
||||
FileUploadProgressListener listener = new FileUploadProgressListener(videoName);
|
||||
ResumableGDataFileUploader uploader = new ResumableGDataFileUploader.Builder(service, new URL(
|
||||
RESUMABLE_UPLOAD_URL), ms, newEntry).title(videoTitle).trackProgress(listener,
|
||||
PROGRESS_UPDATE_INTERVAL).chunkSize(DEFAULT_CHUNK_SIZE).build();
|
||||
|
||||
uploader.start();
|
||||
while (!uploader.isDone())
|
||||
{
|
||||
Thread.sleep(PROGRESS_UPDATE_INTERVAL);
|
||||
}
|
||||
|
||||
switch (uploader.getUploadState())
|
||||
{
|
||||
case COMPLETE:
|
||||
VideoEntry entry = uploader.getResponse(VideoEntry.class);
|
||||
String videoId = entry.getMediaGroup().getVideoId();
|
||||
String contentUrl = entry.getMediaGroup().getContents().get(0).getUrl();
|
||||
String playerUrl = entry.getMediaGroup().getPlayer().getUrl();
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Video content uploaded successfully: " + videoName);
|
||||
log.debug("YouTube video id is " + videoId);
|
||||
log.debug("YouTube content URL is " + contentUrl);
|
||||
log.debug("YouTube video player URL is " + playerUrl);
|
||||
}
|
||||
nodeService.addAspect(nodeRef, YouTubePublishingModel.ASPECT_ASSET, null);
|
||||
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_ID, videoId);
|
||||
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_URL, playerUrl);
|
||||
break;
|
||||
case CLIENT_ERROR:
|
||||
log.error("Video content failed to upload: " + videoName);
|
||||
break;
|
||||
default:
|
||||
log.warn("Unknown upload state. Video content may not have uploaded: " + videoName + "("
|
||||
+ uploader.getUploadState() + ") :" + nodeRef);
|
||||
break;
|
||||
}
|
||||
|
||||
if (deleteContentFileOnCompletion)
|
||||
{
|
||||
contentFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link ProgressListener} implementation to track upload progress. The
|
||||
* listener can track multiple uploads at the same time.
|
||||
*/
|
||||
private class FileUploadProgressListener implements ProgressListener
|
||||
{
|
||||
String videoName;
|
||||
|
||||
public FileUploadProgressListener(String videoName)
|
||||
{
|
||||
this.videoName = videoName;
|
||||
}
|
||||
|
||||
public synchronized void progressChanged(ResumableHttpFileUploader uploader)
|
||||
{
|
||||
switch (uploader.getUploadState())
|
||||
{
|
||||
case COMPLETE:
|
||||
log.info("Upload Completed: " + videoName);
|
||||
break;
|
||||
case CLIENT_ERROR:
|
||||
log.error("Upload Failed: " + videoName);
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
log.info(videoName + String.format(" %3.0f", uploader.getProgress() * 100) + "%");
|
||||
break;
|
||||
case NOT_STARTED:
|
||||
log.info("Upload Not Started: " + videoName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.publishing.youtube;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.node.encryption.MetadataEncryptor;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.google.gdata.client.youtube.YouTubeService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class YouTubePublishingHelper
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(YouTubePublishingHelper.class);
|
||||
private MetadataEncryptor encryptor;
|
||||
|
||||
public void setEncryptor(MetadataEncryptor encryptor)
|
||||
{
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
public YouTubeService getYouTubeServiceFromChannelProperties(Map<QName, Serializable> channelProperties)
|
||||
{
|
||||
YouTubeService service = null;
|
||||
if (channelProperties != null)
|
||||
{
|
||||
String youtubeUsername = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME,
|
||||
channelProperties.get(PublishingModel.PROP_CHANNEL_USERNAME));
|
||||
String youtubePassword = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD,
|
||||
channelProperties.get(PublishingModel.PROP_CHANNEL_PASSWORD));
|
||||
service = new YouTubeService("Alfresco",
|
||||
"AI39si78RHlniONCtnu9o8eBfwZToBAp2ZbbURm5eoJjj4gZi0LcxjDqJTzD35oYokmtFXbCo5ojofbimGnMlRbmNrh7-M7ZCw");
|
||||
try
|
||||
{
|
||||
service.setUserCredentials(youtubeUsername, youtubePassword);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
service = null;
|
||||
log.error("Failed to connect to YouTube", e);
|
||||
}
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.youtube;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface YouTubePublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/youtube/1.0";
|
||||
public static final String PREFIX = "youtube";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class BaseNodePublishStatus implements NodePublishStatus
|
||||
{
|
||||
private final NodeRef nodeRef;
|
||||
private final String channelId;
|
||||
|
||||
public BaseNodePublishStatus(NodeRef nodeRef, String channelName)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.channelId = channelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getChannelId()
|
||||
{
|
||||
return channelId;
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* An extension of the {@link PublishingEvent} interface that allows some changes to be made.
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface MutablePublishingEvent extends PublishingEvent
|
||||
{
|
||||
void setScheduledTime(Calendar time);
|
||||
void setComment(String comment);
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface NodePublishStatus
|
||||
{
|
||||
enum Status {NOT_PUBLISHED, ON_QUEUE, PUBLISHED, PUBLISHED_AND_ON_QUEUE}
|
||||
|
||||
<T> T visit(NodePublishStatusVisitor<T> visitor);
|
||||
|
||||
NodeRef getNodeRef();
|
||||
|
||||
Status getStatus();
|
||||
|
||||
String getChannelId();
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodePublishStatusNotPublished extends BaseNodePublishStatus
|
||||
{
|
||||
/**
|
||||
* @param node NodeRef
|
||||
* @param channelName TODO
|
||||
*/
|
||||
public NodePublishStatusNotPublished(NodeRef node, String channelName)
|
||||
{
|
||||
super(node, channelName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public <T> T visit(NodePublishStatusVisitor<T> visitor)
|
||||
{
|
||||
return visitor.accept(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Status getStatus()
|
||||
{
|
||||
return Status.NOT_PUBLISHED;
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodePublishStatusOnQueue extends BaseNodePublishStatus
|
||||
{
|
||||
private final PublishingEvent queuedEvent;
|
||||
|
||||
public NodePublishStatusOnQueue(NodeRef nodeRef, String channelName, PublishingEvent queuedEvent)
|
||||
{
|
||||
super(nodeRef, channelName);
|
||||
this.queuedEvent =queuedEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public <T> T visit(NodePublishStatusVisitor<T> visitor)
|
||||
{
|
||||
return visitor.accept(this);
|
||||
}
|
||||
|
||||
public PublishingEvent getQueuedPublishingEvent()
|
||||
{
|
||||
return queuedEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Status getStatus()
|
||||
{
|
||||
return Status.ON_QUEUE;
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodePublishStatusPublished extends BaseNodePublishStatus
|
||||
{
|
||||
|
||||
private final PublishingEvent lastEvent;
|
||||
|
||||
public NodePublishStatusPublished(NodeRef node, String channelId, PublishingEvent lastEvent)
|
||||
{
|
||||
super(node, channelId);
|
||||
this.lastEvent = lastEvent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.publishing.NodePublishStatus#visit(org.alfresco.service.cmr.publishing.NodePublishStatusVisitor)
|
||||
*/
|
||||
@Override
|
||||
public <T> T visit(NodePublishStatusVisitor<T> visitor)
|
||||
{
|
||||
return visitor.accept(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the most recent publishing event that affected (created or updated) the node relevant to this status.
|
||||
* @return PublishingEvent
|
||||
*/
|
||||
public PublishingEvent getLatestPublishingEvent()
|
||||
{
|
||||
return lastEvent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.publishing.NodePublishStatus#getStatus()
|
||||
*/
|
||||
@Override
|
||||
public Status getStatus()
|
||||
{
|
||||
return Status.PUBLISHED;
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NodePublishStatusPublishedAndOnQueue extends BaseNodePublishStatus
|
||||
{
|
||||
|
||||
private final PublishingEvent queuedPublishingEvent;
|
||||
private final PublishingEvent latestPublishingEvent;
|
||||
|
||||
/**
|
||||
* @param nodeRef NodeRef
|
||||
* @param channelName TODO
|
||||
* @param queuedPublishingEvent The next scheduled {@link PublishingEvent} on the {@link PublishingQueue}
|
||||
* @param latestPublishingEvent The last {@link PublishingEvent} to successfully publish the node.
|
||||
*/
|
||||
public NodePublishStatusPublishedAndOnQueue(NodeRef nodeRef, String channelName,
|
||||
PublishingEvent queuedPublishingEvent, PublishingEvent latestPublishingEvent)
|
||||
{
|
||||
super(nodeRef, channelName);
|
||||
this.queuedPublishingEvent = queuedPublishingEvent;
|
||||
this.latestPublishingEvent = latestPublishingEvent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.publishing.NodePublishStatus#visit(org.alfresco.service.cmr.publishing.NodePublishStatusVisitor)
|
||||
*/
|
||||
@Override
|
||||
public <T> T visit(NodePublishStatusVisitor<T> visitor)
|
||||
{
|
||||
return visitor.accept(this);
|
||||
}
|
||||
|
||||
public PublishingEvent getQueuedPublishingEvent()
|
||||
{
|
||||
return queuedPublishingEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the most recent publishing event that affected (created or updated) the node relevant to this status.
|
||||
* @return PublishingEvent
|
||||
*/
|
||||
public PublishingEvent getLatestPublishingEvent()
|
||||
{
|
||||
return latestPublishingEvent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.publishing.NodePublishStatus#getStatus()
|
||||
*/
|
||||
@Override
|
||||
public Status getStatus()
|
||||
{
|
||||
return Status.PUBLISHED_AND_ON_QUEUE;
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
/**
|
||||
* An interface that enables the use of the Visitor pattern on {@link NodePublishStatus} objects.
|
||||
*
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface NodePublishStatusVisitor<T>
|
||||
{
|
||||
T accept(NodePublishStatusNotPublished status);
|
||||
T accept(NodePublishStatusOnQueue status);
|
||||
T accept(NodePublishStatusPublished status);
|
||||
T accept(NodePublishStatusPublishedAndOnQueue status);
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface NodeSnapshot
|
||||
{
|
||||
/**
|
||||
* Retrieve the identifier of the node of which this is a snapshot
|
||||
* @return The NodeRef object that identifies the node
|
||||
*/
|
||||
NodeRef getNodeRef();
|
||||
|
||||
/**
|
||||
* The property values assigned to the node at the moment the snapshot was taken.
|
||||
* @return A map that associates property names to property values for the node.
|
||||
*/
|
||||
Map<QName, Serializable> getProperties();
|
||||
|
||||
/**
|
||||
* Retrieve the type of the node at the moment the snapshot was taken.
|
||||
* @return The QName that identifies the type of the node
|
||||
*/
|
||||
QName getType();
|
||||
|
||||
/**
|
||||
* Retrieve all the aspects that were applied to the node at the moment the snapshot was taken
|
||||
* @return A set of QName objects, each identifying an aspect that is applied to the node
|
||||
*/
|
||||
Set<QName> getAspects();
|
||||
|
||||
/**
|
||||
* @return the version of the node when the snapshot was taken.
|
||||
*/
|
||||
String getVersion();
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* A simple DTO used to gather parameters for scheduling a Publishing Event.
|
||||
*
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingDetails
|
||||
{
|
||||
PublishingDetails addNodesToUnpublish(NodeRef... nodesToRemove);
|
||||
|
||||
PublishingDetails addNodesToUnpublish(Collection<NodeRef> nodesToRemove);
|
||||
|
||||
PublishingDetails addNodesToPublish(NodeRef... nodesToPublish);
|
||||
|
||||
PublishingDetails addNodesToPublish(Collection<NodeRef> nodesToPublish);
|
||||
|
||||
PublishingDetails setPublishChannelId(String channelId);
|
||||
|
||||
PublishingDetails setComment(String comment);
|
||||
|
||||
PublishingDetails setSchedule(Calendar schedule);
|
||||
|
||||
PublishingDetails setStatusMessage(String message);
|
||||
|
||||
PublishingDetails setStatusNodeToLinkTo(NodeRef nodeToLinkTo);
|
||||
|
||||
PublishingDetails addStatusUpdateChannels(Collection<String> channelIds);
|
||||
PublishingDetails addStatusUpdateChannels(String... channelIds);
|
||||
|
||||
/**
|
||||
* @return the comment
|
||||
*/
|
||||
String getComment();
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
String getStatusMessage();
|
||||
|
||||
/**
|
||||
* @return the nodeToLinkTo
|
||||
*/
|
||||
NodeRef getNodeToLinkTo();
|
||||
|
||||
/**
|
||||
* @return the publishChannelId
|
||||
*/
|
||||
String getPublishChannelId();
|
||||
|
||||
/**
|
||||
* @return the schedule
|
||||
*/
|
||||
Calendar getSchedule();
|
||||
|
||||
Set<String> getStatusUpdateChannels();
|
||||
|
||||
/**
|
||||
* @return a {@link Set} of all the {@link NodeRef}s to be published.
|
||||
*/
|
||||
Set<NodeRef> getNodesToPublish();
|
||||
|
||||
/**
|
||||
* @return a {@link Set} of all the {@link NodeRef}s to be unpublished.
|
||||
*/
|
||||
Set<NodeRef> getNodesToUnpublish();
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingEvent extends Comparable<PublishingEvent>
|
||||
{
|
||||
/**
|
||||
* @return a unique {@link String} identifier for this {@link PublishingEvent}
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* @return the current {@link Status} of this {@link PublishingEvent}.
|
||||
*/
|
||||
Status getStatus();
|
||||
|
||||
/**
|
||||
* @return the date and time when this {@link PublishingEvent} is scheduled to publish its content.
|
||||
*/
|
||||
Calendar getScheduledTime();
|
||||
|
||||
/**
|
||||
* @return the {@link PublishingPackage} containing all the {@link NodeRef}s to be published and unpublished.
|
||||
*/
|
||||
PublishingPackage getPackage();
|
||||
|
||||
/**
|
||||
* @return the date and time when this {@link PublishingEvent} was created.
|
||||
*/
|
||||
Date getCreatedTime();
|
||||
|
||||
/**
|
||||
* @return the name of the user who created this {@link PublishingEvent}.
|
||||
*/
|
||||
String getCreator();
|
||||
|
||||
/**
|
||||
* @return the date and time when this {@link PublishingEvent} was last modified.
|
||||
*/
|
||||
Date getModifiedTime();
|
||||
|
||||
/**
|
||||
* @return the name of the user who last modified this {@link PublishingEvent}.
|
||||
*/
|
||||
String getModifier();
|
||||
|
||||
/**
|
||||
* @return the comment associatied with this {@link PublishingEvent}.
|
||||
*/
|
||||
String getComment();
|
||||
|
||||
/**
|
||||
* @return a unique identifier indicating which {@link Channel} this {@link PublishingEvent} publishes to.
|
||||
*/
|
||||
String getChannelId();
|
||||
|
||||
/**
|
||||
* @return the {@link StatusUpdate} information, if any.
|
||||
*/
|
||||
StatusUpdate getStatusUpdate();
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingEventFilter
|
||||
{
|
||||
PublishingEventFilter setIds(String... ids);
|
||||
|
||||
PublishingEventFilter setIds(Collection<String> ids);
|
||||
|
||||
Set<String> getIds();
|
||||
|
||||
PublishingEventFilter setPublishedNodes(NodeRef... publishedNodes);
|
||||
|
||||
PublishingEventFilter setPublishedNodes(Collection<NodeRef> publishedNodes);
|
||||
|
||||
Set<NodeRef> getPublishedNodes();
|
||||
|
||||
PublishingEventFilter setUnpublishedNodes(NodeRef... unpublishedNodes);
|
||||
|
||||
PublishingEventFilter setUnpublishedNodes(Collection<NodeRef> unpublishedNodes);
|
||||
|
||||
Set<NodeRef> getUnpublishedNodes();
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingPackage
|
||||
{
|
||||
/**
|
||||
* Retrieve the collection of publishing package entries contained by this publishing package.
|
||||
* @return The collection of publishing package entries. Never <code>null</code>.
|
||||
*/
|
||||
Collection<PublishingPackageEntry> getEntries();
|
||||
|
||||
/**
|
||||
* Returns a {@link Map} from the {@link NodeRef} to be published/unpublished to the corresponding {@link PublishingPackageEntry}.
|
||||
* @return the {@link Map} of Publishing Package Entries.
|
||||
*/
|
||||
Map<NodeRef,PublishingPackageEntry> getEntryMap();
|
||||
|
||||
/**
|
||||
* @return a {@link Set} of all the {@link NodeRef}s to be published.
|
||||
*/
|
||||
Set<NodeRef> getNodesToPublish();
|
||||
|
||||
/**
|
||||
* @return a {@link Set} of all the {@link NodeRef}s to be unpublished.
|
||||
*/
|
||||
Set<NodeRef> getNodesToUnpublish();
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingPackageEntry
|
||||
{
|
||||
/**
|
||||
* Retrieve the identifier of the node that this publishing package entry
|
||||
* relates to
|
||||
*
|
||||
* @return A NodeRef object that identifies the node that this publishing
|
||||
* package entry relates to
|
||||
*/
|
||||
NodeRef getNodeRef();
|
||||
|
||||
/**
|
||||
* Retrieve the snapshot of the node that is held as the payload of this
|
||||
* publishing package entry. The snapshot is taken when the containing
|
||||
* publishing package is placed on the publishing queue IF this is a
|
||||
* "publish" entry as opposed to an "unpublish" entry. No snapshot is taken
|
||||
* for an unpublish entry.
|
||||
*
|
||||
* @return The snapshot of the node that this publishing package entry
|
||||
* relates to if this is a "publish" entry (
|
||||
* <code>null</code> if this is an "unpublish" entry). The snapshot is taken when
|
||||
* the containing publishing package is placed on the publishing queue, so if this operation is called before that point
|
||||
* then it will return <code>null</code>.
|
||||
*/
|
||||
NodeSnapshot getSnapshot();
|
||||
|
||||
/**
|
||||
* Determine if this entry relates to a publish request or an unpublish
|
||||
* request
|
||||
*
|
||||
* @return <code>true</code> if this entry relates to a publish request and
|
||||
* <code>false</code> if it relates to an unpublish request
|
||||
*/
|
||||
boolean isPublish();
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.publishing;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PublishingQueue
|
||||
{
|
||||
/**
|
||||
* A factory method to create an empty publishing package that can be populated before being passed into
|
||||
* a call to the {@link PublishingQueue#scheduleNewEvent(PublishingDetails)} operation.
|
||||
* @return A publishing package that can be populated before being placed on the publishing queue.
|
||||
*/
|
||||
PublishingDetails createPublishingDetails();
|
||||
|
||||
/**
|
||||
* Adds the supplied publishing package onto the queue.
|
||||
* @param publishingDetails The publishing package that is to be enqueued
|
||||
* @return The identifier of the newly scheduled event
|
||||
*/
|
||||
String scheduleNewEvent(PublishingDetails publishingDetails);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user