Search in sources :

Example 6 with SlingRepository

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);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Activate(org.osgi.service.component.annotations.Activate)

Example 7 with SlingRepository

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;
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) SlingLocatorFactory(org.apache.sling.jcr.webdav.impl.helper.SlingLocatorFactory) Session(javax.jcr.Session)

Example 8 with SlingRepository

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));
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Value(javax.jcr.Value) Credentials(javax.jcr.Credentials) Before(org.junit.Before)

Example 9 with SlingRepository

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]);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Event(javax.jcr.observation.Event) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with SlingRepository

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);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Event(javax.jcr.observation.Event) Test(org.junit.Test)

Aggregations

SlingRepository (org.apache.sling.jcr.api.SlingRepository)33 Test (org.junit.Test)18 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)14 Session (javax.jcr.Session)12 Event (javax.jcr.observation.Event)10 Scheduler (org.apache.sling.commons.scheduler.Scheduler)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)9 Credentials (javax.jcr.Credentials)4 Node (javax.jcr.Node)4 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)4 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)4 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)4 Before (org.junit.Before)4 SimpleCredentials (javax.jcr.SimpleCredentials)3 Workspace (javax.jcr.Workspace)3 ObservationManager (javax.jcr.observation.ObservationManager)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 Repository (javax.jcr.Repository)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2