use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceRemoteImpl method getSeriesProperty.
@Override
public String getSeriesProperty(String seriesID, String propertyName) throws SeriesException, NotFoundException, UnauthorizedException {
HttpGet get = new HttpGet(seriesID + "/property/" + propertyName + ".json");
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Series " + seriesID + " not found in remote series index!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
throw new UnauthorizedException("Not authorized to get series " + seriesID);
} else {
logger.debug("Successfully received series {} property {} from the remote series index", seriesID, propertyName);
StringWriter writer = new StringWriter();
IOUtils.copy(response.getEntity().getContent(), writer, "UTF-8");
return writer.toString();
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to parse series from remote series index: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to get series from remote series index");
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceRemoteImpl method getSeriesAccessControl.
@Override
public AccessControlList getSeriesAccessControl(String seriesID) throws NotFoundException, SeriesException {
HttpGet get = new HttpGet(seriesID + "/acl.xml");
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Series ACL " + seriesID + " not found on remote series index!");
} else {
AccessControlList acl = AccessControlParser.parseAcl(response.getEntity().getContent());
logger.info("Successfully get series ACL {} from the remote series index", seriesID);
return acl;
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to parse series ACL form remote series index: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to get series ACL from remote series index");
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class AbstractIncidentService method getIncidentsOfJob.
@Override
public IncidentTree getIncidentsOfJob(long jobId, boolean cascade) throws NotFoundException, IncidentServiceException {
List<Incident> incidents = getIncidentsOfJob(jobId);
List<IncidentTree> childIncidents = new ArrayList<IncidentTree>();
try {
Job job = getServiceRegistry().getJob(jobId);
if (cascade && !"START_WORKFLOW".equals(job.getOperation())) {
childIncidents = getChildIncidents(jobId);
} else if (cascade && "START_WORKFLOW".equals(job.getOperation())) {
for (WorkflowOperationInstance operation : getWorkflowService().getWorkflowById(jobId).getOperations()) {
if (operation.getState().equals(OperationState.INSTANTIATED))
continue;
IncidentTree operationResult = getIncidentsOfJob(operation.getId(), true);
if (hasIncidents(Collections.list(operationResult)))
childIncidents.add(operationResult);
}
}
return new IncidentTreeImpl(incidents, childIncidents);
} catch (NotFoundException ignore) {
// Workflow deleted
return new IncidentTreeImpl(incidents, childIncidents);
} catch (Exception e) {
logger.error("Error loading child jobs of {}: {}", jobId);
throw new IncidentServiceException(e);
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class ServiceRegistryJpaImpl method removeJobs.
@Override
public void removeJobs(List<Long> jobIds) throws NotFoundException, ServiceRegistryException {
for (long jobId : jobIds) {
if (jobId < 1)
throw new NotFoundException("Job ID must be greater than zero (0)");
}
logger.debug("Start deleting jobs with IDs '{}'", jobIds);
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
for (long jobId : jobIds) {
JpaJob job = em.find(JpaJob.class, jobId);
if (job == null) {
logger.error("Job with Id {} cannot be deleted: Not found.", jobId);
tx.rollback();
throw new NotFoundException("Job with ID '" + jobId + "' not found");
}
deleteChildJobs(em, tx, jobId);
em.remove(job);
}
tx.commit();
logger.debug("Jobs with IDs '{}' deleted", jobIds);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class ServiceRegistryJpaImpl method createJob.
/**
* Creates a job on a remote host.
*/
public Job createJob(String host, String serviceType, String operation, List<String> arguments, String payload, boolean dispatchable, Job parentJob, float jobLoad) throws ServiceRegistryException {
if (StringUtils.isBlank(host)) {
throw new IllegalArgumentException("Host can't be null");
}
if (StringUtils.isBlank(serviceType)) {
throw new IllegalArgumentException("Service type can't be null");
}
if (StringUtils.isBlank(operation)) {
throw new IllegalArgumentException("Operation can't be null");
}
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
ServiceRegistrationJpaImpl creatingService = getServiceRegistration(em, serviceType, host);
if (creatingService == null) {
throw new ServiceRegistryException("No service registration exists for type '" + serviceType + "' on host '" + host + "'");
}
if (creatingService.getHostRegistration().isMaintenanceMode()) {
logger.warn("Creating a job from {}, which is currently in maintenance mode.", creatingService.getHost());
} else if (!creatingService.getHostRegistration().isActive()) {
logger.warn("Creating a job from {}, which is currently inactive.", creatingService.getHost());
}
User currentUser = securityService.getUser();
Organization currentOrganization = securityService.getOrganization();
JpaJob jpaJob = new JpaJob(currentUser, currentOrganization, creatingService, operation, arguments, payload, dispatchable, jobLoad);
// Bind the given parent job to the new job
if (parentJob != null) {
// Get the JPA instance of the parent job
JpaJob jpaParentJob;
try {
jpaParentJob = getJpaJob(parentJob.getId());
} catch (NotFoundException e) {
logger.error("{} not found in the persistence context", parentJob);
throw new ServiceRegistryException(e);
}
jpaJob.setParentJob(jpaParentJob);
// Get the JPA instance of the root job
JpaJob jpaRootJob = jpaParentJob;
if (parentJob.getRootJobId() != null) {
try {
jpaRootJob = getJpaJob(parentJob.getRootJobId());
} catch (NotFoundException e) {
logger.error("job with id {} not found in the persistence context", parentJob.getRootJobId());
throw new ServiceRegistryException(e);
}
}
jpaJob.setRootJob(jpaRootJob);
}
// if this job is not dispatchable, it must be handled by the host that has created it
if (dispatchable) {
jpaJob.setStatus(Status.QUEUED);
} else {
jpaJob.setProcessorServiceRegistration(creatingService);
}
em.persist(jpaJob);
tx.commit();
setJobUri(jpaJob);
Job job = jpaJob.toJob();
return job;
} catch (RollbackException e) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
throw e;
} finally {
if (em != null)
em.close();
}
}
Aggregations