Search in sources :

Example 41 with UnauthorizedException

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");
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Example 42 with UnauthorizedException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 43 with UnauthorizedException

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ArrayList(java.util.ArrayList) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) JSONObject(org.json.simple.JSONObject) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Example 44 with UnauthorizedException

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) Properties(java.util.Properties) Map(java.util.Map) HashMap(java.util.HashMap) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 45 with UnauthorizedException

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)133 NotFoundException (org.opencastproject.util.NotFoundException)109 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)52 IOException (java.io.IOException)42 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)39 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)38 HttpResponse (org.apache.http.HttpResponse)37 SeriesException (org.opencastproject.series.api.SeriesException)36 WebApplicationException (javax.ws.rs.WebApplicationException)33 Path (javax.ws.rs.Path)29 RestQuery (org.opencastproject.util.doc.rest.RestQuery)29 ParseException (java.text.ParseException)28 MediaPackage (org.opencastproject.mediapackage.MediaPackage)27 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)26 AccessControlList (org.opencastproject.security.api.AccessControlList)22 ArrayList (java.util.ArrayList)21 User (org.opencastproject.security.api.User)21 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)21 HttpGet (org.apache.http.client.methods.HttpGet)19 Date (java.util.Date)18