REPO-1296 Remove publishing and channels APIs (#33)

This commit is contained in:
Alex Mukha
2018-01-15 11:22:35 +00:00
committed by GitHub
parent 5fd59504ea
commit 0d5b2781a3
55 changed files with 4 additions and 3613 deletions

View File

@@ -1,6 +1,6 @@
# Branch specific configuration file for localisation scripts
MESSAGE_SEARCH_PATH="src/main/resources/alfresco/messages/admin-console*.properties src/main/resources/alfresco/messages/custommodel-restapi-messages*.properties src/main/resources/alfresco/messages/rest-framework-messages*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-repoconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-tenantconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-workflowconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/support-tools/admin-nodebrowser.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/audit/entry*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post.delete*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.put*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/person/user-csv-upload.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.put*.properties"
MESSAGE_SEARCH_PATH="src/main/resources/alfresco/messages/admin-console*.properties src/main/resources/alfresco/messages/custommodel-restapi-messages*.properties src/main/resources/alfresco/messages/rest-framework-messages*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-repoconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-tenantconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-workflowconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/support-tools/admin-nodebrowser.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/audit/entry*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post.delete*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.put*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/person/user-csv-upload.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.put*.properties"
EXCLUDED_FILES="src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/audit/control.properties"

View File

@@ -1,114 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletResponse;
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.publishing.channels.ChannelType.AuthUrlPair;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Brian
* @since 4.0
*/
public class AuthCallbackWebScript extends DeclarativeWebScript
{
private final static Log log = LogFactory.getLog(AuthCallbackWebScript.class);
private ChannelService channelService;
private ChannelAuthHelper channelAuthHelper;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
public void setChannelAuthHelper(ChannelAuthHelper channelAuthHelper)
{
this.channelAuthHelper = channelAuthHelper;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
Map<String,String[]> params = new TreeMap<String, String[]>();
Map<String,String[]> headers = new TreeMap<String, String[]>();
for (String paramName : req.getParameterNames())
{
params.put(paramName, req.getParameterValues(paramName));
}
for (String header : req.getHeaderNames())
{
headers.put(header, req.getHeaderValues(header));
}
if (log.isDebugEnabled())
{
log.debug("templateVars = " + templateVars);
log.debug("params = " + params);
log.debug("headers = " + headers);
}
String channelNodeUuid = templateVars.get("node_id");
String channelNodeStoreProtocol = templateVars.get("store_protocol");
String channelNodeStoreId = templateVars.get("store_id");
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
ChannelType.AuthStatus authStatus = channel.getChannelType().acceptAuthorisationCallback(channel, headers, params);
if (ChannelType.AuthStatus.RETRY.equals(authStatus))
{
AuthUrlPair authoriseUrls = channel.getChannelType().getAuthorisationUrls(channel, channelAuthHelper.getAuthoriseCallbackUrl(channelNodeRef));
String authRequestUrl = authoriseUrls.authorisationRequestUrl;
if (authRequestUrl == null)
{
authRequestUrl = channelAuthHelper.getDefaultAuthoriseUrl(channelNodeRef);
}
status.setCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
status.setLocation(authRequestUrl);
}
Map<String,Object> model = new TreeMap<String, Object>();
model.put("authStatus", authStatus.name());
return model;
}
}

View File

@@ -1,79 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletResponse;
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.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Brian
* @since 4.0
*/
public class AuthFormGetWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String channelNodeUuid = templateVars.get("node_id");
String channelNodeStoreProtocol = templateVars.get("store_protocol");
String channelNodeStoreId = templateVars.get("store_id");
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
Map<String,Object> model = new TreeMap<String, Object>();
if (channel == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Channel not found - " + channelNodeRef);
}
else
{
model.put("channel", channel);
}
return model;
}
}

View File

@@ -1,100 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.UrlUtil;
/**
* @author Brian
* @since 4.0
*/
public class ChannelAuthHelper
{
private String basePath = "/proxy/alfresco/api/publishing/channels/";
private SysAdminParams sysAdminParams;
public void setSysAdminParams(SysAdminParams sysAdminParams)
{
this.sysAdminParams = sysAdminParams;
}
public void setBasePath(String basePath)
{
this.basePath = basePath;
}
public String getBaseChannelApiUrl(NodeRef channelId)
{
StringBuilder urlBuilder = new StringBuilder(UrlUtil.getShareUrl(sysAdminParams));
urlBuilder.append(basePath);
urlBuilder.append(channelId.getStoreRef().getProtocol());
urlBuilder.append('/');
urlBuilder.append(channelId.getStoreRef().getIdentifier());
urlBuilder.append('/');
urlBuilder.append(channelId.getId());
urlBuilder.append('/');
return urlBuilder.toString();
}
public String getDefaultAuthoriseUrl(NodeRef channelId)
{
return getBaseChannelApiUrl(channelId) + "authform";
}
public String getAuthoriseCallbackUrl(NodeRef channelId)
{
return getBaseChannelApiUrl(channelId) + "authcallback";
}
public Map<String, Object> buildAuthorisationModel(Channel channel)
{
String alfrescoCallbackUrl = getAuthoriseCallbackUrl(channel.getNodeRef());
ChannelType.AuthUrlPair authUrlPair = channel.getChannelType().getAuthorisationUrls(channel, alfrescoCallbackUrl);
String authoriseUrl = authUrlPair.authorisationRequestUrl;
if (authoriseUrl == null)
{
// If a channel type returns null as the authorise URL then we
// assume credentials are to be supplied to us directly. We'll point the
// user at our own credential-gathering form.
authoriseUrl = getDefaultAuthoriseUrl(channel.getNodeRef());
}
Map<String, Object> model = new TreeMap<String, Object>();
model.put("authoriseUrl", authoriseUrl);
model.put("channelId", channel.getId());
model.put("authCallbackUrl", alfrescoCallbackUrl);
model.put("authRedirectUrl", authUrlPair.authorisationRedirectUrl);
return model;
}
}

View File

@@ -1,92 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.springframework.extensions.surf.util.URLDecoder;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
/**
* @author Nick Smith
* @since 4.0
*/
public class ChannelPut extends AbstractWebScript
{
private static final String CHANNEL_ID = "channel_id";
private final PublishingJsonParser parser = new PublishingJsonParser();
private ChannelService channelService;
/**
* {@inheritDoc}
*/
@Override
public void execute(WebScriptRequest req, WebScriptResponse res)
{
Map<String, String> params = req.getServiceMatch().getTemplateVars();
String channelId = URLDecoder.decode(params.get(CHANNEL_ID));
Channel channel = channelService.getChannelById(channelId);
if (channel == null)
{
String msg = "No channel found for ID: " + channelId;
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
String content = null;
try
{
content = WebScriptUtil.getContent(req);
if (content == null || content.isEmpty())
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "No publishing event was posted!");
}
parser.updateChannel(channel, content, channelService);
}
catch (Exception e)
{
String msg = "Failed to Rename Channel: " + channelId + ". POST body: " + content;
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
}
}
/**
* @param channelService the channelService to set
*/
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
}

View File

@@ -1,85 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
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.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Brian
* @since 4.0
*/
public class ChannelReauthWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
private ChannelAuthHelper channelAuthHelper;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
public void setChannelAuthHelper(ChannelAuthHelper channelAuthHelper)
{
this.channelAuthHelper = channelAuthHelper;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String channelNodeUuid = templateVars.get("node_id");
String channelNodeStoreProtocol = templateVars.get("store_protocol");
String channelNodeStoreId = templateVars.get("store_id");
if (channelNodeStoreId == null || channelNodeStoreProtocol == null || channelNodeUuid == null)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Missing parameter(s)");
}
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
if (channel == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Channel not found");
}
return channelAuthHelper.buildAuthorisationModel(channel);
}
}

View File

@@ -1,107 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.springframework.core.io.Resource;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.util.FileCopyUtils;
/**
* @author Brian
* @since 4.0
*/
public class ChannelTypeIconGetWebScript extends AbstractWebScript
{
private ChannelService channelService;
private MimetypeService mimetypeService;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
}
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
res.setContentType("text/html");
res.setContentEncoding("UTF-8");
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String channelTypeId = templateVars.get("channelType");
String iconSize = templateVars.get("iconSize");
if (channelTypeId == null || iconSize == null)
{
res.setStatus(400); //Bad request
return;
}
ChannelType channelType = channelService.getChannelType(channelTypeId);
if (channelType == null)
{
res.setStatus(404); // Not found
return;
}
Resource iconFile = channelType.getIcon(iconSize);
if (iconFile == null || !iconFile.exists())
{
res.setStatus(404); //Not found
return;
}
res.setHeader("Content-Length", "" + iconFile.contentLength());
String filename = iconFile.getFilename();
int lastDot = filename.lastIndexOf('.');
String ext = MimetypeMap.EXTENSION_BINARY;
if (lastDot != -1 && lastDot < (filename.length()-1))
{
ext = filename.substring(lastDot + 1);
}
String mimeType = mimetypeService.getMimetype(ext);
res.setContentType(mimeType);
OutputStream out = res.getOutputStream();
InputStream in = iconFile.getInputStream();
FileCopyUtils.copy(in, out);
in.close();
}
}

View File

@@ -1,67 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Nick Smith
* @since 4.0
*/
public class ChannelTypesGet extends DeclarativeWebScript
{
private final PublishingModelBuilder builder = new PublishingModelBuilder();
private ChannelService channelService;
/**
* {@inheritDoc}
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<ChannelType> types = channelService.getChannelTypes();
List<Map<String, Object>> channelTypesModel = builder.buildChannelTypes(types);
return WebScriptUtil.createBaseModel(channelTypesModel);
}
/**
* @param channelService the channelService to set
*/
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
}

View File

@@ -1,86 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.io.IOException;
import java.util.Map;
import org.alfresco.repo.security.permissions.AccessDeniedException;
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.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
/**
* @author Brian
* @since 4.0
*/
public class ChannelsDeleteWebScript extends AbstractWebScript
{
private ChannelService channelService;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String channelNodeUuid = templateVars.get("node_id");
String channelNodeStoreProtocol = templateVars.get("store_protocol");
String channelNodeStoreId = templateVars.get("store_id");
if (channelNodeStoreId == null || channelNodeStoreProtocol == null || channelNodeUuid == null)
{
res.setStatus(Status.STATUS_BAD_REQUEST);
return;
}
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
if (channel == null)
{
res.setStatus(Status.STATUS_NOT_FOUND);
return;
}
try
{
channelService.deleteChannel(channel);
}
catch (AccessDeniedException ex)
{
res.setStatus(Status.STATUS_UNAUTHORIZED);
}
}
}

