cancel
Showing results for 
Search instead for 
Did you mean: 

Registering Custom Model Again

thaneshk
Champ in-the-making
Champ in-the-making
Hi,

I have got this method from DictionaryDAOTest



NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
                    DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
                   
                    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
                    List<String> bootstrapModels = new ArrayList<String>();
                   
                    bootstrapModels.add("alfresco/model/dictionaryModel.xml");
                    bootstrapModels.add("alfresco/model/systemModel.xml");
                    bootstrapModels.add("alfresco/model/contentModel.xml");
                    bootstrapModels.add("alfresco/model/applicationModel.xml");
                    bootstrapModels.add("alfresco/extension/customModel.xml");               
                   
                    bootstrap.setModels(bootstrapModels);
                    bootstrap.setDictionaryDAO(dictionaryDAO);
                    bootstrap.bootstrap();


And i add a new property to my customModel and run this method again. But when i try to set the value for my new property i get java.null pointer exception



     [exec] 11:03:41,597 INFO  [STDOUT] java.lang.NullPointerException
     [exec] 11:03:41,597 INFO  [STDOUT]    at org.alfresco.jcr.item.PropertyImpl.checkSingleValued(PropertyImpl.java:630)
     [exec] 11:03:41,597 INFO  [STDOUT]    at org.alfresco.jcr.item.PropertyImpl.setPropertyValue(PropertyImpl.java:509)
     [exec] 11:03:41,597 INFO  [STDOUT]    at org.alfresco.jcr.item.NodeImpl.setProperty(NodeImpl.java:348)
     [exec] 11:03:41,597 INFO  [STDOUT]    at sun.reflect.GeneratedMethodAccessor326.invoke(Unknown Source)
     [exec] 11:03:41,607 INFO  [STDOUT]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [exec] 11:03:41,607 INFO  [STDOUT]    at java.lang.reflect.Method.invoke(Method.java:585)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:130)
     [exec] 11:03:41,607 INFO  [STDOUT]    at $Proxy135.setProperty(Unknown Source)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.jsp.jsp.dam_005fpoc.assetCreate_jsp._jspService(org.apache.jsp.jsp.dam_005fpoc.assetCreate_jsp:183)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
     [exec] 11:03:41,607 INFO  [STDOUT]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
     [exec] 11:03:41,607 INFO  [STDOUT]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 11:03:41,607 INFO  [STDOUT]    at com.xpflow.admin.access.RequestServiceHandler.doFilter(RequestServiceHandler.java:69)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 11:03:41,607 INFO  [STDOUT]    at com.xpflow.admin.access.SessionServiceHandler.doFilter(SessionServiceHandler.java:133)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
     [exec] 11:03:41,607 INFO  [STDOUT]    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
     [exec] 11:03:41,607 INFO  [STDOUT]    at java.lang.Thread.run(Thread.java:595)
     [exec] 11:03:41,617 INFO  [XPFlowDBManager] Local JTA Transaction rolled back as it was


Do i need to run anything else after i re-register the models.

Please let me know. Urgent help.

Thank you.
3 REPLIES 3

davidc
Star Contributor
Star Contributor
Here's some code that registers a new model programmatically and then uses the model via the JCR API.


package org.alfresco.repo.dictionary;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;

public class RegisterModel
{

   /**
    * @param args
    */
   public static void main(String[] args)
      throws Exception
   {
      // initialise application context
      // Note: the dictionary bootstrap will take during this step
        ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
        DictionaryService service = (DictionaryService)ctx.getBean(ServiceRegistry.DICTIONARY_SERVICE.getLocalName());

        // retrieve type that does not yet exist via Dictionary Service
        QName typeName = QName.createQName("newModelURI", "newType");
        TypeDefinition typeDef = service.getType(typeName);
        assert(typeDef == null);
       
        // create new model and new type (this can also be parsed from XML definition)
        M2Model model = M2Model.createModel("newModelPrefix:newModel");
        M2Namespace importD = model.createImport("http://www.alfresco.org/model/dictionary/1.0", "d");
        M2Namespace importSys = model.createImport("http://www.alfresco.org/model/system/1.0", "sys");
        M2Namespace namespace = model.createNamespace("newModelURI", "newModelPrefix");
        M2Type type = model.createType("newModelPrefix:newType");
        type.setParentName("sys:base");
        M2Property prop = type.createProperty("newModelPrefix:newProp");
        prop.setType("d:text");
       
        // register model programmatically (this is currently only possible via the Dictionary DAO)
        DictionaryDAO dao = (DictionaryDAO)ctx.getBean("dictionaryDAO");
        dao.putModel(model);

        // retrieve type that's now been registered programmatically (via Dictionary Service)
        typeDef = service.getType(typeName);
        assert(typeDef != null);

        // perform simple create of node with new type
        Repository repository = (Repository)ctx.getBean("JCR.Repository");
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
        Node rootNode = session.getRootNode();
        Node newNode = rootNode.addNode("test", "newModelPrefix:newType");
        newNode.setProperty("newModelPrefix:newProp", "dave");
               
        System.out.println(newNode.getProperty("newModelPrefix:newProp").getString());
        System.exit(0);
   }

}

