use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class SessionImporter method importNode.
/**
*
* @param nodeInfo
* @param parent
* @return
* @throws ConstraintViolationException
* @throws ItemNotFoundException
* @throws RepositoryException
*/
private NodeState importNode(NodeInfo nodeInfo, NodeState parent) throws ConstraintViolationException, ItemNotFoundException, RepositoryException {
Name[] parentNtNames = parent.getAllNodeTypeNames();
if (parent.hasPropertyName(nodeInfo.getName())) {
/**
* a property with the same name already exists; if this property
* has been imported as well (e.g. through document view import
* where an element can have the same name as one of the attributes
* of its parent element) we have to rename the conflicting property;
*
* see http://issues.apache.org/jira/browse/JCR-61
*/
PropertyState conflicting = parent.getPropertyState(nodeInfo.getName());
if (conflicting.getStatus() == Status.NEW) {
// assume this property has been imported as well;
// rename conflicting property
// TODO: use better reversible escaping scheme to create unique name
Name newName = session.getNameFactory().create(nodeInfo.getName().getNamespaceURI(), nodeInfo.getName().getLocalName() + "_");
if (parent.hasPropertyName(newName)) {
newName = session.getNameFactory().create(newName.getNamespaceURI(), newName.getLocalName() + "_");
}
// since name changes, need to find new applicable definition
QPropertyDefinition propDef;
if (conflicting.getValues().length == 1) {
// could be single- or multi-valued (n == 1)
try {
// try single-valued
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), false);
} catch (ConstraintViolationException cve) {
// try multi-valued
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), true);
}
} else {
// can only be multi-valued (n == 0 || n > 1)
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), true);
}
Operation ap = AddProperty.create(parent, newName, conflicting.getType(), propDef, conflicting.getValues());
stateMgr.execute(ap);
Operation rm = Remove.create(conflicting);
stateMgr.execute(rm);
}
}
// do create new nodeState
QNodeDefinition def = session.getItemDefinitionProvider().getQNodeDefinition(parentNtNames, nodeInfo.getName(), nodeInfo.getNodeTypeName());
if (def.isProtected()) {
log.debug("Skipping protected nodeState (" + nodeInfo.getName() + ")");
return null;
} else {
Name ntName = nodeInfo.getNodeTypeName();
if (ntName == null) {
// use default node type
ntName = def.getDefaultPrimaryType();
}
Operation an = AddNode.create(parent, nodeInfo.getName(), ntName, nodeInfo.getUUID());
stateMgr.execute(an);
// retrieve id of state that has been created during execution of AddNode
NodeState childState = (NodeState) ((AddNode) an).getAddedStates().get(0);
// and set mixin types
Name[] mixinNames = nodeInfo.getMixinNames();
if (mixinNames != null && mixinNames.length > 0) {
Operation sm = SetMixin.create(childState, nodeInfo.getMixinNames());
stateMgr.execute(sm);
}
return childState;
}
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class SessionImporter method importProperty.
/**
*
* @param pi
* @param parentState
* @param resolver
* @throws RepositoryException
* @throws ConstraintViolationException
*/
private void importProperty(PropInfo pi, NodeState parentState, NamePathResolver resolver) throws RepositoryException, ConstraintViolationException {
Name propName = pi.getName();
TextValue[] tva = pi.getValues();
int infoType = pi.getType();
PropertyState propState = null;
QPropertyDefinition def = null;
NodeEntry parentEntry = (NodeEntry) parentState.getHierarchyEntry();
PropertyEntry pEntry = parentEntry.getPropertyEntry(propName);
if (pEntry != null) {
// a property with that name already exists...
try {
PropertyState existing = pEntry.getPropertyState();
def = existing.getDefinition();
if (def.isProtected()) {
// skip protected property
log.debug("skipping protected property " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
return;
}
if (def.isAutoCreated() && (existing.getType() == infoType || infoType == PropertyType.UNDEFINED) && def.isMultiple() == existing.isMultiValued()) {
// this property has already been auto-created, no need to create it
propState = existing;
} else {
throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
}
} catch (ItemNotFoundException e) {
// property doesn't exist any more
// -> ignore
}
}
Name[] parentNtNames = parentState.getAllNodeTypeNames();
if (def == null) {
// there's no property with that name, find applicable definition
if (tva.length == 1) {
// could be single- or multi-valued (n == 1)
def = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, propName, infoType);
} else {
// can only be multi-valued (n == 0 || n > 1)
def = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, propName, infoType, true);
}
if (def.isProtected()) {
// skip protected property
log.debug("skipping protected property " + propName);
return;
}
}
// retrieve the target property type needed for creation of QValue(s)
// including an eventual conversion. the targetType is then needed for
// setting/updating the type of the property-state.
int targetType = def.getRequiredType();
if (targetType == PropertyType.UNDEFINED) {
if (infoType == PropertyType.UNDEFINED) {
targetType = PropertyType.STRING;
} else {
targetType = infoType;
}
}
QValue[] values = getPropertyValues(pi, targetType, def.isMultiple(), resolver);
if (propState == null) {
// create new property
Operation ap = AddProperty.create(parentState, propName, targetType, def, values);
stateMgr.execute(ap);
propState = parentEntry.getPropertyEntry(propName).getPropertyState();
} else {
// modify value of existing property
Operation sp = SetPropertyValue.create(propState, values, targetType);
stateMgr.execute(sp);
}
// store reference for later resolution
if (propState.getType() == PropertyType.REFERENCE) {
refTracker.processedReference(propState);
}
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class VersionManagerImpl method removeActivity.
public void removeActivity(NodeState activityState) throws UnsupportedRepositoryOperationException, RepositoryException {
Operation op = RemoveActivity.create(activityState, workspaceManager.getHierarchyManager());
workspaceManager.execute(op);
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class VersionManagerImpl method resolveMergeConflict.
public void resolveMergeConflict(NodeState nodeState, NodeState versionState, boolean done) throws RepositoryException {
NodeId vId = versionState.getNodeId();
PropertyState mergeFailedState = nodeState.getPropertyState(NameConstants.JCR_MERGEFAILED);
QValue[] vs = mergeFailedState.getValues();
NodeId[] mergeFailedIds = new NodeId[vs.length - 1];
for (int i = 0, j = 0; i < vs.length; i++) {
NodeId id = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
if (!id.equals(vId)) {
mergeFailedIds[j] = id;
j++;
}
// else: the version id is being solved by this call and not
// part of 'jcr:mergefailed' any more
}
PropertyState predecessorState = nodeState.getPropertyState(NameConstants.JCR_PREDECESSORS);
vs = predecessorState.getValues();
int noOfPredecessors = (done) ? vs.length + 1 : vs.length;
NodeId[] predecessorIds = new NodeId[noOfPredecessors];
int i = 0;
while (i < vs.length) {
predecessorIds[i] = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
i++;
}
if (done) {
predecessorIds[i] = vId;
}
Operation op = ResolveMergeConflict.create(nodeState, mergeFailedIds, predecessorIds, done);
workspaceManager.execute(op);
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class VersionManagerImpl method addVersionLabel.
public void addVersionLabel(NodeState versionHistoryState, NodeState versionState, Name qLabel, boolean moveLabel) throws RepositoryException {
Operation op = AddLabel.create(versionHistoryState, versionState, qLabel, moveLabel);
workspaceManager.execute(op);
}
Aggregations