use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRMetadataStoreTest method listIDs.
@Test
public void listIDs() throws Exception {
Iterator<Integer> IDs = getMetaDataStore().listIDs(true);
while (IDs.hasNext()) {
getMetaDataStore().delete(IDs.next());
}
assertFalse(getMetaDataStore().exists(1));
assertFalse(getMetaDataStore().listIDs(true).hasNext());
assertFalse(getMetaDataStore().listIDs(false).hasNext());
Document xml1 = new Document(new Element("root"));
getMetaDataStore().create(new MCRJDOMContent(xml1));
getMetaDataStore().create(new MCRJDOMContent(xml1));
getMetaDataStore().create(new MCRJDOMContent(xml1));
ArrayList<Integer> l1 = new ArrayList<>();
IDs = getMetaDataStore().listIDs(true);
while (IDs.hasNext()) {
int id = IDs.next();
if (!l1.isEmpty()) {
assertTrue(id > l1.get(l1.size() - 1));
}
l1.add(id);
}
assertTrue(l1.size() == 3);
ArrayList<Integer> l2 = new ArrayList<>();
IDs = getMetaDataStore().listIDs(false);
while (IDs.hasNext()) {
int id = IDs.next();
if (!l2.isEmpty()) {
assertTrue(id < l2.get(l2.size() - 1));
}
l2.add(id);
}
assertTrue(l2.size() == 3);
Collections.sort(l2);
assertEquals(l1, l2);
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRMetadataStoreTest method createDocument.
@Test
public void createDocument() throws Exception {
Document xml1 = new Document(new Element("root"));
MCRStoredMetadata sm = getMetaDataStore().create(new MCRJDOMContent(xml1));
assertNotNull(sm);
int id1 = sm.getID();
assertTrue(id1 > 0);
MCRStoredMetadata sm2 = getMetaDataStore().retrieve(id1);
MCRContent xml2 = sm2.getMetadata();
assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
int id2 = getMetaDataStore().create(new MCRJDOMContent(xml1)).getID();
assertTrue(id2 > id1);
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRVersioningMetadataStoreTest method update.
@Test
public void update() throws Exception {
Document xml1 = new Document(new Element("root"));
MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
Document xml3 = new Document(new Element("update"));
long rev = vm.getRevision();
vm.update(new MCRJDOMContent(xml3));
assertTrue(vm.getRevision() > rev);
MCRContent xml4 = getVersStore().retrieve(vm.getID()).getMetadata();
assertEquals(new MCRJDOMContent(xml3).asString(), xml4.asString());
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRVersioningMetadataStoreTest method versioning.
@Test
public void versioning() throws Exception {
Document xml1 = new Document(new Element("bingo"));
MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
long baseRev = vm.getRevision();
assertTrue(vm.isUpToDate());
List<MCRMetadataVersion> versions = vm.listVersions();
assertNotNull(versions);
assertEquals(1, versions.size());
MCRMetadataVersion mv = versions.get(0);
assertSame(mv.getMetadataObject(), vm);
assertEquals(baseRev, mv.getRevision());
assertEquals(MCRSessionMgr.getCurrentSession().getUserInformation().getUserID(), mv.getUser());
assertEquals(MCRMetadataVersion.CREATED, mv.getType());
bzzz();
Document xml2 = new Document(new Element("bango"));
vm.update(new MCRJDOMContent(xml2));
assertTrue(vm.getRevision() > baseRev);
assertTrue(vm.isUpToDate());
versions = vm.listVersions();
assertEquals(2, versions.size());
mv = versions.get(0);
assertEquals(baseRev, mv.getRevision());
mv = versions.get(1);
assertEquals(vm.getRevision(), mv.getRevision());
assertEquals(MCRMetadataVersion.UPDATED, mv.getType());
bzzz();
Document xml3 = new Document(new Element("bongo"));
vm.update(new MCRJDOMContent(xml3));
versions = vm.listVersions();
assertEquals(3, versions.size());
mv = versions.get(0);
assertEquals(baseRev, mv.getRevision());
mv = versions.get(2);
assertEquals(vm.getRevision(), mv.getRevision());
assertTrue(versions.get(0).getRevision() < versions.get(1).getRevision());
assertTrue(versions.get(1).getRevision() < versions.get(2).getRevision());
assertTrue(versions.get(0).getDate().before(versions.get(1).getDate()));
assertTrue(versions.get(1).getDate().before(versions.get(2).getDate()));
xml1 = versions.get(0).retrieve().asXML();
assertNotNull(xml1);
assertEquals("bingo", xml1.getRootElement().getName());
xml2 = versions.get(1).retrieve().asXML();
assertNotNull(xml2);
assertEquals("bango", xml2.getRootElement().getName());
xml3 = versions.get(2).retrieve().asXML();
assertNotNull(xml1);
assertEquals("bongo", xml3.getRootElement().getName());
bzzz();
versions.get(1).restore();
assertTrue(vm.getRevision() > versions.get(2).getRevision());
assertTrue(vm.getLastModified().after(versions.get(2).getDate()));
assertEquals("bango", vm.getMetadata().asXML().getRootElement().getName());
assertEquals(4, vm.listVersions().size());
}
use of org.mycore.common.content.MCRJDOMContent in project mycore by MyCoRe-Org.
the class MCRLayoutServiceTarget method handleSubmission.
@Override
public void handleSubmission(ServletContext context, MCRServletJob job, MCREditorSession session, String style) throws Exception {
session.getSubmission().setSubmittedValues(job.getRequest().getParameterMap());
Document result = session.getEditedXML();
if (session.getValidator().isValid()) {
result = MCRChangeTracker.removeChangeTracking(result);
result = session.getXMLCleaner().clean(result);
result = session.getPostProcessor().process(result);
if ((style != null) && (!style.isEmpty()))
job.getRequest().setAttribute("XSL.Style", style);
MCRContent editedXML = new MCRJDOMContent(result);
MCRLayoutService.instance().doLayout(job.getRequest(), job.getResponse(), editedXML);
session.setBreakpoint("After handling target layout " + style);
} else {
session.setBreakpoint("After validation failed, target layout " + style);
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(session.getRedirectURL(null)));
}
}
Aggregations