2 Replies Latest reply: Oct 29, 2012 3:01 AM by Kuba P. RSS

    How to check if folder exists

    Kuba P.
      Hi,

      I have a custom filter component:
      public class BarcodeMetadataFilter implements FilterImplementor{
      }
      I need to check there if folder exists by xCollectionId value, so I have two qustions:

      1) What service should I call to check if folder exists ?
      2) How to call this service from filter ?

      Kuba
        • 1. Re: How to check if folder exists
          970471
          Call a service such as COLLECTION_GET_INFO. Pass the parameter dCollectionID which should be xCollectionID. If you receive and error, it may mean the folder does not exists. You should check the error (exception) to ensure what it is telling you is that the folder does not exists.

          http://docs.oracle.com/cd/E23943_01/doc.1111/e11011/c07_folders.htm#i1082467

          The following blog post will show you how to execute a service from a filter: http://jonathanhult.com/blog/2012/06/execute-a-service-from-a-java-filter/

          Jonathan
          http://jonathanhult.com
          • 2. Re: How to check if folder exists
            Kuba P.
            Hi Jonathan,

            I have followed tips from your blog but now I have very strange behavior of my filter. After checking if folder exist (calling service COLLECTION_GET_INFO) I got following exception during checkin:
            Calling service COLLECTION_GET_INFO
            Finished calling service COLLECTION_GET_INFO
            Folder exists
            <2012-10-28 22:01:53 CET> <Error> <oracle.ucm.idccs> <UCM-CS-060003> <Zdarzenie wygenerowane przez użytkownika 'weblogic' na hoście 'localhost:16200'.> 
            <2012-10-28 22:01:53 CET> <Error> <oracle.ucm.idccs> <UCM-CS-000001> <wyjątek ogólny
            intradoc.common.ServiceException: !csUnableToCheckIn,ADF_Best_Practices!csCheckinPrimaryFileMissing
            Without calling COLLECTION_GET_INFO service my filter works fine.
            This is my code:
            public class BarcodeMetadataFilter implements FilterImplementor{
                 
                 public int doFilter(Workspace workspace, DataBinder binder, ExecutionContext ctx) throws DataException, ServiceException {
                      
                      String targetCollectionId  = null;
                      String defaultCollectionID = binder.getLocal("xCollectionID");
                      
                      String barcodeStr = binder.getLocal("xBarCode");
                      
                      if(barcodeStr != null && barcodeStr.length() != 0){
                           // Extract collectionID
                           targetCollectionId  = getCollectionIdFromBarcodeString(barcodeStr);
                           
                           // Check if folder exists
                           boolean exists = executeService(binder, (Service)ctx, targetCollectionId);
                           
                           if(!exists){ // if folder not exists - set default collectionId
                                binder.putLocal("xCollectionID", defaultCollectionID);
                                System.out.println("Folder doesn't exists");
                           }else{
                                binder.putLocal("xCollectionID", targetCollectionId);
                                System.out.println("Folder exists");
                           }
                           
                      }else{// If bracode string doesn't exists - set default collectionId
                           binder.putLocal("xCollectionID", defaultCollectionID);
                           System.out.println("Barcode string not found");
                      }     
                      
                      return CONTINUE;
                 }
                 
                 /**
                  * Extracts folder id from long barcode string 
                  */
                 private String getCollectionIdFromBarcodeString(String barcodeStr){
                      return barcodeStr.substring(0, barcodeStr.indexOf(";"));
                 }
                 
                 /**
                  * Check if folder exists 
                  */
                 public boolean executeService(DataBinder binder, Service service, String collectionId) throws ServiceException {
                      
                      boolean exists = false;
                      UserData userData = service.getUserData();
                      
                      binder.putLocal("IdcService", "COLLECTION_GET_INFO");
                      binder.putLocal("hasCollectionID", "true");
                      binder.putLocal("dCollectionID", collectionId);
                      
                      try {
                           
                           System.out.println("Calling service COLLECTION_GET_INFO");
                           service.getRequestImplementor().executeServiceTopLevelSimple(binder, "COLLECTION_GET_INFO", userData);
                           System.out.println("Finished calling service COLLECTION_GET_INFO");
                           exists = true;
                           
                      } catch (DataException e) {
                           e.printStackTrace();
                           throw new ServiceException("Something went wrong executing service COLLECTION_GET_INFO", e);
                      }
                      
                      return exists;
                 }
            And JUnit test
            public class BarcodeMetadataTest extends BaseTest {
            
                 @Test
                 public void test() throws IOException, IdcClientException {
                      
                      DataBinder binder = idcClient.createBinder();
                      binder.putLocal ("IdcService", "CHECKIN_UNIVERSAL");
                      binder.putLocal("dID", "12345");
                      binder.putLocal("dDocTitle", "Test_File");
                      binder.putLocal("dDocName", "ADF_Best_Practices");
                      binder.putLocal("dDocType", "DOCUMENT");
                      binder.putLocal("dSecurityGroup", "Public");
                      binder.putLocal("xCollectionID", "755573512059000401");
                      binder.putLocal("xBarCode", "755573512059000202;ABCD");
                      binder.addFile ("primaryFile", new TransferFile(new File("/home/ADF Best Practices.pdf")));
                      idcClient.sendRequest (userContext, binder);
                 }
            }
            Kuba