List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.aliyun.odps.ogg.handler.datahub.ConfigureReader.java
public static Configure reader(String configueFileName) throws DocumentException { logger.info("Begin read configure[" + configueFileName + "]"); Configure configure = new Configure(); SAXReader reader = new SAXReader(); File file = new File(configueFileName); Document document = reader.read(file); Element root = document.getRootElement(); String elementText = root.elementTextTrim("batchSize"); if (StringUtils.isNotBlank(elementText)) { configure.setBatchSize(Integer.parseInt(elementText)); }//from w ww . j av a2 s . c o m elementText = root.elementTextTrim("dirtyDataContinue"); if (StringUtils.isNotBlank(elementText)) { configure.setDirtyDataContinue(Boolean.parseBoolean(elementText)); } elementText = root.elementTextTrim("dirtyDataFile"); if (StringUtils.isNotBlank(elementText)) { configure.setDirtyDataFile(elementText); } elementText = root.elementTextTrim("dirtyDataFileMaxSize"); if (StringUtils.isNotBlank(elementText)) { configure.setDirtyDataFileMaxSize(Integer.parseInt(elementText)); } elementText = root.elementTextTrim("retryTimes"); if (StringUtils.isNotBlank(elementText)) { configure.setRetryTimes(Integer.parseInt(elementText)); } elementText = root.elementTextTrim("retryInterval"); if (StringUtils.isNotBlank(elementText)) { configure.setRetryInterval(Integer.parseInt(elementText)); } elementText = root.elementTextTrim("disableCheckPointFile"); if (StringUtils.isNotBlank(elementText)) { configure.setDisableCheckPointFile(Boolean.parseBoolean(elementText)); } elementText = root.elementTextTrim("checkPointFileName"); if (StringUtils.isNotBlank(elementText)) { configure.setCheckPointFileName(elementText); } Element element = root.element("defaultOracleConfigure"); if (element == null) { throw new RuntimeException("defaultOracleConfigure is null"); } elementText = element.elementTextTrim("sid"); if (StringUtils.isBlank(elementText)) { throw new RuntimeException("defaultOracleConfigure.sid is null"); } configure.setSid(elementText); String defaultOracleSchema = element.elementTextTrim("schema"); SimpleDateFormat defaultSimpleDateFormat; elementText = element.elementTextTrim("dateFormat"); if (StringUtils.isNotBlank(elementText)) { defaultSimpleDateFormat = new SimpleDateFormat(elementText); } else { defaultSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } element = root.element("defalutDatahubConfigure"); if (element == null) { throw new RuntimeException("defalutDatahubConfigure is null"); } String endPoint = element.elementText("endPoint"); if (StringUtils.isBlank(endPoint)) { throw new RuntimeException("defalutDatahubConfigure.endPoint is null"); } String defaultDatahubProject = element.elementText("project"); String defaultDatahubAccessID = element.elementText("accessId"); String defaultDatahubAccessKey = element.elementText("accessKey"); Field defaultCTypeField = null; String defaultCTypeColumn = element.elementText("ctypeColumn"); if (StringUtils.isNotBlank(defaultCTypeColumn)) { defaultCTypeField = new Field(defaultCTypeColumn, FieldType.STRING); } Field defaultCTimeField = null; String defaultCTimeColumn = element.elementText("ctimeColumn"); if (StringUtils.isNotBlank(defaultCTimeColumn)) { defaultCTimeField = new Field(defaultCTimeColumn, FieldType.STRING); } Field defaultCidField = null; String defaultCidColumn = element.elementText("cidColumn"); if (StringUtils.isNotBlank(defaultCidColumn)) { defaultCidField = new Field(defaultCidColumn, FieldType.STRING); } String defaultConstColumnMapStr = element.elementText("constColumnMap"); Map<String, String> defalutConstColumnMappings = Maps.newHashMap(); Map<String, Field> defaultConstColumnFieldMappings = Maps.newHashMap(); parseConstColumnMap(defaultConstColumnMapStr, defalutConstColumnMappings, defaultConstColumnFieldMappings); element = root.element("mappings"); if (element == null) { throw new RuntimeException("mappings is null"); } List<Element> mappingElements = element.elements("mapping"); if (mappingElements == null || mappingElements.size() == 0) { throw new RuntimeException("mappings.mapping is null"); } //init table mapping for (Element e : mappingElements) { String oracleSchema = e.elementTextTrim("oracleSchema"); if (StringUtils.isNotBlank(oracleSchema)) { //nothing } else if (StringUtils.isNotBlank(defaultOracleSchema)) { oracleSchema = defaultOracleSchema; } else { throw new RuntimeException( "both mappings.mapping.oracleSchema and defaultOracleConfigure.schema is null"); } String oracleTable = e.elementTextTrim("oracleTable"); if (StringUtils.isBlank(oracleTable)) { throw new RuntimeException("mappings.mapping.oracleTable is null"); } String datahubProject = e.elementTextTrim("datahubProject"); if (StringUtils.isNotBlank(datahubProject)) { //nothing } else if (StringUtils.isNotBlank(defaultOracleSchema)) { datahubProject = defaultDatahubProject; } else { throw new RuntimeException( "both mappings.mapping.datahubProject and defalutDatahubConfigure.project is null"); } String datahubAccessId = e.elementTextTrim("datahubAccessId"); if (StringUtils.isNotBlank(datahubAccessId)) { //nothing } else if (StringUtils.isNotBlank(defaultDatahubAccessID)) { datahubAccessId = defaultDatahubAccessID; } else { throw new RuntimeException( "both mappings.mapping.datahubAccessId and defalutDatahubConfigure.accessId is null"); } String datahubAccessKey = e.elementTextTrim("datahubAccessKey"); if (StringUtils.isNotBlank(datahubAccessKey)) { //nothing } else if (StringUtils.isNotBlank(defaultDatahubAccessKey)) { datahubAccessKey = defaultDatahubAccessKey; } else { throw new RuntimeException( "both mappings.mapping.datahubAccessKey and defalutDatahubConfigure.accessKey is null"); } String topicName = e.elementTextTrim("datahubTopic"); if (topicName == null) { throw new RuntimeException("mappings.mapping.datahubTopic is null"); } String ctypeColumn = e.elementText("ctypeColumn"); String ctimeColumn = e.elementText("ctimeColumn"); String cidColumn = e.elementText("cidColumn"); DatahubConfiguration datahubConfiguration = new DatahubConfiguration( new AliyunAccount(datahubAccessId, datahubAccessKey), endPoint); Project project = Project.Builder.build(datahubProject, datahubConfiguration); Topic topic = project.getTopic(topicName); if (topic == null) { throw new RuntimeException("Can not find datahub topic[" + topicName + "]"); } else { logger.info( "topic name: " + topicName + ", topic schema: " + topic.getRecordSchema().toJsonString()); } TableMapping tableMapping = new TableMapping(); tableMapping.setTopic(topic); tableMapping.setOracleSchema(oracleSchema.toLowerCase()); tableMapping.setOracleTableName(oracleTable.toLowerCase()); tableMapping.setOracleFullTableName( tableMapping.getOracleSchema() + "." + tableMapping.getOracleTableName()); tableMapping .setCtypeField(StringUtils.isNotBlank(ctypeColumn) ? new Field(ctypeColumn, FieldType.STRING) : defaultCTypeField); tableMapping .setCtimeField(StringUtils.isNotBlank(ctimeColumn) ? new Field(ctimeColumn, FieldType.STRING) : defaultCTimeField); tableMapping.setCidField( StringUtils.isNotBlank(cidColumn) ? new Field(cidColumn, FieldType.STRING) : defaultCidField); String constColumnMapStr = e.elementText("constColumnMap"); Map<String, String> constColumnMappings = Maps.newHashMap(); Map<String, Field> constColumnFieldMappings = Maps.newHashMap(); parseConstColumnMap(constColumnMapStr, constColumnMappings, constColumnFieldMappings); tableMapping.setConstColumnMappings( constColumnMappings.isEmpty() ? defalutConstColumnMappings : constColumnMappings); tableMapping.setConstFieldMappings(constColumnFieldMappings.isEmpty() ? defaultConstColumnFieldMappings : constColumnFieldMappings); Map<String, ColumnMapping> columnMappings = Maps.newHashMap(); tableMapping.setColumnMappings(columnMappings); elementText = e.elementTextTrim("shardId"); if (StringUtils.isNotBlank(elementText)) { tableMapping.setShardId(elementText); } configure.addTableMapping(tableMapping); RecordSchema recordSchema = topic.getRecordSchema(); Element columnMappingElement = e.element("columnMapping"); List<Element> columns = columnMappingElement.elements("column"); for (Element columnElement : columns) { String oracleColumnName = columnElement.attributeValue("src"); if (StringUtils.isBlank(oracleColumnName)) { throw new RuntimeException("Topic[" + topicName + "] src attribute is null"); } oracleColumnName = oracleColumnName.toLowerCase(); ColumnMapping columnMapping = new ColumnMapping(); columnMappings.put(oracleColumnName, columnMapping); columnMapping.setOracleColumnName(oracleColumnName); String datahubFieldName = columnElement.attributeValue("dest"); if (datahubFieldName == null) { throw new RuntimeException("Topic[" + topicName + "] dest attribute is null"); } Field field = recordSchema.getField(datahubFieldName.toLowerCase()); if (field == null) { throw new RuntimeException( "Topic[" + topicName + "] Field[" + datahubFieldName + "] is not exist"); } columnMapping.setField(field); String datahubOldFieldName = columnElement.attributeValue("destOld"); if (StringUtils.isNotBlank(datahubOldFieldName)) { Field oldField = recordSchema.getField(datahubOldFieldName); if (field == null) { throw new RuntimeException( "Topic[" + topicName + "] Field[" + datahubOldFieldName + "] is not exist"); } columnMapping.setOldFiled(oldField); } String isShardColumn = columnElement.attributeValue("isShardColumn"); if (StringUtils.isNotBlank(isShardColumn) && Boolean.TRUE.equals(Boolean.valueOf(isShardColumn))) { tableMapping.setIsShardHash(true); columnMapping.setIsShardColumn(true); } else { columnMapping.setIsShardColumn(false); } String isKeyColumn = columnElement.attributeValue("isKeyColumn"); if (StringUtils.isNotBlank(isKeyColumn) && Boolean.TRUE.equals(Boolean.valueOf(isKeyColumn))) { columnMapping.setIsKeyColumn(true); } else { columnMapping.setIsKeyColumn(false); } String dateFormat = columnElement.attributeValue("dateFormat"); if (StringUtils.isNotBlank(dateFormat)) { columnMapping.setSimpleDateFormat(new SimpleDateFormat(dateFormat)); } else { columnMapping.setSimpleDateFormat(defaultSimpleDateFormat); } String isDateFormat = columnElement.attributeValue("isDateFormat"); if (StringUtils.isNotBlank(isDateFormat) && Boolean.FALSE.equals(Boolean.valueOf(isDateFormat))) { columnMapping.setIsDateFormat(false); } else { columnMapping.setIsDateFormat(true); } } } logger.info("Read configure success: " + JsonHelper.beanToJson(configure)); return configure; }
From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java
/** * Get hours from timeSpan/*from w ww. ja va2 s . c om*/ * * @param timeUnitsMap * @return */ private static Double getHours(Map<String, Double> timeUnitsMap) { if (timeUnitsMap == null || timeUnitsMap.isEmpty()) { return null; } Double year = timeUnitsMap.get(MSPROJECT_TIME_UNITS.YEAR); Double month = timeUnitsMap.get(MSPROJECT_TIME_UNITS.MONTH); Double days = timeUnitsMap.get(MSPROJECT_TIME_UNITS.DAY); Double hours = timeUnitsMap.get(MSPROJECT_TIME_UNITS.HOUR); Double minutes = timeUnitsMap.get(MSPROJECT_TIME_UNITS.MINUTE); Double seconds = timeUnitsMap.get(MSPROJECT_TIME_UNITS.SECOND); double doubleHours = 0.0; if (year != null) { doubleHours += year.doubleValue() * 8 * 20 * 12; } if (month != null) { doubleHours += month.doubleValue() * 8 * 20; } if (days != null) { doubleHours += days.doubleValue() * 8; } if (hours != null) { doubleHours = hours.doubleValue(); } if (minutes != null) { doubleHours += minutes.doubleValue() / 60; } if (seconds != null) { doubleHours += seconds.doubleValue() / (60 * 60); } return AccountingBL.roundToDecimalDigits(doubleHours, true); }
From source file:net.firejack.platform.core.utils.db.DBUtils.java
private static String populateInsertQuery(TablesMapping mapping) { Map<Column, Column> columnMapping = mapping.getColumnMapping(); StringBuilder insertQuery = new StringBuilder("insert into "); insertQuery.append(mapping.getTargetTable().getName()).append('('); Set<Map.Entry<Column, Column>> columnEntries = columnMapping.entrySet(); for (Map.Entry<Column, Column> entry : columnEntries) { Column targetColumn = entry.getValue(); insertQuery.append(targetColumn.getName()).append(','); }//from ww w .j a va 2 s .c om if (!columnMapping.isEmpty()) { insertQuery.replace(insertQuery.length() - 1, insertQuery.length(), ""); } insertQuery.append(") values ("); for (int i = 0; i < columnEntries.size(); i++) { insertQuery.append(i == 0 ? '?' : ", ?"); } insertQuery.append(')'); return insertQuery.toString(); }
From source file:com.nts.alphamale.handler.DeviceHandler.java
public static String installApp(String serial, String apkPath, int timeoutSecond) { String rtnValue = ""; Map<String, Object> executorMap = new AdbShellExecutor().execute( AdbShellCommand.cmd(serial, "cmd_install_app", new String[] { apkPath }), false, Settings.EXECUTOR_TIMEOUT); if (executorMap.isEmpty()) { return rtnValue; }/*ww w. ja va 2 s. com*/ LineIterator li = Utils.getLineIterator(executorMap.get("stdOut")); while (li != null && li.hasNext()) { rtnValue += li.nextLine().trim(); } Utils.destoryExecutor(executorMap.get("executor")); return rtnValue; }
From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java
/** * Transform the resource to person map to a string * * @param resourceUIDToPersonIDMap// w w w. ja v a 2 s . co m * @return */ public static String transformResourceMappingsToString(Map<Integer, Integer> resourceUIDToPersonIDMap) { if (resourceUIDToPersonIDMap != null && !resourceUIDToPersonIDMap.isEmpty()) { StringBuilder resourceMappings = new StringBuilder(); for (Iterator<Map.Entry<Integer, Integer>> iterator = resourceUIDToPersonIDMap.entrySet() .iterator(); iterator.hasNext();) { Map.Entry<Integer, Integer> resourceToPerson = (Map.Entry<Integer, Integer>) iterator.next(); resourceMappings.append(resourceToPerson.getKey()); resourceMappings.append(PAIR_SEPARATOR); resourceMappings.append(resourceToPerson.getValue()); resourceMappings.append(ENTRY_SEPARATOR); } return resourceMappings.toString(); } return null; }
From source file:com.nts.alphamale.handler.DeviceHandler.java
public static void startActivity(String serial, String activity) { Map<String, Object> executorMap = new AdbShellExecutor().execute( AdbShellCommand.cmd(serial, "cmd_start_activity", new String[] { "-S", activity }), true, Settings.EXECUTOR_TIMEOUT); if (!executorMap.isEmpty()) { Utils.destoryExecutor(executorMap.get("executor")); }/*from www .j a v a 2 s . co m*/ }
From source file:com.nts.alphamale.handler.DeviceHandler.java
public static String unInstallApp(String serial, String packageName, int timeoutSecond) { String rtnValue = ""; Map<String, Object> executorMap = new AdbShellExecutor().execute( AdbShellCommand.cmd(serial, "cmd_uninstall_app", new String[] { packageName }), false, Settings.EXECUTOR_TIMEOUT); if (executorMap.isEmpty()) { return rtnValue; }//w w w . j a va 2 s . c om LineIterator li = Utils.getLineIterator(executorMap.get("stdOut")); while (li != null && li.hasNext()) { rtnValue += li.nextLine().trim(); } Utils.destoryExecutor(executorMap.get("executor")); return rtnValue; }
From source file:it.geosolutions.imageio.plugins.nitronitf.NITFImageWriter.java
/** * Setup all the header fields taking them from the wrapper * /* w w w . j ava 2s . co m*/ * @param record * @param headerWrapper * @throws NITFException */ private static void initFileHeader(Record record, HeaderWrapper headerWrapper) throws NITFException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Populating file header"); } final FileHeader header = record.getHeader(); NITFUtilities.setField("FHDR", header.getFileHeader(), NITFUtilities.Consts.DEFAULT_FILE_HEADER); NITFUtilities.setField("FVER", header.getFileVersion(), NITFUtilities.Consts.DEFAULT_FILE_VERSION); NITFUtilities.setField("STYPE", header.getSystemType(), NITFUtilities.Consts.DEFAULT_SYSTEM_TYPE); if (headerWrapper != null) { NITFUtilities.setField("OSTAID", header.getOriginStationID(), headerWrapper.getOriginStationId()); NITFUtilities.setField("FDT", header.getFileDateTime(), headerWrapper.getDateTime()); NITFUtilities.setField("FTITLE", header.getFileTitle(), headerWrapper.getTitle()); NITFUtilities.setField("FSCLSY", header.getSecurityGroup().getClassificationSystem(), headerWrapper.getSecurityClassificationSystem()); NITFUtilities.setField("ENCRYP", header.getEncrypted(), Integer.toString(headerWrapper.getEncrypted())); header.getClassification().setData(headerWrapper.getSecurityClassificationSystem()); NITFUtilities.setField("FBKGC", header.getBackgroundColor(), headerWrapper.getBackgroundColor()); NITFUtilities.setField("ONAME", header.getOriginatorName(), headerWrapper.getOriginatorName()); NITFUtilities.setField("OPHONE", header.getOriginatorPhone(), headerWrapper.getOriginatorPhone()); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "file header has been setup"); } // Setting main header TREs if any Map<String, Map<String, String>> tresMap = headerWrapper.getTres(); if (tresMap != null && !tresMap.isEmpty()) { Extensions extendedSection = header.getExtendedSection(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Populating Main Header TREs"); } Set<String> keys = tresMap.keySet(); Iterator<String> it = keys.iterator(); while (it.hasNext()) { String treName = it.next(); Map<String, String> fieldsMapping = tresMap.get(treName); TRE tre = setTRE(treName, fieldsMapping); extendedSection.appendTRE(tre); } } }
From source file:com.nts.alphamale.handler.DeviceHandler.java
public static void deleteJar(String serial, String jarPath) { Map<String, Object> executorMap = new AdbShellExecutor().execute( AdbShellCommand.cmd(serial, "cmd_delete", new String[] { "/data/local/tmp/" + jarPath }), true, Settings.EXECUTOR_TIMEOUT); if (!executorMap.isEmpty()) { Utils.destoryExecutor(executorMap.get("executor")); }//w w w . ja v a 2 s .co m }