/** * Returns the name of the user that last activated the node or null if no activating user has been stored on the node. */ public static String getLastActivatedBy(Node node) throws RepositoryException { return node.hasProperty(LAST_ACTIVATED_BY) ? node.getProperty(LAST_ACTIVATED_BY).getString() : null; }
/** * Replace a Property value. */ public static void updatePropertyIfExist(Node node, String propertyName, String oldValue, String newValue) throws RepositoryException { if(node.hasProperty(propertyName) && oldValue.equals(node.getProperty(propertyName).getString())){ node.setProperty(propertyName, newValue); } }
/** * Updates existing property or creates a new one if it doesn't exist already. */ public static void updateOrCreate(Node node, String string, GregorianCalendar gregorianCalendar) throws RepositoryException { if (node.hasProperty(string)) { node.getProperty(string).setValue(gregorianCalendar); } else { node.setProperty(string, gregorianCalendar); } }
protected void updateVersion(Node node) throws RepositoryException { if (node.hasProperty(ArtefactProperties.PROP_VERSION)) { long l = ((MAX_MM_INT & 0x7FFF) << 16) | (MAX_MM_INT & 0x7FFF); node.setProperty(ArtefactProperties.PROP_VERSION, l); } node.setProperty(ArtefactProperties.PROP_REVISION, version.getRevision()); }
protected void setDefaultHideInNavValueIfNotExisting() { try { if (!content.hasProperty(HIDE_IN_NAV_PROPERTY_NAME)) { content.setProperty(HIDE_IN_NAV_PROPERTY_NAME, HIDE_IN_NAV_DEFAULT_VALUE); content.getSession().save(); } } catch (RepositoryException e) { log.error("Unable to create property 'hideInNav' with value '{}' on node {}", new Object[]{HIDE_IN_NAV_DEFAULT_VALUE, JcrUtils.toString(content)}); log.error(e.getMessage(), e); } }
@Override public void visit(Node node) throws RepositoryException { if (node.hasProperty(CategorizationTemplatingFunctions.PROPERTY_NAME_CATEGORIES)) { node.getProperty(CategorizationTemplatingFunctions.PROPERTY_NAME_CATEGORIES).remove(); node.getSession().save(); } } });
protected void setUp() throws Exception { super.setUp(); testNode = testRootNode.addNode(nodeName1, testNodeType); testRootNode.getSession().save(); // special case for repositories that do allow binary property // values, but only on jcr:content/jcr:data if (propertyName1.equals("jcr:data") && testNode.hasNode("jcr:content") && testNode.getNode("jcr:content").isNodeType("nt:resource") && ! testNode.hasProperty("jcr:data")) { testNode = testNode.getNode("jcr:content"); } }
public void testNewProperty() throws RepositoryException, LockException, ConstraintViolationException, VersionException { Property p = testRootNode.setProperty(propertyName1, testValue); testRootNode.refresh(false); try { p.getString(); fail("Refresh 'false' must invalidate a new child property"); } catch (InvalidItemStateException e) { // ok } assertFalse("Refresh 'false' must remove a new child property", testRootNode.hasProperty(propertyName1)); }
@Override protected void leaving(Node node, int level) throws RepositoryException { if (node.hasProperty("hipposys:value") && node.getProperty("hipposys:value").getString().equals("hippo:facetsubsearch")) { node.setProperty("hipposys:value", "hipposys:facetsubsearch"); } } });
/** * Returns the latest activated version name or null if the version name isn't set. */ public static String getLastActivatedVersion(Node node) throws RepositoryException { return node.hasProperty(LAST_ACTIVATED_VERSION) ? node.getProperty(LAST_ACTIVATED_VERSION).getString() : null; }
private void setProperty(final Node newNode, final Node cloneNode, final String propertyName) throws RepositoryException { if (cloneNode.hasProperty(propertyName)) { final Property property = cloneNode.getProperty(propertyName); newNode.setProperty(propertyName, property.getValue()); } }
/** * Corrects wrong template category. */ private void setCorrectFeatureCategory(Node templateNode) throws RepositoryException { if(getPersistentMapService().getCustomMap(PersistentMapConstant.TEMPLATE_CONTAINING_WRONG_CAT).containsKey(templateNode.getName()) && templateNode.hasProperty("category")){ templateNode.setProperty("category", "feature"); } }
public Property addProperty(String key, Value value) throws RepositoryException { Node parent = getOrCreateParent(key); if (parent.hasProperty(key)) { throw new ItemExistsException(key); } Property p = parent.setProperty(key, value); treeManager.split(this, parent, p); if (autoSave) { p.getSession().save(); } return p; }
@Test public void testMoveAndRemovePropertyAtSource2() throws Exception { setupMovePermissions(); allow(childNPath, privilegesFromName(PrivilegeConstants.REP_REMOVE_PROPERTIES)); testSession.move(nodePath3, siblingDestPath); Node n = testSession.getNode(childNPath); assertTrue(n.hasProperty(propertyName1)); n.getProperty(propertyName1).remove(); testSession.save(); }
public void testJcrVersionHistoryProperty() throws Exception { Node n = testRootNode.addNode(nodeName1, testNodeType); n.addMixin(JcrConstants.MIX_VERSIONABLE); superuser.save(); assertTrue(n.hasProperty(JcrConstants.JCR_VERSIONHISTORY)); }
public void testRemovedNewProperty() throws RepositoryException, LockException, ConstraintViolationException, VersionException { Property p = testRootNode.setProperty(propertyName1, testValue); p.remove(); testRootNode.refresh(false); try { p.getString(); fail("Refresh 'false' must not bring a removed new child property back to life."); } catch (InvalidItemStateException e) { // ok } assertFalse("Refresh 'false' must not bring a removed new child property back to life.", testRootNode.hasProperty(propertyName1)); }
@Override protected void setTransformerClass(Node controlNode) throws RepositoryException { if (controlNode.hasProperty("saveHandler")) { String saveHandler = controlNode.getProperty("saveHandler").getString(); if (!saveHandler.equals("info.magnolia.module.categorization.controls.CategorizationSaveHandler")) { controlNode.setProperty("transformerClass", MultiValueSubChildrenNodeTransformer.class.getName()); } } } }
/** * Returns the comment set when then node was last versioned or null if no comment has been set. */ public static String getComment(Node node) throws RepositoryException { return node.hasProperty(COMMENT) ? node.getProperty(COMMENT).getString() : null; }
private static void updateCleanerToProcessor(final Node node, final String processorType) throws RepositoryException { if (node.hasProperty(HTMLCLEANER_ID)) { node.getProperty(HTMLCLEANER_ID).remove(); } node.setProperty(HTMLPROCESSOR_ID, processorType); }
@Override protected Node doExec(Node context, ErrorHandler errorHandler) throws RepositoryException { if (context.hasProperty(name)) { throw new ItemExistsException(String.format("Property %s already exists at %s", name, context.getPath())); } final Value value = PropertyUtil.createValue(newValue, context.getSession().getValueFactory()); context.setProperty(name, value); return context; } };