List of usage examples for org.springframework.context ApplicationContextException ApplicationContextException
public ApplicationContextException(String msg, Throwable cause)
From source file:ua.com.manometer.jasperreports.AbstractJasperReportsView.java
/** * Loads a <code>JasperReport</code> from the specified <code>Resource</code>. * If the <code>Resource</code> points to an uncompiled report design file then * the report file is compiled dynamically and loaded into memory. * @param resource the <code>Resource</code> containing the report definition or design * @return a <code>JasperReport</code> instance *//*from ww w . java 2 s . c o m*/ protected final JasperReport loadReport(Resource resource) { try { String fileName = resource.getFilename(); if (fileName.endsWith(".jasper")) { // Load pre-compiled report. if (logger.isInfoEnabled()) { logger.info("Loading pre-compiled Jasper Report from " + resource); } InputStream is = resource.getInputStream(); try { return (JasperReport) JRLoader.loadObject(is); } finally { is.close(); } } else if (fileName.endsWith(".jrxml")) { // Compile report on-the-fly. if (logger.isInfoEnabled()) { logger.info("Compiling Jasper Report loaded from " + resource); } InputStream is = resource.getInputStream(); try { JasperDesign design = JRXmlLoader.load(is); return JasperCompileManager.compileReport(design); } finally { is.close(); } } else { throw new IllegalArgumentException( "Report filename [" + fileName + "] must end in either .jasper or .jrxml"); } } catch (IOException ex) { throw new ApplicationContextException("Could not load JasperReports report from " + resource, ex); } catch (JRException ex) { throw new ApplicationContextException("Could not parse JasperReports report from " + resource, ex); } }
From source file:com.dhcc.framework.web.context.DhccContextLoader.java
/** * Return the WebApplicationContext implementation class to use, either the * default XmlWebApplicationContext or a custom context class if specified. * @param servletContext current servlet context * @return the WebApplicationContext implementation class to use * @see #CONTEXT_CLASS_PARAM/* ww w .j a va 2 s . c o m*/ * @see org.springframework.web.context.support.XmlWebApplicationContext */ protected Class<?> determineContextClass(ServletContext servletContext) { String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM); if (contextClassName != null) { try { return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader()); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load custom context class [" + contextClassName + "]", ex); } } else { contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName()); try { return ClassUtils.forName(contextClassName, DhccContextLoader.class.getClassLoader()); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load default context class [" + contextClassName + "]", ex); } } }
From source file:com.cisco.dvbu.ps.deploytool.services.UserManagerImpl.java
private void userAction(String actionName, String serverId, String userIds, String pathToUsersXML, String pathToServersXML) throws CompositeException { // Validate whether the files exist or not if (!CommonUtils.fileExists(pathToUsersXML)) { throw new CompositeException("File [" + pathToUsersXML + "] does not exist."); }/*from w w w . j a v a 2 s. c om*/ if (!CommonUtils.fileExists(pathToServersXML)) { throw new CompositeException("File [" + pathToServersXML + "] does not exist."); } try { List<UserType> userModuleList = getUserModuleUsers(pathToUsersXML); // Used to construct an array of valid users from the UserModule.xml and based on which users in the list can be processed ArrayList<String> validUsers = new ArrayList<String>(); // This is an array of User/Domain objects that were retrieved from CIS based on the validUsers list. // It is possible that a user will not exist in this array even though they are in the validUsers list (means they don't exist in the domain) ArrayList<UserDomain> userArray = new ArrayList<UserDomain>(); String prefix = "userAction"; String processedIds = null; // Get the configuration property file set in the environment with a default of deploy.properties String propertyFile = CommonUtils.getFileOrSystemPropertyValue(CommonConstants.propertyFile, "CONFIG_PROPERTY_FILE"); // Extract variables for the userIds userIds = CommonUtils.extractVariable(prefix, userIds, propertyFile, true); // Set the Module Action Objective String s1 = (userIds == null) ? "no_userIds" : "Ids=" + userIds; System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); // Pre-process the UserModule XML list to determine the number of users to be processed so as to compare with the efficiency threshold int processNumUsers = 0; for (UserType currUser : userModuleList) { // Get the identifier and convert any $VARIABLES String identifier = CommonUtils.extractVariable(prefix, currUser.getId(), propertyFile, true); /** * Possible values for archives * 1. csv string like import1,import2 (we process only resource names which are passed in) * 2. '*' or what ever is configured to indicate all resources (we process all resources in this case) * 3. csv string with '-' or what ever is configured to indicate exclude resources as prefix * like -import1,import3 (we ignore passed in resources and process rest of the in the input xml */ if (DeployUtil.canProcessResource(userIds, identifier)) { // Count the user which can be processed as a valid user processNumUsers++; // Add the valid user to the validUser list - this will be used to get the set of users from CIS validUsers.add(currUser.getUserName().toLowerCase()); } } // option 1=get the entire CIS user list up front. 1 server invocation, option 2=invoke CIS for each user in the UserModule.xml file. int getUserOption = 1; // This is the threshold of the number of users where it is more efficient to go with option 1 and retrieve all users at once vs. option 2 which calls the API to retrieve 1 user at at time int getUserOptionThreshold = 0; String userOptionThreshold = PropertyManager.getInstance().getProperty(propertyFile, "userOptionThreshold"); if (userOptionThreshold != null) { try { getUserOptionThreshold = Integer.valueOf(userOptionThreshold); } catch (Exception e) { getUserOptionThreshold = 0; } } // Balance between the amount of memory required vs. efficiency of invocation to the CIS server if (processNumUsers > getUserOptionThreshold) { // If the number of users to be processed in the UserModule XML file exceeds the threshold then // set the getUserOption=1 and so as to retrieve the entire CIS user list one time // This options requires storing all CIS user and domain in memory. If there are 1000's of users, this could take a lot of memory. getUserOption = 1; } else { // If the number of users to be processed in the UserModule XML file is less than the threshold then // set the getUserOption=2 and so as to retrieve each the user info on each invocation of a user in the list // This requires a web service invocation to the CIS server for each user to be processed. getUserOption = 2; } if (userModuleList != null && userModuleList.size() > 0) { String userName = null; String oldPassword = null; String password = null; String domainName = null; DomainMemberReferenceList groupNames = null; String accessRights = null; String annotation = null; boolean userArrayListPopulated = false; // Loop over the list of users and create/update them. for (UserType currUser : userModuleList) { // Get the identifier and convert any $VARIABLES String identifier = CommonUtils.extractVariable(prefix, currUser.getId(), propertyFile, true); /** * Possible values for archives * 1. csv string like import1,import2 (we process only resource names which are passed in) * 2. '*' or what ever is configured to indicate all resources (we process all resources in this case) * 3. csv string with '-' or what ever is configured to indicate exclude resources as prefix * like -import1,import3 (we ignore passed in resources and process rest of the in the input xml */ if (DeployUtil.canProcessResource(userIds, identifier)) { // Add to the list of processed ids if (processedIds == null) processedIds = ""; else processedIds = processedIds + ","; processedIds = processedIds + identifier; // Set the user name userName = currUser.getUserName().toLowerCase(); // Add a domain name if it exists if (currUser.getDomainName() != null) { domainName = currUser.getDomainName(); } // Set the Module Action Objective s1 = identifier + "=" + ((userName == null) ? "no_userName" : userName + "@" + domainName); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); // Populate the User Array List based on the option // Option 1: Get the entire list of users from CIS and store in a memory ArrayList. This will only get populated once per invocation if (getUserOption == 1) { populateUserArrayList(userArrayListPopulated, validUsers, userArray, domainName, serverId, pathToServersXML); userArrayListPopulated = true; // Only populate the user array once through the loop } else { // Option 2: Get the user from CIS for the current user. Repeated calls to CIS for each user in this loop. validUsers = new ArrayList<String>(); // Initialize valid Users each time through the loop validUsers.add(currUser.getUserName()); // Add the current valid user userArray = new ArrayList<UserDomain>(); // Initialize user array populateUserArrayList(userArrayListPopulated, validUsers, userArray, domainName, serverId, pathToServersXML); userArrayListPopulated = false; // populate the user array each time through the loop } // Create the group list if it exists if (currUser.getGroupMembershipList() != null) { groupNames = new DomainMemberReferenceList(); for (GroupMembershipType groups : currUser.getGroupMembershipList()) { DomainMemberReference domain = new DomainMemberReference(); domain.setName(groups.getGroupName().toLowerCase()); domain.setDomain(groups.getGroupDomain()); groupNames.getEntry().add(domain); } } accessRights = ""; // Convert the list of privileges into a comma separated list if they exist if (currUser.getPrivilege() != null && currUser.getPrivilege().size() > 0) { // Set the privileges as a space separate list for (AccessRightsValidationList privilege : currUser.getPrivilege()) { accessRights = accessRights + privilege + " "; } if (accessRights.length() > 0) { accessRights = accessRights.substring(0, accessRights.length() - 1); } } // Add an annotation if it exists if (currUser.getAnnotation() != null) { annotation = currUser.getAnnotation(); } // Search for the user to see if it exists or not boolean userFound = false; // Lookup the user from a master list of all users that were already acquired from the CIS server and stored in a memory ArrayList for (UserDomain ud : userArray) { if (ud.findUserDomain(userName, domainName)) { // User / domain combination was found userFound = true; break; } } if (actionName.equalsIgnoreCase(UserDAO.action.CREATEORUPDATE.name())) { String actionName2 = null; // Extract the group list into a string for logging purposes String groupList = ""; int i = 0; for (DomainMemberReference groupMember : groupNames.getEntry()) { if (i > 0) { groupList = groupList + ", "; } groupList = groupList + groupMember.getName(); i++; } if (userFound) { actionName2 = UserDAO.action.UPDATE.name(); if (currUser.isForcePassword()) { password = CommonUtils.decrypt(currUser.getEncryptedPassword()); } // Set the Module Action Objective s1 = identifier + "=" + ((userName == null) ? "no_userName" : userName + "@" + domainName); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName2 + " : " + s1); // Update the user information getUserDAO().takeUserAction(actionName2, userName, oldPassword, password, domainName, groupNames, accessRights, annotation, serverId, pathToServersXML); logger.info("Success: action=" + actionName2 + " user: " + userName + " update groups:" + groupList); } else { // Create a new user actionName2 = UserDAO.action.CREATE.name(); password = CommonUtils.decrypt(currUser.getEncryptedPassword()); // Set the Module Action Objective s1 = identifier + "=" + ((userName == null) ? "no_userName" : userName + "@" + domainName); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName2 + " : " + s1); // Check to make sure the password is not null or empty if (password == null || password.length() == 0) { throw new ValidationException( "Password cannot be null or empty when creating a new user."); } getUserDAO().takeUserAction(actionName2, userName, oldPassword, password, domainName, groupNames, accessRights, annotation, serverId, pathToServersXML); logger.info("Success: action=" + actionName2 + " user: " + userName); // Once the user is created, an update must be performed to modify their group affiliation actionName2 = UserDAO.action.UPDATE.name(); // Set the Module Action Objective s1 = identifier + "=" + ((userName == null) ? "no_userName" : userName + "@" + domainName); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName2 + " : " + s1); // Perform the update action on the User to update the group affiliation for the user. getUserDAO().takeUserAction(actionName2, userName, null, null, domainName, groupNames, null, null, serverId, pathToServersXML); logger.info("Success: action=" + actionName2 + " user: " + userName + " update groups:" + groupList); } } if (actionName.equalsIgnoreCase(UserDAO.action.DELETE.name())) { if (userFound) { // Set the Module Action Objective s1 = identifier + "=" + ((userName == null) ? "no_userName" : userName + "@" + domainName); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); getUserDAO().takeUserAction(actionName, userName, oldPassword, password, domainName, groupNames, accessRights, annotation, serverId, pathToServersXML); logger.info("Success: action=" + actionName + " user: " + userName); } else { // Set the Module Action Objective s1 = identifier + "=" + ((userName == null) ? "no_userName" : userName + "@" + domainName + " not found."); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); logger.info("No " + actionName + " action taken due to user (" + userName + ") not found"); } } } } // Determine if any resourceIds were not processed and report on this if (processedIds != null) { if (logger.isInfoEnabled()) { logger.info("User entries processed=" + processedIds); } } else { if (logger.isInfoEnabled()) { String msg = "Warning: No user entries were processed for the input list. userIds=" + userIds; logger.info(msg); System.setProperty("MODULE_ACTION_MESSAGE", msg); } } } else { if (logger.isInfoEnabled()) { String msg = "Warning: No user entries found for User Module XML at path=" + pathToUsersXML; logger.info(msg); System.setProperty("MODULE_ACTION_MESSAGE", msg); } } } catch (CompositeException e) { logger.error("Error while executing action=" + actionName, e); throw new ApplicationContextException(e.getMessage(), e); } }
From source file:com.cisco.dvbu.ps.deploytool.services.PrivilegeManagerImpl.java
private void privilegeAction(String actionName, String serverId, String privilegeIds, String pathToPrivilegeXML, String pathToServersXML) throws CompositeException { String prefix = "privilegeAction"; String processedIds = null;/*from w w w . j a v a 2 s. c om*/ // Validate whether the files exist or not if (!CommonUtils.fileExists(pathToPrivilegeXML)) { throw new CompositeException("File [" + pathToPrivilegeXML + "] does not exist."); } if (!CommonUtils.fileExists(pathToServersXML)) { throw new CompositeException("File [" + pathToServersXML + "] does not exist."); } // Extract variables for the privilegeIds privilegeIds = CommonUtils.extractVariable(prefix, privilegeIds, propertyFile, true); // Set the Module Action Objective String s1 = (privilegeIds == null) ? "no_privilegeIds" : "Ids=" + privilegeIds; System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); String resourcePath = null; try { // Get the list of privileges from the PrivilegeModule.xml property file List<PrivilegeEntryType> privilegeList = getPrvileges(serverId, privilegeIds, pathToPrivilegeXML, pathToServersXML); if (privilegeList != null && privilegeList.size() > 0) { // Set the default mode is if no mode is provided. String mode = "OVERWRITE_APPEND"; // Loop over the list of privileges and apply their attributes to the target CIS instance. for (PrivilegeEntryType privilege : privilegeList) { // Get the identifier and convert any $VARIABLES String identifier = CommonUtils.extractVariable(prefix, privilege.getId(), propertyFile, true); /** * Possible values for privileges * 1. csv string like priv1,priv2 (we process only resource names which are passed in) * 2. " * " or what ever is configured to indicate all resources (we process all resources in this case) * 3. csv string with '-' or what ever is configured to indicate exclude resources as prefix * like -priv1,priv2 (we ignore passed in resources and process rest of the in the input xml * 4. wild card - prefix/postfix any label with a "*" */ if (DeployUtil.canProcessResource(privilegeIds, identifier)) { // Add to the list of processed ids if (processedIds == null) processedIds = ""; else processedIds = processedIds + ","; processedIds = processedIds + identifier; if (logger.isInfoEnabled()) { logger.info("processing action " + actionName + " on privilege " + identifier); } // Validate the privilege coming from the PrivilegeModule.xml property file validatePrivilege(privilege); // Construct the Privilege Entries PrivilegeModule updPrivilegeModule = new PrivilegeModule(); PrivilegeEntryType updPrivilegeEntry = new PrivilegeEntryType(); String resourceType = null; if (privilege.getResourcePath() != null) { // Get the resource path resourcePath = CommonUtils.extractVariable(prefix, privilege.getResourcePath(), propertyFile, true); updPrivilegeEntry.setResourcePath(resourcePath); // Get the resource type if (privilege.getResourceType() == null || privilege.getResourceType().toString().length() == 0) { // Get the Resource Type for the Resource Path resourceType = getResourceManager().getResourceType(serverId, resourcePath, pathToServersXML); updPrivilegeEntry.setResourceType(ResourceTypeSimpleType.valueOf(resourceType)); } else { updPrivilegeEntry.setResourceType( ResourceTypeSimpleType.valueOf(privilege.getResourceType().toString())); } } resourceType = updPrivilegeEntry.getResourceType().toString(); // Set the Module Action Objective s1 = identifier + "=" + ((resourcePath == null) ? "no_resourcePath" : resourcePath); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); // Set the resource owner and domain. Both must be non-null in order to set the target if (privilege.getResourceOwner() != null) { if (privilege.getResourceOwner().getResourceOwnerApply() != null) { // Get the "resourceOwnerApply" and check for variables and then change to lower. String resourceOwnerApply = CommonUtils.extractVariable(prefix, privilege.getResourceOwner().getResourceOwnerApply(), propertyFile, true) .toLowerCase(); // Validate "resourceOwnerApply" if (resourceOwnerApply.equalsIgnoreCase("true") || resourceOwnerApply.equalsIgnoreCase("false")) { // Continue applying the resource ownership only if "resourceOwnerApply" == true if (resourceOwnerApply.equalsIgnoreCase("true")) { // Make sure both resourceOwnerName and resourceOwnerDomain are not null before continuing if (privilege.getResourceOwner().getResourceOwnerName() != null && privilege.getResourceOwner().getResourceOwnerDomain() == null) throw new CompositeException( "Resource Owner Domain \"resourceOwnerDomain\" may not be null when Resource Owner \"resourceOwner\" is not null for resourcePath=" + resourcePath); if (privilege.getResourceOwner().getResourceOwnerName() == null && privilege.getResourceOwner().getResourceOwnerDomain() != null) throw new CompositeException( "Resource Owner \"resourceOwner\" may not be null when Resource Owner Domain \"resourceOwnerDomain\" is not null for resourcePath=" + resourcePath); if (privilege.getResourceOwner().getResourceOwnerName() != null && privilege.getResourceOwner().getResourceOwnerDomain() != null) { if (resourceType.equalsIgnoreCase("COLUMN")) { throw new CompositeException( "Resource type of COLUMN is not permitted when setting \"resourceOwner\" and \"resourceOwnerDomain\" for resourcePath=" + resourcePath); } ResourceOwnerType resourceOwner = new ResourceOwnerType(); resourceOwner.setResourceOwnerName(CommonUtils.extractVariable(prefix, privilege.getResourceOwner().getResourceOwnerName(), propertyFile, true)); resourceOwner.setResourceOwnerDomain(CommonUtils.extractVariable(prefix, privilege.getResourceOwner().getResourceOwnerDomain(), propertyFile, true)); if (privilege.getResourceOwner().getResourceOwnerRecurse() != null) { String resourceOwnerRecurse = CommonUtils.extractVariable( prefix, privilege.getResourceOwner() .getResourceOwnerRecurse().toLowerCase(), propertyFile, true).toLowerCase(); if (resourceOwnerRecurse.equalsIgnoreCase("true") || resourceOwnerRecurse.equalsIgnoreCase("false")) { resourceOwner.setResourceOwnerRecurse(resourceOwnerRecurse); } else { throw new CompositeException( "Resource Owner Recurse \"resourceOwnerRecurse\" must be either [true or false] for resourcePath=" + resourcePath); } } else { resourceOwner.setResourceOwnerRecurse("false"); } updPrivilegeEntry.setResourceOwner(resourceOwner); } } } else { throw new CompositeException( "Resource Owner Apply \"resourceOwnerApply\" must either be [true or false] for resourcePath=" + resourcePath); } } } // Set the child recursion if (privilege.isRecurse() != null) updPrivilegeEntry.setRecurse(privilege.isRecurse()); // Set the dependencies recursion if (privilege.isUpdateDependenciesRecursively() != null) updPrivilegeEntry .setUpdateDependenciesRecursively(privilege.isUpdateDependenciesRecursively()); // Set the dependents recursion if (privilege.isUpdateDependentsRecursively() != null) updPrivilegeEntry .setUpdateDependentsRecursively(privilege.isUpdateDependentsRecursively()); // Set mode if (privilege.getMode() != null) { mode = CommonUtils.extractVariable(prefix, privilege.getMode().name(), propertyFile, true); } updPrivilegeEntry.setMode(PrivilegeModeValidationList.valueOf(mode)); for (PrivilegeType privType : privilege.getPrivilege()) { boolean updatePrivilege = false; if (privType.getNameType().name().toString().equalsIgnoreCase("USER") && !doNotGenerateUsersList.contains(privType.getName().toLowerCase())) { updatePrivilege = true; } if (privType.getNameType().name().toString().equalsIgnoreCase("GROUP") && !doNotGenerateGroupsList.contains(privType.getName().toLowerCase())) { updatePrivilege = true; } if (updatePrivilege) { PrivilegeType updPrivilege = new PrivilegeType(); String domain = null; if (privType.getDomain() != null) { domain = CommonUtils.extractVariable(prefix, privType.getDomain(), propertyFile, true); updPrivilege.setDomain(domain); } if (privType.getName() != null) { // -- 2011-11-18 - grose - fixing bug - setting name to lower case // will break most LDAP names String name = CommonUtils.extractVariable(prefix, privType.getName(), propertyFile, true); if (domain != null) { if (domain.equals("composite")) updPrivilege.setName(name.toLowerCase()); else updPrivilege.setName(name); } else { updPrivilege.setName(name); } } if (privType.getNameType() != null) { String nameType = CommonUtils.extractVariable(prefix, privType.getNameType().name(), propertyFile, true); updPrivilege.setNameType( PrivilegeNameTypeValidationList.valueOf(nameType.toUpperCase())); } // Set privileges if not null /* Note: * Neither CombinedPrivileges nore Inherited Privileges get updated as per info tab of updateResourcePrivileges() * The "combinedPrivs" and "inheritedPrivs" elements on each "privilegeEntry" will be ignored and can be left unset */ if (privType.getPrivileges() != null && privType.getPrivileges().size() > 0) { updPrivilege.getPrivileges().addAll(privType.getPrivileges()); } // Add privileges to the object list updPrivilegeEntry.getPrivilege().add(updPrivilege); } } updPrivilegeModule.getResourcePrivilege().add(updPrivilegeEntry); /*************************************** * * PrivilegeWSDAOImpl Invocation * ***************************************/ // Invoke DAO to take action getPrivilegeDAO().takePrivilegeAction(actionName, updPrivilegeModule, serverId, pathToServersXML); } } // Determine if any resourceIds were not processed and report on this if (processedIds != null) { if (logger.isInfoEnabled()) { logger.info("Privilege entries processed=" + processedIds); } } else { if (logger.isInfoEnabled()) { String msg = "Warning: No privilege entries were processed for the input list. privilegeIds=" + privilegeIds; logger.info(msg); System.setProperty("MODULE_ACTION_MESSAGE", msg); } } } else { if (logger.isInfoEnabled()) { String msg = "Warning: No privilege entries found for Privilege Module XML at path=" + pathToPrivilegeXML; logger.info(msg); System.setProperty("MODULE_ACTION_MESSAGE", msg); } } } catch (CompositeException e) { logger.error("Error performing action=" + actionName + " for privileges on resource: " + resourcePath, e); throw new ApplicationContextException(e.getMessage(), e); } }
From source file:com.dhcc.framework.web.context.DhccContextLoader.java
/** * Return the {@link ApplicationContextInitializer} implementation classes to use * if any have been specified by {@link #CONTEXT_INITIALIZER_CLASSES_PARAM}. * @param servletContext current servlet context * @see #CONTEXT_INITIALIZER_CLASSES_PARAM *//* w w w .ja v a 2 s. c om*/ @SuppressWarnings("unchecked") protected List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> determineContextInitializerClasses( ServletContext servletContext) { String classNames = servletContext.getInitParameter(CONTEXT_INITIALIZER_CLASSES_PARAM); List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> classes = new ArrayList<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>>(); if (classNames != null) { for (String className : StringUtils.tokenizeToStringArray(classNames, ",")) { try { Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader()); Assert.isAssignable(ApplicationContextInitializer.class, clazz, "class [" + className + "] must implement ApplicationContextInitializer"); classes.add((Class<ApplicationContextInitializer<ConfigurableApplicationContext>>) clazz); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load context initializer class [" + className + "]", ex); } } } return classes; }
From source file:com.cisco.dvbu.ps.deploytool.services.ResourceCacheManagerImpl.java
private void resourceCacheAction(String actionName, String serverId, String resourceIds, String pathToResourceCacheXML, String pathToServersXML) throws CompositeException { // Validate whether the files exist or not if (!CommonUtils.fileExists(pathToResourceCacheXML)) { throw new CompositeException("File [" + pathToResourceCacheXML + "] does not exist."); }//from w ww . jav a 2s . c o m if (!CommonUtils.fileExists(pathToServersXML)) { throw new CompositeException("File [" + pathToServersXML + "] does not exist."); } String prefix = "dataSourceAction"; String processedIds = null; // Get the configuration property file set in the environment with a default of deploy.properties String propertyFile = CommonUtils.getFileOrSystemPropertyValue(CommonConstants.propertyFile, "CONFIG_PROPERTY_FILE"); // Extract variables for the resourceIds resourceIds = CommonUtils.extractVariable(prefix, resourceIds, propertyFile, true); // Set the Module Action Objective String s1 = (resourceIds == null) ? "no_resourceIds" : "Ids=" + resourceIds; System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); try { List<ResourceCacheType> resourceCacheModuleList = getResourceCache(serverId, resourceIds, pathToResourceCacheXML, pathToServersXML); if (resourceCacheModuleList != null && resourceCacheModuleList.size() > 0) { // Loop over the list of resource cache entries and apply their configurations to the target CIS instance. for (ResourceCacheType resourceCacheModule : resourceCacheModuleList) { // Get the identifier and convert any $VARIABLES String identifier = CommonUtils.extractVariable(prefix, resourceCacheModule.getId(), propertyFile, true); /** * Possible values for resource cache * 1. csv string like rc1,rc2 (we process only resource names which are passed in) * 2. '*' or whatever is configured to indicate all resources (we process all resources in this case) * 3. csv string with '-' or whatever is configured to indicate exclude resources as prefix * like -rc1,rc2 (we ignore passed in resources and process rest of the in the input xml */ if (DeployUtil.canProcessResource(resourceIds, identifier)) { // Add to the list of processed ids if (processedIds == null) processedIds = ""; else processedIds = processedIds + ","; processedIds = processedIds + identifier; CacheConfig cacheConfig = new CacheConfig(); String resourceCachePath = CommonUtils.extractVariable(prefix, resourceCacheModule.getResourcePath(), propertyFile, true); String resourceCacheType = CommonUtils.extractVariable(prefix, resourceCacheModule.getResourceType().toString(), propertyFile, false); // Set the Module Action Objective s1 = identifier + "=" + ((resourceCachePath == null) ? "no_resourceCachePath" : resourceCachePath); System.setProperty("MODULE_ACTION_OBJECTIVE", actionName + " : " + s1); if (logger.isInfoEnabled()) { logger.info( "processing action " + actionName + " on resource cache " + resourceCachePath); } if (actionName.equals(ResourceCacheDAO.action.ENABLE_DISABLE.name().toString())) { if (resourceCacheModule.getCacheConfig() != null) { // Set enabled flag Boolean enabled = null; if (resourceCacheModule.getCacheConfig().isEnabled() != null) { enabled = resourceCacheModule.getCacheConfig().isEnabled(); } // Set the Module Action Objective s1 = identifier + "=" + ((resourceCachePath == null) ? "no_resourceCachePath" : resourceCachePath); String enable_disabled_action = (enabled == true) ? "ENABLE" : "DISABLE"; System.setProperty("MODULE_ACTION_OBJECTIVE", enable_disabled_action + " : " + s1); updateResourceCacheEnabledAll(serverId, resourceCachePath, resourceCacheType, pathToServersXML, enabled); } } else { if (resourceCacheModule.getCacheConfig() != null) { // Set configured if it exists if (resourceCacheModule.getCacheConfig().isConfigured() != null) { cacheConfig.setConfigured(resourceCacheModule.getCacheConfig().isConfigured()); } // Set enabled if it exists if (resourceCacheModule.getCacheConfig().isEnabled() != null) { cacheConfig.setEnabled(resourceCacheModule.getCacheConfig().isEnabled()); } // Set the storage if it exists if (resourceCacheModule.getCacheConfig().getStorage() != null) { Storage storage = new Storage(); if (resourceCacheModule.getCacheConfig().getStorage().getMode() != null) { storage.setMode(StorageMode.valueOf( resourceCacheModule.getCacheConfig().getStorage().getMode())); } if (resourceCacheModule.getCacheConfig().getStorage() .getStorageDataSourcePath() != null) { storage.setStorageDataSourcePath( CommonUtils .extractVariable(prefix, resourceCacheModule.getCacheConfig().getStorage() .getStorageDataSourcePath(), propertyFile, true)); } if (resourceCacheModule.getCacheConfig().getStorage() .getStorageTargets() != null) { // Define the Target Storage List TargetPathTypePairList entry = new TargetPathTypePairList(); for (ResourceCacheStorageTargetsType storageTarget : resourceCacheModule .getCacheConfig().getStorage().getStorageTargets()) { // Define the Target Storage Entry TargetPathTypePair targetPair = new TargetPathTypePair(); // Set the target pair entry targetPair.setPath(CommonUtils.extractVariable(prefix, storageTarget.getPath(), propertyFile, true)); targetPair.setTargetName(CommonUtils.extractVariable(prefix, storageTarget.getTargetName(), propertyFile, false)); targetPair.setType( ResourceType.valueOf(storageTarget.getType().toUpperCase())); // Add the target pair entry to the list entry.getEntry().add(targetPair); } storage.setStorageTargets(entry); } cacheConfig.setStorage(storage); } //end::if (resourceCacheModule.getCacheConfig().getStorage() != null) { // Set the refresh if it exists if (resourceCacheModule.getCacheConfig().getRefresh() != null) { Refresh refresh = new Refresh(); String refreshMode = resourceCacheModule.getCacheConfig().getRefresh().getMode() .toUpperCase(); refresh.setMode(RefreshMode.valueOf(refreshMode)); if (resourceCacheModule.getCacheConfig().getRefresh().getSchedule() != null) { if (refreshMode.equalsIgnoreCase("SCHEDULED")) { Schedule schedule = new Schedule(); if (resourceCacheModule.getCacheConfig().getRefresh().getSchedule() .getStartTime() != null) { schedule.setStartTime(resourceCacheModule.getCacheConfig() .getRefresh().getSchedule().getStartTime()); } if (resourceCacheModule.getCacheConfig().getRefresh().getSchedule() .getRefreshPeriod().getPeriod() != null) { String period = resourceCacheModule.getCacheConfig().getRefresh() .getSchedule().getRefreshPeriod().getPeriod().toUpperCase(); // Set the mode to INTERVAL if (period.equalsIgnoreCase("SECOND") || period.equalsIgnoreCase("MINUTE")) { schedule.setMode(ScheduleMode.valueOf("INTERVAL")); Long interval = convertPeriodCount(period, resourceCacheModule.getCacheConfig().getRefresh() .getSchedule().getRefreshPeriod().getCount(), "seconds"); schedule.setInterval(interval.intValue()); } else { schedule.setMode(ScheduleMode.valueOf("CALENDAR")); schedule.setPeriod(CalendarPeriod.valueOf(resourceCacheModule .getCacheConfig().getRefresh().getSchedule() .getRefreshPeriod().getPeriod().toUpperCase())); Integer count = (int) resourceCacheModule.getCacheConfig() .getRefresh().getSchedule().getRefreshPeriod() .getCount(); schedule.setCount(count); } } refresh.setSchedule(schedule); } } cacheConfig.setRefresh(refresh); } //end::if (resourceCacheModule.getCacheConfig().getRefresh() != null) { // Set the Expiration if it exists if (resourceCacheModule.getCacheConfig().getExpirationPeriod() != null) { Long milliCount = convertPeriodCount( resourceCacheModule.getCacheConfig().getExpirationPeriod().getPeriod(), resourceCacheModule.getCacheConfig().getExpirationPeriod().getCount(), "milliseconds"); cacheConfig.setExpirationPeriod(milliCount); } // Set the clear rule if it exists if (resourceCacheModule.getCacheConfig().getClearRule() != null) { cacheConfig.setClearRule(ClearRule.valueOf( resourceCacheModule.getCacheConfig().getClearRule().toUpperCase())); } } //end::if (resourceCacheModule.getCacheConfig() != null) { // Validate that the resource exists before acting on it. Boolean validateResourceExists = true; // Execute takeResourceCacheAction() getResourceCacheDAO().takeResourceCacheAction(actionName, resourceCachePath, resourceCacheType, cacheConfig, serverId, pathToServersXML, validateResourceExists); } // end:: if (actionName.equals(ResourceCacheDAO.action.ENABLE_DISABLE.name().toString())) { } // end:: if(DeployUtil.canProcessResource(resourceIds, identifier)) { } // end:: for (ResourceCacheType resourceCache : resourceCacheList) { // Determine if any resourceIds were not processed and report on this if (processedIds != null) { if (logger.isInfoEnabled()) { logger.info("ResourceCache entries processed=" + processedIds); } } else { if (logger.isInfoEnabled()) { String msg = "Warning: No resource cache entries were processed for the input list. resourceIds=" + resourceIds; logger.info(msg); System.setProperty("MODULE_ACTION_MESSAGE", msg); } } } else { if (logger.isInfoEnabled()) { String msg = "Warning: No resource cache entries found for ResourceCache Module XML at path=" + pathToResourceCacheXML; logger.info(msg); System.setProperty("MODULE_ACTION_MESSAGE", msg); } } } catch (CompositeException e) { logger.error("Error on resource cache action (" + actionName + "): ", e); throw new ApplicationContextException(e.getMessage(), e); } }
From source file:com.cisco.dvbu.ps.deploytool.services.ResourceCacheManagerImpl.java
private List<ResourceCacheType> getResourceCache(String serverId, String resourceIds, String pathToResourceCacheXML, String pathToServersXML) { // validate incoming arguments if (serverId == null || serverId.trim().length() == 0 || resourceIds == null || resourceIds.trim().length() == 0 || pathToServersXML == null || pathToServersXML.trim().length() == 0 || pathToResourceCacheXML == null || pathToResourceCacheXML.trim().length() == 0) { throw new ValidationException("Invalid Arguments"); }//w w w . j av a 2 s . c o m try { //using jaxb convert xml to corresponding java objects ResourceCacheModule resourceCacheModuleType = (ResourceCacheModule) XMLUtils .getModuleTypeFromXML(pathToResourceCacheXML); if (resourceCacheModuleType != null && resourceCacheModuleType.getResourceCache() != null && !resourceCacheModuleType.getResourceCache().isEmpty()) { return resourceCacheModuleType.getResourceCache(); } } catch (CompositeException e) { logger.error("Error while parsing resource cache xml", e); throw new ApplicationContextException(e.getMessage(), e); } return null; }
From source file:com.cisco.dvbu.ps.deploytool.services.RebindManagerImpl.java
/** * Get rebind XML from the RebindModule.xml file. * //w w w .ja va2s . c o m * @param serverId * @param rebindIds * @param pathToRebindsXml * @param pathToServersXML * @return */ private List<RebindType> getRebinds(String serverId, String rebindIds, String pathToRebindsXml, String pathToServersXML) { // validate incoming arguments if (serverId == null || serverId.trim().length() == 0 || rebindIds == null || rebindIds.trim().length() == 0 || pathToServersXML == null || pathToServersXML.trim().length() == 0 || pathToRebindsXml == null || pathToRebindsXml.trim().length() == 0) { throw new ValidationException("Invalid Arguments"); } try { //using jaxb convert xml to corresponding java objects RebindModule rebindModule = (RebindModule) XMLUtils.getModuleTypeFromXML(pathToRebindsXml); if (rebindModule != null && rebindModule.getRebind() != null && !rebindModule.getRebind().isEmpty()) { return rebindModule.getRebind(); } } catch (CompositeException e) { logger.error("Error while parsing rebind xml", e); throw new ApplicationContextException(e.getMessage(), e); } return null; }
From source file:com.cisco.dvbu.ps.deploytool.services.UserManagerImpl.java
public void generateUsersXML(String serverId, String domainName, String pathToUsersXML, String pathToServersXML) throws CompositeException { // Set the command and action name String command = "generateUsersXML"; String actionName = "CREATE_XML"; // Validate whether the files exist or not if (!CommonUtils.fileExists(pathToServersXML)) { throw new CompositeException("File [" + pathToServersXML + "] does not exist."); }/*from ww w .ja va 2s . c o m*/ // Set the Module Action Objective String s1 = (domainName == null) ? "no_domainName" : "Domain=" + domainName; System.setProperty("MODULE_ACTION_OBJECTIVE", "GENERATE : " + s1); try { // Prepare a local UserModule XML variable for creating a list of "User" nodes // This XML variable will be written out to the specified file. UserModule userModule = new ObjectFactory().createUserModule(); // Get the list of CIS Users UserList cisUserList = getUserDAO().getAllUsers(null, domainName, serverId, pathToServersXML); // Loop over the list of CIS users and generate the UserModule XML int count = 1; for (User cisUser : cisUserList.getUser()) { UserType u = new UserType(); u.setId("user" + count++); u.setUserName(cisUser.getName().toLowerCase()); u.setDomainName(cisUser.getDomainName()); u.setAnnotation(cisUser.getAnnotation()); u.setEncryptedPassword(""); u.setForcePassword(false); // Create the list of privilege access rights if (cisUser.getExplicitRights() != null) { StringTokenizer st = new StringTokenizer(cisUser.getExplicitRights(), " "); while (st.hasMoreTokens()) { String token = st.nextToken(); u.getPrivilege().add(AccessRightsValidationList.valueOf(token)); } } if (cisBug_getDomainUsers_fixed) { // BUG:: bug in CIS Admin API getDomainUsers() which returns the Group Membership List but group name and domain are always null even though they should have values if (cisUser.getGroupNames() != null) { if (cisUser.getGroupNames().getEntry() != null) { // Create the list of Groups for (DomainMemberReference entry : cisUser.getGroupNames().getEntry()) { GroupMembershipType g = new GroupMembershipType(); g.setGroupDomain(entry.getDomain()); g.setGroupName(entry.getName()); u.getGroupMembershipList().add(g); } } } } else { // Alternative 1 GroupList groupList = getGroupDAO().getGroupsByUser(cisUser.getName(), cisUser.getDomainName(), serverId, pathToServersXML); for (Group group : groupList.getGroup()) { GroupMembershipType g = new GroupMembershipType(); g.setGroupDomain(group.getDomainName()); g.setGroupName(group.getName()); u.getGroupMembershipList().add(g); } // Alternative 2 // BUG:: bug in CIS Admin API getUsers() which returns the User info and Group Membership List but group name and domain are always null even though they should have values /* This code is left here for documentation purposes so as not to lose track of the issue and provide a way in which to test a fix. UserList userList = getUserDAO().getUsers(cisUser.getName(), cisUser.getDomainName(), serverId, pathToServersXML); if(userList.getUser() != null){ for (User user : userList.getUser()) { if (user.getName().equalsIgnoreCase(cisUser.getName()) && user.getDomainName().equalsIgnoreCase(domainName)) { for (DomainMemberReference entry : user.getGroupNames().getEntry()) { GroupMembershipType g = new GroupMembershipType(); g.setGroupDomain(entry.getDomain()); g.setGroupName(entry.getName()); u.getGroupMembershipList().add(g); } } } } */ } // Add the user node userModule.getUser().add(u); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Generate the XML file XMLUtils.createXMLFromModuleType(userModule, pathToUsersXML); } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (CompositeException e) { logger.error("Error while parsing user xml", e); throw new ApplicationContextException(e.getMessage(), e); } }
From source file:com.cisco.dvbu.ps.deploytool.services.UserManagerImpl.java
private List<UserType> getUserModuleUsers(String pathToUsersXML) { // validate incoming arguments if (pathToUsersXML == null || pathToUsersXML.trim().length() == 0) { throw new ValidationException("Invalid Arguments"); }//from w w w . j av a 2s.c o m try { //using jaxb convert xml to corresponding java objects UserModule userModuleType = (UserModule) XMLUtils.getModuleTypeFromXML(pathToUsersXML); if (userModuleType != null && userModuleType.getUser() != null && !userModuleType.getUser().isEmpty()) { return userModuleType.getUser(); } } catch (CompositeException e) { logger.error("Error while parsing user xml", e); throw new ApplicationContextException(e.getMessage(), e); } return null; }