use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class IndexServiceImpl method updateMediaPackageMetadata.
private void updateMediaPackageMetadata(MediaPackage mp, MetadataList metadataList) {
String oldSeriesId = mp.getSeries();
for (EventCatalogUIAdapter catalogUIAdapter : getEventCatalogUIAdapters()) {
Opt<MetadataCollection> metadata = metadataList.getMetadataByAdapter(catalogUIAdapter);
if (metadata.isSome() && metadata.get().isUpdated()) {
catalogUIAdapter.storeFields(mp, metadata.get());
}
}
// update series catalogs
if (!StringUtils.equals(oldSeriesId, mp.getSeries())) {
List<String> seriesDcTags = new ArrayList<>();
List<String> seriesAclTags = new ArrayList<>();
Map<String, List<String>> seriesExtDcTags = new HashMap<>();
if (StringUtils.isNotBlank(oldSeriesId)) {
// remove series dublincore from the media package
for (MediaPackageElement mpe : mp.getElementsByFlavor(MediaPackageElements.SERIES)) {
mp.remove(mpe);
for (String tag : mpe.getTags()) {
seriesDcTags.add(tag);
}
}
// remove series ACL from the media package
for (MediaPackageElement mpe : mp.getElementsByFlavor(MediaPackageElements.XACML_POLICY_SERIES)) {
mp.remove(mpe);
for (String tag : mpe.getTags()) {
seriesAclTags.add(tag);
}
}
// remove series extended metadata from the media package
try {
Opt<Map<String, byte[]>> oldSeriesElementsOpt = seriesService.getSeriesElements(oldSeriesId);
for (Map<String, byte[]> oldSeriesElements : oldSeriesElementsOpt) {
for (String oldSeriesElementType : oldSeriesElements.keySet()) {
for (MediaPackageElement mpe : mp.getElementsByFlavor(MediaPackageElementFlavor.flavor(oldSeriesElementType, "series"))) {
mp.remove(mpe);
String elementType = mpe.getFlavor().getType();
if (StringUtils.isNotBlank(elementType)) {
// remember the tags for this type of element
if (!seriesExtDcTags.containsKey(elementType)) {
// initialize the tags list on the first occurrence of this element type
seriesExtDcTags.put(elementType, new ArrayList<>());
}
for (String tag : mpe.getTags()) {
seriesExtDcTags.get(elementType).add(tag);
}
}
}
}
}
} catch (SeriesException e) {
logger.info("Unable to retrieve series element types from series service for the series {}", oldSeriesId, e);
}
}
if (StringUtils.isNotBlank(mp.getSeries())) {
// add updated series dublincore to the media package
try {
DublinCoreCatalog seriesDC = seriesService.getSeries(mp.getSeries());
if (seriesDC != null) {
mp.setSeriesTitle(seriesDC.getFirst(DublinCore.PROPERTY_TITLE));
try (InputStream in = IOUtils.toInputStream(seriesDC.toXmlString(), "UTF-8")) {
String elementId = UUID.randomUUID().toString();
URI catalogUrl = workspace.put(mp.getIdentifier().compact(), elementId, "dublincore.xml", in);
MediaPackageElement mpe = mp.add(catalogUrl, MediaPackageElement.Type.Catalog, MediaPackageElements.SERIES);
mpe.setIdentifier(elementId);
mpe.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, workspace.read(catalogUrl)));
if (StringUtils.isNotBlank(oldSeriesId)) {
for (String tag : seriesDcTags) {
mpe.addTag(tag);
}
} else {
// add archive tag to the element if the media package had no series set before
mpe.addTag("archive");
}
} catch (IOException e) {
throw new IllegalStateException("Unable to add the series dublincore to the media package " + mp.getIdentifier(), e);
}
}
} catch (SeriesException e) {
throw new IllegalStateException("Unable to retrieve series dublincore catalog for the series " + mp.getSeries(), e);
} catch (NotFoundException | UnauthorizedException e) {
throw new IllegalArgumentException("Unable to retrieve series dublincore catalog for the series " + mp.getSeries(), e);
}
// add updated series ACL to the media package
try {
AccessControlList seriesAccessControl = seriesService.getSeriesAccessControl(mp.getSeries());
if (seriesAccessControl != null) {
mp = authorizationService.setAcl(mp, AclScope.Series, seriesAccessControl).getA();
for (MediaPackageElement seriesAclMpe : mp.getElementsByFlavor(MediaPackageElements.XACML_POLICY_SERIES)) {
if (StringUtils.isNotBlank(oldSeriesId)) {
for (String tag : seriesAclTags) {
seriesAclMpe.addTag(tag);
}
} else {
// add archive tag to the element if the media package had no series set before
seriesAclMpe.addTag("archive");
}
}
}
} catch (SeriesException e) {
throw new IllegalStateException("Unable to retrieve series ACL for series " + oldSeriesId, e);
} catch (NotFoundException e) {
logger.debug("There is no ACL set for the series {}", mp.getSeries());
}
// add updated series extended metadata to the media package
try {
Opt<Map<String, byte[]>> seriesElementsOpt = seriesService.getSeriesElements(mp.getSeries());
for (Map<String, byte[]> seriesElements : seriesElementsOpt) {
for (String seriesElementType : seriesElements.keySet()) {
try (InputStream in = new ByteArrayInputStream(seriesElements.get(seriesElementType))) {
String elementId = UUID.randomUUID().toString();
URI catalogUrl = workspace.put(mp.getIdentifier().compact(), elementId, "dublincore.xml", in);
MediaPackageElement mpe = mp.add(catalogUrl, MediaPackageElement.Type.Catalog, MediaPackageElementFlavor.flavor(seriesElementType, "series"));
mpe.setIdentifier(elementId);
mpe.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, workspace.read(catalogUrl)));
if (StringUtils.isNotBlank(oldSeriesId)) {
if (seriesExtDcTags.containsKey(seriesElementType)) {
for (String tag : seriesExtDcTags.get(seriesElementType)) {
mpe.addTag(tag);
}
}
} else {
// add archive tag to the element if the media package had no series set before
mpe.addTag("archive");
}
} catch (IOException e) {
throw new IllegalStateException(String.format("Unable to serialize series element %s for the series %s", seriesElementType, mp.getSeries()), e);
} catch (NotFoundException e) {
throw new IllegalArgumentException("Unable to retrieve series element dublincore catalog for the series " + mp.getSeries(), e);
}
}
}
} catch (SeriesException e) {
throw new IllegalStateException("Unable to retrieve series elements for the series " + mp.getSeries(), e);
}
}
}
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class ConfigurableSeriesDCCatalogUIAdapter method loadDublinCoreCatalog.
protected Opt<DublinCoreCatalog> loadDublinCoreCatalog(String seriesId) {
try {
Opt<byte[]> seriesElementData = getSeriesService().getSeriesElementData(requireNonNull(seriesId), flavor.getType());
if (seriesElementData.isSome()) {
final DublinCoreCatalog dc = DublinCoreByteFormat.read(seriesElementData.get());
// Make sure that the catalog has its flavor set.
// It may happen, when updating a system, that already saved catalogs
// do not have a flavor.
dc.setFlavor(flavor);
dc.addBindings(config.getXmlNamespaceContext());
return Opt.some(dc);
} else {
final DublinCoreCatalog dc = DublinCores.mkStandard();
dc.addBindings(config.getXmlNamespaceContext());
dc.setRootTag(new EName(config.getCatalogXmlRootNamespace(), config.getCatalogXmlRootElementName()));
dc.setFlavor(flavor);
return Opt.some(dc);
}
} catch (SeriesException e) {
logger.error("Error while loading DublinCore catalog of series '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
return Opt.none();
}
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesListProvider method getList.
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
Map<String, String> series = new HashMap<String, String>();
SeriesQuery q = new SeriesQuery().setCount(Integer.MAX_VALUE);
if (query != null) {
if (query.hasFilter(FILTER_TEXT)) {
StringListFilter filter = (StringListFilter) query.getFilter(FILTER_TEXT);
if (filter.getValue().isSome())
q.setText(filter.getValue().get());
}
if (query.getLimit().isSome())
q.setCount(query.getLimit().get());
if (query.getOffset().isSome())
q.setStartPage(query.getOffset().get());
}
List<DublinCoreCatalog> result = null;
try {
if (!CONTRIBUTORS.equals(listName) && !ORGANIZERS.equals(listName) && !TITLE_EXTENDED.equals(listName)) {
return seriesService.getIdTitleMapOfAllSeries();
}
result = seriesService.getSeries(q).getCatalogList();
} catch (SeriesException e) {
throw new ListProviderException("Error appends on the series service: " + e);
} catch (UnauthorizedException e) {
throw new ListProviderException("Unauthorized access to series service: " + e);
}
for (DublinCoreCatalog dc : result) {
if (CONTRIBUTORS.equals(listName)) {
String contributor = dc.getFirst(DublinCore.PROPERTY_CONTRIBUTOR);
if (StringUtils.isNotBlank(contributor))
series.put(contributor, contributor);
} else if (ORGANIZERS.equals(listName)) {
String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
if (StringUtils.isNotBlank(organizer))
series.put(organizer, organizer);
} else if (TITLE_EXTENDED.equals(listName)) {
String created = dc.getFirst(DublinCoreCatalog.PROPERTY_CREATED);
String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
StringBuilder sb = new StringBuilder(dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
if (StringUtils.isNotBlank(created) && StringUtils.isNotBlank(organizer)) {
List<String> extendedTitleData = new ArrayList<>();
if (StringUtils.isNotBlank(created)) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(EncodingSchemeUtils.decodeDate(created));
extendedTitleData.add(Integer.toString(calendar.get(Calendar.YEAR)));
}
if (StringUtils.isNotBlank(organizer))
extendedTitleData.add(organizer);
sb.append(" (").append(StringUtils.join(extendedTitleData, ", ")).append(")");
}
series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), sb.toString());
} else {
series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
}
}
return series;
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesServiceRemoteImpl method addSeriesElement.
@Override
public boolean addSeriesElement(String seriesID, String type, byte[] data) throws SeriesException {
HttpPut put = new HttpPut("/" + seriesID + "/elements/" + type);
put.setEntity(new ByteArrayEntity(data, ContentType.DEFAULT_BINARY));
HttpResponse response = getResponse(put, SC_CREATED, SC_INTERNAL_SERVER_ERROR);
try {
if (response == null) {
throw new SeriesException(format("Error while adding element of type '%s' in series '%s'", type, seriesID));
} else {
final int statusCode = response.getStatusLine().getStatusCode();
switch(statusCode) {
case SC_CREATED:
return true;
case SC_INTERNAL_SERVER_ERROR:
throw new SeriesException(format("Error while updating element of type '%s' in series '%s'", type, seriesID));
default:
throw new SeriesException(format("Unexpected status code", statusCode));
}
}
} finally {
closeConnection(response);
}
}
use of org.opencastproject.series.api.SeriesException 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");
}
Aggregations