use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class BundleBindingTest method testComplexBundle.
/**
* Tests serialization of a complex bundle.
*/
public void testComplexBundle() throws Exception {
NodeId id = new NodeId(1, 2);
NodePropBundle bundle = new NodePropBundle(id);
bundle.setParentId(new NodeId(3, 4));
bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
bundle.setMixinTypeNames(Collections.singleton(NameConstants.MIX_CREATED));
bundle.setReferenceable(true);
bundle.setSharedSet(new HashSet<NodeId>(Arrays.asList(new NodeId(5, 6), new NodeId(7, 8), new NodeId(9, 10))));
PropertyEntry property;
property = new PropertyEntry(new PropertyId(id, NameConstants.JCR_CREATED));
property.setType(PropertyType.DATE);
property.setMultiValued(false);
Calendar date = Calendar.getInstance();
date.setTimeInMillis(1234567890);
property.setValues(new InternalValue[] { InternalValue.create(date) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, NameConstants.JCR_CREATEDBY));
property.setType(PropertyType.STRING);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create("test") });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "binary")));
property.setType(PropertyType.BINARY);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "boolean")));
property.setType(PropertyType.BOOLEAN);
property.setMultiValued(true);
property.setValues(new InternalValue[] { InternalValue.create(true), InternalValue.create(false) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "date")));
property.setType(PropertyType.DATE);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(date) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "decimal")));
property.setType(PropertyType.DECIMAL);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(new BigDecimal("1234567890.0987654321")) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "double")));
property.setType(PropertyType.DOUBLE);
property.setMultiValued(true);
property.setValues(new InternalValue[] { InternalValue.create(1.0), InternalValue.create(Math.PI) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "long")));
property.setType(PropertyType.LONG);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(1234567890) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "name")));
property.setType(PropertyType.NAME);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(NameConstants.JCR_MIMETYPE) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "path")));
property.setType(PropertyType.PATH);
property.setMultiValued(true);
PathFactory pathFactory = PathFactoryImpl.getInstance();
Path root = pathFactory.getRootPath();
Path path = pathFactory.create(root, NameConstants.JCR_SYSTEM, false);
property.setValues(new InternalValue[] { InternalValue.create(root), InternalValue.create(path) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "reference")));
property.setType(PropertyType.REFERENCE);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(new NodeId(11, 12)) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "string")));
property.setType(PropertyType.STRING);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create("test") });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "uri")));
property.setType(PropertyType.URI);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(new URI("http://jackrabbit.apache.org/")) });
bundle.addProperty(property);
property = new PropertyEntry(new PropertyId(id, factory.create("", "weakreference")));
property.setType(PropertyType.WEAKREFERENCE);
property.setMultiValued(false);
property.setValues(new InternalValue[] { InternalValue.create(new NodeId(13, 14), true) });
bundle.addProperty(property);
bundle.addChildNodeEntry(NameConstants.JCR_SYSTEM, new NodeId(15, 16));
bundle.addChildNodeEntry(NameConstants.JCR_VERSIONSTORAGE, new NodeId(17, 18));
assertBundleRoundtrip(bundle);
assertBundleSerialization(bundle, new byte[] { 2, 0, 0, 1, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 2, 0, 0, 0, 4, -1, -1, -1, -1, 0, 0, 0, 6, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 73, -106, 2, -46, 0, 0, 0, 6, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 116, 101, 115, 116, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 6, 1, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 6, 0, 0, 0, 13, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 109, 105, 109, 101, 84, 121, 112, 101, 0, 0, 0, 6, 0, 0, 0, 15, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 6, 0, 0, 0, 18, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 9, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 49, 57, 55, 48, 45, 48, 49, 45, 49, 53, 84, 48, 55, 58, 53, 54, 58, 48, 55, 46, 56, 57, 48, 43, 48, 49, 58, 48, 48, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 6, 0, 0, 0, 17, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 104, 116, 116, 112, 58, 47, 47, 106, 97, 99, 107, 114, 97, 98, 98, 105, 116, 46, 97, 112, 97, 99, 104, 101, 46, 111, 114, 103, 47, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 116, 101, 115, 116, 0, 0, 0, 6, 0, 0, 0, 11, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 2, 63, -16, 0, 0, 0, 0, 0, 0, 64, 9, 33, -5, 84, 68, 45, 24, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 49, 57, 55, 48, 45, 48, 49, 45, 49, 53, 84, 48, 55, 58, 53, 54, 58, 48, 55, 46, 56, 57, 48, 43, 48, 49, 58, 48, 48, 0, 0, 0, 6, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 1, 1, 0, 21, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 46, 48, 57, 56, 55, 54, 53, 52, 51, 50, 49, 0, 0, 0, 6, 0, 0, 0, 14, 0, 0, 0, 8, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 123, 125, 0, 0, 0, 37, 123, 125, 9, 123, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 106, 99, 112, 46, 111, 114, 103, 47, 106, 99, 114, 47, 49, 46, 48, 125, 115, 121, 115, 116, 101, 109, -1, -1, -1, -1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 6, 115, 121, 115, 116, 101, 109, 1, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 14, 118, 101, 114, 115, 105, 111, 110, 83, 116, 111, 114, 97, 103, 101, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 8, 1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0 });
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class ChangeLogRecord method readEventRecord.
/**
* Read an event record.
*
* @throws JournalException if an error occurs
*/
private void readEventRecord() throws JournalException {
int type = record.readByte();
NodeId parentId = record.readNodeId();
Path parentPath = record.readPath();
NodeId childId = record.readNodeId();
Path childRelPath = record.readPathElement();
Name ntName = record.readQName();
Set<Name> mixins = new HashSet<Name>();
int mixinCount = record.readInt();
for (int i = 0; i < mixinCount; i++) {
mixins.add(record.readQName());
}
String userId = record.readString();
Map<String, InternalValue> info = null;
if (type == Event.NODE_MOVED) {
info = new HashMap<String, InternalValue>();
// read info map
int infoSize = record.readInt();
for (int i = 0; i < infoSize; i++) {
String key = record.readString();
int propType = record.readInt();
InternalValue value;
if (propType == PropertyType.UNDEFINED) {
// indicates null value
value = null;
} else {
value = InternalValue.valueOf(record.readString(), propType);
}
info.put(key, value);
}
}
EventState es = createEventState(type, parentId, parentPath, childId, childRelPath, ntName, mixins, userId);
if (info != null) {
es.setInfo(info);
}
events.add(es);
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class VersionManagerImpl method mergeOrUpdate.
/**
* Combines merge and update method
* @param state the state to merge or update
* @param srcWorkspaceName source workspace name
* @param failedIds list that will contain the failed ids.
* if <code>null</code> and update will be performed.
* @param bestEffort best effort flag
* @param isShallow is shallow flag
* @throws RepositoryException if an error occurs
*/
private void mergeOrUpdate(NodeStateEx state, String srcWorkspaceName, List<ItemId> failedIds, boolean bestEffort, boolean isShallow) throws RepositoryException {
// if same workspace, ignore
if (!srcWorkspaceName.equals(session.getWorkspace().getName())) {
// check authorization for specified workspace
if (!session.getAccessManager().canAccess(srcWorkspaceName)) {
String msg = "not authorized to access " + srcWorkspaceName;
log.error(msg);
throw new AccessDeniedException(msg);
}
// get root node of src workspace
SessionImpl srcSession = null;
try {
// create session on other workspace for current subject
// (may throw NoSuchWorkspaceException and AccessDeniedException)
srcSession = ((RepositoryImpl) session.getRepository()).createSession(session.getSubject(), srcWorkspaceName);
WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
NodeId rootNodeId = ((NodeImpl) srcSession.getRootNode()).getNodeId();
NodeStateEx srcRoot = new NodeStateEx(srcWsp.getItemStateManager(), ntReg, rootNodeId);
merge(state, srcRoot, failedIds, bestEffort, isShallow);
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
if (srcSession != null) {
// we don't need the other session anymore, logout
srcSession.logout();
}
}
}
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class DescendantSelfAxisQuery method execute.
//------------------------< JackrabbitQuery >-------------------------------
/**
* {@inheritDoc}
*/
public QueryHits execute(final JackrabbitIndexSearcher searcher, final SessionImpl session, final Sort sort) throws IOException {
if (sort.getSort().length == 0 && subQueryMatchesAll()) {
// maps path String to ScoreNode
Map<String, ScoreNode> startingPoints = new TreeMap<String, ScoreNode>();
QueryHits result = searcher.evaluate(getContextQuery());
try {
// intermediate ChildNodesQueryHits are required.
for (int i = 2; i <= getMinLevels(); i++) {
result = new ChildNodesQueryHits(result, session);
}
ScoreNode sn;
while ((sn = result.nextScoreNode()) != null) {
NodeId id = sn.getNodeId();
try {
Node node = session.getNodeById(id);
startingPoints.put(node.getPath(), sn);
} catch (ItemNotFoundException e) {
// JCR-3001 access denied to score node, will just skip it
log.warn("Access denied to node id {}.", id);
} catch (RepositoryException e) {
throw Util.createIOException(e);
}
}
} finally {
result.close();
}
// prune overlapping starting points
String previousPath = null;
for (Iterator<String> it = startingPoints.keySet().iterator(); it.hasNext(); ) {
String path = it.next();
// current path is obsolete
if (previousPath != null && path.startsWith(previousPath)) {
it.remove();
} else {
previousPath = path;
}
}
final Iterator<ScoreNode> scoreNodes = startingPoints.values().iterator();
return new AbstractQueryHits() {
private NodeTraversingQueryHits currentTraversal;
{
fetchNextTraversal();
}
public void close() throws IOException {
if (currentTraversal != null) {
currentTraversal.close();
}
}
public ScoreNode nextScoreNode() throws IOException {
while (currentTraversal != null) {
ScoreNode sn = currentTraversal.nextScoreNode();
if (sn != null) {
return sn;
} else {
fetchNextTraversal();
}
}
// if we get here there are no more score nodes
return null;
}
private void fetchNextTraversal() throws IOException {
if (currentTraversal != null) {
currentTraversal.close();
}
currentTraversal = null;
// iterate until we find a good one
while (scoreNodes.hasNext()) {
ScoreNode sn = scoreNodes.next();
NodeId id = sn.getNodeId();
try {
Node node = session.getNodeById(id);
currentTraversal = new NodeTraversingQueryHits(node, getMinLevels() == 0);
break;
} catch (ItemNotFoundException e) {
// JCR-3001 node access denied, will just skip it
log.warn("Access denied to node id {}.", id);
} catch (RepositoryException e) {
throw Util.createIOException(e);
}
}
}
};
} else {
return null;
}
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class ConsistencyCheck method checkIndexConsistency.
private void checkIndexConsistency() throws IOException {
log.info("Checking index consistency");
// Ids of multiple nodes in the index
Set<NodeId> multipleEntries = new HashSet<NodeId>();
CachingMultiIndexReader reader = index.getIndexReader();
try {
for (int i = 0; i < reader.maxDoc(); i++) {
if (i > 10 && i % (reader.maxDoc() / 5) == 0) {
long progress = Math.round((100.0 * (float) i) / ((float) reader.maxDoc() * 2f));
log.info("progress: " + progress + "%");
}
if (reader.isDeleted(i)) {
continue;
}
Document d = reader.document(i, FieldSelectors.UUID);
NodeId id = new NodeId(d.get(FieldNames.UUID));
if (!isIgnored(id)) {
boolean nodeExists = nodeIds.containsKey(id);
if (nodeExists) {
Boolean alreadyIndexed = nodeIds.put(id, Boolean.TRUE);
if (alreadyIndexed) {
multipleEntries.add(id);
}
} else {
errors.add(new NodeDeleted(id));
}
}
}
} finally {
reader.release();
}
// create multiple entries errors
for (NodeId id : multipleEntries) {
errors.add(new MultipleEntries(id));
}
reader = index.getIndexReader();
try {
// run through documents again and check parent
for (int i = 0; i < reader.maxDoc(); i++) {
if (i > 10 && i % (reader.maxDoc() / 5) == 0) {
long progress = Math.round((100.0 * (float) i) / ((float) reader.maxDoc() * 2f));
log.info("progress: " + (progress + 50) + "%");
}
if (reader.isDeleted(i)) {
continue;
}
Document d = reader.document(i, FieldSelectors.UUID_AND_PARENT);
NodeId id = new NodeId(d.get(FieldNames.UUID));
if (!nodeIds.containsKey(id) || isIgnored(id)) {
// this node is ignored or was already marked for deletion
continue;
}
String parent = d.get(FieldNames.PARENT);
if (parent == null || parent.isEmpty()) {
continue;
}
final NodeId parentId = new NodeId(parent);
boolean parentExists = nodeIds.containsKey(parentId);
boolean parentIndexed = parentExists && nodeIds.get(parentId);
if (parentIndexed) {
continue;
} else if (id.equals(RepositoryImpl.SYSTEM_ROOT_NODE_ID) && parentId.equals(RepositoryImpl.ROOT_NODE_ID)) {
// special case for the /jcr:system node
continue;
}
// parent is missing from index
if (parentExists) {
errors.add(new MissingAncestor(id, parentId));
} else {
try {
final ItemState itemState = stateMgr.getItemState(id);
if (parentId.equals(itemState.getParentId())) {
// orphaned node
errors.add(new UnknownParent(id, parentId));
} else {
errors.add(new WrongParent(id, parentId, itemState.getParentId()));
}
} catch (ItemStateException ignored) {
}
}
}
} finally {
reader.release();
}
}
Aggregations