List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:de.thorstenberger.examServer.service.impl.ConfigManagerImpl.java
/** * *//*from w ww .java 2s . c o m*/ public ConfigManagerImpl(final ExamServerManager examServerManager) { this.examServerManager = examServerManager; try { // JAXBException jc = JAXBContext.newInstance("de.thorstenberger.examServer.dao.xml.jaxb"); configFile = new File(examServerManager.getSystemDir(), "config.xml"); if (!configFile.exists()) { final ObjectFactory oF = new ObjectFactory(); config = oF.createConfig(); config.setStudentsLoginEnabled(false); config.setLoadJVMOnStartup(false); setPDFSignatureInfos(new SignatureInfos()); // load initial title from filesystem final Properties prop = new Properties(); prop.load(this.getClass().getClassLoader().getResourceAsStream("initialTitle.properties")); config.setTitle((String) prop.get("title")); save(); return; } // wenn vorhanden, dann auslesen Unmarshaller unmarshaller; unmarshaller = jc.createUnmarshaller(); final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(configFile)); config = (Config) unmarshaller.unmarshal(bis); } catch (final JAXBException e) { throw new RuntimeException(e); } catch (final IOException e1) { throw new RuntimeException(e1); } }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.ideainstance.ApiIdeaInstanceInterface.java
/** * GET http://localhost:8080/<portal>/api/rs/en/ideaInstances?id=1 * @param properties/* w w w. jav a 2 s.c o m*/ * @return * @throws Throwable */ public JAXBIdeaInstance getIdeaInstanceForApi(Properties properties) throws Throwable { JAXBIdeaInstance jaxbIdeaInstance = null; try { String codeParam = properties.getProperty("code"); if (StringUtils.isNotBlank(codeParam)) codeParam = URLDecoder.decode(codeParam, "UTF-8"); UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER); //TODO CREATE ROLE List<Integer> ideaStateFilter = new ArrayList<Integer>(); ideaStateFilter.add(IIdea.STATUS_APPROVED); if (null != user && !this.getAuthorizationManager().isAuthOnPermission(user, Permission.SUPERUSER)) { ideaStateFilter.clear(); } IdeaInstance ideaInstance = this.getIdeaInstanceManager().getIdeaInstance(codeParam, ideaStateFilter); if (null == ideaInstance) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + codeParam + "' does not exist", Response.Status.CONFLICT); } if (!isAuthOnInstance(user, ideaInstance)) { _logger.warn("the current user is not granted to any group required by instance {}", codeParam); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + codeParam + "' does not exist", Response.Status.CONFLICT); } jaxbIdeaInstance = new JAXBIdeaInstance(ideaInstance); } catch (ApiException ae) { throw ae; } catch (Throwable t) { _logger.error("Error extracting ideaInstance", t); throw new ApsSystemException("Error extracting idea instance", t); } return jaxbIdeaInstance; }
From source file:ai.grakn.engine.controller.SystemController.java
@GET @Path("/configuration") @ApiOperation(value = "Get config which is used to build graphs") @ApiImplicitParam(name = "graphConfig", value = "The type of graph config to return", required = true, dataType = "string", paramType = "path") private String getConfiguration(Request request, Response response) { String graphConfig = request.queryParams(GRAPH_CONFIG_PARAM); // Make a copy of the properties object Properties properties = new Properties(); properties.putAll(factory.properties()); // Get the correct factory based on the request switch ((graphConfig != null) ? graphConfig : DEFAULT) { case DEFAULT: break; // Factory is already correctly set case COMPUTER: properties.setProperty(FACTORY_INTERNAL, properties.get(FACTORY_ANALYTICS).toString()); break;//from w w w. j ava2 s .c o m default: throw GraknServerException.internalError("Unrecognised graph config: " + graphConfig); } // Turn the properties into a Json object Json config = Json.make(properties); // Remove the JWT Secret if (config.has(GraknEngineConfig.JWT_SECRET_PROPERTY)) { config.delAt(GraknEngineConfig.JWT_SECRET_PROPERTY); } return config.toString(); }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that meta data are transfered by reformat. * The input file to this test was created with the following command: * goby 1g fasta-to-compact -k key1 -v value1 -k key2 -v value2 test-data/fastx-test-data/test-fastq-1.fq -o test-data/compact-reads/with-meta-data-input.compact-reads * * @throws IOException if there is a problem reading or writing to the files *//*from ww w.j a v a 2 s .c o m*/ @Test public void reformatTransferMetaData() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/with-meta-data-input.compact-reads"; reformat.setInputFilenames(inputFilename); final String outputFilename = "test-results/with-meta-data-output.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); ReadsReader reader1 = new ReadsReader(inputFilename); for (Reads.ReadEntry it : reader1) { System.out.println(it.toString()); System.out.println(); } ReadsReader reader2 = new ReadsReader(outputFilename); for (Reads.ReadEntry it : reader2) { System.out.println(it.toString()); System.out.println(); } assertTrue(FileUtils.contentEquals(new File(inputFilename), new File(outputFilename))); final ReadsReader reader = new ReadsReader(FileUtils.openInputStream(new File(outputFilename))); assertTrue("There should be reads in this file", reader.hasNext()); final Reads.ReadEntry entry = reader.next(); assertNotNull("Entry should not be null", entry); Properties keyValuePairs = reader.getMetaData(); assertEquals("key/value pairs must match", "value1", keyValuePairs.get("key1")); assertEquals("key/value pairs must match", "value2", keyValuePairs.get("key2")); }
From source file:com.linkedin.kmf.common.Utils.java
/** * Create the topic that the monitor uses to monitor the cluster. This method attempts to create a topic so that all * the brokers in the cluster will have partitionToBrokerRatio partitions. If the topic exists, but has different parameters * then this does nothing to update the parameters. * * TODO: Do we care about rack aware mode? I would think no because we want to spread the topic over all brokers. * @param zkUrl zookeeper connection url * @param topic topic name/*ww w . j a v a 2 s . com*/ * @param replicationFactor the replication factor for the topic * @param partitionToBrokerRatio This is multiplied by the number brokers to compute the number of partitions in the topic. * @param topicConfig additional parameters for the topic for example min.insync.replicas * @return the number of partitions created */ public static int createMonitoringTopicIfNotExists(String zkUrl, String topic, int replicationFactor, double partitionToBrokerRatio, Properties topicConfig) { ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled()); try { if (AdminUtils.topicExists(zkUtils, topic)) { LOG.info("Monitoring topic \"" + topic + "\" already exists."); return getPartitionNumForTopic(zkUrl, topic); } int brokerCount = zkUtils.getAllBrokersInCluster().size(); int partitionCount = (int) Math.ceil(brokerCount * partitionToBrokerRatio); int defaultMinIsr = Math.max(replicationFactor - 1, 1); if (!topicConfig.containsKey(KafkaConfig.MinInSyncReplicasProp())) { topicConfig.setProperty(KafkaConfig.MinInSyncReplicasProp(), Integer.toString(defaultMinIsr)); } try { AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, topicConfig, RackAwareMode.Enforced$.MODULE$); } catch (TopicExistsException tee) { //There is a race condition with the consumer. LOG.info("Monitoring topic \"" + topic + "\" already exists (caught exception)."); return getPartitionNumForTopic(zkUrl, topic); } LOG.info("Created monitoring topic \"" + topic + "\" with " + partitionCount + " partitions, min ISR of " + topicConfig.get(KafkaConfig.MinInSyncReplicasProp()) + " and replication factor of " + replicationFactor + "."); return partitionCount; } finally { zkUtils.close(); } }
From source file:edu.mayo.qdm.webapp.rest.store.Md5HashFileSystemResolver.java
/** * File to execution info./*from w ww .ja va 2 s . c o m*/ * * @param dataFile the data file * @return the execution info */ private ExecutionInfo fileToExecutionInfo(File dataFile) { ExecutionInfo info = new ExecutionInfo(); Properties props = new Properties(); try { PropertiesUtil.loadFromFile(props, dataFile); } catch (IOException e) { throw new RuntimeException(e); } info.setId((String) props.get(ID_PROP)); String status = (String) props.get(STATUS_PROP); Status statusEnum; if (StringUtils.isBlank(status)) { statusEnum = Status.UNKNOWN; } else { statusEnum = Status.valueOf(status); } info.setStatus(statusEnum); String start = (String) props.get(START_PROP); info.setStart(new Date(Long.parseLong(start))); String finish = (String) props.get(FINISH_PROP); if (StringUtils.isNotBlank(finish)) { info.setFinish(new Date(Long.parseLong(finish))); } String error = (String) props.get(ERROR_PROP); if (StringUtils.isNotBlank(error)) { info.setError(error); } String startParam = (String) props.get(START_DATE_PARAM_PROP); String endParam = (String) props.get(END_DATE_PARAM_PROP); String zipParam = (String) props.get(XML_FILE_NAME_PARAM_PROP); Parameters params = new Parameters(startParam, endParam, zipParam); info.setParameters(params); return info; }
From source file:com.zotoh.maedr.etc.CmdApps.java
/** * @param appdir/*ww w .ja v a2 s . c om*/ * @param props * @throws Exception */ protected void create3(File appdir, Properties props) throws Exception { String cname = props.getProperty("delegate"); String pk = props.getProperty("package"); String lang = props.getProperty("lang"); boolean wdb = (Boolean) props.get("storage"); File out, f = new File(appdir, SRC + "/" + lang); File cfg = new File(appdir, CFG); File test = new File(appdir, TESTSRC + "/" + lang + "/test"); test.mkdirs(); f.mkdirs(); f = new File(f, strstr(pk, ".", "/")); f.mkdirs(); out = new File(f, cname + "." + lang); // deal with delegate file String s = rc2Str("com/zotoh/maedr/util/Delegate." + lang + ".tpl", "utf-8"); s = strstr(s, "${PACKAGE_ID}", pk); s = strstr(s, "${CLASS_NAME}", cname); // for scala ? s = strstr(s, "${STATEFUL_FLAG}", wdb ? "true" : "false"); s = strstr(s, "${PROC_CLASS_NAME}", props.getProperty("processor")); writeFile(out, s, "utf-8"); // deal with processor file cname = props.getProperty("processor"); out = new File(f, cname + "." + lang); s = rc2Str("com/zotoh/maedr/util/" + (wdb ? "StateP" : "NStateP") + "." + lang + ".tpl", "utf-8"); s = strstr(s, "${PACKAGE_ID}", pk); s = strstr(s, "${CLASS_NAME}", cname); // s=strstr(s, "${TASK_NAME}", props.getProperty("task")); writeFile(out, s, "utf-8"); // add a mock runner for local debugging purpose s = rc2Str("com/zotoh/maedr/util/MockRunner" + "." + lang + ".tpl", "utf-8"); s = strstr(s, "${PACKAGE_ID}", pk); s = strstr(s, "${APP.DIR}", niceFPath(appdir)); s = strstr(s, "${LOG4J.REF}", toFileUrl(new File(cfg, "log4j.properties"))); s = strstr(s, "${MANIFEST.FILE}", niceFPath(new File(cfg, APPPROPS))); out = new File(f, "MockRunner." + lang); writeFile(out, s, "utf-8"); // add a junit test class s = rc2Str("com/zotoh/maedr/util/TestSuite" + "." + lang + ".tpl", "utf-8"); out = new File(test, "TestSuite." + lang); writeFile(out, s, "utf-8"); }
From source file:com.zotoh.maedr.etc.CmdCloud.java
private void launchImage(Cloudr r) throws Exception { CloudData data = CloudData.getInstance(); CloudAPI api = data.getAPI();//from w ww . j a v a 2 s. co m Tuple ts = new Tuple(api.listProducts(32), api.listProducts(64), api.listProducts(0)); CmdLineSequence s = launchInput(ts); Properties props = new Properties(); s.start(props); if (s.isCanceled()) { return; } String[] groups = nsb(props.get("group")).split("(,|;)"); String image = props.getProperty("image"); String ptype = props.getProperty("product"); String key = props.getProperty("key"); String region = props.getProperty("region"); String zone = props.getProperty("zone"); if (!isEmpty(zone)) { data.setDefaultZone(zone); data.save(); } r.launchImage(image, ptype, key, groups, region, zone); }
From source file:com.grantingersoll.intell.clustering.KMeansClusteringEngine.java
private ClusterJob readJobDetails(File jobFile) { log.info("Reading job from: {} ", jobFile); ClusterJob result = null;//from w w w. j a va 2s .c o m try { FileReader fReader = new FileReader(jobFile); Properties props = new Properties(); props.load(fReader); result = new ClusterJob(Integer.parseInt(props.get("k").toString()), props.get("jobDir").toString(), new Path(props.get("input").toString()), new Path(props.get("clustersIn").toString()), new Path(props.get("output").toString()), new Path(props.get("dictionary").toString())); } catch (FileNotFoundException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to load: " + jobFile, e); } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to read: " + jobFile, e); } log.info("Read job: {}", result); return result; }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.idea.ApiIdeaInterface.java
public StringApiResponse updateIdea(JAXBIdea jaxbIdea, Properties properties) throws ApiException, Throwable { StringApiResponse response = new StringApiResponse(); try {//from w w w . j a v a2s . c o m String langCode = (String) properties.get(SystemConstants.API_LANG_CODE_PARAMETER); String instanceCode = jaxbIdea.getInstanceCode(); String id = jaxbIdea.getId(); IIdea clone = this.getIdeaManager().getIdea(id); if (null == clone) { _logger.warn("idea {} not found", id); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Idea with code '" + id + "' does not exist", Response.Status.CONFLICT); } IdeaInstance instance = this.getIdeaInstanceManager().getIdeaInstance(instanceCode); if (null == instance) { _logger.warn("instance {} not found", instanceCode); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + instanceCode + "' does not exist", Response.Status.CONFLICT); } if (StringUtils.isBlank(jaxbIdea.getTitle())) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Title is required", Response.Status.CONFLICT); } if (StringUtils.isBlank(jaxbIdea.getDescr())) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Description is required", Response.Status.CONFLICT); } if (null == jaxbIdea.getTags() || jaxbIdea.getTags().isEmpty()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Al least one tag is required", Response.Status.CONFLICT); } int status = jaxbIdea.getStatus(); if (!ArrayUtils.contains(IIdea.STATES, status)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid status specified: " + status, Response.Status.CONFLICT); } Set<String> tags = this.joinCategories(jaxbIdea, langCode); Idea idea = jaxbIdea.getIdea(); idea.setTags(new ArrayList<String>(tags)); this.getIdeaManager().updateIdea(idea); response.setResult(IResponseBuilder.SUCCESS, null); } catch (ApiException ae) { response.addErrors(ae.getErrors()); response.setResult(IResponseBuilder.FAILURE, null); } catch (Throwable t) { _logger.error("Error on update idea", t); throw new ApsSystemException("Error on update idea", t); } return response; }