Search in sources :

Example 6 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceSolrIndex method updateSecurityPolicy.

@Override
public void updateSecurityPolicy(String seriesId, AccessControlList accessControl) throws NotFoundException, SeriesServiceDatabaseException {
    if (accessControl == null) {
        logger.warn("Access control parameter is null: skipping update for series '{}'", seriesId);
        return;
    }
    SolrDocument seriesDoc = getSolrDocumentByID(seriesId);
    if (seriesDoc == null) {
        logger.debug("No series with ID " + seriesId + " found.");
        throw new NotFoundException("Series with ID " + seriesId + " was not found.");
    }
    String serializedAC;
    try {
        serializedAC = AccessControlParser.toXml(accessControl);
    } catch (Exception e) {
        logger.error("Could not parse access control parameter: {}", e.getMessage());
        throw new SeriesServiceDatabaseException(e);
    }
    final SolrInputDocument inputDoc = ClientUtils.toSolrInputDocument(seriesDoc);
    inputDoc.setField(SolrFields.ACCESS_CONTROL_KEY, serializedAC);
    inputDoc.removeField(SolrFields.ACCESS_CONTROL_CONTRIBUTE);
    inputDoc.removeField(SolrFields.ACCESS_CONTROL_EDIT);
    inputDoc.removeField(SolrFields.ACCESS_CONTROL_READ);
    for (AccessControlEntry ace : accessControl.getEntries()) {
        if (Permissions.Action.CONTRIBUTE.toString().equals(ace.getAction()) && ace.isAllow()) {
            inputDoc.addField(SolrFields.ACCESS_CONTROL_CONTRIBUTE, ace.getRole());
        } else if (Permissions.Action.WRITE.toString().equals(ace.getAction()) && ace.isAllow()) {
            inputDoc.addField(SolrFields.ACCESS_CONTROL_EDIT, ace.getRole());
        } else if (Permissions.Action.READ.toString().equals(ace.getAction()) && ace.isAllow()) {
            inputDoc.addField(SolrFields.ACCESS_CONTROL_READ, ace.getRole());
        }
    }
    if (synchronousIndexing) {
        try {
            synchronized (solrServer) {
                solrServer.add(inputDoc);
                solrServer.commit();
            }
        } catch (Exception e) {
            throw new SeriesServiceDatabaseException("Unable to index ACL", e);
        }
    } else {
        indexingExecutor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    synchronized (solrServer) {
                        solrServer.add(inputDoc);
                        solrServer.commit();
                    }
                } catch (Exception e) {
                    logger.warn("Unable to index ACL for series {}: {}", inputDoc.getFieldValue(SolrFields.COMPOSITE_ID_KEY), e.getMessage());
                }
            }
        });
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 7 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceSolrIndex method getSolrDocumentByID.

/**
 * Returns SolrDocument corresponding to given ID or null if such document does not exist.
 *
 * @param id
 *          SolrDocument ID
 * @return corresponding document
 * @throws SeriesServiceDatabaseException
 *           if exception occurred
 */
protected SolrDocument getSolrDocumentByID(String id) throws SeriesServiceDatabaseException {
    String orgId = securityService.getOrganization().getId();
    StringBuilder solrQueryString = new StringBuilder(SolrFields.COMPOSITE_ID_KEY).append(":").append(ClientUtils.escapeQueryChars(getCompositeKey(id, orgId)));
    SolrQuery q = new SolrQuery(solrQueryString.toString());
    QueryResponse response;
    try {
        response = solrServer.query(q);
        if (response.getResults().isEmpty()) {
            return null;
        } else {
            return response.getResults().get(0);
        }
    } catch (SolrServerException e) {
        logger.error("Could not perform series retrieval:", e);
        throw new SeriesServiceDatabaseException(e);
    }
}
Also used : SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 8 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceSolrIndex method getDublinCore.

/*
   * (non-Javadoc)
   *
   * @see org.opencastproject.series.impl.SeriesServiceIndex#get(java.lang.String)
   */
