Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:org.apache.gobblin.service.FlowConfigResourceLocalHandler.java

/**
 * Get flow config/*w  w  w .j a v a  2 s  .co  m*/
 */
public FlowConfig getFlowConfig(FlowId flowId) throws FlowConfigLoggedException {
    log.info("[GAAS-REST] Get called with flowGroup {} flowName {}", flowId.getFlowGroup(),
            flowId.getFlowName());

    try {
        URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null);
        URI flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(),
                "/" + flowId.getFlowGroup() + "/" + flowId.getFlowName(), null, null);
        FlowSpec spec = (FlowSpec) flowCatalog.getSpec(flowUri);
        FlowConfig flowConfig = new FlowConfig();
        Properties flowProps = spec.getConfigAsProperties();
        Schedule schedule = null;

        if (flowProps.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) {
            schedule = new Schedule();
            schedule.setCronSchedule(flowProps.getProperty(ConfigurationKeys.JOB_SCHEDULE_KEY));
        }
        if (flowProps.containsKey(ConfigurationKeys.JOB_TEMPLATE_PATH)) {
            flowConfig.setTemplateUris(flowProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH));
        } else if (spec.getTemplateURIs().isPresent()) {
            flowConfig.setTemplateUris(StringUtils.join(spec.getTemplateURIs().get(), ","));
        } else {
            flowConfig.setTemplateUris("NA");
        }
        if (schedule != null) {
            if (flowProps.containsKey(ConfigurationKeys.FLOW_RUN_IMMEDIATELY)) {
                schedule.setRunImmediately(
                        Boolean.valueOf(flowProps.getProperty(ConfigurationKeys.FLOW_RUN_IMMEDIATELY)));
            }

            flowConfig.setSchedule(schedule);
        }

        // remove keys that were injected as part of flowSpec creation
        flowProps.remove(ConfigurationKeys.JOB_SCHEDULE_KEY);
        flowProps.remove(ConfigurationKeys.JOB_TEMPLATE_PATH);

        StringMap flowPropsAsStringMap = new StringMap();
        flowPropsAsStringMap.putAll(Maps.fromProperties(flowProps));

        return flowConfig
                .setId(new FlowId().setFlowGroup(flowId.getFlowGroup()).setFlowName(flowId.getFlowName()))
                .setProperties(flowPropsAsStringMap);
    } catch (URISyntaxException e) {
        throw new FlowConfigLoggedException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowId.getFlowName(), e);
    } catch (SpecNotFoundException e) {
        throw new FlowConfigLoggedException(HttpStatus.S_404_NOT_FOUND,
                "Flow requested does not exist: " + flowId.getFlowName(), null);
    }
}

From source file:org.deegree.console.metadata.ResourceProviderMetadata.java

private ResourceProviderMetadata(ResourceProvider<?> rp) {
    String className = rp.getClass().getName();
    name = rp.getClass().getSimpleName();
    URL url = rp.getClass().getResource("/META-INF/console/resourceprovider/" + className);
    if (url != null) {
        LOG.debug("Loading resource provider metadata from '" + url + "'");
        Properties props = new Properties();
        InputStream is = null;/*w  ww .  jav a2 s.c om*/
        try {
            is = url.openStream();
            props.load(is);
            if (props.containsKey("name")) {
                name = props.getProperty("name").trim();
            }
            if (props.containsKey("wizard")) {
                wizardView = props.getProperty("wizard").trim();
            }
            int i = 1;
            while (true) {
                final String examplePrefix = "example" + i++ + "_";
                String exampleLocation = props.getProperty(examplePrefix + "location");
                if (exampleLocation == null) {
                    break;
                }
                exampleLocation = exampleLocation.trim();
                final URL exampleUrl = this.getClass().getResource(exampleLocation);
                if (exampleUrl == null) {
                    LOG.error("Configuration example file '" + exampleLocation + "' is missing on classpath.");
                    continue;
                }
                final String exampleName = getExampleDisplayName(props, examplePrefix, exampleLocation);
                String exampleDescription = null;
                if (props.containsKey(examplePrefix + "description")) {
                    exampleDescription = props.getProperty(examplePrefix + "description").trim();
                }
                ConfigExample example = new ConfigExample(exampleUrl, exampleName, exampleDescription);
                exampleNameToExample.put(exampleName, example);
            }
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            closeQuietly(is);
        }
    }
}

From source file:com.floreantpos.license.FiveStarPOSLicenseManager.java

