for [quote]DocumentRights STARTS NORMAL DISCLAIMERS[/quote]
/*
The code albeit hard coded uses the livelink java api combined
Written in answer for an user at greg's site asking for traversal
of listusers API calltested java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
OJVM Client VM (build 9.0.2.572 cdov, Copyright (c) 1998-2002 Oracle Corp., nojit)
@author K N Nair (appoos@hotmail.com) alias appnair/samalayali
appnair@gmail.com in tektips
Acknowledgement for using printTypeTree as a helper function
Fantastic object tree traversal
Glenn Heying (SCorUser8) Department: Sprint Corporate
SPRINT01 Title: Systems Developer V
E-mail: glenn.heying@mail.sprint.com Phone: (816) 665-9626
All trademarks of OpenText,Sun,Oracle given proper credits
Code can be used for educational purposes only
AND I CANNOT BE HELD RESPONSIBLE IF YOU USE THIS
WITHOUT UNDERSTANDING IT
*/
/*A word about the package create a hierarchy called com/nairkn
and put the source file there and after compilation
execute it by calling java com.nairkn.DocumentRights
Error traps at each stage should be done by looking at
the status of each LAPI call for clarity I have omitted those
*/
package com.nairkn;
import com.opentext.api.*;
import java.util.*; //for our date thing example
public class DocumentRights
{
private static String Server = "localhost"; //livelink host
private static int Port = 4099; //livelink server port see opentext.ini
private static String DFT = ""; //default database file or schema
private static String User = "Admin"; //username
private static String Pass = "livelink"; //passwd
public static void main(String[] args)
{
try
{
Date myDate=new Date();
LLSession session;
LAPI_DOCUMENTS doc;//library object
LLValue value=new LLValue();
session = new LLSession (Server, Port, DFT, User, Pass);
doc = new LAPI_DOCUMENTS (session);
LLValue LLvalueWP=new LLValue();
int volID=0, objID=0,versionID=0;
if (doc.AccessEnterpriseWS(value) == 0)
{
objID = value.toInteger("ID");
volID = value.toInteger("VolumeID");
System.out.println("My objID -->"+objID+" My VolumeID is -->"+volID);
}//if ends
//GetPerms( doc,objID,volID);//for getting eneterprise workspace perms
GetPerms( doc,3462,volID); //3462 in an objid in my enterprise volume
//SetPerms( doc,3462,volID,5348);//manipulating permission bits for groupid=5348
//for objectid=3462
}
catch (Exception e)
{
System.out.println(e.getMessage() );
e.printStackTrace ();
}
} //main ends
/*************HELPERS TO UNDERSTAND LIVELINK DATA STRUCTURES*****************/
/*Bad OOP programming using a bunch of statics very high runtime reqs
not prod worthy [URL unfurl="true"]http://mindprod.com/jgloss/static.html[/URL]
the intent is not performance but iteration of the data structures
encountered */
/*Simple GetPerms Function*/
private static void GetPerms(LAPI_DOCUMENTS doc,int dataid,int volumeid)
{
LLValue rights=new LLValue().setTable();
if (doc.GetObjectRights( volumeid,dataid, rights ) !=0 )
{
System.out.println("This Object Rights I couldnot find");
}
else
{
//printTypeTree(rights ,"*","*");//Uncomment to see the full data structure in its entirety
//printTypeTree(rights.toValue(1).toValue("RIGHTID") ,"*","*");
/*Uncomment above line to see the SECOND row of a zero based index */
System.out.println("Now Printing Who all in livelink gets to see this object");
System.out.println("Well numbers of the people/group actually");
printTypeTree(rights.toValue().toValue("RIGHTID") ,"*","*");
System.out.println("Now Printing the Bitmask permissions of the object passed");
System.out.println("This is the one that shows up in the GUI as SEE,SEE Contents etc");
printTypeTree(rights.toValue().toValue("PERMISSIONS") ,"*","*");
}
}
/*Simple SetPerms Function*/
private static void SetPerms(LAPI_DOCUMENTS doc,int dataid,int volumeid,int userid)
{
/*lets show user for groupid userid how they can set SEE,SEE CONTENTS,MODIFY is 102531 bitmask representation*/
System.out.println("Setting perms SEE & SEE CONTENTS& MODIFY for GroupID or UserID="+userid);
doc.SetObjectRight(volumeid,dataid,doc.RIGHT_UPDATE,userid,102531,0);
System.out.println("Same thing in TRUE BITWISE Fashion");
doc.SetObjectRight(volumeid,dataid,doc.RIGHT_UPDATE,userid,doc.PERM_SEE|doc.PERM_SEECONTENTS|doc.PERM_MODIFY,0);
/*SEE LAPI DOCS ON HOW YOU CAN USE THE BITWISE OR OPERATOR TO MAKE PERMISSION MASKS
FOR EASE OF FOLLOWING I JUST HARDCODE BITMASKED VALUES THE LAST PARAMETER DETERMINES
WHETHER OR NOT PERMISSIONS NEED TO BE PUSHED DOWN TO CHILDREN
NOT A GOOD IDEA TO GO BY NUMBERS AS OT MAY CHANGE BITMASKING AND YOUR CODE WILL
BREAK THEN BITMASK TABLE-NOT AN EXHAUSTIVE LIST
128-NONE
130 -SEE
36995-SEE &SEE CONTENTS
102531-SEE &SEE CONTENTS & MODIFY
233603-SEE &SEE CONTENTS & MODIFY&EDIT ATTRIBUTES
241795-SEE &SEE CONTENTS & MODIFY&EDIT ATTRIBUTES&RESERVE
258179-SEE &SEE CONTENTS & MODIFY&EDIT ATTRIBUTES&RESERVE&DELETE VERSIONS
258187-SEE &SEE CONTENTS & MODIFY&EDIT ATTRIBUTES&RESERVE&DELETE VERSIONS&DELETE
25803-SEE &SEE CONTENTS & MODIFY&EDIT ATTRIBUTES&RESERVE&DELETE VERSIONS&DELETE&EDIT PERMISSIONS
16777215-ALL AND SYSTEM ADMINISTRATION
*/
System.out.println("Let us take out the MODIFY PERMS OUT");
doc.SetObjectRight(volumeid,dataid,doc.RIGHT_UPDATE,userid,doc.PERM_SEE|doc.PERM_SEECONTENTS,0);
/*use this to take out the groups's ACL entry*/
//System.out.println("Let us delete this groups's PERMS OUT");
//doc.SetObjectRight(volumeid,dataid,doc.RIGHT_DELETE,userid,doc.PERM_SEE|doc.PERM_SEECONTENTS,0);
/*ADDING ADMIN USER TO THIS OBJECT*/
System.out.println("Let us ADD ADMIN TO THIS ACL AND NOT GIVE ANY PERMS");
doc.SetObjectRight(volumeid,dataid,doc.RIGHT_ADD,1000,128,0);
}
/****AN EXTREMELY USEFUL HELPER CLASS WHEN YOU WANT TO SEE LLVALUE OBJECTS STARTS****************/
private static void printTypeTree(LLValue inVal, String szSep, String szName) {
System.out.println(szSep + szName + " - " + printLLValueType(inVal.type()) + "\t" + printLLValue(inVal));
if(inVal.type() == LLValue.LL_ASSOC ||
inVal.type() == LLValue.LL_RECORD ||
inVal.type() == LLValue.LL_TABLE) {
LLNameEnumeration enumValue;
enumValue = inVal.enumerateNames();
while(enumValue.hasMoreElements()) {
String elValue = enumValue.nextElement().toString();
printTypeTree(inVal.toValue(elValue), "\t" + szSep, elValue);
}
}
else {
if(inVal.type() == LLValue.LL_LIST) {
for(int i = 0; i < inVal.size(); i++) {
printTypeTree(inVal.toValue(i), "\t" + szSep, "" + i);
}
}
}
}
private static String printLLValue(LLValue llVal)
{
String returnString = "";
switch (llVal.type()) {
case LLValue.LL_BOOLEAN :
returnString = "" + llVal.toBoolean();
break;
case LLValue.LL_DATE :
returnString = llVal.toDate().toString();
break;
case LLValue.LL_DOUBLE :
returnString = "" + llVal.toDouble();
break;
case LLValue.LL_INTEGER :
returnString = "" + llVal.toInteger();
break;
case LLValue.LL_STRING :
returnString = llVal.toString();
break;
default :
break;
}
return returnString;
}
private static String printLLValueType(int iType) {
String returnString = " ";
switch (iType) {
case LLValue.LL_ASSOC :
returnString = "Type is ASSOC";
break;
case LLValue.LL_BOOLEAN :
returnString = "Type is BOOLEAN";
break;
case LLValue.LL_DATE :
returnString = "Type is DATE";
break;
case LLValue.LL_DOUBLE :
returnString = "Type is DOUBLE";
break;
case LLValue.LL_ERROR :
returnString = "Type is ERROR";
break;
case LLValue.LL_INTEGER :
returnString = "Type is INTEGER";
break;
case LLValue.LL_LIST :
returnString = "Type is LIST";
break;
case LLValue.LL_NOTSET :
returnString = "Type is NOTSET";
break;
case LLValue.LL_RECORD :
returnString = "Type is RECORD";
break;
case LLValue.LL_STRING :
returnString = "Type is STRING";
break;
case LLValue.LL_TABLE :
returnString = "Type is TABLE";
break;
case LLValue.LL_UNDEFINED :
returnString = "Type is UNDEFINED";
break;
default :
returnString = "Type is Unknown";
break;
}
return returnString;
}//helper method ends
/****AN EXTREMELY USEFUL HELPER CLASS WHEN YOU WANT TO SEE LLVALUE OBJECTS ENDS************/
}//class ends