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());
}
}
});
}
}
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);
}
}
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;
}
}
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());
}
}
});
}
}
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);
}
}
Aggregations