naveenkumar
Champ in-the-making
Champ in-the-making
I created new content type which includes the cm:content as parent.and stored the newcontent model under extension folder.here is the code
 <type name="dml:rsscontent"> 
         <title>rsscontent</title>
         <parent>cm:content</parent>
         <properties>
            <property name="rss:title">
               <type>d:text</type>
            </property>
            <property name="rss:description">
               <type>d:text</type>
            </property>
            <property name="rss:link">
               <type>d:text</type>
            </property>
            <property name="rss:author">
               <type>d:text</type>
            </property>           
         </properties>
      </type>
 

when i create content through alfresco i am able to select the new content type(i mean rsscontent). content was created and i could view through web client.
when i addnew node through jcr api…. i want to use my new content type(i mean rsscontent) to create a content..here is my java code
Node content = rssFeeds.addNode("dml:" + item.getTitle(),"dml:rsscontent");//Here i am pointing towards my new content type but using this i am not able to create contents.
is there any other properties i need to set?            
is it possible to store the metainformation without adding content using jcr-api?

naveenkumar
Champ in-the-making
Champ in-the-making
hi david i used the same code for creating mymodel..

package org.alfresco.repo.dictionary; 

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;

public class RegisterModel
{

   /**
    * @param args
    */
   public static void main(String[] args)
      throws Exception
   {
      // initialise application context
      // Note: the dictionary bootstrap will take during this step
        ApplicationContext context= ApplicationContextHelper.getApplicationContext();
        DictionaryService service = (DictionaryService)context.getBean(ServiceRegistry.DICTIONARY_SERVICE.getLocalName());

        // retrieve type that does not yet exist via Dictionary Service
        QName typeName = QName.createQName("newModelURI", "newType");
        TypeDefinition typeDef = service.getType(typeName);
        assert(typeDef == null);
       
        // create new model and new type (this can also be parsed from XML definition)
        M2Model model = M2Model.createModel("newModelPrefix:newModel");
        M2Namespace importD = model.createImport("http://www.alfresco.org/model/dictionary/1.0", "d");
        M2Namespace importSys = model.createImport("http://www.alfresco.org/model/system/1.0", "sys");
        M2Namespace namespace = model.createNamespace("newModelURI", "newModelPrefix");
        M2Type type = model.createType("newModelPrefix:newType");
        type.setParentName("sys:base");
        M2Property prop = type.createProperty("newModelPrefix:newProp");
        prop.setType("d:text");
       
        // register model programmatically (this is currently only possible via the Dictionary DAO)
        DictionaryDAO dao = (DictionaryDAO)context.getBean("dictionaryDAO");
        dao.putModel(model);

        // retrieve type that's now been registered programmatically (via Dictionary Service)
        typeDef = service.getType(typeName);
        assert(typeDef != null);

        // perform simple create of node with new type
        Repository repository = (Repository)context.getBean("JCR.Repository");
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
        Node rootNode = session.getRootNode();
        Node newNode = rootNode.addNode("test", "newModelPrefix:newType");
        newNode.setProperty("newModelPrefix:newProp", "dave");
            setMimeType(context, newNode , MimetypeMap.MIMETYPE_TEXT_PLAIN);   
        System.out.println(newNode.getProperty("newModelPrefix:newProp").getString());
        System.exit(0);
   }
private static void setMimeType(ApplicationContext context, Node node,
         String mimeType) throws RepositoryException {
      System.out.println("mime");
      // retrieve service registry
      ServiceRegistry serviceRegistry = (ServiceRegistry) context
            .getBean(ServiceRegistry.SERVICE_REGISTRY);
      NodeService nodeService = serviceRegistry.getNodeService();

      // convert the JCR Node to an Alfresco Node Reference
      NodeRef nodeRef = JCRNodeRef.getNodeRef(node);

      // retrieve the Content Property (represented as a ContentData object in Alfresco)
      ContentData content = (ContentData) nodeService.getProperty(nodeRef,
            ContentModel.PROP_CONTENT);

      // update the Mimetype
      content = ContentData.setMimetype(content, mimeType);
      nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, content);
   }   
}

After running the class able to see the content information in the database but  when i login into the web client not able to see the content…

Please help me ….. its urgent….

Thanks
Naveen