use of org.apache.jackrabbit.api.JackrabbitRepository in project jackrabbit-oak by apache.
the class RepositoryTest method loginWithAttribute.
@Test
public void loginWithAttribute() throws RepositoryException {
Session session = ((JackrabbitRepository) getRepository()).login(new GuestCredentials(), null, Collections.<String, Object>singletonMap(RepositoryImpl.REFRESH_INTERVAL, 42));
String[] attributeNames = session.getAttributeNames();
assertEquals(1, attributeNames.length);
assertEquals(RepositoryImpl.REFRESH_INTERVAL, attributeNames[0]);
assertEquals(42L, session.getAttribute(RepositoryImpl.REFRESH_INTERVAL));
session.logout();
}
use of org.apache.jackrabbit.api.JackrabbitRepository in project jackrabbit-oak by apache.
the class UpgradeOldSegmentTest method upgradeFrom10.
@Test
public void upgradeFrom10() throws Exception {
File testFolder = new File(new File("target"), UpgradeOldSegmentTest.class.getSimpleName());
FileUtils.deleteDirectory(testFolder);
File oldRepo = new File(testFolder, "test-repo-1.0");
oldRepo.mkdirs();
try (InputStream in = UpgradeOldSegmentTest.class.getResourceAsStream("/test-repo-1.0.zip")) {
Util.unzip(in, oldRepo);
}
SegmentTarNodeStoreContainer newRepoContainer = new SegmentTarNodeStoreContainer();
OakUpgrade.main("segment-old:" + oldRepo.getPath(), newRepoContainer.getDescription());
Repository repo = new Jcr(newRepoContainer.open()).createRepository();
Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
Node myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
assertTrue(ntMgr.hasNodeType("test:MyType"));
NodeType nt = ntMgr.getNodeType("test:MyType");
PropertyDefinition[] pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertTrue(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
// flip mandatory flag for test:mandatory
String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string)\n" + " - test:optional (string)";
CndImporter.registerNodeTypes(new StringReader(cnd), s, true);
myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
nt = ntMgr.getNodeType("test:MyType");
pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertFalse(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
s.logout();
if (repo instanceof JackrabbitRepository) {
((JackrabbitRepository) repo).shutdown();
}
newRepoContainer.close();
newRepoContainer.clean();
deleteRecursive(testFolder);
}
use of org.apache.jackrabbit.api.JackrabbitRepository in project sling by apache.
the class OakSlingRepository method createAdministrativeSession.
@Override
protected Session createAdministrativeSession(String workspace) throws RepositoryException {
// TODO: use principal provider to retrieve admin principal
Set<? extends Principal> principals = singleton(new AdminPrincipal() {
@Override
public String getName() {
return OakSlingRepository.this.adminId;
}
});
AuthInfo authInfo = new AuthInfoImpl(this.adminId, Collections.<String, Object>emptyMap(), principals);
Subject subject = new Subject(true, principals, singleton(authInfo), Collections.<Object>emptySet());
Session adminSession;
try {
adminSession = Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>() {
@Override
public Session run() throws Exception {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("oak.refresh-interval", 0);
// TODO OAK-803: Backwards compatibility of long-lived sessions
JackrabbitRepository repo = (JackrabbitRepository) getRepository();
return repo.login(null, null, attrs);
}
}, null);
} catch (PrivilegedActionException e) {
throw new RepositoryException("failed to retrieve admin session.", e);
}
return adminSession;
}
use of org.apache.jackrabbit.api.JackrabbitRepository in project pentaho-platform by pentaho.
the class PentahoSystemReadyListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
Repository jcrRepository = PentahoSystem.get(Repository.class, "jcrRepository", null);
if (jcrRepository == null) {
Logger.error(PentahoSystemReadyListener.class.getName(), "Cannot obtain JCR repository. Exiting");
return;
}
if (!(jcrRepository instanceof JackrabbitRepository)) {
Logger.error(PentahoSystemReadyListener.class.getName(), String.format("Expected RepositoryImpl, but got: [%s]. Exiting", jcrRepository.getClass().getName()));
return;
}
((JackrabbitRepository) jcrRepository).shutdown();
}
use of org.apache.jackrabbit.api.JackrabbitRepository in project jackrabbit-oak by apache.
the class SameNamePropertyNodeTest method testNodeStoreSupport.
/**
* Tests if a nodestore fixture sets the SNNP repository descriptor to true.
*/
@Test
public void testNodeStoreSupport() throws Exception {
NodeStore nodeStore = NodeStoreFixtures.SEGMENT_TAR.createNodeStore();
JackrabbitRepository repository = (JackrabbitRepository) new Jcr(nodeStore).createRepository();
try {
assertTrue(repository.getDescriptorValue(Repository.OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED).getBoolean());
} finally {
repository.shutdown();
}
}
Aggregations