use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method deleteSeriesProperty.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#deleteSeriesProperty(java.lang.String)
*/
@Override
public void deleteSeriesProperty(String seriesId, String propertyName) throws SeriesServiceDatabaseException, NotFoundException {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("Series with ID " + seriesId + " does not exist");
}
Map<String, String> properties = entity.getProperties();
String propertyValue = properties.get(propertyName);
if (propertyValue == null) {
throw new NotFoundException("Series with ID " + seriesId + " doesn't have a property with name '" + propertyName + "'");
}
if (!userHasWriteAccess(entity)) {
throw new UnauthorizedException(securityService.getUser() + " is not authorized to delete series " + seriesId + " property " + propertyName);
}
properties.remove(propertyName);
entity.setProperties(properties);
em.merge(entity);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete series: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
use of org.opencastproject.util.NotFoundException 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.util.NotFoundException 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.util.NotFoundException in project opencast by opencast.
the class SeriesServiceRemoteImpl method isOptOut.
@Override
public boolean isOptOut(String seriesId) throws NotFoundException, SeriesException {
HttpGet get = new HttpGet(seriesId + "/optOut");
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Series with id '" + seriesId + "' not found on remote series service!");
} else {
String optOutString = EntityUtils.toString(response.getEntity(), "UTF-8");
Boolean booleanObject = BooleanUtils.toBooleanObject(optOutString);
if (booleanObject == null)
throw new SeriesException("Could not parse opt out status from the remote series service: " + optOutString);
logger.info("Successfully get opt out status of series with id {} from the remote series service", seriesId);
return booleanObject.booleanValue();
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to get the series opt out status from remote series service: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to get series opt out status from remote series service");
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceRemoteImpl method updateOptOutStatus.
@Override
public void updateOptOutStatus(String seriesId, boolean optOut) throws NotFoundException, SeriesException {
HttpPost post = new HttpPost("/optOutSeries/" + optOut);
HttpResponse response = null;
try {
JSONArray seriesIds = new JSONArray();
seriesIds.put(seriesId);
post.setEntity(new StringEntity(seriesIds.toString()));
response = getResponse(post, SC_OK);
BulkOperationResult bulkOperationResult = new BulkOperationResult();
bulkOperationResult.fromJson(response.getEntity().getContent());
if (bulkOperationResult.getNotFound().size() > 0) {
throw new NotFoundException("Unable to find series with id " + seriesId);
} else if (bulkOperationResult.getServerError().size() > 0) {
throw new SeriesException("Unable to update series " + seriesId + " opt out status using the remote series services.");
}
} catch (Exception e) {
throw new SeriesException("Unable to assemble a remote series request for updating series " + seriesId + " with optOut status of " + optOut + " because:" + ExceptionUtils.getStackTrace(e));
} finally {
if (response != null) {
closeConnection(response);
}
}
throw new SeriesException("Unable to update series " + seriesId + " using the remote series services");
}
Aggregations