diff --git a/l10n.properties b/l10n.properties index 35fda75acf..ecba98738c 100644 --- a/l10n.properties +++ b/l10n.properties @@ -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" diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java deleted file mode 100644 index a8e5e00fb5..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java +++ /dev/null @@ -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 . - * #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 executeImpl(WebScriptRequest req, Status status, Cache cache) - { - Map templateVars = req.getServiceMatch().getTemplateVars(); - Map params = new TreeMap(); - Map headers = new TreeMap(); - - 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 model = new TreeMap(); - model.put("authStatus", authStatus.name()); - return model; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java deleted file mode 100644 index 54537ef1ef..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java +++ /dev/null @@ -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 . - * #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 executeImpl(WebScriptRequest req, Status status, Cache cache) - { - Map 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 model = new TreeMap(); - - if (channel == null) - { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Channel not found - " + channelNodeRef); - } - else - { - model.put("channel", channel); - } - return model; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java deleted file mode 100644 index 45d990d03b..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java +++ /dev/null @@ -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 . - * #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 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 model = new TreeMap(); - model.put("authoriseUrl", authoriseUrl); - model.put("channelId", channel.getId()); - model.put("authCallbackUrl", alfrescoCallbackUrl); - model.put("authRedirectUrl", authUrlPair.authorisationRedirectUrl); - return model; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java deleted file mode 100644 index eae111c769..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java +++ /dev/null @@ -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 . - * #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 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; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java deleted file mode 100644 index 07ce97912d..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java +++ /dev/null @@ -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 . - * #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 executeImpl(WebScriptRequest req, Status status, Cache cache) - { - Map 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); - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java deleted file mode 100644 index f7f49d56a4..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java +++ /dev/null @@ -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 . - * #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 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(); - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java deleted file mode 100644 index 89efdee70d..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java +++ /dev/null @@ -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 . - * #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 executeImpl(WebScriptRequest req, Status status, Cache cache) - { - List types = channelService.getChannelTypes(); - List> channelTypesModel = builder.buildChannelTypes(types); - return WebScriptUtil.createBaseModel(channelTypesModel); - } - - /** - * @param channelService the channelService to set - */ - public void setChannelService(ChannelService channelService) - { - this.channelService = channelService; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java deleted file mode 100644 index 8415f0cf75..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java +++ /dev/null @@ -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 . - * #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 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); - } - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java deleted file mode 100644 index 0f8ca927db..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java +++ /dev/null @@ -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 . - * #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 executeImpl(WebScriptRequest req, Status status, Cache cache) - { - Map params = req.getServiceMatch().getTemplateVars(); - NodeRef node = WebScriptUtil.getNodeRef(params); - - List publishingChannels; - List statusUpdateChannels; - if (node == null) - { - publishingChannels = channelService.getPublishingChannels(false); - statusUpdateChannels = channelService.getStatusUpdateChannels(false); - } - else - { - publishingChannels = channelService.getRelevantPublishingChannels(node); - statusUpdateChannels = channelService.getStatusUpdateChannels(true); - } - - Map model = new HashMap(); - - //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; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java deleted file mode 100644 index 9bdcd0fb92..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java +++ /dev/null @@ -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 . - * #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 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); - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingEventsGet.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingEventsGet.java deleted file mode 100644 index a8e8402af5..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingEventsGet.java +++ /dev/null @@ -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 . - * #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 executeImpl(WebScriptRequest req, Status status, Cache cache) - { - Map 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 events = getSortedPublishingEvents(node); - List> 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 getSortedPublishingEvents(NodeRef node) - { - List publishedEvents = publishingService.getPublishEventsForNode(node); - List unpublishedEvents = publishingService.getUnpublishEventsForNode(node); - ArrayList allEvents = new ArrayList(publishedEvents); - allEvents.addAll(unpublishedEvents); - Collections.sort(allEvents); - return allEvents; - } -} \ No newline at end of file diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java deleted file mode 100644 index 2cb728c45b..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java +++ /dev/null @@ -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 . - * #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 toNodes(JSONArray json) - { - Function transformer = NodeUtils.toNodeRef(); - return JsonUtils.transform(json, transformer); - } - - private List toStrings(JSONArray json) - { - if (json == null || json.length() == 0) - { - return Collections.emptyList(); - } - ArrayList results = new ArrayList(json.length()); - for (int i = 0; i < json.length(); i++) - { - results.add(json.optString(i)); - } - return results; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java deleted file mode 100644 index be172df2b9..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java +++ /dev/null @@ -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 . - * #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 buildPublishingEventForNode(PublishingEvent event, NodeRef node, ChannelService channelService) - { - Map 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> buildPublishingEventsForNode(List events, - final NodeRef node, final ChannelService channelService) - { - return transform(events, new Function>() - { - public Map apply(PublishingEvent event) - { - return buildPublishingEventForNode(event, node, channelService); - } - }); - } - - public Map buildPublishingEvent(PublishingEvent event, ChannelService channelService) - { - Map model = new HashMap(); - 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> buildPublishingEvents(List events, - final ChannelService channelService) - { - return transform(events, new Function>() - { - public Map apply(PublishingEvent event) - { - return buildPublishingEvent(event, channelService); - } - }); - } - - public Map buildChannel(Channel channel) - { - Map model = new HashMap(); - 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> buildChannels(List channels) - { - return transform(channels, new Function>() - { - public Map apply(Channel value) - { - return buildChannel(value); - } - }); - } - - public Map buildChannelType(ChannelType type) - { - Map model = new HashMap(); - 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> buildChannelTypes(List types) - { - return transform(types, new Function>() - { - public Map 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> buildNodes(PublishingPackage pckg, boolean isPublish) - { - Collection nodes = isPublish ? pckg.getNodesToPublish() : pckg.getNodesToUnpublish(); - return buildNodes(pckg, nodes); - } - - private List> buildNodes(PublishingPackage pckg, Collection nodes) - { - List> results = new ArrayList>(nodes.size()); - Map entryMap = pckg.getEntryMap(); - for (NodeRef node : nodes) - { - PublishingPackageEntry entry = entryMap.get(node); - results.add(buildPackageEntry(entry)); - } - return results; - } - - private Map buildPackageEntry(PublishingPackageEntry entry) - { - Map model = new HashMap(); - 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; - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java deleted file mode 100644 index e5aa34501d..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java +++ /dev/null @@ -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 . - * #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 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 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); - } - } -} diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java deleted file mode 100644 index 5faab3db72..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java +++ /dev/null @@ -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 . - * #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; - } -} \ No newline at end of file diff --git a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java b/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java deleted file mode 100644 index 69fce994c4..0000000000 --- a/src/main/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java +++ /dev/null @@ -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 . - * #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"; -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/auth-response.lib.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/auth-response.lib.ftl deleted file mode 100644 index 8cc800d333..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/auth-response.lib.ftl +++ /dev/null @@ -1,47 +0,0 @@ -<#-- Renders the HTML response to a completed Auth Request --> -<#macro htmlPage> - - - - - - - Alfresco » Authorisation - - - - Alfresco -

Publishing Channel Authorisation

-

Completing your authorisation...

- - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authcallback.get.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authcallback.get.desc.xml deleted file mode 100644 index e832d645d1..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authcallback.get.desc.xml +++ /dev/null @@ -1,25 +0,0 @@ - - Authorisation Callback - - - /api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authcallback - - user - required - - - store_protocol - The protocol of the store in which the relevant publishing channel lives. - - - store_id - The identifier of the store in which the relevant publishing channel lives. - - - node_id - The identifier of the node that represents the relevant publishing channel. - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authcallback.get.html.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authcallback.get.html.ftl deleted file mode 100644 index 09f481bcf2..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authcallback.get.html.ftl +++ /dev/null @@ -1,2 +0,0 @@ -<#import "auth-response.lib.ftl" as authResponse /> -<@authResponse.htmlPage /> \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.desc.xml deleted file mode 100644 index f8825f917a..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.desc.xml +++ /dev/null @@ -1,24 +0,0 @@ - - Channel Authorisation Form - - /api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authform - - user - required - - - store_protocol - The protocol of the store in which the relevant publishing channel lives. - - - store_id - The identifier of the store in which the relevant publishing channel lives. - - - node_id - The identifier of the node that represents the relevant publishing channel. - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.html.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.html.ftl deleted file mode 100644 index f085b76d71..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.html.ftl +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - ${msg("authForm.title")} - - - - Alfresco -

