diff --git a/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java b/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java index 31acf5fa14..74b0f2f0f4 100644 --- a/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2017 Alfresco Software Limited + * Copyright (C) 2005 - 2019 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -72,9 +72,6 @@ import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.tenant.TenantUtil; -import org.alfresco.repo.thumbnail.ThumbnailDefinition; -import org.alfresco.repo.thumbnail.ThumbnailHelper; -import org.alfresco.repo.thumbnail.ThumbnailRegistry; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.version.VersionModel; @@ -103,7 +100,6 @@ import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; import org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException; -import org.alfresco.rest.framework.core.exceptions.StaleEntityException; import org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException; import org.alfresco.rest.framework.resource.content.BasicContentInfo; import org.alfresco.rest.framework.resource.content.BinaryResource; @@ -1878,6 +1874,7 @@ public Node createNode(String parentFolderNodeId, Node nodeInfo, Parameters para return newNode; } + @Override public void addCustomAspects(NodeRef nodeRef, List aspectNames, List excludedAspects) { if (aspectNames == null) @@ -2866,6 +2863,7 @@ public Node upload(String parentFolderNodeId, FormData formData, Parameters para String versionComment = null; String relativePath = null; String renditionNames = null; + String aspectNames = null; Map qnameStrProps = new HashMap<>(); Map properties = null; @@ -2923,6 +2921,10 @@ public Node upload(String parentFolderNodeId, FormData formData, Parameters para renditionNames = getStringOrNull(field.getValue()); break; + case "aspectnames": + aspectNames = getStringOrNull(field.getValue()); + break; + default: { final String propName = field.getName(); @@ -2957,7 +2959,8 @@ public Node upload(String parentFolderNodeId, FormData formData, Parameters para // if requested, make (get or create) path parentNodeRef = getOrCreatePath(parentNodeRef, relativePath); final QName assocTypeQName = ContentModel.ASSOC_CONTAINS; - final Set renditions = getRequestedRenditions(renditionNames); + final Set renditions = splitCommaSeparatedString(renditionNames); + final Set aspects = splitCommaSeparatedString(aspectNames); try { @@ -3009,7 +3012,15 @@ else if (overwrite && nodeService.hasAspect(existingFile, ContentModel.ASPECT_VE checkRenditionNames(renditions); requestRenditions(renditions, fileNode); - return fileNode; + if(aspects != null) + { + List aspectsList = new ArrayList<>(aspects); + addCustomAspects(nodeRef, aspectsList, EXCLUDED_ASPECTS); + } + + Node newNode = getFolderOrDocument(nodeRef.getId(), parameters); + + return newNode; // Do not clean formData temp files to allow for retries. // Temp files will be deleted later when GC call DiskFileItem#finalize() method or by temp file cleaner. @@ -3096,25 +3107,25 @@ private void checkRenditionNames(Set renditionNames) } } - static Set getRequestedRenditions(String renditionsParam) + static Set splitCommaSeparatedString(String listString) { - if (renditionsParam == null) + if (listString == null) { return null; } - String[] renditionNames = renditionsParam.split(","); + String[] subValues = listString.split(","); - Set renditions = new LinkedHashSet<>(renditionNames.length); - for (String name : renditionNames) + Set subValuesSet = new LinkedHashSet<>(subValues.length); + for (String name : subValues) { name = name.trim(); if (!name.isEmpty()) { - renditions.add(name.trim()); + subValuesSet.add(name.trim()); } } - return renditions; + return subValuesSet; } private void requestRenditions(Set renditionNames, Node fileNode) diff --git a/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java b/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java index af0a7f5c6c..fae95a4121 100644 --- a/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java +++ b/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java @@ -333,7 +333,7 @@ public void createRenditions(NodeRef nodeRef, List renditions, Parame for (Rendition rendition : renditions) { String name = getName(rendition); - Set requestedRenditions = NodesImpl.getRequestedRenditions(name); + Set requestedRenditions = NodesImpl.splitCommaSeparatedString(name); if (requestedRenditions == null) { renditionNames.add(null); diff --git a/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java b/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java index e4d59805f8..663a290006 100644 --- a/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -2638,6 +2638,28 @@ public void testMultipartFormDataUpload() throws Exception // Upload with multipart with missing boundary e.g. multipart/form-data; boundary=7cgH0q1hSgrlmU7tUe8kGSWT4Un6aRH post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, "multipart/form-data", 415); + + // set aspect which doesn't exist + List aspects = new ArrayList<>(); + aspects.add("hackathon:2019"); + aspects.add("papi:dessertable"); + multiPartBuilder.setAspects(aspects); + reqBody = multiPartBuilder.build(); + post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 400); + + // set aspect which exist + aspects = new ArrayList<>(); + aspects.add("papi:dessertable"); + multiPartBuilder.setAspects(aspects); + reqBody = multiPartBuilder.build(); + HttpResponse response = post(getNodeChildrenUrl(Nodes.PATH_MY), reqBody.getBody(), null, reqBody.getContentType(), 201); + + Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); + + // Check the upload response + assertEquals("quick-1.txt", document.getName()); + assertNotNull(document.getAspectNames()); + assertTrue("Doesn't contains papi:dessertable in aspects", document.getAspectNames().contains("papi:dessertable")); } diff --git a/src/test/java/org/alfresco/rest/api/tests/util/MultiPartBuilder.java b/src/test/java/org/alfresco/rest/api/tests/util/MultiPartBuilder.java index 527d5fa3d9..dbb155e410 100644 --- a/src/test/java/org/alfresco/rest/api/tests/util/MultiPartBuilder.java +++ b/src/test/java/org/alfresco/rest/api/tests/util/MultiPartBuilder.java @@ -278,7 +278,7 @@ public MultiPartRequest build() throws IOException addPartIfNotNull(parts, "updatenoderef", updateNodeRef); addPartIfNotNull(parts, "description", description); addPartIfNotNull(parts, "contenttype", contentTypeQNameStr); - addPartIfNotNull(parts, "aspects", getCommaSeparated(aspects)); + addPartIfNotNull(parts, "aspectnames", getCommaSeparated(aspects)); addPartIfNotNull(parts, "majorversion", majorVersion); addPartIfNotNull(parts, "overwrite", overwrite); addPartIfNotNull(parts, "autorename", autoRename);