Re: [xwiki-users] Creating class properties with groovy
Similar question has appeared in this list earlier with no good answer. Though I suspect, this approach seems necessary is due to weak design. Can you describe use case why it seems necessary in place of database list, where you can set hql query for filtering necessary elements? Valdis Essentially I'm creating a sort of template for a space that I will want to duplicate later. I have scripts that create objects from a spreadsheet specifically for a certain class in this space. Rather than duplicating the class by hand on the next space I want these scripts/objects on, I'd like to be able to quickly and safely duplicate the class, so I wanted to write a quick groovy script to do it. If there is an easier way of doing this, I'd appreciate any ideas. -Mike I want to create properties for a new class on a blank document with groovy. I can do the following: def doc = xwiki.getDocument(space.docname) c = doc.getxWikiClass(); and look at elements of a class that already exists by doing: prop = c.get('propertyname') propToEdit = prop.getPropertyClass propToEdit.setValues('a|b|c') But, how can I add a new property to a class that has no existing properties/fields? Thanks, -Mike _ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccountocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4 ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Creating class properties with groovy
It wouldn't work to copy the document with the class into each space? If I were to go about creating classes, I would use the same technique that the XWiki core uses to create the comments class. Note that you will have to have programming rights and in groovy or velocity you will need to call doc.getDocument() to get the underlying XWikiDocument. Example: public BaseClass getCommentsClass(XWikiContext context) throws XWikiException { XWikiDocument doc; boolean needsUpdate = false; doc = getDocument(XWiki.XWikiComments, context); BaseClass bclass = doc.getXClass(); if (context.get(initdone) != null) { return bclass; } bclass.setName(XWiki.XWikiComments); needsUpdate |= bclass.addTextField(author, Author, 30); needsUpdate |= bclass.addTextAreaField(highlight, Highlighted Text, 40, 2); needsUpdate |= bclass.addNumberField(replyto, Reply To, 5, integer); needsUpdate |= bclass.addDateField(date, Date); needsUpdate |= bclass.addTextAreaField(comment, Comment, 40, 5); needsUpdate |= setClassDocumentFields(doc, XWiki Comment Class); if (needsUpdate) { saveDocument(doc, context); } return bclass; } Mike Davis wrote: Similar question has appeared in this list earlier with no good answer. Though I suspect, this approach seems necessary is due to weak design. Can you describe use case why it seems necessary in place of database list, where you can set hql query for filtering necessary elements? Valdis Essentially I'm creating a sort of template for a space that I will want to duplicate later. I have scripts that create objects from a spreadsheet specifically for a certain class in this space. Rather than duplicating the class by hand on the next space I want these scripts/objects on, I'd like to be able to quickly and safely duplicate the class, so I wanted to write a quick groovy script to do it. If there is an easier way of doing this, I'd appreciate any ideas. -Mike I want to create properties for a new class on a blank document with groovy. I can do the following: def doc = xwiki.getDocument(space.docname) c = doc.getxWikiClass(); and look at elements of a class that already exists by doing: prop = c.get('propertyname') propToEdit = prop.getPropertyClass propToEdit.setValues('a|b|c') But, how can I add a new property to a class that has no existing properties/fields? Thanks, -Mike ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Creating class properties with groovy
Hi Mike, On Mon, Apr 12, 2010 at 20:53, Mike Davis sk00te...@hotmail.com wrote: Similar question has appeared in this list earlier with no good answer. Though I suspect, this approach seems necessary is due to weak design. Can you describe use case why it seems necessary in place of database list, where you can set hql query for filtering necessary elements? Valdis Essentially I'm creating a sort of template for a space that I will want to duplicate later. I have scripts that create objects from a spreadsheet specifically for a certain class in this space. Rather than duplicating the class by hand on the next space I want these scripts/objects on, I'd like to be able to quickly and safely duplicate the class, so I wanted to write a quick groovy script to do it. If there is an easier way of doing this, I'd appreciate any ideas. Have you tried copying the document holding the class? Guillaume -Mike I want to create properties for a new class on a blank document with groovy. I can do the following: def doc = xwiki.getDocument(space.docname) c = doc.getxWikiClass(); and look at elements of a class that already exists by doing: prop = c.get('propertyname') propToEdit = prop.getPropertyClass propToEdit.setValues('a|b|c') But, how can I add a new property to a class that has no existing properties/fields? Thanks, -Mike _ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccountocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4 ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users -- Guillaume Lerouge Product Manager - XWiki SAS Skype: wikibc Twitter: glerouge http://guillaumelerouge.com/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
[xwiki-users] Creating class properties with groovy
I want to create properties for a new class on a blank document with groovy. I can do the following: def doc = xwiki.getDocument(space.docname) c = doc.getxWikiClass(); and look at elements of a class that already exists by doing: prop = c.get('propertyname') propToEdit = prop.getPropertyClass propToEdit.setValues('a|b|c') But, how can I add a new property to a class that has no existing properties/fields? Thanks, -Mike _ The New Busy is not the old busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users