Jahia in English > Jahia export import...

0 (0 Good)
0 (0 Bad)

Jahia export import service API

by  satishsharma »  2013/10/01 08:01

Hi ,

I am using ImportExportService to export site in zip format and then I have to import the same. When I try to export via Jahia export option inside web project management the exported file contains three zip files inside a single zip namely (roles.zip, user.zip , and site_name.zip) each of which contains repository.xml and live-repository.xml.But when I try with ImportExportService it contains full data of sites including images themes etc all in a single zip. Code that I have tried : 

private final static String DEFAULT_LANGUAGE = "en";
private final static String TESTSITE_NAME = "tatlsNewPersonalizeBranding";
private final static String SITECONTENT_ROOT_NODE = "sites/" + TESTSITE_NAME;
 
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource,
JCRSessionWrapper session, Map<String, List<String>> parameters, URLResolver urlResolver) throws Exception {
System.out.println("InSide the required method of export to excel !!! ");
JahiaUser loggedInUser = renderContext.getUser();
Boolean isUser = Boolean.parseBoolean(loggedInUser.getProperty("isUser") != null ? loggedInUser
                .getProperty("isUser") : Boolean.TRUE.toString());
        // to prevent attendee from calling this action
System.out.println("isUser = " + isUser);
        if (!isUser) {
            return new ActionResult(HttpServletResponse.SC_FORBIDDEN);
        }
testNodeExportImportWithLive();
return null;
}
 
public void testNodeExportImportWithLive() throws Exception {
System.out.println("In second call !!!");
JCRSessionFactory sf = JCRSessionFactory.getInstance();
sf.closeAllSessions();
JCRTemplate.getInstance().doExecuteWithUserSession(
sf.getCurrentUser().getName(), Constants.LIVE_WORKSPACE,
LanguageCodeConverters.languageCodeToLocale(DEFAULT_LANGUAGE),
new JCRCallback<Object>() {
public Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
                        JCRSessionWrapper sessionNoLocale = JCRSessionFactory.getInstance().getCurrentUserSession(Constants.EDIT_WORKSPACE);
                        JCRNodeWrapper englishLiveSiteRootNode = sessionNoLocale.getNode("/" + SITECONTENT_ROOT_NODE);
                        JCRNodeWrapper englishLiveSiteHomeNode = (JCRNodeWrapper) englishLiveSiteRootNode.getNode("home");
 
                        nodeExportImportAndCheck(session, englishLiveSiteHomeNode);
 
                        return null;
                    }
});
sf.closeAllSessions();
}
 
private File nodeExportImportAndCheck(JCRSessionWrapper editSession,
JCRNodeWrapper node) throws RepositoryException {
System.out.println("In third call !!!");
File createdZip = exportNode(node);
System.out.println("Export Failed = " + createdZip);
return createdZip;
}
 
private File exportNode(JCRNodeWrapper node) throws RepositoryException {
System.out.println("In Forth Call !!!");
Map<String, Object> params = new HashMap<String, Object>();
params.put(ImportExportService.INCLUDE_TEMPLATES, Boolean.TRUE);
params.put(ImportExportService.INCLUDE_ROLES, Boolean.TRUE);
params.put(ImportExportService.INCLUDE_USERS, Boolean.TRUE);
params.put(ImportExportService.XSL_PATH, "/home/data/installed/apache-tomcat-7.0.33/webapps/concierge/WEB-INF/etc/repository/export/cleanup.xsl");
 
ImportExportService importExportService = ServicesRegistry.getInstance().getImportExportService();
File zipFile = null;
 
try {
zipFile = File.createTempFile("nodeimportexporttest", ".zip", new File("/home/infoobjects/installed/apache-tomcat-7.0.33"));
OutputStream outputStream = new FileOutputStream(zipFile);
importExportService.exportZip(node, null, outputStream, params);
System.out.println("zipFile = " + zipFile.getPath());
System.out.println("zipFile = " + zipFile.getTotalSpace());
outputStream.close();
 
} catch (FileNotFoundException e) {
logger.error("Exception during ImportExportTest", e);
} catch (IOException e) {
logger.error("Exception during ImportExportTest", e);
} catch (SAXException e) {
logger.error("Exception during ImportExportTest", e);
} catch (JDOMException e) {
logger.error("Exception during ImportExportTest", e);
}
return zipFile;
}

This code generates the zip but I am unable to import that zip.

 

Can anyone knows the actual implementation of Rest API to export import site in same way as Jahia provides with its export import functionality.

 

