Bug 56154

Summary: [CoreProperties] - get|set - lastModifiedBy missing
Product: POI Reporter: marcel <marcel_kobain>
Component: POI OverallAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: solid.danil
Priority: P2    
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: patch and small test
moved tests to separate method

Description marcel 2014-02-18 15:38:01 UTC
Hello,

Why it is not possible to set a lastModifiedBy in a POIXMLProperties.CoreProperties ?

(Even the function exists in PackagePropertiesPart.setLastModifiedByProperty ...)

I think we have to add the attribut in POIXMLProperties.CoreProperties :


public String getLastModifiedBy () {
return part.getLastModifiedBy;
}

public String setLastModifiedBy (String lastModifiedBy) {
return part.setLastModifiedBy(lastModifiedBy);
}

Thanks,
Comment 1 Nick Burch 2014-02-18 16:00:21 UTC
Any chance you could turn this into a very small patch, then write a short junit unit test that verifies we can read / change / save / read this property? (It can probably re-use an existing test file for this)
Comment 2 Daniil Lopatin 2016-07-08 14:31:55 UTC
Created attachment 34025 [details]
patch and small test

Please apply this patch to 3.15 version.
It simply adds setter and getter for lastModifiedBy.
Test with core properties has been updated.
Comment 3 Daniil Lopatin 2016-07-08 16:15:40 UTC
Created attachment 34026 [details]
moved tests to separate method
Comment 4 Daniil Lopatin 2016-07-08 16:16:47 UTC
Comment on attachment 34026 [details]
moved tests to separate method

>Index: src/ooxml/java/org/apache/poi/POIXMLProperties.java
>===================================================================
>--- src/ooxml/java/org/apache/poi/POIXMLProperties.java	(revision 1751911)
>+++ src/ooxml/java/org/apache/poi/POIXMLProperties.java	(working copy)
>@@ -301,6 +301,12 @@
>         public void setLastPrinted(String date) {
>             part.setLastPrintedProperty(date);
>         }
>+        public String getLastModifiedBy() {
>+            return part.getLastModifiedByProperty().getValue();
>+        }
>+        public void setLastModifiedBy(String lastModifiedBy) {
>+            part.setLastModifiedByProperty(lastModifiedBy);
>+        }
>         public Date getModified() {
>             return part.getModifiedProperty().getValue();
>         }
>Index: src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
>===================================================================
>--- src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java	(revision 1751911)
>+++ src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java	(working copy)
>@@ -192,7 +192,7 @@
> 
>         XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
>         doc.close();
>-        cp = doc.getProperties().getCoreProperties();
>+        cp = doc2.getProperties().getCoreProperties();
>         Date dt3 = cp.getCreated();
>         assertEquals(dateCreated, dt3);
>         doc2.close();
>@@ -208,6 +208,14 @@
>         assertEquals("20", _coreProperties.getRevision());
>     }
> 
>+    @Test
>+    public void testLastModifiedByProperty() {
>+        String lastModifiedBy = _coreProperties.getLastModifiedBy();
>+        assertEquals("Paolo Mottadelli", lastModifiedBy);
>+        _coreProperties.setLastModifiedBy("Test User");
>+        assertEquals("Test User", _coreProperties.getLastModifiedBy());
>+    }
>+
>     public static boolean dateTimeEqualToUTCString(Date dateTime, String utcString) {
>         Calendar utcCalendar = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);
>         utcCalendar.setTimeInMillis(dateTime.getTime());
Comment 5 Javen O'Neal 2016-07-08 18:05:58 UTC
Applied in r1751948, r1751949, and r1751950. Will be included in POI 3.15 beta 3 release.

Updated changelog in r1751952.
Comment 6 Javen O'Neal 2016-07-08 18:07:01 UTC
I renamed these new methods to getLastModifiedByUser and setLastModifiedByUser for clarity.