Search in sources :

Example 36 with UnauthorizedException

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);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 37 with UnauthorizedException

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");
}
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) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) 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 38 with UnauthorizedException

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");
}
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) 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)

Example 39 with UnauthorizedException

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");
}
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) 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)

Example 40 with UnauthorizedException

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);
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ArrayList(java.util.ArrayList) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) HttpPut(org.apache.http.client.methods.HttpPut) 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)

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