use of org.alfresco.service.cmr.view.Location in project alfresco-remote-api by Alfresco.
the class SiteExportGet method doUserACPExport.
protected void doUserACPExport(List<NodeRef> userNodes, SiteInfo site, CloseIgnoringOutputStream writeTo) throws IOException {
// Build the parameters
ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
parameters.setExportFrom(new Location(userNodes.toArray(new NodeRef[userNodes.size()])));
parameters.setCrawlChildNodes(true);
parameters.setCrawlSelf(true);
parameters.setCrawlContent(true);
// And the export handler
ACPExportPackageHandler handler = new ACPExportPackageHandler(writeTo, new File(site.getShortName() + "-users.xml"), new File(site.getShortName() + "-users"), mimetypeService);
// Do the export
exporterService.exportView(handler, parameters, null);
}
use of org.alfresco.service.cmr.view.Location in project alfresco-remote-api by Alfresco.
the class SiteExportGet method doSiteACPExport.
protected void doSiteACPExport(SiteInfo site, CloseIgnoringOutputStream writeTo) throws IOException {
// Build the parameters
ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
parameters.setExportFrom(new Location(site.getNodeRef()));
parameters.setCrawlChildNodes(true);
parameters.setCrawlSelf(true);
parameters.setCrawlContent(true);
// And the export handler
ACPExportPackageHandler handler = new ACPExportPackageHandler(writeTo, new File(site.getShortName() + ".xml"), new File(site.getShortName()), mimetypeService);
// Do the export
exporterService.exportView(handler, parameters, null);
}
use of org.alfresco.service.cmr.view.Location in project alfresco-remote-api by Alfresco.
the class StreamACP method execute.
/**
* @see org.springframework.extensions.webscripts.WebScript#execute(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.WebScriptResponse)
*/
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
File tempACPFile = null;
try {
NodeRef[] nodeRefs = null;
String contentType = req.getContentType();
if (MULTIPART_FORMDATA.equals(contentType)) {
// get nodeRefs parameter from form
nodeRefs = getNodeRefs(req.getParameter(PARAM_NODE_REFS));
} else {
// presume the request is a JSON request so get nodeRefs from JSON body
nodeRefs = getNodeRefs(new JSONObject(new JSONTokener(req.getContent().getContent())));
}
// setup the ACP parameters
ExporterCrawlerParameters params = new ExporterCrawlerParameters();
params.setCrawlSelf(true);
params.setCrawlChildNodes(true);
params.setExportFrom(new Location(nodeRefs));
// create an ACP of the nodes
tempACPFile = createACP(params, ACPExportPackageHandler.ACP_EXTENSION, false);
// stream the ACP back to the client as an attachment (forcing save as)
streamContent(req, res, tempACPFile, true, tempACPFile.getName(), null);
} catch (IOException ioe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", ioe);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
} finally {
// try and delete the temporary file
if (tempACPFile != null) {
if (logger.isDebugEnabled())
logger.debug("Deleting temporary archive: " + tempACPFile.getAbsolutePath());
tempACPFile.delete();
}
}
}
use of org.alfresco.service.cmr.view.Location in project records-management by Alfresco.
the class ExportPost method execute.
/**
* @see org.alfresco.web.scripts.WebScript#execute(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/
@SuppressWarnings("deprecation")
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
File tempACPFile = null;
try {
NodeRef[] nodeRefs = null;
boolean transferFormat = false;
String contentType = req.getContentType();
if (MULTIPART_FORMDATA.equals(contentType)) {
// get nodeRefs parameter from form
nodeRefs = getNodeRefs(req.getParameter(PARAM_NODE_REFS));
// look for the transfer format
String transferFormatParam = req.getParameter(PARAM_TRANSFER_FORMAT);
if (transferFormatParam != null && transferFormatParam.length() > 0) {
transferFormat = Boolean.parseBoolean(transferFormatParam);
}
} else {
// presume the request is a JSON request so get nodeRefs from JSON body
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
nodeRefs = getNodeRefs(json);
if (json.has(PARAM_TRANSFER_FORMAT)) {
transferFormat = json.getBoolean(PARAM_TRANSFER_FORMAT);
}
}
// setup the ACP parameters
ExporterCrawlerParameters params = new ExporterCrawlerParameters();
params.setCrawlSelf(true);
params.setCrawlChildNodes(true);
params.setExportFrom(new Location(nodeRefs));
// if transfer format has been requested we need to exclude certain aspects
if (transferFormat) {
// restrict specific aspects from being returned
QName[] excludedAspects = new QName[] { RenditionModel.ASPECT_RENDITIONED, ContentModel.ASPECT_THUMBNAILED, RecordsManagementModel.ASPECT_DISPOSITION_LIFECYCLE, RecordsManagementSearchBehaviour.ASPECT_RM_SEARCH, RecordsManagementModel.ASPECT_EXTENDED_SECURITY };
params.setExcludeAspects(excludedAspects);
} else {
// restrict specific aspects from being returned
QName[] excludedAspects = new QName[] { RecordsManagementModel.ASPECT_EXTENDED_SECURITY };
params.setExcludeAspects(excludedAspects);
}
// create an ACP of the nodes
tempACPFile = createACP(params, transferFormat ? ZIP_EXTENSION : ACPExportPackageHandler.ACP_EXTENSION, transferFormat);
// stream the ACP back to the client as an attachment (forcing save as)
contentStreamer.streamContent(req, res, tempACPFile, null, true, tempACPFile.getName(), null);
} catch (IOException ioe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", ioe);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
StringWriter stack = new StringWriter();
e.printStackTrace(new PrintWriter(stack));
logger.debug("Caught exception; decorating with appropriate status template : " + stack.toString());
}
throw createStatusException(e, req, res);
} finally {
// try and delete the temporary file
if (tempACPFile != null) {
if (logger.isDebugEnabled()) {
logger.debug("Deleting temporary archive: " + tempACPFile.getAbsolutePath());
}
tempACPFile.delete();
}
}
}
use of org.alfresco.service.cmr.view.Location in project records-management by Alfresco.
the class BootstrapTestDataGet method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
// resolve import argument
boolean importData = false;
if (req.getParameter(ARG_IMPORT) != null) {
importData = Boolean.parseBoolean(req.getParameter(ARG_IMPORT));
}
// resolve rm site
String siteName = RmSiteType.DEFAULT_SITE_NAME;
if (req.getParameter(ARG_SITE_NAME) != null) {
siteName = req.getParameter(ARG_SITE_NAME);
}
if (importData) {
SiteInfo site = siteService.getSite(siteName);
if (site == null) {
throw new AlfrescoRuntimeException("Records Management site does not exist: " + siteName);
}
// resolve documentLibrary (filePlan) container
NodeRef filePlan = siteService.getContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
if (filePlan == null) {
filePlan = siteService.createContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY, TYPE_FILE_PLAN, null);
}
// import the RM test data ACP into the the provided filePlan node reference
InputStream is = BootstrapTestDataGet.class.getClassLoader().getResourceAsStream(XML_IMPORT);
if (is == null) {
throw new AlfrescoRuntimeException("The DODExampleFilePlan.xml import file could not be found");
}
Reader viewReader = null;
try {
viewReader = new InputStreamReader(is, CHARSET_NAME);
} catch (UnsupportedEncodingException error) {
throw new AlfrescoRuntimeException("The Character Encoding '" + CHARSET_NAME + "' is not supported.", error);
}
Location location = new Location(filePlan);
importerService.importView(viewReader, location, null, null);
}
// Patch data
BootstrapTestDataGet.patchLoadedData(searchService, nodeService, recordsManagementService, recordsManagementActionService, permissionService, authorityService, recordsManagementSecurityService, recordsManagementSearchBehaviour, dispositionService, recordFolderService);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("success", true);
return model;
}
Aggregations