3

我正在尝试使用IBM提供的 Java 程序。请参阅下面的代码。当我尝试编译这个程序时,

C:\Temp>"C:\Program Files (x86)\Java\jdk1.6.0_25\bin\javac.exe" GetOrphanMyFolde
rs.java

我收到一条错误消息

GetOrphanMyFolders.java:96: cannot find symbol
symbol  : variable PropEnum
location: class GetOrphanMyFolders
                                 PropEnum.canBurst      ,
                                 ^
GetOrphanMyFolders.java:97: cannot find symbol
symbol  : variable PropEnum
location: class GetOrphanMyFolders
                                 PropEnum.capabilities   ,
                                 ^

我是Java菜鸟,这个错误的原因是什么?我正在使用的程序在这里

/**
 * Licensed Material - Property of IBM
 * © Copyright IBM Corp. 2012
 *
 * GetOrphanMyFolders.java
 *
 * Description: Technote 1340789 - SDK Sample: How to recover the My Folders of users that no longer exist in the Authentication Provider
 *
 * Tested with: IBM Cognos BI 10.1.1, IBM Java 5.0, Axis 1.4
 *
 */

import java.util.Vector;

import javax.xml.namespace.QName;

import org.apache.axis.client.Stub;
import org.apache.axis.message.SOAPHeaderElement;

import com.cognos.developer.schemas.bibus._3.BaseClass;
import com.cognos.developer.schemas.bibus._3.BiBusHeader;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_PortType;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_ServiceLocator;
import com.cognos.developer.schemas.bibus._3.CopyOptions;
import com.cognos.developer.schemas.bibus._3.PropEnum;
import com.cognos.developer.schemas.bibus._3.QueryOptions;
import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
import com.cognos.developer.schemas.bibus._3.Sort;
import com.cognos.developer.schemas.bibus._3.UpdateActionEnum;
import com.cognos.developer.schemas.bibus._3.XmlEncodedXML;

public class GetOrphanMyFolders
{
    //TODO: change the following variables depending on your installation and setup

    //--- begin changes ----
    private static String dispatcherURL = "http://localhost:9300/p2pd/servlet/dispatch";

    //Change the next three variables to a valid namespace ID as defined in Cognos Configuration and NOT the namespace name
    //Provide a valid user ID and password if Anonymous is disabled
    private static String nameSpaceID   = "Cognos";
    private static String userName      = "admin";
    private static String password      = "password";

    // define where you are copying the orphaned my folders to
    private static String targetLocation = "/content/folder[@name='OrphanedMyFolders']";
    //--- end changes ---

    //Services to be used in the sample
    private ContentManagerService_PortType cmService = null;