@Override
public DublinCoreCatalog getDublinCore(String seriesId) throws SeriesServiceDatabaseException, NotFoundException {
    SolrDocument result = getSolrDocumentByID(seriesId);
    if (result == null) {
        logger.debug("No series exists with ID {}", seriesId);
        throw new NotFoundException("Series with ID " + seriesId + " does not exist");
    } else {
        String dcXML = (String) result.get(SolrFields.XML_KEY);
        DublinCoreCatalog dc;
        try {
            dc = parseDublinCore(dcXML);
        } catch (IOException e) {
            logger.error("Could not parse Dublin core:", e);
            throw new SeriesServiceDatabaseException(e);
        }
        return dc;
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 9 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceSolrIndex method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final String id) throws SeriesServiceDatabaseException {
    if (synchronousIndexing) {
        try {
            synchronized (solrServer) {
                solrServer.deleteById(getCompositeKey(id, securityService.getOrganization().getId()));
                solrServer.commit();
            }
        } catch (Exception e) {
            throw new SeriesServiceDatabaseException(e);
        }
    } else {
        indexingExecutor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    synchronized (solrServer) {
                        solrServer.deleteById(id);
                        solrServer.commit();
                    }
                } catch (Exception e) {
                    logger.warn("Could not delete from index series {}: {}", id, e.getMessage());
                }
            }
        });
    }
}
Also used : SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 10 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceSolrIndex method search.

/**
 * {@inheritDoc}
 */
@Override
public DublinCoreCatalogList search(SeriesQuery query) throws SeriesServiceDatabaseException {
    // default to 20 items if not specified
    int count = query.getCount() > 0 ? query.getCount() : 20;
    // default to page zero
    int startPage = query.getStartPage() > 0 ? query.getStartPage() : 0;
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setRows(count);
    solrQuery.setStart(startPage * count);
    String solrQueryString = null;
    solrQueryString = buildSolrQueryString(query, query.isEdit());
    solrQuery.setQuery(solrQueryString);
    if (query.getSort() != null) {
        SolrQuery.ORDER order = query.isSortAscending() ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc;
        solrQuery.addSortField(getSortField(query.getSort()) + "_sort", order);
    }
    if (!SeriesQuery.Sort.CREATED.equals(query.getSort())) {
        solrQuery.addSortField(getSortField(SeriesQuery.Sort.CREATED) + "_sort", SolrQuery.ORDER.desc);
    }
    List<DublinCoreCatalog> result;
    try {
        QueryResponse response = solrServer.query(solrQuery);
        SolrDocumentList items = response.getResults();
        result = new LinkedList<DublinCoreCatalog>();
        // Iterate through the results
        for (SolrDocument doc : items) {
            DublinCoreCatalog item = parseDublinCore((String) doc.get(SolrFields.XML_KEY));
            result.add(item);
        }
        return new DublinCoreCatalogList(result, response.getResults().getNumFound());
    } catch (Exception e) {
        logger.error("Could not retrieve results: {}", e.getMessage());
        throw new SeriesServiceDatabaseException(e);
    }
}
Also used : DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Aggregations

SeriesServiceDatabaseException (org.opencastproject.series.impl.SeriesServiceDatabaseException)24 IOException (java.io.IOException)23 NotFoundException (org.opencastproject.util.NotFoundException)23 EntityManager (javax.persistence.EntityManager)15 NoResultException (javax.persistence.NoResultException)15 AccessControlParsingException (org.opencastproject.security.api.AccessControlParsingException)15 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)15 EntityTransaction (javax.persistence.EntityTransaction)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 MalformedURLException (java.net.MalformedURLException)7 SeriesException (org.opencastproject.series.api.SeriesException)7 SolrDocument (org.apache.solr.common.SolrDocument)6 AccessControlList (org.opencastproject.security.api.AccessControlList)5 Organization (org.opencastproject.security.api.Organization)4 User (org.opencastproject.security.api.User)4 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 Query (javax.persistence.Query)2