View File

@@ -1,104 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.PUBLISHING_CHANNELS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.STATUS_UPDATE_CHANNELS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.URL_LENGTH;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.web.scripts.WebScriptUtil;
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.urlshortening.UrlShortener;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Nick Smith
* @since 4.0
*/
public class ChannelsGet extends DeclarativeWebScript
{
private final PublishingModelBuilder builder = new PublishingModelBuilder();
private ChannelService channelService;
private UrlShortener urlShortener;
/**
* {@inheritDoc}
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> params = req.getServiceMatch().getTemplateVars();
NodeRef node = WebScriptUtil.getNodeRef(params);
List<Channel> publishingChannels;
List<Channel> statusUpdateChannels;
if (node == null)
{
publishingChannels = channelService.getPublishingChannels(false);
statusUpdateChannels = channelService.getStatusUpdateChannels(false);
}
else
{
publishingChannels = channelService.getRelevantPublishingChannels(node);
statusUpdateChannels = channelService.getStatusUpdateChannels(true);
}
Map<String, Object> model = new HashMap<String, Object>();
//TODO Implement URL shortening.
model.put(URL_LENGTH, urlShortener.getUrlLength()+1);
model.put(PUBLISHING_CHANNELS, builder.buildChannels(publishingChannels));
model.put(STATUS_UPDATE_CHANNELS, builder.buildChannels(statusUpdateChannels));
return WebScriptUtil.createBaseModel(model);
}
/**
* @param channelService the channelService to set
*/
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
/**
* @param urlShortener the urlShortener to set
*/
public void setUrlShortener(UrlShortener urlShortener)
{
this.urlShortener = urlShortener;
}
}

View File

@@ -1,67 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Brian
* @since 4.0
*/
public class ChannelsPostWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
private ChannelAuthHelper channelAuthHelper;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
public void setChannelAuthHelper(ChannelAuthHelper channelAuthHelper)
{
this.channelAuthHelper = channelAuthHelper;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String channelType = req.getParameter("channelType");
String channelName = req.getParameter("channelName");
Channel newChannel = channelService.createChannel(channelType, channelName, null);
return channelAuthHelper.buildAuthorisationModel(newChannel);
}
}

View File

