Skip to content
Snippets Groups Projects
Commit 554d34e7 authored by srosse's avatar srosse
Browse files

OO-4328: copy metadata from template in REST API too

parent 2aa72c23
No related branches found
No related tags found
No related merge requests found
......@@ -532,6 +532,7 @@ public class CoursesWebService {
preparedEntry = handler.copy(initialAuthor, src, preparedEntry);
preparedEntry.setCanDownload(src.getCanDownload());
preparedEntry.setMainLanguage(src.getMainLanguage());
if(StringHelper.containsNonWhitespace(softKey)) {
preparedEntry.setSoftkey(softKey);
}
......@@ -543,24 +544,36 @@ public class CoursesWebService {
}
if(StringHelper.containsNonWhitespace(authors)) {
preparedEntry.setAuthors(authors);
} else {
preparedEntry.setAuthors(src.getAuthors());
}
if(StringHelper.containsNonWhitespace(location)) {
preparedEntry.setLocation(location);
} else {
preparedEntry.setLocation(src.getLocation());
}
if(StringHelper.containsNonWhitespace(managedFlags)) {
preparedEntry.setManagedFlagsString(managedFlags);
}
if(StringHelper.containsNonWhitespace(objectives)) {
preparedEntry.setObjectives(objectives);
} else {
preparedEntry.setObjectives(src.getObjectives());
}
if(StringHelper.containsNonWhitespace(credits)) {
preparedEntry.setCredits(credits);
} else {
preparedEntry.setCredits(src.getCredits());
}
if(StringHelper.containsNonWhitespace(requirements)) {
preparedEntry.setRequirements(requirements);
} else {
preparedEntry.setRequirements(src.getRequirements());
}
if(StringHelper.containsNonWhitespace(expenditureOfWork)) {
preparedEntry.setExpenditureOfWork(expenditureOfWork);
} else {
preparedEntry.setExpenditureOfWork(src.getExpenditureOfWork());
}
preparedEntry.setEntryStatus(status);
preparedEntry.setAllUsers(allUsers);
......
......@@ -536,6 +536,50 @@ public class CoursesTest extends OlatRestTestCase {
assertNotNull(vo.getRepoEntryKey());
assertNotNull(vo.getKey());
}
@Test
public void testCopyCourse_metadata() throws IOException, URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-5");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
Assert.assertNotNull(entry);
// set some metadata
repositoryManager.setDescriptionAndName(entry, "REST Course copy", "external-ref", "Prof.Dr. Mueller",
"A very descriptive course", "With high objectives", "Lots of requirements", "But credited", "English", "Bienne",
"Expedited in 2 hours", null, null, null);
dbInstance.commitAndCloseSession();
conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses")
.queryParam("shortTitle", "Course copy")
.queryParam("title", "Course copy")
.queryParam("initialAuthor", author.getKey().toString())
.queryParam("copyFrom", entry.getKey().toString())
.build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
CourseVO vo = conn.parse(response, CourseVO.class);
Assert.assertNotNull(vo);
Assert.assertNotNull(vo.getRepoEntryKey());
Assert.assertNotNull(vo.getKey());
// check metadata
RepositoryEntry courseEntry = repositoryManager.lookupRepositoryEntry(vo.getRepoEntryKey());
Assert.assertNotNull(courseEntry);
Assert.assertNull(courseEntry.getExternalId());
Assert.assertNull(courseEntry.getExternalRef());
Assert.assertEquals("A very descriptive course", courseEntry.getDescription());
Assert.assertEquals("With high objectives", courseEntry.getObjectives());
Assert.assertEquals("Lots of requirements", courseEntry.getRequirements());
Assert.assertEquals("But credited", courseEntry.getCredits());
Assert.assertEquals("English", courseEntry.getMainLanguage());
Assert.assertEquals("Bienne", courseEntry.getLocation());
Assert.assertEquals("Expedited in 2 hours", courseEntry.getExpenditureOfWork());
}
@Test
public void testCopyCourse_unkownCourse() throws IOException, URISyntaxException {
......
......@@ -34,11 +34,11 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.document.Document;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.resource.OresHelper;
......@@ -47,7 +47,7 @@ import org.olat.core.util.vfs.NamedContainerImpl;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.vfs.VFSManager;
import org.olat.search.model.OlatDocument;
import org.olat.search.model.AbstractOlatDocument;
import org.olat.search.service.SearchResourceContext;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -150,13 +150,13 @@ public class FileDocumentFactoryTest extends OlatTestCase {
resourceContext.setFilePath(filePath + "/" + leaf.getName());
Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
// 1. Check content
String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
String content = htmlDocument.get(AbstractOlatDocument.CONTENT_FIELD_NAME);
assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
// 2. Check resourceUrl
String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
String resourceUrl = htmlDocument.get(AbstractOlatDocument.RESOURCEURL_FIELD_NAME);
assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
// 3. Check File-Type
String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
String fileType = htmlDocument.get(AbstractOlatDocument.FILETYPE_FIELD_NAME);
assertEquals("Wrong file-type", "type.file.html", fileType);
} catch (IOException e) {
......
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