]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5678: Merging with latest trunk sources.
authorRichard Millet <remillet@berkeley.edu>
Fri, 2 Aug 2013 02:28:42 +0000 (19:28 -0700)
committerRichard Millet <remillet@berkeley.edu>
Fri, 2 Aug 2013 02:28:42 +0000 (19:28 -0700)
60 files changed:
1  2 
pom.xml
services/JaxRsServiceProvider/pom.xml
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/acquisition/3rdparty/build.xml
services/acquisition/3rdparty/nuxeo-platform-cs-acquisition/pom.xml
services/acquisition/3rdparty/pom.xml
services/authorization-mgt/import/pom.xml
services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java
services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java
services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java
services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationSeed.java
services/authorization-mgt/import/src/main/resources/log4j.properties
services/blob/3rdparty/build.xml
services/blob/3rdparty/pom.xml
services/build.xml
services/collectionobject/3rdparty/build.xml
services/collectionobject/3rdparty/pom.xml
services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java
services/common/pom.xml
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java
services/concept/3rdparty/build.xml
services/concept/3rdparty/pom.xml
services/config/pom.xml
services/contact/3rdparty/build.xml
services/contact/3rdparty/pom.xml
services/group/3rdparty/build.xml
services/group/3rdparty/pom.xml
services/intake/3rdparty/build.xml
services/intake/3rdparty/pom.xml
services/loanin/3rdparty/build.xml
services/loanin/3rdparty/pom.xml
services/loanout/3rdparty/build.xml
services/loanout/3rdparty/pom.xml
services/location/3rdparty/build.xml
services/location/3rdparty/nuxeo-platform-cs-location/pom.xml
services/location/3rdparty/pom.xml
services/media/3rdparty/build.xml
services/media/3rdparty/pom.xml
services/movement/3rdparty/build.xml
services/movement/3rdparty/pom.xml
services/movement/client/pom.xml
services/note/3rdparty/build.xml
services/note/3rdparty/pom.xml
services/objectexit/3rdparty/build.xml
services/objectexit/3rdparty/pom.xml
services/organization/3rdparty/build.xml
services/organization/3rdparty/pom.xml
services/person/3rdparty/build.xml
services/person/3rdparty/pom.xml
services/place/3rdparty/build.xml
services/place/3rdparty/pom.xml
services/pom.xml
services/report/3rdparty/build.xml
services/report/3rdparty/pom.xml
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java
services/taxonomy/3rdparty/build.xml
services/taxonomy/3rdparty/pom.xml
services/vocabulary/3rdparty/build.xml
services/vocabulary/3rdparty/pom.xml

diff --cc pom.xml
index 49eac8883a12e4503951c2c28dca1ba598c9ee9c,a6391e985eb1435452941542af5b17056c43d453..f877bc8fa3cef8073b18bf6e13404c2be5eb72e1
+++ b/pom.xml
@@@ -56,9 -56,9 +56,9 @@@
                        </snapshots>\r
                </repository>\r
                <repository>\r
-                       <id>libs-releases-local</id>\r
-                       <name>libs-releases-local</name>\r
+                       <id>libs-release-local</id>\r
+                       <name>libs-release-local</name>\r
 -                      <url>http://source.collectionspace.org:8081/artifactory/libs-release-local</url>\r
 +                      <url>http://nightly.collectionspace.org:8081/artifactory/libs-release-local</url>\r
                        <snapshots>\r
                                <enabled>false</enabled>\r
                        </snapshots>\r
                        <dependency>\r
                                <groupId>org.slf4j</groupId>\r
                                <artifactId>slf4j-api</artifactId>\r
--                              <version>1.5.8</version>\r
++                              <version>1.6.1</version>\r
                        </dependency>\r
                        <dependency>\r
                                <groupId>org.slf4j</groupId>\r
                                <artifactId>slf4j-log4j12</artifactId>\r
--                              <version>1.5.8</version>\r
++                              <version>1.6.1</version>\r
                        </dependency>\r
              <dependency>\r
                  <groupId>org.testng</groupId>\r
index ca004c0c8f025db0bb93013c064388332fe984cc,ad0ce694fa1a70c21ff63b7e6c1709f587e4f65b..e5f77c3aa35e84d0ad1587801145791aa0d3b45d
              <groupId>log4j</groupId>\r
              <artifactId>log4j</artifactId>\r
              <version>1.2.14</version>\r
 -                      <scope>provided</scope>\r
 +            <scope>provided</scope>\r
          </dependency>\r
--        <!-- somewhere dependency is added 1.5.8 unnecessarily -->\r
++        <!-- somewhere dependency is added 1.6.1 unnecessarily -->\r
          <dependency>\r
              <groupId>org.slf4j</groupId>\r
              <artifactId>slf4j-simple</artifactId>\r
--            <version>1.5.8</version>\r
++            <version>1.6.1</version>\r
              <scope>test</scope>\r
          </dependency>\r
          <dependency>\r
              <groupId>org.slf4j</groupId>\r
              <artifactId>jcl-over-slf4j</artifactId>\r
--            <version>1.5.8</version>\r
++            <version>1.6.1</version>\r
              <scope>test</scope>\r
          </dependency>\r
          <!-- CollectionSpace dependencies -->\r
Simple merge
index fd1d87a29bcad42f7c1a60b604e4d9070edb37f8,e9345e0ef2322afea2e48c0cbf75c08b556ab144..79c679c2e752c60af97f46fe8f456a02530262eb
          <dependency>\r
              <groupId>org.slf4j</groupId>\r
              <artifactId>slf4j-api</artifactId>\r
--            <version>1.6.1</version>\r
          </dependency>\r
          <dependency>\r
              <groupId>org.slf4j</groupId>\r
              <artifactId>slf4j-log4j12</artifactId>\r
--            <version>1.6.1</version>\r
          </dependency>\r
          <!-- CollectionSpace dependencies -->\r
          <dependency>\r
                                                                                                <!-- This should be (Needs testing):\r
                                                                                                <argument>${jboss.server.cspace}</argument>\r
                                                                                                -->\r
--                        <argument>${basedir}/../../common/src/main</argument>\r
++                        <argument>${env.CSPACE_JEESERVER_HOME}</argument>\r
                          <argument>-edir</argument>\r
                          <argument>${basedir}/target</argument>\r
                      </arguments>\r
index 0b348e3edae5915aec5f07446bf92dd8ac2c4a0e,0b348e3edae5915aec5f07446bf92dd8ac2c4a0e..949b7ba8addd5e03be85c8ef5eceefe532da1108
@@@ -36,12 -36,12 +36,16 @@@ import org.apache.commons.cli.GnuParser
  import org.apache.commons.cli.Options;
  import org.apache.commons.cli.ParseException;
  import org.collectionspace.services.authorization.driver.AuthorizationSeedDriver;
