Publish a WI document via java

Hi,

has anyone successfully added a WI document to the corporate repository using the Java api?

I want to add the personal documents of users to the corporate repository ( no, I do NOT want a workaround :wink: .

I either receive an error when calling

document.publish( … )

or simply cant open the document in Infoview, wich fails with a WIS 30551 Error.

I looked at the infoview sources and the samples, but this didn’t help.

'specially as the samples produce the same error as my code does ^^^

cu,

olli


haupto :de: (BOB member since 2004-04-16)

I once wrote a java app that copied wid files in personal folder of pre-defined user and then used the API to publish the document to corporate repository.

I did not encounter this error. I was using 6.1a at that time.

HTH

Shamit


shamit (BOB member since 2004-07-01)

Hi,

you got some pieces of code?

Would be helpful, as I failed yesterday after a couple of hours trying.
I used this code:



WISession session = null; 
			
	try {
		session = server.openSession( "haupt", PW );
		logger.info( "Loading document." );
		
		WIDocuments docs = session.openAllDocuments( WIDocuments.RT_PERSONAL );
		WIRecordset rs = docs.getRecordset( true );
			
		int count =1;
		while ( !rs.isEOF() ) {
			WIDocument doc = docs.openDocument( rs.getString( "Name" ) );
				
			logger.info( "Opened document " + doc.getName() + " successfully." );
				
			doc.attachCategory( "IT" );
				
			doc.updateCategories();
				
				
										
			String[] cats = doc.getCategoryList();
			if ( cats != null ) {
				for ( int i=0; i<cats.length; i++ ) {
					logger.info( "Categorie: " + cats[i] ); 
				}
			}
										
			String[] groups = { "1", "64", "88" };
			
			doc.publish( doc.getName(), "Dokument", true, groups );
			
			rs.moveNext();	
		}
	} catch ( Exception e ) {
		logger.error( "Crash." , e );
	}

In the end I even failed to set the categor< of the document with this code.

Was surprising, as I was able to insert the doc in the reporsitory ( I checked it in the database … ) and in the first run I could see the doc in infoview, but trying to open it resultet in a 30551 error.

Thanks in advance,

olli


haupto :de: (BOB member since 2004-04-16)

I’ll post the code snippet in evening (thats after 6 hours). I do not see anything wrong with your code.

Can you try doing the same thing manually (thru infoview) and see it it works. i.e.

  1. Create a wid file
  2. Save in you personal folder
  3. Delete from Corporate repo
  4. Open it from personal folder and publish it to corp repo.
  5. Refresh it.

If it works then try doing the same thing with Java code.

That ways you can localize the problem. I.e. you cna ensure that the problem is not related to mismatch of data providers etc.


shamit (BOB member since 2004-07-01)

Hi,

would be neat if you could post your code, so I could maybe track the error down in my code :wink:

cu,

olli


haupto :de: (BOB member since 2004-04-16)

I located that piece of code. Hope it is of some help to you.



    public boolean transferDoctoCorpRepo(WISession sess,String docName,String domain,String []groups)
    {
        try
        {
            System.out.println("Publishing " + docName);
            WIDocument wid = sess.openDocument(docName,WIDocuments.RT_PERSONAL);
            if(wid != null)
            {
                wid.publish(docName,domain,true,groups);
                return true;
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            throw new RuntimeException("Could not upload::"+docName+"::Error::"+ex.toString());
        }
        return false;
    }


The only difference that I could notice (as compared to your code), was use of a recordset for iterations and attaching categories. Rationally spiking, that should not make any difference.

Still give this code a try “as it is”. And let me know if it works.


shamit (BOB member since 2004-07-01)

Thanks,

as I am installing some parts of the server again ( due to upcoming inf 00130 errors ) this will take me some time to test the code, but I’ll let you know about the results.

Thanks so far :slight_smile:

cu,
olli


haupto :de: (BOB member since 2004-04-16)

Hi,

finally it worked. I made a quite simple mistake. The groups ( or users ) have to be set via their name, not the grou/user id.

That was all.

Thanks,

olli


haupto :de: (BOB member since 2004-04-16)