use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SearchServiceDatabaseImpl method getOrganizationId.
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.impl.persistence.SearchServiceDatabase#getOrganizationId(String)
*/
@Override
public String getOrganizationId(String mediaPackageId) throws NotFoundException, SearchServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
SearchEntity searchEntity = getSearchEntity(mediaPackageId, em);
if (searchEntity == null)
throw new NotFoundException("No media package with id=" + mediaPackageId + " exists");
// Ensure this user is allowed to read this media package
String accessControlXml = searchEntity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, READ.toString()))
throw new UnauthorizedException(currentUser + " is not authorized to read media package " + mediaPackageId);
}
return searchEntity.getOrganization();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not get deletion date {}: {}", mediaPackageId, e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SearchServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceImplTest method testSeriesManagement.
@Test
public void testSeriesManagement() throws Exception {
testCatalog.set(DublinCore.PROPERTY_TITLE, "Some title");
seriesService.updateSeries(testCatalog);
DublinCoreCatalog retrivedSeries = seriesService.getSeries(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
Assert.assertEquals("Some title", retrivedSeries.getFirst(DublinCore.PROPERTY_TITLE));
testCatalog.set(DublinCore.PROPERTY_TITLE, "Some other title");
seriesService.updateSeries(testCatalog);
retrivedSeries = seriesService.getSeries(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
Assert.assertEquals("Some other title", retrivedSeries.getFirst(DublinCore.PROPERTY_TITLE));
seriesService.deleteSeries(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
try {
seriesService.getSeries(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
Assert.fail("Series should not be available after removal.");
} catch (NotFoundException e) {
// expected
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceImplTest method testACLManagement.
@Test
public void testACLManagement() throws Exception {
// sample access control list
AccessControlList accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("admin", "delete", true));
try {
seriesService.updateAccessControl("failid", accessControlList);
Assert.fail("Should fail when adding ACL to nonexistent series,");
} catch (NotFoundException e) {
// expected
}
seriesService.updateSeries(testCatalog);
seriesService.updateAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER), accessControlList);
AccessControlList retrievedACL = seriesService.getSeriesAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
Assert.assertNotNull(retrievedACL);
acl = retrievedACL.getEntries();
Assert.assertEquals(acl.size(), 1);
Assert.assertEquals("admin", acl.get(0).getRole());
acl = accessControlList.getEntries();
acl.clear();
acl.add(new AccessControlEntry("student", Permissions.Action.READ.toString(), true));
seriesService.updateAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER), accessControlList);
retrievedACL = seriesService.getSeriesAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
Assert.assertNotNull(retrievedACL);
acl = retrievedACL.getEntries();
Assert.assertEquals(acl.size(), 1);
Assert.assertEquals("student", acl.get(0).getRole());
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceSolrTest method testAccessControlManagment.
@Test
public void testAccessControlManagment() throws Exception {
// sample access control list
AccessControlList accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("admin", "delete", true));
index.updateIndex(testCatalog);
String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
index.updateSecurityPolicy(seriesID, accessControlList);
AccessControlList retrievedACL = index.getAccessControl(seriesID);
Assert.assertNotNull(retrievedACL);
acl = retrievedACL.getEntries();
Assert.assertEquals(acl.size(), 1);
Assert.assertEquals(acl.get(0).getRole(), "admin");
try {
index.updateSecurityPolicy("failid", accessControlList);
Assert.fail("Should fail when indexing ACL to nonexistent series");
} catch (NotFoundException e) {
// expected
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class IncidentServiceEndpoint method getIncidentsOfJobAsList.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("job/incidents.{type:xml|json}")
@RestQuery(name = "incidentsofjobaslist", description = "Returns the job incidents with the given identifiers.", returnDescription = "Returns the job incidents.", pathParameters = { @RestParameter(name = "type", isRequired = true, description = "The media type of the response [xml|json]", defaultValue = "xml", type = Type.STRING) }, restParameters = { @RestParameter(name = "id", isRequired = true, description = "The job identifiers.", type = Type.INTEGER), @RestParameter(name = "format", isRequired = false, description = "The response format [full|digest|sys]. Defaults to sys", defaultValue = "sys", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The job incidents.") })
public Response getIncidentsOfJobAsList(@Context HttpServletRequest request, @QueryParam("id") final List<Long> jobIds, @QueryParam("format") @DefaultValue(FMT_DEFAULT) final String format, @PathParam("type") final String type) {
try {
final List<Incident> incidents = svc.getIncidentsOfJob(jobIds);
final MediaType mt = getResponseType(type);
if (eq(FMT_SYS, format)) {
return ok(mt, new JaxbIncidentList(incidents));
} else if (eq(FMT_DIGEST, format)) {
return ok(mt, new JaxbIncidentDigestList(svc, request.getLocale(), incidents));
} else if (eq(FMT_FULL, format)) {
return ok(mt, new JaxbIncidentFullList(svc, request.getLocale(), incidents));
} else {
return unknownFormat();
}
} catch (NotFoundException e) {
// should not happen
logger.error("Unable to get job incident for id {}! Consistency issue!");
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
} catch (IncidentServiceException e) {
logger.warn("Unable to get job incident for id {}: {}", jobIds, e.getMessage());
throw new WebApplicationException(INTERNAL_SERVER_ERROR);
}
}
Aggregations