Search in sources :

Example 51 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceDatabaseImpl method deleteSeriesProperty.

/*
   * (non-Javadoc)
   *
   * @see org.opencastproject.series.impl.SeriesServiceDatabase#deleteSeriesProperty(java.lang.String)
   */
@Override
public void deleteSeriesProperty(String seriesId, String propertyName) throws SeriesServiceDatabaseException, NotFoundException {
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        SeriesEntity entity = getSeriesEntity(seriesId, em);
        if (entity == null) {
            throw new NotFoundException("Series with ID " + seriesId + " does not exist");
        }
        Map<String, String> properties = entity.getProperties();
        String propertyValue = properties.get(propertyName);
        if (propertyValue == null) {
            throw new NotFoundException("Series with ID " + seriesId + " doesn't have a property with name '" + propertyName + "'");
        }
        if (!userHasWriteAccess(entity)) {
            throw new UnauthorizedException(securityService.getUser() + " is not authorized to delete series " + seriesId + " property " + propertyName);
        }
        properties.remove(propertyName);
        entity.setProperties(properties);
        em.merge(entity);
        tx.commit();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not delete series: {}", e.getMessage());
        if (tx.isActive()) {
            tx.rollback();
        }
        throw new SeriesServiceDatabaseException(e);
    } finally {
        em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Example 52 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceSolrIndex method updateSecurityPolicy.

@Override
public void updateSecurityPolicy(String seriesId, AccessControlList accessControl) throws NotFoundException, SeriesServiceDatabaseException {
    if (accessControl == null) {
        logger.warn("Access control parameter is null: skipping update for series '{}'", seriesId);
        return;
    }
    SolrDocument seriesDoc = getSolrDocumentByID(seriesId);
    if (seriesDoc == null) {
        logger.debug("No series with ID " + seriesId + " found.");
        throw new NotFoundException("Series with ID " + seriesId + " was not found.");
    }
    String serializedAC;
    try {
        serializedAC = AccessControlParser.toXml(accessControl);
    } catch (Exception e) {
        logger.error("Could not parse access control parameter: {}", e.getMessage());
        throw new SeriesServiceDatabaseException(e);
    }
    final SolrInputDocument inputDoc = ClientUtils.toSolrInputDocument(seriesDoc);
    inputDoc.setField(SolrFields.ACCESS_CONTROL_KEY, serializedAC);
    inputDoc.removeField(SolrFields.ACCESS_CONTROL_CONTRIBUTE);
    inputDoc.removeField(SolrFields.ACCESS_CONTROL_EDIT);
    inputDoc.removeField(SolrFields.ACCESS_CONTROL_READ);
    for (AccessControlEntry ace : accessControl.getEntries()) {
        if (Permissions.Action.CONTRIBUTE.toString().equals(ace.getAction()) && ace.isAllow()) {
            inputDoc.addField(SolrFields.ACCESS_CONTROL_CONTRIBUTE, ace.getRole());
        } else if (Permissions.Action.WRITE.toString().equals(ace.getAction()) && ace.isAllow()) {
            inputDoc.addField(SolrFields.ACCESS_CONTROL_EDIT, ace.getRole());
        } else if (Permissions.Action.READ.toString().equals(ace.getAction()) && ace.isAllow()) {
            inputDoc.addField(SolrFields.ACCESS_CONTROL_READ, ace.getRole());
        }
    }
    if (synchronousIndexing) {
        try {
            synchronized (solrServer) {
                solrServer.add(inputDoc);
                solrServer.commit();
            }
        } catch (Exception e) {
            throw new SeriesServiceDatabaseException("Unable to index ACL", e);
        }
    } else {
        indexingExecutor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    synchronized (solrServer) {
                        solrServer.add(inputDoc);
                        solrServer.commit();
                    }
                } catch (Exception e) {
                    logger.warn("Unable to index ACL for series {}: {}", inputDoc.getFieldValue(SolrFields.COMPOSITE_ID_KEY), e.getMessage());
                }
            }
        });
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 53 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceSolrIndex method getDublinCore.

