use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project openolat by klemens.
the class RepositoryEntryResource method updateEntry.
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateEntry(@PathParam("repoEntryKey") String repoEntryKey, RepositoryEntryVO vo, @Context HttpServletRequest request) {
if (!RestSecurityHelper.isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
RepositoryEntryLifecycle lifecycle = null;
RepositoryEntryLifecycleVO lifecycleVo = vo.getLifecycle();
if (lifecycleVo != null) {
RepositoryEntryLifecycleDAO lifecycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
if (lifecycleVo.getKey() != null) {
lifecycle = lifecycleDao.loadById(lifecycleVo.getKey());
if (lifecycle.isPrivateCycle()) {
// check date
String fromStr = lifecycleVo.getValidFrom();
String toStr = lifecycleVo.getValidTo();
String label = lifecycleVo.getLabel();
String softKey = lifecycleVo.getSoftkey();
Date from = ObjectFactory.parseDate(fromStr);
Date to = ObjectFactory.parseDate(toStr);
lifecycle.setLabel(label);
lifecycle.setSoftKey(softKey);
lifecycle.setValidFrom(from);
lifecycle.setValidTo(to);
}
} else {
String fromStr = lifecycleVo.getValidFrom();
String toStr = lifecycleVo.getValidTo();
String label = lifecycleVo.getLabel();
String softKey = lifecycleVo.getSoftkey();
Date from = ObjectFactory.parseDate(fromStr);
Date to = ObjectFactory.parseDate(toStr);
lifecycle = lifecycleDao.create(label, softKey, true, from, to);
}
}
RepositoryEntry reloaded = repositoryManager.setDescriptionAndName(re, vo.getDisplayname(), vo.getDescription(), vo.getLocation(), vo.getAuthors(), vo.getExternalId(), vo.getExternalRef(), vo.getManagedFlags(), lifecycle);
RepositoryEntryVO rvo = ObjectFactory.get(reloaded);
return Response.ok(rvo).build();
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method updateEntry.
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateEntry(@PathParam("repoEntryKey") String repoEntryKey, RepositoryEntryVO vo, @Context HttpServletRequest request) {
if (!RestSecurityHelper.isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
RepositoryEntryLifecycle lifecycle = null;
RepositoryEntryLifecycleVO lifecycleVo = vo.getLifecycle();
if (lifecycleVo != null) {
RepositoryEntryLifecycleDAO lifecycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
if (lifecycleVo.getKey() != null) {
lifecycle = lifecycleDao.loadById(lifecycleVo.getKey());
if (lifecycle.isPrivateCycle()) {
// check date
String fromStr = lifecycleVo.getValidFrom();
String toStr = lifecycleVo.getValidTo();
String label = lifecycleVo.getLabel();
String softKey = lifecycleVo.getSoftkey();
Date from = ObjectFactory.parseDate(fromStr);
Date to = ObjectFactory.parseDate(toStr);
lifecycle.setLabel(label);
lifecycle.setSoftKey(softKey);
lifecycle.setValidFrom(from);
lifecycle.setValidTo(to);
}
} else {
String fromStr = lifecycleVo.getValidFrom();
String toStr = lifecycleVo.getValidTo();
String label = lifecycleVo.getLabel();
String softKey = lifecycleVo.getSoftkey();
Date from = ObjectFactory.parseDate(fromStr);
Date to = ObjectFactory.parseDate(toStr);
lifecycle = lifecycleDao.create(label, softKey, true, from, to);
}
}
RepositoryEntry reloaded = repositoryManager.setDescriptionAndName(re, vo.getDisplayname(), vo.getDescription(), vo.getLocation(), vo.getAuthors(), vo.getExternalId(), vo.getExternalRef(), vo.getManagedFlags(), lifecycle);
RepositoryEntryVO rvo = ObjectFactory.get(reloaded);
return Response.ok(rvo).build();
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.
the class ObjectFactory method get.
public static CourseVO get(RepositoryEntry re, ICourse course) {
CourseVO vo = new CourseVO();
vo.setKey(course.getResourceableId());
vo.setDisplayName(re.getDisplayname());
vo.setDescription(re.getDescription());
vo.setTitle(course.getCourseTitle());
vo.setEditorRootNodeId(course.getEditorTreeModel().getRootNode().getIdent());
vo.setSoftKey(re.getSoftkey());
vo.setRepoEntryKey(re.getKey());
OLATResource resource = re.getOlatResource();
if (resource != null) {
vo.setOlatResourceKey(resource.getKey());
vo.setOlatResourceId(resource.getResourceableId());
vo.setOlatResourceTypeName(resource.getResourceableTypeName());
}
vo.setAuthors(re.getAuthors());
vo.setLocation(re.getLocation());
vo.setExternalId(re.getExternalId());
vo.setExternalRef(re.getExternalRef());
vo.setManagedFlags(re.getManagedFlagsString());
if (re.getLifecycle() != null) {
vo.setLifecycle(new RepositoryEntryLifecycleVO(re.getLifecycle()));
}
return vo;
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.
the class ObjectFactory method get.
public static RepositoryEntryVO get(RepositoryEntry entry) {
RepositoryEntryVO vo = new RepositoryEntryVO();
vo.setKey(entry.getKey());
vo.setSoftkey(entry.getSoftkey());
vo.setResourcename(entry.getResourcename());
vo.setDisplayname(entry.getDisplayname());
vo.setDescription(entry.getDescription());
vo.setAuthors(entry.getAuthors());
vo.setLocation(entry.getLocation());
vo.setResourceableId(entry.getResourceableId());
vo.setResourceableTypeName(entry.getResourceableTypeName());
OLATResource resource = entry.getOlatResource();
if (resource != null) {
vo.setOlatResourceKey(resource.getKey());
vo.setOlatResourceId(resource.getResourceableId());
vo.setOlatResourceTypeName(resource.getResourceableTypeName());
}
vo.setExternalId(entry.getExternalId());
vo.setExternalRef(entry.getExternalRef());
vo.setManagedFlags(entry.getManagedFlagsString());
if (entry.getLifecycle() != null) {
vo.setLifecycle(new RepositoryEntryLifecycleVO(entry.getLifecycle()));
}
return vo;
}
use of org.olat.restapi.support.vo.RepositoryEntryLifecycleVO in project OpenOLAT by OpenOLAT.
the class RepositoryEntryLifecycleTest method testGetEntries.
@Test
public void testGetEntries() throws IOException, URISyntaxException {
// create a public life cycle
RepositoryEntryLifecycle reLifeCycle = reLifeCycleDao.create("REST life cycle", "Unique", false, null, null);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -2);
Date from = cal.getTime();
cal.add(Calendar.DATE, 5);
Date to = cal.getTime();
RepositoryEntryLifecycle limitLifeCycle = reLifeCycleDao.create("REST life cycle", "Unique", false, from, to);
dbInstance.commitAndCloseSession();
// retrieve the public life cycles
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/lifecycle").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<RepositoryEntryLifecycleVO> entryVoes = parseRepoArray(body);
assertNotNull(entryVoes);
int found = 0;
for (RepositoryEntryLifecycleVO entryVo : entryVoes) {
if (reLifeCycle.getKey().equals(entryVo.getKey())) {
found++;
} else if (limitLifeCycle.getKey().equals(entryVo.getKey())) {
found++;
}
}
conn.shutdown();
Assert.assertEquals(2, found);
}
Aggregations