diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js index a6cb21af1c..098c1d6487 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js @@ -18,4 +18,5 @@ for (userName in memberships) // Pass the information to the template model.site = site; model.memberships = memberships; -model.people = peopleList; \ No newline at end of file +model.people = peopleList; + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.delete.js index 96977b8cda..1eb10784ea 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.delete.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.delete.js @@ -1,16 +1,21 @@ -// Get the shortname -var shortName = url.extension; - -// Get the site -var site = siteService.getSite(shortName); -if (site != null) +function main() { - // Delete the site - site.deleteSite(); + // Get the shortname + var shortName = url.extension; + + // Get the site + var site = siteService.getSite(shortName); + if (site != null) + { + // Delete the site + site.deleteSite(); + } + else + { + // Return 404 + status.setCode(404, "The site " + shortName + " does not exist"); + return; + } } -else -{ - // Return 404 - status.code = 404; - status.redirect = true; -} \ No newline at end of file + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.get.js index a487f4c622..0b17aaca33 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.get.js @@ -1,17 +1,22 @@ -// Get the shortname -var shortName = url.extension; - -// Get the site -var site = siteService.getSite(shortName); - -if (site != null) +function main() { - // Pass the site to the template - model.site = site; + // Get the shortname + var shortName = url.extension; + + // Get the site + var site = siteService.getSite(shortName); + + if (site != null) + { + // Pass the site to the template + model.site = site; + } + else + { + // Return 404 + status.setCode(404, "Site " + shortName + " does not exist"); + return; + } } -else -{ - // Return 404 - status.code = 404; - status.redirect = true; -} \ No newline at end of file + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.put.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.put.js index 27cbc0b125..94f43466dd 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.put.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/site.put.js @@ -1,21 +1,26 @@ -// Get the site -var shortName = url.extension; -var site = siteService.getSite(shortName); - -if (site != null) +function main() { - // Update the sites details - site.title = json.get("title"); - site.description = json.get("description"); - site.isPublic = json.getBoolean("isPublic"); - site.save(); + // Get the site + var shortName = url.extension; + var site = siteService.getSite(shortName); - // Pass the model to the template - model.site = site; + if (site != null) + { + // Update the sites details + site.title = json.get("title"); + site.description = json.get("description"); + site.isPublic = json.getBoolean("isPublic"); + site.save(); + + // Pass the model to the template + model.site = site; + } + else + { + // Return 404 + status.setCode(status.STATUS_NOT_FOUND, "Site " + shortName + " does not exist"); + return; + } } -else -{ - // Return 404 - status.code = 404; - status.redirect = true; -} \ No newline at end of file + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.js index df74dd8f4f..c75e707613 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.js @@ -4,18 +4,14 @@ function main() var shortName = json.get("shortName"); if (shortName == null || shortName.length == 0) { - status.code = 400; - status.message = "Short name missing when creating site."; - status.redirect = true; + status.setCode(status.STATUS_BAD_REQUEST, "Short name missing when creating site"); return; } var sitePreset = json.get("sitePreset"); if (shortName == null || shortName.length == 0) { - status.code = 400; - status.message = "Site preset missing when creating site."; - status.redirect = true; + status.setCode(status.STATUS_BAD_REQUEST, "Site preset missing when creating site"); return; } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.delete.desc.xml new file mode 100644 index 0000000000..714a790cd0 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.delete.desc.xml @@ -0,0 +1,9 @@ + + Thumbnails + Delete a thumbnail for a content resource + /api/node/{store_type}/{store_id}/{id}/content{property?}/thumbnails/{thumbnailname} + /api/path/{store_type}/{store_id}/{id}/content{property?}/thumbnails/{thumbnailname} + + guest + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.desc.xml new file mode 100644 index 0000000000..73604772a5 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.desc.xml @@ -0,0 +1,9 @@ + + Thumbnails + Create a new thumbnail for a content resource + /api/node/{store_type}/{store_id}/{id}/content{property?}/thumbnails + /api/path/{store_type}/{store_id}/{id}/content{property?}/thumbnails + + guest + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.js new file mode 100644 index 0000000000..6f6809752c --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.js @@ -0,0 +1,29 @@ +function main() +{ + // Get the node from the URL + var pathSegments = url.match.split("/"); + var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); + var node = search.findNode(pathSegments[2], reference); + + // 404 if the node to thumbnail is not found + if (node == null) + { + status.setCode(status.STATUS_NOT_FOUND, "The thumbnail source node could not be found"); + return; + } + + // Get the thumbnail name from the JSON content + var thumbnailName = pathSegments[8]; + + // 404 if no thumbnail name found + if (thumbnailName == null) + { + status.setCode(status.STATUS_NOT_FOUND, "Thumbnail name was not provided"); + } + + // Get the thumbnail ... + + +} + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.desc.xml new file mode 100644 index 0000000000..915a27edc8 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.desc.xml @@ -0,0 +1,9 @@ + + Thumbnails + Update a thumbnail for a content resource + /api/node/{store_type}/{store_id}/{id}/content{property?}/thumbnails/{thumbnailname} + /api/path/{store_type}/{store_id}/{id}/content{property?}/thumbnails/{thumbnailname} + + guest + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml new file mode 100644 index 0000000000..b4f3b480da --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml @@ -0,0 +1,9 @@ + + Thumbnails + Get a named thumbnail for a content resource + /api/node/{store_type}/{store_id}/{id}/content{property?}/thumbnails/{thumbnailname} + /api/path/{store_type}/{store_id}/{id}/content{property?}/thumbnails/{thumbnailname} + + guest + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.desc.xml new file mode 100644 index 0000000000..ffd9b01018 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.desc.xml @@ -0,0 +1,9 @@ + + Thumbnails + Create a new thumbnail for a content resource + /api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails + /api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails + + guest + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.js new file mode 100644 index 0000000000..4880e3beb6 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.js @@ -0,0 +1,40 @@ +function main() +{ + // Get the node from the URL + var pathSegments = url.match.split("/"); + var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); + var node = search.findNode(pathSegments[2], reference); + + // 404 if the node to thumbnail is not found + if (node == null) + { + status.setCode(status.STATUS_NOT_FOUND, "The thumbnail source node could not be found"); + return; + } + + // Get the thumbnail name from the JSON content + var thumbnailName = null; + if (json.isNull("thumbnailName") == false) + { + thumbnailName = json.get("thumbnailName"); + } + + // 400 if no thumbnail name found + if (thumbnailName == null) + { + status.setCode(status.STATUS_BAD_REQUEST, "Thumbnail name was not provided"); + } + + // TODO double check that the thumbnail name is valid + + // Create the thumbnail + var thumbnail = node.createThumbnail(thumbnailName); + + // Prep the model + model.node = node; + model.thumbnailName = thumbnailName; + model.thumbnail = thumbnail; + +} + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.json.ftl new file mode 100644 index 0000000000..cca01a660f --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.post.json.ftl @@ -0,0 +1,4 @@ +{ + "thumbnailName" : "${thumbnailName}", + "url" : "${url.serviceContext}/api/node/${node.storeType}/${node.storeId}/${node.id}/content/thumbnails/${thumbnailName}" +} \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index c2f2b51e44..ab67c59a3f 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -77,18 +77,7 @@ - - - - - - - - - - ${spaces.store} - /${spaces.company_home.childname} - + @@ -114,7 +103,7 @@ - + @@ -199,7 +188,7 @@ - + diff --git a/source/java/org/alfresco/repo/web/scripts/Repository.java b/source/java/org/alfresco/repo/web/scripts/Repository.java deleted file mode 100644 index 8ceb632531..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/Repository.java +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright (C) 2005-2008 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program 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 General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletResponse; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.repo.tenant.TenantDeployer; -import org.alfresco.repo.tenant.TenantDeployerService; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.avm.AVMNodeDescriptor; -import org.alfresco.service.cmr.avm.AVMService; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.model.FileNotFoundException; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.util.AbstractLifecycleBean; -import org.alfresco.web.scripts.WebScriptException; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; - - -/** - * Provision of Repository Context - * - * @author davidc - */ -public class Repository implements ApplicationContextAware, ApplicationListener, TenantDeployer -{ - private ProcessorLifecycle lifecycle = new ProcessorLifecycle(); - - // dependencies - private RetryingTransactionHelper retryingTransactionHelper; - private NamespaceService namespaceService; - private SearchService searchService; - private NodeService nodeService; - private FileFolderService fileFolderService; - private PersonService personService; - private AVMService avmService; - private TenantDeployerService tenantDeployerService; - - // company home - private StoreRef companyHomeStore; - private String companyHomePath; - private Map companyHomeRefs; - - - /** - * Sets the Company Home Store - * - * @param companyHomeStore - */ - public void setCompanyHomeStore(String companyHomeStore) - { - this.companyHomeStore = new StoreRef(companyHomeStore); - } - - /** - * Sets the Company Home Path - * - * @param companyHomePath - */ - public void setCompanyHomePath(String companyHomePath) - { - this.companyHomePath = companyHomePath; - } - - /** - * Sets helper that provides transaction callbacks - */ - public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) - { - this.retryingTransactionHelper = retryingTransactionHelper; - } - - /** - * Sets the namespace service - * - * @param namespaceService - */ - public void setNamespaceService(NamespaceService namespaceService) - { - this.namespaceService = namespaceService; - } - - /** - * Sets the search service - * - * @param searchService - */ - public void setSearchService(SearchService searchService) - { - this.searchService = searchService; - } - - /** - * Sets the node service - * - * @param nodeService - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - /** - * Sets the file folder service - * - * @param nodeService - */ - public void setFileFolderService(FileFolderService fileFolderService) - { - this.fileFolderService = fileFolderService; - } - - /** - * Sets the person service - * - * @param personService - */ - public void setPersonService(PersonService personService) - { - this.personService = personService; - } - - /** - * Sets the tenant deployer service - * - * @param tenantDeployerService - */ - public void setTenantDeployerService(TenantDeployerService tenantDeployerService) - { - this.tenantDeployerService = tenantDeployerService; - } - - /** - * Sets the AVM service - * - * @param avmService - */ - public void setAvmService(AVMService avmService) - { - this.avmService = avmService; - } - - /* (non-Javadoc) - * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) - */ - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException - { - lifecycle.setApplicationContext(applicationContext); - } - - /* (non-Javadoc) - * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) - */ - public void onApplicationEvent(ApplicationEvent event) - { - lifecycle.onApplicationEvent(event); - } - - /** - * Hooks into Spring Application Lifecycle - */ - private class ProcessorLifecycle extends AbstractLifecycleBean - { - @Override - protected void onBootstrap(ApplicationEvent event) - { - initContext(); - } - - @Override - protected void onShutdown(ApplicationEvent event) - { - } - } - - /** - * Initialise Repository Context - */ - protected void initContext() - { - tenantDeployerService.register(this); - - if (companyHomeRefs == null) - { - companyHomeRefs = new HashMap(1); - } - - getCompanyHome(); - } - - - /** - * Gets the root home of the company home store - * - * @return root node ref - */ - public NodeRef getRootHome() - { - return nodeService.getRootNode(companyHomeStore); - } - - /** - * Gets the Company Home - * - * @return company home node ref - */ - public NodeRef getCompanyHome() - { - String tenantDomain = tenantDeployerService.getCurrentUserDomain(); - NodeRef companyHomeRef = companyHomeRefs.get(tenantDomain); - if (companyHomeRef == null) - { - companyHomeRef = AuthenticationUtil.runAs(new RunAsWork() - { - public NodeRef doWork() throws Exception - { - return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - public NodeRef execute() throws Exception - { - List refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false); - if (refs.size() != 1) - { - throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size()); - } - return refs.get(0); - } - }); - } - }, AuthenticationUtil.getSystemUserName()); - - companyHomeRefs.put(tenantDomain, companyHomeRef); - } - return companyHomeRef; - } - - /** - * Gets the currently authenticated person - * - * @return person node ref - */ - public NodeRef getPerson() - { - NodeRef person = null; - String currentUserName = AuthenticationUtil.getCurrentUserName(); - if (personService.personExists(currentUserName)) - { - person = personService.getPerson(currentUserName); - } - return person; - } - - /** - * Gets the user home of the currently authenticated person - * - * @param person person - * @return user home of person - */ - public NodeRef getUserHome(NodeRef person) - { - return (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER); - } - - /** - * Helper to convert a Web Script Request URL to a Node Ref - * - * 1) Node - {store_type}/{store_id}/{node_id} - * - * Resolve to node via its Node Reference. - * - * 2) Path - {store_type}/{store_id}/{path} - * - * Resolve to node via its display path. - * - * 3) AVM Path - {store_id}/{path} - * - * Resolve to AVM node via its display path - * - * 4) QName - {store_type}/{store_id}/{child_qname_path} TODO: Implement - * - * Resolve to node via its child qname path. - * - * @param referenceType one of node, path, avmpath or qname - * @return reference array of reference segments (as described above for each reference type) - */ - public NodeRef findNodeRef(String referenceType, String[] reference) - { - NodeRef nodeRef = null; - - if (referenceType.equals("avmpath")) - { - if (reference.length == 0) - { - throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Reference " + Arrays.toString(reference) + " is not properly formed"); - } - String path = reference[0] + ":/"; - if (reference.length > 1) - { - Object[] pathElements = ArrayUtils.subarray(reference, 1, reference.length); - path += StringUtils.join(pathElements, "/"); - } - AVMNodeDescriptor nodeDesc = avmService.lookup(-1, path); - if (nodeDesc != null) - { - nodeRef = AVMNodeConverter.ToNodeRef(-1, path); - } - } - else - { - // construct store reference - if (reference.length < 3) - { - throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Reference " + Arrays.toString(reference) + " is not properly formed"); - } - StoreRef storeRef = new StoreRef(reference[0], reference[1]); - if (nodeService.exists(storeRef)) - { - if (referenceType.equals("node")) - { - // find the node the rest of the path is relative to - NodeRef relRef = new NodeRef(storeRef, reference[2]); - if (nodeService.exists(relRef)) - { - // are there any relative path elements to process? - if (reference.length == 3 || reference.length == 4) - { - // just the NodeRef can be specified - nodeRef = relRef; - } - else - { - // process optional path elements - List paths = new ArrayList(reference.length - 3); - for (int i=3; i 2) - { - Object[] pathElements = ArrayUtils.subarray(reference, 2, reference.length); - path += StringUtils.join(pathElements, "/"); - } - AVMNodeDescriptor nodeDesc = avmService.lookup(-1, path); - if (nodeDesc != null) - { - nodeRef = AVMNodeConverter.ToNodeRef(-1, path); - } - } - else - { - // TODO: Allow a root path to be specified - for now, hard-code to Company Home - //NodeRef rootNodeRef = nodeService.getRootNode(storeRef); - NodeRef rootNodeRef = getCompanyHome(); - if (reference.length == 3) - { - nodeRef = rootNodeRef; - } - else - { - String[] path = new String[reference.length - /*2*/3]; - System.arraycopy(reference, /*2*/3, path, 0, path.length); - - try - { - FileInfo fileInfo = fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(path)); - nodeRef = fileInfo.getNodeRef(); - } - catch (FileNotFoundException e) - { - // NOTE: return null node ref - } - } - } - } - - else - { - // TODO: Implement 'qname' style - throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script Node URL specified an invalid reference style of '" + referenceType + "'"); - } - } - } - - return nodeRef; - } - - /* (non-Javadoc) - * @see org.alfresco.repo.tenant.TenantDeployer#onEnableTenant() - */ - public void onEnableTenant() - { - init(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.tenant.TenantDeployer#onDisableTenant() - */ - public void onDisableTenant() - { - destroy(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.tenant.TenantDeployer#init() - */ - public void init() - { - initContext(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.tenant.TenantDeployer#destroy() - */ - public void destroy() - { - companyHomeRefs.remove(tenantDeployerService.getCurrentUserDomain()); - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java b/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java index 56f2600386..1b7acd54ec 100644 --- a/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java +++ b/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java @@ -31,6 +31,7 @@ import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.tenant.TenantDeployer; import org.alfresco.repo.tenant.TenantDeployerService; diff --git a/source/java/org/alfresco/repo/web/scripts/bean/ContentGet.java b/source/java/org/alfresco/repo/web/scripts/bean/ContentGet.java index 8ac63a248a..877aaacb94 100644 --- a/source/java/org/alfresco/repo/web/scripts/bean/ContentGet.java +++ b/source/java/org/alfresco/repo/web/scripts/bean/ContentGet.java @@ -35,7 +35,7 @@ import javax.servlet.http.HttpServletResponse; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.web.scripts.Repository; +import org.alfresco.repo.model.Repository; import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; diff --git a/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java b/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java new file mode 100644 index 0000000000..66fe309250 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.thumbnail; + +import java.io.InputStream; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.model.Repository; +import org.alfresco.repo.web.scripts.BaseWebScriptTest; +import org.alfresco.service.cmr.model.FileFolderService; +import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.util.GUID; +import org.json.JSONObject; +import org.springframework.mock.web.MockHttpServletResponse; + +/** + * Unit test to test thumbnail web script API + * + * @author Roy Wetherall + */ +public class ThumbnailServiceTest extends BaseWebScriptTest +{ + private NodeRef testRoot; + private NodeRef pdfNode; + private NodeRef jpgNode; + + private NodeService nodeService; + private FileFolderService fileFolderService; + private ContentService contentService; + private Repository repositoryHelper; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService"); + this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService"); + this.contentService = (ContentService)getServer().getApplicationContext().getBean("ContentService"); + this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper"); + + this.testRoot = this.repositoryHelper.getCompanyHome(); + + // Get test content + InputStream pdfStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf"); + assertNotNull(pdfStream); + InputStream jpgStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_image.jpg"); + assertNotNull(jpgStream); + + String guid = GUID.generate(); + + // Create new nodes and set test content + FileInfo fileInfoPdf = this.fileFolderService.create(this.testRoot, "test_doc" + guid + ".pdf", ContentModel.TYPE_CONTENT); + this.pdfNode = fileInfoPdf.getNodeRef(); + ContentWriter contentWriter = this.contentService.getWriter(fileInfoPdf.getNodeRef(), ContentModel.PROP_CONTENT, true); + contentWriter.setEncoding("UTF-8"); + contentWriter.setMimetype(MimetypeMap.MIMETYPE_PDF); + contentWriter.putContent(pdfStream); + + FileInfo fileInfoJpg = this.fileFolderService.create(this.testRoot, "test_image" + guid + ".jpg", ContentModel.TYPE_CONTENT); + this.jpgNode = fileInfoJpg.getNodeRef(); + contentWriter = this.contentService.getWriter(fileInfoJpg.getNodeRef(), ContentModel.PROP_CONTENT, true); + contentWriter.setEncoding("UTF-8"); + contentWriter.setMimetype(MimetypeMap.MIMETYPE_IMAGE_JPEG); + contentWriter.putContent(jpgStream); + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + + } + + public void testCreateThumbnail() throws Exception + { + String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnails"; + System.out.println(url); + + JSONObject tn = new JSONObject(); + tn.put("thumbnailName", "webpreview"); + System.out.println(tn.toString()); + + MockHttpServletResponse response = this.postRequest(url, 200, tn.toString(), "application/json"); + //JSONObject result = new JSONObject(response.getContentAsString()); + + System.out.println(response.getContentAsString()); + } + + + +} diff --git a/source/java/org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf b/source/java/org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf new file mode 100644 index 0000000000..9b033d052b Binary files /dev/null and b/source/java/org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf differ diff --git a/source/java/org/alfresco/repo/web/scripts/thumbnail/test_image.jpg b/source/java/org/alfresco/repo/web/scripts/thumbnail/test_image.jpg new file mode 100644 index 0000000000..6db32ca1db Binary files /dev/null and b/source/java/org/alfresco/repo/web/scripts/thumbnail/test_image.jpg differ