Hello,
currently I'm trying to write metadata to a specific page.
It is difficult to find good groovy sample scripts, I'll share here my findings.
If you have anything to make better, don't hesitate...
Current problems:
1) I have "pagemanager"-object and I need to come from there to
contentPropertyManager.setTextProperty(contentEntityObject, "your.key", "your value");
to be able to write the value...
2) I have a "ContentEntityObject" but it is from current page, not from an indicated page...
Thanks,
Sven
Here I am for the moment:
(if I insert it with the groovy-macro tabs inside code-field the online editor here crashes)
import com.atlassian.confluence.core.ContentEntityObject;
import com.atlassian.confluence.util.GeneralUtil;
import com.atlassian.spring.container.ContainerManager;
import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.pages.Attachment;
import com.atlassian.confluence.pages.AttachmentManager;
import com.atlassian.confluence.util.velocity.VelocityUtils;
import com.atlassian.confluence.web.context.StaticHttpContext;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import javax.activation.MimetypesFileTypeMap;
import java.util.Date;
import com.atlassian.user.*;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
def String myusername = 'balu';
println('test: ' + myusername);
User user = AuthenticatedUserThreadLocal.getUser()
String username = AuthenticatedUserThreadLocal.getUsername()
ContentEntityObject ceo = context.getEntity()
//PageManager mypagemanager = pagemanager;
//contentPropertyManager.setTextProperty(contentEntityObject, "your.key", "your value");
println '<br>ceo.getAttachmentsUrlPath() = ' + ceo.getAttachmentsUrlPath()
println '<br>ceo.getPreviousVersion() = ' + ceo.getPreviousVersion()
println '→ current version = ' + (ceo.getPreviousVersion() + 1)
println '<br>'
println '<br>ceo.getContentStatus() = ' + ceo.getContentStatus()
println '<br>ceo.getDisplayTitle() = ' + ceo.getDisplayTitle()
println '<br>ceo.getIdAsString() = ' + ceo.getIdAsString()
println '<br>'
println '<br>ceo.getLabelCount() = ' + ceo.getLabelCount()
println '<br>ceo.getGlobalLabels(user) = ' + ceo.getGlobalLabels(user)
println '<br>ceo.getLabels() = ' + ceo.getLabels()
println '<br>ceo.getLabelsForDisplay() = ' + ceo.getLabelsForDisplay(user)
println '<br>ceo.getPersonalLabels() = ' + ceo.getPersonalLabels(user)
println '<br>'
println '<br>ceo.getNameForComparison() = ' + ceo.getNameForComparison()
println '<br>ceo.getTitle() = ' + ceo.getTitle()
println '<br>ceo.getType() = ' + ceo.getType()
println '<br>ceo.getUrlPath() = ' + ceo.getUrlPath()
println '<br>'
println '<br>context.getPageTitle() = ' + context.getPageTitle()
println '<br>context.getSpaceKey() = ' + context.getSpaceKey()
println '<br>context.getSiteRoot() = ' + context.getSiteRoot()
println '<br>context.getCharacterEncoding() = ' + context.getCharacterEncoding()
println '<br>context.getImagePath() = ' + context.getImagePath()
println '<br>context.getOutputType() = ' + context.getOutputType()
Community moderators have prevented the ability to post new answers.
That was a hard one, see below...
see in comment --- sorry, everytime I want to paste in the groovy code I'll get an error 500 ;-/ finally something stayed there...
(add below {groovy}...{groovy}-Tags around ;-)
Finally I could paste this in, little bit ugly...
def ContentPropertyManager mycpm = ( ContentPropertyManager ) ContainerManager.getComponent( 'contentPropertyManager' )
def Page mypageZiel = new Page()
mypageZiel = pageManager.getPage('space_key', 'titleofentry')
mycpm.setTextProperty(mypageZiel, 'metadata.Startdatum', 'startdatum')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
imports... def ContentPropertyManager mycpm = ( ContentPropertyManager ) ContainerManager.getComponent( 'contentPropertyManager' ); def Page mypageZiel = new Page(); mypageZiel = pageManager.getPage('space_key', 'titleofentry'); mycpm.setTextProperty(mypageZiel, 'metadata.Startdatum', 'startdatum'); mycpm.setTextProperty(mypageZiel, 'metadata.Fällig bis', 'faelligbis'); mycpm.setTextProperty(mypageZiel, 'metadata.Verantwortlich', 'verantwortlich');
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.confluence.core.ContentEntityObject; import com.atlassian.confluence.core.ContentPropertyManager; import com.atlassian.confluence.util.GeneralUtil; import com.atlassian.spring.container.ContainerManager; import com.atlassian.confluence.pages.Page; import com.atlassian.confluence.pages.PageManager; import com.atlassian.confluence.util.velocity.VelocityUtils; import java.util.Date; def ContentPropertyManager mycpm = ( ContentPropertyManager ) ContainerManager.getComponent( 'contentPropertyManager' ); def Page mypageZiel = new Page(); mypageZiel = pageManager.getPage('space_key', 'titleofentry'); mycpm.setTextProperty(mypageZiel, 'metadata.Startdatum', 'startdatum'); mycpm.setTextProperty(mypageZiel, 'metadata.Fällig bis', 'faelligbis'); mycpm.setTextProperty(mypageZiel, 'metadata.Verantwortlich', 'verantwortlich');
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
imports...
sorry, everytime I want to paste in the groovy code I'll get an error 500 ;-/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.confluence.core.ContentEntityObject; import com.atlassian.confluence.core.ContentPropertyManager; import com.atlassian.confluence.util.GeneralUtil; import com.atlassian.spring.container.ContainerManager; import com.atlassian.confluence.pages.Page; import com.atlassian.confluence.pages.PageManager; import com.atlassian.confluence.util.velocity.VelocityUtils; import java.util.Date; def ContentPropertyManager mycpm = ( ContentPropertyManager ) ContainerManager.getComponent( 'contentPropertyManager' ); def Page mypageZiel = new Page(); mypageZiel = pageManager.getPage('space_key', 'titleofentry'); mycpm.setTextProperty(mypageZiel, 'metadata.Startdatum', 'startdatum'); mycpm.setTextProperty(mypageZiel, 'metadata.Fällig bis', 'faelligbis'); mycpm.setTextProperty(mypageZiel, 'metadata.Verantwortlich', 'verantwortlich');
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.