Thanks In Advance.

  • Jahia export import service API
    2013/10/01 08:03

    satishsharma <p> Hi ,</p> <p> I am using&nbsp;<strong>ImportExportService</strong> to export site in zip format and then I have to import the same. When I try to export via Jahia export option inside web project management the exported file contains three zip files inside a single zip namely (<strong>roles.zip, user.zip , and site_name.zip</strong>) each of which contains repository.xml and live-repository.xml.But when I try with&nbsp;<strong>ImportExportService</strong> it contains full data of sites including images themes etc all in a single zip. Code that I have tried :&nbsp;</p> <div> <div> private final static String DEFAULT_LANGUAGE = &quot;en&quot;;</div> <div> private final static String TESTSITE_NAME = &quot;tatlsNewPersonalizeBranding&quot;;</div> <div> private final static String SITECONTENT_ROOT_NODE = &quot;sites/&quot; + TESTSITE_NAME;</div> <div> &nbsp;</div> <div> public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource,</div> <div> JCRSessionWrapper session, Map&lt;String, List&lt;String&gt;&gt; parameters, URLResolver urlResolver) throws Exception {</div> <div> System.out.println(&quot;InSide the required method of export to excel !!! &quot;);</div> <div> JahiaUser loggedInUser = renderContext.getUser();</div> <div> Boolean isUser = Boolean.parseBoolean(loggedInUser.getProperty(&quot;isUser&quot;) != null ? loggedInUser</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .getProperty(&quot;isUser&quot;) : Boolean.TRUE.toString());</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; // to prevent attendee from calling this action</div> <div> System.out.println(&quot;isUser = &quot; + isUser);</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; if (!isUser) {</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new ActionResult(HttpServletResponse.SC_FORBIDDEN);</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; }</div> <div> testNodeExportImportWithLive();</div> <div> return null;</div> <div> }</div> <div> &nbsp;</div> <div> public void testNodeExportImportWithLive() throws Exception {</div> <div> System.out.println(&quot;In second call !!!&quot;);</div> <div> JCRSessionFactory sf = JCRSessionFactory.getInstance();</div> <div> sf.closeAllSessions();</div> <div> JCRTemplate.getInstance().doExecuteWithUserSession(</div> <div> sf.getCurrentUser().getName(), Constants.LIVE_WORKSPACE,</div> <div> LanguageCodeConverters.languageCodeToLocale(DEFAULT_LANGUAGE),</div> <div> new JCRCallback&lt;Object&gt;() {</div> <div> public Object doInJCR(JCRSessionWrapper session) throws RepositoryException {</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JCRSessionWrapper sessionNoLocale = JCRSessionFactory.getInstance().getCurrentUserSession(Constants.EDIT_WORKSPACE);</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JCRNodeWrapper englishLiveSiteRootNode = sessionNoLocale.getNode(&quot;/&quot; + SITECONTENT_ROOT_NODE);</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JCRNodeWrapper englishLiveSiteHomeNode = (JCRNodeWrapper) englishLiveSiteRootNode.getNode(&quot;home&quot;);</div> <div> &nbsp;</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nodeExportImportAndCheck(session, englishLiveSiteHomeNode);</div> <div> &nbsp;</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return null;</div> <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div> <div> });</div> <div> sf.closeAllSessions();</div> <div> }</div> <div> &nbsp;</div> <div> private File nodeExportImportAndCheck(JCRSessionWrapper editSession,</div> <div> JCRNodeWrapper node) throws RepositoryException {</div> <div> System.out.println(&quot;In third call !!!&quot;);</div> <div> File createdZip = exportNode(node);</div> <div> System.out.println(&quot;Export Failed = &quot; + createdZip);</div> <div> return createdZip;</div> <div> }</div> <div> &nbsp;</div> <div> private File exportNode(JCRNodeWrapper node) throws RepositoryException {</div> <div> System.out.println(&quot;In Forth Call !!!&quot;);</div> <div> Map&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();</div> <div> params.put(ImportExportService.INCLUDE_TEMPLATES, Boolean.TRUE);</div> <div> params.put(ImportExportService.INCLUDE_ROLES, Boolean.TRUE);</div> <div> params.put(ImportExportService.INCLUDE_USERS, Boolean.TRUE);</div> <div> params.put(ImportExportService.XSL_PATH, &quot;/home/data/installed/apache-tomcat-7.0.33/webapps/concierge/WEB-INF/etc/repository/export/cleanup.xsl&quot;);</div> <div> &nbsp;</div> <div> ImportExportService importExportService = ServicesRegistry.getInstance().getImportExportService();</div> <div> File zipFile = null;</div> <div> &nbsp;</div> <div> try {</div> <div> zipFile = File.createTempFile(&quot;nodeimportexporttest&quot;, &quot;.zip&quot;, new File(&quot;/home/infoobjects/installed/apache-tomcat-7.0.33&quot;));</div> <div> OutputStream outputStream = new FileOutputStream(zipFile);</div> <div> importExportService.exportZip(node, null, outputStream, params);</div> <div> System.out.println(&quot;zipFile = &quot; + zipFile.getPath());</div> <div> System.out.println(&quot;zipFile = &quot; + zipFile.getTotalSpace());</div> <div> outputStream.close();</div> <div> &nbsp;</div> <div> } catch (FileNotFoundException e) {</div> <div> logger.error(&quot;Exception during ImportExportTest&quot;, e);</div> <div> } catch (IOException e) {</div> <div> logger.error(&quot;Exception during ImportExportTest&quot;, e);</div> <div> } catch (SAXException e) {</div> <div> logger.error(&quot;Exception during ImportExportTest&quot;, e);</div> <div> } catch (JDOMException e) {</div> <div> logger.error(&quot;Exception during ImportExportTest&quot;, e);</div> <div> }</div> <div> return zipFile;</div> <div> }</div> </div> <p> This code generates the zip but I am unable to import that zip.</p> <p> &nbsp;</p> <p> Can anyone knows the actual implementation of Rest API to export import site in same way as Jahia provides with its export import functionality.</p> <p> &nbsp;</p> <p> Thanks In Advance.</p>

  • Number of messages  7
    Registration date Oct 1, 2013
    0 (0 Good)
    0 (0 Bad)

    Re: Jahia export import service API

    by  faissah »  2013/10/04 21:45

    Hi,

    I haven't actually tried it but have you tried something like that?

                zipFile = File.createTempFile("exporttest", ".zip");
                OutputStream outputStream = new FileOutputStream(zipFile);
                List<JahiaSite> sites = Lists.newArrayList(ServicesRegistry.getInstance().getJahiaSitesService().getSiteByKey(TESTSITE_NAME));
                importExportService.exportSites(outputStream, params, sites);
                outputStream.close();

    Regards,

    Fabrice

    Fabrice  (faissah)

    Number of messages  264
    Registration date
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page