use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class OaiPmhPersistenceTest method testDeleting.
@Test
public void testDeleting() throws Exception {
oaiPmhDatabase.store(mp1, REPOSITORY_ID_1);
boolean failed = false;
try {
oaiPmhDatabase.delete(mp1.getIdentifier().toString(), "abc");
} catch (NotFoundException e) {
failed = true;
}
Assert.assertTrue(failed);
oaiPmhDatabase.delete(mp1.getIdentifier().toString(), REPOSITORY_ID_1);
SearchResult search = oaiPmhDatabase.search(query().mediaPackageId(mp1).build());
Assert.assertEquals(1, search.size());
Assert.assertTrue(search.getItems().get(0).isDeleted());
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class ServiceRegistryJpaImpl method getMaxLoadOnNode.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoadOnNode(java.lang.String)
*/
@Override
public NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException, NotFoundException {
Query query = null;
EntityManager em = null;
try {
em = emf.createEntityManager();
query = em.createNamedQuery("HostRegistration.getMaxLoadByHostName");
query.setParameter("host", host);
return new NodeLoad(host, ((Number) query.getSingleResult()).floatValue());
} catch (NoResultException e) {
throw new NotFoundException(e);
} catch (Exception e) {
throw new ServiceRegistryException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class StaticFileRestService method getStaticFile.
@GET
@Path("{uuid}")
@RestQuery(name = "getStaticFile", description = "Returns a static file resource", pathParameters = { @RestParameter(description = "Static File Universal Unique Id", isRequired = true, name = "uuid", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a static file resource", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No file by the given uuid found", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "")
public Response getStaticFile(@PathParam("uuid") String uuid) throws NotFoundException {
try {
final InputStream file = staticFileService.getFile(uuid);
final String filename = staticFileService.getFileName(uuid);
final Long length = staticFileService.getContentLength(uuid);
// It is safe to pass the InputStream without closing it, JAX-RS takes care of that
return RestUtil.R.ok(file, getMimeType(filename), Option.some(length), Option.some(filename));
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.warn("Unable to retrieve file with uuid {} because: {}", uuid, ExceptionUtils.getStackTrace(e));
return Response.serverError().build();
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class StaticFileRestServiceTest method testDeleteStaticFile.
@Test
public void testDeleteStaticFile() throws FileUploadException, Exception {
// Setup static file service.
StaticFileService fileService = EasyMock.createMock(StaticFileService.class);
final String fileUuid = "12345";
EasyMock.expect(fileService.storeFile(anyObject(String.class), anyObject(InputStream.class))).andReturn(fileUuid);
fileService.deleteFile(fileUuid);
EasyMock.expectLastCall();
EasyMock.expect(fileService.getFile(fileUuid)).andThrow(new NotFoundException());
EasyMock.replay(fileService);
// Run the test
StaticFileRestService staticFileRestService = new StaticFileRestService();
staticFileRestService.activate(getComponentContext(null, 100000000L));
staticFileRestService.setSecurityService(getSecurityService());
staticFileRestService.setStaticFileService(fileService);
// Test a good store request
Response result = staticFileRestService.postStaticFile(newMockRequest());
assertEquals(Status.CREATED.getStatusCode(), result.getStatus());
String location = result.getMetadata().get("location").get(0).toString();
String uuid = location.substring(location.lastIndexOf("/") + 1);
Response response = staticFileRestService.deleteStaticFile(uuid);
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
try {
staticFileRestService.getStaticFile(uuid);
fail("NotFoundException must be passed on");
} catch (NotFoundException e) {
// expected
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SoxServiceImpl method analyze.
protected Option<Track> analyze(Job job, Track audioTrack) throws SoxException {
if (!audioTrack.hasAudio())
throw new SoxException("No audio stream available");
if (audioTrack.hasVideo())
throw new SoxException("It must not have a video stream");
try {
// Get the tracks and make sure they exist
final File audioFile;
try {
audioFile = workspace.get(audioTrack.getURI());
} catch (NotFoundException e) {
throw new SoxException("Requested audio track " + audioTrack + " is not found");
} catch (IOException e) {
throw new SoxException("Unable to access audio track " + audioTrack);
}
logger.info("Analyzing audio track {}", audioTrack.getIdentifier());
// Do the work
ArrayList<String> command = new ArrayList<String>();
command.add(binary);
command.add(audioFile.getAbsolutePath());
command.add("-n");
command.add("remix");
command.add("-");
command.add("stats");
List<String> analyzeResult = launchSoxProcess(command);
// Add audio metadata and return audio track
return some(addAudioMetadata(audioTrack, analyzeResult));
} catch (Exception e) {
logger.warn("Error analyzing {}: {}", audioTrack, e.getMessage());
if (e instanceof SoxException) {
throw (SoxException) e;
} else {
throw new SoxException(e);
}
}
}
Aggregations