@@ -1,85 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Nick Smith
* @since 4.0
*/
public class PublishingEventsGet extends PublishingWebScript
{
/**
* {@inheritDoc}
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> params = req.getServiceMatch().getTemplateVars();
NodeRef node = WebScriptUtil.getNodeRef(params);
if (node == null)
{
String msg = "A valid NodeRef must be specified!";
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
try
{
ArrayList<PublishingEvent> events = getSortedPublishingEvents(node);
List<Map<String, Object>> model = builder.buildPublishingEventsForNode(events, node, channelService);
return WebScriptUtil.createBaseModel(model);
}
catch (Exception e)
{
String msg = "Failed to query for publishing events for node: " + node;
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
}
}
private ArrayList<PublishingEvent> getSortedPublishingEvents(NodeRef node)
{
List<PublishingEvent> publishedEvents = publishingService.getPublishEventsForNode(node);
List<PublishingEvent> unpublishedEvents = publishingService.getUnpublishEventsForNode(node);
ArrayList<PublishingEvent> allEvents = new ArrayList<PublishingEvent>(publishedEvents);
allEvents.addAll(unpublishedEvents);
Collections.sort(allEvents);
return allEvents;
}
}

View File

@@ -1,123 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import static org.alfresco.repo.web.scripts.WebScriptUtil.getCalendar;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.repo.node.NodeUtils;
import org.alfresco.service.cmr.publishing.PublishingDetails;
import org.alfresco.service.cmr.publishing.PublishingQueue;
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.NodeRef;
import org.alfresco.util.collections.Function;
import org.alfresco.util.collections.JsonUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
/**
* @author Nick Smith
* @since 4.0
*/
public class PublishingJsonParser implements PublishingWebScriptConstants
{
public JSONObject getJson(String jsonStr) throws JSONException
{
if (jsonStr != null && jsonStr.isEmpty() == false)
{
return new JSONObject(new JSONTokener(jsonStr));
}
return new JSONObject();
}
public void updateChannel(Channel channel, String jsonStr, ChannelService channelService) throws JSONException
{
JSONObject json = getJson(jsonStr);
String newName = json.optString(NAME);
if (newName != null && newName.isEmpty() == false)
{
channelService.renameChannel(channel, newName);
}
}
public String schedulePublishingEvent(PublishingService publishingService, String jsonStr) throws ParseException, JSONException
{
JSONObject json = getJson(jsonStr);
PublishingDetails details = publishingService.createPublishingDetails()
.setPublishChannelId(json.optString(CHANNEL_ID))
.setComment(json.optString(COMMENT))
.setSchedule(getCalendar(json.optJSONObject(SCHEDULED_TIME)))
.addNodesToPublish(toNodes(json.optJSONArray(PUBLISH_NODES)))
.addNodesToUnpublish(toNodes(json.optJSONArray(UNPUBLISH_NODES)));
details = setStatusUpdate(details, json.optJSONObject(STATUS_UPDATE));
return publishingService.scheduleNewEvent(details);
}
public PublishingDetails setStatusUpdate(PublishingDetails details, JSONObject json)
{
if (json != null)
{
details.setStatusMessage(json.optString(MESSAGE));
String nodeStr = json.optString(NODE_REF);
if (nodeStr != null && nodeStr.isEmpty() == false)
{
details.setStatusNodeToLinkTo(new NodeRef(nodeStr));
}
details.addStatusUpdateChannels(toStrings(json.optJSONArray(CHANNEL_IDS)));
}
return details;
}
public List<NodeRef> toNodes(JSONArray json)
{
Function<String, NodeRef> transformer = NodeUtils.toNodeRef();
return JsonUtils.transform(json, transformer);
}
private List<String> toStrings(JSONArray json)
{
if (json == null || json.length() == 0)
{
return Collections.emptyList();
}
ArrayList<String> results = new ArrayList<String>(json.length());
for (int i = 0; i < json.length(); i++)
{
results.add(json.optString(i));
}
return results;
}
}

View File

@@ -1,243 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import static org.alfresco.repo.web.scripts.WebScriptUtil.buildCalendarModel;
import static org.alfresco.repo.web.scripts.WebScriptUtil.buildDateModel;
import static org.alfresco.util.collections.CollectionUtils.toListOfStrings;
import static org.alfresco.util.collections.CollectionUtils.transform;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
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.StoreRef;
import org.alfresco.util.collections.Function;
import org.springframework.extensions.surf.util.URLEncoder;
/**
* @author Nick Smith
* @since 4.0
*/
public class PublishingModelBuilder implements PublishingWebScriptConstants
{
public Map<String, Object> buildPublishingEventForNode(PublishingEvent event, NodeRef node, ChannelService channelService)
{
Map<String, Object> model = buildPublishingEvent(event, channelService);
boolean isPublish = event.getPackage().getNodesToPublish().contains(node);
String type = isPublish ? "published" : "unpublished";
model.put(EVENT_TYPE, type);
return model;
}
public List<Map<String, Object>> buildPublishingEventsForNode(List<PublishingEvent> events,
final NodeRef node, final ChannelService channelService)
{
return transform(events, new Function<PublishingEvent, Map<String, Object>>()
{
public Map<String, Object> apply(PublishingEvent event)
{
return buildPublishingEventForNode(event, node, channelService);
}
});
}
public Map<String, Object> buildPublishingEvent(PublishingEvent event, ChannelService channelService)
{
Map<String, Object> model = new HashMap<String, Object>();
model.put(ID, event.getId());
model.put(URL, getUrl(event));
model.put(STATUS, event.getStatus().name());
model.put(COMMENT, event.getComment());
model.put(SCHEDULED_TIME, buildCalendarModel(event.getScheduledTime()));
model.put(CREATOR, event.getCreator());
model.put(CREATED_TIME, buildDateModel(event.getCreatedTime()));
model.put(PUBLISH_NODES, buildNodes(event.getPackage(), true));
model.put(UNPUBLISH_NODES, buildNodes(event.getPackage(), false));
String channelId = event.getChannelId();
Channel channel = channelService.getChannelById(channelId);
if (channel!= null)
{
model.put(CHANNEL, buildChannel(channel));
}
else
{
// Channel may have been deleted!
model.put(CHANNEL_ID, channelId);
}
return model;
}
public List<Map<String, Object>> buildPublishingEvents(List<PublishingEvent> events,
final ChannelService channelService)
{
return transform(events, new Function<PublishingEvent, Map<String, Object>>()
{
public Map<String, Object> apply(PublishingEvent event)
{
return buildPublishingEvent(event, channelService);
}
});
}
public Map<String, Object> buildChannel(Channel channel)
{
Map<String, Object> model = new HashMap<String, Object>();
model.put(URL, getUrl(channel));
model.put(ID, channel.getId());
model.put(NAME, channel.getName());
//TODO Localize the title.
model.put(TITLE, channel.getName());
model.put(CAN_PUBLISH, toString(channel.canPublish()));
model.put(CAN_UNPUBLISH, toString(channel.canUnpublish()));
model.put(CAN_PUBLISH_STATUS_UPDATES, toString(channel.canPublishStatusUpdates()));
model.put(CHANNEL_TYPE, buildChannelType(channel.getChannelType()));
model.put(CHANNEL_AUTH_STATUS, toString(channel.isAuthorised()));
return model;
}
public List<Map<String, Object>> buildChannels(List<Channel> channels)
{
return transform(channels, new Function<Channel, Map<String, Object>>()
{
public Map<String, Object> apply(Channel value)
{
return buildChannel(value);
}
});
}
public Map<String, Object> buildChannelType(ChannelType type)
{
Map<String, Object> model = new HashMap<String, Object>();
model.put(ID, type.getId());
model.put(TITLE, type.getTitle());
model.put(URL, getUrl(type));
model.put(CHANNEL_NODE_TYPE, type.getChannelNodeType().toString());
model.put(SUPPORTED_CONTENT_TYPES, toListOfStrings(type.getSupportedContentTypes()));
model.put(SUPPORTED_MIME_TYPES, type.getSupportedMimeTypes());
model.put(CAN_PUBLISH, toString(type.canPublish()));
model.put(CAN_PUBLISH_STATUS_UPDATES, toString(type.canPublishStatusUpdates()));
model.put(CAN_UNPUBLISH, toString(type.canUnpublish()));
model.put(MAX_STATUS_LENGTH, type.getMaximumStatusLength());
model.put(ICON, getUrl(type) + "/icon");
return model;
}
public List<Map<String, Object>> buildChannelTypes(List<ChannelType> types)
{
return transform(types, new Function<ChannelType, Map<String, Object>>()
{
public Map<String, Object> apply(ChannelType value)
{
return buildChannelType(value);
}
});
}
public static String getUrl(PublishingEvent event)
{
return "api/publishing/events/"+URLEncoder.encode(event.getId());
}
public static String getUrl(ChannelType type)
{
return "api/publishing/channel-types/"+URLEncoder.encode(type.getId());
}
public static String getUrl(Channel channel)
{
NodeRef node = channel.getNodeRef();
StoreRef storeRef = node.getStoreRef();
StringBuilder sb = new StringBuilder("api/publishing/channels/");
sb.append(storeRef.getProtocol()).append("/")
.append(storeRef.getIdentifier()).append("/")
.append(node.getId());
return sb.toString();
}
private String toString(boolean b)
{
return Boolean.toString(b);
}
private List<Map<String, Object>> buildNodes(PublishingPackage pckg, boolean isPublish)
{
Collection<NodeRef> nodes = isPublish ? pckg.getNodesToPublish() : pckg.getNodesToUnpublish();
return buildNodes(pckg, nodes);
}
private List<Map<String, Object>> buildNodes(PublishingPackage pckg, Collection<NodeRef> nodes)
{
List<Map<String, Object>> results = new ArrayList<Map<String,Object>>(nodes.size());
Map<NodeRef, PublishingPackageEntry> entryMap = pckg.getEntryMap();
for (NodeRef node : nodes)
{
PublishingPackageEntry entry = entryMap.get(node);
results.add(buildPackageEntry(entry));
}
return results;
}
private Map<String, Object> buildPackageEntry(PublishingPackageEntry entry)
{
Map<String, Object> model = new HashMap<String, Object>();
NodeSnapshot snapshot = entry.getSnapshot();
model.put(NODEREF, entry.getNodeRef().toString());
String version = snapshot.getVersion();
if (version != null && version.isEmpty() == false)
{
model.put(VERSION, version);
}
String name = (String) snapshot.getProperties().get(ContentModel.PROP_NAME);
if (name != null && name.isEmpty() == false)
{
model.put(NAME, name);
}
return model;
}
}

View File

@@ -1,75 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author Nick Smith
* @since 4.0
*/
public class PublishingQueuePost extends PublishingWebScript
{
/**
* {@inheritDoc}
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String content = null;
try
{
content = WebScriptUtil.getContent(req);
if (content == null || content.isEmpty())
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "No publishing event was posted!");
}
String eventId = jsonParser.schedulePublishingEvent(publishingService, content);
PublishingEvent event = publishingService.getPublishingEvent(eventId);
Map<String, Object> eventModel = builder.buildPublishingEvent(event, channelService);
return WebScriptUtil.createBaseModel(eventModel);
}
catch (WebScriptException we)
{
throw we;
}
catch (Exception e)
{
String msg = "Failed to schedule publishing event. POST body: " + content;
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
}
}
}

View File

@@ -1,61 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import org.alfresco.service.cmr.publishing.PublishingQueue;
import org.alfresco.service.cmr.publishing.PublishingService;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
/**
* @author Nick Smith
* @since 4.0
*/
public abstract class PublishingWebScript extends DeclarativeWebScript
{
protected final PublishingJsonParser jsonParser = new PublishingJsonParser();
protected final PublishingModelBuilder builder= new PublishingModelBuilder();
protected PublishingService publishingService;
protected ChannelService channelService;
/**
* @param publishingService the publishingService to set
*/
public void setPublishingService(PublishingService publishingService)
{
this.publishingService = publishingService;
}
/**
* @param channelService the channelService to set
*/
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
}

View File

@@ -1,83 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
/**
* @author Nick Smith
* @since 4.0
*/
public interface PublishingWebScriptConstants
{
// General Model Keys
public static final String ID = "id";
public static final String URL = "url";
public static final String ICON = "icon";
public static final String TITLE = "title";
// Channel Type Model Keys
public static final String CHANNEL_NODE_TYPE = "channelNodeType";
public static final String CONTENT_ROOT_NODE_TYPE = "contentRootNodeType";
public static final String SUPPORTED_CONTENT_TYPES = "supportedContentTypes";
public static final String SUPPORTED_MIME_TYPES = "supportedMimeTypes";
public static final String CAN_PUBLISH = "canPublish";
public static final String CAN_PUBLISH_STATUS_UPDATES = "canPublishStatusUpdates";
public static final String CAN_UNPUBLISH = "canUnpublish";
public static final String MAX_STATUS_LENGTH = "maxStatusLength";
// Channel Keys
public static final String NAME = "name";
public static final String CHANNEL_TYPE = "channelType";
public static final String CHANNEL_AUTH_STATUS = "authorised";
// Publishing Event Model Keys
public static final String CHANNEL = "channel";
public static final String STATUS = "status";
public static final String COMMENT = "comment";
public static final String SCHEDULED_TIME = "scheduledTime";
public static final String CREATOR = "creator";
public static final String CREATED_TIME = "createdTime";
public static final String PUBLISH_NODES = "publishNodes";
public static final String UNPUBLISH_NODES = "unpublishNodes";
public static final String NODEREF = "nodeRef";
public static final String VERSION = "version";
public static final String STATUS_UPDATE = "statusUpdate";
public static final String CHANNEL_NAME = "channelName";
public static final String CHANNEL_ID = "channelId";
// Status Update Model Keys
public static final String CHANNEL_IDS = "channelIds";
public static final String NODE_REF = "nodeRef";
public static final String MESSAGE = "message";
// Publishing Events For Node Modek Keys
public static final String EVENT_TYPE = "eventType";
// channels.get Model Keys
public static final String URL_LENGTH = "urlLength";
public static final String PUBLISHING_CHANNELS = "publishChannels";
public static final String STATUS_UPDATE_CHANNELS = "statusUpdateChannels";
}

View File

@@ -1,47 +0,0 @@
<#-- Renders the HTML response to a completed Auth Request -->
<#macro htmlPage>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Alfresco Repository">
<title>Alfresco &raquo; Authorisation</title>
<style type="text/css">
body {margin:3em;font-family:arial,helvetica,clean,sans-serif;}
div.header {background:#56A3D9;}
h1 {color: white;font-size: 1.3em;padding:5px 6px 3px;}
</style>
</head>
<body>
<img src="http://www.alfresco.com/images/alfresco-logo.png" alt="Alfresco" />
<div class="header"><h1>Publishing Channel Authorisation</h1></div>
<p id="status">Completing your authorisation...</p>
<script>
// The Auth token is received from the publisher as a hash on the URL of this call
// This needs passing back to the originating Alfresco instance.
// One of the easiest ways to achieve this is if we still have a handle to the
// window that opened the page:
var statusEl = document.getElementById("status");
try
{
if (window.opener !== null)
{
// We have a handle on the window:
window.opener.location.hash = "complete";
statusEl.innerHTML = "Your authorisation has been completed. You may now close this window";
} else
{
// No window opener - we can't submit the token back.
statusEl.innerHTML = "Your authorisation could not be completed. Please return to the Admin Console and try again."
}
self.close();
}
catch(error)
{
statusEl.innerHTML = "Your authorisation has been completed. You may now close this window. You will need to refresh the channel list to see your changes";
}
</script>
</body>
</html>
</#macro>

View File

@@ -1,25 +0,0 @@
<webscript>
<shortname>Authorisation Callback</shortname>
<description><![CDATA[
Used to receive authorisation callbacks from publishing service providers
]]></description>
<description></description>
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authcallback</url>
<format default="html"/>
<authentication>user</authentication>
<transaction>required</transaction>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The protocol of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The identifier of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The identifier of the node that represents the relevant publishing channel.</description>
</arg>
</args>
</webscript>

View File

@@ -1,2 +0,0 @@
<#import "auth-response.lib.ftl" as authResponse />
<@authResponse.htmlPage />

View File

@@ -1,24 +0,0 @@
<webscript>
<shortname>Channel Authorisation Form</shortname>
<description><![CDATA[
Used to obtain a form to provide credentials to publish to a channel.
]]></description>
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authform</url>
<format default="html"/>
<authentication>user</authentication>
<transaction>required</transaction>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The protocol of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The identifier of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The identifier of the node that represents the relevant publishing channel.</description>
</arg>
</args>
</webscript>

View File

@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Alfresco Repository">
<title>${msg("authForm.title")}</title>
<style type="text/css">
body {margin:3em;font-family:arial,helvetica,clean,sans-serif;}
div.header {background:#56A3D9;}
h1 {color: white;font-size: 1.3em;padding:5px 6px 3px;}
</style>
</head>
<body>
<img src="http://www.alfresco.com/images/alfresco-logo.png" alt="Alfresco" />
<div class="header"><h1>${msg("authForm.heading", channel.name)}</h1></div>
<p>${msg("authForm.directions", channel.name)}</p>
<form id="loginform" action="#" method="post" accept-charset="UTF-8">
<div>
<label id="txt-username" for="username">${msg("authForm.user")}</label>
</div>
<div style="padding-top:4px">
<input id="username" type="text" value="admin" style="width:200px" maxlength="255" name="username">
</div>
<div style="padding-top:12px">
<label id="txt-password" for="password">${msg("authForm.password")}</label>
</div>
<div style="padding-top:4px">
<input id="password" type="password" style="width:200px" maxlength="255" name="password">
</div>
<div style="padding-top:16px">
<input id="btn-login" class="login-button" type="submit" value="${msg("authForm.login")}">
</div>
</form>
</body>
</html>

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; Channel Authentication Details
authForm.heading=Channel Authentication
authForm.directions=Please enter your username and password for {0}
authForm.user=User Name:
authForm.password=Password:
authForm.login=Login

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; Kanalauthentifizierungsdaten
authForm.heading=Kanalauthentifizierung
authForm.directions=Geben Sie Ihren Benutzernamen und Ihr Passwort f\u00fcr {0} ein
authForm.user=Benutzername:
authForm.password=Passwort:
authForm.login=Anmelden

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; Datos de autenticaci\u00f3n del canal
authForm.heading=Autenticaci\u00f3n del canal
authForm.directions=Introduzca su nombre de usuario y contrase\u00f1a de {0}
authForm.user=Nombre de usuario:
authForm.password=Contrase\u00f1a:
authForm.login=Iniciar sesi\u00f3n

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; D\u00e9tails d'authentification de canal
authForm.heading=Authentification de canal
authForm.directions=Veuillez saisir votre nom d''utilisateur et votre mot de passe pour {0}
authForm.user=Nom d'utilisateur :
authForm.password=Mot de passe :
authForm.login=Connexion

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; Dati di autenticazione canale
authForm.heading=Autenticazione canale
authForm.directions=Immettere nome utente e password per {0}
authForm.user=Nome utente:
authForm.password=Password:
authForm.login=Login

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; \u30c1\u30e3\u30cd\u30eb\u8a8d\u8a3c\u306e\u8a73\u7d30
authForm.heading=\u30c1\u30e3\u30cd\u30eb\u8a8d\u8a3c
authForm.directions={0}\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002
authForm.user=\u30e6\u30fc\u30b6\u30fc\u540d\uff1a
authForm.password=\u30d1\u30b9\u30ef\u30fc\u30c9\uff1a
authForm.login=\u30ed\u30b0\u30a4\u30f3

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; Detaljer om kanalgodkjenning
authForm.heading=Kanalgodkjenning
authForm.directions=Angi brukernavn og passord for {0}
authForm.user=Brukernavn:
authForm.password=Passord:
authForm.login=Logg inn

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; kanaalverificatiegegevens
authForm.heading=Kanaalverificatie
authForm.directions=Voer uw gebruikersnaam en wachtwoord in voor {0}
authForm.user=Gebruikersnaam:
authForm.password=Wachtwoord:
authForm.login=Aanmelden

View File

@@ -1,6 +0,0 @@
authForm.title=Detalhes de autentica\u00e7\u00e3o de canal do Alfresco &raquo;
authForm.heading=Autentica\u00e7\u00e3o de canal
authForm.directions=Insira seu nome de usu\u00e1rio e senha para {0}
authForm.user=Nome de usu\u00e1rio:
authForm.password=Senha:
authForm.login=Login

View File

@@ -1,6 +0,0 @@
authForm.title=\u0421\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u0431 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 Alfresco &raquo;
authForm.heading=\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043a\u0430\u043d\u0430\u043b\u043e\u0432
authForm.directions=\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u0432\u043e\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f {0}
authForm.user=\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:
authForm.password=\u041f\u0430\u0440\u043e\u043b\u044c:
authForm.login=\u0412\u043e\u0439\u0442\u0438

View File

@@ -1,6 +0,0 @@
authForm.title=Alfresco &raquo; \u6e20\u9053\u8eab\u4efd\u9a8c\u8bc1\u8be6\u7ec6\u4fe1\u606f
authForm.heading=\u6e20\u9053\u8eab\u4efd\u9a8c\u8bc1
authForm.directions=\u8bf7\u8f93\u5165\u60a8\u7684 {0} \u7528\u6237\u540d\u548c\u5bc6\u7801
authForm.user=\u7528\u6237\u540d\uff1a
authForm.password=\u5bc6\u7801\uff1a
authForm.login=\u767b\u5f55

View File

@@ -1,24 +0,0 @@
<webscript>
<shortname>Channel Authorisation Form</shortname>
<description><![CDATA[
Used to post back credentials to publish to a channel.
]]></description>
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authform</url>
<format default="html"/>
<authentication>user</authentication>
<transaction>required</transaction>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The protocol of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The identifier of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The identifier of the node that represents the relevant publishing channel.</description>
</arg>
</args>
</webscript>

View File

@@ -1,2 +0,0 @@
<#import "auth-response.lib.ftl" as authResponse />
<@authResponse.htmlPage />

View File

@@ -1,58 +0,0 @@
<webscript>
<shortname>Reauthorise the specified publishing channel</shortname>
<description><![CDATA[
Initiate an attempt to reauthorise the specified publishing channel.
<br />
Response status may be:
<dl>
<dt>200</dt><dd>The body of the response contains the necessary information to continue the reauthorisation process</dd>
<dt>400</dt><dd>invalid data received from caller</dd>
<dt>404</dt><dd>the specified channel cannot be found</dd>
</dl>
Returns three pieces of informtation:
<br />
<dl>
<dt>channelId</dt><dd>the identifier of the publishing channel</dd>
<dt>authoriseUrl</dt> <dd>The URL to send the user to in order for them to authorise access to the channel</dd>
<dt>authCallbackUrl</dt> <dd>The URL to return the channel authorisation details to</dd>
<dt>authRedirectUrl</dt> <dd>The URL that the channel service provider will try to redirect the user to</dd>
</dl>
]]></description>
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/reauthorise</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The protocol of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The identifier of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The identifier of the node that represents the relevant publishing channel.</description>
</arg>
</args>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
{
"data":
{
"channelId": string,
"authoriseUrl": string
"authCallbackUrl": string
"authRedirectUrl": string
}
}
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -1,5 +0,0 @@
<#import "publishing.lib.ftl" as publishLib />
{
"data":
<@publishLib.channelAuthJSON />
}

View File

@@ -1,29 +0,0 @@
<webscript>
<shortname>Get channel type icon</shortname>
<description><![CDATA[
Create a new publishing channel using the supplied information.
<br />
<dl>
<dt>channelType</dt><dd>mandatory - the channel type for which the icon is required</dd>
<dt>iconSize</dt> <dd>mandatory - the size of the icon required. Must be either "16" or "32"</dd>
</dl>
Streams the requested icon if it can be found, otherwise returns a 404 status code. If either channelType or iconSize
are missing then a 400 status code is returned.
]]></description>
<description></description>
<url>/api/publishing/channel-types/{channelType}/icon/{iconSize}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>channelType</shortname>
<description>The identifier of the channel type whose icon is wanted.</description>
</arg>
<arg>
<shortname>iconSize</shortname>
<description>The size (in pixels) of the required icon. Must be either "16" or "32".</description>
</arg>
</args>
</webscript>

View File

@@ -1,40 +0,0 @@
<webscript>
<shortname>Get Publishing Channels</shortname>
<description>Get the publishing channels for a Share Site.or specified NodeRef</description>
<url>/api/publishing/channel-types</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
{
"data":
{
[
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
},
...
]
}
}
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -1,13 +0,0 @@
<#-- List Channels -->
<#import "publishing.lib.ftl" as publishLib />
{
"data":
[
<#if data??>
<#list data as type>
<@publishLib.channelTypeJSON type=type/>
<#if type_has_next>,</#if>
</#list>
</#if>
]
}

View File

@@ -1,27 +0,0 @@
<webscript>
<shortname>Update Channel</shortname>
<description>Updates an existing Channel's name.</description>
<url>/api/publishing/channels/{channel_id}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>channel_id</shortname>
<description>The URL-encoded id of the channel to be updated.</description>
</arg>
</args>
<requests>
<request>
<format>json</format>
<type>
<![CDATA[
{
"name": string
}
]]>
</type>
</request>
</requests>
</webscript>

View File

@@ -1,34 +0,0 @@
<webscript>
<shortname>Delete specified publishing channel</shortname>
<description><![CDATA[
Request the deletion of the publishing channel specified on the URL.
<br />
Response status indicates result:
<dl>
<dt>200</dt><dd>deletion successful</dd>
<dt>400</dt><dd>invalid data received from caller</dd>
<dt>401</dt><dd>user doesn't have permission to delete the specified channel</dd>
<dt>404</dt><dd>the specified channel cannot be found</dd>
</dl>
]]></description>
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The protocol of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The identifier of the store in which the relevant publishing channel lives.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The identifier of the node that represents the relevant publishing channel.</description>
</arg>
</args>
</webscript>

View File

@@ -1,97 +0,0 @@
<webscript>
<shortname>Get Publishing Channels</shortname>
<description>Get the publishing channels for specified NodeRef or returns all Publishing Channels</description>
<url>/api/publishing/channels</url>
<url>/api/publishing/{store_protocol}/{store_id}/{node_id}/channels</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The protocol used by the StoreRef to retrieve channels for.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The id of the StoreRef to retrieve channels for.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The id of the NodeRef to retrieve channels for.</description>
</arg>
</args>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
{
"data":
{
"urlLength": number,
"publishChannels":
[
{
"url": string,
"id": string,
"name": string,
"title": string,
"authorised": boolean,
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"channelType":
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
}
},
...
],
"statusUpdateChannels":
[
{
"url": string,
"id": string,
"name": string,
"title": string,
"authorised": boolean,
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"channelType":
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
}
},
...
]
}
}
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -1,12 +0,0 @@
<#-- List Channels -->
<#import "publishing.lib.ftl" as publishLib />
{
"data":
{
<#if data.urlLength??>"urlLength": ${data.urlLength},</#if>
"publishChannels":
<@publishLib.channelsJSON channels=data.publishChannels />,
"statusUpdateChannels":
<@publishLib.channelsJSON channels=data.statusUpdateChannels />
}
}

View File

@@ -1,60 +0,0 @@
<webscript>
<shortname>Create a publishing channel</shortname>
<description><![CDATA[
Create a new publishing channel using the supplied information.
<br />
<dl>
<dt>channelType</dt><dd>mandatory - the type of delivery channel to create</dd>
<dt>siteId</dt> <dd>mandatory - the Share site with which the new delivery channel is to be associated</dd>
<dt>channelName</dt> <dd>mandatory - the name of the new delivery channel</dd>
</dl>
Returns three pieces of informtation:
<br />
<dl>
<dt>channelId</dt><dd>the identifier of the new publishing channel</dd>
<dt>pollUrl</dt> <dd>The URL to poll to discover whether the channel has been authorised</dd>
<dt>authoriseUrl</dt> <dd>The URL to send the user to in order for them to authorise access to the channel</dd>
<dt>authCallbackUrl</dt> <dd>The URL to return the channel authorisation details to</dd>
<dt>authRedirectUrl</dt> <dd>The URL to which the channel service provider will redirect the user upon authorisation</dd>
</dl>
]]></description>
<description></description>
<url>/api/publishing/channels</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>siteId</shortname>
<description>The id of the site to create a delivery channel on.</description>
</arg>
<arg>
<shortname>channelType</shortname>
<description>The identifier of the type of delivery channel to create.</description>
</arg>
<arg>
<shortname>channelName</shortname>
<description>The name of the channel that is to be created.</description>
</arg>
</args>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
{
"data":
{
"channelId": string,
"authoriseUrl": string
"authCallbackUrl": string
"authRedirectUrl": string
}
}
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -1,6 +0,0 @@
<#-- Response to a request to create a publishing channel -->
<#import "publishing.lib.ftl" as publishLib />
{
"data":
<@publishLib.channelAuthJSON />
}

View File

@@ -1,165 +0,0 @@
<webscript>
<shortname>Get Publishing Events For Node</shortname>
<description>Find all PublishingEvents that publish or unpublish the specified node.</description>
<url>/api/publishing/{store_protocol}/{store_id}/{node_id}/events</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<args>
<arg>
<shortname>store_protocol</shortname>
<description>The store protocol for the published/unpublished node.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The store id for the published/unpublished node.</description>
</arg>
<arg>
<shortname>node_id</shortname>
<description>The node id for the published/unpublished node.</description>
</arg>
</args>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
{
"data":
{
"publishingEvents":
[
{
"id": string,
"url": string,
"status": string,
"comment": string,
"eventType": string,
"scheduledTime":
{
"dateTime": string,
"format": string,
"timeZone": string
}
"creator": string,
"createdTime":
{
"dateTime": string,
"format": string
},
"publishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
],
"unpublishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
]
"channel":
{
"url": string,
"id": string,
"name": string,
"title": string,
"authorised": boolean,
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"channelType":
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
}
}
},
...
]
unpublishingEvents:
[
{
"id": string,
"url": string,
"status": string,
"comment": string,
"scheduledTime":
{
"dateTime": string,
"format": string,
"timeZone": string
}
"creator": string,
"createdTime":
{
"dateTime": string,
"format": string
},
"publishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
],
"unpublishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
]
"channel":
{
"url": string,
"name": string,
"title": string,
"channelType":
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
}
}
},
...
]
}
}
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -1,6 +0,0 @@
<#-- List Channels -->
<#import "publishing.lib.ftl" as publishLib />
{
"data":
<@publishLib.eventsJSON events=data />
}

