From: Richard Millet Date: Fri, 2 Aug 2013 02:28:42 +0000 (-0700) Subject: CSPACE-5678: Merging with latest trunk sources. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=7c677bdfead853bae2654a7312c65fb890e6121c;p=tmp%2Fjakarta-migration.git CSPACE-5678: Merging with latest trunk sources. --- 7c677bdfead853bae2654a7312c65fb890e6121c diff --cc pom.xml index 49eac8883,a6391e985..f877bc8fa --- a/pom.xml +++ b/pom.xml @@@ -56,9 -56,9 +56,9 @@@ - libs-releases-local - libs-releases-local + libs-release-local + libs-release-local - http://source.collectionspace.org:8081/artifactory/libs-release-local + http://nightly.collectionspace.org:8081/artifactory/libs-release-local false @@@ -348,12 -342,12 +348,12 @@@ org.slf4j slf4j-api -- 1.5.8 ++ 1.6.1 org.slf4j slf4j-log4j12 -- 1.5.8 ++ 1.6.1 org.testng diff --cc services/JaxRsServiceProvider/pom.xml index ca004c0c8,ad0ce694f..e5f77c3aa --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@@ -33,19 -31,19 +33,19 @@@ log4j log4j 1.2.14 - provided + provided -- ++ org.slf4j slf4j-simple -- 1.5.8 ++ 1.6.1 test org.slf4j jcl-over-slf4j -- 1.5.8 ++ 1.6.1 test diff --cc services/authorization-mgt/import/pom.xml index fd1d87a29,e9345e0ef..79c679c2e --- a/services/authorization-mgt/import/pom.xml +++ b/services/authorization-mgt/import/pom.xml @@@ -22,12 -22,12 +22,10 @@@ org.slf4j slf4j-api -- 1.6.1 org.slf4j slf4j-log4j12 -- 1.6.1 @@@ -202,7 -207,7 +205,7 @@@ -- ${basedir}/../../common/src/main ++ ${env.CSPACE_JEESERVER_HOME} -edir ${basedir}/target diff --cc services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java index 0b348e3ed,0b348e3ed..949b7ba8a --- a/services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java @@@ -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, @@@ -161,6 -161,6 +165,7 @@@ 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 diff --cc services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java index f69f8dc9f,f69f8dc9f..700ea66d0 --- a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java @@@ -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) { @@@ -202,6 -202,6 +202,7 @@@ em.getTransaction().begin(); AuthorizationStore authzStore = new AuthorizationStore(); ++ logger.info("Seeding Roles metadata to database."); for (Role role : authzGen.getDefaultRoles()) { try { authzStore.store(em, role); @@@ -218,10 -218,10 +219,12 @@@ } } ++ 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 permRoleRels = new ArrayList(); for (PermissionRole pr : authzGen.getDefaultPermissionRoles()) { PermissionRoleUtil.buildPermissionRoleRel(em, pr, SubjectType.ROLE, permRoleRels, false /*not for delete*/); @@@ -233,7 -233,7 +236,7 @@@ 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()) { diff --cc services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java index a56db9cac,97e6714ca..892ffbacf --- a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java @@@ -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 tenantMgmntPermList = new ArrayList(); private List tenantMgmntPermRoleList = new ArrayList(); @@@ -88,13 -91,14 +84,17 @@@ private List 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()) { diff --cc services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationSeed.java index 366530130,366530130..fa59a890e --- a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationSeed.java +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationSeed.java @@@ -92,20 -92,20 +92,29 @@@ public class AuthorizationSeed */ public void seedPermissions(List permList, List 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 diff --cc services/authorization-mgt/import/src/main/resources/log4j.properties index 79746b946,b24525085..f39efb3db --- a/services/authorization-mgt/import/src/main/resources/log4j.properties +++ b/services/authorization-mgt/import/src/main/resources/log4j.properties @@@ -2,32 -2,30 +2,38 @@@ log4j.rootLogger=debug, stdout, log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -- # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n ++log4j.appender.commandline=org.apache.log4j.ConsoleAppender ++log4j.appender.commandline.target=System.err ++log4j.appender.commandline.layout=org.apache.log4j.PatternLayout ++log4j.appender.commandline.layout.ConversionPattern=%d %p: %m%n ++ log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=target/test-client.log -- log4j.appender.R.MaxFileSize=100KB --# Keep one backup file log4j.appender.R.MaxBackupIndex=1 -- log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n #packages --log4j.logger.org.collectionspace=DEBUG log4j.logger.org.collectionspace.services.authorization.spring=INFO +# log4j.logger.org.collectionspace.services.common.authorization_mgt.AuthorizationStore=TRACE log4j.logger.org.apache=INFO log4j.logger.httpclient=INFO log4j.logger.org.jboss.resteasy=INFO log4j.logger.hibernate=WARN log4j.logger.org.hibernate=WARN log4j.logger.org.hibernate.cfg=WARN --log4j.logger.org.springframework=INFO ++log4j.logger.org.springframework=WARN log4j.logger.ch.elca.el4j.services.xmlmerge=INFO log4j.logger.com.sun.xml.bind.v2.runtime=DEBUG --log4j.logger.javax.persistence.PersistenceException=TRACE ++log4j.logger.javax.persistence.PersistenceException=ERROR ++ ++# ++# Logging for the command line tool that generates the Service artifacts ++# ++log4j.logger.org.collectionspace=INFO, commandline ++log4j.additivity.org.collectionspace=false + diff --cc services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java index b64d98db1,b64d98db1..fffc22727 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java @@@ -15,5 -15,5 +15,9 @@@ public class CommonAPI public static String showRelations_QP = "showRelations"; public static String showSiblings_QP = "showSiblings"; public static String showAllRelations_QP = "showAllRelations"; ++ ++ public static final String GENERATE_BUNDLES = "core"; ++ public static final String GENERATE_BINDINGS = "delta"; ++ } diff --cc services/common/pom.xml index 374afd33e,7551c8f4b..6af2af462 --- a/services/common/pom.xml +++ b/services/common/pom.xml @@@ -377,7 -367,12 +377,7 @@@ spring-security-acl ${spring.security.version} provided - + - - org.collectionspace.services - org.collectionspace.services.common-api - ${project.version} - diff --cc services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java index 166758222,a451d5500..ec7d8b500 --- a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java @@@ -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> { - - 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> { + 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 tenantBindingTypeList; - //tenant id, tenant binding, for tenants not marked as createDisabled - private Hashtable enabledTenantBindings = - new Hashtable(); - //tenant id, tenant binding - private Hashtable allTenantBindings = - new Hashtable(); - //repository domains - private Hashtable domains = - new Hashtable(); - //tenant-qualified servicename, service binding - private Hashtable serviceBindings = - new Hashtable(); - - //tenant-qualified service object name to service name, service binding - private Hashtable docTypes = - new Hashtable(); - - - 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 tenantBindingTypeList; - //tenant id, tenant binding - private Hashtable tenantBindings = - new Hashtable(); - //repository domains - private Hashtable domains = - new Hashtable(); - //tenant-qualified servicename, service binding - private Hashtable serviceBindings = - new Hashtable(); - - //tenant-qualified service object name to service name, service binding - private Hashtable docTypes = - new Hashtable(); - - - 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 tenantBindingTypeList; ++ // tenant id, tenant binding, for tenants not marked as createDisabled ++ private Hashtable enabledTenantBindings = new Hashtable(); ++ // tenant id, tenant binding ++ private Hashtable allTenantBindings = new Hashtable(); ++ // repository domains ++ private Hashtable domains = new Hashtable(); ++ // tenant-qualified servicename, service binding ++ private Hashtable serviceBindings = new Hashtable(); ++ ++ // tenant-qualified service object name to service name, service binding ++ private Hashtable docTypes = new Hashtable(); ++ ++ 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; @@@ -116,176 -120,188 +119,198 @@@ } } } 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 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 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 readTenantConfigs(File protoBindingsFile, List tenantDirList) throws IOException { - List result = new ArrayList(); - List readTenantConfigs(File protoBindingsDir, List 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 readTenantConfigs(File protoBindingsDir, List tenantDirList, ++ boolean useAppGeneratedBindings) throws IOException { + List result = new ArrayList(); - ++ // // 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; @@@ -293,235 -309,228 +318,252 @@@ } } } // 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 getConfiguration() { ++ return tenantBindingTypeList; ++ } ++ ++ /** ++ * getTenantBindings returns all the tenant bindings read from configuration ++ * ++ * @return ++ */ ++ public Hashtable getTenantBindings() { ++ return getTenantBindings(EXCLUDE_CREATE_DISABLED_TENANTS); ++ } ++ ++ /** ++ * getTenantBindings returns all the tenant bindings read from configuration ++ * ++ * @return ++ */ ++ public Hashtable 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 getServiceBindingsByType(String tenantId, String serviceType) { ++ List serviceTypes = new ArrayList(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 getServiceBindingsByType(String tenantId, List serviceTypes) { ++ ArrayList 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(); ++ } ++ 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 getConfiguration() { -- return tenantBindingTypeList; -- } -- -- /** -- * getTenantBindings returns all the tenant bindings read from configuration -- * @return -- */ -- public Hashtable getTenantBindings() { - return getTenantBindings(EXCLUDE_CREATE_DISABLED_TENANTS); - } - - /** - * getTenantBindings returns all the tenant bindings read from configuration - * @return - */ - public Hashtable 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 getServiceBindingsByType( -- String tenantId, String serviceType) { -- List serviceTypes = new ArrayList(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 getServiceBindingsByType( -- String tenantId, List serviceTypes) { -- ArrayList 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(); -- } -- 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 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 getTenantIds() { - return getTenantIds(EXCLUDE_CREATE_DISABLED_TENANTS); - } - /** - * Returns a list of tenant identifiers (tenant IDs). - * - * @return a list of tenant IDs - */ - public List getTenantIds(boolean includeDisabled) { -- List tenantIds = new ArrayList(); -- String tenantId; - Hashtable tenantBindings = getTenantBindings(includeDisabled); - Hashtable 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 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 getTenantIds() { ++ return getTenantIds(EXCLUDE_CREATE_DISABLED_TENANTS); ++ } ++ ++ /** ++ * Returns a list of tenant identifiers (tenant IDs). ++ * ++ * @return a list of tenant IDs ++ */ ++ public List getTenantIds(boolean includeDisabled) { ++ List tenantIds = new ArrayList(); ++ String tenantId; ++ Hashtable 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; ++ } } diff --cc services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index dc2b5b3f8,30b7e9762..f7a4eaf69 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@@ -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 params, InvocationContext invContext) { + InvocationContext.Params icParams = invContext.getParams(); + if(icParams!= null) { + List 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 params, String reportFileName) + private InputStream buildReportResult(String reportCSID, + HashMap 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()) {