Created
June 27, 2014 15:21
-
-
Save stillalex/aafe80228853ad948459 to your computer and use it in GitHub Desktop.
uuid generation for a new node of type file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licensed to the Apache Software Foundation (ASF) under one or more | |
* contributor license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright ownership. | |
* The ASF licenses this file to You under the Apache License, Version 2.0 | |
* (the "License"); you may not use this file except in compliance with | |
* the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package org.apache.jackrabbit.oak; | |
import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT; | |
import static org.apache.jackrabbit.JcrConstants.JCR_DATA; | |
import static org.apache.jackrabbit.JcrConstants.JCR_LASTMODIFIED; | |
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; | |
import static org.apache.jackrabbit.JcrConstants.NT_FILE; | |
import static org.apache.jackrabbit.JcrConstants.NT_RESOURCE; | |
import static org.apache.jackrabbit.oak.api.Type.NAME; | |
import static org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState.binaryProperty; | |
import java.util.Calendar; | |
import org.apache.jackrabbit.oak.api.ContentRepository; | |
import org.apache.jackrabbit.oak.api.ContentSession; | |
import org.apache.jackrabbit.oak.api.Root; | |
import org.apache.jackrabbit.oak.api.Tree; | |
import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider; | |
import org.apache.jackrabbit.oak.plugins.commit.JcrConflictHandler; | |
import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider; | |
import org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider; | |
import org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexProvider; | |
import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider; | |
import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider; | |
import org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider; | |
import org.apache.jackrabbit.oak.plugins.index.reference.ReferenceIndexProvider; | |
import org.apache.jackrabbit.oak.plugins.itemsave.ItemSaveValidatorProvider; | |
import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider; | |
import org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider; | |
import org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider; | |
import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent; | |
import org.apache.jackrabbit.oak.plugins.version.VersionEditorProvider; | |
import org.apache.jackrabbit.oak.spi.commit.EditorHook; | |
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider; | |
import org.junit.Test; | |
public class OakUuidTest { | |
@Test | |
public void testAddFile() throws Exception { | |
// based on JcrUtils#putFile | |
ContentRepository repo = new Oak().with(new InitialContent()) | |
.with(JcrConflictHandler.JCR_CONFLICT_HANDLER) | |
.with(new EditorHook(new VersionEditorProvider())) | |
.with(new OpenSecurityProvider()) | |
.with(new ItemSaveValidatorProvider()) | |
.with(new NameValidatorProvider()) | |
.with(new NamespaceEditorProvider()) | |
.with(new TypeEditorProvider()) | |
.with(new ConflictValidatorProvider()) | |
.with(new ReferenceEditorProvider()) | |
.with(new ReferenceIndexProvider()) | |
.with(new PropertyIndexEditorProvider()) | |
.with(new PropertyIndexProvider()) | |
.with(new OrderedPropertyIndexProvider()) | |
.with(new NodeTypeIndexProvider()) | |
.with(new OrderedPropertyIndexEditorProvider()) | |
.createContentRepository(); | |
String wspName = null; | |
ContentSession cs = null; | |
try { | |
cs = repo.login(null, wspName); | |
Root root = cs.getLatestRoot(); | |
Tree file = root.getTree("/").addChild("file"); | |
file.setProperty(JCR_PRIMARYTYPE, NT_FILE, NAME); | |
Tree content = file.addChild(JCR_CONTENT); | |
content.setProperty(JCR_PRIMARYTYPE, NT_RESOURCE, NAME); | |
content.setProperty(JCR_LASTMODIFIED, Calendar.getInstance()); | |
content.setProperty(binaryProperty(JCR_DATA, "test".getBytes())); | |
root.commit(); | |
} finally { | |
if (cs != null) { | |
cs.close(); | |
} | |
} | |
} | |
} |
Author
stillalex
commented
Jun 27, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment