use of org.alfresco.service.cmr.view.Location in project records-management by Alfresco.
the class TransferGet method executeTransfer.
@Override
protected File executeTransfer(NodeRef transferNode, WebScriptRequest req, WebScriptResponse res, Status status, Cache cache) throws IOException {
// get all 'transferred' nodes
NodeRef[] itemsToTransfer = getTransferNodes(transferNode);
// setup the ACP parameters
ExporterCrawlerParameters params = new ExporterCrawlerParameters();
params.setCrawlSelf(true);
params.setCrawlChildNodes(true);
params.setExportFrom(new Location(itemsToTransfer));
QName[] excludedAspects = new QName[] { RenditionModel.ASPECT_RENDITIONED, ContentModel.ASPECT_THUMBNAILED, RecordsManagementModel.ASPECT_DISPOSITION_LIFECYCLE, RecordsManagementSearchBehaviour.ASPECT_RM_SEARCH };
params.setExcludeAspects(excludedAspects);
// create an archive of all the nodes to transfer
File tempFile = createACP(params, ZIP_EXTENSION, true);
if (logger.isDebugEnabled()) {
logger.debug("Creating transfer archive for " + itemsToTransfer.length + " items into file: " + tempFile.getAbsolutePath());
}
// stream the archive back to the client as an attachment (forcing save as)
contentStreamer.streamContent(req, res, tempFile, null, true, tempFile.getName(), null);
// return the temp file for deletion
return tempFile;
}
use of org.alfresco.service.cmr.view.Location in project alfresco-remote-api by Alfresco.
the class SitesImpl method importSite.
private void importSite(final String siteId, final NodeRef siteNodeRef) {
ImportPackageHandler acpHandler = new SiteImportPackageHandler(siteSurfConfig, siteId);
Location location = new Location(siteNodeRef);
ImporterBinding binding = new ImporterBinding() {
@Override
public String getValue(String key) {
if (key.equals("siteId")) {
return siteId;
}
return null;
}
@Override
public UUID_BINDING getUUIDBinding() {
return UUID_BINDING.CREATE_NEW;
}
@Override
public QName[] getExcludedClasses() {
return null;
}
@Override
public boolean allowReferenceWithinTransaction() {
return false;
}
@Override
public ImporterContentCache getImportConentCache() {
return null;
}
};
importerService.importView(acpHandler, location, binding, (ImporterProgress) null);
}
use of org.alfresco.service.cmr.view.Location in project alfresco-remote-api by Alfresco.
the class SiteExportGet method doPeopleACPExport.
protected void doPeopleACPExport(final List<NodeRef> peopleNodes, SiteInfo site, CloseIgnoringOutputStream writeTo) throws IOException {
if (!peopleNodes.isEmpty()) {
// Build the parameters
ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
parameters.setExportFrom(new Location(peopleNodes.toArray(new NodeRef[peopleNodes.size()])));
parameters.setCrawlChildNodes(true);
parameters.setCrawlSelf(true);
parameters.setCrawlContent(true);
// And the export handler
ACPExportPackageHandler handler = new ACPExportPackageHandler(writeTo, new File(site.getShortName() + "-people.xml"), new File(site.getShortName() + "-people"), mimetypeService);
// Do the export
exporterService.exportView(handler, parameters, null);
}
}
use of org.alfresco.service.cmr.view.Location in project records-management by Alfresco.
the class ImportPost method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
// Unwrap to a WebScriptServletRequest if we have one
WebScriptServletRequest webScriptServletRequest = null;
WebScriptRequest current = req;
do {
if (current instanceof WebScriptServletRequest) {
webScriptServletRequest = (WebScriptServletRequest) current;
current = null;
} else if (current instanceof WrappingWebScriptRequest) {
current = ((WrappingWebScriptRequest) req).getNext();
} else {
current = null;
}
} while (current != null);
// get the content type of request and ensure it's multipart/form-data
String contentType = req.getContentType();
if (MULTIPART_FORMDATA.equals(contentType) && webScriptServletRequest != null) {
String nodeRef = req.getParameter(PARAM_DESTINATION);
if (nodeRef == null || nodeRef.length() == 0) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory 'destination' parameter was not provided in form data");
}
// create and check noderef
final NodeRef destination = new NodeRef(nodeRef);
if (nodeService.exists(destination)) {
// check the destination is an RM container
if (!nodeService.hasAspect(destination, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) || !dictionaryService.isSubClass(nodeService.getType(destination), ContentModel.TYPE_FOLDER)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "NodeRef '" + destination + "' does not represent an Records Management container node.");
}
} else {
status.setCode(HttpServletResponse.SC_NOT_FOUND, "NodeRef '" + destination + "' does not exist.");
}
// as there is no 'import capability' and the RM admin user is different from
// the DM admin user (meaning the webscript 'admin' authentication can't be used)
// perform a manual check here to ensure the current user has the RM admin role.
boolean isAdmin = filePlanRoleService.hasRMAdminRole(filePlanService.getFilePlan(destination), AuthenticationUtil.getRunAsUser());
if (!isAdmin) {
throw new WebScriptException(Status.STATUS_FORBIDDEN, "Access Denied");
}
File acpFile = null;
try {
// create a temporary file representing uploaded ACP file
FormField acpContent = webScriptServletRequest.getFileField(PARAM_ARCHIVE);
if (acpContent == null) {
acpContent = webScriptServletRequest.getFileField(PARAM_FILEDATA);
if (acpContent == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory 'archive' file content was not provided in form data");
}
}
acpFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, "." + ACPExportPackageHandler.ACP_EXTENSION);
// copy contents of uploaded file to temp ACP file
FileOutputStream fos = new FileOutputStream(acpFile);
// NOTE: this method closes both streams
FileCopyUtils.copy(acpContent.getInputStream(), fos);
if (logger.isDebugEnabled()) {
logger.debug("Importing uploaded ACP (" + acpFile.getAbsolutePath() + ") into " + nodeRef);
}
// setup the import handler
final ACPImportPackageHandler importHandler = new ACPImportPackageHandler(acpFile, "UTF-8");
// import the ACP file as the system user
AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {
public NodeRef doWork() {
importerService.importView(importHandler, new Location(destination), null, null);
return null;
}
}, AuthenticationUtil.getSystemUserName());
// create and return model
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("success", true);
return model;
} catch (FileNotFoundException fnfe) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Failed to import ACP file", fnfe);
} catch (IOException ioe) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Failed to import ACP file", ioe);
} finally {
if (acpFile != null) {
acpFile.delete();
}
}
} else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Request is not " + MULTIPART_FORMDATA + " encoded");
}
}
use of org.alfresco.service.cmr.view.Location in project records-management by Alfresco.
the class DataSetServiceImpl method loadDataSet.
/**
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#loadDataSet(java.lang.String,
* org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public void loadDataSet(NodeRef filePlan, String dataSetId) {
ParameterCheck.mandatory("filePlan", filePlan);
ParameterCheck.mandatoryString("dataSetId", dataSetId);
// Get the data set
DataSet dataSet = getDataSets().get(dataSetId);
// Import the RM test data ACP into the the provided file plan node
// reference
InputStream is = null;
try {
is = getClass().getClassLoader().getResourceAsStream(dataSet.getPath());
if (is == null) {
throw new AlfrescoRuntimeException("The '" + dataSet.getLabel() + "' import file could not be found!");
}
// Import view
Reader viewReader = new InputStreamReader(is, CHARSET_NAME);
Location location = new Location(filePlan);
importerService.importView(viewReader, location, null, null);
// Patch data
patchLoadedData();
// Set the data set id into the file plan's custom aspect
setDataSetIdIntoFilePlan(dataSetId, filePlan);
} catch (Exception ex) {
throw new AlfrescoRuntimeException("Unexpected exception thrown. Please refer to the log files for details.", ex);
} finally {
if (is != null) {
try {
is.close();
is = null;
} catch (IOException ex) {
throw new AlfrescoRuntimeException("Failed to close the input stream!", ex);
}
}
}
}
Aggregations