Search in sources :

Example 1 with Location

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);
}
Also used : ACPExportPackageHandler(org.alfresco.repo.exporter.ACPExportPackageHandler) ExporterCrawlerParameters(org.alfresco.service.cmr.view.ExporterCrawlerParameters) File(java.io.File) Location(org.alfresco.service.cmr.view.Location)

Example 2 with Location

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);
}
Also used : ACPExportPackageHandler(org.alfresco.repo.exporter.ACPExportPackageHandler) ExporterCrawlerParameters(org.alfresco.service.cmr.view.ExporterCrawlerParameters) File(java.io.File) Location(org.alfresco.service.cmr.view.Location)

Example 3 with Location

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();
        }
    }
}
Also used : JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ExporterCrawlerParameters(org.alfresco.service.cmr.view.ExporterCrawlerParameters) JSONException(org.json.JSONException) IOException(java.io.IOException) File(java.io.File) Location(org.alfresco.service.cmr.view.Location)

Example 4 with Location

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();
        }
    }
}
Also used : QName(org.alfresco.service.namespace.QName) ExporterCrawlerParameters(org.alfresco.service.cmr.view.ExporterCrawlerParameters) JSONException(org.json.JSONException) IOException(java.io.IOException) IOException(java.io.IOException) JSONException(org.json.JSONException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) StringWriter(java.io.StringWriter) File(java.io.File) Location(org.alfresco.service.cmr.view.Location) PrintWriter(java.io.PrintWriter)

Example 5 with Location

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;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Location(org.alfresco.service.cmr.view.Location)

Aggregations

Location (org.alfresco.service.cmr.view.Location)10 File (java.io.File)7 ExporterCrawlerParameters (org.alfresco.service.cmr.view.ExporterCrawlerParameters)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 IOException (java.io.IOException)4 ACPExportPackageHandler (org.alfresco.repo.exporter.ACPExportPackageHandler)3 QName (org.alfresco.service.namespace.QName)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 JSONTokener (org.json.JSONTokener)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1