private final License loadLicense(File licenseFile) throws LicenseException {

    Properties properties = loadProperties(licenseFile);
    if (!properties.containsKey(License.SIGNATURE)) {
        throw new LicenseException("Invalid license key! Please contact our support.");
    }//from w w w .ja v a 2s  .  c om

    String signature = (String) properties.remove(License.SIGNATURE);
    String encoded = properties.toString();

    PublicKey publicKey = readPublicKey(String.format("/license/%s", PUBLIC_KEY_FILE));

    if (!verify(encoded.getBytes(), signature, publicKey)) {
        throw new LicenseException("Invalid license key! Please contact our support.");
    }

    License license = new License(properties);
    if (license.isExpired()) {
        throw new LicenseException("License key expired! Please contact our support.");
    }
    return license;
}

From source file:org.alfresco.grid.WebDriverFactory.java

/**
 * Creates new instance of {@link SafariDriver}.
 * @return {@link WebDriver} instance of {@link SafariDriver}
 *///  w w  w. ja  va 2  s .c o m
private WebDriver getSafariDriver() {
    if (safariServerPath == null || safariServerPath.isEmpty()) {
        throw new RuntimeException("Failed to create SafariDriver, require a valid safariPath");
    }
    Properties props = System.getProperties();
    if (!props.containsKey(SAFARI_SERVER_DRIVER_PATH)) {
        props.put(SAFARI_SERVER_DRIVER_PATH, safariServerPath);
    }
    return new SafariDriver();
}

From source file:org.apache.stratos.cloud.controller.iaases.cloudstack.CloudStackPartitionValidator.java

@Override
public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException {
    try {/*w w  w  .  j  av a2 s  .c  o  m*/
        IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);
        Iaas updatedIaas = updatedIaasProvider.buildIaas();
        updatedIaas.setIaasProvider(updatedIaasProvider);
        if (properties.containsKey(Scope.ZONE.toString())) {
            String zone = properties.getProperty(Scope.ZONE.toString());
            iaas.isValidZone(null, zone);
            updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone);
            updatedIaas = updatedIaasProvider.buildIaas();
            updatedIaas.setIaasProvider(updatedIaasProvider);
        }
    } catch (Exception e) {
        String msg = String.format("Invalid partition detected: [partition-id] %s", partition.getId());
        log.error(msg, e);
        throw new InvalidPartitionException(msg, e);
    }
    return iaasProvider;
}

From source file:org.alfresco.grid.WebDriverFactory.java

/**
 * Creates new instance of {@link InternetExplorerDriver}.
 * @return {@link WebDriver} instance of {@link InternetExplorerDriver}
 *//*from  w w w.ja v  a  2  s .  c o m*/
private WebDriver getInternetExplorerDriver() {
    if (chromeServerPath == null || chromeServerPath.isEmpty()) {
        throw new RuntimeException("Failed to create InternetExplorerDriver, require a valid ieServerPath");
    }
    Properties props = System.getProperties();
    if (!props.containsKey(IE_SERVER_DRIVER_PATH)) {
        props.put(IE_SERVER_DRIVER_PATH, ieServerPath);
    }
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    return new InternetExplorerDriver(capabilities);
}

From source file:gobblin.metrics.event.sla.SlaEventSubmitter.java

/**
 * Construct an {@link SlaEventSubmitter} by extracting Sla event metadata from the properties. See
 * {@link SlaEventKeys} for keys to set in properties
 * <p>//from  w w w .ja v  a2s .  c o m
 * The <code>props</code> MUST have required property {@link SlaEventKeys#DATASET_URN_KEY} set.<br>
 * All properties with prefix {@link SlaEventKeys#EVENT_ADDITIONAL_METADATA_PREFIX} will be automatically added as
 * event metadata
 * </p>
 * <p>
 * Use {@link SlaEventSubmitter#builder()} to build an {@link SlaEventSubmitter} directly with event metadata.
 * </p>
 *
 * @param submitter used to submit the event
 * @param name of the event
 * @param props reference that contains event metadata
 */
