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);
}
}
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);
}
Aggregations