use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class HierarchyManagerImpl method getName.
/**
* {@inheritDoc}
*/
public Name getName(NodeId id, NodeId parentId) throws ItemNotFoundException, RepositoryException {
NodeState parentState;
try {
parentState = (NodeState) getItemState(parentId);
} catch (NoSuchItemStateException nsis) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new ItemNotFoundException(id.toString());
} catch (ItemStateException ise) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
ChildNodeEntry entry = getChildNodeEntry(parentState, id);
if (entry == null) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new ItemNotFoundException(msg);
}
return entry.getName();
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class HierarchyManagerImpl method getName.
/**
* {@inheritDoc}
*/
public Name getName(ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (itemId.denotesNode()) {
NodeId nodeId = (NodeId) itemId;
try {
NodeState nodeState = (NodeState) getItemState(nodeId);
NodeId parentId = getParentId(nodeState);
if (parentId == null) {
// FIXME
return EMPTY_NAME;
}
return getName(nodeId, parentId);
} catch (NoSuchItemStateException nsis) {
String msg = "failed to resolve name of " + nodeId;
log.debug(msg);
throw new ItemNotFoundException(nodeId.toString());
} catch (ItemStateException ise) {
String msg = "failed to resolve name of " + nodeId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
} else {
return ((PropertyId) itemId).getName();
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class ItemSaveOperation method processShareableNodes.
/**
* Process all items given in iterator and check whether <code>mix:shareable</code>
* or (some derived node type) has been added or removed:
* <ul>
* <li>If the mixin <code>mix:shareable</code> (or some derived node type),
* then initialize the shared set inside the state.</li>
* <li>If the mixin <code>mix:shareable</code> (or some derived node type)
* has been removed, throw.</li>
* </ul>
*/
private void processShareableNodes(NodeTypeRegistry registry, Iterable<ItemState> states) throws RepositoryException {
for (ItemState is : states) {
if (is.isNode()) {
NodeState ns = (NodeState) is;
boolean wasShareable = false;
if (ns.hasOverlayedState()) {
NodeState old = (NodeState) ns.getOverlayedState();
EffectiveNodeType ntOld = getEffectiveNodeType(registry, old);
wasShareable = ntOld.includesNodeType(NameConstants.MIX_SHAREABLE);
}
EffectiveNodeType ntNew = getEffectiveNodeType(registry, ns);
boolean isShareable = ntNew.includesNodeType(NameConstants.MIX_SHAREABLE);
if (!wasShareable && isShareable) {
// mix:shareable has been added
ns.addShare(ns.getParentId());
} else if (wasShareable && !isShareable) {
// mix:shareable has been removed: not supported
String msg = "Removing mix:shareable is not supported.";
log.debug(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
}
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class ItemSaveOperation method initVersionHistories.
/**
* Initialises the version history of all new nodes of node type
* <code>mix:versionable</code>.
*
* @param states
* @return true if this call generated new transient state; otherwise false
* @throws RepositoryException
*/
private boolean initVersionHistories(SessionContext context, Iterable<ItemState> states) throws RepositoryException {
SessionImpl session = context.getSessionImpl();
ItemManager itemMgr = context.getItemManager();
// walk through list of transient items and search for new versionable nodes
boolean createdTransientState = false;
for (ItemState itemState : states) {
if (itemState.isNode()) {
NodeState nodeState = (NodeState) itemState;
EffectiveNodeType nt = getEffectiveNodeType(context.getRepositoryContext().getNodeTypeRegistry(), nodeState);
if (nt.includesNodeType(NameConstants.MIX_VERSIONABLE)) {
if (!nodeState.hasPropertyName(NameConstants.JCR_VERSIONHISTORY)) {
NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
InternalVersionManager vMgr = session.getInternalVersionManager();
/**
* check if there's already a version history for that
* node; this would e.g. be the case if a versionable
* node had been exported, removed and re-imported with
* either IMPORT_UUID_COLLISION_REMOVE_EXISTING or
* IMPORT_UUID_COLLISION_REPLACE_EXISTING;
* otherwise create a new version history
*/
VersionHistoryInfo history = vMgr.getVersionHistory(session, nodeState, null);
InternalValue historyId = InternalValue.create(history.getVersionHistoryId());
InternalValue versionId = InternalValue.create(history.getRootVersionId());
node.internalSetProperty(NameConstants.JCR_VERSIONHISTORY, historyId);
node.internalSetProperty(NameConstants.JCR_BASEVERSION, versionId);
node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
node.internalSetProperty(NameConstants.JCR_PREDECESSORS, new InternalValue[] { versionId });
createdTransientState = true;
}
} else if (nt.includesNodeType(NameConstants.MIX_SIMPLE_VERSIONABLE)) {
// we need to check the version manager for an existing
// version history, since simple versioning does not
// expose it's reference in a property
InternalVersionManager vMgr = session.getInternalVersionManager();
vMgr.getVersionHistory(session, nodeState, null);
// create isCheckedOutProperty if not already exists
NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
if (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
createdTransientState = true;
}
}
}
}
return createdTransientState;
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class ItemManager method getDefinition.
NodeDefinitionImpl getDefinition(NodeState state) throws RepositoryException {
if (state.getId().equals(sessionContext.getRootNodeId())) {
// special handling required for root node
return rootNodeDef;
}
NodeId parentId = state.getParentId();
if (parentId == null) {
// removed state has parentId set to null
// get from overlayed state
ItemState overlaid = state.getOverlayedState();
if (overlaid != null) {
parentId = overlaid.getParentId();
} else {
throw new InvalidItemStateException("Could not find parent of node " + state.getNodeId());
}
}
NodeState parentState = null;
try {
// access the parent state circumventing permission check, since
// read permission on the parent isn't required in order to retrieve
// a node's definition. see also JCR-2418
ItemData parentData = getItemData(parentId, null, false);
parentState = (NodeState) parentData.getState();
if (state.getParentId() == null) {
// that used to be the actual parent
if (parentState.getStatus() == ItemState.STATUS_NEW) {
// force getting parent from attic
parentState = null;
} else {
parentState = (NodeState) parentState.getOverlayedState();
}
}
} catch (ItemNotFoundException e) {
// parent probably removed, get it from attic. see below
}
if (parentState == null) {
try {
// use overlayed state if available
parentState = (NodeState) sism.getAttic().getItemState(parentId).getOverlayedState();
} catch (ItemStateException ex) {
throw new RepositoryException(ex);
}
}
// get child node entry
ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
if (cne == null) {
throw new InvalidItemStateException("Could not find child " + state.getNodeId() + " of node " + parentState.getNodeId());
}
NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
try {
EffectiveNodeType ent = ntReg.getEffectiveNodeType(parentState.getNodeTypeName(), parentState.getMixinTypeNames());
QNodeDefinition def;
try {
def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
} catch (ConstraintViolationException e) {
// fallback to child node definition of a nt:unstructured
ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
log.warn("Fallback to nt:unstructured due to unknown child " + "node definition for type '" + state.getNodeTypeName() + "'");
}
return sessionContext.getNodeTypeManager().getNodeDefinition(def);
} catch (NodeTypeConflictException e) {
throw new RepositoryException(e);
}
}
Aggregations