Search in sources :

Example 91 with NotFoundException

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());
}
Also used : NotFoundException(org.opencastproject.util.NotFoundException) SearchResult(org.opencastproject.oaipmh.persistence.SearchResult) Test(org.junit.Test)

Example 92 with NotFoundException

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) URISyntaxException(java.net.URISyntaxException) NoResultException(javax.persistence.NoResultException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) PersistenceException(javax.persistence.PersistenceException) RollbackException(javax.persistence.RollbackException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NodeLoad(org.opencastproject.serviceregistry.api.SystemLoad.NodeLoad)

Example 93 with NotFoundException

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();
    }
}
Also used : ProgressInputStream(org.opencastproject.util.ProgressInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) ConfigurationException(org.osgi.service.cm.ConfigurationException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 94 with NotFoundException

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
    }
}
Also used : Response(javax.ws.rs.core.Response) StaticFileService(org.opencastproject.staticfiles.api.StaticFileService) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Example 95 with NotFoundException

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);
        }
    }
}
Also used : SoxException(org.opencastproject.sox.api.SoxException) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) File(java.io.File) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) SoxException(org.opencastproject.sox.api.SoxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException)

Aggregations

NotFoundException (org.opencastproject.util.NotFoundException)382 IOException (java.io.IOException)137 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)130 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)79 MediaPackage (org.opencastproject.mediapackage.MediaPackage)69 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)67 EntityManager (javax.persistence.EntityManager)55 SeriesException (org.opencastproject.series.api.SeriesException)53 Path (javax.ws.rs.Path)52 WebApplicationException (javax.ws.rs.WebApplicationException)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)51 ConfigurationException (org.osgi.service.cm.ConfigurationException)51 URI (java.net.URI)50 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)50 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)49 Date (java.util.Date)48 Test (org.junit.Test)47 File (java.io.File)46 HttpResponse (org.apache.http.HttpResponse)46 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)46