jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ferdinand Malzer (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JCR-3548) using properties property defined as OnParentVersionAction.IGNORE could not be changed without check-out (see jcr 2.0 chapter 15.2.2) description holds reproducer
Date Wed, 27 Mar 2013 10:11:15 GMT
Ferdinand Malzer created JCR-3548:
-------------------------------------

             Summary: using properties property defined as OnParentVersionAction.IGNORE could
not be changed without check-out (see jcr 2.0 chapter 15.2.2) description holds reproducer
                 Key: JCR-3548
                 URL: https://issues.apache.org/jira/browse/JCR-3548
             Project: Jackrabbit Content Repository
          Issue Type: Bug
          Components: jackrabbit-core
    Affects Versions: 2.4.3
         Environment: windows xp on hpq_nc8540
            Reporter: Ferdinand Malzer
            Priority: Minor


import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.nodetype.NodeTypeManager;
import javax.jcr.nodetype.NodeTypeTemplate;
import javax.jcr.nodetype.PropertyDefinitionTemplate;
import javax.jcr.query.qom.QueryObjectModelConstants;
import javax.jcr.version.OnParentVersionAction;

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


import sun.net.www.MimeTable;


public class ReproduceOPVIgnoreProblem {

    private static final String NT_RESOURCE = "my_Resource";
    private static final String RESOURCE_PROP_TEST = "my_TestProperty";
    private static final String CONTENT = "some information";
    private static final String RES_NAME = "test.txt";

    private RepositoryImpl repository;


    public static void main(String[] args) throws Exception {
        ReproduceOPVIgnoreProblem useCase = new ReproduceOPVIgnoreProblem();
            useCase.run();
    }


    private void run() throws IOException, RepositoryException {
        RepositoryConfig config = RepositoryConfig.install(new File("C:/JavaDev/jaRabT1/jrContent"));
        repository = RepositoryImpl.create(config);

        addResourceNodeType();
        System.out.println("node type added");
        createResourceAndCheckIn();
        System.out.println("new node checked-in");
        System.out.println("################# before change OPV property ####################");
        changeOPVIgnoreproperty();
        System.out.println("################# after change OPV property ####################");
        deleteResource();
        System.out.println("node deleted");
    }


    private void deleteResource() throws RepositoryException {
      Session session = null;
      try {
          session = login();
          Node node = session.getRootNode().getNode(RES_NAME);
          node.remove();
          session.save();
      } catch (Exception e) {
          e.printStackTrace(System.out);
      } finally {
          if (session != null) session.logout();
      }
    }


    private void createResourceAndCheckIn() {
      Session session = null;
      try {
          session = login();
          Node parentNode = session.getRootNode();
          Node fileNode = parentNode.addNode(RES_NAME, NT_RESOURCE);
          fileNode.addMixin(JcrConstants.MIX_VERSIONABLE);
          fileNode.addMixin(JcrConstants.MIX_LOCKABLE);

          Node resNode = fileNode.addNode(JcrConstants.JCR_CONTENT, "nt:resource");
          String mimeType = getMimeType(RES_NAME);
          resNode.setProperty("jcr:mimeType", mimeType);
          InputStream stream = new BufferedInputStream(new ByteArrayInputStream(CONTENT.getBytes()));
          Binary binary = session.getValueFactory().createBinary(stream);
          resNode.setProperty(JcrConstants.JCR_DATA ,binary);
          session.save();
          session.getWorkspace().getVersionManager().checkin(fileNode.getPath());
      } catch (Exception e) {
          e.printStackTrace(System.out);
      } finally {
          if (session != null) session.logout();
      }
    }


    private void changeOPVIgnoreproperty () throws RepositoryException {
        Session session = null;
        try {
            session = login();
            Node node = session.getRootNode().getNode(RES_NAME);
            node.setProperty(RESOURCE_PROP_TEST, "testValue");
            session.save();

        } catch (Exception e) {
            e.printStackTrace(System.out);
        } finally {
            if (session != null) session.logout();
        }
    }

    private void addResourceNodeType() throws RepositoryException {

        Session session = null;
        try {
            session = login();
            NodeTypeManager ntm =session.getWorkspace().getNodeTypeManager();
            NodeTypeTemplate gcms_content = ntm.createNodeTypeTemplate();
            gcms_content.setDeclaredSuperTypeNames(new String[]{JcrConstants.NT_FILE});
            gcms_content.setName(NT_RESOURCE);
            gcms_content.setQueryable(true);
            @SuppressWarnings("unchecked")
            List<PropertyDefinitionTemplate> propDefList = gcms_content.getPropertyDefinitionTemplates();

            //additional properties
            PropertyDefinitionTemplate propDef = ntm.createPropertyDefinitionTemplate();
            //ALL or REGISTERED
            propDef.setName(RESOURCE_PROP_TEST);
            propDef.setAutoCreated(false);
            propDef.setRequiredType(PropertyType.STRING);
            propDef.setAvailableQueryOperators(new String[] {QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO});
            propDef.setOnParentVersion(OnParentVersionAction.IGNORE);
            propDefList.add(propDef);

            ntm.registerNodeType(gcms_content, true);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        } finally {
            if (session != null) session.logout();
        }
    }


    private String getMimeType(String fileName) {
        MimeTable mt = MimeTable.getDefaultTable();
        String mimeType = mt.getContentTypeFor(fileName);
        if (mimeType==null) mimeType="application/octet-stream";
        return mimeType;
    }

    private Session login () throws RepositoryException {
        return repository.login(new SimpleCredentials("admin","admin".toCharArray()));
    }

}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message