• Updating metadata for documents

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #49532  by Deepti
 
Hi,

I am using 6.3.4 community version of OpenKM

I have query regarding update of the metadata for documents after they are uploaded to OpenKM.
My scenario:

There is a metadata group added with some properties in OpenKM and some documents were uploaded to OpenKM by setting the required metadata for the documents.

Now I have added 1 more property to the metadata group, so for the new documents getting uploaded I will set this property also and metadata is updated.

I want this metadata property updated for the old documents as well, how do i go about it?
Two approaches

1. Written a stored procedure which updates ‘USER’ metadata property with the ‘author’ of the old documents. This was tested and the corresponding updated metadata can be seen for the documents in the OpenKM application UI.
Stored procedure as below
Code: Select all
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`()
BEGIN
DECLARE finished INTEGER default 0;
DECLARE docId varchar(100) default "";
DECLARE maxId INTEGER;

DECLARE curs CURSOR FOR select NDV_PARENT from okmdb.okm_node_document_version as T2 where not exists ( select * from okmdb.okm_node_property as T1 where T1.NPG_NODE = T2.NDV_PARENT and T1.NPG_NAME='okp:OPENKM.USER');
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
    
  OPEN curs;
    select max(NPG_ID) + 1 into maxId from okmdb.okm_node_property;
    insertRecords:LOOP 
		FETCH curs into docId;
        if finished = 1 then
			leave insertRecords;
        end if;
	insert into okmdb.okm_node_property (NPG_ID, NPG_GROUP, NPG_NAME, NPG_VALUE, NPG_NODE) 
    values (maxId, 'okg:OPENKM','okp:OPENKM.USER', (select NDV_AUTHOR from okmdb.okm_node_document_version where NDV_PARENT = docId), docId);
    set maxId = maxId + 1;
    END LOOP insertRecords;
    CLOSE curs;
END
Is this the correct way of doing it? Do i need to update any other tables?

2. There is also an API given by OpenKM to update the metadata property for a document. I have done a POC of this API and it successfully updated the property for the given document in the DB table, but this updated metadata is not visible in OpenKM application UI.
Why with the 2nd approach I am not able to see the updated metadata? This does not show the updated metadata after restarting the server also.
Sample code:
Code: Select all
public class OpenKMTest {
    public static void main(String[] args) {
        String host = "http://localhost:8180/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
        
       try {        
               	List<FormElement> fElements = new ArrayList<>();
                Input user = new Input();
                user.setName("okg:OPENKM.USER");
                user.setValue("MyUser");
                fElements.add(user);
                ws.setPropertyGroupProperties("4ac33d91-9bd2-413f-a4c3-1fb1079f4e5b","okg:OPENKM", fElements);
                System.out.println("Done");
            } catch (Exception e) {
                e.printStackTrace();
            }
        } 
 }
 #49535  by saulhidalgo
 
Hello Deepti.

I would definitely suggest to take the approach number 2. However, you are not using the API Properly.

The idea would be to do a Search by Property Value, getting a list of all documents with the new field not assigned. Please, take a look at the following documentation.

https://docs.openkm.com/kcenter/view/ok ... pertyValue

You can even run the code directly in the OpenKM interpreter.

Then simply you assign the desired value to the metadata of the document.

https://docs.openkm.com/kcenter/view/ok ... tiesSimple

I hope it helps. In case you need any advice or guide, you can contact me.

Mail: saulhidalgoaular@gmail.com.
Skype: saulhidalgoaular@outlook.com

Best Regards.
Saul Hidalgo.
 #49545  by jllort
 
The problem of updating metadata from the database side is the search engine has not been updated about the change in the node and you will not be able to search by these metadata values.

From api you must doing two actions:
adding group ( missing in your code )
setting properties

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.