List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:org.dllearner.reasoning.SPARQLReasoner.java
/** * Pre-computes the class hierarchy. Instead of executing queries for each class, * we query by the predicate rdfs:subClassOf. * @return the class hierarchy/* ww w . ja v a 2 s .com*/ */ public final ClassHierarchy prepareSubsumptionHierarchyFast() { logger.info("Preparing class subsumption hierarchy ..."); long startTime = System.currentTimeMillis(); TreeMap<OWLClassExpression, SortedSet<OWLClassExpression>> subsumptionHierarchyUp = new TreeMap<>(); TreeMap<OWLClassExpression, SortedSet<OWLClassExpression>> subsumptionHierarchyDown = new TreeMap<>(); String query = "SELECT * WHERE {" + "?sub a <http://www.w3.org/2002/07/owl#Class> . " // + "?sup a <http://www.w3.org/2002/07/owl#Class> . " + "?sub (<http://www.w3.org/2000/01/rdf-schema#subClassOf>|<http://www.w3.org/2002/07/owl#equivalentClass>) ?sup ." + "FILTER(?sub != ?sup)" + "}"; ResultSet rs = executeSelectQuery(query); while (rs.hasNext()) { QuerySolution qs = rs.next(); if (qs.get("sub").isURIResource() && qs.get("sup").isURIResource()) { OWLClass sub = df.getOWLClass(IRI.create(qs.get("sub").asResource().getURI())); OWLClass sup = df.getOWLClass(IRI.create(qs.get("sup").asResource().getURI())); //add subclasses SortedSet<OWLClassExpression> subClasses = subsumptionHierarchyDown.get(sup); if (subClasses == null) { subClasses = new TreeSet<>(); subsumptionHierarchyDown.put(sup, subClasses); } subClasses.add(sub); //add superclasses SortedSet<OWLClassExpression> superClasses = subsumptionHierarchyUp.get(sub); if (superClasses == null) { superClasses = new TreeSet<>(); subsumptionHierarchyUp.put(sub, superClasses); } superClasses.add(sup); } } logger.info("... done in {}ms", (System.currentTimeMillis() - startTime)); hierarchy = new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); return hierarchy; }
From source file:org.ecocean.Encounter.java
public String getDynamicPropertyValue(String name) { if (dynamicProperties != null) { name = name.replaceAll("%20", " "); //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); }/*from w w w . j av a 2 s .c o m*/ if (tm.containsKey(name)) { return tm.get(name); } } return null; }
From source file:com.adobe.cq.dialogconversion.datasources.DialogsDataSource.java
private void setDataSource(Resource resource, String path, ResourceResolver resourceResolver, SlingHttpServletRequest request, String itemResourceType) throws RepositoryException { List<Resource> resources = new ArrayList<Resource>(); if (StringUtils.isNotEmpty(path)) { Session session = request.getResourceResolver().adaptTo(Session.class); TreeMap<String, Node> nodeMap = new TreeMap<String, Node>(); // sanitize path path = path.trim();//from www. jav a2 s . c o m if (!path.startsWith("/")) { path = "/" + path; } // First check if the supplied path is a dialog node itself if (session.nodeExists(path)) { Node node = session.getNode(path); DialogType type = DialogRewriteUtils.getDialogType(node); if (type != DialogType.UNKNOWN && type != DialogType.CORAL_3) { nodeMap.put(node.getPath(), node); } } // If the path does not point to a dialog node: we query for dialog nodes if (nodeMap.isEmpty()) { String encodedPath = "/".equals(path) ? "" : ISO9075.encodePath(path); if (encodedPath.length() > 1 && encodedPath.endsWith("/")) { encodedPath = encodedPath.substring(0, encodedPath.length() - 1); } String classicStatement = "SELECT * FROM [" + NT_DIALOG + "] AS s WHERE ISDESCENDANTNODE(s, '" + encodedPath + "') " + "AND NAME() IN ('" + NameConstants.NN_DIALOG + "', '" + NameConstants.NN_DESIGN_DIALOG + "')"; String coral2Statement = "SELECT parent.* FROM [nt:unstructured] AS parent INNER JOIN [nt:unstructured] " + "AS child on ISCHILDNODE(child, parent) WHERE ISDESCENDANTNODE(parent, '" + encodedPath + "') " + "AND NAME(parent) IN ('" + NN_CQ_DIALOG + "', '" + NN_CQ_DIALOG + CORAL_2_BACKUP_SUFFIX + "', '" + NN_CQ_DESIGN_DIALOG + "', '" + NN_CQ_DESIGN_DIALOG + CORAL_2_BACKUP_SUFFIX + "') " + "AND NAME(child) = 'content' AND child.[sling:resourceType] NOT LIKE '" + DIALOG_CONTENT_RESOURCETYPE_PREFIX_CORAL3 + "%'"; QueryManager queryManager = session.getWorkspace().getQueryManager(); List<Query> queries = new ArrayList<Query>(); queries.add(queryManager.createQuery(classicStatement, Query.JCR_SQL2)); queries.add(queryManager.createQuery(coral2Statement, Query.JCR_SQL2)); for (Query query : queries) { NodeIterator iterator = query.execute().getNodes(); while (iterator.hasNext()) { Node node = iterator.nextNode(); Node parent = node.getParent(); if (parent != null) { // put design dialogs at a relative key String key = (DialogRewriteUtils.isDesignDialog(node)) ? parent.getPath() + "/" + NameConstants.NN_DESIGN_DIALOG : parent.getPath(); // backup Coral 2 dialogs shouldn't override none backup ones if (node.getName().endsWith(CORAL_2_BACKUP_SUFFIX) && nodeMap.get(key) != null) { continue; } nodeMap.put(key, node); } } } } int index = 0; Iterator iterator = nodeMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); Node dialog = (Node) entry.getValue(); if (dialog == null) { continue; } Node parent = dialog.getParent(); if (parent == null) { continue; } DialogType dialogType = DialogRewriteUtils.getDialogType(dialog); String dialogPath = dialog.getPath(); String type = dialogType.getString(); String href = externalizer.relativeLink(request, dialogPath) + ".html"; String crxHref = externalizer.relativeLink(request, CRX_LITE_PATH) + ".jsp#" + dialogPath; boolean isDesignDialog = DialogRewriteUtils.isDesignDialog(dialog); // only allow Coral 2 backup dialogs in the result if there's a replacement if (dialogType == DialogType.CORAL_2 && dialog.getName().endsWith(CORAL_2_BACKUP_SUFFIX)) { if ((!isDesignDialog && !parent.hasNode(NN_CQ_DIALOG)) || (isDesignDialog && !parent.hasNode(NN_CQ_DESIGN_DIALOG))) { continue; } } boolean converted = false; if (dialogType == DialogType.CLASSIC) { converted = isDesignDialog ? parent.hasNode(NN_CQ_DESIGN_DIALOG) : parent.hasNode(NN_CQ_DIALOG); } else if (dialogType == DialogType.CORAL_2) { converted = dialog.getName().endsWith(CORAL_2_BACKUP_SUFFIX); } Map<String, Object> map = new HashMap<String, Object>(); map.put("dialogPath", dialogPath); map.put("type", type); map.put("href", href); map.put("converted", converted); map.put("crxHref", crxHref); if (converted) { Node convertedNode = (isDesignDialog) ? parent.getNode(NN_CQ_DESIGN_DIALOG) : parent.getNode(NN_CQ_DIALOG); String touchHref = externalizer.relativeLink(request, convertedNode.getPath()) + ".html"; String touchCrxHref = externalizer.relativeLink(request, CRX_LITE_PATH) + ".jsp#" + convertedNode.getPath().replaceAll(":", "%3A"); map.put("touchHref", touchHref); map.put("touchCrxHref", touchCrxHref); } resources.add(new ValueMapResource(resourceResolver, resource.getPath() + "/dialog_" + index, itemResourceType, new ValueMapDecorator(map))); index++; } } DataSource ds = new SimpleDataSource(resources.iterator()); request.setAttribute(DataSource.class.getName(), ds); }
From source file:org.apache.hadoop.hbase.backup.util.RestoreTool.java
/** * Calculate region boundaries and add all the column families to the table descriptor * @param regionDirList region dir list//from w ww . ja v a2 s . c om * @return a set of keys to store the boundaries */ byte[][] generateBoundaryKeys(ArrayList<Path> regionDirList) throws FileNotFoundException, IOException { TreeMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR); // Build a set of keys to store the boundaries // calculate region boundaries and add all the column families to the table descriptor for (Path regionDir : regionDirList) { LOG.debug("Parsing region dir: " + regionDir); Path hfofDir = regionDir; if (!fs.exists(hfofDir)) { LOG.warn("HFileOutputFormat dir " + hfofDir + " not found"); } FileStatus[] familyDirStatuses = fs.listStatus(hfofDir); if (familyDirStatuses == null) { throw new IOException("No families found in " + hfofDir); } for (FileStatus stat : familyDirStatuses) { if (!stat.isDirectory()) { LOG.warn("Skipping non-directory " + stat.getPath()); continue; } boolean isIgnore = false; String pathName = stat.getPath().getName(); for (String ignore : ignoreDirs) { if (pathName.contains(ignore)) { LOG.warn("Skipping non-family directory" + pathName); isIgnore = true; break; } } if (isIgnore) { continue; } Path familyDir = stat.getPath(); LOG.debug("Parsing family dir [" + familyDir.toString() + " in region [" + regionDir + "]"); // Skip _logs, etc if (familyDir.getName().startsWith("_") || familyDir.getName().startsWith(".")) { continue; } // start to parse hfile inside one family dir Path[] hfiles = FileUtil.stat2Paths(fs.listStatus(familyDir)); for (Path hfile : hfiles) { if (hfile.getName().startsWith("_") || hfile.getName().startsWith(".") || StoreFileInfo.isReference(hfile.getName()) || HFileLink.isHFileLink(hfile.getName())) { continue; } HFile.Reader reader = HFile.createReader(fs, hfile, conf); final byte[] first, last; try { reader.loadFileInfo(); first = reader.getFirstRowKey(); last = reader.getLastRowKey(); LOG.debug("Trying to figure out region boundaries hfile=" + hfile + " first=" + Bytes.toStringBinary(first) + " last=" + Bytes.toStringBinary(last)); // To eventually infer start key-end key boundaries Integer value = map.containsKey(first) ? (Integer) map.get(first) : 0; map.put(first, value + 1); value = map.containsKey(last) ? (Integer) map.get(last) : 0; map.put(last, value - 1); } finally { reader.close(); } } } } return LoadIncrementalHFiles.inferBoundaries(map); }
From source file:org.apache.accumulo.shell.commands.ConfigCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceNotFoundException { reader = shellState.getReader();/*from ww w . ja v a2 s .c o m*/ final String tableName = cl.getOptionValue(tableOpt.getOpt()); if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName)) { throw new TableNotFoundException(null, tableName, null); } final String namespace = cl.getOptionValue(namespaceOpt.getOpt()); if (namespace != null && !shellState.getConnector().namespaceOperations().exists(namespace)) { throw new NamespaceNotFoundException(null, namespace, null); } if (cl.hasOption(deleteOpt.getOpt())) { // delete property from table String property = cl.getOptionValue(deleteOpt.getOpt()); if (property.contains("=")) { throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand, fullCommand.indexOf('=')); } if (tableName != null) { if (!Property.isValidTablePropertyKey(property)) { Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there."); } shellState.getConnector().tableOperations().removeProperty(tableName, property); Shell.log.debug("Successfully deleted table configuration option."); } else if (namespace != null) { if (!Property.isValidTablePropertyKey(property)) { Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there."); } shellState.getConnector().namespaceOperations().removeProperty(namespace, property); Shell.log.debug("Successfully deleted namespace configuration option."); } else { if (!Property.isValidZooPropertyKey(property)) { Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there."); } shellState.getConnector().instanceOperations().removeProperty(property); Shell.log.debug("Successfully deleted system configuration option"); } } else if (cl.hasOption(setOpt.getOpt())) { // set property on table String property = cl.getOptionValue(setOpt.getOpt()), value = null; if (!property.contains("=")) { throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand, fullCommand.indexOf(property)); } final String pair[] = property.split("=", 2); property = pair[0]; value = pair[1]; if (tableName != null) { if (!Property.isValidTablePropertyKey(property)) { throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property)); } if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) { new ColumnVisibility(value); // validate that it is a valid expression } shellState.getConnector().tableOperations().setProperty(tableName, property, value); Shell.log.debug("Successfully set table configuration option."); } else if (namespace != null) { if (!Property.isValidTablePropertyKey(property)) { throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property)); } if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) { new ColumnVisibility(value); // validate that it is a valid expression } shellState.getConnector().namespaceOperations().setProperty(namespace, property, value); Shell.log.debug("Successfully set table configuration option."); } else { if (!Property.isValidZooPropertyKey(property)) { throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand, fullCommand.indexOf(property)); } shellState.getConnector().instanceOperations().setProperty(property, value); Shell.log.debug("Successfully set system configuration option"); } } else { // display properties final TreeMap<String, String> systemConfig = new TreeMap<String, String>(); systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration()); final String outputFile = cl.getOptionValue(outputFileOpt.getOpt()); final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile); final TreeMap<String, String> siteConfig = new TreeMap<String, String>(); siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration()); final TreeMap<String, String> defaults = new TreeMap<String, String>(); for (Entry<String, String> defaultEntry : AccumuloConfiguration.getDefaultConfiguration()) { defaults.put(defaultEntry.getKey(), defaultEntry.getValue()); } final TreeMap<String, String> namespaceConfig = new TreeMap<String, String>(); if (tableName != null) { String n = Namespaces.getNamespaceName(shellState.getInstance(), Tables.getNamespaceId( shellState.getInstance(), Tables.getTableId(shellState.getInstance(), tableName))); for (Entry<String, String> e : shellState.getConnector().namespaceOperations().getProperties(n)) { namespaceConfig.put(e.getKey(), e.getValue()); } } Iterable<Entry<String, String>> acuconf = shellState.getConnector().instanceOperations() .getSystemConfiguration().entrySet(); if (tableName != null) { acuconf = shellState.getConnector().tableOperations().getProperties(tableName); } else if (namespace != null) { acuconf = shellState.getConnector().namespaceOperations().getProperties(namespace); } final TreeMap<String, String> sortedConf = new TreeMap<String, String>(); for (Entry<String, String> propEntry : acuconf) { sortedConf.put(propEntry.getKey(), propEntry.getValue()); } for (Entry<String, String> propEntry : acuconf) { final String key = propEntry.getKey(); // only show properties with similar names to that // specified, or all of them if none specified if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) { continue; } if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) { continue; } COL2 = Math.max(COL2, propEntry.getKey().length() + 3); } final ArrayList<String> output = new ArrayList<String>(); printConfHeader(output); for (Entry<String, String> propEntry : sortedConf.entrySet()) { final String key = propEntry.getKey(); // only show properties with similar names to that // specified, or all of them if none specified if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) { continue; } if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) { continue; } String siteVal = siteConfig.get(key); String sysVal = systemConfig.get(key); String curVal = propEntry.getValue(); String dfault = defaults.get(key); String nspVal = namespaceConfig.get(key); boolean printed = false; if (dfault != null && key.toLowerCase().contains("password")) { siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*"); } if (sysVal != null) { if (defaults.containsKey(key) && !Property.getPropertyByKey(key).isExperimental()) { printConfLine(output, "default", key, dfault); printed = true; } if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) { printConfLine(output, "site", printed ? " @override" : key, siteVal == null ? "" : siteVal); printed = true; } if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) { printConfLine(output, "system", printed ? " @override" : key, sysVal); printed = true; } } if (nspVal != null) { if (!systemConfig.containsKey(key) || !sysVal.equals(nspVal)) { printConfLine(output, "namespace", printed ? " @override" : key, nspVal); printed = true; } } // show per-table value only if it is different (overridden) if (tableName != null && !curVal.equals(nspVal)) { printConfLine(output, "table", printed ? " @override" : key, curVal); } else if (namespace != null && !curVal.equals(sysVal)) { printConfLine(output, "namespace", printed ? " @override" : key, curVal); } } printConfFooter(output); shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile); if (printFile != null) { printFile.close(); } } return 0; }
From source file:org.apache.accumulo.core.util.shell.commands.ConfigCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceNotFoundException { reader = shellState.getReader();//www . j a va2s . co m final String tableName = cl.getOptionValue(tableOpt.getOpt()); if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName)) { throw new TableNotFoundException(null, tableName, null); } final String namespace = cl.getOptionValue(namespaceOpt.getOpt()); if (namespace != null && !shellState.getConnector().namespaceOperations().exists(namespace)) { throw new NamespaceNotFoundException(null, namespace, null); } if (cl.hasOption(deleteOpt.getOpt())) { // delete property from table String property = cl.getOptionValue(deleteOpt.getOpt()); if (property.contains("=")) { throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand, fullCommand.indexOf('=')); } if (tableName != null) { if (!Property.isValidTablePropertyKey(property)) { Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there."); } shellState.getConnector().tableOperations().removeProperty(tableName, property); Shell.log.debug("Successfully deleted table configuration option."); } else if (namespace != null) { if (!Property.isValidTablePropertyKey(property)) { Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there."); } shellState.getConnector().namespaceOperations().removeProperty(namespace, property); Shell.log.debug("Successfully deleted namespace configuration option."); } else { if (!Property.isValidZooPropertyKey(property)) { Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there."); } shellState.getConnector().instanceOperations().removeProperty(property); Shell.log.debug("Successfully deleted system configuration option"); } } else if (cl.hasOption(setOpt.getOpt())) { // set property on table String property = cl.getOptionValue(setOpt.getOpt()), value = null; if (!property.contains("=")) { throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand, fullCommand.indexOf(property)); } final String pair[] = property.split("=", 2); property = pair[0]; value = pair[1]; if (tableName != null) { if (!Property.isValidTablePropertyKey(property)) { throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property)); } if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) { new ColumnVisibility(value); // validate that it is a valid expression } shellState.getConnector().tableOperations().setProperty(tableName, property, value); Shell.log.debug("Successfully set table configuration option."); } else if (namespace != null) { if (!Property.isValidTablePropertyKey(property)) { throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property)); } if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) { new ColumnVisibility(value); // validate that it is a valid expression } shellState.getConnector().namespaceOperations().setProperty(namespace, property, value); Shell.log.debug("Successfully set table configuration option."); } else { if (!Property.isValidZooPropertyKey(property)) { throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand, fullCommand.indexOf(property)); } shellState.getConnector().instanceOperations().setProperty(property, value); Shell.log.debug("Successfully set system configuration option"); } } else { // display properties final TreeMap<String, String> systemConfig = new TreeMap<String, String>(); systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration()); final String outputFile = cl.getOptionValue(outputFileOpt.getOpt()); final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile); final TreeMap<String, String> siteConfig = new TreeMap<String, String>(); siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration()); final TreeMap<String, String> defaults = new TreeMap<String, String>(); for (Entry<String, String> defaultEntry : AccumuloConfiguration.getDefaultConfiguration()) { defaults.put(defaultEntry.getKey(), defaultEntry.getValue()); } final TreeMap<String, String> namespaceConfig = new TreeMap<String, String>(); if (tableName != null) { String n = Namespaces.getNamespaceName(shellState.getInstance(), Tables.getNamespaceId( shellState.getInstance(), Tables.getTableId(shellState.getInstance(), tableName))); for (Entry<String, String> e : shellState.getConnector().namespaceOperations().getProperties(n)) { namespaceConfig.put(e.getKey(), e.getValue()); } } Iterable<Entry<String, String>> acuconf = shellState.getConnector().instanceOperations() .getSystemConfiguration().entrySet(); if (tableName != null) { acuconf = shellState.getConnector().tableOperations().getProperties(tableName); } else if (namespace != null) { acuconf = shellState.getConnector().namespaceOperations().getProperties(namespace); } final TreeMap<String, String> sortedConf = new TreeMap<String, String>(); for (Entry<String, String> propEntry : acuconf) { sortedConf.put(propEntry.getKey(), propEntry.getValue()); } for (Entry<String, String> propEntry : acuconf) { final String key = propEntry.getKey(); // only show properties with similar names to that // specified, or all of them if none specified if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) { continue; } if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) { continue; } COL2 = Math.max(COL2, propEntry.getKey().length() + 3); } final ArrayList<String> output = new ArrayList<String>(); printConfHeader(output); for (Entry<String, String> propEntry : sortedConf.entrySet()) { final String key = propEntry.getKey(); // only show properties with similar names to that // specified, or all of them if none specified if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) { continue; } if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) { continue; } String siteVal = siteConfig.get(key); String sysVal = systemConfig.get(key); String curVal = propEntry.getValue(); String dfault = defaults.get(key); String nspVal = namespaceConfig.get(key); boolean printed = false; if (dfault != null && key.toLowerCase().contains("password")) { siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*"); } if (sysVal != null) { if (defaults.containsKey(key)) { printConfLine(output, "default", key, dfault); printed = true; } if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) { printConfLine(output, "site", printed ? " @override" : key, siteVal == null ? "" : siteVal); printed = true; } if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) { printConfLine(output, "system", printed ? " @override" : key, sysVal == null ? "" : sysVal); printed = true; } } if (nspVal != null) { if (!systemConfig.containsKey(key) || !sysVal.equals(nspVal)) { printConfLine(output, "namespace", printed ? " @override" : key, nspVal == null ? "" : nspVal); printed = true; } } // show per-table value only if it is different (overridden) if (tableName != null && !curVal.equals(nspVal)) { printConfLine(output, "table", printed ? " @override" : key, curVal); } else if (namespace != null && !curVal.equals(sysVal)) { printConfLine(output, "namespace", printed ? " @override" : key, curVal); } } printConfFooter(output); shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile); if (printFile != null) { printFile.close(); } } return 0; }
From source file:architecture.user.spring.controller.SecureUserMgmtDataController.java
@RequestMapping(value = "/mgmt/permissions/list.json", method = { RequestMethod.POST }) @ResponseBody/*from w ww . ja v a 2 s . c o m*/ public Map<String, Object> listAllPermissions(@RequestBody PermsSetForm permsSetGroup) { User currentUser = SecurityHelper.getUser(); List<PermSet> list1 = new ArrayList<PermSet>(); List<PermSet> list2 = new ArrayList<PermSet>(); List<UserPermSet> list3 = new ArrayList<UserPermSet>(); List<GroupPermSet> list4 = new ArrayList<GroupPermSet>(); TreeMap<User, UserPermSet> tree1 = new TreeMap<User, UserPermSet>(new Comparator<User>() { public int compare(User o1, User o2) { return o1.getUsername().toLowerCase().compareTo(o2.getUsername().toLowerCase()); } }); TreeMap<Group, GroupPermSet> tree2 = new TreeMap<Group, GroupPermSet>(new Comparator<Group>() { public int compare(Group o1, Group o2) { return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase()); } }); PermissionsManagerHelper helper = getPermissionsManagerHelper(permsSetGroup.getObjectType(), permsSetGroup.getObjectId()); for (String permissionName : permsSetGroup.getPerms()) { long permission = Permissions.PermissionAtom.valueOf(permissionName).getAtomId(); if (Permissions.PermissionAtom.valueOf(permissionName) != null) permission = Permissions.PermissionAtom.valueOf(permissionName).getAtomId(); else permission = permissionsManager.getPermissionMask(permissionName); log.debug("permission:" + permissionName + "(" + permission + ")"); // anonymous PermSet p1 = new PermSet(permissionName); p1.setAdditive(helper.anonymousUserHasPermission(PermissionType.ADDITIVE, permission)); p1.setNegative(helper.anonymousUserHasPermission(PermissionType.NEGATIVE, permission)); p1.setInherited(false); list1.add(p1); // member PermSet p2 = new PermSet(permissionName); p2.setAdditive(helper.registeredUserHasPermission(PermissionType.ADDITIVE, permission)); p2.setNegative(helper.registeredUserHasPermission(PermissionType.NEGATIVE, permission)); p2.setInherited(false); list2.add(p2); // users log.debug("user : " + helper.usersWithPermissionCount(PermissionType.ADDITIVE, permission)); for (User user : helper.usersWithPermission(PermissionType.ADDITIVE, permission)) { if (tree1.containsKey(user)) { UserPermSet up = tree1.get(user); up.getPermSet(permissionName, true).setAdditive(true); } else { UserPermSet up = new UserPermSet(user); up.getPermSet(permissionName, true).setAdditive(true); tree1.put(user, up); } } for (User user : helper.usersWithPermission(PermissionType.NEGATIVE, permission)) { if (tree1.containsKey(user)) { UserPermSet up = tree1.get(user); up.getPermSet(permissionName, true).setNegative(true); } else { UserPermSet up = new UserPermSet(user); up.getPermSet(permissionName, true).setNegative(true); tree1.put(user, up); } } // groups log.debug("group : " + helper.groupsWithPermissionCount(PermissionType.ADDITIVE, permission)); for (Group group : helper.groupsWithPermission(PermissionType.ADDITIVE, permission)) { if (tree1.containsKey(group)) { GroupPermSet gp = tree2.get(group); gp.getPermSet(permissionName, true).setAdditive(true); } else { GroupPermSet gp = new GroupPermSet(group); gp.getPermSet(permissionName, true).setAdditive(true); tree2.put(group, gp); } } for (Group group : helper.groupsWithPermission(PermissionType.NEGATIVE, permission)) { if (tree1.containsKey(group)) { GroupPermSet gp = tree2.get(group); gp.getPermSet(permissionName, true).setNegative(true); } else { GroupPermSet gp = new GroupPermSet(group); gp.getPermSet(permissionName, true).setNegative(true); tree2.put(group, gp); } } } list3.addAll(tree1.values()); list4.addAll(tree2.values()); Map<String, Object> map = new HashMap<String, Object>(); map.put("anonymous", list1); map.put("member", list2); map.put("users", list3); map.put("groups", list4); return map; }
From source file:net.triptech.metahive.messaging.JmsMetahiveContributionListener.java
private int processSubmission(final Submission submission) { int processCount = 0; // Build the validated data grid ValidatedDataGrid dataGrid = new ValidatedDataGrid(submission.getRawDataGrid()); MetahivePreferences prefs = MetahivePreferences.load(); TreeMap<Integer, Definition> definitions = new TreeMap<Integer, Definition>(); int columnIndex = 0; int primaryIndex = 0; int secondaryIndex = 0; int tertiaryIndex = 0; for (ValidatedField field : dataGrid.getHeaderFields()) { logger.info("Field valid: " + field.isValid()); logger.info("Id field: " + field.isIdField()); logger.info("Field value: " + field.getValue()); logger.info("Column index: " + columnIndex); if (field.isValid()) { if (field.isIdField()) { if (StringUtils.equalsIgnoreCase(prefs.getPrimaryRecordName(), field.getValue())) { primaryIndex = columnIndex; }//from w w w . ja v a 2 s .c o m if (StringUtils.equalsIgnoreCase(prefs.getSecondaryRecordName(), field.getValue())) { secondaryIndex = columnIndex; } if (StringUtils.equalsIgnoreCase(prefs.getTertiaryRecordName(), field.getValue())) { tertiaryIndex = columnIndex; } } else { Definition definition = Definition.findDefinitionByNameEquals(field.getValue()); definitions.put(columnIndex, definition); } } columnIndex++; } for (ValidatedRow row : dataGrid.getRows()) { if (row.isValid()) { // Load the record String primaryRecord = ""; String secondaryRecord = ""; String tertiaryRecord = ""; primaryRecord = row.getFields().get(primaryIndex).getValue(); if (secondaryIndex > 0) { secondaryRecord = row.getFields().get(secondaryIndex).getValue(); } if (tertiaryIndex > 0) { tertiaryRecord = row.getFields().get(tertiaryIndex).getValue(); } if (StringUtils.isBlank(secondaryRecord) && StringUtils.isNotBlank(prefs.getSecondaryRecordDefault())) { secondaryRecord = prefs.getSecondaryRecordDefault(); } if (StringUtils.isBlank(tertiaryRecord) && StringUtils.isNotBlank(prefs.getTertiaryRecordDefault())) { tertiaryRecord = prefs.getTertiaryRecordDefault(); } if (StringUtils.isNotBlank(secondaryRecord)) { secondaryRecord = KeyValueCalculator.parseRecordId(secondaryRecord); } if (StringUtils.isNotBlank(tertiaryRecord)) { tertiaryRecord = KeyValueCalculator.parseRecordId(tertiaryRecord); } logger.info("Primary record: " + primaryRecord); logger.info("Secondary record: " + secondaryRecord); logger.info("Tertiary record: " + tertiaryRecord); Record record = Record.findRecordByRecordIdEquals(primaryRecord); logger.info("Record id: " + record.getId()); if (record != null) { for (int index : definitions.keySet()) { Definition definition = definitions.get(index); ValidatedField cell = row.getFields().get(index); if (cell.isValid() && StringUtils.isNotBlank(cell.getValue())) { SubmittedField field = new SubmittedField(); field.setDefinition(definition); field.setRecord(record); field.setSubmission(submission); field.setPrimaryRecordId(primaryRecord); field.setSecondaryRecordId(secondaryRecord); field.setTertiaryRecordId(tertiaryRecord); field.setValue(cell.getValue().trim()); field.persist(); field.flush(); processCount++; logger.info("Submitted field id: " + field.getId()); JmsRecalculateRequest req = new JmsRecalculateRequest(field); keyValueGenerationTemplate.convertAndSend(req); } } } } } return processCount; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java
public GraphCleaningResults processSingleFile(File file, File outputDir, String prefix, Boolean collectGeneratedArgumentPairs) throws Exception { GraphCleaningResults result = new GraphCleaningResults(); File outFileTable = new File(outputDir, prefix + file.getName() + "_table.csv"); File outFileInfo = new File(outputDir, prefix + file.getName() + "_info.txt"); PrintStream psTable = new PrintStream(new FileOutputStream(outFileTable)); PrintStream psInfo = new PrintStream(new FileOutputStream(outFileInfo)); // load one topic/side List<AnnotatedArgumentPair> pairs = new ArrayList<>( (List<AnnotatedArgumentPair>) XStreamTools.getXStream().fromXML(file)); int fullDataSize = pairs.size(); // filter out missing gold data Iterator<AnnotatedArgumentPair> iterator = pairs.iterator(); while (iterator.hasNext()) { AnnotatedArgumentPair pair = iterator.next(); if (pair.getGoldLabel() == null) { iterator.remove();/*from w w w.j a va 2s. c o m*/ } // or we want to completely remove equal edges in advance! else if (this.removeEqualEdgesParam && "equal".equals(pair.getGoldLabel())) { iterator.remove(); } } // sort pairs by their weight this.argumentPairListSorter.sortArgumentPairs(pairs); int preFilteredDataSize = pairs.size(); // compute correlation between score threshold and number of removed edges double[] correlationEdgeWeights = new double[pairs.size()]; double[] correlationRemovedEdges = new double[pairs.size()]; // only cycles of length 0 to 5 are interesting (5+ are too big) Range<Integer> range = Range.between(0, 5); psTable.print( "EdgeWeightThreshold\tPairs\tignoredEdgesCount\tIsDAG\tTransitivityScoreMean\tTransitivityScoreMax\tTransitivityScoreSamples\tEdges\tNodes\t"); for (int j = range.getMinimum(); j <= range.getMaximum(); j++) { psTable.print("Cycles_" + j + "\t"); } psTable.println(); // store the indices of all pairs (edges) that have been successfully added without // generating cycles TreeSet<Integer> addedPairsIndices = new TreeSet<>(); // number of edges ignored as they generated cycles int ignoredEdgesCount = 0; Graph lastGraph = null; // flag that the first cycle was already processed boolean firstCycleAlreadyHit = false; for (int i = 1; i < pairs.size(); i++) { // now filter the finalArgumentPairList and add only pairs that have not generated cycles List<AnnotatedArgumentPair> subList = new ArrayList<>(); for (Integer index : addedPairsIndices) { subList.add(pairs.get(index)); } // and add the current at the end subList.add(pairs.get(i)); // what is the current lowest value of a pair weight? double weakestEdgeWeight = computeEdgeWeight(subList.get(subList.size() - 1), LAMBDA_PENALTY); // Graph graph = buildGraphFromArgumentPairs(finalArgumentPairList); int numberOfLoops; // map for storing cycles by their length TreeMap<Integer, TreeSet<String>> lengthCyclesMap = new TreeMap<>(); Graph graph = buildGraphFromArgumentPairs(subList); lastGraph = graph; List<List<Object>> cyclesInGraph = findCyclesInGraph(graph); DescriptiveStatistics transitivityScore = new DescriptiveStatistics(); if (cyclesInGraph.isEmpty()) { // we have DAG transitivityScore = computeTransitivityScores(graph); // update results result.maxTransitivityScore = (int) transitivityScore.getMax(); result.avgTransitivityScore = transitivityScore.getMean(); } numberOfLoops = cyclesInGraph.size(); // initialize map for (int r = range.getMinimum(); r <= range.getMaximum(); r++) { lengthCyclesMap.put(r, new TreeSet<String>()); } // we hit a loop if (numberOfLoops > 0) { // let's update the result if (!firstCycleAlreadyHit) { result.graphSizeEdgesBeforeFirstCycle = graph.getEdgeCount(); result.graphSizeNodesBeforeFirstCycle = graph.getNodeCount(); // find the shortest cycle int shortestCycleLength = Integer.MAX_VALUE; for (List<Object> cycle : cyclesInGraph) { shortestCycleLength = Math.min(shortestCycleLength, cycle.size()); } result.lengthOfFirstCircle = shortestCycleLength; result.pairsBeforeFirstCycle = i; firstCycleAlreadyHit = true; } // ignore this edge further ignoredEdgesCount++; // update counts of different cycles lengths for (List<Object> cycle : cyclesInGraph) { int currentSize = cycle.size(); // convert to sorted set of nodes List<String> cycleAsSortedIDs = new ArrayList<>(); for (Object o : cycle) { cycleAsSortedIDs.add(o.toString()); } Collections.sort(cycleAsSortedIDs); if (range.contains(currentSize)) { lengthCyclesMap.get(currentSize).add(cycleAsSortedIDs.toString()); } } } else { addedPairsIndices.add(i); } // we hit the first cycle // collect loop sizes StringBuilder loopsAsString = new StringBuilder(); for (int j = range.getMinimum(); j <= range.getMaximum(); j++) { // loopsAsString.append(j).append(":"); loopsAsString.append(lengthCyclesMap.get(j).size()); loopsAsString.append("\t"); } psTable.printf(Locale.ENGLISH, "%.4f\t%d\t%d\t%b\t%.2f\t%d\t%d\t%d\t%d\t%s%n", weakestEdgeWeight, i, ignoredEdgesCount, numberOfLoops == 0, Double.isNaN(transitivityScore.getMean()) ? 0d : transitivityScore.getMean(), (int) transitivityScore.getMax(), transitivityScore.getN(), graph.getEdgeCount(), graph.getNodeCount(), loopsAsString.toString().trim()); // update result result.finalGraphSizeEdges = graph.getEdgeCount(); result.finalGraphSizeNodes = graph.getNodeCount(); result.ignoredEdgesThatBrokeDAG = ignoredEdgesCount; // update stats for correlation correlationEdgeWeights[i] = weakestEdgeWeight; // correlationRemovedEdges[i] = (double) ignoredEdgesCount; // let's try: if we keep = 0, if we remove = 1 correlationRemovedEdges[i] = numberOfLoops == 0 ? 0.0 : 1.0; } psInfo.println("Original: " + fullDataSize + ", removed by MACE: " + (fullDataSize - preFilteredDataSize) + ", final: " + (preFilteredDataSize - ignoredEdgesCount) + " (removed: " + ignoredEdgesCount + ")"); double[][] matrix = new double[correlationEdgeWeights.length][]; for (int i = 0; i < correlationEdgeWeights.length; i++) { matrix[i] = new double[2]; matrix[i][0] = correlationEdgeWeights[i]; matrix[i][1] = correlationRemovedEdges[i]; } PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation(matrix); double pValue = pearsonsCorrelation.getCorrelationPValues().getEntry(0, 1); double correlation = pearsonsCorrelation.getCorrelationMatrix().getEntry(0, 1); psInfo.printf(Locale.ENGLISH, "Correlation: %.3f, p-Value: %.4f%n", correlation, pValue); if (lastGraph == null) { throw new IllegalStateException("Graph is null"); } // close psInfo.close(); psTable.close(); // save filtered final gold data List<AnnotatedArgumentPair> finalArgumentPairList = new ArrayList<>(); for (Integer index : addedPairsIndices) { finalArgumentPairList.add(pairs.get(index)); } XStreamTools.toXML(finalArgumentPairList, new File(outputDir, prefix + file.getName())); // TODO: here, we can add newly generated edges from graph transitivity if (collectGeneratedArgumentPairs) { Set<GeneratedArgumentPair> generatedArgumentPairs = new HashSet<>(); // collect all arguments Map<String, Argument> allArguments = new HashMap<>(); for (ArgumentPair argumentPair : pairs) { allArguments.put(argumentPair.getArg1().getId(), argumentPair.getArg1()); allArguments.put(argumentPair.getArg2().getId(), argumentPair.getArg2()); } Graph finalGraph = buildGraphFromArgumentPairs(finalArgumentPairList); for (Edge e : finalGraph.getEdgeSet()) { e.setAttribute(WEIGHT, 1.0); } for (Node j : finalGraph) { for (Node k : finalGraph) { if (j != k) { // is there a path between? BellmanFord bfShortest = new BellmanFord(WEIGHT, j.getId()); bfShortest.init(finalGraph); bfShortest.compute(); Path shortestPath = bfShortest.getShortestPath(k); if (shortestPath.size() > 0) { // we have a path GeneratedArgumentPair ap = new GeneratedArgumentPair(); Argument arg1 = allArguments.get(j.getId()); if (arg1 == null) { throw new IllegalStateException("Cannot find argument " + j.getId()); } ap.setArg1(arg1); Argument arg2 = allArguments.get(k.getId()); if (arg2 == null) { throw new IllegalStateException("Cannot find argument " + k.getId()); } ap.setArg2(arg2); ap.setGoldLabel("a1"); generatedArgumentPairs.add(ap); } } } } // and now add the reverse ones Set<GeneratedArgumentPair> generatedReversePairs = new HashSet<>(); for (GeneratedArgumentPair pair : generatedArgumentPairs) { GeneratedArgumentPair ap = new GeneratedArgumentPair(); ap.setArg1(pair.getArg2()); ap.setArg2(pair.getArg1()); ap.setGoldLabel("a2"); generatedReversePairs.add(ap); } generatedArgumentPairs.addAll(generatedReversePairs); // and save it XStreamTools.toXML(generatedArgumentPairs, new File(outputDir, "generated_" + prefix + file.getName())); } result.fullPairsSize = fullDataSize; result.removedApriori = (fullDataSize - preFilteredDataSize); result.finalPairsRetained = finalArgumentPairList.size(); // save the final graph Graph outGraph = cleanCopyGraph(lastGraph); FileSinkDGS dgs1 = new FileSinkDGS(); File outFile = new File(outputDir, prefix + file.getName() + ".dgs"); System.out.println("Saved to " + outFile); FileWriter w1 = new FileWriter(outFile); dgs1.writeAll(outGraph, w1); w1.close(); return result; }
From source file:org.apache.hadoop.hbase.backup.util.RestoreServerUtil.java
/** * Calculate region boundaries and add all the column families to the table descriptor * @param regionDirList region dir list/*from w w w .ja v a2s . c om*/ * @return a set of keys to store the boundaries */ byte[][] generateBoundaryKeys(ArrayList<Path> regionDirList) throws FileNotFoundException, IOException { TreeMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR); // Build a set of keys to store the boundaries byte[][] keys = null; // calculate region boundaries and add all the column families to the table descriptor for (Path regionDir : regionDirList) { LOG.debug("Parsing region dir: " + regionDir); Path hfofDir = regionDir; if (!fs.exists(hfofDir)) { LOG.warn("HFileOutputFormat dir " + hfofDir + " not found"); } FileStatus[] familyDirStatuses = fs.listStatus(hfofDir); if (familyDirStatuses == null) { throw new IOException("No families found in " + hfofDir); } for (FileStatus stat : familyDirStatuses) { if (!stat.isDirectory()) { LOG.warn("Skipping non-directory " + stat.getPath()); continue; } boolean isIgnore = false; String pathName = stat.getPath().getName(); for (String ignore : ignoreDirs) { if (pathName.contains(ignore)) { LOG.warn("Skipping non-family directory" + pathName); isIgnore = true; break; } } if (isIgnore) { continue; } Path familyDir = stat.getPath(); LOG.debug("Parsing family dir [" + familyDir.toString() + " in region [" + regionDir + "]"); // Skip _logs, etc if (familyDir.getName().startsWith("_") || familyDir.getName().startsWith(".")) { continue; } // start to parse hfile inside one family dir Path[] hfiles = FileUtil.stat2Paths(fs.listStatus(familyDir)); for (Path hfile : hfiles) { if (hfile.getName().startsWith("_") || hfile.getName().startsWith(".") || StoreFileInfo.isReference(hfile.getName()) || HFileLink.isHFileLink(hfile.getName())) { continue; } HFile.Reader reader = HFile.createReader(fs, hfile, new CacheConfig(conf), conf); final byte[] first, last; try { reader.loadFileInfo(); first = reader.getFirstRowKey(); last = reader.getLastRowKey(); LOG.debug("Trying to figure out region boundaries hfile=" + hfile + " first=" + Bytes.toStringBinary(first) + " last=" + Bytes.toStringBinary(last)); // To eventually infer start key-end key boundaries Integer value = map.containsKey(first) ? (Integer) map.get(first) : 0; map.put(first, value + 1); value = map.containsKey(last) ? (Integer) map.get(last) : 0; map.put(last, value - 1); } finally { reader.close(); } } } } keys = LoadIncrementalHFiles.inferBoundaries(map); return keys; }