${msg("authForm.heading", channel.name)}

-

${msg("authForm.directions", channel.name)}

-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.properties deleted file mode 100644 index f6894d4738..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » 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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_de.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_de.properties deleted file mode 100755 index 3040f857d6..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_de.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » 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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_es.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_es.properties deleted file mode 100755 index 8acc3d5240..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_es.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » 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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_fr.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_fr.properties deleted file mode 100755 index eb573a320f..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_fr.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » 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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_it.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_it.properties deleted file mode 100755 index 27471a1a86..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_it.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » 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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_ja.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_ja.properties deleted file mode 100755 index 065c51f1c3..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_ja.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » \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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_nb.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_nb.properties deleted file mode 100755 index c9e20fcced..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_nb.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » Detaljer om kanalgodkjenning -authForm.heading=Kanalgodkjenning -authForm.directions=Angi brukernavn og passord for {0} -authForm.user=Brukernavn: -authForm.password=Passord: -authForm.login=Logg inn diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_nl.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_nl.properties deleted file mode 100755 index cf969f06e3..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_nl.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » kanaalverificatiegegevens -authForm.heading=Kanaalverificatie -authForm.directions=Voer uw gebruikersnaam en wachtwoord in voor {0} -authForm.user=Gebruikersnaam: -authForm.password=Wachtwoord: -authForm.login=Aanmelden diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_pt_BR.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_pt_BR.properties deleted file mode 100644 index ce27720ca8..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_pt_BR.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Detalhes de autentica\u00e7\u00e3o de canal do Alfresco » -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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_ru.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_ru.properties deleted file mode 100755 index 2a3abdc493..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_ru.properties +++ /dev/null @@ -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 » -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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_zh_CN.properties b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_zh_CN.properties deleted file mode 100755 index d80e3377d6..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.get_zh_CN.properties +++ /dev/null @@ -1,6 +0,0 @@ -authForm.title=Alfresco » \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 diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.post.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.post.desc.xml deleted file mode 100644 index ce6d42014f..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.post.desc.xml +++ /dev/null @@ -1,24 +0,0 @@ - - Channel Authorisation Form - - /api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authform - - user - required - - - store_protocol - The protocol of the store in which the relevant publishing channel lives. - - - store_id - The identifier of the store in which the relevant publishing channel lives. - - - node_id - The identifier of the node that represents the relevant publishing channel. - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.post.html.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.post.html.ftl deleted file mode 100644 index 09f481bcf2..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/authform.post.html.ftl +++ /dev/null @@ -1,2 +0,0 @@ -<#import "auth-response.lib.ftl" as authResponse /> -<@authResponse.htmlPage /> \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.desc.xml deleted file mode 100644 index 791b08af47..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.desc.xml +++ /dev/null @@ -1,58 +0,0 @@ - - Reauthorise the specified publishing channel - - Response status may be: -
-
200
The body of the response contains the necessary information to continue the reauthorisation process
-
400
invalid data received from caller
-
404
the specified channel cannot be found
-
- Returns three pieces of informtation: -
-
-
channelId
the identifier of the publishing channel
-
authoriseUrl
The URL to send the user to in order for them to authorise access to the channel
-
authCallbackUrl
The URL to return the channel authorisation details to
-
authRedirectUrl
The URL that the channel service provider will try to redirect the user to
-
- ]]>
- /api/publishing/channels/{store_protocol}/{store_id}/{node_id}/reauthorise - - user - required - limited_support - - - store_protocol - The protocol of the store in which the relevant publishing channel lives. - - - store_id - The identifier of the store in which the relevant publishing channel lives. - - - node_id - The identifier of the node that represents the relevant publishing channel. - - - - - json - - - - - -
\ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.json.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.json.ftl deleted file mode 100644 index 15992eb63e..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-reauth.post.json.ftl +++ /dev/null @@ -1,5 +0,0 @@ -<#import "publishing.lib.ftl" as publishLib /> -{ - "data": - <@publishLib.channelAuthJSON /> -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-type-icon.get.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-type-icon.get.desc.xml deleted file mode 100644 index 31f4f4e901..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-type-icon.get.desc.xml +++ /dev/null @@ -1,29 +0,0 @@ - - Get channel type icon - -
-
channelType
mandatory - the channel type for which the icon is required
-
iconSize
mandatory - the size of the icon required. Must be either "16" or "32"
-
- 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. - ]]>
- - /api/publishing/channel-types/{channelType}/icon/{iconSize} - - user - required - limited_support - - - channelType - The identifier of the channel type whose icon is wanted. - - - iconSize - The size (in pixels) of the required icon. Must be either "16" or "32". - - -
\ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.desc.xml deleted file mode 100644 index fd25023a15..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.desc.xml +++ /dev/null @@ -1,40 +0,0 @@ - - Get Publishing Channels - Get the publishing channels for a Share Site.or specified NodeRef - /api/publishing/channel-types - - user - required - limited_support - - - json - - - - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.json.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.json.ftl deleted file mode 100644 index 87d85a360c..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.json.ftl +++ /dev/null @@ -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>, - - - ] -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel.put.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel.put.desc.xml deleted file mode 100644 index 3ff0f2655a..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel.put.desc.xml +++ /dev/null @@ -1,27 +0,0 @@ - - Update Channel - Updates an existing Channel's name. - /api/publishing/channels/{channel_id} - - user - required - limited_support - - - channel_id - The URL-encoded id of the channel to be updated. - - - - - json - - - - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.delete.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.delete.desc.xml deleted file mode 100644 index 80ec997e86..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.delete.desc.xml +++ /dev/null @@ -1,34 +0,0 @@ - - Delete specified publishing channel - - Response status indicates result: -
-
200
deletion successful
-
400
invalid data received from caller
-
401
user doesn't have permission to delete the specified channel
-
404
the specified channel cannot be found
-
- - ]]>
- /api/publishing/channels/{store_protocol}/{store_id}/{node_id} - - user - required - limited_support - - - store_protocol - The protocol of the store in which the relevant publishing channel lives. - - - store_id - The identifier of the store in which the relevant publishing channel lives. - - - node_id - The identifier of the node that represents the relevant publishing channel. - - -
\ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.desc.xml deleted file mode 100644 index 8ba9c03946..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.desc.xml +++ /dev/null @@ -1,97 +0,0 @@ - - Get Publishing Channels - Get the publishing channels for specified NodeRef or returns all Publishing Channels - /api/publishing/channels - /api/publishing/{store_protocol}/{store_id}/{node_id}/channels - - user - required - limited_support - - - store_protocol - The protocol used by the StoreRef to retrieve channels for. - - - store_id - The id of the StoreRef to retrieve channels for. - - - node_id - The id of the NodeRef to retrieve channels for. - - - - - json - - - - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.json.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.json.ftl deleted file mode 100644 index d9be03dc98..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.json.ftl +++ /dev/null @@ -1,12 +0,0 @@ -<#-- List Channels --> -<#import "publishing.lib.ftl" as publishLib /> -{ - "data": - { - <#if data.urlLength??>"urlLength": ${data.urlLength}, - "publishChannels": - <@publishLib.channelsJSON channels=data.publishChannels />, - "statusUpdateChannels": - <@publishLib.channelsJSON channels=data.statusUpdateChannels /> - } -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml deleted file mode 100644 index df66dc5e1a..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.desc.xml +++ /dev/null @@ -1,60 +0,0 @@ - - Create a publishing channel - -
-
channelType
mandatory - the type of delivery channel to create
-
siteId
mandatory - the Share site with which the new delivery channel is to be associated
-
channelName
mandatory - the name of the new delivery channel
-
- Returns three pieces of informtation: -
-
-
channelId
the identifier of the new publishing channel
-
pollUrl
The URL to poll to discover whether the channel has been authorised
-
authoriseUrl
The URL to send the user to in order for them to authorise access to the channel
-
authCallbackUrl
The URL to return the channel authorisation details to
-
authRedirectUrl
The URL to which the channel service provider will redirect the user upon authorisation
-
- - ]]>
- - /api/publishing/channels - - user - required - limited_support - - - siteId - The id of the site to create a delivery channel on. - - - channelType - The identifier of the type of delivery channel to create. - - - channelName - The name of the channel that is to be created. - - - - - json - - - - - -
\ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl deleted file mode 100644 index 685717eabd..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.post.json.ftl +++ /dev/null @@ -1,6 +0,0 @@ -<#-- Response to a request to create a publishing channel --> -<#import "publishing.lib.ftl" as publishLib /> -{ - "data": - <@publishLib.channelAuthJSON /> -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events.get.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events.get.desc.xml deleted file mode 100644 index d01cf640c3..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events.get.desc.xml +++ /dev/null @@ -1,165 +0,0 @@ - - Get Publishing Events For Node - Find all PublishingEvents that publish or unpublish the specified node. - /api/publishing/{store_protocol}/{store_id}/{node_id}/events - - user - required - limited_support - - - store_protocol - The store protocol for the published/unpublished node. - - - store_id - The store id for the published/unpublished node. - - - node_id - The node id for the published/unpublished node. - - - - - json - - - - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events.get.json.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events.get.json.ftl deleted file mode 100644 index ab6b289ccd..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events.get.json.ftl +++ /dev/null @@ -1,6 +0,0 @@ -<#-- List Channels --> -<#import "publishing.lib.ftl" as publishLib /> -{ - "data": - <@publishLib.eventsJSON events=data /> -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml deleted file mode 100644 index a835abe025..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml +++ /dev/null @@ -1,178 +0,0 @@ - - Post Content to Publishing Queue - Place a new Publishing Event on the Publishing Queue.. - /api/publishing/queue - - user - required - limited_support - - - json - - - - - - - - json - - - - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.json.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.json.ftl deleted file mode 100644 index ac66e54bd6..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.json.ftl +++ /dev/null @@ -1,7 +0,0 @@ -<#-- List Channels --> -<#import "publishing.lib.ftl" as publishLib /> -{ - "data": - { - } -} diff --git a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl b/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl deleted file mode 100644 index 34851403fc..0000000000 --- a/src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl +++ /dev/null @@ -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>, - - -] - - - - -<#-- Renders a Publishing Event. --> -<#macro eventJSON event> -{ - "id": "${event.id}", - "url": "${event.url}", - "status": "${event.status}", - <#if event.comment?? >"comment": "${event.comment}", - <#if event.eventType?? >"eventType": "${event.eventType}", - <#if event.scheduledTime?? > - "scheduledTime": - <@calendarJSON calendar=event.scheduledTime />, - - "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}" - -} - - -<#-- 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>, - - -] - - -<#-- Renders a Published/Unpublished Node. --> -<#macro publishNodeJSON node> -{ - <#if node.name?? >"name": "${node.name}", - <#if node.version?? >"version": "${node.version}", - "nodeRef": "${node.nodeRef}" -} - - -<#-- 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>, - - -] - - - -<#-- 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 /> -} - - -<#-- Renders a Channel Type. --> -<#macro channelTypeJSON type> -{ - "id": "${type.id}", - "title": "${type.title}", - "url": "${type.url}", - <#if type.channelNodeType??>"channelNodeType": "${type.channelNodeType}", - <#if type.supportedContentTypes?? > - "supportedContentTypes": - <@iterateStringsJSON strings=type.supportedContentTypes />, - - <#if type.supportedMimeTypes?? > - "supportedMimeTypes": - <@iterateStringsJSON strings=type.supportedMimeTypes/>, - - "canPublish": ${type.canPublish}, - "canPublishStatusUpdates": ${type.canPublishStatusUpdates}, - "canUnpublish": ${type.canUnpublish}, - <#if type.icon??>"icon": "${type.icon}", - "maxStatusLength": ${type.maxStatusLength} -} - - -<#-- Renders a List of Strings. --> -<#macro iterateStringsJSON strings> -<#if strings??> -[ - <#list strings as string> - "${string}" - <#if string_has_next>, - -] -<#else> -[] - - - -<#-- Renders a date. --> -<#macro dateJSON date> -{ - "dateTime": "${date.dateTime}", - "format": "${date.format}" -} - - -<#-- Renders a calendar. --> -<#macro calendarJSON calendar> -{ - "dateTime": "${calendar.dateTime}", - "format": "${calendar.format}", - "timeZone": "${calendar.timeZone}" -} - - -<#-- 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}" - } - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/web-scripts-application-context.xml b/src/main/resources/alfresco/web-scripts-application-context.xml index 292b95d170..4bf49eeb44 100644 --- a/src/main/resources/alfresco/web-scripts-application-context.xml +++ b/src/main/resources/alfresco/web-scripts-application-context.xml @@ -959,100 +959,6 @@ class="org.alfresco.repo.web.scripts.workflow.WorkflowInstanceDelete" parent="abstractWorkflowWebScript"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/java/org/alfresco/AppContext04TestSuite.java b/src/test/java/org/alfresco/AppContext04TestSuite.java index 95e69bcf77..7d4895f3ad 100644 --- a/src/test/java/org/alfresco/AppContext04TestSuite.java +++ b/src/test/java/org/alfresco/AppContext04TestSuite.java @@ -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, diff --git a/src/test/java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java b/src/test/java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java index 9ae49bc4e5..a74d4d4a57 100644 --- a/src/test/java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java +++ b/src/test/java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java @@ -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 ); diff --git a/src/test/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java b/src/test/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java deleted file mode 100644 index 022e73c359..0000000000 --- a/src/test/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java +++ /dev/null @@ -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 . - * #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 events = publishingService.getPublishEventsForNode(textNode); - List ids = CollectionUtils.transform(events, new Function() - { - 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 publishedEvents = publishingService.getPublishEventsForNode(textNode); - - assertEquals(1, publishedEvents.size()); - - PublishingEvent event = publishedEvents.get(0); - assertEquals(publishChannel.getId(), event.getChannelId()); - assertEquals(comment, event.getComment()); - Collection expectedPubEventStatuses = Arrays.asList(Status.SCHEDULED, Status.IN_PROGRESS, Status.COMPLETED); - assertTrue(expectedPubEventStatuses.contains(event.getStatus())); - - // Check Package - PublishingPackage pckg = event.getPackage(); - Set 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 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 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 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 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 nodes = isPublish ? pckg.getNodesToPublish() : pckg.getNodesToUnpublish(); - checkContainsNodes(nodes, pckg.getEntryMap(), json); - } - - private void checkContainsNodes(Collection nodes, Map 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 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 transformer = new Function() - { - public String apply(Channel channel) - { - return channel.getId(); - } - }; - List 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 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 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(); - } - } -}