use of org.opencastproject.themes.persistence.ThemesServiceDatabaseException in project opencast by opencast.
the class ThemesEndpoint method updateTheme.
@PUT
@Path("{themeId}")
@RestQuery(name = "updateTheme", description = "Updates a theme", returnDescription = "Return the updated theme", pathParameters = { @RestParameter(name = "themeId", description = "The theme identifier", isRequired = true, type = Type.INTEGER) }, restParameters = { @RestParameter(name = "default", description = "Whether the theme is default", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "name", description = "The theme name", isRequired = false, type = Type.STRING), @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT), @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING), @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Theme updated"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found.") })
public Response updateTheme(@PathParam("themeId") long themeId, @FormParam("default") Boolean isDefault, @FormParam("name") String name, @FormParam("description") String description, @FormParam("bumperActive") Boolean bumperActive, @FormParam("trailerActive") Boolean trailerActive, @FormParam("titleSlideActive") Boolean titleSlideActive, @FormParam("licenseSlideActive") Boolean licenseSlideActive, @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile, @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile, @FormParam("titleSlideBackground") String titleSlideBackground, @FormParam("licenseSlideBackground") String licenseSlideBackground, @FormParam("titleSlideMetadata") String titleSlideMetadata, @FormParam("licenseSlideDescription") String licenseSlideDescription, @FormParam("watermarkPosition") String watermarkPosition) throws NotFoundException {
try {
Theme origTheme = themesServiceDatabase.getTheme(themeId);
if (isDefault == null)
isDefault = origTheme.isDefault();
if (StringUtils.isBlank(name))
name = origTheme.getName();
if (StringUtils.isEmpty(description))
description = origTheme.getDescription();
if (bumperActive == null)
bumperActive = origTheme.isBumperActive();
if (StringUtils.isEmpty(bumperFile))
bumperFile = origTheme.getBumperFile();
if (trailerActive == null)
trailerActive = origTheme.isTrailerActive();
if (StringUtils.isEmpty(trailerFile))
trailerFile = origTheme.getTrailerFile();
if (titleSlideActive == null)
titleSlideActive = origTheme.isTitleSlideActive();
if (StringUtils.isEmpty(titleSlideMetadata))
titleSlideMetadata = origTheme.getTitleSlideMetadata();
if (StringUtils.isEmpty(titleSlideBackground))
titleSlideBackground = origTheme.getTitleSlideBackground();
if (licenseSlideActive == null)
licenseSlideActive = origTheme.isLicenseSlideActive();
if (StringUtils.isEmpty(licenseSlideBackground))
licenseSlideBackground = origTheme.getLicenseSlideBackground();
if (StringUtils.isEmpty(licenseSlideDescription))
licenseSlideDescription = origTheme.getLicenseSlideDescription();
if (watermarkActive == null)
watermarkActive = origTheme.isWatermarkActive();
if (StringUtils.isEmpty(watermarkFile))
watermarkFile = origTheme.getWatermarkFile();
if (StringUtils.isEmpty(watermarkPosition))
watermarkPosition = origTheme.getWatermarkPosition();
Theme theme = new Theme(origTheme.getId(), origTheme.getCreationDate(), isDefault, origTheme.getCreator(), name, StringUtils.trimToNull(description), BooleanUtils.toBoolean(bumperActive), StringUtils.trimToNull(bumperFile), BooleanUtils.toBoolean(trailerActive), StringUtils.trimToNull(trailerFile), BooleanUtils.toBoolean(titleSlideActive), StringUtils.trimToNull(titleSlideMetadata), StringUtils.trimToNull(titleSlideBackground), BooleanUtils.toBoolean(licenseSlideActive), StringUtils.trimToNull(licenseSlideBackground), StringUtils.trimToNull(licenseSlideDescription), BooleanUtils.toBoolean(watermarkActive), StringUtils.trimToNull(watermarkFile), StringUtils.trimToNull(watermarkPosition));
try {
updateReferencedFiles(origTheme, theme);
} catch (IOException e) {
logger.warn("Error while persisting file: {}", e.getMessage());
return R.serverError();
} catch (NotFoundException e) {
logger.warn("A file that is referenced in theme '{}' was not found: {}", theme, e.getMessage());
return R.badRequest("Referenced non-existing file");
}
Theme updatedTheme = themesServiceDatabase.updateTheme(theme);
return RestUtils.okJson(themeToJSON(updatedTheme));
} catch (ThemesServiceDatabaseException e) {
logger.error("Unable to update theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
}
use of org.opencastproject.themes.persistence.ThemesServiceDatabaseException in project opencast by opencast.
the class ThemesEndpoint method deleteTheme.
@DELETE
@Path("{themeId}")
@RestQuery(name = "deleteTheme", description = "Deletes a theme", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "themeId", isRequired = true, description = "The theme identifier", type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method does not return any content"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public Response deleteTheme(@PathParam("themeId") long themeId) throws NotFoundException, UnauthorizedException {
try {
Theme theme = themesServiceDatabase.getTheme(themeId);
try {
deleteReferencedFiles(theme);
} catch (IOException e) {
logger.warn("Error while deleting referenced file: {}", e.getMessage());
return R.serverError();
}
themesServiceDatabase.deleteTheme(themeId);
deleteThemeOnSeries(themeId);
return RestUtil.R.noContent();
} catch (NotFoundException e) {
logger.warn("Unable to find a theme with id " + themeId);
throw e;
} catch (ThemesServiceDatabaseException e) {
logger.error("Error getting theme {} during delete operation because: {}", themeId, ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
}
use of org.opencastproject.themes.persistence.ThemesServiceDatabaseException in project opencast by opencast.
the class ThemeWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.debug("Running theme workflow operation on workflow {}", workflowInstance.getId());
final MediaPackageElementFlavor bumperFlavor = getOptConfig(workflowInstance, BUMPER_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "bumper"));
final MediaPackageElementFlavor trailerFlavor = getOptConfig(workflowInstance, TRAILER_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "trailer"));
final MediaPackageElementFlavor titleSlideFlavor = getOptConfig(workflowInstance, TITLE_SLIDE_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "title-slide"));
final MediaPackageElementFlavor licenseSlideFlavor = getOptConfig(workflowInstance, LICENSE_SLIDE_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "license-slide"));
final MediaPackageElementFlavor watermarkFlavor = getOptConfig(workflowInstance, WATERMARK_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "watermark"));
final List<String> bumperTags = asList(workflowInstance.getConfiguration(BUMPER_TAGS));
final List<String> trailerTags = asList(workflowInstance.getConfiguration(TRAILER_TAGS));
final List<String> titleSlideTags = asList(workflowInstance.getConfiguration(TITLE_SLIDE_TAGS));
final List<String> licenseSlideTags = asList(workflowInstance.getConfiguration(LICENSE_SLIDE_TAGS));
final List<String> watermarkTags = asList(workflowInstance.getConfiguration(WATERMARK_TAGS));
Opt<String> layoutStringOpt = getOptConfig(workflowInstance, WATERMARK_LAYOUT);
Opt<String> watermarkLayoutVariable = getOptConfig(workflowInstance, WATERMARK_LAYOUT_VARIABLE);
List<String> layoutList = new ArrayList<>(Stream.$(layoutStringOpt).bind(Strings.split(";")).toList());
try {
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
String series = mediaPackage.getSeries();
if (series == null) {
logger.info("Skipping theme workflow operation, no series assigned to mediapackage {}", mediaPackage.getIdentifier());
return createResult(Action.SKIP);
}
Long themeId;
try {
themeId = Long.parseLong(seriesService.getSeriesProperty(series, THEME_PROPERTY_NAME));
} catch (NotFoundException e) {
logger.info("Skipping theme workflow operation, no theme assigned to series {} on mediapackage {}.", series, mediaPackage.getIdentifier());
return createResult(Action.SKIP);
} catch (UnauthorizedException e) {
logger.warn("Skipping theme workflow operation, user not authorized to perform operation: {}", ExceptionUtils.getStackTrace(e));
return createResult(Action.SKIP);
}
Theme theme;
try {
theme = themesServiceDatabase.getTheme(themeId);
} catch (NotFoundException e) {
logger.warn("Skipping theme workflow operation, no theme with id {} found.", themeId);
return createResult(Action.SKIP);
}
logger.info("Applying theme {} to mediapackage {}", themeId, mediaPackage.getIdentifier());
/* Make theme settings available to workflow instance */
workflowInstance.setConfiguration(THEME_ACTIVE, Boolean.toString(theme.isBumperActive() || theme.isTrailerActive() || theme.isTitleSlideActive() || theme.isWatermarkActive()));
workflowInstance.setConfiguration(THEME_BUMPER_ACTIVE, Boolean.toString(theme.isBumperActive()));
workflowInstance.setConfiguration(THEME_TRAILER_ACTIVE, Boolean.toString(theme.isTrailerActive()));
workflowInstance.setConfiguration(THEME_TITLE_SLIDE_ACTIVE, Boolean.toString(theme.isTitleSlideActive()));
workflowInstance.setConfiguration(THEME_TITLE_SLIDE_UPLOADED, Boolean.toString(StringUtils.isNotBlank(theme.getTitleSlideBackground())));
workflowInstance.setConfiguration(THEME_WATERMARK_ACTIVE, Boolean.toString(theme.isWatermarkActive()));
if (theme.isBumperActive() && StringUtils.isNotBlank(theme.getBumperFile())) {
try (InputStream bumper = staticFileService.getFile(theme.getBumperFile())) {
addElement(mediaPackage, bumperFlavor, bumperTags, bumper, staticFileService.getFileName(theme.getBumperFile()), Type.Track);
} catch (NotFoundException e) {
logger.warn("Bumper file {} not found in static file service, skip applying it", theme.getBumperFile());
}
}
if (theme.isTrailerActive() && StringUtils.isNotBlank(theme.getTrailerFile())) {
try (InputStream trailer = staticFileService.getFile(theme.getTrailerFile())) {
addElement(mediaPackage, trailerFlavor, trailerTags, trailer, staticFileService.getFileName(theme.getTrailerFile()), Type.Track);
} catch (NotFoundException e) {
logger.warn("Trailer file {} not found in static file service, skip applying it", theme.getTrailerFile());
}
}
if (theme.isTitleSlideActive()) {
if (StringUtils.isNotBlank(theme.getTitleSlideBackground())) {
try (InputStream titleSlideBackground = staticFileService.getFile(theme.getTitleSlideBackground())) {
addElement(mediaPackage, titleSlideFlavor, titleSlideTags, titleSlideBackground, staticFileService.getFileName(theme.getTitleSlideBackground()), Type.Attachment);
} catch (NotFoundException e) {
logger.warn("Title slide file {} not found in static file service, skip applying it", theme.getTitleSlideBackground());
}
}
// TODO add the title slide metadata to the workflow properties to be used by the cover-image WOH
// String titleSlideMetadata = theme.getTitleSlideMetadata();
}
if (theme.isLicenseSlideActive()) {
if (StringUtils.isNotBlank(theme.getLicenseSlideBackground())) {
try (InputStream licenseSlideBackground = staticFileService.getFile(theme.getLicenseSlideBackground())) {
addElement(mediaPackage, licenseSlideFlavor, licenseSlideTags, licenseSlideBackground, staticFileService.getFileName(theme.getLicenseSlideBackground()), Type.Attachment);
} catch (NotFoundException e) {
logger.warn("License slide file {} not found in static file service, skip applying it", theme.getLicenseSlideBackground());
}
} else {
// TODO define what to do here (maybe extract image as background)
}
// TODO add the license slide description to the workflow properties to be used by the cover-image WOH
// String licenseSlideDescription = theme.getLicenseSlideDescription();
}
if (theme.isWatermarkActive() && StringUtils.isNotBlank(theme.getWatermarkFile())) {
try (InputStream watermark = staticFileService.getFile(theme.getWatermarkFile())) {
addElement(mediaPackage, watermarkFlavor, watermarkTags, watermark, staticFileService.getFileName(theme.getWatermarkFile()), Type.Attachment);
} catch (NotFoundException e) {
logger.warn("Watermark file {} not found in static file service, skip applying it", theme.getWatermarkFile());
}
if (layoutStringOpt.isNone() || watermarkLayoutVariable.isNone())
throw new WorkflowOperationException(format("Configuration key '%s' or '%s' is either missing or empty", WATERMARK_LAYOUT, WATERMARK_LAYOUT_VARIABLE));
AbsolutePositionLayoutSpec watermarkLayout = parseLayout(theme.getWatermarkPosition());
layoutList.set(layoutList.size() - 1, Serializer.json(watermarkLayout).toJson());
layoutStringOpt = Opt.some(Stream.$(layoutList).mkString(";"));
}
if (watermarkLayoutVariable.isSome() && layoutStringOpt.isSome())
workflowInstance.setConfiguration(watermarkLayoutVariable.get(), layoutStringOpt.get());
return createResult(mediaPackage, Action.CONTINUE);
} catch (SeriesException | ThemesServiceDatabaseException | IllegalStateException | IllegalArgumentException | IOException e) {
throw new WorkflowOperationException(e);
}
}
use of org.opencastproject.themes.persistence.ThemesServiceDatabaseException in project opencast by opencast.
the class ThemesEndpoint method createTheme.
@POST
@Path("")
@RestQuery(name = "createTheme", description = "Add a theme", returnDescription = "Return the created theme", restParameters = { @RestParameter(name = "default", description = "Whether the theme is default", isRequired = true, type = Type.BOOLEAN), @RestParameter(name = "name", description = "The theme name", isRequired = true, type = Type.STRING), @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT), @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING), @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Theme created"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The theme references a non-existing file") })
public Response createTheme(@FormParam("default") boolean isDefault, @FormParam("name") String name, @FormParam("description") String description, @FormParam("bumperActive") Boolean bumperActive, @FormParam("trailerActive") Boolean trailerActive, @FormParam("titleSlideActive") Boolean titleSlideActive, @FormParam("licenseSlideActive") Boolean licenseSlideActive, @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile, @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile, @FormParam("titleSlideBackground") String titleSlideBackground, @FormParam("licenseSlideBackground") String licenseSlideBackground, @FormParam("titleSlideMetadata") String titleSlideMetadata, @FormParam("licenseSlideDescription") String licenseSlideDescription, @FormParam("watermarkPosition") String watermarkPosition) {
User creator = securityService.getUser();
Theme theme = new Theme(Option.<Long>none(), new Date(), isDefault, creator, name, StringUtils.trimToNull(description), BooleanUtils.toBoolean(bumperActive), StringUtils.trimToNull(bumperFile), BooleanUtils.toBoolean(trailerActive), StringUtils.trimToNull(trailerFile), BooleanUtils.toBoolean(titleSlideActive), StringUtils.trimToNull(titleSlideMetadata), StringUtils.trimToNull(titleSlideBackground), BooleanUtils.toBoolean(licenseSlideActive), StringUtils.trimToNull(licenseSlideBackground), StringUtils.trimToNull(licenseSlideDescription), BooleanUtils.toBoolean(watermarkActive), StringUtils.trimToNull(watermarkFile), StringUtils.trimToNull(watermarkPosition));
try {
persistReferencedFiles(theme);
} catch (NotFoundException e) {
logger.warn("A file that is referenced in theme '{}' was not found: {}", theme, e.getMessage());
return R.badRequest("Referenced non-existing file");
} catch (IOException e) {
logger.warn("Error while persisting file: {}", e.getMessage());
return R.serverError();
}
try {
Theme createdTheme = themesServiceDatabase.updateTheme(theme);
return RestUtils.okJson(themeToJSON(createdTheme));
} catch (ThemesServiceDatabaseException e) {
logger.error("Unable to create a theme");
return RestUtil.R.serverError();
}
}
Aggregations