View File

@@ -1,178 +0,0 @@
<webscript>
<shortname>Post Content to Publishing Queue</shortname>
<description>Place a new Publishing Event on the Publishing Queue..</description>
<url>/api/publishing/queue</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>limited_support</lifecycle>
<requests>
<request>
<format>json</format>
<type>
<![CDATA[
{
"channelId": string,
"comment": string,
"scheduledTime":
{
"dateTime": string,
"format": string,
"timeZone": string,
},
"publishNodes": [string, ... ],
"unpublishNodes": [string, ... ],
"statusUpdate":
{
"message": string,
"nodeRef": string,
"channelIds": [string, ... ]
}
}
]]>
</type>
</request>
</requests>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
{
"data":
{
"publishingEvents":
[
{
"id": string,
"url": string,
"status": string,
"comment": string,
"eventType": string,
"scheduledTime":
{
"dateTime": string,
"format": string,
"timeZone": string
}
"creator": string,
"createdTime":
{
"dateTime": string,
"format": string
},
"publishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
],
"unpublishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
]
"channel":
{
"url": string,
"id": string,
"name": string,
"title": string,
"authorised": boolean,
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"channelType":
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
}
}
},
...
]
unpublishingEvents:
[
{
"id": string,
"url": string,
"status": string,
"comment": string,
"scheduledTime":
{
"dateTime": string,
"format": string,
"timeZone": string
}
"creator": string,
"createdTime":
{
"dateTime": string,
"format": string
},
"publishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
],
"unpublishNodes":
[
{
"nodeRef": string,
"name": string,
"version": string
},
...
]
"channel":
{
"url": string,
"name": string,
"title": string,
"channelType":
{
"id": string,
"title": string,
"url": string,
"channelNodeType": string,
"contentRootNodeType": string,
"supportedContentTypes": [string, ...],
"supportedMimeTypes": [string, ...],
"canPublish": boolean,
"canPublishStatusUpdates": boolean,
"canUnpublish": boolean,
"maxStatusLength": number,
"icon": string
}
}
},
...
]
}
}
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -1,7 +0,0 @@
<#-- List Channels -->
<#import "publishing.lib.ftl" as publishLib />
{
"data":
{
}
}