public SlaEventSubmitter(EventSubmitter submitter, String name, Properties props) {

    this.eventName = name;
    this.eventSubmitter = submitter;
    this.datasetUrn = props.getProperty(SlaEventKeys.DATASET_URN_KEY);
    if (props.containsKey(SlaEventKeys.DATASET_URN_KEY)) {
        this.datasetUrn = props.getProperty(SlaEventKeys.DATASET_URN_KEY);
    } else {
        this.datasetUrn = props.getProperty(ConfigurationKeys.DATASET_URN_KEY);
    }
    this.partition = props.getProperty(SlaEventKeys.PARTITION_KEY);
    this.originTimestamp = props.getProperty(SlaEventKeys.ORIGIN_TS_IN_MILLI_SECS_KEY);
    this.upstreamTimestamp = props.getProperty(SlaEventKeys.UPSTREAM_TS_IN_MILLI_SECS_KEY);
    this.completenessPercentage = props.getProperty(SlaEventKeys.COMPLETENESS_PERCENTAGE_KEY);
    this.recordCount = props.getProperty(SlaEventKeys.RECORD_COUNT_KEY);
    this.previousPublishTimestamp = props.getProperty(SlaEventKeys.PREVIOUS_PUBLISH_TS_IN_MILLI_SECS_KEY);
    this.dedupeStatus = props.getProperty(SlaEventKeys.DEDUPE_STATUS_KEY);
    this.isFirstPublish = props.getProperty(SlaEventKeys.IS_FIRST_PUBLISH);

    this.additionalMetadata = Maps.newHashMap();
    for (Entry<Object, Object> entry : props.entrySet()) {
        if (StringUtils.startsWith(entry.getKey().toString(), SlaEventKeys.EVENT_ADDITIONAL_METADATA_PREFIX)) {
            this.additionalMetadata.put(StringUtils.removeStart(entry.getKey().toString(),
                    SlaEventKeys.EVENT_ADDITIONAL_METADATA_PREFIX), entry.getValue().toString());
        }
    }
}

From source file:org.alfresco.grid.WebDriverFactory.java

/**
 * Creates new instance of {@link ChromeDriver}.
 * @return {@link WebDriver} instance of {@link ChromeDriver}
 *//*from   ww  w  .  ja  va 2 s  .  c o  m*/
private WebDriver getChromeDriver() {
    if (chromeServerPath == null || chromeServerPath.isEmpty()) {
        throw new RuntimeException("Failed to create ChromeDriver, require a valid chromeServerPath");
    }
    Properties props = System.getProperties();
    if (!props.containsKey(CHROME_SERVER_DRIVER_PATH)) {
        props.put(CHROME_SERVER_DRIVER_PATH, chromeServerPath);
    }
    ChromeOptions options = new ChromeOptions();
    //Chrome Option to add full Screen Mode.
    options.addArguments("--kiosk");
    return new ChromeDriver(options);
}

From source file:nl.nn.adapterframework.jdbc.dbms.DbmsSupportFactory.java

public IDbmsSupport getDbmsSupport(Connection conn) {
    String product;// w ww  . j  a va2 s .  c o  m
    try {
        DatabaseMetaData md = conn.getMetaData();
        product = md.getDatabaseProductName();
    } catch (SQLException e1) {
        throw new RuntimeException("cannot obtain product from connection metadata", e1);
    }
    Properties supportMap = getDbmsSupportMap();
    if (supportMap != null) {
        if (StringUtils.isEmpty(product)) {
            log.warn("no product found from connection metadata");
        } else {
            if (!supportMap.containsKey(product)) {
                log.warn("product [" + product + "] not configured in dbmsSupportMap");
            } else {
                String dbmsSupportClass = supportMap.getProperty(product);
                if (StringUtils.isEmpty(dbmsSupportClass)) {
                    log.warn("product [" + product + "] configured empty in dbmsSupportMap");
                } else {
                    try {
                        if (log.isDebugEnabled())
                            log.debug("creating dbmsSupportClass [" + dbmsSupportClass + "] for product ["
                                    + product + "]");
                        return (IDbmsSupport) ClassUtils.newInstance(dbmsSupportClass);
                    } catch (Exception e) {
                        throw new RuntimeException("Cannot create dbmsSupportClass [" + dbmsSupportClass
                                + "] for product [" + product + "]", e);
                    }
                }
            }
        }
    } else {
        log.warn("no dbmsSupportMap specified, reverting to built in types");
        if (PRODUCT_NAME_ORACLE_.equals(product)) {
            log.debug("Setting databasetype to ORACLE");
            return new OracleDbmsSupport();
        }
        if (PRODUCT_NAME_MSSQLSERVER.equals(product)) {
            log.debug("Setting databasetype to MSSQLSERVER");
            return new MsSqlServerDbmsSupport();
        }
    }
    log.debug("Setting databasetype to GENERIC, productName [" + product + "]");
    return new GenericDbmsSupport();
}

From source file:com.adaptris.core.services.metadata.WriteMetadataToFilesystemTest.java

public void testService_Default() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = createMessage();
    WriteMetadataToFilesystem service = createService(subDir);
    File parentDir = FsHelper/*from www.  j  a  v  a2  s  . c o  m*/
            .createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true));
    String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId();
    execute(service, msg);
    Properties p = readProperties(new File(propsFilename), false);
    assertTrue(p.containsKey("key5"));
    assertEquals("v5", p.getProperty("key5"));
}