++import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
  
  /**
   * ImportAuthz imports default permissions and roles for a tenant(s)
   * @authorF
   */
  public class ImportAuthz {
++      private static final Logger logger = LoggerFactory.getLogger(ImportAuthz.class);
  
        final private static String OPTIONS_GENERATE_ONLY = "generate only";
      final private static String OPTIONS_USERNAME = "username";
@@@ -52,8 -52,8 +56,8 @@@
      final private static String OPTIONS_HELP = "help";
  
      final private static String MSG_SEPARATOR = "--";
--    final private static String LOGGING_SEPARATOR_HEAD = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>";
--    final private static String LOGGING_SEPARATOR_TAIL = "<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
++    final private static String LOGGING_SEPARATOR_HEAD = "[>>>>>>>>>>>>>>>>>>>>>>>>>>>>]";
++    final private static String LOGGING_SEPARATOR_TAIL = "[<<<<<<<<<<<<<<<<<<<<<<<<<<<<]";
      final private static String LOGGING_INFO_PREFIX = "[INFO] ";
      final private static String LOGGING_ERROR_PREFIX = "[ERROR] ";
  
@@@ -78,7 -78,7 +82,7 @@@
      }
      
      private static void logInfo(String infoMessage) {
--      logInfo(System.out, infoMessage);
++      logger.info(infoMessage);
      }
      
      private static void logConfiguration(String user,
              AuthorizationSeedDriver driver = new AuthorizationSeedDriver(
                      user, password, tenantBinding, exportDir);
              driver.generate();
++            logger.info("Finished processing all tenant bindings files and generating all AuthN/AuthZ metadata.");
              //
              // If the "-g" option was set, then we will NOT seed the AuthZ tables.  Instead, we'll
              // just merge the prototypical tenant bindings and generate the permissions XML output
index f69f8dc9fd2d5988868c4175482f5d2a3e232d3a,f69f8dc9fd2d5988868c4175482f5d2a3e232d3a..700ea66d0c240a26f32842b1574b937fa49b961b
@@@ -141,7 -141,7 +141,7 @@@ public class AuthorizationSeedDriver 
  //            authzSeed.seedPermissions(exportDir + File.separator + PERMISSION_FILE,
  //                    exportDir + File.separator + PERMISSION_ROLE_FILE);
              if (logger.isDebugEnabled()) {
--                logger.debug("authorization seeding completed ");
++                logger.debug("Authorization seeding completed.");
              }
          } catch (Exception ex) {
              if (status != null) {
              em.getTransaction().begin();
              
                AuthorizationStore authzStore = new AuthorizationStore();
++              logger.info("Seeding Roles metadata to database.");
                for (Role role : authzGen.getDefaultRoles()) {
                        try {
                                authzStore.store(em, role);
                        }
                }
        
++              logger.info("Seeding Permissions metadata to database.");
                for (Permission perm : authzGen.getDefaultPermissions()) { //FIXME: REM - 3/27/2012 - If we change the CSID of permissions to something like a refname, then we need to check for existing perms just like we did above for roles
                    authzStore.store(em, perm);
                }
        
++              logger.info("Seeding Permissions/Roles relationships metadata to database.");
                List<PermissionRoleRel> permRoleRels = new ArrayList<PermissionRoleRel>();
                for (PermissionRole pr : authzGen.getDefaultPermissionRoles()) {
                    PermissionRoleUtil.buildPermissionRoleRel(em, pr, SubjectType.ROLE, permRoleRels, false /*not for delete*/);
                em.getTransaction().commit();
                em.close();
                if (logger.isInfoEnabled()) {
--                  logger.info("Authroization metata persisted.");
++                  logger.info("All Authroization metata persisted.");
                }
          } catch (Exception e) {
              if (em != null && em.getTransaction().isActive()) {
index a56db9cac8a6a300db7ddde66ac194935db9032d,97e6714cadd19b68d352854111c473c2fedb4970..892ffbacf31501d833d626e7314bdad6a9cf6c78
@@@ -27,22 -27,22 +27,15 @@@ import java.io.File
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import java.util.ArrayList;
--import java.util.Date;
  import java.util.Hashtable;
  import java.util.List;
--import java.util.UUID;
  import javax.xml.bind.JAXBContext;
  import javax.xml.bind.Marshaller;
--import org.collectionspace.services.authorization.perms.ActionType;
  import org.collectionspace.services.authorization.perms.Permission;
--import org.collectionspace.services.authorization.perms.EffectType;
--import org.collectionspace.services.authorization.perms.PermissionAction;
--import org.collectionspace.services.authorization.PermissionActionUtil;
  import org.collectionspace.services.authorization.PermissionRole;
  import org.collectionspace.services.authorization.PermissionValue;
  import org.collectionspace.services.authorization.perms.PermissionsList;
  import org.collectionspace.services.authorization.PermissionsRolesList;
--import org.collectionspace.services.client.RoleClient;
  import org.collectionspace.services.client.TenantClient;
  import org.collectionspace.services.authorization.Role;
  import org.collectionspace.services.authorization.RoleValue;
@@@ -67,7 -68,9 +61,9 @@@ public class AuthorizationGen 
      final public static boolean AUTHZ_IS_ENTITY_PROXY = false;
      
      final public static String TENANT_MGMNT_ID = "0";
 -
 +    
+       private static final boolean USE_APP_GENERATED_BINDINGS = true;
+     
      final Logger logger = LoggerFactory.getLogger(AuthorizationGen.class);
      private List<Permission> tenantMgmntPermList = new ArrayList<Permission>();
      private List<PermissionRole> tenantMgmntPermRoleList = new ArrayList<PermissionRole>();
        private List<Role> allRoleList;
  
      public void initialize(String tenantRootDirPath) throws Exception {
+       ServicesConfigReaderImpl servicesConfigReader = new ServicesConfigReaderImpl(tenantRootDirPath);
+         servicesConfigReader.read(USE_APP_GENERATED_BINDINGS);        
+         Boolean useAppGeneratedBindings = servicesConfigReader.getConfiguration().isUseAppGeneratedTenantBindings();
          TenantBindingConfigReaderImpl tenantBindingConfigReader =
                  new TenantBindingConfigReaderImpl(tenantRootDirPath);
-         tenantBindingConfigReader.read();
+         tenantBindingConfigReader.read(useAppGeneratedBindings);
 -        tenantBindings = tenantBindingConfigReader.getTenantBindings();
 +        // Note that we build permissions for all tenants, whether or not they are marked create disabled.
 +        // This is a hack until we can correctly run an incremental import.
 +        tenantBindings = tenantBindingConfigReader.getTenantBindings(
 +                                                      TenantBindingConfigReaderImpl.INCLUDE_CREATE_DISABLED_TENANTS);
          cspaceTenantMgmntRole = buildTenantMgmntRole();
  
          if (logger.isDebugEnabled()) {
index 3665301301386016016b33dd23ee173bed667340,3665301301386016016b33dd23ee173bed667340..fa59a890e3c6a67cc2742594011fe95eedbb77dc
@@@ -92,20 -92,20 +92,29 @@@ public class AuthorizationSeed 
       */
      public void seedPermissions(List<Permission> permList, List<PermissionRole> permRoleList)
              throws Exception {
++      if (logger.isInfoEnabled() == true) {
++              logger.info("Started seeding Spring Security Tables...");
++      }
++      int factor = permRoleList.size();
++      int permsToSeed = permList.size() * factor;
++      int permsSeeded = 0;
++      
          for (Permission p : permList) {
--            if (logger.isTraceEnabled()) {
--                logger.trace("adding permission for res=" + p.getResourceName() +
--                        " for tenant=" + p.getTenantId());
--            }
++              if (permsSeeded++ % 10 == 0 && logger.isInfoEnabled()) {
++                      logger.info(String.format("Seeded %d permissions of %d...", permsSeeded * factor, permsToSeed));
++              }
              for (PermissionRole pr : permRoleList) {
                  if (pr.getPermission().get(0).getPermissionId().equals(p.getCsid())) {
                        AuthorizationCommon.addPermissionsForUri(p, pr);
                  }
              }
          }
++        
++        if (logger.isInfoEnabled() == true) {
++              logger.info("Finished seeding Spring Security Tables.");
++        }
      }
      
--    
      /**
       * getAction is a convenience method to get corresponding action for
       * given ActionType
index 79746b946e6dc75107dd034e868491cfcd7fe78a,b245250850b79708ee89cc34b42e397cae92f98d..f39efb3dbd0cfbfd217f1023d897aee59d42c6e5
@@@ -2,32 -2,30 +2,38 @@@ log4j.rootLogger=debug, stdout, 
  \r
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
--\r
  # Pattern to output the caller's file name and line number.\r
  log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
  \r
++log4j.appender.commandline=org.apache.log4j.ConsoleAppender\r
++log4j.appender.commandline.target=System.err\r
++log4j.appender.commandline.layout=org.apache.log4j.PatternLayout\r
++log4j.appender.commandline.layout.ConversionPattern=%d %p: %m%n\r
++\r
  log4j.appender.R=org.apache.log4j.RollingFileAppender\r
  log4j.appender.R.File=target/test-client.log\r
--\r
  log4j.appender.R.MaxFileSize=100KB\r
--# Keep one backup file\r
  log4j.appender.R.MaxBackupIndex=1\r
--\r
  log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
  log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
  \r
  #packages\r
--log4j.logger.org.collectionspace=DEBUG\r
  log4j.logger.org.collectionspace.services.authorization.spring=INFO\r
 +# log4j.logger.org.collectionspace.services.common.authorization_mgt.AuthorizationStore=TRACE\r
  log4j.logger.org.apache=INFO\r
  log4j.logger.httpclient=INFO\r
  log4j.logger.org.jboss.resteasy=INFO\r
  log4j.logger.hibernate=WARN\r
  log4j.logger.org.hibernate=WARN\r
  log4j.logger.org.hibernate.cfg=WARN\r
--log4j.logger.org.springframework=INFO\r
++log4j.logger.org.springframework=WARN\r
  log4j.logger.ch.elca.el4j.services.xmlmerge=INFO\r
  log4j.logger.com.sun.xml.bind.v2.runtime=DEBUG\r
--log4j.logger.javax.persistence.PersistenceException=TRACE\r
++log4j.logger.javax.persistence.PersistenceException=ERROR\r
++\r
++#\r
++# Logging for the command line tool that generates the Service artifacts\r
++#\r
++log4j.logger.org.collectionspace=INFO, commandline\r
++log4j.additivity.org.collectionspace=false\r
 +\r
Simple merge
Simple merge
Simple merge
index b64d98db119c4b761b6be425379107f86a73883c,b64d98db119c4b761b6be425379107f86a73883c..fffc22727b4ba35aecbbe0adff5dbbdf7316896e
@@@ -15,5 -15,5 +15,9 @@@ public class CommonAPI 
      public static String showRelations_QP = "showRelations";\r
      public static String showSiblings_QP = "showSiblings";\r
      public static String showAllRelations_QP = "showAllRelations";\r
++    \r
++      public static final String GENERATE_BUNDLES = "core";\r
++      public static final String GENERATE_BINDINGS = "delta";\r
++\r
  }\r
  \r
index 374afd33e9cfa2ed712866269b91cea833cd1fbb,7551c8f4b3e4aa2e58b91fc2c6d9d50e73de2404..6af2af462f648082cb85b58eb365b41be2b1e945
              <artifactId>spring-security-acl</artifactId>\r
              <version>${spring.security.version}</version>\r
              <scope>provided</scope>\r
-         </dependency>        \r
+         </dependency>\r
 -        <dependency>\r
 -                  <groupId>org.collectionspace.services</groupId>\r
 -              <artifactId>org.collectionspace.services.common-api</artifactId>\r
 -                      <version>${project.version}</version>\r
 -        </dependency>\r
      </dependencies>\r
  \r
      <repositories>\r
index 166758222b4307606619b98c24211e18b5079863,a451d55005814acec58280964f088636c3eaf502..ec7d8b500370346fb37df8906afef5175d844083
@@@ -50,57 -52,59 +52,58 @@@ import org.slf4j.LoggerFactory
  
  /**
   * ServicesConfigReader reads service layer specific configuration
-- *
-- * $LastChangedRevision: $
-- * $LastChangedDate: $
++ * 
++ * $LastChangedRevision: $ $LastChangedDate: $
   */
--public class TenantBindingConfigReaderImpl
--        extends AbstractConfigReaderImpl<List<TenantBindingType>> {
-       
 -    final private static String TENANT_BINDINGS_ERROR = "Tenant bindings error(s) for tenant: ";
 -    final private static String TENANT_BINDINGS_DELTA_FILENAME = JEEServerDeployment.TENANT_BINDINGS_FILENAME_PREFIX + ".delta.xml";
 -    final private static String MERGED_SUFFIX = ".merged.xml";
++public class TenantBindingConfigReaderImpl extends AbstractConfigReaderImpl<List<TenantBindingType>> {
 +      final public static boolean INCLUDE_CREATE_DISABLED_TENANTS = true;
 +      final public static boolean EXCLUDE_CREATE_DISABLED_TENANTS = false;
-       
-     final private static String TENANT_BINDINGS_ERROR = "Tenant bindings error: ";
-     final private static String TENANT_BINDINGS_ROOTDIRNAME = "tenants";
-     final private static String TENANT_BINDINGS_FILENAME_PREFIX = "tenant-bindings";
-     final private static String TENANT_BINDINGS_PROTOTYPE_FILENAME = TENANT_BINDINGS_FILENAME_PREFIX + "-proto.xml";
-     final private static String TENANT_BINDINGS_DELTA_FILENAME = TENANT_BINDINGS_FILENAME_PREFIX + ".delta.xml";
-     final private static String MERGED_SUFFIX = ".merged.xml";
-     
-     final Logger logger = LoggerFactory.getLogger(TenantBindingConfigReaderImpl.class);
-     private List<TenantBindingType> tenantBindingTypeList;
-     //tenant id, tenant binding, for tenants not marked as createDisabled
-     private Hashtable<String, TenantBindingType> enabledTenantBindings =
-             new Hashtable<String, TenantBindingType>();
-     //tenant id, tenant binding
-     private Hashtable<String, TenantBindingType> allTenantBindings =
-             new Hashtable<String, TenantBindingType>();
-     //repository domains
-     private Hashtable<String, RepositoryDomainType> domains =
-             new Hashtable<String, RepositoryDomainType>();
-     //tenant-qualified servicename, service binding
-     private Hashtable<String, ServiceBindingType> serviceBindings =
-             new Hashtable<String, ServiceBindingType>();
-     //tenant-qualified service object name to service name, service binding
-     private Hashtable<String, ServiceBindingType> docTypes =
-             new Hashtable<String, ServiceBindingType>();
-     public TenantBindingConfigReaderImpl(String serverRootDir) {
-         super(serverRootDir);
-     }
-     @Override
-     public String getFileName() {
-         return TENANT_BINDINGS_DELTA_FILENAME;
-     }
-     
++
++      final private static String TENANT_BINDINGS_ERROR = "Tenant bindings error(s) for tenant: ";
++      final private static String TENANT_BINDINGS_DELTA_FILENAME = JEEServerDeployment.TENANT_BINDINGS_FILENAME_PREFIX
++                      + ".delta.xml";
++      final private static String MERGED_SUFFIX = ".merged.xml";
+       private static final String NO_SERVICE_BINDINGS_FOUND_ERR = "No Service bindings found.";
 -    
 -    private static final Logger logger = LoggerFactory.getLogger(TenantBindingConfigReaderImpl.class);
 -    private List<TenantBindingType> tenantBindingTypeList;
 -    //tenant id, tenant binding
 -    private Hashtable<String, TenantBindingType> tenantBindings =
 -            new Hashtable<String, TenantBindingType>();
 -    //repository domains
 -    private Hashtable<String, RepositoryDomainType> domains =
 -            new Hashtable<String, RepositoryDomainType>();
 -    //tenant-qualified servicename, service binding
 -    private Hashtable<String, ServiceBindingType> serviceBindings =
 -            new Hashtable<String, ServiceBindingType>();
 -
 -    //tenant-qualified service object name to service name, service binding
 -    private Hashtable<String, ServiceBindingType> docTypes =
 -            new Hashtable<String, ServiceBindingType>();
 -
 -
 -    public TenantBindingConfigReaderImpl(String serverRootDir) {
 -        super(serverRootDir);
 -    }
 -
 -    @Override
 -    public String getFileName() {
 -        return TENANT_BINDINGS_DELTA_FILENAME;
 -    }
 -    
 -    private String getFileName(String tenantName, boolean useAppGeneratedBindings) {
 -      String result = getFileName();
 -      
 -      if (useAppGeneratedBindings == true) {
 -              result = tenantName + "-" + result;
 -      }
 -      
 -      return result;
 -    }
 -    
 -    
++
++      private static final Logger logger = LoggerFactory.getLogger(TenantBindingConfigReaderImpl.class);
++      private List<TenantBindingType> tenantBindingTypeList;
++      // tenant id, tenant binding, for tenants not marked as createDisabled
++      private Hashtable<String, TenantBindingType> enabledTenantBindings = new Hashtable<String, TenantBindingType>();
++      // tenant id, tenant binding
++      private Hashtable<String, TenantBindingType> allTenantBindings = new Hashtable<String, TenantBindingType>();
++      // repository domains
++      private Hashtable<String, RepositoryDomainType> domains = new Hashtable<String, RepositoryDomainType>();
++      // tenant-qualified servicename, service binding
++      private Hashtable<String, ServiceBindingType> serviceBindings = new Hashtable<String, ServiceBindingType>();
++
++      // tenant-qualified service object name to service name, service binding
++      private Hashtable<String, ServiceBindingType> docTypes = new Hashtable<String, ServiceBindingType>();
++
++      public TenantBindingConfigReaderImpl(String serverRootDir) {
++              super(serverRootDir);
++      }
++
++      @Override
++      public String getFileName() {
++              return TENANT_BINDINGS_DELTA_FILENAME;
++      }
++
++      private String getFileName(String tenantName, boolean useAppGeneratedBindings) {
++              String result = getFileName();
++
++              if (useAppGeneratedBindings == true) {
++                      result = tenantName + "-" + result;
++              }
++
++              return result;
++      }
++
        protected File getTenantsRootDir() {
                File result = null;
                String errMessage = null;
                try {
-                       String tenantsRootPath = getConfigRootDir() + File.separator + TENANT_BINDINGS_ROOTDIRNAME;
 -                      String tenantsRootPath = getConfigRootDir() + File.separator + JEEServerDeployment.TENANT_BINDINGS_ROOTDIRNAME;
++                      String tenantsRootPath = getConfigRootDir() + File.separator
++                                      + JEEServerDeployment.TENANT_BINDINGS_ROOTDIRNAME;
                        File tenantsRootDir = new File(tenantsRootPath);
                        if (tenantsRootDir.exists() == true) {
                                result = tenantsRootDir;
                                }
                        }
                } catch (IOException e) {
--                      // Log this exception, but continue anyway.  Caller should handle the null result gracefully.
++                      // Log this exception, but continue anyway. Caller should handle the
++                      // null result gracefully.
                        logger.equals(e);
                }
--              
++
                if (errMessage != null) {
                        logger.error(errMessage);
                }
--              
++
                return result;
        }
--      
--    /*
--     * Take the directory of the prototype bindings and the directory of the delta bindings.  Merge the two and create (replace) a file
--     * named "tenant-bindings.xml"
--     */
++
++      /*
++       * Take the directory of the prototype bindings and the directory of the
++       * delta bindings. Merge the two and create (replace) a file named
++       * "tenant-bindings.xml"
++       */
  
        private InputStream merge(File srcFile, File deltaFile) throws IOException {
                InputStream result = null;
--              try {                                           
++              try {
                        FileInputStream srcStream = new FileInputStream(srcFile);
                        FileInputStream deltaStream = new FileInputStream(deltaFile);
--                      InputStream[] inputStreamArray = {srcStream, deltaStream};                      
--                      
++                      InputStream[] inputStreamArray = { srcStream, deltaStream };
++
                        Configurer configurer = new AttributeMergeConfigurer();
                        result = new ConfigurableXmlMerge(configurer).merge(inputStreamArray);
                } catch (Exception e) {
--                      logger.error("Could not merge tenant configuration delta file: " +
--                                      deltaFile.getCanonicalPath(), e);
++                      logger.error("Could not merge tenant configuration delta file: " + deltaFile.getCanonicalPath(), e);
                }
                //
--              // Try to save the merge output to a file that is suffixed with ".merged.xml" in the same directory
++              // Try to save the merge output to a file that is suffixed with
++              // ".merged.xml" in the same directory
                // as the delta file.
                //
                if (result != null) {
                        File outputDir = deltaFile.getParentFile();
--                      String mergedFileName = outputDir.getAbsolutePath() + File.separator +
-                               TenantBindingConfigReaderImpl.TENANT_BINDINGS_FILENAME_PREFIX + MERGED_SUFFIX;                  
 -                                      JEEServerDeployment.TENANT_BINDINGS_FILENAME_PREFIX + MERGED_SUFFIX;                    
++                      String mergedFileName = outputDir.getAbsolutePath() + File.separator
++                                      + JEEServerDeployment.TENANT_BINDINGS_FILENAME_PREFIX + MERGED_SUFFIX;
                        File mergedOutFile = new File(mergedFileName);
                        try {
                                FileUtils.copyInputStreamToFile(result, mergedOutFile);
                        } catch (IOException e) {
--                              logger.warn("Could not create a copy of the merged tenant configuration at: " +
--                                              mergedFileName, e);
++                              logger.warn("Could not create a copy of the merged tenant configuration at: " + mergedFileName, e);
                        }
--                      result.reset(); //reset the stream even if the file create failed.
++                      result.reset(); // reset the stream even if the file create failed.
                }
  
                return result;
        }
  
--    @Override
-     public void read() throws Exception {
 -    public void read(boolean useAppGeneratedBindings) throws Exception {
--      String tenantsRootPath = getTenantsRootDir().getAbsolutePath();
-         read(tenantsRootPath);
 -        read(tenantsRootPath, useAppGeneratedBindings);
--    }
--
--    @Override
-     public void read(String tenantRootDirPath) throws Exception {
 -    public void read(String tenantRootDirPath, boolean useAppGeneratedBindings) throws Exception {
--        File tenantsRootDir = new File(tenantRootDirPath);
--        if (tenantsRootDir.exists() == false) {
--              throw new Exception("Cound not find tenant bindings root directory: " +
--                              tenantRootDirPath);
--        }
-         File protoBindingsFile = new File(tenantRootDirPath + File.separator +
-                       TENANT_BINDINGS_PROTOTYPE_FILENAME);
--        
--        List<File> tenantDirs = getDirectories(tenantsRootDir);
-         tenantBindingTypeList = readTenantConfigs(protoBindingsFile, tenantDirs);
 -        tenantBindingTypeList = readTenantConfigs(new File(tenantRootDirPath), tenantDirs, useAppGeneratedBindings);
 -        if (tenantBindingTypeList == null || tenantBindingTypeList.size() < 1) {
 -              throw new Exception(NO_SERVICE_BINDINGS_FOUND_ERR);
 -        }
--        
--        for (TenantBindingType tenantBinding : tenantBindingTypeList) {
-               if(allTenantBindings.get(tenantBinding.getId()) != null) {
-                       TenantBindingType tenantBindingOld = allTenantBindings.get(tenantBinding.getId());
 -              if (tenantBindings.get(tenantBinding.getId()) != null) {
 -                      TenantBindingType tenantBindingOld = tenantBindings.get(tenantBinding.getId());
--                logger.error("Ignoring duplicate binding definition for tenant id=" 
--                              + tenantBinding.getId()
--                        + " existing name=" + tenantBindingOld.getName()
--                        + " conflicting (ignored) name=" + tenantBinding.getName());
--                continue;
-               }
-               allTenantBindings.put(tenantBinding.getId(), tenantBinding);
-               if(!tenantBinding.isCreateDisabled()) {
-               enabledTenantBindings.put(tenantBinding.getId(), tenantBinding);
-               } else {
--              }
 -            tenantBindings.put(tenantBinding.getId(), tenantBinding);
--            readDomains(tenantBinding);
--            readServiceBindings(tenantBinding);
--            if (logger.isInfoEnabled()) {
--                logger.info("Finished reading tenant bindings for tenant id=" + tenantBinding.getId()
--                        + " name=" + tenantBinding.getName());
-               if(tenantBinding.isCreateDisabled())
-                       logger.info("Tenant tenant id={} is marked createDisabled.", tenantBinding.getId());
--            }
--        }
--    }
--    
--    /*
--     * Take the directory of the prototype bindings and the directory of the delta bindings.  Merge the two and create (replace) a file
--     * named "tenant-bindings.xml"
--     *
--      private static String merge(String original, String patch) {
--              InputStream result = null;
--              try {
--                      Configurer configurer = new AttributeMergeConfigurer();
--                      
--                      
--                      FileInputStream ins1 = new FileInputStream(".\\src\\main\\resources\\File1.xml");
--                      FileInputStream ins2 = new FileInputStream(".\\src\\main\\resources\\File2.xml");
--                      InputStream[] inputStreamArray = {ins1, ins2};                  
--                      
--                      result = new ConfigurableXmlMerge(configurer).merge(inputStreamArray);
--//                    result = new ConfigurableXmlMerge(configurer).merge(new String[] {original, patch});
--              } catch (Exception e) {
--                      // TODO Auto-generated catch block
--                      e.printStackTrace();
++      @Override
++      public void read(boolean useAppGeneratedBindings) throws Exception {
++              String tenantsRootPath = getTenantsRootDir().getAbsolutePath();
++              read(tenantsRootPath, useAppGeneratedBindings);
++      }
++
++      @Override
++      public void read(String tenantRootDirPath, boolean useAppGeneratedBindings) throws Exception {
++              File tenantsRootDir = new File(tenantRootDirPath);
++              if (tenantsRootDir.exists() == false) {
++                      throw new Exception("Cound not find tenant bindings root directory: " + tenantRootDirPath);
                }
--              File mergedOutFile = new File(".\\target\\merged.xml");
--              try {
--                      FileUtils.copyInputStreamToFile(result, mergedOutFile);
--              } catch (IOException e) {
--                      // TODO Auto-generated catch block
--                      e.printStackTrace();
++
++              List<File> tenantDirs = getDirectories(tenantsRootDir);
++              tenantBindingTypeList = readTenantConfigs(new File(tenantRootDirPath), tenantDirs, useAppGeneratedBindings);
++              if (tenantBindingTypeList == null || tenantBindingTypeList.size() < 1) {
++                      throw new Exception(NO_SERVICE_BINDINGS_FOUND_ERR);
                }
  
--              return null;
++              for (TenantBindingType tenantBinding : tenantBindingTypeList) {
++                      if (allTenantBindings.get(tenantBinding.getId()) != null) {
++                              TenantBindingType tenantBindingOld = allTenantBindings.get(tenantBinding.getId());
++                              logger.error("Ignoring duplicate binding definition for tenant id=" + tenantBinding.getId()
++                                              + " existing name=" + tenantBindingOld.getName() + " conflicting (ignored) name="
++                                              + tenantBinding.getName());
++                              continue;
++                      }
++                      allTenantBindings.put(tenantBinding.getId(), tenantBinding);
++                      if (!tenantBinding.isCreateDisabled()) {
++                              enabledTenantBindings.put(tenantBinding.getId(), tenantBinding);
++                      } else {
++                      }
++                      readDomains(tenantBinding);
++                      readServiceBindings(tenantBinding);
++                      if (logger.isInfoEnabled()) {
++                              logger.info("Finished reading tenant bindings for tenant id=" + tenantBinding.getId() + " name="
++                                              + tenantBinding.getName());
++                              if (tenantBinding.isCreateDisabled())
++                                      logger.info("Tenant tenant id={} is marked createDisabled.", tenantBinding.getId());
++                      }
++              }
        }
--      */
--    
++
++      /*
++       * Take the directory of the prototype bindings and the directory of the
++       * delta bindings. Merge the two and create (replace) a file named
++       * "tenant-bindings.xml"
++       * 
++       * private static String merge(String original, String patch) { InputStream
++       * result = null; try { Configurer configurer = new
++       * AttributeMergeConfigurer();
++       * 
++       * 
++       * FileInputStream ins1 = new
++       * FileInputStream(".\\src\\main\\resources\\File1.xml"); FileInputStream
++       * ins2 = new FileInputStream(".\\src\\main\\resources\\File2.xml");
++       * InputStream[] inputStreamArray = {ins1, ins2};
++       * 
++       * result = new ConfigurableXmlMerge(configurer).merge(inputStreamArray); //
++       * result = new ConfigurableXmlMerge(configurer).merge(new String[]
++       * {original, patch}); } catch (Exception e) { // TODO Auto-generated catch
++       * block e.printStackTrace(); } File mergedOutFile = new
++       * File(".\\target\\merged.xml"); try {
++       * FileUtils.copyInputStreamToFile(result, mergedOutFile); } catch
++       * (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
++       * }
++       * 
++       * return null; }
++       */
++
        /**
--     * Merge and read the prototype bindsings with each tenant specific bindings delta to create the final
--     * tenant bindings.
--     *
--     * @param protoBindingsFile - The prototypical bindings file.
--     * @param tenantDirList - The list of tenant directories containing tenant specific bindings
--     * @return A list of tenant bindings.
--     * @throws IOException Signals that an I/O exception has occurred.
--     */
-     List<TenantBindingType> readTenantConfigs(File protoBindingsFile, List<File> tenantDirList) throws IOException {
-               List<TenantBindingType> result = new ArrayList<TenantBindingType>();            
 -    List<TenantBindingType> readTenantConfigs(File protoBindingsDir, List<File> tenantDirList, boolean useAppGeneratedBindings) throws IOException {
++       * Merge and read the prototype bindsings with each tenant specific bindings
++       * delta to create the final tenant bindings.
++       * 
++       * @param protoBindingsFile
++       *            - The prototypical bindings file.
++       * @param tenantDirList
++       *            - The list of tenant directories containing tenant specific
++       *            bindings
++       * @return A list of tenant bindings.
++       * @throws IOException
++       *             Signals that an I/O exception has occurred.
++       */
++      List<TenantBindingType> readTenantConfigs(File protoBindingsDir, List<File> tenantDirList,
++                      boolean useAppGeneratedBindings) throws IOException {
+               List<TenantBindingType> result = new ArrayList<TenantBindingType>();
 -                              
++
                //
                // Iterate through a list of directories.
                //
                for (File tenantDir : tenantDirList) {
                        boolean found = false;
                        String errMessage = null;
-                       File configFile = new File(tenantDir.getAbsoluteFile() + File.separator + getFileName());
-                       if (configFile.exists() == true) {
-                       InputStream tenantBindingsStream = this.merge(protoBindingsFile, configFile);
-                       TenantBindingConfig tenantBindingConfig = null;
-                       try {
-                                       tenantBindingConfig = (TenantBindingConfig) parse(tenantBindingsStream,
-                                                       TenantBindingConfig.class);
-                       } catch (Exception e) {
-                               logger.error("Could not parse the merged tenant bindings.", e);
-                       }
-                               if (tenantBindingConfig != null) {
-                                       TenantBindingType binding = tenantBindingConfig.getTenantBinding();
-                                       if (binding != null) {
-                                               result.add(binding);
-                                               found = true;
-                                               if (logger.isInfoEnabled() == true) {
-                                                       logger.info("Parsed tenant configureation for: " + binding.getDisplayName());
 -                      
++
+                       File tenantBindingsProtoFile = null;
 -                      String tenantName = tenantDir.getName(); // By convention, the directory name should be the tenant name
++                      String tenantName = tenantDir.getName();        // By convention, the
++                                                                                                              // directory name should
++                                                                                                              // be the tenant name
+                       if (useAppGeneratedBindings == true) {
 -                              tenantBindingsProtoFile = new File(protoBindingsDir.getAbsolutePath() + File.separator + tenantName +
 -                                              "-" + JEEServerDeployment.TENANT_BINDINGS_PROTOTYPE_FILENAME);
++                              tenantBindingsProtoFile = new File(protoBindingsDir.getAbsolutePath() + File.separator + tenantName
++                                              + "-" + JEEServerDeployment.TENANT_BINDINGS_PROTOTYPE_FILENAME);
+                       } else {
 -                      tenantBindingsProtoFile = new File(protoBindingsDir + File.separator +
 -                                      JEEServerDeployment.TENANT_BINDINGS_PROTOTYPE_FILENAME);                                
++                              tenantBindingsProtoFile = new File(protoBindingsDir + File.separator
++                                              + JEEServerDeployment.TENANT_BINDINGS_PROTOTYPE_FILENAME);
+                       }
 -                      
++
+                       if (tenantBindingsProtoFile.exists() == true) {
 -                              File configFile = new File(tenantDir.getAbsoluteFile() + File.separator + getFileName(tenantName, useAppGeneratedBindings));
++                              File configFile = new File(tenantDir.getAbsoluteFile() + File.separator
++                                              + getFileName(tenantName, useAppGeneratedBindings));
+                               if (configFile.exists() == true) {
 -                              InputStream tenantBindingsStream = this.merge(tenantBindingsProtoFile, configFile);
 -                              TenantBindingConfig tenantBindingConfig = null;
 -                              try {
++                                      InputStream tenantBindingsStream = this.merge(tenantBindingsProtoFile, configFile);
++                                      TenantBindingConfig tenantBindingConfig = null;
++                                      try {
+                                               tenantBindingConfig = (TenantBindingConfig) parse(tenantBindingsStream,
+                                                               TenantBindingConfig.class);
 -                              } catch (Exception e) {
 -                                      logger.error("Could not parse the merged tenant bindings.", e);
 -                              }
++                                      } catch (Exception e) {
++                                              logger.error("Could not parse the merged tenant bindings.", e);
++                                      }
+                                       if (tenantBindingConfig != null) {
+                                               TenantBindingType binding = tenantBindingConfig.getTenantBinding();
+                                               if (binding != null) {
+                                                       result.add(binding);
+                                                       found = true;
+                                                       if (logger.isInfoEnabled() == true) {
+                                                               logger.info("Parsed tenant configureation for: " + binding.getDisplayName());
+                                                       }
+                                               } else {
+                                                       errMessage = "Cound not parse the tentant bindings in: ";
                                                }
                                        } else {
-                                               errMessage = "Cound not parse the tentant bindings in: ";
 -                                              errMessage = "Could not parse the tenant bindings file: ";                              
++                                              errMessage = "Could not parse the tenant bindings file: ";
                                        }
                                } else {
-                                       errMessage = "Could not parse the tenant bindings file: ";                              
 -                                      errMessage = "Expected to, but could not, find the tenant delta configuration file: " + configFile.getAbsolutePath();
++                                      errMessage = "Expected to, but could not, find the tenant delta configuration file: "
++                                                      + configFile.getAbsolutePath();
                                }
                        } else {
-                               errMessage = "Cound not find a tenant configuration file: ";
 -                              errMessage = "Expected to, but could not, find the tenant proto configuration file: " + tenantBindingsProtoFile.getAbsolutePath();
++                              errMessage = "Expected to, but could not, find the tenant proto configuration file: "
++                                              + tenantBindingsProtoFile.getAbsolutePath();
                        }
 -                      
++
                        if (found == false) {
                                if (logger.isErrorEnabled() == true) {
                                        errMessage = errMessage != null ? errMessage : TENANT_BINDINGS_ERROR;
                                }
                        }
                } // else-for
--              
++
++              return result;
++      }
++
++      private void readDomains(TenantBindingType tenantBinding) throws Exception {
++              for (RepositoryDomainType domain : tenantBinding.getRepositoryDomain()) {
++                      String key = getTenantQualifiedIdentifier(tenantBinding.getId(), domain.getName());
++                      domains.put(key, domain);
++              }
++      }
++
++      private void readServiceBindings(TenantBindingType tenantBinding) throws Exception {
++              for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
++                      String key = getTenantQualifiedServiceName(tenantBinding.getId(), serviceBinding.getName());
++                      if (key == null) {
++                              continue;
++                      }
++                      serviceBindings.put(key, serviceBinding);
++
++                      if (serviceBinding != null) {
++                              ServiceObjectType objectType = serviceBinding.getObject();
++                              if (objectType != null) {
++                                      String docType = objectType.getName();
++                                      String docTypeKey = getTenantQualifiedIdentifier(tenantBinding.getId(), docType);
++                                      docTypes.put(docTypeKey, serviceBinding);
++                              }
++                      }
++                      if (logger.isTraceEnabled()) {
++                              logger.trace("readServiceBindings() added service " + " name=" + key + " workspace="
++                                              + serviceBinding.getName());
++                      }
++              }
++      }
++
++      @Override
++      public List<TenantBindingType> getConfiguration() {
++              return tenantBindingTypeList;
++      }
++
++      /**
++       * getTenantBindings returns all the tenant bindings read from configuration
++       * 
++       * @return
++       */
++      public Hashtable<String, TenantBindingType> getTenantBindings() {
++              return getTenantBindings(EXCLUDE_CREATE_DISABLED_TENANTS);
++      }
++
++      /**
++       * getTenantBindings returns all the tenant bindings read from configuration
++       * 
++       * @return
++       */
++      public Hashtable<String, TenantBindingType> getTenantBindings(boolean includeDisabled) {
++              return includeDisabled ? allTenantBindings : enabledTenantBindings;
++      }
++
++      /**
++       * getTenantBinding gets tenant binding for given tenant
++       * 
++       * @param tenantId
++       * @return
++       */
++      public TenantBindingType getTenantBinding(String tenantId) {
++              return allTenantBindings.get(tenantId);
++      }
++
++      /**
++       * getRepositoryDomain gets repository domain configuration for the given
++       * name
++       * 
++       * @param domainName
++       * @return
++       */
++      public RepositoryDomainType getRepositoryDomain(String domainName) {
++              return domains.get(domainName.trim());
++      }
++
++      /**
++       * getRepositoryDomain gets repository domain configuration for the given
++       * service and given tenant id
++       * 
++       * @param tenantId
++       * @param serviceName
++       * @return
++       */
++      public RepositoryDomainType getRepositoryDomain(String tenantId, String serviceName) {
++              ServiceBindingType serviceBinding = getServiceBinding(tenantId, serviceName);
++              if (serviceBinding == null) {
++                      throw new IllegalArgumentException("no service binding found for " + serviceName + " of tenant with id="
++                                      + tenantId);
++              }
++              String repoDomain = serviceBinding.getRepositoryDomain();
++              if (repoDomain == null) {
++                      if (logger.isTraceEnabled()) {
++                              logger.trace("No repository domain configured for " + serviceName + " of tenant with id=" + tenantId);
++                      }
++                      return null;
++              }
++              String key = this.getTenantQualifiedIdentifier(tenantId, repoDomain.trim());
++              return domains.get(key);
++      }
++
++      /**
++       * getServiceBinding gets service binding for given tenant for a given
++       * service
++       * 
++       * @param tenantId
++       * @param serviceName
++       * @return
++       */
++      public ServiceBindingType getServiceBinding(String tenantId, String serviceName) {
++              String key = getTenantQualifiedServiceName(tenantId, serviceName);
++              return serviceBindings.get(key);
++      }
++
++      /**
++       * getServiceBinding gets service binding for given tenant for a given
++       * service
++       * 
++       * @param tenantId
++       * @param docType
++       * @return
++       */
++      public ServiceBindingType getServiceBindingForDocType(String tenantId, String docType) {
++              String key = getTenantQualifiedIdentifier(tenantId, docType);
++              return docTypes.get(key);
++      }
++
++      /**
++       * getServiceBinding gets service binding for given tenant for a given
++       * service
++       * 
++       * @param tenantId
++       * @param serviceName
++       * @return
++       */
++      public List<ServiceBindingType> getServiceBindingsByType(String tenantId, String serviceType) {
++              List<String> serviceTypes = new ArrayList<String>(1);
++              serviceTypes.add(serviceType);
++              return getServiceBindingsByType(tenantId, serviceTypes);
++      }
++
++      /**
++       * getServiceBindingsByType gets service bindings for a given tenant for the
++       * services that fall within a supplied set of service type(s)
++       * 
++       * @param tenantId
++       * @param serviceTypes
++       * @return
++       */
++      public List<ServiceBindingType> getServiceBindingsByType(String tenantId, List<String> serviceTypes) {
++              ArrayList<ServiceBindingType> list = null;
++              TenantBindingType tenant = allTenantBindings.get(tenantId);
++              if (tenant != null) {
++                      for (ServiceBindingType sb : tenant.getServiceBindings()) {
++                              if (serviceTypes.contains(sb.getType())) {
++                                      if (list == null) {
++                                              list = new ArrayList<ServiceBindingType>();
++                                      }
++                                      list.add(sb);
++                              }
++                      }
++              }
++              return list;
++      }
++
++      /**
++       * @param tenantId
++       * @param serviceName
++       * @return the properly qualified service name
++       */
++      public static String getTenantQualifiedServiceName(String tenantId, String serviceName) {
++              String result = null;
++
++              if (serviceName != null) {
++                      if (logger.isDebugEnabled() == true) {
++                              logger.debug(String.format(" * tenant:serviceBindings '%s'", serviceName));
++                              System.out.println(String.format(" * tenant:serviceBindings '%s'", serviceName)); // Debug only
++                      }
++                      result = getTenantQualifiedIdentifier(tenantId, serviceName.toLowerCase());
++              }
++
                return result;
        }
--    
--    private void readDomains(TenantBindingType tenantBinding) throws Exception {
--        for (RepositoryDomainType domain : tenantBinding.getRepositoryDomain()) {
--              String key = getTenantQualifiedIdentifier(tenantBinding.getId(),
--                              domain.getName());
--            domains.put(key, domain);
--        }
--    }
--
--    private void readServiceBindings(TenantBindingType tenantBinding) throws Exception {
--        for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
--            String key = getTenantQualifiedServiceName(tenantBinding.getId(),
--                    serviceBinding.getName());
 -            if (key == null) {
 -              continue;
 -            }
--            serviceBindings.put(key, serviceBinding);
--
--            if (serviceBinding!=null){
--                ServiceObjectType objectType = serviceBinding.getObject();
-                 if (objectType!=null){
 -                if (objectType != null) {
--                    String docType = objectType.getName();
--                    String docTypeKey = getTenantQualifiedIdentifier(tenantBinding.getId(), docType);
--                    docTypes.put(docTypeKey, serviceBinding);
--                }
--            }
--            if (logger.isTraceEnabled()) {
--                logger.trace("readServiceBindings() added service "
--                        + " name=" + key
--                        + " workspace=" + serviceBinding.getName());
--            }
--        }
--    }
--
--    @Override
--    public List<TenantBindingType> getConfiguration() {
--        return tenantBindingTypeList;
--    }
--
--    /**
--     * getTenantBindings returns all the tenant bindings read from configuration
--     * @return
--     */
--    public Hashtable<String, TenantBindingType> getTenantBindings() {
-         return getTenantBindings(EXCLUDE_CREATE_DISABLED_TENANTS);
-     }
-     /**
-      * getTenantBindings returns all the tenant bindings read from configuration
-      * @return
-      */
-     public Hashtable<String, TenantBindingType> getTenantBindings(boolean includeDisabled) {
-         return includeDisabled?allTenantBindings:enabledTenantBindings;
 -        return tenantBindings;
--    }
--
--    /**
--     * getTenantBinding gets tenant binding for given tenant
--     * @param tenantId
--     * @return
--     */
--    public TenantBindingType getTenantBinding(
--            String tenantId) {
-         return allTenantBindings.get(tenantId);
 -        return tenantBindings.get(tenantId);
--    }
--
--    /**
--     * getRepositoryDomain gets repository domain configuration for the given name
--     * @param domainName
--     * @return
--     */
--    public RepositoryDomainType getRepositoryDomain(String domainName) {
--        return domains.get(domainName.trim());
--    }
--
--    /**
--     * getRepositoryDomain gets repository domain configuration for the given service
--     * and given tenant id
--     * @param tenantId
--     * @param serviceName
--     * @return
--     */
--    public RepositoryDomainType getRepositoryDomain(String tenantId, String serviceName) {
--        ServiceBindingType serviceBinding = getServiceBinding(tenantId, serviceName);
--        if (serviceBinding == null) {
--            throw new IllegalArgumentException("no service binding found for " + serviceName
--                    + " of tenant with id=" + tenantId);
--        }
--        String repoDomain = serviceBinding.getRepositoryDomain(); 
--        if (repoDomain == null) {
--            if (logger.isTraceEnabled()) {
--                logger.trace("No repository domain configured for " + serviceName
--                        + " of tenant with id=" + tenantId);
--            }
--            return null;
--        }
--        String key = this.getTenantQualifiedIdentifier(tenantId, repoDomain.trim());
--        return domains.get(key);
--    }
--
--    /**
--     * getServiceBinding gets service binding for given tenant for a given service
--     * @param tenantId
--     * @param serviceName
--     * @return
--     */
--    public ServiceBindingType getServiceBinding(
--            String tenantId, String serviceName) {
--        String key = getTenantQualifiedServiceName(tenantId, serviceName);
--        return serviceBindings.get(key);
--    }
--
--    /**
--     * getServiceBinding gets service binding for given tenant for a given service
--     * @param tenantId
--     * @param docType
--     * @return
--     */
--    public ServiceBindingType getServiceBindingForDocType (String tenantId, String docType) {
--        String key = getTenantQualifiedIdentifier(tenantId, docType);
--        return docTypes.get(key);
--    }
--
--    /**
--     * getServiceBinding gets service binding for given tenant for a given service
--     * @param tenantId
--     * @param serviceName
--     * @return
--     */
--    public List<ServiceBindingType> getServiceBindingsByType(
--            String tenantId, String serviceType) {
--      List<String> serviceTypes = new ArrayList<String>(1);
--      serviceTypes.add(serviceType);
--      return getServiceBindingsByType(tenantId, serviceTypes);
--    }
--    /**
--     * getServiceBindingsByType gets service bindings for a given tenant
--     * for the services that fall within a supplied set of service type(s)
--     * @param tenantId
--     * @param serviceTypes
--     * @return
--     */
--    public List<ServiceBindingType> getServiceBindingsByType(
--            String tenantId, List<String> serviceTypes) {
--        ArrayList<ServiceBindingType> list = null;
-         TenantBindingType tenant = allTenantBindings.get(tenantId);
 -        TenantBindingType tenant = tenantBindings.get(tenantId);
--        if (tenant != null) {
--            for (ServiceBindingType sb : tenant.getServiceBindings()) {
--                if (serviceTypes.contains(sb.getType())) {
--                    if (list == null) {
--                        list = new ArrayList<ServiceBindingType>();
--                    }
--                    list.add(sb);
--                }
--            }
--        }
--        return list;
--    }
--
--    /**
--     * @param tenantId
--     * @param serviceName
--     * @return the properly qualified service name
--     */
-     public static String getTenantQualifiedServiceName(
-             String tenantId, String serviceName) {
- //        return tenantId + "." + serviceName.toLowerCase();
-         return getTenantQualifiedIdentifier(tenantId, serviceName.toLowerCase());
 -    public static String getTenantQualifiedServiceName(String tenantId, String serviceName) {
 -      String result = null;
 -      
 -      if (serviceName != null) {
 -              logger.debug(String.format(" * tenant:serviceBindings '%s'", serviceName));
 -              System.out.println(String.format(" * tenant:serviceBindings '%s'", serviceName)); // Debug only
 -              return getTenantQualifiedIdentifier(tenantId, serviceName.toLowerCase());
 -      }
 -      
 -      return result;
--    }
--
--    public static String getTenantQualifiedIdentifier(String tenantId, String identifier) {
--        return tenantId + "." + identifier;
--    }
--    /**
--     * Sets properties in the passed list on the local properties for this TenantBinding.
--     * Note: will only set properties not already set on the TenantBinding.
--     * 
--     * @param propList
--     * @param propagateToServices If true, recurses to set set properties 
--     *                        on the associated services.
--     */
--    public void setDefaultPropertiesOnTenants(List<PropertyItemType> propList,
--            boolean propagateToServices) {
--        // For each tenant, set properties in list that are not already set
--        if (propList == null || propList.isEmpty()) {
--            return;
--        }
-         for (TenantBindingType tenant : allTenantBindings.values()) {
 -        for (TenantBindingType tenant : tenantBindings.values()) {
--            for (PropertyItemType prop : propList) {
--                TenantBindingUtils.setPropertyValue(tenant,
--                        prop, TenantBindingUtils.SET_PROP_IF_MISSING);
--            }
--            if (propagateToServices) {
--                TenantBindingUtils.propagatePropertiesToServices(tenant,
--                        TenantBindingUtils.SET_PROP_IF_MISSING);
--            }
--        }
--    }
--
--    public String getResourcesDir(){
--        return getConfigRootDir() + File.separator + RESOURCES_DIR_NAME;
--    }
--    
--    
--    /**
--     * Returns a list of tenant identifiers (tenant IDs).
--     * 
--     * @return a list of tenant IDs
--     */
--    public List<String> getTenantIds() {
-       return getTenantIds(EXCLUDE_CREATE_DISABLED_TENANTS);
-     }
-     /**
-      * Returns a list of tenant identifiers (tenant IDs).
-      * 
-      * @return a list of tenant IDs
-      */
-     public List<String> getTenantIds(boolean includeDisabled) {
--        List<String> tenantIds = new ArrayList<String>();
--        String tenantId;
-         Hashtable<String, TenantBindingType> tenantBindings = getTenantBindings(includeDisabled);
 -        Hashtable<String, TenantBindingType> tenantBindings = getTenantBindings();
--        if (tenantBindings != null && !tenantBindings.isEmpty()) {
--            Enumeration keys = tenantBindings.keys();
--            while (keys.hasMoreElements()) {
--                tenantId = (String) keys.nextElement();
--                if (Tools.notBlank(tenantId)) {
--                    tenantIds.add(tenantId);
--                }
--            }
--        }
--        return tenantIds;
--    }
++
++      public static String getTenantQualifiedIdentifier(String tenantId, String identifier) {
++              return tenantId + "." + identifier;
++      }
++
++      /**
++       * Sets properties in the passed list on the local properties for this
++       * TenantBinding. Note: will only set properties not already set on the
++       * TenantBinding.
++       * 
++       * @param propList
++       * @param propagateToServices
++       *            If true, recurses to set set properties on the associated
++       *            services.
++       */
++      public void setDefaultPropertiesOnTenants(List<PropertyItemType> propList, boolean propagateToServices) {
++              // For each tenant, set properties in list that are not already set
++              if (propList == null || propList.isEmpty()) {
++                      return;
++              }
++              for (TenantBindingType tenant : allTenantBindings.values()) {
++                      for (PropertyItemType prop : propList) {
++                              TenantBindingUtils.setPropertyValue(tenant, prop, TenantBindingUtils.SET_PROP_IF_MISSING);
++                      }
++                      if (propagateToServices) {
++                              TenantBindingUtils.propagatePropertiesToServices(tenant, TenantBindingUtils.SET_PROP_IF_MISSING);
++                      }
++              }
++      }
++
++      public String getResourcesDir() {
++              return getConfigRootDir() + File.separator + RESOURCES_DIR_NAME;
++      }
++
++      /**
++       * Returns a list of tenant identifiers (tenant IDs).
++       * 
++       * @return a list of tenant IDs
++       */
++      public List<String> getTenantIds() {
++              return getTenantIds(EXCLUDE_CREATE_DISABLED_TENANTS);
++      }
++
++      /**
++       * Returns a list of tenant identifiers (tenant IDs).
++       * 
++       * @return a list of tenant IDs
++       */
++      public List<String> getTenantIds(boolean includeDisabled) {
++              List<String> tenantIds = new ArrayList<String>();
++              String tenantId;
++              Hashtable<String, TenantBindingType> tenantBindings = getTenantBindings(includeDisabled);
++              if (tenantBindings != null && !tenantBindings.isEmpty()) {
++                      Enumeration keys = tenantBindings.keys();
++                      while (keys.hasMoreElements()) {
++                              tenantId = (String) keys.nextElement();
++                              if (Tools.notBlank(tenantId)) {
++                                      tenantIds.add(tenantId);
++                              }
++                      }
++              }
++              return tenantIds;
++      }
  }
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index dc2b5b3f8923309bb31ef149afc5ad49525545bf,30b7e97624a7878913d9c7f44ea22241fafb48ff..f7a4eaf694abbe8d161668258cc05216a1a8cd0e
@@@ -63,10 -44,8 +63,11 @@@ import org.collectionspace.services.Rep
  import org.collectionspace.services.report.ReportsCommon;
  import org.collectionspace.services.client.PoxPayloadIn;
  import org.collectionspace.services.client.PoxPayloadOut;
 +import org.collectionspace.services.client.ReportClient;
  import org.collectionspace.services.common.ServiceMain;
+ import org.collectionspace.services.common.api.JEEServerDeployment;
 +import org.collectionspace.services.common.api.FileTools;
 +import org.collectionspace.services.common.api.Tools;
  import org.collectionspace.services.common.config.ConfigReader;
  import org.collectionspace.services.common.context.ServiceContext;
  import org.collectionspace.services.common.document.BadRequestException;
@@@ -210,60 -176,20 +211,60 @@@ public class ReportDocumentModelHandle
                                repoClient.releaseRepositorySession(ctx, repoSession);
                        }
                }
 -              return buildReportResponse(csid, params, reportFileName);
 +              
 +              return buildReportResult(csid, params, reportFileNameProperty, outMimeType.toString(), outReportFileName);
 +      }
 +      
 +      private void setParamsFromContext(Map<String, Object> params, InvocationContext invContext) {
 +              InvocationContext.Params icParams = invContext.getParams();
 +              if(icParams!= null) {
 +                      List<InvocationContext.Params.Param> icParamList = icParams.getParam();
 +                      if(icParamList != null) {
 +                              for(InvocationContext.Params.Param param:icParamList) {
 +                                      String key = param.getKey();
 +                                      String value = param.getValue();
 +                                      if(!Tools.isEmpty(key) && !Tools.isEmpty(value)) {
 +                                              params.put(key, value);
 +                                      }
 +                              }
 +                      }
 +              }
 +              
        }
  
 -
 -    private Response buildReportResponse(String reportCSID, HashMap<String, Object> params, String reportFileName)
 +    private InputStream buildReportResult(String reportCSID, 
 +              HashMap<String, Object> params, String reportFileName, String outputMimeType, StringBuffer outReportFileName)
                                throws Exception {
                Connection conn = null;
 -              Response response = null;
 +              InputStream result = null;
 +              
        try {
 -                      String fullPath = ServiceMain.getInstance().getServerRootDir() +
 +              String fileNameBase = Tools.getFilenameBase(reportFileName);
 +              String compiledReportFilename = fileNameBase+ReportClient.COMPILED_REPORT_EXTENSION;
 +              String reportDescriptionFilename = fileNameBase+ReportClient.REPORT_DECSRIPTION_EXTENSION;
 +              
 +                      String basePath = ServiceMain.getInstance().getServerRootDir() +
-                                                               File.separator + ConfigReader.CSPACE_DIR_NAME + 
+                                                               File.separator + JEEServerDeployment.CSPACE_DIR_NAME + 
                                                                File.separator + REPORTS_FOLDER +
                                                                // File.separator + tenantName +
 -                                                              File.separator + reportFileName;
 +                                                              File.separator; // + reportFileName;
 +                      
 +                      String compiledFilePath = basePath+compiledReportFilename; 
 +                      File f = new File(compiledFilePath);
 +                      if(!f.exists()) { // Need to compile the file
 +                              // First verify that there is a source file.
 +                              String sourceFilePath = basePath+reportDescriptionFilename; 
 +                              File f2 = new File(sourceFilePath);
 +                              if(!f2.exists()) { // Missing source file - error!
 +                                      logger.error("Report for csid={} is missing the specified source file: {}",
 +                                                                      reportCSID, sourceFilePath);
 +                                      throw new RuntimeException("Report is missing the specified source file!");
 +                              }
 +              logger.info("Report for csid={} is not compiled. Compiling first, and saving to: {}",
 +                              reportCSID, compiledFilePath);
 +              JasperCompileManager.compileReportToFile(sourceFilePath, compiledFilePath);
 +                      }                               
 +                              
                        conn = getConnection();
        
              if (logger.isTraceEnabled()) {
Simple merge
Simple merge
Simple merge