/*
   * (non-Javadoc)
   *
   * @see org.opencastproject.series.impl.SeriesServiceIndex#get(java.lang.String)
   */
@Override
public DublinCoreCatalog getDublinCore(String seriesId) throws SeriesServiceDatabaseException, NotFoundException {
    SolrDocument result = getSolrDocumentByID(seriesId);
    if (result == null) {
        logger.debug("No series exists with ID {}", seriesId);
        throw new NotFoundException("Series with ID " + seriesId + " does not exist");
    } else {
        String dcXML = (String) result.get(SolrFields.XML_KEY);
        DublinCoreCatalog dc;
        try {
            dc = parseDublinCore(dcXML);
        } catch (IOException e) {
            logger.error("Could not parse Dublin core:", e);
            throw new SeriesServiceDatabaseException(e);
        }
        return dc;
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 54 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceRemoteImpl method isOptOut.

@Override
public boolean isOptOut(String seriesId) throws NotFoundException, SeriesException {
    HttpGet get = new HttpGet(seriesId + "/optOut");
    HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Series with id '" + seriesId + "' not found on remote series service!");
            } else {
                String optOutString = EntityUtils.toString(response.getEntity(), "UTF-8");
                Boolean booleanObject = BooleanUtils.toBooleanObject(optOutString);
                if (booleanObject == null)
                    throw new SeriesException("Could not parse opt out status from the remote series service: " + optOutString);
                logger.info("Successfully get opt out status of series with id {} from the remote series service", seriesId);
                return booleanObject.booleanValue();
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to get the series opt out status from remote series service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to get series opt out status from remote series service");
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 55 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class SeriesServiceRemoteImpl method updateOptOutStatus.

@Override
public void updateOptOutStatus(String seriesId, boolean optOut) throws NotFoundException, SeriesException {
    HttpPost post = new HttpPost("/optOutSeries/" + optOut);
    HttpResponse response = null;
    try {
        JSONArray seriesIds = new JSONArray();
        seriesIds.put(seriesId);
        post.setEntity(new StringEntity(seriesIds.toString()));
        response = getResponse(post, SC_OK);
        BulkOperationResult bulkOperationResult = new BulkOperationResult();
        bulkOperationResult.fromJson(response.getEntity().getContent());
        if (bulkOperationResult.getNotFound().size() > 0) {
            throw new NotFoundException("Unable to find series with id " + seriesId);
        } else if (bulkOperationResult.getServerError().size() > 0) {
            throw new SeriesException("Unable to update series " + seriesId + " opt out status using the remote series services.");
        }
    } catch (Exception e) {
        throw new SeriesException("Unable to assemble a remote series request for updating series " + seriesId + " with optOut status of " + optOut + " because:" + ExceptionUtils.getStackTrace(e));
    } finally {
        if (response != null) {
            closeConnection(response);
        }
    }
    throw new SeriesException("Unable to update series " + seriesId + " using the remote series services");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) JSONArray(org.codehaus.jettison.json.JSONArray) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) BulkOperationResult(org.opencastproject.rest.BulkOperationResult) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

NotFoundException (org.opencastproject.util.NotFoundException)382 IOException (java.io.IOException)137 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)130 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)79 MediaPackage (org.opencastproject.mediapackage.MediaPackage)69 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)67 EntityManager (javax.persistence.EntityManager)55 SeriesException (org.opencastproject.series.api.SeriesException)53 Path (javax.ws.rs.Path)52 WebApplicationException (javax.ws.rs.WebApplicationException)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)51 ConfigurationException (org.osgi.service.cm.ConfigurationException)51 URI (java.net.URI)50 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)50 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)49 Date (java.util.Date)48 Test (org.junit.Test)47 File (java.io.File)46 HttpResponse (org.apache.http.HttpResponse)46 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)46