List of usage examples for java.util TreeMap containsKey
public boolean containsKey(Object key)
From source file:org.apache.nutch.crawl.CrawlDbReader.java
private TreeMap<String, Writable> processStatJobHelper(String crawlDb, Configuration config, boolean sort) throws IOException, InterruptedException, ClassNotFoundException { Path tmpFolder = new Path(crawlDb, "stat_tmp" + System.currentTimeMillis()); Job job = NutchJob.getInstance(config); config = job.getConfiguration();/*from w ww .j a v a 2 s.c o m*/ job.setJobName("stats " + crawlDb); config.setBoolean("db.reader.stats.sort", sort); FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME)); job.setInputFormatClass(SequenceFileInputFormat.class); job.setJarByClass(CrawlDbReader.class); job.setMapperClass(CrawlDbStatMapper.class); job.setCombinerClass(CrawlDbStatReducer.class); job.setReducerClass(CrawlDbStatReducer.class); FileOutputFormat.setOutputPath(job, tmpFolder); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(NutchWritable.class); // https://issues.apache.org/jira/browse/NUTCH-1029 config.setBoolean("mapreduce.fileoutputcommitter.marksuccessfuljobs", false); FileSystem fileSystem = tmpFolder.getFileSystem(config); try { boolean success = job.waitForCompletion(true); if (!success) { String message = "CrawlDbReader job did not succeed, job status:" + job.getStatus().getState() + ", reason: " + job.getStatus().getFailureInfo(); LOG.error(message); fileSystem.delete(tmpFolder, true); throw new RuntimeException(message); } } catch (IOException | InterruptedException | ClassNotFoundException e) { LOG.error(StringUtils.stringifyException(e)); fileSystem.delete(tmpFolder, true); throw e; } // reading the result SequenceFile.Reader[] readers = SegmentReaderUtil.getReaders(tmpFolder, config); Text key = new Text(); NutchWritable value = new NutchWritable(); TreeMap<String, Writable> stats = new TreeMap<>(); for (int i = 0; i < readers.length; i++) { SequenceFile.Reader reader = readers[i]; while (reader.next(key, value)) { String k = key.toString(); Writable val = stats.get(k); if (val == null) { stats.put(k, value.get()); continue; } if (k.equals("sc")) { float min = Float.MAX_VALUE; float max = Float.MIN_VALUE; if (stats.containsKey("scn")) { min = ((FloatWritable) stats.get("scn")).get(); } else { min = ((FloatWritable) stats.get("sc")).get(); } if (stats.containsKey("scx")) { max = ((FloatWritable) stats.get("scx")).get(); } else { max = ((FloatWritable) stats.get("sc")).get(); } float fvalue = ((FloatWritable) value.get()).get(); if (min > fvalue) { min = fvalue; } if (max < fvalue) { max = fvalue; } stats.put("scn", new FloatWritable(min)); stats.put("scx", new FloatWritable(max)); } else if (k.equals("ft") || k.equals("fi")) { long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; String minKey = k + "n"; String maxKey = k + "x"; if (stats.containsKey(minKey)) { min = ((LongWritable) stats.get(minKey)).get(); } else if (stats.containsKey(k)) { min = ((LongWritable) stats.get(k)).get(); } if (stats.containsKey(maxKey)) { max = ((LongWritable) stats.get(maxKey)).get(); } else if (stats.containsKey(k)) { max = ((LongWritable) stats.get(k)).get(); } long lvalue = ((LongWritable) value.get()).get(); if (min > lvalue) { min = lvalue; } if (max < lvalue) { max = lvalue; } stats.put(k + "n", new LongWritable(min)); stats.put(k + "x", new LongWritable(max)); } else if (k.equals("sct")) { FloatWritable fvalue = (FloatWritable) value.get(); ((FloatWritable) val).set(((FloatWritable) val).get() + fvalue.get()); } else if (k.equals("scd")) { MergingDigest tdigest = null; MergingDigest tdig = MergingDigest .fromBytes(ByteBuffer.wrap(((BytesWritable) value.get()).getBytes())); if (val instanceof BytesWritable) { tdigest = MergingDigest.fromBytes(ByteBuffer.wrap(((BytesWritable) val).getBytes())); tdigest.add(tdig); } else { tdigest = tdig; } ByteBuffer tdigestBytes = ByteBuffer.allocate(tdigest.smallByteSize()); tdigest.asSmallBytes(tdigestBytes); stats.put(k, new BytesWritable(tdigestBytes.array())); } else { LongWritable lvalue = (LongWritable) value.get(); ((LongWritable) val).set(((LongWritable) val).get() + lvalue.get()); } } reader.close(); } // remove score, fetch interval, and fetch time // (used for min/max calculation) stats.remove("sc"); stats.remove("fi"); stats.remove("ft"); // removing the tmp folder fileSystem.delete(tmpFolder, true); return stats; }
From source file:com.netflix.ice.processor.BillingFileProcessor.java
@Override protected void poll() throws Exception { TreeMap<DateTime, List<BillingFile>> filesToProcess = Maps.newTreeMap(); Map<DateTime, List<BillingFile>> monitorFilesToProcess = Maps.newTreeMap(); // list the tar.gz file in billing file folder for (int i = 0; i < config.billingS3BucketNames.length; i++) { String billingS3BucketName = config.billingS3BucketNames[i]; String billingS3BucketPrefix = config.billingS3BucketPrefixes.length > i ? config.billingS3BucketPrefixes[i] : ""; String accountId = config.billingAccountIds.length > i ? config.billingAccountIds[i] : ""; String billingAccessRoleName = config.billingAccessRoleNames.length > i ? config.billingAccessRoleNames[i] : ""; String billingAccessExternalId = config.billingAccessExternalIds.length > i ? config.billingAccessExternalIds[i] : ""; logger.info("trying to list objects in billing bucket " + billingS3BucketName + " using assume role, and external id " + billingAccessRoleName + " " + billingAccessExternalId); List<S3ObjectSummary> objectSummaries = AwsUtils.listAllObjects(billingS3BucketName, billingS3BucketPrefix, accountId, billingAccessRoleName, billingAccessExternalId); logger.info("found " + objectSummaries.size() + " in billing bucket " + billingS3BucketName); TreeMap<DateTime, S3ObjectSummary> filesToProcessInOneBucket = Maps.newTreeMap(); Map<DateTime, S3ObjectSummary> monitorFilesToProcessInOneBucket = Maps.newTreeMap(); // for each file, download&process if not needed for (S3ObjectSummary objectSummary : objectSummaries) { String fileKey = objectSummary.getKey(); DateTime dataTime = AwsUtils.getDateTimeFromFileNameWithTags(fileKey); boolean withTags = true; if (dataTime == null) { dataTime = AwsUtils.getDateTimeFromFileName(fileKey); withTags = false;// ww w . j a v a2 s . co m } if (dataTime != null && !dataTime.isBefore(config.startDate)) { if (!filesToProcessInOneBucket.containsKey(dataTime) || withTags && config.resourceService != null || !withTags && config.resourceService == null) filesToProcessInOneBucket.put(dataTime, objectSummary); else logger.info("ignoring file " + objectSummary.getKey()); } else { logger.info("ignoring file " + objectSummary.getKey()); } } for (S3ObjectSummary objectSummary : objectSummaries) { String fileKey = objectSummary.getKey(); DateTime dataTime = AwsUtils.getDateTimeFromFileNameWithMonitoring(fileKey); if (dataTime != null && !dataTime.isBefore(config.startDate)) { monitorFilesToProcessInOneBucket.put(dataTime, objectSummary); } } for (DateTime key : filesToProcessInOneBucket.keySet()) { List<BillingFile> list = filesToProcess.get(key); if (list == null) { list = Lists.newArrayList(); filesToProcess.put(key, list); } list.add(new BillingFile(filesToProcessInOneBucket.get(key), accountId, billingAccessRoleName, billingAccessExternalId, billingS3BucketPrefix)); } for (DateTime key : monitorFilesToProcessInOneBucket.keySet()) { List<BillingFile> list = monitorFilesToProcess.get(key); if (list == null) { list = Lists.newArrayList(); monitorFilesToProcess.put(key, list); } list.add(new BillingFile(monitorFilesToProcessInOneBucket.get(key), accountId, billingAccessRoleName, billingAccessExternalId, billingS3BucketPrefix)); } } for (DateTime dataTime : filesToProcess.keySet()) { startMilli = endMilli = dataTime.getMillis(); init(); boolean hasNewFiles = false; boolean hasTags = false; long lastProcessed = lastProcessTime(AwsUtils.monthDateFormat.print(dataTime)); for (BillingFile billingFile : filesToProcess.get(dataTime)) { S3ObjectSummary objectSummary = billingFile.s3ObjectSummary; if (objectSummary.getLastModified().getTime() < lastProcessed) { logger.info("data has been processed. ignoring " + objectSummary.getKey() + "..."); continue; } hasNewFiles = true; } if (!hasNewFiles) { logger.info("data has been processed. ignoring all files at " + AwsUtils.monthDateFormat.print(dataTime)); continue; } long processTime = new DateTime(DateTimeZone.UTC).getMillis(); for (BillingFile billingFile : filesToProcess.get(dataTime)) { S3ObjectSummary objectSummary = billingFile.s3ObjectSummary; String fileKey = objectSummary.getKey(); File file = new File(config.localDir, fileKey.substring(billingFile.prefix.length())); logger.info("trying to download " + fileKey + "..."); boolean downloaded = AwsUtils.downloadFileIfChangedSince(objectSummary.getBucketName(), billingFile.prefix, file, lastProcessed, billingFile.accountId, billingFile.accessRoleName, billingFile.externalId); if (downloaded) logger.info("downloaded " + fileKey); else { logger.info("file already downloaded " + fileKey + "..."); } logger.info("processing " + fileKey + "..."); boolean withTags = fileKey.contains("with-resources-and-tags"); hasTags = hasTags || withTags; processingMonitor = false; processBillingZipFile(file, withTags); logger.info("done processing " + fileKey); } if (monitorFilesToProcess.get(dataTime) != null) { for (BillingFile monitorBillingFile : monitorFilesToProcess.get(dataTime)) { S3ObjectSummary monitorObjectSummary = monitorBillingFile.s3ObjectSummary; if (monitorObjectSummary != null) { String monitorFileKey = monitorObjectSummary.getKey(); logger.info("processing " + monitorFileKey + "..."); File monitorFile = new File(config.localDir, monitorFileKey.substring(monitorFileKey.lastIndexOf("/") + 1)); logger.info("trying to download " + monitorFileKey + "..."); boolean downloaded = AwsUtils.downloadFileIfChangedSince( monitorObjectSummary.getBucketName(), monitorBillingFile.prefix, monitorFile, lastProcessed, monitorBillingFile.accountId, monitorBillingFile.accessRoleName, monitorBillingFile.externalId); if (downloaded) logger.info("downloaded " + monitorFile); else logger.warn(monitorFile + "already downloaded..."); FileInputStream in = new FileInputStream(monitorFile); try { processingMonitor = true; processBillingFile(monitorFile.getName(), in, true); } catch (Exception e) { logger.error("Error processing " + monitorFile, e); } finally { in.close(); } } } } if (dataTime.equals(filesToProcess.lastKey())) { int hours = (int) ((endMilli - startMilli) / 3600000L); logger.info("cut hours to " + hours); cutData(hours); } // now get reservation capacity to calculate upfront and un-used cost for (Ec2InstanceReservationPrice.ReservationUtilization utilization : Ec2InstanceReservationPrice.ReservationUtilization .values()) processReservations(utilization); if (hasTags && config.resourceService != null) config.resourceService.commit(); logger.info("archiving results for " + dataTime + "..."); archive(); logger.info("done archiving " + dataTime); updateProcessTime(AwsUtils.monthDateFormat.print(dataTime), processTime); if (dataTime.equals(filesToProcess.lastKey())) { sendOndemandCostAlert(); } } logger.info("AWS usage processed."); }
From source file:org.opendatakit.database.data.ColumnDefinitionTest.java
@SuppressWarnings("unchecked") @Test/*from w ww. ja va 2 s. co m*/ public void testBuildExtendedJson() { List<Column> columns = new ArrayList<Column>(); // arbitrary type derived from integer columns.add(new Column("col0", "col0", "myothertype:integer", "[]")); // primitive types columns.add(new Column("col1", "col1", "boolean", "[]")); columns.add(new Column("col2", "col2", "integer", "[]")); columns.add(new Column("col3", "col3", "number", "[]")); columns.add(new Column("col4", "col4", "string", "[]")); // string with 500 varchars allocated to it columns.add(new Column("col5", "col5", "string(500)", "[]")); columns.add(new Column("col6", "col6", "configpath", "[]")); columns.add(new Column("col7", "col7", "rowpath", "[]")); // object type (geopoint) columns.add(new Column("col8", "col8", "geopoint", "[\"col8_accuracy\",\"col8_altitude\",\"col8_latitude\",\"col8_longitude\"]")); columns.add(new Column("col8_accuracy", "accuracy", "number", "[]")); columns.add(new Column("col8_altitude", "altitude", "number", "[]")); columns.add(new Column("col8_latitude", "latitude", "number", "[]")); columns.add(new Column("col8_longitude", "longitude", "number", "[]")); // arbitrary type derived from string columns.add(new Column("col9", "col9", "mytype", "[]")); // arrays columns.add(new Column("col12", "col12", "array", "[\"col12_items\"]")); columns.add(new Column("col12_items", "items", "integer", "[]")); // array with 500 varchars allocated to it columns.add(new Column("col14", "col14", "array(400)", "[\"col14_items\"]")); columns.add(new Column("col14_items", "items", "string", "[]")); columns.add(new Column("col1a", "col1a", "geolist:array(500)", "[\"col1a_items\"]")); columns.add(new Column("col1a_items", "items", "geopoint", "[\"col1a_items_accuracy\",\"col1a_items_altitude\",\"col1a_items_latitude\"," + "\"col1a_items_longitude\"]")); columns.add(new Column("col1a_items_accuracy", "accuracy", "number", "[]")); columns.add(new Column("col1a_items_altitude", "altitude", "number", "[]")); columns.add(new Column("col1a_items_latitude", "latitude", "number", "[]")); columns.add(new Column("col1a_items_longitude", "longitude", "number", "[]")); ArrayList<ColumnDefinition> colDefs = ColumnDefinition.buildColumnDefinitions("appName", "testTable", columns); String equivalentXLSXConverterDataTableModel = "{" + "\"col0\": {" + "\"type\": \"integer\"," + "\"_defn\": [" + "{" + "\"_row_num\": 2," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"myothertype:integer\"," + "\"elementKey\": \"col0\"," + "\"elementName\": \"col0\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col0\"" + "}," + "\"col1\": {" + "\"type\": \"boolean\"," + "\"_defn\": [" + "{" + "\"_row_num\": 3," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementKey\": \"col1\"," + "\"elementName\": \"col1\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1\"" + "}," + "\"col2\": {" + "\"type\": \"integer\"," + "\"_defn\": [" + "{" + "\"_row_num\": 4," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementKey\": \"col2\"," + "\"elementName\": \"col2\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col2\"" + "}," + "\"col3\": {" + "\"type\": \"number\"," + "\"_defn\": [" + "{" + "\"_row_num\": 5," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementKey\": \"col3\"," + "\"elementName\": \"col3\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col3\"" + "}," + "\"col4\": {" + "\"type\": \"string\"," + "\"_defn\": [" + "{" + "\"_row_num\": 6," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementKey\": \"col4\"," + "\"elementName\": \"col4\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col4\"" + "}," + "\"col5\": {" + "\"type\": \"string\"," + "\"_defn\": [" + "{" + "\"_row_num\": 7," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"string(500)\"," + "\"elementKey\": \"col5\"," + "\"elementName\": \"col5\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col5\"" + "}," + "\"col6\": {" + "\"type\": \"string\"," + "\"_defn\": [" + "{" + "\"_row_num\": 8," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"configpath\"," + "\"elementKey\": \"col6\"," + "\"elementName\": \"col6\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col6\"" + "}," + "\"col7\": {" + "\"type\": \"string\"," + "\"_defn\": [" + "{" + "\"_row_num\": 9," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"rowpath\"," + "\"elementKey\": \"col7\"," + "\"elementName\": \"col7\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col7\"" + "}," + "\"col8\": {" + "\"type\": \"object\"," + "\"elementType\": \"geopoint\"," + "\"properties\": {" + "\"latitude\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_latitude\"," + "\"elementName\": \"latitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.latitude\"" + "}," + "\"longitude\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_longitude\"," + "\"elementName\": \"longitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.longitude\"" + "}," + "\"altitude\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_altitude\"," + "\"elementName\": \"altitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.altitude\"" + "}," + "\"accuracy\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_accuracy\"," + "\"elementName\": \"accuracy\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.accuracy\"" + "}" + "}," + "\"_defn\": [" + "{" + "\"_row_num\": 10," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementKey\": \"col8\"," + "\"elementName\": \"col8\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8\"," + "\"listChildElementKeys\": [" + "\"col8_accuracy\"," + "\"col8_altitude\"," + "\"col8_latitude\"," + "\"col8_longitude\"" + "]," + "\"notUnitOfRetention\": true" + "}," + "\"col9\": {" + "\"type\": \"string\"," + "\"_defn\": [" + "{" + "\"_row_num\": 11," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"mytype\"," + "\"elementKey\": \"col9\"," + "\"elementName\": \"col9\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col9\"" + "}," + "\"col12\": {" + "\"type\": \"array\"," + "\"_defn\": [" + "{" + "\"_row_num\": 12," + "\"section_name\": \"model\"" + "}" + "]," + "\"items\": {" + "\"type\": \"integer\"," + "\"elementKey\": \"col12_items\"," + "\"elementName\": \"items\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col12.items\"," + "\"notUnitOfRetention\": true" + "}," + "\"elementKey\": \"col12\"," + "\"elementName\": \"col12\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col12\"," + "\"listChildElementKeys\": [" + "\"col12_items\"" + "]" + "}," + "\"col14\": {" + "\"type\": \"array\"," + "\"_defn\": [" + "{" + "\"_row_num\": 13," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"array(400)\"," + "\"items\": {" + "\"type\": \"string\"," + "\"elementKey\": \"col14_items\"," + "\"elementName\": \"items\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col14.items\"," + "\"notUnitOfRetention\": true" + "}," + "\"elementKey\": \"col14\"," + "\"elementName\": \"col14\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col14\"," + "\"listChildElementKeys\": [" + "\"col14_items\"" + "]" + "}," + "\"col1a\": {" + "\"type\": \"array\"," + "\"_defn\": [" + "{" + "\"_row_num\": 14," + "\"section_name\": \"model\"" + "}" + "]," + "\"elementType\": \"geolist:array(500)\"," + "\"items\": {" + "\"type\": \"object\"," + "\"elementType\": \"geopoint\"," + "\"properties\": {" + "\"latitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"latitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.latitude\"," + "\"elementKey\": \"col1a_items_latitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"longitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"longitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.longitude\"," + "\"elementKey\": \"col1a_items_longitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"altitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"altitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.altitude\"," + "\"elementKey\": \"col1a_items_altitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"accuracy\": {" + "\"type\": \"number\"," + "\"elementName\": \"accuracy\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.accuracy\"," + "\"elementKey\": \"col1a_items_accuracy\"," + "\"notUnitOfRetention\": true" + "}" + "}," + "\"elementKey\": \"col1a_items\"," + "\"elementName\": \"items\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items\"," + "\"listChildElementKeys\": [" + "\"col1a_items_accuracy\"," + "\"col1a_items_altitude\"," + "\"col1a_items_latitude\"," + "\"col1a_items_longitude\"" + "]," + "\"notUnitOfRetention\": true" + "}," + "\"elementKey\": \"col1a\"," + "\"elementName\": \"col1a\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a\"," + "\"listChildElementKeys\": [" + "\"col1a_items\"" + "]" + "}," + "\"col8_latitude\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_latitude\"," + "\"elementName\": \"latitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.latitude\"" + "}," + "\"col8_longitude\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_longitude\"," + "\"elementName\": \"longitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.longitude\"" + "}," + "\"col8_altitude\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_altitude\"," + "\"elementName\": \"altitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.altitude\"" + "}," + "\"col8_accuracy\": {" + "\"type\": \"number\"," + "\"elementKey\": \"col8_accuracy\"," + "\"elementName\": \"accuracy\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col8.accuracy\"" + "}," + "\"col12_items\": {" + "\"type\": \"integer\"," + "\"elementKey\": \"col12_items\"," + "\"elementName\": \"items\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col12.items\"," + "\"notUnitOfRetention\": true" + "}," + "\"col14_items\": {" + "\"type\": \"string\"," + "\"elementKey\": \"col14_items\"," + "\"elementName\": \"items\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col14.items\"," + "\"notUnitOfRetention\": true" + "}," + "\"col1a_items\": {" + "\"type\": \"object\"," + "\"elementType\": \"geopoint\"," + "\"properties\": {" + "\"latitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"latitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.latitude\"," + "\"elementKey\": \"col1a_items_latitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"longitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"longitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.longitude\"," + "\"elementKey\": \"col1a_items_longitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"altitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"altitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.altitude\"," + "\"elementKey\": \"col1a_items_altitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"accuracy\": {" + "\"type\": \"number\"," + "\"elementName\": \"accuracy\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.accuracy\"," + "\"elementKey\": \"col1a_items_accuracy\"," + "\"notUnitOfRetention\": true" + "}" + "}," + "\"elementKey\": \"col1a_items\"," + "\"elementName\": \"items\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items\"," + "\"listChildElementKeys\": [" + "\"col1a_items_accuracy\"," + "\"col1a_items_altitude\"," + "\"col1a_items_latitude\"," + "\"col1a_items_longitude\"" + "]," + "\"notUnitOfRetention\": true" + "}," + "\"col1a_items_latitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"latitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.latitude\"," + "\"elementKey\": \"col1a_items_latitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"col1a_items_longitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"longitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.longitude\"," + "\"elementKey\": \"col1a_items_longitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"col1a_items_altitude\": {" + "\"type\": \"number\"," + "\"elementName\": \"altitude\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.altitude\"," + "\"elementKey\": \"col1a_items_altitude\"," + "\"notUnitOfRetention\": true" + "}," + "\"col1a_items_accuracy\": {" + "\"type\": \"number\"," + "\"elementName\": \"accuracy\"," + "\"elementSet\": \"data\"," + "\"elementPath\": \"col1a.items.accuracy\"," + "\"elementKey\": \"col1a_items_accuracy\"," + "\"notUnitOfRetention\": true" + "}," + "\"_id\": {" + "\"type\": \"string\"," + "\"isNotNullable\": true," + "\"elementKey\": \"_id\"," + "\"elementName\": \"_id\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_id\"" + "}," + "\"_row_etag\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_row_etag\"," + "\"elementName\": \"_row_etag\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_row_etag\"" + "}," + "\"_sync_state\": {" + "\"type\": \"string\"," + "\"isNotNullable\": true," + "\"elementKey\": \"_sync_state\"," + "\"elementName\": \"_sync_state\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_sync_state\"" + "}," + "\"_conflict_type\": {" + "\"type\": \"integer\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_conflict_type\"," + "\"elementName\": \"_conflict_type\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_conflict_type\"" + "}," + "\"_default_access\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_default_access\"," + "\"elementName\": \"_default_access\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_default_access\"" + "}," + "\"_row_owner\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_row_owner\"," + "\"elementName\": \"_row_owner\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_row_owner\"" + "}," + "\"_group_read_only\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_group_read_only\"," + "\"elementName\": \"_group_read_only\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_group_read_only\"" + "}," + "\"_group_modify\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_group_modify\"," + "\"elementName\": \"_group_modify\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_group_modify\"" + "}," + "\"_group_privileged\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_group_privileged\"," + "\"elementName\": \"_group_privileged\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_group_privileged\"" + "}," + "\"_form_id\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_form_id\"," + "\"elementName\": \"_form_id\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_form_id\"" + "}," + "\"_locale\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_locale\"," + "\"elementName\": \"_locale\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_locale\"" + "}," + "\"_savepoint_type\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_savepoint_type\"," + "\"elementName\": \"_savepoint_type\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_savepoint_type\"" + "}," + "\"_savepoint_timestamp\": {" + "\"type\": \"string\"," + "\"isNotNullable\": true," + "\"elementKey\": \"_savepoint_timestamp\"," + "\"elementName\": \"_savepoint_timestamp\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_savepoint_timestamp\"" + "}," + "\"_savepoint_creator\": {" + "\"type\": \"string\"," + "\"isNotNullable\": false," + "\"elementKey\": \"_savepoint_creator\"," + "\"elementName\": \"_savepoint_creator\"," + "\"elementSet\": \"instanceMetadata\"," + "\"elementPath\": \"_savepoint_creator\"" + "}" + "}"; int metaCount = 0; TreeMap<String, Object> model = ColumnDefinition.getExtendedDataModel(colDefs); TypeReference<TreeMap<String, Object>> refType = new TypeReference<TreeMap<String, Object>>() { }; TreeMap<String, Object> xlsxModel; try { xlsxModel = ODKFileUtils.mapper.readValue(equivalentXLSXConverterDataTableModel, refType); } catch (IOException e) { assertFalse("failed to parse XLSXConverter version", true); return; } for (String elementKey : model.keySet()) { TreeMap<String, Object> value = (TreeMap<String, Object>) model.get(elementKey); assert (xlsxModel.containsKey(elementKey)); Map<String, Object> xlsxValue = (Map<String, Object>) xlsxModel.get(elementKey); List<String> ignoredKeys = new ArrayList<String>(); for (String key : xlsxValue.keySet()) { if (key.startsWith("_")) { ignoredKeys.add(key); } if (key.equals("prompt_type_name")) { ignoredKeys.add(key); } } for (String key : ignoredKeys) { xlsxValue.remove(key); } assertEquals("Investigating: " + elementKey, value.size(), xlsxValue.size()); recursiveMatch(elementKey, value, xlsxValue); ColumnDefinition def = null; try { def = ColumnDefinition.find(colDefs, elementKey); } catch (IllegalArgumentException e) { // ignore } if (def == null) { assertEquals(value.get("elementSet"), "instanceMetadata"); assertEquals(value.get("elementKey"), elementKey); assertEquals(value.get("elementName"), elementKey); assertEquals(value.get("elementPath"), elementKey); assertEquals(value.containsKey("notUnitOfRetention"), false); if (elementKey.equals(TableConstants.ID)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), true); } else if (elementKey.equals(TableConstants.ROW_ETAG)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.SYNC_STATE)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), true); } else if (elementKey.equals(TableConstants.CONFLICT_TYPE)) { metaCount++; assertEquals(value.get("type"), "integer"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.DEFAULT_ACCESS)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.ROW_OWNER)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.GROUP_READ_ONLY)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.GROUP_MODIFY)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.GROUP_PRIVILEGED)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.SAVEPOINT_TIMESTAMP)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), true); } else if (elementKey.equals(TableConstants.SAVEPOINT_TYPE)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.SAVEPOINT_CREATOR)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.FORM_ID)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else if (elementKey.equals(TableConstants.LOCALE)) { metaCount++; assertEquals(value.get("type"), "string"); assertEquals(value.get("isNotNullable"), false); } else { throw new IllegalStateException("Unexpected non-user column"); } } else { assertEquals(value.get("elementPath"), def.getElementName()); assertEquals(value.get("elementSet"), "data"); assertEquals(value.get("elementName"), def.getElementName()); assertEquals(value.get("elementKey"), def.getElementKey()); if (!def.isUnitOfRetention()) { assertEquals(value.get("notUnitOfRetention"), true); } // TODO: there are a lot more paths to verify here... assertEquals(value.containsKey("isNotNullable"), false); } } assertEquals(metaCount, 14); }
From source file:com.sfs.whichdoctor.dao.VoteDAOImpl.java
/** * Loads an array of groups based on the submitted voteNumber and year. * * @param voteNumber the vote number/* ww w.j a v a 2 s. c o m*/ * @param year the year * * @return the collection< group bean> * * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<GroupBean> findElections(final int voteNumber, final int year) throws WhichDoctorDaoException { if (year == 0) { throw new WhichDoctorDaoException("Sorry a valid year is required"); } Collection<GroupBean> elections = new ArrayList<GroupBean>(); dataLogger.info("Loading elections for: " + voteNumber + "/" + year); /* Identify the referenceGUID from the vote number and year */ int referenceGUID = PersonBean.getVoterGUID(voteNumber, year); TreeMap<Integer, Integer> electionList = new TreeMap<Integer, Integer>(); try { Collection<Integer> guids = this.getJdbcTemplateReader().query( this.getSQL().getValue("vote/findPossibleElections"), new Object[] { year, referenceGUID }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return rs.getInt("GUID"); } }); for (Integer guid : guids) { electionList.put(guid, guid); } } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } try { Collection<Integer> guids = this.getJdbcTemplateReader().query( this.getSQL().getValue("vote/findVotedElections"), new Object[] { year, referenceGUID }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return rs.getInt("GUID"); } }); for (Integer guid : guids) { if (electionList.containsKey(guid)) { // This election has been voted for already, remove it from the list electionList.remove(guid); } } } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } if (electionList.size() > 0) { // An unvoted election exists in the map, perform a group search to load it Collection<Object> guidCollection = new ArrayList<Object>(); for (Integer groupGUID : electionList.keySet()) { guidCollection.add(groupGUID); } try { SearchBean search = this.searchDAO.initiate("group", null); search.setLimit(0); search.setOrderColumn("groups.Weighting"); search.setOrderColumn2("groups.Name"); search.setSearchArray(guidCollection, "Unvoted list of elections"); BuilderBean loadDetails = new BuilderBean(); loadDetails.setParameter("CANDIDATES", true); SearchResultsBean results = this.searchDAO.search(search, loadDetails); if (results != null) { // Add each group to the election array for (Object result : results.getSearchResults()) { GroupBean election = (GroupBean) result; elections.add(election); } } } catch (Exception e) { dataLogger.error("Error performing election search: " + e.getMessage()); throw new WhichDoctorDaoException("Error performing election search: " + e.getMessage()); } } return elections; }
From source file:com.sfs.whichdoctor.importer.Importer.java
/** * Sets the column map./* www .j av a 2s. co m*/ * * @param type the type * @param data the data * @param includeRowsVal the include rows */ public final void setColumnMap(final String type, final TreeMap<Integer, TreeMap<Integer, String>> data, final TreeMap<Integer, String> includeRowsVal) { TreeMap<Integer, String> columnMapVal = new TreeMap<Integer, String>(); List<String> fields = new ArrayList<String>(); if (StringUtils.equalsIgnoreCase(type, "exam")) { ExamImporter examImporter = new ExamImporter(); fields = examImporter.getFields(); } // Inspect the first row of data supplied Integer rowIndex = data.keySet().iterator().next(); TreeMap<Integer, String> firstRow = data.get(rowIndex); int fieldMatches = 0; for (Integer columnNumber : firstRow.keySet()) { String dataField = firstRow.get(columnNumber); String fieldName = ""; // Iterate through each field to see if there is a match // If there is more than two matches then the first row // is indicating column field names for (int i = 0; i < fields.size(); i++) { String field = (String) fields.get(i); if (StringUtils.equalsIgnoreCase(dataField, field)) { // Matching field fieldName = dataField; fieldMatches++; } } columnMapVal.put(columnNumber, fieldName); } if (fieldMatches > 2) { // There were more than two field matches // Deselect the first column from the list of imports if (includeRowsVal.containsKey(rowIndex)) { includeRowsVal.remove(rowIndex); } } setIncludeRows(includeRowsVal); setColumnMap(columnMapVal); }
From source file:com.sfs.whichdoctor.analysis.AgedDebtorsAnalysisDAOImpl.java
/** * Load groupings./*from w w w . j a v a2 s .c om*/ * * @param analysis the analysis * @return the aged debtors analysis bean */ private AgedDebtorsAnalysisBean loadGroupings(final AgedDebtorsAnalysisBean analysis) { HashMap<Integer, AgedDebtorsRecord> records = buildRecordMap(analysis); HashMap<Integer, ReceiptBean> lastReceipts = loadLastReceipts(analysis); TreeMap<String, AgedDebtorsGrouping> groupings = new TreeMap<String, AgedDebtorsGrouping>(); // If there are no records then there is no need to perform any searches if (records.size() > 0) { // Loop through these for the different periods and in total for (Integer periodId : analysis.getPeriods().keySet()) { AgedDebtorsPeriod period = analysis.getPeriods().get(periodId); for (String type : types) { dataLogger.debug("Performing lookup for " + type); Collection<AgedDebtorsRecord> results = performLookup(analysis, period, type); for (AgedDebtorsRecord result : results) { int guid = result.getPersonGUID(); if (result.getOrganisationGUID() > 0) { guid = result.getOrganisationGUID(); } String groupName = analysis.getGroupName(guid); AgedDebtorsGrouping grouping = new AgedDebtorsGrouping(); grouping.setName(groupName); if (groupings.containsKey(groupName)) { grouping = groupings.get(groupName); } dataLogger.debug("Processing result for GUID: " + guid + ", " + Formatter.toCurrency(result.getOutstandingDebitValue())); AgedDebtorsRecord record = records.get(guid); AgedDebtorsPeriod periodResult = new AgedDebtorsPeriod(period); if (record.getPeriodBreakdown().containsKey(periodId)) { periodResult = record.getPeriodBreakdown().get(periodId); } if (StringUtils.equalsIgnoreCase(type, "debit")) { periodResult.setOutstandingDebitValue(result.getOutstandingDebitValue()); // Update the running total for the record record.setOutstandingDebitValue( record.getOutstandingDebitValue() + result.getOutstandingDebitValue()); // Update the running total for the period period.setOutstandingDebitValue( period.getOutstandingDebitValue() + result.getOutstandingDebitValue()); } if (StringUtils.equalsIgnoreCase(type, "credit")) { periodResult.setUnallocatedCreditValue(result.getOutstandingDebitValue()); // Update the running total for the record record.setUnallocatedCreditValue( record.getUnallocatedCreditValue() + result.getOutstandingDebitValue()); // Update the running total for the period period.setUnallocatedCreditValue( period.getUnallocatedCreditValue() + result.getOutstandingDebitValue()); } if (StringUtils.equalsIgnoreCase(type, "refund")) { periodResult.setUnallocatedRefundValue(result.getOutstandingDebitValue()); // Update the running total for the record record.setUnallocatedRefundValue( record.getUnallocatedRefundValue() + result.getOutstandingDebitValue()); // Update the running total for the period period.setUnallocatedRefundValue( period.getUnallocatedRefundValue() + result.getOutstandingDebitValue()); } if (StringUtils.equalsIgnoreCase(type, "receipt")) { periodResult.setUnallocatedReceiptValue(result.getOutstandingDebitValue()); // Update the running total for the record record.setUnallocatedReceiptValue( record.getUnallocatedReceiptValue() + result.getOutstandingDebitValue()); // Update the running total for the period period.setUnallocatedReceiptValue( period.getUnallocatedReceiptValue() + result.getOutstandingDebitValue()); } // Set the last receipt if one exists for this record if (lastReceipts.containsKey(guid)) { record.setLastReceipt(lastReceipts.get(guid)); } record.getPeriodBreakdown().put(periodId, periodResult); grouping.getRecords().put(analysis.getOrderKey(guid), record); groupings.put(groupName, grouping); } } analysis.getPeriods().put(periodId, period); } } analysis.setGroupings(processGroups(groupings, analysis.getShowZeroBalances())); return analysis; }
From source file:com.sfs.whichdoctor.webservice.RotationXmlOutputImpl.java
/** * Builds a list of rotations in the second-gen XML format. * * @param rotations the rotation array//from w w w .java 2 s. co m * @param personIdentifier the person identifier * @param division the division * @param currentRotations the current rotations * * @return the rotations in XML format */ public final String getSecondGenRotations(final List<RotationBean> rotations, final int personIdentifier, final String division, final Collection<RotationBean> currentRotations) { Element xml = new Element("trainee"); xml.setAttribute("MIN", String.valueOf(personIdentifier)); // Process the current organisations TreeMap<String, Element> siteMap = new TreeMap<String, Element>(); for (RotationBean rtn : currentRotations) { if (StringUtils.isNotBlank(rtn.getOrganisation1Name())) { Element site = new Element("site"); String type = "primary"; if (!StringUtils.equalsIgnoreCase(type, rtn.getOrganisation1TypeMapping())) { // If not primary set the type to training type = "training"; } site.setAttribute("type", "current_" + type); site.setAttribute("state", loadOrgCity(rtn.getOrganisation1Id())); site.setAttribute("name", rtn.getOrganisation1Name()); siteMap.put(type, site); } if (StringUtils.isNotBlank(rtn.getOrganisation2Name())) { Element site = new Element("site"); String type = "training"; if (siteMap.containsKey(type)) { // Set to primary if the training key exists type = "primary"; } site.setAttribute("type", "current_" + type); site.setAttribute("state", loadOrgCity(rtn.getOrganisation2Id())); site.setAttribute("name", rtn.getOrganisation2Name()); siteMap.put(type, site); } } if (siteMap.size() == 1) { for (String type : siteMap.keySet()) { Element site = siteMap.get(type); Element site2 = (Element) site.clone(); String secondType = "training"; if (StringUtils.equalsIgnoreCase(type, "training")) { secondType = "primary"; } site2.setAttribute("type", "current_" + secondType); siteMap.put(secondType, site2); } } Element sitesElement = new Element("sites"); for (String type : siteMap.keySet()) { Element site = siteMap.get(type); sitesElement.addContent(site); } xml.addContent(sitesElement); Element rtnsXml = new Element("rotations"); rtnsXml.setAttribute("min", String.valueOf(personIdentifier)); for (RotationBean rtn : rotations) { rtnsXml.addContent(RotationXmlHelper.getSecondGenRotationInfo(rtn, division, loadOrgCity(rtn.getOrganisation1Id()), loadOrgCity(rtn.getOrganisation2Id()))); } xml.addContent(rtnsXml); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getCompactFormat(); format.setOmitDeclaration(true); outputter.setFormat(format); return outputter.outputString(new Document(xml)); }
From source file:IndexService.Indexer.java
private List<IRecord> getRange1(String indexdir, String partname, List<IRecord.IFValue> startvalue, List<IRecord.IFValue> endvalue, String indexids, int limit, int fieldnum) throws IOException { String dir = indexdir.endsWith("/") ? indexdir : (indexdir + "/"); Path partfile = new Path(dir + partname); TreeMap<String, TreeSet<Integer>> indexresult = new TreeMap<String, TreeSet<Integer>>(); HashMap<String, Boolean> iscolumn = new HashMap<String, Boolean>(); FileStatus[] fss = fs.listStatus(partfile); long time = System.currentTimeMillis(); for (FileStatus status : fss) { IFormatDataFile ifdf = new IFormatDataFile(conf); ifdf.open(status.getPath().toString()); if (ifdf.fileInfo().head().fieldMap().fieldtypes().size() < startvalue.size() + 2) { throw new IOException("input value field size is more than index can support"); }/*from www . ja v a 2s . c om*/ for (int i = 0; i < startvalue.size(); i++) { if (ifdf.fileInfo().head().fieldMap().fieldtypes().get(i).type() != startvalue.get(i).type() .type()) { throw new IOException("input value field type is not fit the index field type"); } } HashMap<Integer, String> infos = ifdf.fileInfo().head().getUdi().infos(); List<IndexValue> res = getIndexResRange(ifdf, startvalue, endvalue, limit); for (IndexValue iv : res) { int fileid = iv.getFileindex(); String filename = infos.get(fileid); if (!indexresult.containsKey(filename)) { indexresult.put(filename, new TreeSet<Integer>()); iscolumn.put(filename, ifdf.fileInfo().head().getUdi().infos().get(123456).equals("column")); } indexresult.get(filename).add(iv.getRowid()); } ifdf.close(); } System.out.println("getIndexResRange time:\t" + (System.currentTimeMillis() - time) / 1000 + "s"); System.out.println("related file num:\t" + indexresult.size()); return getRecord(indexresult, iscolumn, indexids, limit, fieldnum); }
From source file:com.sfs.beans.PrivilegesBean.java
/** * Gets a list of email addresses for the supplied user. * * @param user the user bean/* w w w.j a v a 2 s. com*/ * * @return the list of email addresses */ public final Collection<String> getEmailAddresses(final UserBean user) { Collection<String> addresses = new ArrayList<String>(); TreeMap<String, String> unique = new TreeMap<String, String>(); if (user.getMemberOf() != null) { for (String role : user.getMemberOf()) { if (role != null) { RoleBean roleBean = (RoleBean) this.roles.get(role); StringBuffer address = new StringBuffer(); if (StringUtils.isNotBlank(roleBean.getEmailAddress())) { address.append(roleBean.getEmailAddress().trim()); if (StringUtils.isNotBlank(roleBean.getEmailName())) { address.insert(0, roleBean.getEmailName().trim() + " <"); address.append(">"); } } if (StringUtils.isNotBlank(address.toString())) { unique.put(address.toString(), address.toString()); } } } } StringBuffer userAddress = new StringBuffer(); if (StringUtils.isNotBlank(user.getEmail())) { userAddress.append(user.getEmail().trim()); if (StringUtils.isNotBlank(user.getLastName())) { userAddress.insert(0, user.getLastName().trim() + " <"); userAddress.append(">"); } if (StringUtils.isNotBlank(user.getPreferredName())) { userAddress.insert(0, user.getPreferredName().trim() + " "); } // Remove the address if it is already in the unique tree map if (unique.containsKey(userAddress.toString())) { unique.remove(userAddress.toString()); } } // Add the user name to the top of the list if (StringUtils.isNotBlank(userAddress.toString())) { addresses.add(userAddress.toString()); } for (String address : unique.keySet()) { addresses.add(address); } return addresses; }
From source file:com.sfs.whichdoctor.webservice.RotationServiceImpl.java
/** * Process the rotation update.//w ww. ja v a2 s. co m * * @param traineeMIN the trainee MIN * @param rotationGUID the rotation GUID * @param educationMIN the education MIN * @param pdaMIN the pda MIN * @return the result string * @throws Exception the exception */ private boolean processRotationUpdate(final int traineeMIN, final int rotationGUID, final int educationMIN, final int pdaMIN) throws Exception { boolean success = false; // Check that the trainee, rotation and supervisor records exist. // If not return an error loadTrainee(traineeMIN); RotationBean rotation = loadRotation(rotationGUID); PersonBean educationSpvr = loadSupervisor(educationMIN); PersonBean pdaSpvr = loadSupervisor(pdaMIN); // Process the supervisor change ArrayList<SupervisorBean> updatedSupervisorList = new ArrayList<SupervisorBean>(); // This holds the existing supervisors that maybe changed TreeMap<String, ArrayList<SupervisorBean>> supervisorsToBeChanged = new TreeMap<String, ArrayList<SupervisorBean>>(); // First build a list of existing supervisors that do not need modifying if (rotation.getSupervisors() != null) { for (SupervisorBean spvr : rotation.getSupervisors()) { // At present function only changes the Education and PDA supervisors. // Any other supervisors should be added to the updated list. String type = spvr.getRelationshipType(); if (StringUtils.equalsIgnoreCase("Education", type) || StringUtils.equalsIgnoreCase("PDA", type)) { ArrayList<SupervisorBean> spvrs = new ArrayList<SupervisorBean>(); if (supervisorsToBeChanged.containsKey(type)) { spvrs = supervisorsToBeChanged.get(type); } if (StringUtils.equalsIgnoreCase("Education", type)) { // An education supervisor - if educationMIN < 0 then unchanged if (educationMIN < 0) { updatedSupervisorList.add(spvr); } else { spvrs.add(spvr); } } if (StringUtils.equalsIgnoreCase("PDA", type)) { // An education supervisor - if pdaMIN < 0 then unchanged if (pdaMIN < 0) { updatedSupervisorList.add(spvr); } else { spvrs.add(spvr); } } supervisorsToBeChanged.put(type, spvrs); } else { updatedSupervisorList.add(spvr); } } } // WhichDoctor can store multiple education/PDA supervisors, // but the web service only accepts one of each. int educationOrder = EDUCATION_ORDER; int pdaOrder = PDA_ORDER; // Update the education supervisor (if one is provided) if (educationSpvr != null) { boolean supervisorProcessed = false; if (supervisorsToBeChanged.containsKey("Education")) { // Education supervisors currently exist - check if new or existing. ArrayList<SupervisorBean> spvrs = supervisorsToBeChanged.get("Education"); for (SupervisorBean spvr : spvrs) { if (spvr.getPersonGUID() == educationSpvr.getGUID()) { // The supervisor already exists, add the updated list updatedSupervisorList.add(spvr); supervisorProcessed = true; } } } if (!supervisorProcessed) { // The supervisor does not currently exist, create new updatedSupervisorList .add(createSupervisor(rotation.getGUID(), educationSpvr, educationOrder, "Education")); } } // Update the PDA supervisor (if one is provided) if (pdaSpvr != null) { boolean supervisorProcessed = false; if (supervisorsToBeChanged.containsKey("PDA")) { // PDA supervisors currently exist - check if new or existing. ArrayList<SupervisorBean> spvrs = supervisorsToBeChanged.get("PDA"); for (SupervisorBean spvr : spvrs) { if (spvr.getPersonGUID() == pdaSpvr.getGUID()) { // The supervisor already exists, add the updated list updatedSupervisorList.add(spvr); supervisorProcessed = true; } } } if (!supervisorProcessed) { // The supervisor does not currently exist, create new updatedSupervisorList.add(createSupervisor(rotation.getGUID(), pdaSpvr, pdaOrder, "PDA")); } } // Add the updated list of supervisors rotation.setSupervisors(updatedSupervisorList); rotation.setLogMessage("Rotation supervisors updated by web service"); // Load the privileges bean for the change PrivilegesBean privileges = null; try { privileges = privilegesDAO.load(); } catch (SFSDaoException sde) { logger.error("Error loading privileges: " + sde.getMessage()); throw new Exception("Error loading privileges"); } // Update the rotation and supervisors try { rotationDAO.modify(rotation, this.user, privileges); success = true; } catch (WhichDoctorDaoException wde) { logger.error("Error modifying rotation: " + wde.getMessage()); throw new Exception("Cannot modify rotation - " + wde.getMessage()); } return success; }