    private String[] getAllMyFoldersSearchPaths(String namespaceID)
    {
        String listOfAccountSP [] = null;
        PropEnum props[] = new PropEnum[] {PropEnum.searchPath, PropEnum.defaultName, PropEnum.portalPage};
        Sort sOpt[] = new Sort[]{}; 
        QueryOptions qOpt = new QueryOptions(); 
        try
        {
            // get the template user's Account object. 
            BaseClass template[] = cmService.query(new SearchPathMultipleObject("//folder"), props, sOpt, qOpt);
            listOfAccountSP = new String [template.length];

            for (int x=0;x<template.length;x++)
            {
                if ( template[x].getSearchPath().getValue().indexOf(")/folder[@name='My Folders']")>0 )
                {
                    listOfAccountSP[x]=template[x].getSearchPath().getValue();
                }
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }
        return listOfAccountSP;
    }

    private PropEnum[] getAllPropEnum ()
      {
        PropEnum properties[] = new PropEnum[]{
                 PropEnum.active, 
                 PropEnum.actualCompletionTime,
                 PropEnum.actualExecutionTime ,
                 PropEnum.advancedSettings ,
                 PropEnum.ancestors ,
                 PropEnum.asOfTime ,
                 PropEnum.base ,
                 PropEnum.brsAffineConnections, 
                 PropEnum.brsMaximumProcesses ,
                 PropEnum.brsNonAffineConnections, 
                 PropEnum.burstKey ,
                 PropEnum.businessPhone,             
                 PropEnum.canBurst      ,       
                 PropEnum.capabilities   ,          
                 PropEnum.capacity        ,     
                 PropEnum.closeConnectionCommands,             
                 PropEnum.closeSessionCommands    ,         
                 PropEnum.configuration            , 
                 PropEnum.connections             ,
                 PropEnum.connectionString         ,    
                 PropEnum.consumers             ,
                 PropEnum.contact             ,
                 PropEnum.contactEMail         ,    
                 PropEnum.contentLocale         ,    
                 PropEnum.creationTime           ,  
                 PropEnum.credential             ,
                 PropEnum.credentialNamespaces    ,         
                 PropEnum.credentials             ,
                 PropEnum.cubeContentName          ,   
                 PropEnum.dailyPeriod             ,
                 PropEnum.data             ,
                 PropEnum.dataBlocks        ,     
                 PropEnum.dataSize           ,  
                 PropEnum.dataType            , 
                 PropEnum.defaultDescription   ,          
                 PropEnum.defaultName           ,  
                 PropEnum.defaultOutputFormat    ,         
                 PropEnum.defaultScreenTip        ,     
                 PropEnum.defaultTriggerDescription,
                 PropEnum.deployedObject ,
                 PropEnum.deployedObjectAncestorDefaultNames, 
                 PropEnum.deployedObjectClass ,
                 PropEnum.deployedObjectDefaultName, 
                 PropEnum.deployedObjectStatus      ,       
                 PropEnum.deployedObjectUsage        ,     
                 PropEnum.deploymentOptions           ,  
                 PropEnum.description             ,
                 PropEnum.disabled             ,
                 PropEnum.dispatcherID          ,   
                 PropEnum.dispatcherPath         ,    
                 PropEnum.displaySequence         ,    
                 PropEnum.email             ,
                 PropEnum.endDate            , 
                 PropEnum.endType             ,
                 PropEnum.eventID             ,
                 PropEnum.everyNPeriods        ,     
                 PropEnum.executionFormat        ,     
                 PropEnum.executionLocale         ,    
                 PropEnum.executionPageDefinition  ,           
                 PropEnum.executionPageOrientation  ,           
                 PropEnum.executionPrompt            , 
                 PropEnum.faxPhone             ,
                 PropEnum.format             ,
                 PropEnum.gateway             ,
                 PropEnum.givenName            , 
                 PropEnum.governors             ,
                 PropEnum.hasChildren            , 
                 PropEnum.hasMessage             ,
                 PropEnum.hasPrompts             ,
                 PropEnum.height             ,
                 PropEnum.homePhone           ,  
                 PropEnum.horizontalElementsRenderingLimit,
                 PropEnum.identity ,
                 PropEnum.isolationLevel, 
                 PropEnum.lastConfigurationModificationTime, 
                 PropEnum.lastPage ,
                 PropEnum.loadBalancingMode, 
                 PropEnum.locale ,
                 PropEnum.location, 
                 PropEnum.members ,
                 PropEnum.message ,
                 PropEnum.metadataModel ,
                 PropEnum.mobilePhone ,
                 PropEnum.model ,
                 PropEnum.modelName ,
                 PropEnum.modificationTime ,
                 PropEnum.monthlyAbsoluteDay ,
                 PropEnum.monthlyRelativeDay ,
                 PropEnum.monthlyRelativeWeek ,
                 PropEnum.name ,
                 PropEnum.namespaceFormat ,
                 PropEnum.objectClass ,
                 PropEnum.openConnectionCommands ,
                 PropEnum.openSessionCommands ,
                 PropEnum.options ,
                 PropEnum.output ,
                 PropEnum.owner ,
                 PropEnum.ownerPassport ,
                 PropEnum.packageBase ,
                 PropEnum.page ,
                 PropEnum.pageOrientation ,
                 PropEnum.pagerPhone ,
                 PropEnum.parameters ,
                 PropEnum.parent ,
                 PropEnum.paths ,
                 PropEnum.permissions ,
                 PropEnum.policies ,
                 PropEnum.portalPage ,
                 PropEnum.position ,
                 PropEnum.postalAddress ,
                 PropEnum.printerAddress ,
                 PropEnum.productLocale ,
                 PropEnum.qualifier ,
                 PropEnum.recipients ,
                 PropEnum.recipientsEMail ,
                 PropEnum.related ,
                 PropEnum.replacement ,
                 PropEnum.requestedExecutionTime ,
                 PropEnum.retentions ,
                 PropEnum.rsAffineConnections ,
                 PropEnum.rsMaximumProcesses ,
                 PropEnum.rsNonAffineConnections ,
                 PropEnum.rsQueueLimit ,
                 PropEnum.runAsOwner ,
                 PropEnum.runningState ,
                 PropEnum.runOptions ,
                 PropEnum.screenTip ,
                 PropEnum.searchPath ,
                 PropEnum.searchPathForURL ,
                 PropEnum.sequencing ,
                 PropEnum.serverGroup ,
                 PropEnum.source ,
                 PropEnum.specification ,
                 PropEnum.startAsActive ,
                 PropEnum.startDate ,
                 PropEnum.state ,
                 PropEnum.status ,
                 PropEnum.stepObject ,
                 PropEnum.surname ,
                 PropEnum.target ,
                 PropEnum.taskID ,
                 PropEnum.timeZoneID ,
                 PropEnum.triggerDescription ,
                 PropEnum.triggerName ,
                 PropEnum.type ,
                 PropEnum.unit ,
                 PropEnum.uri ,
                 PropEnum.usage ,
                 PropEnum.user ,
                 PropEnum.userCapabilities ,
                 PropEnum.userCapability ,
                 PropEnum.userName ,
                 PropEnum.version ,
                 PropEnum.verticalElementsRenderingLimit ,
                 PropEnum.viewed ,
                 PropEnum.weeklyFriday ,
                 PropEnum.weeklyMonday ,
                 PropEnum.weeklySaturday ,
                 PropEnum.weeklySunday ,
                 PropEnum.weeklyThursday ,
                 PropEnum.weeklyTuesday ,
                 PropEnum.weeklyWednesday ,
                 PropEnum.width ,
                 PropEnum.yearlyAbsoluteDay, 
                 PropEnum.yearlyAbsoluteMonth, 
                 PropEnum.yearlyRelativeDay ,
                 PropEnum.yearlyRelativeMonth, 
                 PropEnum.yearlyRelativeWeek ,

        };
        return properties;
      }

    private String[][] getAllCIs(String namespaceID)
    {
        String listOfCIs [][] = null;

        String searchPath = "CAMID('"+namespaceID+"')//account";
        PropEnum props[] = new PropEnum[] {PropEnum.searchPath, PropEnum.defaultName, PropEnum.portalPage};
        Sort sOpt[] = new Sort[]{}; 
        QueryOptions qOpt = new QueryOptions(); 
        try
        {
            // get the template user's Account object. 
            BaseClass template[] = cmService.query(new SearchPathMultipleObject(searchPath), props, sOpt, qOpt);
            listOfCIs = new String [2] [template.length];

            for (int x=0;x<template.length;x++)
            {
                    listOfCIs[0][x]=template[x].getSearchPath().getValue();
                    listOfCIs[1][x]=template[x].getDefaultName().getValue();
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }

        return listOfCIs;

    }

    private void moveMF2PF(String path, String targetLocation)
    {
        String userSearchPaths = path ;
        PropEnum props[] = getAllPropEnum();
        String user = path.substring(0, path.indexOf("/folder[@name='My Folders']"));

        try
        {
            //Query the Content Store for all objects in My Folders for user userName
            BaseClass bc[] = cmService.query(new SearchPathMultipleObject(userSearchPaths), props, new Sort[]{}, new QueryOptions());

            if (bc != null && bc.length > 0)
            {
                //copy the folder to Public Folders and rename
                String[] newName={user};
                CopyOptions opt = new CopyOptions();
                opt.setUpdateAction(UpdateActionEnum.replace);
                opt.setRecursive(true);
                cmService.copyRename(bc,new SearchPathSingleObject(targetLocation),newName,opt);
            }
            else
                System.out.println("User " + user+" did not have My Folders. It could be that they have not logged on yet");
        }
        catch (Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }
    }

    /**
     * Establish a connection to Cognos BI and initialize the different services
     */
    private void connectToCognos() 
    {
        ContentManagerService_ServiceLocator cmServiceLocator = new ContentManagerService_ServiceLocator();

        try 
        {
            cmService = cmServiceLocator.getcontentManagerService(new java.net.URL(dispatcherURL));
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }

    /**
     * Logon to Cognos BI using valid credentials information
     */
    private void logon(String nameSpaceID, String userName, String password) 
    {
        StringBuffer credentialXML = new StringBuffer();

        credentialXML.append("<credential>");
        credentialXML.append("<namespace>").append(nameSpaceID).append("</namespace>");
        credentialXML.append("<username>").append(userName).append("</username>");
        credentialXML.append("<password>").append(password).append("</password>");
        credentialXML.append("</credential>");

        String encodedCredentials = credentialXML.toString();
        XmlEncodedXML xmlCredentials = new XmlEncodedXML();
        xmlCredentials.set_value(encodedCredentials);

        try 
        {
            cmService.logon(xmlCredentials, null);
            getSetHeaders();
        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }
    }

    private void getSetHeaders()
    {
        String BiBus_NS = "http://developer.cognos.com/schemas/bibus/3/";
        String BiBus_H = "biBusHeader";

        BiBusHeader CMbibus = null;

        SOAPHeaderElement temp = ((Stub)cmService).getResponseHeader(BiBus_NS, BiBus_H);

        try 
        {
            CMbibus = (BiBusHeader)temp.getValueAsType(new QName (BiBus_NS, BiBus_H));
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }

        if (CMbibus != null)
        {
            ((Stub)cmService).setHeader(BiBus_NS, BiBus_H, CMbibus);
        }
    }

    /**
     * This is the main class, which connects to Cognos BI and calls the
     * method doWork(), containing the specific code for this sample
     */
    public static void main(String args[]) 
    {

        GetOrphanMyFolders mainClass = new GetOrphanMyFolders();

        mainClass.connectToCognos();

        // If Anonymous is disabled, then logon
        if (nameSpaceID.length() > 0) 
        {
            mainClass.logon(nameSpaceID, userName, password);
        }

        //get all the CAMIDs related to the My Folders searchpath
        String[] listOfMyFolders = mainClass.getAllMyFoldersSearchPaths(nameSpaceID);
        String[][] listOfCamIds = mainClass.getAllCIs(nameSpaceID);
        Vector<String> orphanedMyFolders = new Vector<String>();

        // find a my folder that does not have an existing owner from the ldap 
        boolean found = false;
        for (int i = 0; i < listOfMyFolders.length; i++)
        {
            if (listOfMyFolders[i] != null )
            {
                if (listOfMyFolders[i].endsWith("[@name='My Folders']")) 
                {
                    int y = 0;
                    for (y = 0; y < listOfCamIds[0].length - 1; y++) 
                    {
                        String test = listOfCamIds[0][y];
                        if (listOfMyFolders[i].indexOf(test) >= 0) 
                        {
                            found = true;
                        }
                    }
                    if (!found) 
                    {
                        //  String userName = getUserNameFromCamid(listOfMyFolders[i]);
                        System.out.println(listOfMyFolders[i] + " does not have an associated user");
                        orphanedMyFolders.add(listOfMyFolders[i]);
                    }
                    found = false;
                }               
            }
        }

        // Now we need to take the list of orphaned My Folders and move them to the 
        // public folders so that the content can be examined.
        for (int x = 0; x < orphanedMyFolders.size(); x++)
        {
            mainClass.moveMF2PF(orphanedMyFolders.elementAt(x).toString(), targetLocation);
        }
        System.out.println("Done ....");
    }
}
4

4 回答 4

6

问题是 cognos jar 目前是不可见的。因此,编译器无法解析对打包在此 jar 中的类的引用。

您可以在 cognos 安装目录中找到axisCognosClient.jar

 %COGNOS_INSTALL_DIR%/c8/webapps/p2pd/WEB-INF/lib 

编译时将此目录包含在类路径中。此 jar 包含您在 import 语句中引用的所有类。

于 2013-01-31T08:15:25.873 回答
3

这通常是最重要的报告的错误。修复这些将修复其余部分。如果第一个错误看起来像这样: GetOrphanMyFolders.java:19: error: package com.cognos.developer does not exist import com.cognos.developer.*; ^

然后您需要按照一些 IBM 说明下载这些包并将它们添加到您的类路径中。

如果已经下载,请尝试http://www-01.ibm.com/support/docview.wss?uid=swg21343429

于 2013-02-04T21:16:14.177 回答
3

该示例GetOrphanMyFolders.java使用在外部库(即 jars)中定义的类,这些类应该在Cognos 8 SDK(通常在C8_INSTALLATION_DIR/sdk/lib)中可用,我相信您应该寻找cognosClient.jaraxisCognosClient.jar

由于您是 Java 新手,因此使用编译它javac并将外部 jar 添加到类路径中会很麻烦。我建议你使用eclipse

下载/安装后(只需解压缩到您喜欢的任何目录),创建一个,在包下New Java Project添加(复制/粘贴或拖放)。然后查看此问题以了解如何将库添加到项目类路径中。GetOrphanMyFolders.javasrc

这比弄清楚如何做到这一点要容易得多javac -cp

于 2013-02-09T00:14:22.647 回答
2

您正在初始化 PropEnum 类型的属性数组。可能是 PropEnum 没有定义为属性的 canBurst 和功能。

只需尝试删除 {PropEnum.canBurst ,PropEnum.capabilities ,} 到 {PropEnum.canBurst, PropEnum.capabilities,} 之间的空格。空间不应该是问题。

于 2013-02-07T13:33:39.127 回答