Change modified by property of CSFile while generating / updating the file through CS SDK
Hello,
We have a complex system where product details are maintained in PIM tool (Akeneo) and product specific content is sent to TS through publish jobs using CS SDK. Both TS & PIM are configured to different auth mechanism which overrules possibility of sharing session / context.
As of today, each of the file (CSFile) created or updated through PIM to TS - have modified by name of the root user (whose credentials are used while connecting through CS SDK).
We are able to figure out a valid CSUser through client.getPrincipalManager().getAllTSUsers(), even set owner for CSFile - however unable to change the modified by property.
Can you please guide?
Thank you,
Regards,
TSDEVL
Answers
-
You are asking us to help you debug your custom code that no one here has any idea about.
You should first ask yourself when was the last time it worked and what changed ? Don't say nothing, because there had to be some changes.
You can also work on a SAMPLE piece of code that replicates the issue and ask for help from support or these forums.
You should also put specifics about your environment, We have no way of knowing Unix/DOS or what versions, except you use TS and PIM, whatever that is
0 -
Thanks Andy for your prompt reply !
Here are the details about the environment -
OS - 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 13 10:46:25 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
TS - 8.2.0.1.0The file creation flow always worked .. however the issue is - the files created shows the modified by value as that of the root user (obviously that's right behavior as we are using root credentials to connect to CSSDK client), instead of the actual logged in user in pim (say - TSDEVL), also can be seen in the screenshot below.
Here is the sample code -
package com.sample.mediators;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;
import java.util.Properties;import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.factory.CSFactory;
import com.interwoven.cssdk.filesys.CSAreaRelativePath;
import com.interwoven.cssdk.filesys.CSSimpleFile;
import com.interwoven.cssdk.filesys.CSVPath;
import com.interwoven.cssdk.filesys.CSWorkarea;public class CSClientTask {
public static void main(String[] args) { try { String serviceBaseURL = "https://xyz.sample.com"; String userName = "root"; String password = "root"; CSClient client = null; Properties properties = new Properties(); properties.setProperty("com.interwoven.cssdk.factory.CSFactory", "com.interwoven.cssdk.factory.CSSOAPFactory"); properties.setProperty("serviceBaseURL", serviceBaseURL); CSFactory factory = CSFactory.getFactory(properties); client = factory.getClient(userName, StringUtils.EMPTY, password, Locale.US, "TEST", null); String areaPath = "//sample.com/default/main/sample/us/en/WORKAREA/shared/"; String data = "{\"Name\": \"Demo\",\"Author\": \"demo author\",\"Company List\": [\"Compnay: Demo Comp1\",\"Compnay: Demo Comp2\",\"Compnay: Demo Comp3\"]}"; String path = "sites/sample/us/en/website/sampleproduct/2124.json"; CSVPath fullPath = new CSVPath(areaPath); CSWorkarea area = client.getWorkarea(fullPath, false); CSSimpleFile file = addFile(area, path); CSIterator csIterator = client.getPrincipalManager() .getAllTSUsers(); while (csIterator.hasNext()) { CSUser cs = (CSUser) csIterator.next(); if (cs.getDisplayName().equals("TSDEVL")) { file.setOwner(cs); } } CSBinaryExtendedAttribute csbea=new CSBinaryExtendedAttribute(); csbea.setName("Modified By"); csbea.setValue("TSDEVL".getBytes()); InputStream dataStream = IOUtils.toInputStream(data, "UTF-8"); writeDataToFile(area, file, dataStream); } catch (Exception e) { e.printStackTrace(); } } private static void writeDataToFile(CSWorkarea area, CSSimpleFile file, InputStream dataStream) { OutputStream outputStream; try { outputStream = file.getOutputStream(true); IOUtils.copyLarge(dataStream, outputStream); IOUtils.closeQuietly(outputStream); } catch (Exception e) { e.printStackTrace(); } } private static CSSimpleFile addFile(CSWorkarea area, String path) { CSAreaRelativePath relativePath = new CSAreaRelativePath(path); try { return area.createSimpleFile(relativePath); } catch (Exception e) { e.printStackTrace(); return null; } }
}
It creates the file successfully in TS as attached screenshot below.
MY WORKAREA VIEW - AFTER FILE CREATION
**Now, the ask is - ** Can we change modified by property to something like TSDEVL instead of actual value root, programatically.
We tried exploring CSFile / CSNode / CSSimpleFile APIs to change the modified by attribute but no luck .. Tried adding a new CSBinaryExtendedAttribute as well, but that creates a new attribute with name Modified By and doesn't let us change the existing attribute .. Here is a screenshot for reference of file properties
which shows root changed as "TSDEVL" and an additional property added "Modified By".Much appreciate if you can look at our impl and advise if we can change the TS modified by value to a valid CSUser - in my workarea view .. !
Thanks a lot !
Good Day,
TSDEVL
0 -
Hi Andy,
Thanks for your reply.
File creation through CS SDK API has always worked. The problem we are facing is - CS SDK client is created with root credentials to push PIM content to TS. However, now the ask is to show Modified By value to be of the actual user in PIM (e.g. TSDEVL).
Problem is both PIM and TS runs on different authentication mechanism and we can't synchronize the session.
**OS: ** Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 13 10:46:25 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
**TS: ** 8.2.0.1.0Here is the sample code which creates the file:
package com.sample.mediators;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;
import java.util.Properties;import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;import com.interwoven.cssdk.access.CSUser;
import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.common.CSIterator;
import com.interwoven.cssdk.factory.CSFactory;
import com.interwoven.cssdk.filesys.CSAreaRelativePath;
import com.interwoven.cssdk.filesys.CSBinaryExtendedAttribute;
import com.interwoven.cssdk.filesys.CSSimpleFile;
import com.interwoven.cssdk.filesys.CSVPath;
import com.interwoven.cssdk.filesys.CSWorkarea;public class CSClientTask {
public static void main(String[] args) { try { String serviceBaseURL = "https://sample.com"; String userName = "root"; String password = "root"; CSClient client = null; Properties properties = new Properties(); properties.setProperty("com.interwoven.cssdk.factory.CSFactory", "com.interwoven.cssdk.factory.CSSOAPFactory"); properties.setProperty("serviceBaseURL", serviceBaseURL); CSFactory factory = CSFactory.getFactory(properties); client = factory.getClient( userName, StringUtils.EMPTY, password, Locale.US, "PIM", null); String areaPath="sample.com/default/main/sample/us/en/WORKAREA/shared"; String data="{\"Name\": \"Demo\",\"Author\": \"demo author\",\"Company List\": [\"Compnay: Demo Comp1\",\"Compnay: Demo Comp2\",\"Compnay: Demo Comp3\"]}"; String path="sites/sample/us/en/website/sampleproduct/2124.json"; CSVPath fullPath = new CSVPath(areaPath); CSWorkarea area = client.getWorkarea(fullPath, false); CSSimpleFile file = addFile(area, path); //TRYING TO CHANGE THE OWNER OF THE FILE - WHICH WORKS FINE CSIterator csIterator = client.getPrincipalManager().getAllTSUsers(); while (csIterator.hasNext()) { CSUser cs = (CSUser) csIterator.next(); if (cs.getDisplayName().equals("TSDEVL")) { file.setOwner(cs); } } //TRYING TO CHANGE THE MODIFIED BY ATTR OF THE FILE - WHICH FAILS CSBinaryExtendedAttribute csbea=new CSBinaryExtendedAttribute(); csbea.setName("Modified By"); csbea.setValue("TSDEVL".getBytes()); file.setBinaryExtendedAttribute(csbea); InputStream dataStream = IOUtils.toInputStream(data, "UTF-8"); writeDataToFile(file, dataStream); } catch (Exception e) { e.printStackTrace(); } } private static void writeDataToFile(CSSimpleFile file, InputStream dataStream) { OutputStream outputStream; try { outputStream = file.getOutputStream(true); IOUtils.copyLarge(dataStream, outputStream); IOUtils.closeQuietly(outputStream); } catch (Exception e) { e.printStackTrace(); } } private static CSSimpleFile addFile(CSWorkarea area, String path) { CSAreaRelativePath relativePath = new CSAreaRelativePath(path); try { return area.createSimpleFile(relativePath); } catch (Exception e) { e.printStackTrace(); return null; } }
}
Here is the **screenshot for file created **-
and the property of the file -
The ask is - Does CSSimpleFIle / CSFile expose an API through which we can change the Modified by attribute displayed as root today in my workarea?
Kindly let me know if more details required.
Much appreciate your help !
Thank you,
Regards,
TSDEVL0 -
You are pretty much answering your own question. The issue is not CSFile. The issue is that you are running a process as root, which is modifying a file. Thus the modified by attribute is being set to root.
Pretty simple. If you want to change the modified by attribute, then you need ot run th eprocess as someone else.
This is a common complaint, but it is working as designed.
1
Categories
- All Categories
- 109 Developer Announcements
- 49 Articles
- 100 General Questions
- 122 IM Services
- 40 OpenText Hackathon
- 31 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 897 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 122 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- Docker Automation
- LiveSite Content Services (LSCS) REST API
- Single Page Application (SPA) Modules
- TeamSite Add-ons
If you are interested in gaining full access to the content, you can register for a My Support account here.