View File

@@ -1,160 +0,0 @@
<#-- Renders a List of Publishing Events -->
<#macro eventsJSON events>
<#escape x as jsonUtils.encodeJSONString(x)>
[
<#if events??>
<#list events as event>
<@eventJSON event=event />
<#if event_has_next>,</#if>
</#list>
</#if>
]
</#escape>
</#macro>
<#-- Renders a Publishing Event. -->
<#macro eventJSON event>
{
"id": "${event.id}",
"url": "${event.url}",
"status": "${event.status}",
<#if event.comment?? >"comment": "${event.comment}",</#if>
<#if event.eventType?? >"eventType": "${event.eventType}",</#if>
<#if event.scheduledTime?? >
"scheduledTime":
<@calendarJSON calendar=event.scheduledTime />,
</#if>
"creator": "${event.creator}",
"createdTime":
<@dateJSON date=event.createdTime/>,
"publishNodes":
<@publishNodesJSON nodes=event.publishNodes/>,
"unpublishNodes":
<@publishNodesJSON nodes=event.unpublishNodes/>,
<#if event.channel?? >
"channel":
<@channelJSON channel=event.channel/>
<#elseif event.channelId?? >
"channelId": "${event.channelId}"
</#if>
}
</#macro>
<#-- Renders a List of Nodes to be published/unpublished. -->
<#macro publishNodesJSON nodes>
[
<#if nodes??>
<#list nodes as node>
<@publishNodeJSON node=node/>
<#if node_has_next>,</#if>
</#list>
</#if>
]
</#macro>
<#-- Renders a Published/Unpublished Node. -->
<#macro publishNodeJSON node>
{
<#if node.name?? >"name": "${node.name}",</#if>
<#if node.version?? >"version": "${node.version}",</#if>
"nodeRef": "${node.nodeRef}"
}
</#macro>
<#-- Renders a List of Channel.s -->
<#macro channelsJSON channels>
<#escape x as jsonUtils.encodeJSONString(x)>
[
<#if channels??>
<#list channels as channel>
<@channelJSON channel=channel />
<#if channel_has_next>,</#if>
</#list>
</#if>
]
</#escape>
</#macro>
<#-- Renders a Channel. -->
<#macro channelJSON channel>
{
"url": "${channel.url}",
"id": "${channel.id}",
"name": "${channel.name}",
"title": "${channel.title}",
"authorised": ${channel.authorised},
"canPublish": ${channel.canPublish},
"canPublishStatusUpdates": ${channel.canPublishStatusUpdates},
"canUnpublish": ${channel.canUnpublish},
"channelType":
<@channelTypeJSON type=channel.channelType />
}
</#macro>
<#-- Renders a Channel Type. -->
<#macro channelTypeJSON type>
{
"id": "${type.id}",
"title": "${type.title}",
"url": "${type.url}",
<#if type.channelNodeType??>"channelNodeType": "${type.channelNodeType}",</#if>
<#if type.supportedContentTypes?? >
"supportedContentTypes":
<@iterateStringsJSON strings=type.supportedContentTypes />,
</#if>
<#if type.supportedMimeTypes?? >
"supportedMimeTypes":
<@iterateStringsJSON strings=type.supportedMimeTypes/>,
</#if>
"canPublish": ${type.canPublish},
"canPublishStatusUpdates": ${type.canPublishStatusUpdates},
"canUnpublish": ${type.canUnpublish},
<#if type.icon??>"icon": "${type.icon}",</#if>
"maxStatusLength": ${type.maxStatusLength}
}
</#macro>
<#-- Renders a List of Strings. -->
<#macro iterateStringsJSON strings>
<#if strings??>
[
<#list strings as string>
"${string}"
<#if string_has_next>,</#if>
</#list>
]
<#else>
[]
</#if>
</#macro>
<#-- Renders a date. -->
<#macro dateJSON date>
{
"dateTime": "${date.dateTime}",
"format": "${date.format}"
}
</#macro>
<#-- Renders a calendar. -->
<#macro calendarJSON calendar>
{
"dateTime": "${calendar.dateTime}",
"format": "${calendar.format}",
"timeZone": "${calendar.timeZone}"
}
</#macro>
<#-- Renders the info needed about a channel's authorisation -->
<#macro channelAuthJSON>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"channelId" : "${channelId}",
"authoriseUrl": "${authoriseUrl}",
"authCallbackUrl": "${authCallbackUrl}",
"authRedirectUrl": "${authRedirectUrl}"
}
</#escape>
</#macro>

View File

