use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class WorkspaceImpl method deleteFromCollection.
@Override
public void deleteFromCollection(String collectionId, String fileName, boolean removeCollection) throws NotFoundException, IOException {
// local delete
final File f = workspaceFile(WorkingFileRepository.COLLECTION_PATH_PREFIX, collectionId, PathSupport.toSafeName(fileName));
FileUtils.deleteQuietly(f);
if (removeCollection) {
FileSupport.delete(f.getParentFile());
}
// delete in WFR
try {
wfr.deleteFromCollection(collectionId, fileName, removeCollection);
} catch (IllegalArgumentException e) {
throw new NotFoundException(e);
}
// wait for WFR
waitForResource(wfr.getCollectionURI(collectionId, fileName), SC_NOT_FOUND, "File %s does not disappear in WFR");
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class WorkspaceImpl method downloadIfNecessary.
/**
* Download content of <code>uri</code> to file <code>dst</code> only if necessary, i.e. either the file does not yet
* exist in the workspace or a newer version is available at <code>uri</code>.
*
* @return the file
*/
private File downloadIfNecessary(final URI src, final File dst) throws IOException, NotFoundException {
HttpGet get = createGetRequest(src, dst);
while (true) {
// run the http request and handle its response
final Either<Exception, Either<String, Option<File>>> result = trustedHttpClient.<Either<String, Option<File>>>runner(get).run(handleDownloadResponse(src, dst));
// right: there's an expected result
for (Either<String, Option<File>> a : result.right()) {
// right: either a file could be found or not
for (Option<File> ff : a.right()) {
for (File f : ff) {
return f;
}
FileUtils.deleteQuietly(dst);
// none
throw new NotFoundException();
}
// left: file will be ready later
for (String token : a.left()) {
get = createGetRequest(src, dst, tuple("token", token));
sleep(60000);
}
}
// left: an exception occurred
for (Exception e : result.left()) {
logger.warn(format("Could not copy %s to %s: %s", src.toString(), dst.getAbsolutePath(), e.getMessage()));
FileUtils.deleteQuietly(dst);
throw new NotFoundException(e);
}
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SecurityUtil method getUserOfOrganization.
/**
* Get a user of a certain organization by its ID.
*/
public static Option<User> getUserOfOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId) {
final Organization prevOrg = sec.getOrganization();
try {
final Organization org = orgDir.getOrganization(orgId);
sec.setOrganization(org);
return option(userDir.loadUser(userId));
} catch (NotFoundException e) {
return none();
} finally {
sec.setOrganization(prevOrg);
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class AbstractJobProducerEndpoint method dispatchJob.
/**
* @see org.opencastproject.job.api.JobProducer#acceptJob(org.opencastproject.job.api.Job)
*/
@POST
@Path("/dispatch")
public Response dispatchJob(@FormParam("id") long jobId, @FormParam("operation") String jobOperation) throws ServiceRegistryException {
final JobProducer service = getService();
if (service == null)
throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
// See if the service is ready to accept anything
if (!service.isReadyToAcceptJobs(jobOperation)) {
logger.debug("Service {} is not ready to accept jobs with operation {}", service, jobOperation);
return Response.status(Status.SERVICE_UNAVAILABLE).build();
}
Job job;
try {
job = getServiceRegistry().getJob(jobId);
} catch (NotFoundException e) {
logger.warn("Unable to find dispatched job {}", jobId);
return Response.status(Status.NOT_FOUND).build();
}
// See if the service has strong feelings about this particular job
try {
if (!service.isReadyToAccept(job)) {
logger.debug("Service {} temporarily refused to accept job {}", service, jobId);
return Response.status(Status.SERVICE_UNAVAILABLE).build();
}
} catch (UndispatchableJobException e) {
logger.warn("Service {} permanently refused to accept job {}", service, jobId);
return Response.status(Status.PRECONDITION_FAILED).build();
}
service.acceptJob(job);
return Response.noContent().build();
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class JobUtilTest method setUp.
@Before
public void setUp() throws Exception {
serviceRegistry = createNiceMock(ServiceRegistry.class);
JobImpl job = new JobImpl(20);
job.setPayload("a payload");
Job finishedJob1 = new JobImpl(1);
finishedJob1.setStatus(Status.FINISHED);
Job finishedJob2 = new JobImpl(2);
finishedJob2.setStatus(Status.FINISHED);
Job finishedJob3 = new JobImpl(3);
finishedJob3.setStatus(Status.FINISHED);
expect(serviceRegistry.getJob(1)).andReturn(finishedJob1).anyTimes();
expect(serviceRegistry.getJob(2)).andReturn(finishedJob2).anyTimes();
expect(serviceRegistry.getJob(3)).andReturn(finishedJob3).anyTimes();
expect(serviceRegistry.getJob(23)).andThrow(new NotFoundException()).anyTimes();
expect(serviceRegistry.getJob(20)).andReturn(job).anyTimes();
replay(serviceRegistry);
}
Aggregations