Search in sources :

Example 1 with CustomModelDownload

use of org.alfresco.rest.api.model.CustomModelDownload in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method createDownload.

@Override
public CustomModelDownload createDownload(String modelName, Parameters parameters) {
    // Check the current user is authorised to export the model
    validateCurrentUser();
    if (modelName == null) {
        throw new InvalidArgumentException(MODEL_NAME_NULL_ERR);
    }
    String propName = parameters.getParameter(PARAM_WITH_EXT_MODULE);
    boolean withForm = Boolean.valueOf(propName);
    try {
        NodeRef nodeRef = customModelService.createDownloadNode(modelName, withForm);
        return new CustomModelDownload(nodeRef);
    } catch (Exception ex) {
        String errorMsg = "cmm.rest_api.model_download_failure";
        if (ex.getMessage() != null) {
            errorMsg = ex.getMessage();
        }
        throw new ApiException(errorMsg, ex);
    }
}
Also used : CustomModelDownload(org.alfresco.rest.api.model.CustomModelDownload) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActiveModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException) ModelDoesNotExistException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) CustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 2 with CustomModelDownload

use of org.alfresco.rest.api.model.CustomModelDownload in project alfresco-remote-api by Alfresco.

the class TestCustomModelExport method testCreateDownload.

@Test
public void testCreateDownload() throws Exception {
    setRequestContext(customModelAdmin);
    final String modelName = "testModel" + System.currentTimeMillis();
    final String modelExportFileName = modelName + ".xml";
    final String shareExtExportFileName = "CMM_" + modelName + "_module.xml";
    Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    createCustomModel(modelName, namespacePair, ModelStatus.DRAFT, null, "Mark Moe");
    // Add type
    String typeBaseName = "testTypeBase" + System.currentTimeMillis();
    createTypeAspect(CustomType.class, modelName, typeBaseName, "test typeBase title", "test typeBase Desc", "cm:content");
    // Create Share extension module
    downloadTestUtil.createShareExtModule(modelName);
    setRequestContext(nonAdminUserName);
    // Try to create download the model as a non Admin user
    post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 403);
    setRequestContext(customModelAdmin);
    // Create download for custom model only
    HttpResponse response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 201);
    CustomModelDownload returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class);
    assertNotNull(returnedDownload);
    assertNotNull(returnedDownload.getNodeRef());
    NodeRef downloadNode = new NodeRef(returnedDownload.getNodeRef());
    DownloadStatus status = downloadTestUtil.getDownloadStatus(downloadNode);
    while (status.getStatus() == DownloadStatus.Status.PENDING) {
        Thread.sleep(PAUSE_TIME);
        status = downloadTestUtil.getDownloadStatus(downloadNode);
    }
    Set<String> entries = downloadTestUtil.getDownloadEntries(downloadNode);
    assertEquals(1, entries.size());
    String modelEntry = downloadTestUtil.getDownloadEntry(entries, modelExportFileName);
    assertNotNull(modelEntry);
    assertEquals(modelEntry, modelExportFileName);
    // Create download for custom model and its share extension module
    response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(true), 201);
    returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class);
    assertNotNull(returnedDownload);
    assertNotNull(returnedDownload.getNodeRef());
    downloadNode = new NodeRef(returnedDownload.getNodeRef());
    status = downloadTestUtil.getDownloadStatus(downloadNode);
    while (status.getStatus() == DownloadStatus.Status.PENDING) {
        Thread.sleep(PAUSE_TIME);
        status = downloadTestUtil.getDownloadStatus(downloadNode);
    }
    entries = downloadTestUtil.getDownloadEntries(downloadNode);
    assertEquals(2, entries.size());
    modelEntry = downloadTestUtil.getDownloadEntry(entries, modelExportFileName);
    assertNotNull(modelEntry);
    assertEquals(modelEntry, modelExportFileName);
    String shareExtEntry = downloadTestUtil.getDownloadEntry(entries, shareExtExportFileName);
    assertNotNull(shareExtEntry);
    assertEquals(shareExtEntry, shareExtExportFileName);
}
Also used : CustomModelDownload(org.alfresco.rest.api.model.CustomModelDownload) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DownloadStatus(org.alfresco.service.cmr.download.DownloadStatus) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Test(org.junit.Test)

Aggregations

CustomModelDownload (org.alfresco.rest.api.model.CustomModelDownload)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)1 CustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException)1 ActiveModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException)1 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)1 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)1 ModelDoesNotExistException (org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException)1 ModelExistsException (org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException)1 DownloadStatus (org.alfresco.service.cmr.download.DownloadStatus)1 Test (org.junit.Test)1