use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceImpl method getTechnicalMetadata.
@Override
public TechnicalMetadata getTechnicalMetadata(String mediaPackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
notEmpty(mediaPackageId, "mediaPackageId");
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
AResult result = query.select(p.optOut().target(), p.agent().target(), p.start().target(), p.end().target(), p.presenters().target(), p.recordingStatus().target(), p.recordingLastHeard().target(), query.propertiesOf(CA_NAMESPACE), query.propertiesOf(WORKFLOW_NAMESPACE)).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId)).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace()))).run();
final Opt<ARecord> record = result.getRecords().head();
if (record.isNone())
throw new NotFoundException();
return getTechnicalMetadata(record.get(), p);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to get technical metadata of event '{}': {}", mediaPackageId, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getDublinCore.
@Override
public DublinCoreCatalog getDublinCore(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/dublincore.xml"));
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("Event catalog '" + eventId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get dublincore of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get dublincore of the event " + eventId);
} else {
DublinCoreCatalog dublinCoreCatalog = DublinCores.read(response.getEntity().getContent());
logger.info("Successfully get event dublincore {} from the remote scheduler service", eventId);
return dublinCoreCatalog;
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to parse event dublincore from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event dublincore from remote scheduler service");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method rollbackTransaction.
private void rollbackTransaction(String id) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpPost post = new HttpPost(UrlSupport.concat("transaction", id, "rollback"));
HttpResponse response = getResponse(post, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Successfully rolled back scheduler transaction '{}' to the scheduler service", id);
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to rollback scheduler transaction '{}'", id);
throw new UnauthorizedException("Unauthorized to rollback scheduler transaction");
} else if (response != null && SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Scheduler transaction '{}' not found", id);
throw new NotFoundException("Not found scheduler transaction " + id);
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to rollback scheduler transaction '" + id + "' to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to rollback scheduler transaction '" + id + "' to the scheduler service");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method commitTransaction.
private void commitTransaction(String id) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpPost post = new HttpPost(UrlSupport.concat("transaction", id, "commit"));
HttpResponse response = getResponse(post, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Successfully committed scheduler transaction '{}' to the scheduler service", id);
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to commit scheduler transaction '{}'", id);
throw new UnauthorizedException("Unauthorized to commit scheduler transaction");
} else if (response != null && SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Scheduler transaction '{}' not found", id);
throw new NotFoundException("Not found scheduler transaction " + id);
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to commit scheduler transaction '" + id + "' to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to commit scheduler transaction '" + id + "' to the scheduler service");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method updateEvent.
@Override
public void updateEvent(String eventId, Opt<Date> startDateTime, Opt<Date> endDateTime, Opt<String> captureAgentId, Opt<Set<String>> userIds, Opt<MediaPackage> mediaPackage, Opt<Map<String, String>> wfProperties, Opt<Map<String, String>> caMetadata, Opt<Opt<Boolean>> optOut, String origin) throws NotFoundException, UnauthorizedException, SchedulerTransactionLockException, SchedulerConflictException, SchedulerException {
logger.debug("Start updating event {}.", eventId);
HttpPut put = new HttpPut("/" + eventId);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
if (startDateTime.isSome())
params.add(new BasicNameValuePair("start", Long.toString(startDateTime.get().getTime())));
if (endDateTime.isSome())
params.add(new BasicNameValuePair("end", Long.toString(endDateTime.get().getTime())));
if (captureAgentId.isSome())
params.add(new BasicNameValuePair("agent", captureAgentId.get()));
if (userIds.isSome())
params.add(new BasicNameValuePair("users", StringUtils.join(userIds.get(), ",")));
if (mediaPackage.isSome())
params.add(new BasicNameValuePair("mediaPackage", MediaPackageParser.getAsXml(mediaPackage.get())));
if (wfProperties.isSome())
params.add(new BasicNameValuePair("wfproperties", toPropertyString(wfProperties.get())));
if (caMetadata.isSome())
params.add(new BasicNameValuePair("agentparameters", toPropertyString(caMetadata.get())));
if (optOut.isSome()) {
params.add(new BasicNameValuePair("updateOptOut", Boolean.toString(true)));
if (optOut.get().isSome())
params.add(new BasicNameValuePair("optOut", Boolean.toString(optOut.get().get())));
} else {
params.add(new BasicNameValuePair("updateOptOut", Boolean.toString(false)));
}
params.add(new BasicNameValuePair("origin", origin));
put.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(put, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED, SC_FORBIDDEN, SC_CONFLICT);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Event {} was not found by the scheduler service", eventId);
throw new NotFoundException("Event '" + eventId + "' not found on remote scheduler service!");
} else if (SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Event {} successfully updated with capture agent metadata.", eventId);
return;
} else if (response != null && SC_CONFLICT == response.getStatusLine().getStatusCode()) {
String errorJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(errorJson);
JSONObject error = (JSONObject) json.get("error");
String errorCode = (String) error.get("code");
if (SchedulerTransactionLockException.ERROR_CODE.equals(errorCode)) {
logger.info("Event is locked by a transaction, unable to update event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to update event " + eventId);
} else if (SchedulerConflictException.ERROR_CODE.equals(errorCode)) {
logger.info("Conflicting events found when updating event {}", eventId);
throw new SchedulerConflictException("Conflicting events found when updating event " + eventId);
} else {
throw new SchedulerException("Unexpected error code " + errorCode);
}
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to update the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to update the event " + eventId);
} else if (SC_FORBIDDEN == response.getStatusLine().getStatusCode()) {
logger.info("Forbidden to update the event {}.", eventId);
throw new SchedulerException("Event with specified ID cannot be updated");
} else {
throw new SchedulerException("Unexpected status code " + response.getStatusLine());
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to update event " + eventId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to update event " + eventId);
}
Aggregations