Search in sources :

Example 1 with MCRStoredMetadata

use of org.mycore.datamodel.ifs2.MCRStoredMetadata in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method retrieveObjectDates.

/**
 * returns an enhanced list of object ids and their last modified date
 * @param ids MCRObject ids
 * @throws IOException thrown by {@link MCRObjectIDFileSystemDate}
 */
public List<MCRObjectIDDate> retrieveObjectDates(List<String> ids) throws IOException {
    List<MCRObjectIDDate> objidlist = new ArrayList<>(ids.size());
    for (String id : ids) {
        MCRStoredMetadata sm = this.retrieveStoredMetadata(MCRObjectID.getInstance(id));
        objidlist.add(new MCRObjectIDFileSystemDate(sm, id));
    }
    return objidlist;
}
Also used : MCRObjectIDFileSystemDate(org.mycore.datamodel.ifs2.MCRObjectIDFileSystemDate) MCRStoredMetadata(org.mycore.datamodel.ifs2.MCRStoredMetadata) ArrayList(java.util.ArrayList)

Example 2 with MCRStoredMetadata

use of org.mycore.datamodel.ifs2.MCRStoredMetadata in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method retrieveContent.

public MCRContent retrieveContent(MCRObjectID mcrid) throws IOException {
    MCRContent metadata;
    MCRStoredMetadata storedMetadata = retrieveStoredMetadata(mcrid);
    if (storedMetadata == null || storedMetadata.isDeleted()) {
        return null;
    }
    metadata = storedMetadata.getMetadata();
    return metadata;
}
Also used : MCRStoredMetadata(org.mycore.datamodel.ifs2.MCRStoredMetadata) MCRContent(org.mycore.common.content.MCRContent)

Example 3 with MCRStoredMetadata

use of org.mycore.datamodel.ifs2.MCRStoredMetadata in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method update.

/**
 * Updates metadata of existing MCRObject in the persistent store.
 *
 * @param mcrid the MCRObjectID
 * @param xml the xml metadata of the MCRObject
 * @param lastModified the date of last modification to set
 * @return the stored metadata as IFS2 object
 */
public MCRStoredMetadata update(MCRObjectID mcrid, MCRContent xml, Date lastModified) throws IOException {
    if (!exists(mcrid)) {
        String msg = "Object to update does not exist: " + mcrid;
        throw new MCRPersistenceException(msg);
    }
    MCRStoredMetadata sm = getStore(mcrid).retrieve(mcrid.getNumberAsInteger());
    try {
        sm.update(xml);
    } catch (JDOMException e) {
        throw new MCRPersistenceException("Error while updating object: " + mcrid, e);
    }
    sm.setLastModified(lastModified);
    MCRConfiguration.instance().systemModified();
    return sm;
}
Also used : MCRStoredMetadata(org.mycore.datamodel.ifs2.MCRStoredMetadata) JDOMException(org.jdom2.JDOMException) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 4 with MCRStoredMetadata

use of org.mycore.datamodel.ifs2.MCRStoredMetadata in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method getLastModified.

/**
 * Returns the time when the xml data of a MCRObject was last modified.
 * @return output of {@link MCRStoredMetadata#getLastModified()}
 * @throws IOException thrown by {@link MCRMetadataStore#retrieve(int)}
 */
public long getLastModified(MCRObjectID id) throws IOException {
    MCRMetadataStore store = getStore(id);
    MCRStoredMetadata metadata = store.retrieve(id.getNumberAsInteger());
    if (metadata != null) {
        return metadata.getLastModified().getTime();
    }
    return -1;
}
Also used : MCRStoredMetadata(org.mycore.datamodel.ifs2.MCRStoredMetadata) MCRMetadataStore(org.mycore.datamodel.ifs2.MCRMetadataStore)

Example 5 with MCRStoredMetadata

use of org.mycore.datamodel.ifs2.MCRStoredMetadata in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManagerTest method delete.

@Test
public void delete() throws IOException {
    MCRStoredMetadata metadata = getStore().create(MyCoRe_document_00000001.id, MyCoRe_document_00000001.blob, MyCoRe_document_00000001.lastModified);
    assertFalse(MyCoRe_document_00000001.id + " should not have been deleted", metadata.isDeleted());
    assertTrue(MyCoRe_document_00000001.id + " should exist", getStore().exists(MyCoRe_document_00000001.id));
    try {
        getStore().delete(MCR_document_00000001.id);
    } catch (IOException e) {
    // is expected as MCR_document_00000001 does not exist
    }
    assertTrue(MyCoRe_document_00000001.id + " should not have been deleted", getStore().exists(MyCoRe_document_00000001.id));
}
Also used : MCRStoredMetadata(org.mycore.datamodel.ifs2.MCRStoredMetadata) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MCRStoredMetadata (org.mycore.datamodel.ifs2.MCRStoredMetadata)6 JDOMException (org.jdom2.JDOMException)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 MCRContent (org.mycore.common.content.MCRContent)1 MCRMetadataStore (org.mycore.datamodel.ifs2.MCRMetadataStore)1 MCRObjectIDFileSystemDate (org.mycore.datamodel.ifs2.MCRObjectIDFileSystemDate)1