Skip to content
Snippets Groups Projects
Commit 3249537c authored by srosse's avatar srosse
Browse files

OO-1386: copy more fields of the source entry to the copy of the resource

parent e616294e
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,7 @@ public interface RepositoryService { ...@@ -50,7 +50,7 @@ public interface RepositoryService {
public RepositoryEntry create(String initialAuthor, String resourceName, public RepositoryEntry create(String initialAuthor, String resourceName,
String displayname, String description, OLATResource resource); String displayname, String description, OLATResource resource);
public RepositoryEntry copy(RepositoryEntry sourceEntry, Identity author, String displayname, String description); public RepositoryEntry copy(RepositoryEntry sourceEntry, Identity author, String displayname);
public RepositoryEntry loadByKey(Long key); public RepositoryEntry loadByKey(Long key);
......
...@@ -254,6 +254,7 @@ cmd.import.ressource.desc=W\u00E4hlen Sie eine Lernressource f\u00FCr den Import ...@@ -254,6 +254,7 @@ cmd.import.ressource.desc=W\u00E4hlen Sie eine Lernressource f\u00FCr den Import
comments=Kommentar comments=Kommentar
confirmation.no.toolHelp=Aktion abbrechen. confirmation.no.toolHelp=Aktion abbrechen.
confirmation.yes.toolHelp=Lernressource l\u00F6schen. confirmation.yes.toolHelp=Lernressource l\u00F6schen.
copy.suffix= (Kopie)
course.config.changed.text=Sie m\u00F6chten die Kurseinstellungen \u00E4ndern. Wenn Sie 'Ja' klicken, m\u00FCssen {0} Personen im Kurs den Kurs neu starten. Bei 'Nein' werden die \u00C4nderungen verworfen. Wollen Sie fortfahren? course.config.changed.text=Sie m\u00F6chten die Kurseinstellungen \u00E4ndern. Wenn Sie 'Ja' klicken, m\u00FCssen {0} Personen im Kurs den Kurs neu starten. Bei 'Nein' werden die \u00C4nderungen verworfen. Wollen Sie fortfahren?
course.config.changed.title=\u00C4nderung der Einstellungen course.config.changed.title=\u00C4nderung der Einstellungen
course.made.by=mit course.made.by=mit
......
...@@ -253,6 +253,7 @@ cmd.import.ressource.desc=Choose a learning resource to import\:<ul><li>OpenOLAT ...@@ -253,6 +253,7 @@ cmd.import.ressource.desc=Choose a learning resource to import\:<ul><li>OpenOLAT
comments=Comments comments=Comments
confirmation.no.toolHelp=Cancel action. confirmation.no.toolHelp=Cancel action.
confirmation.yes.toolHelp=Delete learning resource. confirmation.yes.toolHelp=Delete learning resource.
copy.suffix= (copy)
course.config.changed.text=You want to modify your course settings. When clicking on 'Yes' {0} participants will have to restart this course. When clicking on 'No' all modifications will be discarded. Do you wish to proceed? course.config.changed.text=You want to modify your course settings. When clicking on 'Yes' {0} participants will have to restart this course. When clicking on 'No' all modifications will be discarded. Do you wish to proceed?
course.config.changed.title=Modification of settings course.config.changed.title=Modification of settings
course.made.by=with course.made.by=with
......
...@@ -255,6 +255,7 @@ cmd.import.ressource.desc=Choisissez une ressource didactique \u00E0 importer\:< ...@@ -255,6 +255,7 @@ cmd.import.ressource.desc=Choisissez une ressource didactique \u00E0 importer\:<
comments=Commentaires comments=Commentaires
confirmation.no.toolHelp=Annuler l'op\u00E9ration confirmation.no.toolHelp=Annuler l'op\u00E9ration
confirmation.yes.toolHelp=Supprimer la ressource confirmation.yes.toolHelp=Supprimer la ressource
copy.suffix= (copie)
course.config.changed.text=Vous voulez modifier les r\u00E9glages du cours. Si vous cliquez 'oui' les personnes utilisant le cours doivent red\u00E9marrer le cours. Si vous cliquez sur 'non', les modifications ne sont pas retenues. Voulez-vous continuer? course.config.changed.text=Vous voulez modifier les r\u00E9glages du cours. Si vous cliquez 'oui' les personnes utilisant le cours doivent red\u00E9marrer le cours. Si vous cliquez sur 'non', les modifications ne sont pas retenues. Voulez-vous continuer?
course.config.changed.title=Modification des r\u00E9glages course.config.changed.title=Modification des r\u00E9glages
course.made.by=avec course.made.by=avec
......
...@@ -186,15 +186,25 @@ public class RepositoryServiceImpl implements RepositoryService { ...@@ -186,15 +186,25 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public RepositoryEntry copy(RepositoryEntry sourceEntry, Identity author, String displayname, String description) { public RepositoryEntry copy(RepositoryEntry sourceEntry, Identity author, String displayname) {
OLATResource sourceResource = sourceEntry.getOlatResource(); OLATResource sourceResource = sourceEntry.getOlatResource();
OLATResource copyResource = resourceManager.createOLATResourceInstance(sourceResource.getResourceableTypeName()); OLATResource copyResource = resourceManager.createOLATResourceInstance(sourceResource.getResourceableTypeName());
RepositoryEntry copyEntry = create(author, null, sourceEntry.getResourcename(), displayname, RepositoryEntry copyEntry = create(author, null, sourceEntry.getResourcename(), displayname,
description, copyResource, RepositoryEntry.ACC_OWNERS); sourceEntry.getDescription(), copyResource, RepositoryEntry.ACC_OWNERS);
//copy all fields
copyEntry.setAuthors(sourceEntry.getAuthors());
copyEntry.setCredits(sourceEntry.getCredits());
copyEntry.setExpenditureOfWork(sourceEntry.getExpenditureOfWork());
copyEntry.setMainLanguage(sourceEntry.getMainLanguage());
copyEntry.setObjectives(sourceEntry.getObjectives());
copyEntry.setRequirements(sourceEntry.getRequirements());
copyEntry = dbInstance.getCurrentEntityManager().merge(copyEntry);
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(sourceEntry); RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(sourceEntry);
copyEntry = handler.copy(sourceEntry, copyEntry); copyEntry = handler.copy(sourceEntry, copyEntry);
//copy the image //copy the image
RepositoryManager.getInstance().copyImage(sourceEntry, copyEntry); RepositoryManager.getInstance().copyImage(sourceEntry, copyEntry);
......
...@@ -721,8 +721,7 @@ public class AuthorListController extends FormBasicController implements Activat ...@@ -721,8 +721,7 @@ public class AuthorListController extends FormBasicController implements Activat
for(AuthoringEntryRow row:rows) { for(AuthoringEntryRow row:rows) {
RepositoryEntry sourceEntry = repositoryService.loadByKey(row.getKey()); RepositoryEntry sourceEntry = repositoryService.loadByKey(row.getKey());
String displayname = "Copy of " + sourceEntry.getDisplayname(); String displayname = "Copy of " + sourceEntry.getDisplayname();
String description = sourceEntry.getDescription(); repositoryService.copy(sourceEntry, getIdentity(), displayname);
repositoryService.copy(sourceEntry, getIdentity(), displayname, description);
} }
showInfo("details.copy.success", new String[]{ Integer.toString(rows.size()) }); showInfo("details.copy.success", new String[]{ Integer.toString(rows.size()) });
......
...@@ -21,26 +21,18 @@ package org.olat.repository.ui.author; ...@@ -21,26 +21,18 @@ package org.olat.repository.ui.author;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItemContainer; import org.olat.core.gui.components.form.flexible.FormItemContainer;
import org.olat.core.gui.components.form.flexible.elements.RichTextElement;
import org.olat.core.gui.components.form.flexible.elements.TextElement; import org.olat.core.gui.components.form.flexible.elements.TextElement;
import org.olat.core.gui.components.form.flexible.impl.FormBasicController; import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event; import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.WindowControl;
import org.olat.core.logging.activity.LearningResourceLoggingAction;
import org.olat.core.logging.activity.OlatResourceableType;
import org.olat.core.logging.activity.ThreadLocalUserActivityLogger;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
import org.olat.core.util.Util; import org.olat.core.util.Util;
import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager; import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryService; import org.olat.repository.RepositoryService;
import org.olat.repository.handlers.RepositoryHandler;
import org.olat.repository.handlers.RepositoryHandlerFactory;
import org.olat.resource.OLATResource;
import org.olat.resource.OLATResourceManager; import org.olat.resource.OLATResourceManager;
import org.olat.util.logging.activity.LoggingResourceable;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
...@@ -52,7 +44,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -52,7 +44,6 @@ import org.springframework.beans.factory.annotation.Autowired;
public class CopyRepositoryEntryController extends FormBasicController { public class CopyRepositoryEntryController extends FormBasicController {
private TextElement displaynameEl; private TextElement displaynameEl;
private RichTextElement descriptionEl;
private RepositoryEntry copyEntry; private RepositoryEntry copyEntry;
private final RepositoryEntry sourceEntry; private final RepositoryEntry sourceEntry;
...@@ -75,13 +66,10 @@ public class CopyRepositoryEntryController extends FormBasicController { ...@@ -75,13 +66,10 @@ public class CopyRepositoryEntryController extends FormBasicController {
@Override @Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String sourceName = StringHelper.escapeHtml(sourceEntry.getDisplayname()); String sourceName = StringHelper.escapeHtml(sourceEntry.getDisplayname());
sourceName += " " + translate("copy.suffix");
displaynameEl = uifactory.addTextElement("cif.displayname", "cif.displayname", 100, sourceName, formLayout); displaynameEl = uifactory.addTextElement("cif.displayname", "cif.displayname", 100, sourceName, formLayout);
displaynameEl.setDisplaySize(30); displaynameEl.setDisplaySize(30);
displaynameEl.setMandatory(true); displaynameEl.setMandatory(true);
descriptionEl = uifactory.addRichTextElementForStringData("cif.description", "cif.description",
"", 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
descriptionEl.getEditorConfiguration().setFileBrowserUploadRelPath("media");
FormLayoutContainer buttonContainer = FormLayoutContainer.createButtonLayout("buttonContainer", getTranslator()); FormLayoutContainer buttonContainer = FormLayoutContainer.createButtonLayout("buttonContainer", getTranslator());
formLayout.add("buttonContainer", buttonContainer); formLayout.add("buttonContainer", buttonContainer);
...@@ -101,13 +89,13 @@ public class CopyRepositoryEntryController extends FormBasicController { ...@@ -101,13 +89,13 @@ public class CopyRepositoryEntryController extends FormBasicController {
@Override @Override
protected void formOK(UserRequest ureq) { protected void formOK(UserRequest ureq) {
doCopy(); String displayname = displaynameEl.getValue();
copyEntry = repositoryService.copy(sourceEntry, getIdentity(), displayname);
fireEvent(ureq, Event.DONE_EVENT); fireEvent(ureq, Event.DONE_EVENT);
} }
@Override @Override
protected void formCancelled(UserRequest ureq) { protected void formCancelled(UserRequest ureq) {
doCleanUp();
fireEvent(ureq, Event.CANCELLED_EVENT); fireEvent(ureq, Event.CANCELLED_EVENT);
} }
...@@ -126,30 +114,4 @@ public class CopyRepositoryEntryController extends FormBasicController { ...@@ -126,30 +114,4 @@ public class CopyRepositoryEntryController extends FormBasicController {
return allOk & super.validateFormLogic(ureq); return allOk & super.validateFormLogic(ureq);
} }
private void doCopy() {
String displayname = displaynameEl.getValue();
String description = descriptionEl.getValue();
OLATResource sourceResource = sourceEntry.getOlatResource();
OLATResource copyResource = resourceManager.createOLATResourceInstance(sourceResource.getResourceableTypeName());
copyEntry = repositoryService.create(getIdentity(), null, sourceEntry.getResourcename(), displayname,
description, copyResource, RepositoryEntry.ACC_OWNERS);
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(sourceEntry);
copyEntry = handler.copy(sourceEntry, copyEntry);
//copy the image
RepositoryManager.getInstance().copyImage(sourceEntry, copyEntry);
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CREATE, getClass(),
LoggingResourceable.wrap(copyEntry, OlatResourceableType.genRepoEntry));
repositoryManager.triggerIndexer(copyEntry);
}
private void doCleanUp() {
//remove repo
}
} }
\ No newline at end of file
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