@@ -959,100 +959,6 @@
class="org.alfresco.repo.web.scripts.workflow.WorkflowInstanceDelete"
parent="abstractWorkflowWebScript"></bean>
<!-- -->
<!-- Publishing Service REST API -->
<!-- -->
<!-- Get Channels web script -->
<bean id="webscript.org.alfresco.repository.publishing.channels.get"
class="org.alfresco.repo.web.scripts.publishing.ChannelsGet"
parent="webscript">
<property name="channelService" ref="channelService" />
<property name="urlShortener" ref="urlShortener" />
</bean>
<!-- Update Channel web script -->
<bean id="webscript.org.alfresco.repository.publishing.channel.put"
class="org.alfresco.repo.web.scripts.publishing.ChannelPut"
parent="webscript">
<property name="channelService" ref="channelService" />
</bean>
<!-- Get Channel Types web script -->
<bean id="webscript.org.alfresco.repository.publishing.channel-types.get"
class="org.alfresco.repo.web.scripts.publishing.ChannelTypesGet"
parent="webscript">
<property name="channelService" ref="channelService" />
</bean>
<!-- Post Event to a Publishing Queue web script -->
<bean id="webscript.org.alfresco.repository.publishing.publishing-queue.post"
class="org.alfresco.repo.web.scripts.publishing.PublishingQueuePost"
parent="webscript">
<property name="publishingService" ref="publishingService" />
<property name="channelService" ref="channelService" />
</bean>
<!-- Create a new Channel web script -->
<bean id="webscript.org.alfresco.repository.publishing.channels.post"
class="org.alfresco.repo.web.scripts.publishing.ChannelsPostWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
<property name="channelAuthHelper" ref="channelAuthHelper" />
</bean>
<bean id="channelAuthHelper" class="org.alfresco.repo.web.scripts.publishing.ChannelAuthHelper">
<property name="sysAdminParams" ref="sysAdminParams" />
</bean>
<bean id="webscript.org.alfresco.repository.publishing.authcallback.get"
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
<property name="channelAuthHelper" ref="channelAuthHelper" />
</bean>
<bean id="webscript.org.alfresco.repository.publishing.authform.post"
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
<property name="channelAuthHelper" ref="channelAuthHelper" />
</bean>
<bean id="webscript.org.alfresco.repository.publishing.authform.get"
class="org.alfresco.repo.web.scripts.publishing.AuthFormGetWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
</bean>
<!-- Get Publishing Events For Node web script -->
<bean id="webscript.org.alfresco.repository.publishing.publishing-events.get"
class="org.alfresco.repo.web.scripts.publishing.PublishingEventsGet"
parent="webscript">
<property name="publishingService" ref="publishingService" />
<property name="channelService" ref="channelService" />
</bean>
<bean id="webscript.org.alfresco.repository.publishing.channel-type-icon.get"
class="org.alfresco.repo.web.scripts.publishing.ChannelTypeIconGetWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
<property name="mimetypeService" ref="mimetypeService" />
</bean>
<bean id="webscript.org.alfresco.repository.publishing.channels.delete"
class="org.alfresco.repo.web.scripts.publishing.ChannelsDeleteWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
</bean>
<bean id="webscript.org.alfresco.repository.publishing.channel-reauth.post"
class="org.alfresco.repo.web.scripts.publishing.ChannelReauthWebScript"
parent="webscript">
<property name="channelService" ref="channelService" />
<property name="channelAuthHelper" ref="channelAuthHelper" />
</bean>
<!-- -->
<!-- Audit Service REST API -->
<!-- -->

View File

@@ -63,7 +63,6 @@ import org.junit.runners.Suite;
org.alfresco.repo.web.scripts.thumbnail.ThumbnailServiceTest.class,
org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest.class,
org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest.class,
org.alfresco.repo.web.scripts.publishing.PublishingRestApiTest.class,
org.alfresco.repo.web.scripts.solr.SOLRWebScriptTest.class,
org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceRestApiTest.class,
org.alfresco.repo.web.scripts.facet.FacetRestApiTest.class,

View File

@@ -48,7 +48,6 @@ import org.alfresco.repo.web.scripts.links.LinksRestApiTest;
import org.alfresco.repo.web.scripts.node.NodeWebScripTest;
import org.alfresco.repo.web.scripts.person.PersonServiceTest;
import org.alfresco.repo.web.scripts.preference.PreferenceServiceTest;
import org.alfresco.repo.web.scripts.publishing.PublishingRestApiTest;
import org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest;
import org.alfresco.repo.web.scripts.rating.RatingRestApiTest;
import org.alfresco.repo.web.scripts.replication.ReplicationRestApiTest;
@@ -62,8 +61,8 @@ import org.alfresco.repo.web.scripts.tagging.TaggingServiceTest;
import org.alfresco.repo.web.scripts.thumbnail.ThumbnailServiceTest;
import org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest;
import org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest;
import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest;
import org.alfresco.repo.web.scripts.content.ContentGetTest;
import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest;
import org.alfresco.repo.web.scripts.content.ContentGetTest;
/**
* Web Scripts test suite
@@ -105,13 +104,12 @@ public class WebScriptTestSuite extends TestSuite
suite.addTestSuite( TransferWebScriptTest.class );
suite.addTestSuite( WorkflowModelBuilderTest.class );
suite.addTestSuite( ActivitiWorkflowRestApiTest.class );
suite.addTestSuite( PublishingRestApiTest.class );
suite.addTestSuite( SOLRWebScriptTest.class );
suite.addTestSuite( SubscriptionServiceRestApiTest.class );
suite.addTestSuite( FacetRestApiTest.class );
suite.addTestSuite( CommentsApiTest.class );
suite.addTestSuite( DeclarativeSpreadsheetWebScriptTest.class );
suite.addTestSuite( ContentGetTest.class);
suite.addTestSuite( ContentGetTest.class);
suite.addTestSuite( XssVulnerabilityTest.class );
suite.addTestSuite( LinksRestApiTest.class );
suite.addTestSuite( RemoteFileFolderLoaderTest.class );

View File

@@ -1,818 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* 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.web.scripts.publishing;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CAN_PUBLISH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CAN_PUBLISH_STATUS_UPDATES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CAN_UNPUBLISH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_AUTH_STATUS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_ID;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_IDS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_NODE_TYPE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_TYPE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.COMMENT;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CREATED_TIME;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CREATOR;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.ICON;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.ID;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.MAX_STATUS_LENGTH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.MESSAGE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.NAME;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.NODE_REF;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.PUBLISHING_CHANNELS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.PUBLISH_NODES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SCHEDULED_TIME;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.STATUS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.STATUS_UPDATE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.STATUS_UPDATE_CHANNELS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SUPPORTED_CONTENT_TYPES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SUPPORTED_MIME_TYPES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.TITLE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.UNPUBLISH_NODES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.URL;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.URL_LENGTH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.VERSION;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.publishing.AbstractChannelType;
import org.alfresco.repo.publishing.ChannelHelper;
import org.alfresco.repo.publishing.ChannelServiceImpl;
import org.alfresco.repo.publishing.PublishServiceImpl;
import org.alfresco.repo.publishing.PublishingTestHelper;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.person.TestPersonManager;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
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.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
import org.alfresco.service.cmr.publishing.PublishingService;
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.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.util.GUID;
import org.alfresco.util.ISO8601DateFormat;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Function;
import org.alfresco.util.testing.category.LuceneTests;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.experimental.categories.Category;
import org.mockito.ArgumentCaptor;
import org.springframework.context.ApplicationContext;
import org.springframework.extensions.surf.util.URLEncoder;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/**
* @author Nick Smith
* @since 4.0
*/
@Category(LuceneTests.class)
public class PublishingRestApiTest extends BaseWebScriptTest
{
private static final String publishPdfType = "publishPdfForTest";
private static final String publishAnyType = "publishAnyForTest";
private static final String statusUpdateType = "statusUpdateForTest";
private static final int maxStatusLength = 100;
private static final String CHANNELS_URL = "api/publishing/channels";
private static final String CHANNEL_URL = "api/publishing/channels/{0}";
private static final String CHANNELS_NODE_URL = "api/publishing/{0}/{1}/{2}/channels";
private static final String CHANNEL_TYPES_URL = "api/publishing/channel-types";
private static final String PUBLISHING_QUEUE_URL = "api/publishing/queue";
private static final String PUBLISHING_EVENTS_URL = "api/publishing/{0}/{1}/{2}/events";
private static final String JSON = "application/json";
private NodeService nodeService;
private PermissionService permissionService;
private ChannelService channelService;
private PublishingService publishingService;
private ChannelHelper channelHelper;
private PublishingTestHelper testHelper;
TestPersonManager personManager;
private String userName = GUID.generate();
public void testGetChannels() throws Exception
{
Channel publishAnyChannel = testHelper.createChannel(publishAnyType);
Channel publishPdfChannel = testHelper.createChannel(publishPdfType);
Channel statusUpdateChannel=testHelper. createChannel(statusUpdateType);
// Call channels defined.
Response response = sendRequest(new GetRequest(CHANNELS_URL), 200);
JSONObject data = getJsonData(response);
assertEquals(21, data.getInt(URL_LENGTH));
JSONArray publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS);
JSONArray statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS);
checkChannels(publishingChannels, publishAnyChannel, publishPdfChannel);
checkChannels(statusChannels, statusUpdateChannel);
personManager.setUser(userName);
response = sendRequest(new GetRequest(CHANNELS_URL), 200);
data = getJsonData(response);
publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS);
statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS);
checkChannels(publishingChannels, publishAnyChannel, publishPdfChannel);
checkChannels(statusChannels, statusUpdateChannel);
}
public void testGetChannelsForNode() throws Exception
{
NodeRef textNode = testHelper.createContentNode("plainContent", "Some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN);
permissionService.setPermission(textNode, userName, PermissionService.READ, true);
File pdfFile = AbstractContentTransformerTest.loadQuickTestFile("pdf");
assertNotNull("Failed to load required test file.", pdfFile);
NodeRef xmlNode = testHelper.createContentNode("xmlContent", pdfFile, MimetypeMap.MIMETYPE_PDF);
StoreRef store = textNode.getStoreRef();
String plainTextNodeUrl = MessageFormat.format(CHANNELS_NODE_URL, store.getProtocol(), store.getIdentifier(), textNode.getId() );
Channel publishAnyChannel = testHelper.createChannel(publishAnyType);
Channel publishPdfChannel = testHelper.createChannel(publishPdfType);
Channel statusUpdateChannel= testHelper.createChannel(statusUpdateType);
// Call with channels defined.
Response response = sendRequest(new GetRequest(plainTextNodeUrl), 200);
JSONObject data = getJsonData(response);
//TODO Fix hard coding.
assertEquals(21, data.getInt(URL_LENGTH));
JSONArray publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS);
JSONArray statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS);
checkChannels(publishingChannels, publishAnyChannel);
checkChannels(statusChannels, statusUpdateChannel);
String xmlNodeUrl = MessageFormat.format(CHANNELS_NODE_URL, store.getProtocol(), store.getIdentifier(), xmlNode.getId() );
response = sendRequest(new GetRequest(xmlNodeUrl), 200);
data = getJsonData(response);
assertEquals(21, data.getInt(URL_LENGTH));
publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS);
statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS);
checkChannels(publishingChannels, publishAnyChannel, publishPdfChannel);
checkChannels(statusChannels, statusUpdateChannel);
personManager.setUser(userName);
response = sendRequest(new GetRequest(plainTextNodeUrl), 200);
data = getJsonData(response);
publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS);
statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS);
assertEquals(0, publishingChannels.length());
assertEquals(0, statusChannels.length());
testHelper.allowChannelAccess(userName, publishAnyChannel.getId());
testHelper.allowChannelAccess(userName, publishPdfChannel.getId());
testHelper.allowChannelAccess(userName, statusUpdateChannel.getId());
personManager.setUser(userName);
response = sendRequest(new GetRequest(plainTextNodeUrl), 200);
data = getJsonData(response);
publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS);
statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS);
checkChannels(publishingChannels, publishAnyChannel);
checkChannels(statusChannels, statusUpdateChannel);
}
public void testChannelPut() throws Exception
{
Channel channel1 = testHelper.createChannel(publishAnyType);
Channel channel2 = testHelper.createChannel(publishAnyType);
String name1 = channel1.getName();
String name2 = channel2.getName();
String newName = name1 + "Foo";
JSONObject json = new JSONObject();
json.put(NAME, newName);
String jsonStr = json.toString();
String channel1Url = MessageFormat.format(CHANNEL_URL, URLEncoder.encode(channel1.getId()));
// Post JSON content.
sendRequest(new PutRequest(channel1Url, jsonStr, JSON), 200);
Channel renamedCH1 = channelService.getChannelById(channel1.getId());
assertEquals("Channel1 was not renamed correctly!", newName, renamedCH1.getName());
Channel renamedCH2 = channelService.getChannelById(channel2.getId());
assertEquals("Channel2 name should not have changed!", name2, renamedCH2.getName());
}
public void testPublishingQueuePost() throws Exception
{
// Create some content.
NodeRef textNode = testHelper.createContentNode("plainContent", "Some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN);
try
{
checkPublishingQueuePost(textNode);
}
finally
{
// Clean up events
List<PublishingEvent> events = publishingService.getPublishEventsForNode(textNode);
List<String> ids = CollectionUtils.transform(events, new Function<PublishingEvent, String>()
{
public String apply(PublishingEvent value)
{
return value.getId();
}
});
testHelper.addEvents(ids);
}
}
@SuppressWarnings("unchecked")
private void checkPublishingQueuePost(NodeRef textNode) throws Exception
{
// Create publish and status update channels.
Channel publishChannel = testHelper.createChannel(publishAnyType);
Channel statusChannel = testHelper.createChannel(statusUpdateType);
// Post empty content.
sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, "", JSON), 400);
String comment = "The comment";
String statusMessage = "The status message";
JSONObject json = buildScheduleEventJson(textNode, publishChannel, comment, statusMessage, true, statusChannel);
String jsonStr = json.toString();
// Post JSON content.
sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200);
List<PublishingEvent> publishedEvents = publishingService.getPublishEventsForNode(textNode);
assertEquals(1, publishedEvents.size());
PublishingEvent event = publishedEvents.get(0);
assertEquals(publishChannel.getId(), event.getChannelId());
assertEquals(comment, event.getComment());
Collection<Status> expectedPubEventStatuses = Arrays.asList(Status.SCHEDULED, Status.IN_PROGRESS, Status.COMPLETED);
assertTrue(expectedPubEventStatuses.contains(event.getStatus()));
// Check Package
PublishingPackage pckg = event.getPackage();
Set<NodeRef> toPublish = pckg.getNodesToPublish();
assertEquals(1, toPublish.size());
assertTrue(toPublish.contains(textNode));
assertTrue(pckg.getNodesToUnpublish().isEmpty());
// Check StatusUpdate
StatusUpdate statusUpdate = event.getStatusUpdate();
assertEquals(statusMessage, statusUpdate.getMessage());
assertEquals(textNode, statusUpdate.getNodeToLinkTo());
Set<String> channelIds = statusUpdate.getChannelIds();
assertEquals(1, channelIds.size());
assertTrue(channelIds.contains(statusChannel.getId()));
// Wait for Publishing Event to execute asynchronously
Thread.sleep(5000);
AbstractChannelType publishAnyChannelType = (AbstractChannelType) channelService.getChannelType(publishAnyType);
AbstractChannelType statusUpdateChannelType = (AbstractChannelType) channelService.getChannelType(statusUpdateType);
NodeRef mappedTextNode = channelHelper.mapSourceToEnvironment(textNode, publishChannel.getNodeRef());
// Check publish is called.
verify(publishAnyChannelType)
.publish(eq(mappedTextNode), anyMap());
// Check updateStatus is called correctly.
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(statusUpdateChannelType)
.sendStatusUpdate(any(Channel.class), captor.capture());
String actualStatusMessage = captor.getValue();
assertTrue(actualStatusMessage.startsWith(statusMessage));
verify(statusUpdateChannelType, never()).publish(any(NodeRef.class), anyMap());
verify(publishAnyChannelType, never()).sendStatusUpdate(any(Channel.class), anyString());
JSONObject status = json.optJSONObject(STATUS_UPDATE);
status.remove(NODE_REF);
jsonStr = json.toString();
// Post JSON without NodeRef in status.
sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200);
json.remove(STATUS_UPDATE);
jsonStr = json.toString();
// Post JSON without Status Update.
sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200);
// Wait for Publishing Events to execute asynchronously
Thread.sleep(5000);
// Check published node still exists.
assertTrue(nodeService.exists(mappedTextNode));
// Check unpublish hasn't been called yet.
verify(publishAnyChannelType, never())
.unpublish(eq(mappedTextNode), anyMap());
// Create unpublish Json
json = buildScheduleEventJson(textNode, publishChannel, comment, null, false);
jsonStr = json.toString();
// Post Unpublish JSON.
sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200);
// Wait for unpublishing Event to execute asynchronously
Thread.sleep(5000);
// Check published node has been deleted.
assertFalse(nodeService.exists(mappedTextNode));
NodeRef remappedTextNode = channelHelper.mapSourceToEnvironment(textNode, publishChannel.getNodeRef());
assertNull(remappedTextNode);
// Check unpublish was called
verify(publishAnyChannelType)
.unpublish(eq(mappedTextNode), anyMap());
// Check can get unpublish event.
String protocol = textNode.getStoreRef().getProtocol();
String storeId = textNode.getStoreRef().getIdentifier();
String nodeId = textNode.getId();
String textNodeUrl = MessageFormat.format(PUBLISHING_EVENTS_URL, protocol, storeId, nodeId);
// Get events on textNode1 before any events created.
Response response = sendRequest(new GetRequest(textNodeUrl), 200);
JSONArray data = getDataArray(response);
List<PublishingEvent> unpublishEvents = publishingService.getUnpublishEventsForNode(textNode);
assertEquals(1, unpublishEvents.size());
PublishingEvent unpublishedEvent = unpublishEvents.get(0);
checkContainsEvent(data, unpublishedEvent.getId());
}
public void testPublishingEventsGet() throws Exception
{
Channel publishChannel = testHelper.createChannel(publishAnyType);
NodeRef textNode1 = testHelper.createContentNode("plain1.txt", "This is some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN);
NodeRef textNode2 = testHelper.createContentNode("plain2.txt", "This is some more plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN);
String protocol = textNode1.getStoreRef().getProtocol();
String storeId = textNode1.getStoreRef().getIdentifier();
String nodeId1 = textNode1.getId();
String textNode1Url = MessageFormat.format(PUBLISHING_EVENTS_URL, protocol, storeId, nodeId1);
// Get events on textNode1 before any events created.
Response response = sendRequest(new GetRequest(textNode1Url), 200);
JSONArray data = getDataArray(response);
assertEquals(0, data.length());
// Create publishing event for textNode1.
String comment = "This is a comment";
PublishingDetails details = publishingService.createPublishingDetails()
.setPublishChannelId(publishChannel.getId())
.addNodesToPublish(textNode1)
.setComment(comment);
String event1Id = testHelper.scheduleEvent1Year(details);
// Query for events on textNode1.
response = sendRequest(new GetRequest(textNode1Url), 200);
data = getDataArray(response);
checkContainsEvents(data, event1Id);
// Query for events on textNode2.
String nodeId2 = textNode2.getId();
String textNode2Url = MessageFormat.format(PUBLISHING_EVENTS_URL, protocol, storeId, nodeId2);
response = sendRequest(new GetRequest(textNode2Url), 200);
data = getDataArray(response);
assertEquals(0, data.length());
// Change to non-Admin user.
personManager.setUser(userName);
// Query for events on textNode1.
response = sendRequest(new GetRequest(textNode1Url), 200);
data = getDataArray(response);
checkContainsEvents(data, event1Id);
// Query for events on textNode2.
response = sendRequest(new GetRequest(textNode2Url), 200);
data = getDataArray(response);
assertEquals(0, data.length());
}
public void testChannelTypesGet() throws Exception
{
Response response = sendRequest(new GetRequest(CHANNEL_TYPES_URL), 200);
JSONArray data = getDataArray(response);
checkChannelTypes(data, channelService.getChannelTypes());
}
private void checkChannelTypes(JSONArray data, List<ChannelType> channelTypes) throws Exception
{
assertEquals(channelTypes.size(), data.length());
for (ChannelType type : channelTypes)
{
checkContainsChannelType(data, type);
}
}
private void checkContainsChannelType(JSONArray data, ChannelType type) throws Exception
{
String typeId = type.getId();
for (int i = 0; i < data.length(); i++)
{
JSONObject json = data.optJSONObject(i);
if (typeId.equals(json.optString(ID)))
{
checkChannelType(json, type);
return;
}
}
fail("Failed to find Channel Type: " + typeId);
}
private void checkContainsEvents(JSONArray data, String... eventIds) throws Exception
{
assertEquals(eventIds.length, data.length());
for (String eventId : eventIds)
{
checkContainsEvent(data, eventId);
}
}
private void checkContainsEvent(JSONArray data, String eventId) throws Exception
{
for (int i = 0; i < data.length(); i++)
{
JSONObject json = data.optJSONObject(i);
if (eventId.equals(json.optString(ID)))
{
PublishingEvent event = publishingService.getPublishingEvent(eventId);
checkJsonEvent(event, json);
return;
}
}
fail("Failed to find Publishing Event: " + eventId);
}
private void checkJsonEvent(PublishingEvent event, JSONObject json) throws Exception
{
String url = "api/publishing/events/" + URLEncoder.encode(event.getId());
assertEquals(url, json.getString(URL));
assertEquals(event.getStatus().name(), json.getString(STATUS));
assertEquals(event.getComment(), json.optString(COMMENT));
checkCalendar(event.getScheduledTime(), json.optJSONObject(SCHEDULED_TIME));
assertEquals(event.getCreator(), json.getString(CREATOR));
checkDate(event.getCreatedTime(), json.getJSONObject(CREATED_TIME));
PublishingPackage pckg = event.getPackage();
checkContainsNodes(pckg, json.getJSONArray(PUBLISH_NODES), true);
checkContainsNodes(pckg, json.getJSONArray(UNPUBLISH_NODES), false);
Channel channel = channelService.getChannelById(event.getChannelId());
checkChannel(json.getJSONObject(CHANNEL), channel);
}
private void checkContainsNodes(PublishingPackage pckg, JSONArray json, boolean isPublish) throws JSONException
{
Collection<NodeRef> nodes = isPublish ? pckg.getNodesToPublish() : pckg.getNodesToUnpublish();
checkContainsNodes(nodes, pckg.getEntryMap(), json);
}
private void checkContainsNodes(Collection<NodeRef> nodes, Map<NodeRef, PublishingPackageEntry> entryMap, JSONArray json) throws JSONException
{
assertEquals(nodes.size(), json.length());
for (NodeRef node : nodes)
{
checkContainsNode(entryMap.get(node), json);
}
}
private void checkContainsNode(PublishingPackageEntry entry, JSONArray jsonArray) throws JSONException
{
String nodeId = entry.getNodeRef().toString();
for (int i = 0; i < jsonArray.length(); i++)
{
JSONObject json = jsonArray.getJSONObject(i);
if (nodeId.equals(json.getString(NODE_REF)))
{
checkNode(entry, json);
return;
}
}
fail("NodeRef was not found!");
}
private void checkNode(PublishingPackageEntry entry, JSONObject json) throws JSONException
{
NodeSnapshot snapshot = entry.getSnapshot();
String version = snapshot.getVersion();
if (version != null && version.isEmpty() == false)
{
assertEquals(version, json.getString(VERSION));
}
String name = (String) snapshot.getProperties().get(ContentModel.PROP_NAME);
if (name != null && name.isEmpty() == false)
{
assertEquals(name, json.getString(NAME));
}
}
private void checkCalendar(Calendar calendar, JSONObject json) throws JSONException
{
checkDate(calendar.getTime(), json);
String timeZone = calendar.getTimeZone().getID();
assertEquals(timeZone, json.getString(WebScriptUtil.TIME_ZONE));
}
private void checkDate(Date date, JSONObject json) throws JSONException
{
assertEquals(WebScriptUtil.ISO8601, json.getString(WebScriptUtil.FORMAT));
String dateStr = json.getString(WebScriptUtil.DATE_TIME);
Date actualDate = ISO8601DateFormat.parse(dateStr);
assertEquals(date, actualDate);
}
private JSONObject buildScheduleEventJson(NodeRef node, Channel publishChannel,
String comment, String statusMessage,
boolean publish, Channel... statusChannels) throws JSONException
{
JSONObject json = new JSONObject();
json.put(CHANNEL_ID, publishChannel.getId());
json.put(COMMENT, comment);
Collection<String> publishNodes = Collections.singleton(node.toString());
if (publish)
{
json.put(PUBLISH_NODES, publishNodes);
}
else
{
json.put(UNPUBLISH_NODES, publishNodes);
}
if (statusMessage != null)
{
json.put(STATUS_UPDATE, buildStatusUpdate(statusMessage, node, statusChannels));
}
return json;
}
private JSONObject buildStatusUpdate(String message, NodeRef textNode, Channel... theChannels) throws JSONException
{
Function<Channel, String> transformer = new Function<Channel, String>()
{
public String apply(Channel channel)
{
return channel.getId();
}
};
List<String> ids = CollectionUtils.transform(transformer, theChannels);
JSONObject statusUpdate = new JSONObject();
statusUpdate.put(MESSAGE, message);
statusUpdate.put(NODE_REF, textNode.toString());
statusUpdate.put(CHANNEL_IDS, ids);
return statusUpdate;
}
private void checkChannels(JSONArray json, Channel... theChannels)throws Exception
{
for (Channel channel : theChannels)
{
checkContainsChannel(json, channel);
}
}
private void checkContainsChannel(JSONArray json, Channel channel) throws Exception
{
for (int i = 0; i < json.length(); i++)
{
JSONObject jsonChannel = json.getJSONObject(i);
String name = jsonChannel.getString(NAME);
if (channel.getName().equals(name))
{
checkChannel(jsonChannel, channel);
return;
}
}
fail("Json did not contain channel: " + channel.getName());
}
private void checkChannel(JSONObject jsonChannel, Channel channel) throws Exception
{
NodeRef node = channel.getNodeRef();
StoreRef storeRef = node.getStoreRef();
check(ID, jsonChannel, channel.getId());
String expUrl = "api/publishing/channels/"
+ storeRef.getProtocol() + "/"
+ storeRef.getIdentifier() + "/"
+ node.getId();
check(URL, jsonChannel, expUrl);
check(TITLE, jsonChannel, channel.getName());
check(CAN_PUBLISH, jsonChannel, channel.canPublish());
check(CAN_UNPUBLISH, jsonChannel, channel.canUnpublish());
check(CAN_PUBLISH_STATUS_UPDATES, jsonChannel, channel.canPublishStatusUpdates());
check(CHANNEL_AUTH_STATUS, jsonChannel, channel.isAuthorised());
JSONObject jsonType = jsonChannel.getJSONObject(CHANNEL_TYPE);
assertNotNull("The channel type is null!", jsonType);
checkChannelType(jsonType, channel.getChannelType());
}
private void checkChannelType(JSONObject jsonType, ChannelType channelType) throws Exception
{
check(ID, jsonType, channelType.getId());
check(TITLE, jsonType, channelType.getId());
String expUrl = "api/publishing/channel-types/"+URLEncoder.encode(channelType.getId());
check(URL, jsonType, expUrl);
check(CHANNEL_NODE_TYPE, jsonType, channelType.getChannelNodeType().toString());
List<String> contentTypes = CollectionUtils.toListOfStrings(channelType.getSupportedContentTypes());
checkStrings(jsonType.getJSONArray(SUPPORTED_CONTENT_TYPES), contentTypes);
checkStrings(jsonType.getJSONArray(SUPPORTED_MIME_TYPES), channelType.getSupportedMimeTypes());
check(CAN_PUBLISH, jsonType, channelType.canPublish());
check(CAN_PUBLISH_STATUS_UPDATES, jsonType, channelType.canPublishStatusUpdates());
check(CAN_UNPUBLISH, jsonType, channelType.canUnpublish());
check(MAX_STATUS_LENGTH, jsonType, channelType.getMaximumStatusLength());
//TODO Implement Icon URL
check(ICON, jsonType, expUrl + "/icon");
}
private void check(String key, JSONObject json, Object exp)
{
Object actual = json.opt(key);
if (exp instanceof String && actual instanceof String)
{
exp = exp.toString().toLowerCase();
actual = actual.toString().toLowerCase();
}
assertEquals("Comparing "+key, exp, actual);
}
private void checkStrings(JSONArray json, Collection<String> strings) throws Exception
{
assertEquals(strings.size(), json.length());
for (String string : strings)
{
checkContains(json, string);
}
}
private void checkContains(JSONArray json, String string) throws Exception
{
for (int i = 0; i < json.length(); i++)
{
if (string.equals(json.getString(i)))
{
return;
}
}
fail("Did not contain " + string);
}
private JSONObject getJsonData(Response response) throws Exception
{
JSONObject json = getJson(response);
JSONObject data = json.getJSONObject("data");
assertNotNull("Data was null!", data);
return data;
}
public JSONArray getDataArray(Response response) throws Exception
{
JSONObject json = getJson(response);
JSONArray data = json.getJSONArray("data");
assertNotNull("Data was null!", data);
return data;
}
private JSONObject getJson(Response response) throws UnsupportedEncodingException, JSONException
{
String jsonStr = response.getContentAsString();
assertNotNull("The JSON is null!", jsonStr);
return new JSONObject(jsonStr);
}
@Override
protected void setUp() throws Exception
{
super.setUp();
ApplicationContext ctx = getServer().getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
SiteService siteService = serviceRegistry.getSiteService();
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
this.nodeService = serviceRegistry.getNodeService();
this.permissionService= serviceRegistry.getPermissionService();
this.channelService = (ChannelService) ctx.getBean(ChannelServiceImpl.NAME);
this.publishingService= (PublishingService) ctx.getBean(PublishServiceImpl.NAME);
this.channelHelper = (ChannelHelper) ctx.getBean(ChannelHelper.NAME);
this.testHelper = new PublishingTestHelper(channelService, publishingService, siteService, fileFolderService, permissionService);
MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
PersonService personService = serviceRegistry.getPersonService();
this.personManager = new TestPersonManager(authenticationService, personService, nodeService);
personManager.createPerson(userName);
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
ChannelType publishAny = testHelper.mockChannelType(publishAnyType);
when(publishAny.canPublish()).thenReturn(true);
when(publishAny.canUnpublish()).thenReturn(true);
ChannelType publishPdf= testHelper.mockChannelType(publishPdfType);
when(publishPdf.canPublish()).thenReturn(true);
when(publishPdf.getSupportedMimeTypes()).thenReturn(Collections.singleton(MimetypeMap.MIMETYPE_PDF));
ChannelType statusUpdate= testHelper.mockChannelType(statusUpdateType);
when(statusUpdate.canPublishStatusUpdates()).thenReturn(true);
when(statusUpdate.getMaximumStatusLength()).thenReturn(maxStatusLength);
}
@Override
public void tearDown() throws Exception
{
try
{
testHelper.tearDown();
}
finally
{
super.tearDown();
}
}
}