mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'feature/RM-5416_REST_API_Tests_for_Folder_Classification_2' into 'master'
Feature/rm 5416 rest api tests for folder classification 2 See merge request !580
This commit is contained in:
@@ -34,6 +34,7 @@ import org.alfresco.rest.model.RestHtmlResponse;
|
||||
import org.alfresco.rest.model.RestSiteModel;
|
||||
import org.alfresco.rest.model.RestSiteModelsCollection;
|
||||
import org.alfresco.rest.requests.coreAPI.RestCoreAPI;
|
||||
import org.alfresco.rest.requests.search.SearchAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.GSCoreAPI;
|
||||
import org.alfresco.utility.model.StatusModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
@@ -145,6 +146,12 @@ public class RMRestWrapper
|
||||
return restWrapper.withCoreAPI();
|
||||
}
|
||||
|
||||
/** Get the Alfresco Search API. */
|
||||
public SearchAPI withSearchAPI()
|
||||
{
|
||||
return restWrapper.withSearchAPI();
|
||||
}
|
||||
|
||||
/**
|
||||
* You can handle the request sent to server by calling this method.
|
||||
* If for example you want to sent multipart form data you can use: <pre>
|
||||
|
@@ -32,6 +32,7 @@ import javax.annotation.Resource;
|
||||
|
||||
import org.alfresco.rest.requests.Node;
|
||||
import org.alfresco.rest.requests.coreAPI.RestCoreAPI;
|
||||
import org.alfresco.rest.requests.search.SearchAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.GSCoreAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI;
|
||||
@@ -84,6 +85,12 @@ public class RestAPIFactory
|
||||
getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser());
|
||||
return getRmRestWrapper().withCoreAPI();
|
||||
}
|
||||
|
||||
private SearchAPI getSearchAPI(UserModel userModel)
|
||||
{
|
||||
getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser());
|
||||
return getRmRestWrapper().withSearchAPI();
|
||||
}
|
||||
|
||||
public Node getNodeAPI(RepoTestModel model) throws Exception
|
||||
{
|
||||
|
@@ -74,7 +74,7 @@ public abstract class BaseAPI
|
||||
|
||||
/** exception key in JSON response body */
|
||||
private static final String EXCEPTION_KEY = "exception";
|
||||
protected static final String NODE_PREFIX = "workspace/SpacesStore/";
|
||||
public static final String NODE_PREFIX = "workspace/SpacesStore/";
|
||||
protected static final String UPDATE_METADATA_API = "{0}node/{1}/formprocessor";
|
||||
protected static final String ACTIONS_API = "{0}actionQueue";
|
||||
protected static final String RM_ACTIONS_API = "{0}rma/actions/ExecutionQueue";
|
||||
|
@@ -34,6 +34,8 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@@ -59,6 +61,7 @@ import lombok.NoArgsConstructor;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties (ignoreUnknown = true)
|
||||
public class RecordCategoryProperties extends TestModel
|
||||
{
|
||||
/*************************/
|
||||
|
@@ -40,6 +40,8 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@@ -65,6 +67,7 @@ import lombok.NoArgsConstructor;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties (ignoreUnknown = true)
|
||||
public class RecordFolderProperties extends TestModel
|
||||
{
|
||||
/*************************/
|
||||
|
@@ -33,11 +33,14 @@ import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_TITLE
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING;
|
||||
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
|
||||
@@ -49,8 +52,10 @@ import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.dataprep.ContentService;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.core.RestAPIFactory;
|
||||
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
||||
@@ -65,8 +70,15 @@ import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||
import org.alfresco.rest.search.SearchNodeModel;
|
||||
import org.alfresco.rest.search.SearchRequest;
|
||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -92,6 +104,14 @@ public class BaseRMRestTest extends RestTest
|
||||
@Getter (value = PROTECTED)
|
||||
private DataUser dataUser;
|
||||
|
||||
@Autowired
|
||||
@Getter(value = PROTECTED)
|
||||
private ContentService contentService;
|
||||
|
||||
@Autowired
|
||||
@Getter(value = PROTECTED)
|
||||
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
||||
|
||||
/**
|
||||
* Asserts the given status code
|
||||
*
|
||||
@@ -468,4 +488,131 @@ public class BaseRMRestTest extends RestTest
|
||||
{
|
||||
return getFilePlanAsUser(getAdminUser(), componentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively delete a folder
|
||||
*
|
||||
* @param siteModel
|
||||
* @param folder
|
||||
*/
|
||||
public void deleteFolder(SiteModel siteModel, FolderModel folder)
|
||||
{
|
||||
contentService.deleteTree(getAdminUser().getUsername(), getAdminUser().getPassword(), siteModel.getId(),
|
||||
folder.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an electronic record
|
||||
*
|
||||
* @param parentId the id of the parent
|
||||
* @param name the name of the record
|
||||
* @return the created record
|
||||
* @throws Exception
|
||||
*/
|
||||
public Record createElectronicRecord(String parentId, String name) throws Exception
|
||||
{
|
||||
return createElectronicRecord(parentId, name ,null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an electronic record
|
||||
*
|
||||
* @param parentId the id of the parent
|
||||
* @param name the name of the record
|
||||
* @return the created record
|
||||
* @throws Exception
|
||||
*/
|
||||
public Record createElectronicRecord(String parentId, String name, UserModel user) throws Exception
|
||||
{
|
||||
RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(user);
|
||||
Record recordModel = Record.builder().name(name).nodeType(CONTENT_TYPE).build();
|
||||
return recordFolderAPI.createRecord(recordModel, parentId);
|
||||
}
|
||||
/**
|
||||
* Delete a record folder
|
||||
*
|
||||
* @param recordFolderId the id of the record folder to delete
|
||||
*/
|
||||
public void deleteRecordFolder(String recordFolderId)
|
||||
{
|
||||
RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI();
|
||||
recordFolderAPI.deleteRecordFolder(recordFolderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a record category
|
||||
*
|
||||
* @param recordCategoryId the id of the record category to delete
|
||||
*/
|
||||
public void deleteRecordCategory(String recordCategoryId)
|
||||
{
|
||||
RecordCategoryAPI recordCategoryAPI = restAPIFactory.getRecordCategoryAPI();
|
||||
recordCategoryAPI.deleteRecordCategory(recordCategoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign filling permission on a record category and give the user RM_USER role
|
||||
*
|
||||
* @param user the user to assign the permission to
|
||||
* @param categoryId the id of the category to assign permissions for
|
||||
* @throws Exception
|
||||
*/
|
||||
public void assignFillingPermissionsOnCategory(UserModel user, String categoryId,
|
||||
String userPermission, String userRole) throws Exception
|
||||
{
|
||||
getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission);
|
||||
rmRolesAndActionsAPI.assignUserToRole(getAdminUser().getUsername(),
|
||||
getAdminUser().getPassword(), user.getUsername(), userRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns search results for the given search term
|
||||
*
|
||||
* @param user
|
||||
* @param term
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<String> searchForContentAsUser(UserModel user, String term) throws Exception
|
||||
{
|
||||
getRestAPIFactory().getRmRestWrapper().authenticateUser(user);
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
SearchRequest query = new SearchRequest(queryReq);
|
||||
queryReq.setQuery("cm:name:*" + term + "*");
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
// wait for solr indexing
|
||||
int counter = 0;
|
||||
int waitInMilliSeconds = 6000;
|
||||
while (counter < 3)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.wait(waitInMilliSeconds);
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
List<SearchNodeModel> searchResults = getRestAPIFactory().getRmRestWrapper().withSearchAPI().search(query)
|
||||
.getEntries();
|
||||
if ((searchResults != null && !searchResults.isEmpty()))
|
||||
{
|
||||
searchResults.forEach(childNode ->
|
||||
{
|
||||
names.add(childNode.onModel().getName());
|
||||
});
|
||||
break;
|
||||
} else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
// double wait time to not overdo solr search
|
||||
waitInMilliSeconds = (waitInMilliSeconds * 2);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user