Skip to content
Snippets Groups Projects
Commit 605ac11a authored by uhensler's avatar uhensler
Browse files

OO-5323: Prevent transcodings for external video resources

parent 36db420b
No related branches found
No related tags found
No related merge requests found
Showing
with 232 additions and 95 deletions
...@@ -382,11 +382,12 @@ public interface VideoManager { ...@@ -382,11 +382,12 @@ public interface VideoManager {
public Size getVideoResolutionFromOLATResource (OLATResource videoResource); public Size getVideoResolutionFromOLATResource (OLATResource videoResource);
/** /**
* Gets the all video resources metadata. * Gets the video resources metadata.
* @param searchParams
* *
* @return the all video resources metadata * @return the video resources metadata
*/ */
public List<VideoMeta> getAllVideoResourcesMetadata(); public List<VideoMeta> getVideoMetadata(VideoMetadataSearchParams searchParams);
/** /**
* Gets the video meta data. * Gets the video meta data.
...@@ -395,7 +396,7 @@ public interface VideoManager { ...@@ -395,7 +396,7 @@ public interface VideoManager {
* @return the video meta data * @return the video meta data
*/ */
public VideoMeta getVideoMetadata(OLATResource videoResource); public VideoMeta getVideoMetadata(OLATResource videoResource);
/** /**
* Exchange poster of the new resource. * Exchange poster of the new resource.
* *
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.video;
/**
*
* Initial date: 4 Mar 2021<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class VideoMetadataSearchParams {
private Boolean urlNull;
private Integer minHeight;
public Boolean getUrlNull() {
return urlNull;
}
public void setUrlNull(Boolean urlNull) {
this.urlNull = urlNull;
}
public Integer getMinHeight() {
return minHeight;
}
public void setMinHeight(Integer minHeight) {
this.minHeight = minHeight;
}
}
...@@ -84,6 +84,7 @@ import org.olat.modules.video.VideoManager; ...@@ -84,6 +84,7 @@ import org.olat.modules.video.VideoManager;
import org.olat.modules.video.VideoMarkers; import org.olat.modules.video.VideoMarkers;
import org.olat.modules.video.VideoMeta; import org.olat.modules.video.VideoMeta;
import org.olat.modules.video.VideoMetadata; import org.olat.modules.video.VideoMetadata;
import org.olat.modules.video.VideoMetadataSearchParams;
import org.olat.modules.video.VideoModule; import org.olat.modules.video.VideoModule;
import org.olat.modules.video.VideoQuestion; import org.olat.modules.video.VideoQuestion;
import org.olat.modules.video.VideoQuestions; import org.olat.modules.video.VideoQuestions;
...@@ -1246,8 +1247,8 @@ public class VideoManagerImpl implements VideoManager { ...@@ -1246,8 +1247,8 @@ public class VideoManagerImpl implements VideoManager {
} }
@Override @Override
public List<VideoMeta> getAllVideoResourcesMetadata() { public List<VideoMeta> getVideoMetadata(VideoMetadataSearchParams searchParams) {
return videoMetadataDao.getAllVideoResourcesMetadata(); return videoMetadataDao.getVideoMetadata(searchParams);
} }
@Override @Override
......
...@@ -22,11 +22,15 @@ package org.olat.modules.video.manager; ...@@ -22,11 +22,15 @@ package org.olat.modules.video.manager;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.persistence.TypedQuery;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.QueryBuilder;
import org.olat.core.commons.services.image.Size; import org.olat.core.commons.services.image.Size;
import org.olat.modules.video.VideoFormat; import org.olat.modules.video.VideoFormat;
import org.olat.modules.video.VideoManager; import org.olat.modules.video.VideoManager;
import org.olat.modules.video.VideoMeta; import org.olat.modules.video.VideoMeta;
import org.olat.modules.video.VideoMetadataSearchParams;
import org.olat.modules.video.model.VideoMetaImpl; import org.olat.modules.video.model.VideoMetaImpl;
import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntry;
import org.olat.resource.OLATResource; import org.olat.resource.OLATResource;
...@@ -73,18 +77,24 @@ public class VideoMetadataDAO { ...@@ -73,18 +77,24 @@ public class VideoMetadataDAO {
return dbInstance.getCurrentEntityManager().merge(videoMetadata); return dbInstance.getCurrentEntityManager().merge(videoMetadata);
} }
/** List<VideoMeta> getVideoMetadata(VideoMetadataSearchParams searchParams) {
* Gets the all video resources metadata. QueryBuilder sb = new QueryBuilder();
* sb.append("select meta from videometadata as meta");
* @return the all video resources metadata sb.append(" inner join fetch meta.videoResource as vResource");
*/ if (searchParams.getUrlNull() != null) {
List<VideoMeta> getAllVideoResourcesMetadata () { sb.and().append("meta.url is ").append("not ", !searchParams.getUrlNull().booleanValue()).append("null");
StringBuilder sb = new StringBuilder(); }
sb.append("select meta from videometadata as meta") if (searchParams.getMinHeight() != null) {
.append(" order by meta.creationDate asc, meta.id asc"); sb.and().append("meta.height >= :minHeight");
return dbInstance.getCurrentEntityManager() }
.createQuery(sb.toString(),VideoMeta.class)
.getResultList(); TypedQuery<VideoMeta> query = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(),VideoMeta.class);
if (searchParams.getMinHeight() != null) {
query.setParameter("minHeight", searchParams.getMinHeight());
}
return query.getResultList();
} }
/** /**
......
...@@ -131,6 +131,7 @@ public class VideoMetaImpl implements VideoMeta, Persistable, ModifiedInfo { ...@@ -131,6 +131,7 @@ public class VideoMetaImpl implements VideoMeta, Persistable, ModifiedInfo {
return url; return url;
} }
@Override
public void setUrl(String url) { public void setUrl(String url) {
this.url = url; this.url = url;
} }
......
...@@ -26,74 +26,50 @@ package org.olat.modules.video.ui; ...@@ -26,74 +26,50 @@ package org.olat.modules.video.ui;
*/ */
public class TranscodingRow { public class TranscodingRow {
private int resolution; private final int resolution;
private int sumVideos; private final int sumVideos;
private int missingTranscodings; private final int external;
private int failedTranscodings; private final int missingTranscodings;
private int numberTranscodings; private final int failedTranscodings;
private boolean allTranscoded; private final int numberTranscodings;
private final boolean startTranscodingAvailable;
public TranscodingRow(int resolution, int numberTranscodings, int failedTranscodings, int sumVideos, boolean mayTranscode) { public TranscodingRow(int resolution, int numberTranscodings, int failedTranscodings, int extern, int sumVideos, boolean mayTranscode) {
super();
this.resolution = resolution; this.resolution = resolution;
this.numberTranscodings = numberTranscodings; this.numberTranscodings = numberTranscodings;
this.sumVideos = sumVideos; this.sumVideos = sumVideos;
this.missingTranscodings = sumVideos - numberTranscodings - failedTranscodings; this.external = extern;
this.missingTranscodings = sumVideos - extern - numberTranscodings - failedTranscodings;
this.failedTranscodings = failedTranscodings; this.failedTranscodings = failedTranscodings;
this.allTranscoded = numberTranscodings + failedTranscodings < sumVideos && mayTranscode; this.startTranscodingAvailable = mayTranscode && missingTranscodings > 0;
}
public boolean isAllTranscoded() {
return allTranscoded;
}
public void setAllTranscoded(boolean allTranscoded) {
this.allTranscoded = allTranscoded;
} }
public int getResolution() { public int getResolution() {
return resolution; return resolution;
} }
public void setResolution(int resolution) {
this.resolution = resolution;
}
public int getSumVideos() { public int getSumVideos() {
return sumVideos; return sumVideos;
} }
public void setSumVideos(int sumVideos) { public int getExtern() {
this.sumVideos = sumVideos; return external;
} }
public int getNumberTranscodings() { public int getNumberTranscodings() {
return numberTranscodings; return numberTranscodings;
} }
public void setNumberTranscodings(int numberTranscodings) {
this.numberTranscodings = numberTranscodings;
}
public int getFailedTranscodings() { public int getFailedTranscodings() {
return failedTranscodings; return failedTranscodings;
} }
public void setFailedTranscodings(int failedTranscodings) {
this.failedTranscodings = failedTranscodings;
}
public int getMissingTranscodings() { public int getMissingTranscodings() {
return missingTranscodings >= 0 ? missingTranscodings : 0; return missingTranscodings >= 0 ? missingTranscodings : 0;
} }
public void setMissingTranscodings(int missingTranscodings) { public boolean isStartTranscodingAvailable() {
this.missingTranscodings = missingTranscodings; return startTranscodingAvailable;
} }
} }
...@@ -49,10 +49,11 @@ public class TranscodingTableModel extends DefaultFlexiTableDataModel<Transcodin ...@@ -49,10 +49,11 @@ public class TranscodingTableModel extends DefaultFlexiTableDataModel<Transcodin
switch(TranscodingCols.values()[col]) { switch(TranscodingCols.values()[col]) {
case resolutions: return translator.translate("quality.resolution." + resolution.getResolution()); case resolutions: return translator.translate("quality.resolution." + resolution.getResolution());
case sumVideos: return resolution.getSumVideos(); case sumVideos: return resolution.getSumVideos();
case extern: return resolution.getExtern();
case numberTranscodings: return resolution.getNumberTranscodings(); case numberTranscodings: return resolution.getNumberTranscodings();
case failedTranscodings: return resolution.getFailedTranscodings(); case failedTranscodings: return resolution.getFailedTranscodings();
case missingTranscodings: return resolution.getMissingTranscodings(); case missingTranscodings: return resolution.getMissingTranscodings();
case transcode: return resolution.isAllTranscoded(); case transcode: return resolution.isStartTranscodingAvailable();
case delete: return resolution.getNumberTranscodings() > 0; case delete: return resolution.getNumberTranscodings() > 0;
default: return ""; default: return "";
} }
...@@ -61,6 +62,7 @@ public class TranscodingTableModel extends DefaultFlexiTableDataModel<Transcodin ...@@ -61,6 +62,7 @@ public class TranscodingTableModel extends DefaultFlexiTableDataModel<Transcodin
public enum TranscodingCols implements FlexiSortableColumnDef { public enum TranscodingCols implements FlexiSortableColumnDef {
resolutions("quality.table.header.resolution"), resolutions("quality.table.header.resolution"),
sumVideos("sum.video"), sumVideos("sum.video"),
extern("extern.videos"),
numberTranscodings("number.transcodings"), numberTranscodings("number.transcodings"),
failedTranscodings("number.transcodings.failed"), failedTranscodings("number.transcodings.failed"),
missingTranscodings("missing.transcodings"), missingTranscodings("missing.transcodings"),
......
...@@ -40,8 +40,10 @@ import org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionE ...@@ -40,8 +40,10 @@ import org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionE
import org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer; import org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer;
import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.WindowControl;
import org.olat.core.util.StringHelper;
import org.olat.modules.video.VideoManager; import org.olat.modules.video.VideoManager;
import org.olat.modules.video.VideoMeta; import org.olat.modules.video.VideoMeta;
import org.olat.modules.video.VideoMetadataSearchParams;
import org.olat.modules.video.VideoModule; import org.olat.modules.video.VideoModule;
import org.olat.modules.video.VideoTranscoding; import org.olat.modules.video.VideoTranscoding;
import org.olat.modules.video.model.TranscodingCount; import org.olat.modules.video.model.TranscodingCount;
...@@ -58,11 +60,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -58,11 +60,12 @@ import org.springframework.beans.factory.annotation.Autowired;
*/ */
public class VideoAdminTranscodingController extends FormBasicController { public class VideoAdminTranscodingController extends FormBasicController {
// Hardcoded same as VideoAdminSetController
private static final List<Integer> RESOLUTIONS = List.of(2160, 1080, 720, 480, 360, 240);
private TranscodingTableModel tableModel; private TranscodingTableModel tableModel;
private FlexiTableElement transcodingTable; private FlexiTableElement transcodingTable;
private Map<OLATResource,Integer> nativeResolutions;
@Autowired @Autowired
private VideoManager videoManager; private VideoManager videoManager;
@Autowired @Autowired
...@@ -70,13 +73,6 @@ public class VideoAdminTranscodingController extends FormBasicController { ...@@ -70,13 +73,6 @@ public class VideoAdminTranscodingController extends FormBasicController {
public VideoAdminTranscodingController(UserRequest ureq, WindowControl wControl) { public VideoAdminTranscodingController(UserRequest ureq, WindowControl wControl) {
super(ureq, wControl, "transcoding_admin"); super(ureq, wControl, "transcoding_admin");
nativeResolutions = new HashMap<>();
List<VideoMeta> olatresources = videoManager.getAllVideoResourcesMetadata();
//cache native resolutions
for (VideoMeta videoResource : olatresources) {
nativeResolutions.put(videoResource.getVideoResource(), videoResource.getHeight());
}
initForm(ureq); initForm(ureq);
} }
...@@ -90,6 +86,7 @@ public class VideoAdminTranscodingController extends FormBasicController { ...@@ -90,6 +86,7 @@ public class VideoAdminTranscodingController extends FormBasicController {
FlexiTableColumnModel transcodingModel = FlexiTableDataModelFactory.createFlexiTableColumnModel(); FlexiTableColumnModel transcodingModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.resolutions)); transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.resolutions));
transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.sumVideos)); transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.sumVideos));
transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.extern));
transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.numberTranscodings)); transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.numberTranscodings));
transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.failedTranscodings)); transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.failedTranscodings));
transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.missingTranscodings)); transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.missingTranscodings));
...@@ -122,9 +119,7 @@ public class VideoAdminTranscodingController extends FormBasicController { ...@@ -122,9 +119,7 @@ public class VideoAdminTranscodingController extends FormBasicController {
} }
private void loadTable() { private void loadTable() {
List<TranscodingRow> resolutions = new ArrayList<>(); List<TranscodingRow> resolutions = new ArrayList<>(6);
// Hardcoded same as VideoAdminSetController
int[] fixresolution = { 2160, 1080, 720, 480, 360, 240 };
Map<Integer, Integer> successCount = new HashMap<>(); Map<Integer, Integer> successCount = new HashMap<>();
int beginErrorCode = VideoTranscoding.TRANSCODING_STATUS_INEFFICIENT; int beginErrorCode = VideoTranscoding.TRANSCODING_STATUS_INEFFICIENT;
for (TranscodingCount transcodingCount : videoManager.getAllVideoTranscodingsCountSuccess(beginErrorCode)) { for (TranscodingCount transcodingCount : videoManager.getAllVideoTranscodingsCountSuccess(beginErrorCode)) {
...@@ -134,19 +129,27 @@ public class VideoAdminTranscodingController extends FormBasicController { ...@@ -134,19 +129,27 @@ public class VideoAdminTranscodingController extends FormBasicController {
for (TranscodingCount transcodingCount : videoManager.getAllVideoTranscodingsCountFails(beginErrorCode)) { for (TranscodingCount transcodingCount : videoManager.getAllVideoTranscodingsCountFails(beginErrorCode)) {
failCount.put(transcodingCount.getResolution(), transcodingCount.getCount()); failCount.put(transcodingCount.getResolution(), transcodingCount.getCount());
} }
for (int i = 0; i < fixresolution.length; i++) {
int counter = 0; List<VideoMeta> videoMetadatas = videoManager.getVideoMetadata(new VideoMetadataSearchParams());
for (OLATResource videoResource : nativeResolutions.keySet()) { for (Integer resolution: RESOLUTIONS) {
if (nativeResolutions.get(videoResource) >= fixresolution[i]) counter++; int sumVideos = 0;
int extern = 0;
for (VideoMeta videoMetadata : videoMetadatas) {
if (videoMetadata.getHeight() >= resolution) {
sumVideos++;
if (StringHelper.containsNonWhitespace(videoMetadata.getUrl())) {
extern++;
}
}
} }
int success = successCount.get(fixresolution[i]) != null ? successCount.get(fixresolution[i]) : 0;
int fails = failCount.get(fixresolution[i]) != null ? failCount.get(fixresolution[i]) : 0; int success = successCount.get(resolution) != null ? successCount.get(resolution) : 0;
TranscodingRow transcodingRow = new TranscodingRow(fixresolution[i], success, fails, counter, mayTranscode(fixresolution[i])); int fails = failCount.get(resolution) != null ? failCount.get(resolution) : 0;
TranscodingRow transcodingRow = new TranscodingRow(resolution.intValue(), success, fails, extern, sumVideos,
mayTranscode(resolution.intValue()));
resolutions.add(transcodingRow); resolutions.add(transcodingRow);
} }
if (resolutions != null){ tableModel.setObjects(resolutions);
tableModel.setObjects(resolutions);
}
transcodingTable.reset(true, true, true); transcodingTable.reset(true, true, true);
} }
...@@ -176,8 +179,6 @@ public class VideoAdminTranscodingController extends FormBasicController { ...@@ -176,8 +179,6 @@ public class VideoAdminTranscodingController extends FormBasicController {
reloadTable(); reloadTable();
} }
// state orders for inexistent transcodings
private void queueCreateTranscoding(TranscodingRow source) { private void queueCreateTranscoding(TranscodingRow source) {
List<VideoTranscoding> allVideoTranscodings = videoManager.getOneVideoResolution(source.getResolution()); List<VideoTranscoding> allVideoTranscodings = videoManager.getOneVideoResolution(source.getResolution());
Map<OLATResource, Set<Integer>> availableTranscodings = new HashMap<>(); Map<OLATResource, Set<Integer>> availableTranscodings = new HashMap<>();
...@@ -190,12 +191,15 @@ public class VideoAdminTranscodingController extends FormBasicController { ...@@ -190,12 +191,15 @@ public class VideoAdminTranscodingController extends FormBasicController {
availableTranscodings.put(videoTranscoding.getVideoResource(), availableresolutions); availableTranscodings.put(videoTranscoding.getVideoResource(), availableresolutions);
} }
} }
for (OLATResource videoResource : nativeResolutions.keySet()) {
if (availableTranscodings.get(videoResource) == null || VideoMetadataSearchParams searchParams = new VideoMetadataSearchParams();
!availableTranscodings.get(videoResource).contains(source.getResolution())) { searchParams.setUrlNull(Boolean.TRUE);
if (nativeResolutions.get(videoResource) >= source.getResolution()) { searchParams.setMinHeight(source.getResolution());
videoManager.createTranscoding(videoResource, source.getResolution(), "mp4"); List<VideoMeta> videoMetadatas = videoManager.getVideoMetadata(searchParams);
} for (VideoMeta videoMetadata : videoMetadatas) {
OLATResource videoResource = videoMetadata.getVideoResource();
if (!availableTranscodings.containsKey(videoResource) || !availableTranscodings.get(videoResource).contains(source.getResolution())) {
videoManager.createTranscoding(videoResource, source.getResolution(), "mp4");
} }
} }
} }
......
...@@ -20,6 +20,7 @@ delete.transcodings=Alle Transcodings dieser Aufl\u00F6sung wurden gel\u00F6scht ...@@ -20,6 +20,7 @@ delete.transcodings=Alle Transcodings dieser Aufl\u00F6sung wurden gel\u00F6scht
error.format.not.supported=Format ist nicht unterst\u00FCtzt. error.format.not.supported=Format ist nicht unterst\u00FCtzt.
error.no.duration=Dauer must gr\u00F6sser als 0 sein. error.no.duration=Dauer must gr\u00F6sser als 0 sein.
error.percent.value=Wert muss zwischen 0 und 100 sein. error.percent.value=Wert muss zwischen 0 und 100 sein.
extern.videos=Extern
info.transcoding=Fehlende Transcodings werden erstellt. info.transcoding=Fehlende Transcodings werden erstellt.
listing.viewing.counter={0} Aufrufe listing.viewing.counter={0} Aufrufe
manage.transcodings.description=Verwalten Sie alle Transkodierungen einer Aufl\u00F6sungen mit einem Klick. Ist das H\u00E4kchen gesetzt, sind alle Transkodierungen vorhanden und k\u00F6nnen durch Deaktivieren des Kontrollk\u00E4stchens gel\u00F6scht werden. Sind die Transkodieungen unvollst\u00E4ndig, werden fehlende transkodiert. manage.transcodings.description=Verwalten Sie alle Transkodierungen einer Aufl\u00F6sungen mit einem Klick. Ist das H\u00E4kchen gesetzt, sind alle Transkodierungen vorhanden und k\u00F6nnen durch Deaktivieren des Kontrollk\u00E4stchens gel\u00F6scht werden. Sind die Transkodieungen unvollst\u00E4ndig, werden fehlende transkodiert.
......
...@@ -20,6 +20,7 @@ delete.transcodings=All Transcodings of this Resolution have been deleted. ...@@ -20,6 +20,7 @@ delete.transcodings=All Transcodings of this Resolution have been deleted.
error.format.not.supported=Format is not supported. error.format.not.supported=Format is not supported.
error.no.duration=Duration must be greater than 0. error.no.duration=Duration must be greater than 0.
error.percent.value=Value nned to be between 0 and 100 error.percent.value=Value nned to be between 0 and 100
extern.videos=External
info.transcoding=Missing Transcodings will be created. info.transcoding=Missing Transcodings will be created.
listing.viewing.counter={0} viewings listing.viewing.counter={0} viewings
manage.transcodings.description=Manage all transcodings per selection of the checkbox. Is the resolution checkbox is checked, unselect the checkbox to delete all. Are transcodings incomplete, select the checkbox to transcode the missing. manage.transcodings.description=Manage all transcodings per selection of the checkbox. Is the resolution checkbox is checked, unselect the checkbox to delete all. Are transcodings incomplete, select the checkbox to transcode the missing.
......
...@@ -21,7 +21,6 @@ package org.olat.upgrade; ...@@ -21,7 +21,6 @@ package org.olat.upgrade;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.services.doceditor.onlyoffice.OnlyOfficeModule;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -37,11 +36,10 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade { ...@@ -37,11 +36,10 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade {
private static final String VERSION = "OLAT_15.3.12"; private static final String VERSION = "OLAT_15.3.12";
private static final String DELETE_APPOINTMENT_USER_RESTRICTIONS = "DELETE APPOINTMENT USER RESTRICTIONS"; private static final String DELETE_APPOINTMENT_USER_RESTRICTIONS = "DELETE APPOINTMENT USER RESTRICTIONS";
private static final String DELETE_TRANSCODING_OF_EXTERNAL_VIDEOS = "DELETE TRANSCODING OF EXTERNAL VIDEOS";
@Autowired @Autowired
private DB dbInstance; private DB dbInstance;
@Autowired
private OnlyOfficeModule onlyofficeModule;
public OLATUpgrade_15_3_12() { public OLATUpgrade_15_3_12() {
super(); super();
...@@ -64,6 +62,7 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade { ...@@ -64,6 +62,7 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade {
boolean allOk = true; boolean allOk = true;
allOk &= deleteAppointmentUserRestriction(upgradeManager, uhd); allOk &= deleteAppointmentUserRestriction(upgradeManager, uhd);
allOk &= deleteTranscodingOfExternalVideos(upgradeManager, uhd);
uhd.setInstallationComplete(allOk); uhd.setInstallationComplete(allOk);
upgradeManager.setUpgradesHistory(uhd, VERSION); upgradeManager.setUpgradesHistory(uhd, VERSION);
...@@ -84,7 +83,7 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade { ...@@ -84,7 +83,7 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade {
.createQuery(query) .createQuery(query)
.executeUpdate(); .executeUpdate();
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
log.info("Deleted ppointment restriction with no group."); log.info("Deleted appointment restriction with no group.");
} catch (Exception e) { } catch (Exception e) {
log.error("", e); log.error("", e);
allOk = false; allOk = false;
...@@ -96,4 +95,30 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade { ...@@ -96,4 +95,30 @@ public class OLATUpgrade_15_3_12 extends OLATUpgrade {
return allOk; return allOk;
} }
private boolean deleteTranscodingOfExternalVideos(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
boolean allOk = true;
if (!uhd.getBooleanDataValue(DELETE_TRANSCODING_OF_EXTERNAL_VIDEOS)) {
try {
StringBuilder sb = new StringBuilder();
sb.append("delete from videotranscoding as transcoding");
sb.append(" where transcoding.videoResource.key in (");
sb.append(" select metadata.videoResource.key from videometadata as metadata where metadata.url is not null");
sb.append(")");
dbInstance.getCurrentEntityManager()
.createQuery(sb.toString())
.executeUpdate();
dbInstance.commitAndCloseSession();
log.info("Deleted transcodings of external videos");
} catch (Exception e) {
log.error("", e);
allOk = false;
}
uhd.setBooleanDataValue(DELETE_TRANSCODING_OF_EXTERNAL_VIDEOS, allOk);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return allOk;
}
} }
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
*/ */
package org.olat.modules.video.manager; package org.olat.modules.video.manager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.olat.test.JunitTestHelper.random;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.Assert;
...@@ -26,6 +29,7 @@ import org.junit.Test; ...@@ -26,6 +29,7 @@ import org.junit.Test;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.modules.video.VideoFormat; import org.olat.modules.video.VideoFormat;
import org.olat.modules.video.VideoMeta; import org.olat.modules.video.VideoMeta;
import org.olat.modules.video.VideoMetadataSearchParams;
import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntry;
import org.olat.test.JunitTestHelper; import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase; import org.olat.test.OlatTestCase;
...@@ -77,6 +81,68 @@ public class VideoMetadataDAOTest extends OlatTestCase { ...@@ -77,6 +81,68 @@ public class VideoMetadataDAOTest extends OlatTestCase {
Assert.assertEquals("https://frentix.com/video.mp4", reloadMeta.getUrl()); Assert.assertEquals("https://frentix.com/video.mp4", reloadMeta.getUrl());
} }
@Test
public void shouldFilterMetadataByUrlNull() {
RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, null, VideoFormat.mp4);
VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1100, null, VideoFormat.mp4);
VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1200, random(), VideoFormat.mp4);
VideoMetadataSearchParams searchParams = new VideoMetadataSearchParams();
searchParams.setUrlNull(Boolean.TRUE);
List<VideoMeta> metadata = videoMetadataDao.getVideoMetadata(searchParams);
assertThat(metadata)
.contains(meta0, meta1)
.doesNotContain(meta2);
}
@Test
public void shouldFilterMetadataByUrlNotNull() {
RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, random(), VideoFormat.mp4);
VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1100, random(), VideoFormat.mp4);
VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1200, null, VideoFormat.mp4);
VideoMetadataSearchParams searchParams = new VideoMetadataSearchParams();
searchParams.setUrlNull(Boolean.FALSE);
List<VideoMeta> metadata = videoMetadataDao.getVideoMetadata(searchParams);
assertThat(metadata)
.contains(meta0, meta1)
.doesNotContain(meta2);
}
@Test
public void shouldFilterMetadataByMinHight() {
RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry3 = JunitTestHelper.createAndPersistRepositoryEntry();
VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, null, VideoFormat.mp4);
meta0.setHeight(1000);
meta0 = videoMetadataDao.updateVideoMetadata(meta0);
VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1500, null, VideoFormat.mp4);
meta1.setHeight(2000);
meta1 = videoMetadataDao.updateVideoMetadata(meta1);
VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1500, null, VideoFormat.mp4);
meta2.setHeight(500);
meta2 = videoMetadataDao.updateVideoMetadata(meta2);
VideoMeta meta3 = videoMetadataDao.createVideoMetadata(entry3, 1500, null, VideoFormat.mp4);
VideoMetadataSearchParams searchParams = new VideoMetadataSearchParams();
searchParams.setMinHeight(1000);
List<VideoMeta> metadata = videoMetadataDao.getVideoMetadata(searchParams);
assertThat(metadata)
.contains(meta0, meta1)
.doesNotContain(meta2, meta3);
}
@Test @Test
public void deleteVideoMetadata () { public void deleteVideoMetadata () {
RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry(); RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
...@@ -96,7 +162,7 @@ public class VideoMetadataDAOTest extends OlatTestCase { ...@@ -96,7 +162,7 @@ public class VideoMetadataDAOTest extends OlatTestCase {
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
//retrieve list of entries //retrieve list of entries
List<VideoMeta> metadata = videoMetadataDao.getAllVideoResourcesMetadata(); List<VideoMeta> metadata = videoMetadataDao.getVideoMetadata(new VideoMetadataSearchParams());
Assert.assertTrue(metadata.contains(meta0)); Assert.assertTrue(metadata.contains(meta0));
Assert.assertTrue(metadata.contains(meta1)); Assert.assertTrue(metadata.contains(meta1));
Assert.assertTrue(metadata.contains(meta2)); Assert.assertTrue(metadata.contains(meta2));
...@@ -110,7 +176,7 @@ public class VideoMetadataDAOTest extends OlatTestCase { ...@@ -110,7 +176,7 @@ public class VideoMetadataDAOTest extends OlatTestCase {
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
//retrieve new list //retrieve new list
List<VideoMeta> deleteMetadata = videoMetadataDao.getAllVideoResourcesMetadata(); List<VideoMeta> deleteMetadata = videoMetadataDao.getVideoMetadata(new VideoMetadataSearchParams());
Assert.assertFalse(deleteMetadata.contains(meta0)); Assert.assertFalse(deleteMetadata.contains(meta0));
Assert.assertTrue(deleteMetadata.contains(meta1)); Assert.assertTrue(deleteMetadata.contains(meta1));
Assert.assertTrue(deleteMetadata.contains(meta2)); Assert.assertTrue(deleteMetadata.contains(meta2));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment