use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class JcrResourceProvider method activate.
@Activate
protected void activate(final ComponentContext context) throws RepositoryException {
SlingRepository repository = context.locateService(REPOSITORY_REFERNENCE_NAME, this.repositoryReference);
if (repository == null) {
// concurrent unregistration of SlingRepository service
// don't care, this component is going to be deactivated
// so we just stop working
logger.warn("activate: Activation failed because SlingRepository may have been unregistered concurrently");
return;
}
this.repository = repository;
this.stateFactory = new JcrProviderStateFactory(repositoryReference, repository, classLoaderManagerReference);
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class SlingWebDavServlet method getLocatorFactory.
@Override
public DavLocatorFactory getLocatorFactory() {
if (locatorFactory == null) {
// configured default workspace name
SlingRepository slingRepo = (SlingRepository) getRepository();
String workspace = slingRepo.getDefaultWorkspace();
// no configuration, try to login and acquire the default name
if (workspace == null || workspace.length() == 0) {
Session tmp = null;
try {
tmp = slingRepo.login();
workspace = tmp.getWorkspace().getName();
} catch (Throwable t) {
// TODO: log !!
// fall back name
workspace = "default";
} finally {
if (tmp != null) {
tmp.logout();
}
}
}
locatorFactory = new SlingLocatorFactory(workspace);
}
return locatorFactory;
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class JcrResourceListenerTest method setUp.
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
RepositoryUtil.startRepository();
this.adminSession = RepositoryUtil.getRepository().loginAdministrative(null);
RepositoryUtil.registerSlingNodeTypes(adminSession);
final SlingRepository repo = RepositoryUtil.getRepository();
this.config = new JcrListenerBaseConfig(getObservationReporter(), new SlingRepository() {
@Override
public Session login(Credentials credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException {
return repo.login(credentials, workspaceName);
}
@Override
public Session login(String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException {
return repo.login(workspaceName);
}
@Override
public Session login(Credentials credentials) throws LoginException, RepositoryException {
return repo.login(credentials);
}
@Override
public Session login() throws LoginException, RepositoryException {
return repo.login();
}
@Override
public boolean isStandardDescriptor(String key) {
return repo.isStandardDescriptor(key);
}
@Override
public boolean isSingleValueDescriptor(String key) {
return repo.isSingleValueDescriptor(key);
}
@Override
public Value[] getDescriptorValues(String key) {
return repo.getDescriptorValues(key);
}
@Override
public Value getDescriptorValue(String key) {
return repo.getDescriptorValue(key);
}
@Override
public String[] getDescriptorKeys() {
return repo.getDescriptorKeys();
}
@Override
public String getDescriptor(String key) {
return repo.getDescriptor(key);
}
@Override
public Session loginService(String subServiceName, String workspace) throws LoginException, RepositoryException {
return repo.loginAdministrative(workspace);
}
@Override
public Session loginAdministrative(String workspace) throws LoginException, RepositoryException {
return repo.loginAdministrative(workspace);
}
@Override
public String getDefaultWorkspace() {
// TODO Auto-generated method stub
return repo.getDefaultWorkspace();
}
});
this.listener = new JcrResourceListener(this.config, getObservationReporter().getObserverConfigurations().get(0));
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class AbstractJcrEventTriggerTest method addToListTest.
//"SLING-6054"
@Test
public void addToListTest() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
String path = "/";
String serviceUser = "service-user";
AbstractJcrEventTrigger trigger = new AbstractJcrEventTrigger(repository, scheduler, rrf, path, serviceUser) {
@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
return null;
}
};
String descendant = "/a/b/c/d/e/f/h";
String ancestor = "/a/b/c/d";
List<DistributionRequest> requests = new LinkedList<DistributionRequest>();
requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, descendant));
DistributionRequest newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor);
trigger.addToList(newRequest, requests);
assertEquals(1, requests.size());
assertEquals(3, requests.get(0).getPaths().length);
String[] paths = requests.get(0).getPaths();
assertEquals(ancestor, paths[0]);
// the missing path is added
assertEquals("/a/b/c/d/e/f/g", paths[1]);
assertEquals(descendant, paths[2]);
// invert order of requests
requests = new LinkedList<DistributionRequest>();
requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor));
newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, descendant);
trigger.addToList(newRequest, requests);
assertEquals(1, requests.size());
assertEquals(3, requests.get(0).getPaths().length);
paths = requests.get(0).getPaths();
assertEquals(ancestor, paths[0]);
// the missing path is added
assertEquals("/a/b/c/d/e/f/g", paths[1]);
assertEquals(descendant, paths[2]);
}
use of org.apache.sling.jcr.api.SlingRepository in project sling by apache.
the class JcrEventDistributionTriggerTest method testProcessEventOnMultipleIgnoredPattern.
@Test
public void testProcessEventOnMultipleIgnoredPattern() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
String path = "/home/users";
String serviceName = "serviceId";
String[] ignoredPaths = new String[] { ".*/.tokens.*", ".*/.rep:cache.*" };
JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, ignoredPaths);
Event event = mock(Event.class);
when(event.getPath()).thenReturn("/home/users/3/3U3HxUUzJJ60BdN4lEDJ/.tokens/2017-01-10T15.52.37.842+01.00");
DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
assertNull(distributionRequest);
}
Aggregations