Search in sources :

Example 1 with SolrIndexManager

use of org.opencastproject.search.impl.solr.SolrIndexManager in project opencast by opencast.

the class SearchServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    // workspace
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {

        @Override
        public File answer() throws Throwable {
            return new File(new URI(EasyMock.getCurrentArguments()[0].toString()));
        }
    }).anyTimes();
    EasyMock.replay(workspace);
    // User, organization and service registry
    userResponder = new Responder<User>(defaultUser);
    organizationResponder = new Responder<Organization>(defaultOrganization);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andAnswer(userResponder).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andAnswer(organizationResponder).anyTimes();
    EasyMock.replay(securityService);
    User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    // mpeg7 service
    Mpeg7CatalogService mpeg7CatalogService = new Mpeg7CatalogService();
    // Persistence storage
    searchDatabase = new SearchServiceDatabaseImpl();
    searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
    searchDatabase.activate(null);
    searchDatabase.setSecurityService(securityService);
    // search service
    service = new SearchServiceImpl();
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    StaticMetadataService mdService = newStaticMetadataService(workspace);
    SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
    DublinCoreCatalog seriesCatalog = getSeriesDublinCoreCatalog("/series-dublincore.xml");
    AccessControlList seriesAcl = new AccessControlList();
    EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(seriesCatalog).anyTimes();
    EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(seriesAcl).anyTimes();
    EasyMock.replay(seriesService);
    service.setStaticMetadataService(mdService);
    service.setWorkspace(workspace);
    service.setMpeg7CatalogService(mpeg7CatalogService);
    service.setSecurityService(securityService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    service.setServiceRegistry(serviceRegistry);
    service.setPersistence(searchDatabase);
    SolrServer solrServer = SearchServiceImpl.setupSolr(new File(solrRoot));
    service.testSetup(solrServer, new SolrRequester(solrServer, securityService), new SolrIndexManager(solrServer, workspace, Arrays.asList(mdService), seriesService, mpeg7CatalogService, securityService));
    // acl
    String anonymousRole = securityService.getOrganization().getAnonymousRole();
    acl = new AccessControlList(new AccessControlEntry(anonymousRole, Permissions.Action.READ.toString(), true));
    authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.expect(authorizationService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
    service.setAuthorizationService(authorizationService);
    EasyMock.replay(authorizationService);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) StaticMetadataService(org.opencastproject.metadata.api.StaticMetadataService) URI(java.net.URI) SolrServer(org.apache.solr.client.solrj.SolrServer) SecurityService(org.opencastproject.security.api.SecurityService) SolrRequester(org.opencastproject.search.impl.solr.SolrRequester) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) SolrIndexManager(org.opencastproject.search.impl.solr.SolrIndexManager) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Mpeg7CatalogService(org.opencastproject.metadata.mpeg7.Mpeg7CatalogService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) SeriesService(org.opencastproject.series.api.SeriesService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchServiceDatabaseImpl(org.opencastproject.search.impl.persistence.SearchServiceDatabaseImpl) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 2 with SolrIndexManager

use of org.opencastproject.search.impl.solr.SolrIndexManager in project opencast by opencast.

the class SearchServiceImpl method activate.

/**
 * Service activator, called via declarative services configuration. If the solr server url is configured, we try to
 * connect to it. If not, the solr data directory with an embedded Solr server is used.
 *
 * @param cc
 *          the component context
 */
@Override
public void activate(final ComponentContext cc) throws IllegalStateException {
    super.activate(cc);
    final String solrServerUrlConfig = StringUtils.trimToNull(cc.getBundleContext().getProperty(CONFIG_SOLR_URL));
    logger.info("Setting up solr server");
    solrServer = new Object() {

        SolrServer create() {
            if (solrServerUrlConfig != null) {
                /* Use external SOLR server */
                try {
                    logger.info("Setting up solr server at {}", solrServerUrlConfig);
                    URL solrServerUrl = new URL(solrServerUrlConfig);
                    return setupSolr(solrServerUrl);
                } catch (MalformedURLException e) {
                    throw connectError(solrServerUrlConfig, e);
                }
            } else {
                /* Set-up embedded SOLR */
                String solrRoot = SolrServerFactory.getEmbeddedDir(cc, CONFIG_SOLR_ROOT, "search");
                try {
                    logger.debug("Setting up solr server at {}", solrRoot);
                    return setupSolr(new File(solrRoot));
                } catch (IOException e) {
                    throw connectError(solrServerUrlConfig, e);
                } catch (SolrServerException e) {
                    throw connectError(solrServerUrlConfig, e);
                }
            }
        }

        IllegalStateException connectError(String target, Exception e) {
            logger.error("Unable to connect to solr at {}: {}", target, e.getMessage());
            return new IllegalStateException("Unable to connect to solr at " + target, e);
        }
    }.create();
    // CHECKSTYLE:ON
    solrRequester = new SolrRequester(solrServer, securityService, serializer);
    indexManager = new SolrIndexManager(solrServer, workspace, mdServices, seriesService, mpeg7CatalogService, securityService);
    String systemUserName = cc.getBundleContext().getProperty(SecurityUtil.PROPERTY_KEY_SYS_USER);
    populateIndex(systemUserName);
}
Also used : MalformedURLException(java.net.MalformedURLException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrRequester(org.opencastproject.search.impl.solr.SolrRequester) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) ServiceException(org.osgi.framework.ServiceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) SearchException(org.opencastproject.search.api.SearchException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SolrIndexManager(org.opencastproject.search.impl.solr.SolrIndexManager)

Aggregations

File (java.io.File)2 SolrIndexManager (org.opencastproject.search.impl.solr.SolrIndexManager)2 SolrRequester (org.opencastproject.search.impl.solr.SolrRequester)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 SolrServer (org.apache.solr.client.solrj.SolrServer)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 IAnswer (org.easymock.IAnswer)1 Before (org.junit.Before)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 StaticMetadataService (org.opencastproject.metadata.api.StaticMetadataService)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1 Mpeg7CatalogService (org.opencastproject.metadata.mpeg7.Mpeg7CatalogService)1 SearchException (org.opencastproject.search.api.SearchException)1 SearchServiceDatabaseException (org.opencastproject.search.impl.persistence.SearchServiceDatabaseException)1 SearchServiceDatabaseImpl (org.opencastproject.search.impl.persistence.SearchServiceDatabaseImpl)1 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)1