List of usage examples for org.apache.commons.collections.bidimap DualHashBidiMap DualHashBidiMap
public DualHashBidiMap(Map map)
HashBidiMap and copies the mappings from specified Map. From source file:de.fau.cs.osr.utils.SimpleTypeNameMapper.java
public SimpleTypeNameMapper(SimpleTypeNameMapper stnm) { typeToName = new DualHashBidiMap(stnm.typeToName); }
From source file:com.github.lucapino.jira.helpers.IssuesReportHelper.java
/** * Get a list of id:s for the columns that are to be included in the report. * This method also handles deprecated column names, which will still work. * If deprecated column names are used they generate a warning, indicating * the replacement column name./*from w w w . j a va2 s. co m*/ * * @param columnNames The names of the columns * @param allColumns A mapping from column name to column id * @param deprecatedColumns A mapping from deprecated column name to column * id * @param log A log * @return A List of column id:s */ public static List<Integer> getColumnIds(String columnNames, Map<String, Integer> allColumns, Map<String, Integer> deprecatedColumns, Log log) { DualHashBidiMap bidiColumns = null; List<Integer> columnIds = new ArrayList<>(); String[] columnNamesArray = columnNames.split(","); if (deprecatedColumns != null) { bidiColumns = new DualHashBidiMap(allColumns); } // Loop through the names of the columns, to validate each of them and add their id to the list for (String columnNamesNotTrimmed : columnNamesArray) { String columnName = columnNamesNotTrimmed.trim(); if (allColumns.containsKey(columnName)) { columnIds.add(allColumns.get(columnName)); } else if (deprecatedColumns != null && deprecatedColumns.containsKey(columnName)) { Integer columnId = deprecatedColumns.get(columnName); columnIds.add(columnId); if (log != null && bidiColumns != null) { log.warn("The columnName '" + columnName + "' has been deprecated." + " Please use " + "the columnName '" + bidiColumns.getKey(columnId) + "' instead."); } } } return columnIds; }
From source file:cn.nukkit.Server.java
@SuppressWarnings("unchecked") Server(MainLogger logger, final String filePath, String dataPath, String pluginPath) { Preconditions.checkState(instance == null, "Already initialized!"); currentThread = Thread.currentThread(); // Saves the current thread instance as a reference, used in Server#isPrimaryThread() instance = this; this.logger = logger; this.filePath = filePath; if (!new File(dataPath + "worlds/").exists()) { new File(dataPath + "worlds/").mkdirs(); this.getLogger().info(TextFormat.AQUA + dataPath + "worlds/ was created!"); }// w ww .j av a 2 s.co m if (!new File(dataPath + "players/").exists()) { new File(dataPath + "players/").mkdirs(); this.getLogger().info(TextFormat.AQUA + dataPath + "players/ was created!"); } if (!new File(pluginPath).exists()) { new File(pluginPath).mkdirs(); this.getLogger().info(TextFormat.AQUA + pluginPath + "plugins/ was created!"); this.getLogger().info(TextFormat.AQUA + dataPath + "worlds/ ?????"); } if (!new File(dataPath + "players/").exists()) { new File(dataPath + "players/").mkdirs(); this.getLogger().info(TextFormat.AQUA + dataPath + "players/ ?????"); } if (!new File(pluginPath).exists()) { new File(pluginPath).mkdirs(); this.getLogger().info(TextFormat.AQUA + pluginPath + " ?????"); } if (!new File(dataPath + "unpackedPlugins/").exists()) { new File(dataPath + "unpackedPlugins/").mkdirs(); this.getLogger().info(TextFormat.AQUA + pluginPath + "unpackedPlugins/ ?????"); } if (!new File(dataPath + "compileOrder/").exists()) { new File(dataPath + "compileOrder/").mkdirs(); this.getLogger().info(TextFormat.AQUA + pluginPath + "compileOrder/ ?????"); } this.dataPath = new File(dataPath).getAbsolutePath() + "/"; this.pluginPath = new File(pluginPath).getAbsolutePath() + "/"; this.console = new CommandReader(); //todo: VersionString ?? if (!new File(this.dataPath + "nukkit.yml").exists()) { this.getLogger().info(TextFormat.GREEN + "Welcome! Please choose a language first!"); try { String[] lines = Utils .readFile(this.getClass().getClassLoader().getResourceAsStream("lang/language.list")) .split("\n"); for (String line : lines) { this.getLogger().info(line); } } catch (IOException e) { throw new RuntimeException(e); } String fallback = BaseLang.FALLBACK_LANGUAGE; String language = null; while (language == null) { String lang = this.console.readLine(); InputStream conf = this.getClass().getClassLoader() .getResourceAsStream("lang/" + lang + "/lang.ini"); if (conf != null) { language = lang; } } InputStream advacedConf = this.getClass().getClassLoader() .getResourceAsStream("lang/" + language + "/nukkit.yml"); if (advacedConf == null) { advacedConf = this.getClass().getClassLoader() .getResourceAsStream("lang/" + fallback + "/nukkit.yml"); } try { Utils.writeFile(this.dataPath + "nukkit.yml", advacedConf); } catch (IOException e) { throw new RuntimeException(e); } } this.console.start(); this.logger.info(TextFormat.GREEN + "nukkit.yml" + TextFormat.WHITE + "?????..."); this.config = new Config(this.dataPath + "nukkit.yml", Config.YAML); this.logger .info(TextFormat.GREEN + "server.properties" + TextFormat.WHITE + "?????..."); this.properties = new Config(this.dataPath + "server.properties", Config.PROPERTIES, new ConfigSection() { { put("motd", "Jupiter Server For Minecraft: PE"); put("server-port", 19132); put("server-ip", "0.0.0.0"); put("view-distance", 10); put("white-list", false); put("achievements", true); put("announce-player-achievements", true); put("spawn-protection", 16); put("max-players", 20); put("allow-flight", false); put("spawn-animals", true); put("spawn-mobs", true); put("gamemode", 0); put("force-gamemode", false); put("hardcore", false); put("pvp", true); put("difficulty", 1); put("generator-settings", ""); put("level-name", "world"); put("level-seed", ""); put("level-type", "DEFAULT"); put("enable-query", true); put("enable-rcon", false); put("rcon.password", Base64.getEncoder() .encodeToString(UUID.randomUUID().toString().replace("-", "").getBytes()).substring(3, 13)); put("auto-save", true); put("force-resources", false); } }); this.logger.info(TextFormat.GREEN + "jupiter.yml" + TextFormat.WHITE + "?????..."); if (!new File(this.dataPath + "jupiter.yml").exists()) { InputStream advacedConf = this.getClass().getClassLoader().getResourceAsStream("lang/jpn/jupiter.yml"); if (advacedConf == null) this.getLogger().error( "Jupiter.yml????????????????"); try { Utils.writeFile(this.dataPath + "jupiter.yml", advacedConf); } catch (IOException e) { throw new RuntimeException(e); } } this.loadJupiterConfig(); InputStream advacedConf1 = this.getClass().getClassLoader().getResourceAsStream("lang/jpn/jupiter.yml"); if (advacedConf1 == null) this.getLogger().error( "Jupiter.yml????????????????"); try { Utils.writeFile(this.dataPath + "jupiter1.yml", advacedConf1); } catch (IOException e) { throw new RuntimeException(e); } //get Jupiter.yml in the jar Config jupiter = new Config(this.getDataPath() + "jupiter1.yml"); Map<String, Object> jmap = jupiter.getAll(); Collection<Object> objj = jmap.values(); Object[] objj1 = objj.toArray(); Object objj2 = objj1[objj1.length - 1]; BidiMap mapp = new DualHashBidiMap(jmap); String keyy = (String) mapp.getKey(objj2); //get JupiterConfig key in the delectory Collection<Object> obj = jupiterconfig.values(); Object[] obj1 = obj.toArray(); Object obj2 = obj1[obj1.length - 1]; BidiMap map = new DualHashBidiMap(jupiterconfig); String key1 = (String) map.getKey(obj2); //delete jupiter1.yml File jf = new File(this.dataPath + "jupiter1.yml"); jf.delete(); if (!keyy.equals(key1)) { File conf = new File(this.dataPath + "jupiter.yml"); conf.delete(); InputStream advacedConf = this.getClass().getClassLoader().getResourceAsStream("lang/jpn/jupiter.yml"); if (advacedConf == null) this.getLogger().error( "Jupiter.yml????????????????"); try { Utils.writeFile(this.dataPath + "jupiter.yml", advacedConf); } catch (IOException ex) { throw new RuntimeException(ex); } this.getLogger() .info(TextFormat.AQUA + "Jupiter.yml????????????"); this.loadJupiterConfig(); } if (this.getJupiterConfigBoolean("destroy-block-particle")) { Level.sendDestroyParticle = true; } else { Level.sendDestroyParticle = false; } this.forceLanguage = (Boolean) this.getConfig("settings.force-language", false); this.baseLang = new BaseLang((String) this.getConfig("settings.language", BaseLang.FALLBACK_LANGUAGE)); this.logger.info(this.getLanguage().translateString("language.selected", new String[] { getLanguage().getName(), getLanguage().getLang() })); this.logger.info(this.getLanguage().translateString("nukkit.server.start", TextFormat.AQUA + this.getVersion() + TextFormat.WHITE)); Object poolSize = this.getConfig("settings.async-workers", "auto"); if (!(poolSize instanceof Integer)) { try { poolSize = Integer.valueOf((String) poolSize); } catch (Exception e) { poolSize = Math.max(Runtime.getRuntime().availableProcessors() + 1, 4); } } ServerScheduler.WORKERS = (int) poolSize; int threshold; try { threshold = Integer.valueOf(String.valueOf(this.getConfig("network.batch-threshold", 256))); } catch (Exception e) { threshold = 256; } if (threshold < 0) { threshold = -1; } Network.BATCH_THRESHOLD = threshold; this.networkCompressionLevel = (int) this.getConfig("network.compression-level", 7); this.networkCompressionAsync = (boolean) this.getConfig("network.async-compression", true); this.networkCompressionLevel = (int) this.getConfig("network.compression-level", 7); this.networkCompressionAsync = (boolean) this.getConfig("network.async-compression", true); this.autoTickRate = (boolean) this.getConfig("level-settings.auto-tick-rate", true); this.autoTickRateLimit = (int) this.getConfig("level-settings.auto-tick-rate-limit", 20); this.alwaysTickPlayers = (boolean) this.getConfig("level-settings.always-tick-players", false); this.baseTickRate = (int) this.getConfig("level-settings.base-tick-rate", 1); this.scheduler = new ServerScheduler(); if (this.getPropertyBoolean("enable-rcon", false)) { this.rcon = new RCON(this, this.getPropertyString("rcon.password", ""), (!this.getIp().equals("")) ? this.getIp() : "0.0.0.0", this.getPropertyInt("rcon.port", this.getPort())); } this.entityMetadata = new EntityMetadataStore(); this.playerMetadata = new PlayerMetadataStore(); this.levelMetadata = new LevelMetadataStore(); this.operators = new Config(this.dataPath + "ops.txt", Config.ENUM); this.whitelist = new Config(this.dataPath + "white-list.txt", Config.ENUM); this.banByName = new BanList(this.dataPath + "banned-players.json"); this.banByName.load(); this.banByIP = new BanList(this.dataPath + "banned-ips.json"); this.banByIP.load(); this.maxPlayers = this.getPropertyInt("max-players", 20); this.setAutoSave(this.getPropertyBoolean("auto-save", true)); if (this.getPropertyBoolean("hardcore", false) && this.getDifficulty() < 3) { this.setPropertyInt("difficulty", 3); } Nukkit.DEBUG = (int) this.getConfig("debug.level", 1); if (this.logger instanceof MainLogger) { this.logger.setLogDebug(Nukkit.DEBUG > 1); } this.logger.info(this.getLanguage().translateString("nukkit.server.networkStart", new String[] { this.getIp().equals("") ? "*" : this.getIp(), String.valueOf(this.getPort()) })); this.serverID = UUID.randomUUID(); this.network = new Network(this); this.network.setName(this.getMotd()); this.logger.info(this.getLanguage().translateString("nukkit.server.info", this.getName(), TextFormat.YELLOW + this.getNukkitVersion() + TextFormat.WHITE, TextFormat.AQUA + this.getCodename() + TextFormat.WHITE, this.getApiVersion())); this.logger.info(this.getLanguage().translateString("nukkit.server.license", this.getName())); this.consoleSender = new ConsoleCommandSender(); this.commandMap = new SimpleCommandMap(this); this.registerEntities(); this.registerBlockEntities(); Block.init(); Enchantment.init(); Item.init(); Biome.init(); Effect.init(); Potion.init(); Attribute.init(); this.craftingManager = new CraftingManager(); this.resourcePackManager = new ResourcePackManager(new File(Nukkit.DATA_PATH, "resource_packs")); this.pluginManager = new PluginManager(this, this.commandMap); this.pluginManager.subscribeToPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE, this.consoleSender); this.pluginManager.registerInterface(JavaPluginLoader.class); this.queryRegenerateEvent = new QueryRegenerateEvent(this, 5); this.network.registerInterface(new RakNetInterface(this)); Calendar now = Calendar.getInstance(); int y = now.get(Calendar.YEAR); int mo = now.get(Calendar.MONTH) + 1; int d = now.get(Calendar.DATE); int h = now.get(Calendar.HOUR_OF_DAY); int m = now.get(Calendar.MINUTE); int s = now.get(Calendar.SECOND); this.logger.info(TextFormat.AQUA + "=================================================================================="); this.logger.info(TextFormat.AQUA + ""); this.logger.info( " || || || || || || || ||"); this.logger.info(" | | | | | | | || | | | | | | | | || |"); this.logger.info(" | | | | | | | | | | | | | | | | "); this.logger.info(" _| | | | | | | | | | | | | | | | "); this.logger.info(" |____| |_____| |_| |__| |__| | | |_| _|"); this.logger.info(""); this.logger.info(TextFormat.AQUA + ""); this.logger.info(TextFormat.AQUA + "----------------------------------------------------------------------------------"); this.logger.info(TextFormat.GREEN + "Jupiter - Nukkit Fork"); this.logger.info(TextFormat.YELLOW + "JupiterDevelopmentTeam "); this.logger.info(TextFormat.AQUA + "----------------------------------------------------------------------------------"); this.logger.info( ": " + TextFormat.BLUE + y + "/" + mo + "/" + d + " " + h + "" + m + "" + s + ""); this.logger.info("???: " + TextFormat.GREEN + this.getMotd()); this.logger.info("ip: " + TextFormat.GREEN + this.getIp()); this.logger.info("?: " + TextFormat.GREEN + this.getPort()); this.logger.info("Nukkit?: " + TextFormat.LIGHT_PURPLE + this.getNukkitVersion()); this.logger.info("API?: " + TextFormat.LIGHT_PURPLE + this.getApiVersion()); this.logger.info("?: " + TextFormat.LIGHT_PURPLE + this.getCodename()); this.logger.info(TextFormat.AQUA + "=================================================================================="); if (this.getJupiterConfigBoolean("jupiter-compiler-mode")) { this.logger.info(TextFormat.YELLOW + "----------------------------------------------------------------------------------"); getLogger().info(TextFormat.AQUA + "?????..."); File f = new File(dataPath + "compileOrder/"); File[] list = f.listFiles(); for (int i = 0; i < list.length; i++) { if (new PluginCompiler().Compile(list[i])) getLogger().info(list[i].toPath().toString() + " :" + TextFormat.GREEN + ""); else getLogger().info(list[i].toPath().toString() + " :" + TextFormat.RED + ""); } this.logger.info(TextFormat.YELLOW + "----------------------------------------------------------------------------------"); } this.logger.info(TextFormat.LIGHT_PURPLE + "----------------------------------------------------------------------------------"); getLogger().info(TextFormat.AQUA + "?????..."); this.pluginManager.loadPlugins(this.pluginPath); this.enablePlugins(PluginLoadOrder.STARTUP); LevelProviderManager.addProvider(this, Anvil.class); LevelProviderManager.addProvider(this, McRegion.class); LevelProviderManager.addProvider(this, LevelDB.class); Generator.addGenerator(Flat.class, "flat", Generator.TYPE_FLAT); Generator.addGenerator(Normal.class, "normal", Generator.TYPE_INFINITE); Generator.addGenerator(Normal.class, "default", Generator.TYPE_INFINITE); Generator.addGenerator(Nether.class, "nether", Generator.TYPE_NETHER); //todo: add old generator and hell generator for (String name : ((Map<String, Object>) this.getConfig("worlds", new HashMap<>())).keySet()) { if (!this.loadLevel(name)) { long seed; try { seed = ((Integer) this.getConfig("worlds." + name + ".seed")).longValue(); } catch (Exception e) { seed = System.currentTimeMillis(); } Map<String, Object> options = new HashMap<>(); String[] opts = ((String) this.getConfig("worlds." + name + ".generator", Generator.getGenerator("default").getSimpleName())).split(":"); Class<? extends Generator> generator = Generator.getGenerator(opts[0]); if (opts.length > 1) { String preset = ""; for (int i = 1; i < opts.length; i++) { preset += opts[i] + ":"; } preset = preset.substring(0, preset.length() - 1); options.put("preset", preset); } this.generateLevel(name, seed, generator, options); } } if (this.getDefaultLevel() == null) { String defaultName = this.getPropertyString("level-name", "world"); if (defaultName == null || "".equals(defaultName.trim())) { this.getLogger().warning("level-name cannot be null, using default"); defaultName = "world"; this.setPropertyString("level-name", defaultName); } if (!this.loadLevel(defaultName)) { long seed; String seedString = String.valueOf(this.getProperty("level-seed", System.currentTimeMillis())); try { seed = Long.valueOf(seedString); } catch (NumberFormatException e) { seed = seedString.hashCode(); } this.generateLevel(defaultName, seed == 0 ? System.currentTimeMillis() : seed); } this.setDefaultLevel(this.getLevelByName(defaultName)); } this.properties.save(true); if (this.getDefaultLevel() == null) { this.getLogger().emergency(this.getLanguage().translateString("nukkit.level.defaultError")); this.forceShutdown(); return; } if ((int) this.getConfig("ticks-per.autosave", 6000) > 0) { this.autoSaveTicks = (int) this.getConfig("ticks-per.autosave", 6000); } this.enablePlugins(PluginLoadOrder.POSTWORLD); this.logger.info(TextFormat.LIGHT_PURPLE + "----------------------------------------------------------------------------------"); this.start(); }
From source file:org.apache.maven.plugin.issues.IssuesReportHelper.java
/** * Get a list of id:s for the columns that are to be included in the report. * This method also handles deprecated column names, which will still work. * If deprecated column names are used they generate a warning, indicating * the replacement column name./*w w w . jav a 2s .c om*/ * * @param columnNames The names of the columns * @param allColumns A mapping from column name to column id * @param deprecatedColumns A mapping from deprecated column name to column id * @param log A log * @return A List of column id:s */ public static List<Integer> getColumnIds(String columnNames, Map<String, Integer> allColumns, Map<String, Integer> deprecatedColumns, Log log) { DualHashBidiMap bidiColumns = null; List<Integer> columnIds = new ArrayList<Integer>(); String[] columnNamesArray = columnNames.split(","); if (deprecatedColumns != null) { bidiColumns = new DualHashBidiMap(allColumns); } // Loop through the names of the columns, to validate each of them and add their id to the list for (String aColumnNamesArray : columnNamesArray) { String columnName = aColumnNamesArray.trim(); if (allColumns.containsKey(columnName)) { columnIds.add(allColumns.get(columnName)); } else if (deprecatedColumns != null && deprecatedColumns.containsKey(columnName)) { Integer columnId = deprecatedColumns.get(columnName); columnIds.add(columnId); if (log != null) { log.warn("The columnName '" + columnName + "' has been deprecated." + " Please use " + "the columnName '" + bidiColumns.getKey(columnId) + "' instead."); } } } return columnIds; }
From source file:org.kuali.kpme.core.inquirable.KPMEInquirableImpl.java
@Override // copied the getInquiryUrl() from KualiInquirableImpl and added effectiveDate to parameters public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { Properties parameters = new Properties(); AnchorHtmlData hRef = new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING); parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start"); Class inquiryBusinessObjectClass = null; String attributeRefName = ""; boolean isPkReference = false; boolean doesNestedReferenceHaveOwnPrimitiveReference = false; BusinessObject nestedBusinessObject = null; if (attributeName .equals(getBusinessObjectDictionaryService().getTitleAttribute(businessObject.getClass()))) { inquiryBusinessObjectClass = businessObject.getClass(); isPkReference = true;/* w w w. j a v a 2s .c o m*/ } else { if (ObjectUtils.isNestedAttribute(attributeName)) { // if we have a reference object, we should determine if we should either provide an inquiry link to // the reference object itself, or some other nested primitive. // for example, if the attribute is "referenceObject.someAttribute", and there is no primitive reference for // "someAttribute", then an inquiry link is provided to the "referenceObject". If it does have a primitive reference, then // the inquiry link is directed towards it instead String nestedReferenceName = ObjectUtils.getNestedAttributePrefix(attributeName); Object nestedReferenceObject = ObjectUtils.getNestedValue(businessObject, nestedReferenceName); if (ObjectUtils.isNotNull(nestedReferenceObject) && nestedReferenceObject instanceof BusinessObject) { nestedBusinessObject = (BusinessObject) nestedReferenceObject; String nestedAttributePrimitive = ObjectUtils.getNestedAttributePrimitive(attributeName); if (nestedAttributePrimitive.equals(getBusinessObjectDictionaryService() .getTitleAttribute(nestedBusinessObject.getClass()))) { // we are going to inquiry the record that contains the attribute we're rendering an inquiry URL for inquiryBusinessObjectClass = nestedBusinessObject.getClass(); // I know it's already set to false, just to show how this variable is set doesNestedReferenceHaveOwnPrimitiveReference = false; } else { Map primitiveReference = LookupUtils.getPrimitiveReference(nestedBusinessObject, nestedAttributePrimitive); if (primitiveReference != null && !primitiveReference.isEmpty()) { attributeRefName = (String) primitiveReference.keySet().iterator().next(); inquiryBusinessObjectClass = (Class) primitiveReference.get(attributeRefName); doesNestedReferenceHaveOwnPrimitiveReference = true; } else { // we are going to inquiry the record that contains the attribute we're rendering an inquiry URL for inquiryBusinessObjectClass = nestedBusinessObject.getClass(); // I know it's already set to false, just to show how this variable is set doesNestedReferenceHaveOwnPrimitiveReference = false; } } } } else { Map primitiveReference = LookupUtils.getPrimitiveReference(businessObject, attributeName); if (primitiveReference != null && !primitiveReference.isEmpty()) { attributeRefName = (String) primitiveReference.keySet().iterator().next(); inquiryBusinessObjectClass = (Class) primitiveReference.get(attributeRefName); } } } if (inquiryBusinessObjectClass != null && DocumentHeader.class.isAssignableFrom(inquiryBusinessObjectClass)) { String documentNumber = (String) ObjectUtils.getPropertyValue(businessObject, attributeName); if (!StringUtils.isBlank(documentNumber)) { // if NullPointerException on the following line, maybe the Spring bean wasn't injected w/ KualiConfigurationException, or if // instances of a sub-class of this class are not Spring created, then override getKualiConfigurationService() in the subclass // to return the configuration service from a Spring service locator (or set it). hRef.setHref(getKualiConfigurationService().getPropertyValueAsString(KRADConstants.WORKFLOW_URL_KEY) + KRADConstants.DOCHANDLER_DO_URL + documentNumber + KRADConstants.DOCHANDLER_URL_CHUNK); } return hRef; } if (inquiryBusinessObjectClass == null || getBusinessObjectDictionaryService().isInquirable(inquiryBusinessObjectClass) == null || !getBusinessObjectDictionaryService().isInquirable(inquiryBusinessObjectClass).booleanValue()) { return hRef; } synchronized (SUPER_CLASS_TRANSLATOR_LIST) { for (Class clazz : SUPER_CLASS_TRANSLATOR_LIST) { if (clazz.isAssignableFrom(inquiryBusinessObjectClass)) { inquiryBusinessObjectClass = clazz; break; } } } if (!inquiryBusinessObjectClass.isInterface() && ExternalizableBusinessObject.class.isAssignableFrom(inquiryBusinessObjectClass)) { inquiryBusinessObjectClass = ExternalizableBusinessObjectUtils .determineExternalizableBusinessObjectSubInterface(inquiryBusinessObjectClass); } parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, inquiryBusinessObjectClass.getName()); // listPrimaryKeyFieldNames returns an unmodifiable list. So a copy is necessary. List<String> keys = new ArrayList<String>( getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(inquiryBusinessObjectClass)); if (keys == null) { keys = Collections.emptyList(); } DataObjectRelationship businessObjectRelationship = null; if (attributeRefName != null && !"".equals(attributeRefName)) { businessObjectRelationship = getBusinessObjectMetaDataService() .getBusinessObjectRelationship(businessObject, attributeRefName); if (businessObjectRelationship != null && businessObjectRelationship.getParentToChildReferences() != null) { for (String targetNamePrimaryKey : businessObjectRelationship.getParentToChildReferences() .values()) { keys.add(targetNamePrimaryKey); } } } // build key value url parameters used to retrieve the business object String keyName = null; String keyConversion = null; Map<String, String> fieldList = new HashMap<String, String>(); for (Iterator iter = keys.iterator(); iter.hasNext();) { keyName = (String) iter.next(); keyConversion = keyName; if (ObjectUtils.isNestedAttribute(attributeName)) { if (doesNestedReferenceHaveOwnPrimitiveReference) { String nestedAttributePrefix = ObjectUtils.getNestedAttributePrefix(attributeName); //String foreignKeyFieldName = getBusinessObjectMetaDataService().getForeignKeyFieldName( // inquiryBusinessObjectClass.getClass(), attributeRefName, keyName); String foreignKeyFieldName = getBusinessObjectMetaDataService() .getForeignKeyFieldName(nestedBusinessObject.getClass(), attributeRefName, keyName); keyConversion = nestedAttributePrefix + "." + foreignKeyFieldName; } else { keyConversion = ObjectUtils.getNestedAttributePrefix(attributeName) + "." + keyName; } } else { if (isPkReference) { keyConversion = keyName; } else if (businessObjectRelationship != null) { //Using BusinessObjectMetaDataService instead of PersistenceStructureService //since otherwise, relationship information from datadictionary is not used at all //Also, BOMDS.getBusinessObjectRelationship uses PersistenceStructureService, //so both datadictionary and the persistance layer get covered /* BusinessObjectRelationship businessObjectRelationship = getBusinessObjectMetaDataService().getBusinessObjectRelationship( businessObject, attributeRefName); */ BidiMap bidiMap = new DualHashBidiMap(businessObjectRelationship.getParentToChildReferences()); keyConversion = (String) bidiMap.getKey(keyName); //keyConversion = getPersistenceStructureService().getForeignKeyFieldName(businessObject.getClass(), attributeRefName, keyName); } } Object keyValue = null; if (keyConversion != null) { keyValue = ObjectUtils.getPropertyValue(businessObject, keyConversion); } if (keyValue == null) { keyValue = ""; } else if (keyValue instanceof Date) { //format the date for passing in url if (Formatter.findFormatter(keyValue.getClass()) != null) { Formatter formatter = Formatter.getFormatter(keyValue.getClass()); keyValue = (String) formatter.format(keyValue); } } else { keyValue = keyValue.toString(); } // Encrypt value if it is a field that has restriction that prevents a value from being shown to user, // because we don't want the browser history to store the restricted attribute's value in the URL AttributeSecurity attributeSecurity = KNSServiceLocator.getDataDictionaryService() .getAttributeSecurity(businessObject.getClass().getName(), keyName); if (attributeSecurity != null && attributeSecurity.hasRestrictionThatRemovesValueFromUI()) { try { keyValue = getEncryptionService().encrypt(keyValue); } catch (GeneralSecurityException e) { LOG.error("Exception while trying to encrypted value for inquiry framework.", e); throw new RuntimeException(e); } } parameters.put(keyName, keyValue); fieldList.put(keyName, keyValue.toString()); } // pass in effective date of the businessObject Date aDate = (Date) ObjectUtils.getPropertyValue(businessObject, "effectiveDate"); if (aDate != null) { parameters.put("effectiveDate", new SimpleDateFormat("MM/dd/yyyy").format(aDate)); } return getHyperLink(inquiryBusinessObjectClass, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters)); }
From source file:org.kuali.rice.kns.inquiry.KualiInquirableImpl.java
/** * Helper method to build an inquiry url for a result field. * //from w w w . j av a 2 s .c o m * @param bo * the business object instance to build the urls for * @param propertyName * the property which links to an inquirable * @return String url to inquiry */ @Deprecated public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { Properties parameters = new Properties(); AnchorHtmlData hRef = new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING); parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start"); Class inquiryBusinessObjectClass = null; String attributeRefName = ""; boolean isPkReference = false; boolean doesNestedReferenceHaveOwnPrimitiveReference = false; BusinessObject nestedBusinessObject = null; Class businessObjectClass = ObjectUtils.materializeClassForProxiedObject(businessObject); if (attributeName.equals(getBusinessObjectDictionaryService().getTitleAttribute(businessObjectClass))) { inquiryBusinessObjectClass = businessObjectClass; isPkReference = true; } else { if (ObjectUtils.isNestedAttribute(attributeName)) { // if we have a reference object, we should determine if we // should either provide an inquiry link to // the reference object itself, or some other nested primitive. // for example, if the attribute is // "referenceObject.someAttribute", and there is no primitive // reference for // "someAttribute", then an inquiry link is provided to the // "referenceObject". If it does have a primitive reference, // then // the inquiry link is directed towards it instead String nestedReferenceName = ObjectUtils.getNestedAttributePrefix(attributeName); Object nestedReferenceObject = ObjectUtils.getNestedValue(businessObject, nestedReferenceName); if (ObjectUtils.isNotNull(nestedReferenceObject) && nestedReferenceObject instanceof BusinessObject) { nestedBusinessObject = (BusinessObject) nestedReferenceObject; String nestedAttributePrimitive = ObjectUtils.getNestedAttributePrimitive(attributeName); Class nestedBusinessObjectClass = ObjectUtils .materializeClassForProxiedObject(nestedBusinessObject); if (nestedAttributePrimitive.equals( getBusinessObjectDictionaryService().getTitleAttribute(nestedBusinessObjectClass))) { // we are going to inquiry the record that contains the // attribute we're rendering an inquiry URL for inquiryBusinessObjectClass = nestedBusinessObjectClass; // I know it's already set to false, just to show how // this variable is set doesNestedReferenceHaveOwnPrimitiveReference = false; } else { Map primitiveReference = LookupUtils.getPrimitiveReference(nestedBusinessObject, nestedAttributePrimitive); if (primitiveReference != null && !primitiveReference.isEmpty()) { attributeRefName = (String) primitiveReference.keySet().iterator().next(); inquiryBusinessObjectClass = (Class) primitiveReference.get(attributeRefName); doesNestedReferenceHaveOwnPrimitiveReference = true; } else { // we are going to inquiry the record that contains // the attribute we're rendering an inquiry URL for inquiryBusinessObjectClass = ObjectUtils .materializeClassForProxiedObject(nestedBusinessObject); // I know it's already set to false, just to show // how this variable is set doesNestedReferenceHaveOwnPrimitiveReference = false; } } } } else { Map primitiveReference = LookupUtils.getPrimitiveReference(businessObject, attributeName); if (primitiveReference != null && !primitiveReference.isEmpty()) { attributeRefName = (String) primitiveReference.keySet().iterator().next(); inquiryBusinessObjectClass = (Class) primitiveReference.get(attributeRefName); } } } if (inquiryBusinessObjectClass != null && DocumentHeader.class.isAssignableFrom(inquiryBusinessObjectClass)) { String documentNumber = (String) ObjectUtils.getPropertyValue(businessObject, attributeName); if (!StringUtils.isBlank(documentNumber)) { // if NullPointerException on the following line, maybe the // Spring bean wasn't injected w/ KualiConfigurationException, // or if // instances of a sub-class of this class are not Spring // created, then override getKualiConfigurationService() in the // subclass // to return the configuration service from a Spring service // locator (or set it). hRef.setHref(getKualiConfigurationService().getPropertyValueAsString(KRADConstants.WORKFLOW_URL_KEY) + KRADConstants.DOCHANDLER_DO_URL + documentNumber + KRADConstants.DOCHANDLER_URL_CHUNK); } return hRef; } if (inquiryBusinessObjectClass == null || getBusinessObjectDictionaryService().isInquirable(inquiryBusinessObjectClass) == null || !getBusinessObjectDictionaryService().isInquirable(inquiryBusinessObjectClass).booleanValue()) { return hRef; } synchronized (SUPER_CLASS_TRANSLATOR_LIST) { for (Class clazz : SUPER_CLASS_TRANSLATOR_LIST) { if (clazz.isAssignableFrom(inquiryBusinessObjectClass)) { inquiryBusinessObjectClass = clazz; break; } } } if (!inquiryBusinessObjectClass.isInterface() && ExternalizableBusinessObject.class.isAssignableFrom(inquiryBusinessObjectClass)) { inquiryBusinessObjectClass = ExternalizableBusinessObjectUtils .determineExternalizableBusinessObjectSubInterface(inquiryBusinessObjectClass); } parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, inquiryBusinessObjectClass.getName()); // listPrimaryKeyFieldNames returns an unmodifiable list. So a copy is // necessary. List<String> keys = new ArrayList<String>( KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(inquiryBusinessObjectClass)); if (keys == null) { keys = Collections.emptyList(); } DataObjectRelationship dataObjectRelationship = null; if (attributeRefName != null && !"".equals(attributeRefName)) { dataObjectRelationship = getBusinessObjectMetaDataService() .getBusinessObjectRelationship(businessObject, attributeRefName); if (dataObjectRelationship != null && dataObjectRelationship.getParentToChildReferences() != null) { for (String targetNamePrimaryKey : dataObjectRelationship.getParentToChildReferences().values()) { keys.add(targetNamePrimaryKey); } } } // build key value url parameters used to retrieve the business object String keyName = null; String keyConversion = null; Map<String, String> fieldList = new HashMap<String, String>(); for (Iterator iter = keys.iterator(); iter.hasNext();) { keyName = (String) iter.next(); keyConversion = keyName; if (ObjectUtils.isNestedAttribute(attributeName)) { if (doesNestedReferenceHaveOwnPrimitiveReference) { String nestedAttributePrefix = ObjectUtils.getNestedAttributePrefix(attributeName); // String foreignKeyFieldName = // getBusinessObjectMetaDataService().getForeignKeyFieldName( // inquiryBusinessObjectClass.getClass(), attributeRefName, // keyName); String foreignKeyFieldName = getBusinessObjectMetaDataService() .getForeignKeyFieldName(nestedBusinessObject.getClass(), attributeRefName, keyName); keyConversion = nestedAttributePrefix + "." + foreignKeyFieldName; } else { keyConversion = ObjectUtils.getNestedAttributePrefix(attributeName) + "." + keyName; } } else { if (isPkReference) { keyConversion = keyName; } else if (dataObjectRelationship != null) { // Using BusinessObjectMetaDataService instead of // PersistenceStructureService // since otherwise, relationship information from // datadictionary is not used at all // Also, BOMDS.getBusinessObjectRelationship uses // PersistenceStructureService, // so both datadictionary and the persistance layer get // covered /* * DataObjectRelationship dataObjectRelationship = * getBusinessObjectMetaDataService * ().getBusinessObjectRelationship( businessObject, * attributeRefName); */ BidiMap bidiMap = new DualHashBidiMap(dataObjectRelationship.getParentToChildReferences()); keyConversion = (String) bidiMap.getKey(keyName); // keyConversion = // getPersistenceStructureService().getForeignKeyFieldName(businessObject.getClass(), // attributeRefName, keyName); } } Object keyValue = null; if (keyConversion != null) { keyValue = ObjectUtils.getPropertyValue(businessObject, keyConversion); } if (keyValue == null) { keyValue = ""; } else if (keyValue instanceof java.sql.Date) { // format the date for // passing in url if (Formatter.findFormatter(keyValue.getClass()) != null) { Formatter formatter = Formatter.getFormatter(keyValue.getClass()); keyValue = (String) formatter.format(keyValue); } } else { keyValue = keyValue.toString(); } // Encrypt value if it is a field that has restriction that prevents // a value from being shown to user, // because we don't want the browser history to store the restricted // attribute's value in the URL AttributeSecurity attributeSecurity = KRADServiceLocatorWeb.getDataDictionaryService() .getAttributeSecurity(businessObject.getClass().getName(), keyName); if (attributeSecurity != null && attributeSecurity.hasRestrictionThatRemovesValueFromUI()) { try { if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { keyValue = getEncryptionService().encrypt(keyValue); } } catch (GeneralSecurityException e) { LOG.error("Exception while trying to encrypted value for inquiry framework.", e); throw new RuntimeException(e); } } parameters.put(keyName, keyValue); fieldList.put(keyName, keyValue.toString()); } return getHyperLink(inquiryBusinessObjectClass, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters)); }