use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method search.
@Override
public List<MediaPackage> search(Opt<String> captureAgentId, Opt<Date> startsFrom, Opt<Date> startsTo, Opt<Date> endFrom, Opt<Date> endTo) throws UnauthorizedException, SchedulerException {
List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
for (String s : captureAgentId) {
queryStringParams.add(new BasicNameValuePair("agent", s));
}
for (Date d : startsFrom) {
queryStringParams.add(new BasicNameValuePair("startsfrom", Long.toString(d.getTime())));
}
for (Date d : startsTo) {
queryStringParams.add(new BasicNameValuePair("startsto", Long.toString(d.getTime())));
}
for (Date d : endFrom) {
queryStringParams.add(new BasicNameValuePair("endsfrom", Long.toString(d.getTime())));
}
for (Date d : endTo) {
queryStringParams.add(new BasicNameValuePair("endsto", Long.toString(d.getTime())));
}
HttpGet get = new HttpGet("recordings.xml?".concat(URLEncodedUtils.format(queryStringParams, UTF_8)));
HttpResponse response = getResponse(get, SC_OK, SC_UNAUTHORIZED);
try {
if (response != null) {
if (SC_OK == response.getStatusLine().getStatusCode()) {
String mediaPackageXml = EntityUtils.toString(response.getEntity(), UTF_8);
List<MediaPackage> events = MediaPackageParser.getArrayFromXml(mediaPackageXml);
logger.info("Successfully get recordings from the remote scheduler service");
return events;
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to search for events");
throw new UnauthorizedException("Unauthorized to search for events");
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get recordings from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get recordings from remote scheduler service");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method cleanupTransactions.
@Override
public void cleanupTransactions() throws UnauthorizedException, SchedulerException {
HttpPost post = new HttpPost("/transaction/cleanup");
HttpResponse response = getResponse(post, SC_OK, SC_UNAUTHORIZED);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Successfully cleaned up scheduler transactions to the scheduler service");
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to cleanup scheduler transactions");
throw new UnauthorizedException("Unauthorized to cleanup scheduler transactions");
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to cleanup scheduler transactions to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to cleanup scheduler transactions to the scheduler service");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method addEvent.
@Override
public void addEvent(Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Map<String, String> wfProperties, Map<String, String> caMetadata, Opt<Boolean> optOut, Opt<String> schedulingSource, String origin) throws UnauthorizedException, SchedulerTransactionLockException, SchedulerConflictException, SchedulerException {
HttpPost post = new HttpPost("/");
String eventId = mediaPackage.getIdentifier().compact();
logger.debug("Start adding a new event {} through remote Schedule Service", eventId);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("start", Long.toString(startDateTime.getTime())));
params.add(new BasicNameValuePair("end", Long.toString(endDateTime.getTime())));
params.add(new BasicNameValuePair("agent", captureAgentId));
params.add(new BasicNameValuePair("users", StringUtils.join(userIds, ",")));
params.add(new BasicNameValuePair("mediaPackage", MediaPackageParser.getAsXml(mediaPackage)));
params.add(new BasicNameValuePair("wfproperties", toPropertyString(wfProperties)));
params.add(new BasicNameValuePair("agentparameters", toPropertyString(caMetadata)));
if (optOut.isSome())
params.add(new BasicNameValuePair("optOut", Boolean.toString(optOut.get())));
if (schedulingSource.isSome())
params.add(new BasicNameValuePair("source", schedulingSource.get()));
params.add(new BasicNameValuePair("origin", origin));
post.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(post, SC_CREATED, SC_UNAUTHORIZED, SC_CONFLICT);
try {
if (response != null && SC_CREATED == response.getStatusLine().getStatusCode()) {
logger.info("Successfully added event {} to the scheduler service", 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 add event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to add event " + eventId);
} else if (SchedulerConflictException.ERROR_CODE.equals(errorCode)) {
logger.info("Conflicting events found when adding event {}", eventId);
throw new SchedulerConflictException("Conflicting events found when adding event " + eventId);
} else {
throw new SchedulerException("Unexpected error code " + errorCode);
}
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to create the event");
throw new UnauthorizedException("Unauthorized to create the event");
} else {
throw new SchedulerException("Unable to add event " + eventId + " to the scheduler service");
}
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to add event " + eventId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getCaptureAgentConfiguration.
@Override
public Map<String, String> getCaptureAgentConfiguration(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/agent.properties"));
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 capture agent configuration '" + eventId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get capture agent config of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get capture agent config of the event " + eventId);
} else {
Properties properties = new Properties();
properties.load(response.getEntity().getContent());
logger.info("Successfully get event capture agent configuration {} from the remote scheduler service", eventId);
return new HashMap<String, String>((Map) properties);
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to parse event capture agent configuration from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event capture agent configuration from remote scheduler service");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method isOptOut.
@Override
public boolean isOptOut(String mediapackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(UrlSupport.concat(mediapackageId, "optOut"));
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 with mediapackage id '" + mediapackageId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get opt out status of the event {}.", mediapackageId);
throw new UnauthorizedException("Unauthorized to get opt out status of the event " + mediapackageId);
} else {
String optOutString = EntityUtils.toString(response.getEntity(), UTF_8);
Boolean booleanObject = BooleanUtils.toBooleanObject(optOutString);
if (booleanObject == null)
throw new SchedulerException("Could not parse opt out status from the remote scheduler service: " + optOutString);
logger.info("Successfully get opt out status of event with mediapackage id {} from the remote scheduler service", mediapackageId);
return booleanObject.booleanValue();
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get event opt out status from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event opt out status from remote scheduler service");
}
Aggregations