jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tomasz Dabrowski" <Tomasz.Dabrow...@cognifide.com>
Subject Export/import versioning node - error?
Date Mon, 06 Feb 2006 09:49:32 GMT
Hi,

As far as I found after export/import versioning node there is need to
checkin it. I wrote some simple prototype for it. I'm not sure if
version name after checkin node is correct. My scenario is:

1. Create some node with type "mix:versionable" in "default" workspace
(node named by NODE_NAME in my source).
2. Export this node using document view.
3. Create diffrent workspace (named by WORKSPACE_WITH_IMPORTED_DATA in
my source).
4. Login to newly created workspace.
5. Import my data using method on Workspace object.
6. Get my imported node (created in step 1) and check-in it.
7. Print version name for imported node. 

Here is output:

10:38:39 INFO  - Creating EmbeddedRepository.
10:38:40 INFO  - Created EmbeddedRepository successfully in location
[d:/repo_prototyping/].
10:38:40 INFO  - Data exported.
10:38:41 INFO  - Workspace with name=[importedWorkspace2] created.
10:38:41 ERROR
org.apache.jackrabbit.core.ItemValidator.safeGetJCRPath(ItemValidator.ja
va:237) - 117b4ae6-4ca4-4e12-82a1-5ea284494e6c: failed to build path
10:38:41 INFO  - Data imported.
10:38:41 INFO  - version name=[rootVersion.1]
10:38:41 INFO  - Done.

I'm a bit afraid of this error - "117b4ae6-4ca4-4e12-82a1-5ea284494e6c:
failed to build path". Is it ok?? What about version name
("rootVersion.1")? Shouldn't it be built using only digits?

Kind regards,
Tomek

=========================================================
I attached my source.

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.jcr.ImportUUIDBehavior;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Workspace;

import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.WorkspaceImpl;
import org.apache.jackrabbit.core.config.RepositoryConfig;

public class JackrabbitExportTest {

    private static final org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(JackrabbitExportTest.class)
;

    public static String REPOSITORY_HOME = "d:/repo_prototyping/";

    public static String REPOSITORY_CONFIG = REPOSITORY_HOME +
"repository.xml";

    private static final String WORKSPACE_WITH_IMPORTED_DATA =
"importedWorkspace2";

    private static final String EXPORT_DOCUMENT_VIEW_FILE_PATH =
"exportDocumentView.xml";

    private static final String EXPORT_SYSTEM_VIEW_FILE_PATH =
"exportSystemView.xml";

    private static final String NODE_NAME = "node";

    public static void main(String[] args) throws RepositoryException,
FileNotFoundException, IOException {
        System.setProperty("java.security.auth.login.config",
"jaas_jcr.config");

        // login to first repository
        log.info("Creating EmbeddedRepository.");
        RepositoryConfig config =
RepositoryConfig.create(REPOSITORY_CONFIG, REPOSITORY_HOME);
        Repository repository = RepositoryImpl.create(config);
        log.info("Created EmbeddedRepository successfully in location ["
+ REPOSITORY_HOME + "].");
        Session session = repository.login(new
SimpleCredentials("admin", "admin".toCharArray()));

        // create some data
        Node root = session.getRootNode();
        Node node = null;
        if (root.hasNode(NODE_NAME)) {
            node = root.getNode(NODE_NAME);
            node.checkout();
        }
        else {
            node = root.addNode(NODE_NAME);
            node.addMixin("mix:versionable");
        }

        root.save();
        node.checkin();

        // export it
        try {
            String path = "/" + NODE_NAME;
            FileOutputStream fos1 = new
FileOutputStream(EXPORT_DOCUMENT_VIEW_FILE_PATH);
            session.exportDocumentView(path, fos1, false, false);
            fos1.close();

            log.info("Data exported.");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        // create next workspace in the same repository
        String workspaceName = WORKSPACE_WITH_IMPORTED_DATA;
        createWorkspace(session, workspaceName);
        log.info("Workspace with name=[" + workspaceName + "]
created.");
        session.logout();

        // import data into created workspace
        FileInputStream fis1 = new
FileInputStream(EXPORT_DOCUMENT_VIEW_FILE_PATH);
        session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()), workspaceName);
        Workspace workspace = session.getWorkspace();
        workspace.importXML("/", fis1,
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
        log.info("Data imported.");

        // checkin imported node and print its version name
        root = session.getRootNode();
        node = root.getNode(NODE_NAME);
        node.checkin();
        log.info("version name=[" + node.getBaseVersion().getName() +
"]");

        // close repository
        session.logout();
        ((RepositoryImpl) repository).shutdown();

        log.info("Done.");
    }

    private static void createWorkspace(Session session, String
workspaceName) throws RepositoryException {
        ((WorkspaceImpl)
session.getWorkspace()).createWorkspace(workspaceName);
    }

}

--
Tomasz Dabrowski
email: tomasz.dabrowski@cognifide.com
skype: tomekdab
www: www.cognifide.com

Mime
View raw message