mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
ACS-1584: REST API storage-classes endpoint (#509)
This commit is contained in:
committed by
Andrea Ligios
parent
4a7ea71f4e
commit
dab6f70936
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
|
||||
/**
|
||||
* Storage Classes API
|
||||
*/
|
||||
public interface ContentStorageClasses
|
||||
{
|
||||
/**
|
||||
* Lists supported storage classes
|
||||
*/
|
||||
CollectionWithPagingInfo<StorageClass> getStorageClasses(Paging paging);
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import org.alfresco.rest.api.ContentStorageClasses;
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Centralises access to storage classes functionality
|
||||
*/
|
||||
public class ContentStorageClassesImpl implements ContentStorageClasses
|
||||
{
|
||||
private ContentService contentService;
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<StorageClass> getStorageClasses(Paging paging)
|
||||
{
|
||||
Set<String> storageClasses = contentService.getSupportedStorageClasses();
|
||||
return CollectionWithPagingInfo.asPaged(paging, storageClasses.stream().map(StorageClass::new).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
/**
|
||||
* Represents a storage class.
|
||||
*/
|
||||
public class StorageClass
|
||||
{
|
||||
private String id;
|
||||
|
||||
public StorageClass(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public StorageClass()
|
||||
{
|
||||
}
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.storageclasses;
|
||||
|
||||
import org.alfresco.rest.api.ContentStorageClasses;
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.EntityResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
|
||||
/**
|
||||
* An implementation of an Entity Resource for handling storage classes.
|
||||
*/
|
||||
@EntityResource(name = "storage-classes", title = "Storage Classes")
|
||||
public class StorageClassesEntityResource implements EntityResourceAction.Read<StorageClass>
|
||||
{
|
||||
private ContentStorageClasses contentStorageClasses;
|
||||
|
||||
public void setContentStorageClasses(ContentStorageClasses contentStorageClasses)
|
||||
{
|
||||
this.contentStorageClasses = contentStorageClasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Get List of Storage Classes", description = "Get List of Storage Classes")
|
||||
public CollectionWithPagingInfo<StorageClass> readAll(Parameters params)
|
||||
{
|
||||
return contentStorageClasses.getStorageClasses(params.getPaging());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@WebApi(name="alfresco", scope= Api.SCOPE.PUBLIC, version=1)
|
||||
package org.alfresco.rest.api.storageclasses;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.WebApi;
|
@@ -799,6 +799,24 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="contentStorageClasses" class="org.alfresco.rest.api.impl.ContentStorageClassesImpl">
|
||||
<property name="contentService" ref="ContentService" />
|
||||
</bean>
|
||||
|
||||
<bean id="ContentStorageClasses" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="proxyInterfaces">
|
||||
<value>org.alfresco.rest.api.ContentStorageClasses</value>
|
||||
</property>
|
||||
<property name="target">
|
||||
<ref bean="contentStorageClasses" />
|
||||
</property>
|
||||
<property name="interceptorNames">
|
||||
<list>
|
||||
<idref bean="legacyExceptionInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tags" class="org.alfresco.rest.api.impl.TagsImpl">
|
||||
<property name="nodes" ref="nodes" />
|
||||
<property name="taggingService" ref="TaggingService" />
|
||||
@@ -987,6 +1005,10 @@
|
||||
<property name="actions" ref="Actions"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.storageclasses.StorageClassesEntityResource">
|
||||
<property name="contentStorageClasses" ref="ContentStorageClasses" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.trashcan.TrashcanEntityResource">
|
||||
<property name="deletedNodes" ref="DeletedNodes" />
|
||||
</bean>
|
||||
|
@@ -55,6 +55,7 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.rest.api.tests.QueriesNodesApiTest.class,
|
||||
org.alfresco.rest.api.tests.QueriesPeopleApiTest.class,
|
||||
org.alfresco.rest.api.tests.QueriesSitesApiTest.class,
|
||||
org.alfresco.rest.api.tests.StorageClassesTest.class,
|
||||
org.alfresco.rest.api.tests.TestActivities.class,
|
||||
org.alfresco.rest.api.tests.TestDownloads.class,
|
||||
org.alfresco.rest.api.tests.TestFavouriteSites.class,
|
||||
|
@@ -79,6 +79,7 @@ import org.junit.runners.Suite;
|
||||
TestPublicApiCaching.class,
|
||||
TestDownloads.class,
|
||||
AuditAppTest.class,
|
||||
StorageClassesTest.class,
|
||||
TempOutputStreamTest.class,
|
||||
BufferedResponseTest.class
|
||||
})
|
||||
|
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.alfresco.rest.api.tests.util.RestApiUtil.parseRestApiEntries;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* V1 REST API tests for Storage Classes
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/storage-classes} </li>
|
||||
* </ul>
|
||||
*/
|
||||
public class StorageClassesTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String STORAGE_CLASSES = "storage-classes";
|
||||
private ContentService contentService;
|
||||
private ContentStore originalStore;
|
||||
@Mock
|
||||
private ContentStore mockStore;
|
||||
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
contentService = applicationContext.getBean("contentService", ContentService.class);
|
||||
originalStore = (ContentStore) ReflectionTestUtils.getField(contentService, "store");
|
||||
|
||||
setRequestContext(user1);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
ReflectionTestUtils.setField(contentService, "store", originalStore);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultStorageClasses() throws Exception
|
||||
{
|
||||
PublicApiClient.Paging paging = getPaging(0, 100);
|
||||
|
||||
HttpResponse response = getAll(STORAGE_CLASSES, paging, 200);
|
||||
List<StorageClass> nodes = parseRestApiEntries(response.getJsonResponse(), StorageClass.class);
|
||||
|
||||
assertNotNull(nodes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStorageClasses() throws Exception
|
||||
{
|
||||
ReflectionTestUtils.setField(contentService, "store", mockStore);
|
||||
|
||||
Set<String> expectedStorageClasses = Set.of("default", "archive", "worm");
|
||||
when(mockStore.getSupportedStorageClasses()).thenReturn(expectedStorageClasses);
|
||||
|
||||
PublicApiClient.Paging paging = getPaging(0, 100);
|
||||
HttpResponse response = getAll(STORAGE_CLASSES, paging, 200);
|
||||
List<StorageClass> nodes = parseRestApiEntries(response.getJsonResponse(), StorageClass.class);
|
||||
|
||||
assertNotNull(nodes);
|
||||
assertEquals(3, nodes.size());
|
||||
}
|
||||
}
|
@@ -481,7 +481,7 @@
|
||||
<!-- =========================== -->
|
||||
|
||||
<!-- Reading requires the permission to read content -->
|
||||
<!-- Writing required the permission to write conent -->
|
||||
<!-- Writing required the permission to write content -->
|
||||
|
||||
<bean id="ContentService_security" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
|
||||
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
|
||||
@@ -491,6 +491,9 @@
|
||||
<value>
|
||||
org.alfresco.service.cmr.repository.ContentService.getStoreTotalSpace=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getStoreFreeSpace=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getSupportedStorageClasses=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.isStorageClassesSupported=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getStorageClassesTransitions=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getRawReader=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||
org.alfresco.service.cmr.repository.ContentService.getReader=ACL_NODE.0.sys:base.ReadContent
|
||||
org.alfresco.service.cmr.repository.ContentService.getWriter=ACL_NODE.0.sys:base.WriteContent
|
||||
|
Reference in New Issue
Block a user