Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Changes for release 2.5.0 are merged from develop into master branch
  • Loading branch information
abhaychandel-capgemini committed Jan 10, 2018
2 parents ddb142e + 0b219b9 commit 4043422
Show file tree
Hide file tree
Showing 97 changed files with 4,942 additions and 574 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: java
dist: precise
jdk:
- oraclejdk7
script: mvn install
sudo: false
sudo: false
127 changes: 87 additions & 40 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cxf.version>3.1.8</cxf.version>
<mmm.util.version>7.3.0</mmm.util.version>
<mmm.util.version>7.5.1</mmm.util.version>
<oasp.flatten.mode>bom</oasp.flatten.mode>
</properties>

<dependencyManagement>
<dependencies>
<!-- *** EXTERNAL DEPENDENCIES *** -->
<!-- BOM for localization -->
<!-- Library with general utilities as well as I18N and exception support -->
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-l10n-bom</artifactId>
<version>1.4.0</version>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-bom</artifactId>
<version>${mmm.util.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -59,42 +60,6 @@
<artifactId>guava</artifactId>
<version>17.0</version>
</dependency>
<!-- Library with general utilities as well as I18N and exception support -->
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-core</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-io</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-entity</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-pojo</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-validation</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-search</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-cli</artifactId>
<version>${mmm.util.version}</version>
</dependency>
<!-- Library with advanced collection support -->
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -161,6 +126,11 @@
<version>2.0.1</version>
</dependency>
<!-- CXF for REST and Webservices -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
Expand Down Expand Up @@ -258,6 +228,13 @@
<version>2.2.6</version>
</dependency>

<!-- Optional logging dependency -->
<dependency>
<groupId>org.owasp</groupId>
<artifactId>security-logging-logback</artifactId>
<version>1.1.3</version>
</dependency>

<!-- *** INTERNAL DEPENDENCIES *** -->
<dependency>
<groupId>io.oasp.java.modules</groupId>
Expand Down Expand Up @@ -294,11 +271,81 @@
<artifactId>oasp4j-security</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-json</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-cxf-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-cxf-client-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-cxf-client-ws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-cxf-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-cxf-server-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-cxf-server-ws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-cxf-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-cxf-client-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-cxf-client-ws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-cxf-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-cxf-server-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-cxf-server-ws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-jpa</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package io.oasp.module.basic.common.api.config;

import java.util.Map;
import java.util.Set;

/**
* Simple abstraction interface for generic access to configuration properties (from spring-boot
* {@code application.properties}).
*
* @since 3.0.0
*/
public interface ConfigProperties {

/** The separator charactor '.' for hierarchical keys such as "spring.datasource.url". */
char KEY_SEPARATOR = '.';

/** An immutable instance of {@link ConfigProperties} that is always {@link #isEmpty() empty} */
ConfigProperties EMPTY = new EmptyConfigProperties();

/**
* @return the {@link Set} of the {@link #getChild(String) direct child keys} available in the
* {@link ConfigProperties}-node.
*/
Set<String> getChildKeys();

/**
* @param key the {@link #getChildKeys() child key} of the requested configuration value.
* @return the child {@link ConfigProperties}. Will be an {@link #isEmpty() empty} child if undefined.
*/
ConfigProperties getChild(String key);

/**
* Recursive variant of {@link #getChild(String)} such that
* <code>{@link ConfigProperties config}.{@link #getChild(String...) getChild}(key1, ..., keyN)</code> is the same as
* <code>{@link ConfigProperties config}.{@link #getChild(String) getChild}(key1)...{@link #getChild(String) getChild}(keyN)</code>.
*
* @param keys the keys to traverse recursively.
* @return the descendant {@link #getChild(String) child} reached from recursively traversing the given {@code keys}.
*/
ConfigProperties getChild(String... keys);

/**
* Shortcut for {@link #getChild(String) getChild(key)}.{@link #getValue()}.
*
* @param key the {@link #getChild(String) key of the child}
* @return the value of this {@link ConfigProperties}-node. May be {@code null}.
*/
String getChildValue(String key);

/**
* Shortcut for {@link #getChild(String...) getChild(keys)}.{@link #getValue()}.
*
* @param keys the keys to traverse recursively.
* @return the {@link #getValue() value} of the {@link #getChild(String...) descendant child} traversed by
* {@code keys}. May be {@code null}.
*/
String getChildValue(String... keys);

/**
* @return the value of this {@link ConfigProperties}-node. May be {@code null}.
*/
String getValue();

/**
* @param <T> the requested {@code type}
* @param type the {@link Class} reflecting the requested result type.
* @return the value of this {@link ConfigProperties}-node converted to the given {@code type}. Will be {@code null}
* if undefined.
*/
<T> T getValue(Class<T> type);

/**
* @param <T> the requested {@code type}
* @param type the {@link Class} reflecting the requested result type.
* @param defaultValue the value returned as default if the actual {@link #getValue() value} is undefined.
* @return the value of this {@link ConfigProperties}-node converted to the given {@code type}. Will be
* {@code defaultValue} if undefined.
*/
<T> T getValue(Class<T> type, T defaultValue);

/**
* @return the {@link #getValue(Class, Object)} as {@code boolean} with {@code false} as default.
*/
boolean getValueAsBoolean();

/**
* @return {@code true} if this is an empty {@link ConfigProperties}-node that neither has a {@link #getValue() value}
* nor {@link #getChildKeys() any} {@link #getChild(String) child}.
*/
boolean isEmpty();

/**
* @return this {@link ConfigProperties} converted to a {@link ConfigProperties#toFlatMap() flat} {@link Map}.
*/
Map<String, String> toFlatMap();

/**
* @param rootKey the root key used as prefix for the {@link java.util.Map.Entry#getKey() keys} separated with a dot
* if not {@link String#isEmpty() empty}. Typically the empty {@link String}.
* @return this {@link ConfigProperties} converted to a {@link ConfigProperties#toFlatMap() flat} {@link Map}.
*/
Map<String, String> toFlatMap(String rootKey);

/**
* @return this {@link ConfigProperties} converted to a {@link ConfigProperties#toHierarchicalMap() hierarchical}
* {@link Map}.
*/
Map<String, Object> toHierarchicalMap();

/**
* @param parent the parent {@link ConfigProperties} to extend.
* @return a new instance of {@link ConfigProperties} with all {@link #getChild(String) children} and
* {@link #getValue() value}(s) from this {@link ConfigProperties}-tree and all {@link #getChild(String)
* children} and {@link #getValue() value}(s) inherited from the given {@code parent}
* {@link ConfigProperties}-tree if they are undefined in this tree.
*/
MutableConfigProperties inherit(ConfigProperties parent);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.oasp.module.basic.common.api.config;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Currency;

/**
* Utility that helps to deal with configuration values.
*/
public final class ConfigValueUtil {

private ConfigValueUtil() {
}

/**
* @param <T> the generic {@code type}.
* @param object the {@link Object} to convert. Will not be {@code null}.
* @param type the {@link Class} reflecting the requested type.
* @return the given {@link Object} converted to the given {@code type}.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> T convertValue(Object object, Class<T> type) {

try {
Object result;
if (type.isInstance(object)) {
result = object;
} else if (type.isEnum()) {
result = Enum.valueOf((Class<? extends Enum>) type, object.toString());
} else if (type.isAssignableFrom(String.class)) {
result = object.toString();
} else if ((type == boolean.class) || (type == Boolean.class)) {
result = Boolean.valueOf(object.toString());
} else if ((type == int.class) || (type == Integer.class)) {
result = Integer.valueOf(object.toString());
} else if ((type == long.class) || (type == Long.class)) {
result = Long.valueOf(object.toString());
} else if ((type == double.class) || (type == Double.class)) {
result = Double.valueOf(object.toString());
} else if (type == Class.class) {
result = Class.forName(object.toString());
} else if ((type == float.class) || (type == Float.class)) {
result = Float.valueOf(object.toString());
} else if ((type == short.class) || (type == Short.class)) {
result = Short.valueOf(object.toString());
} else if ((type == byte.class) || (type == Byte.class)) {
result = Byte.valueOf(object.toString());
} else if (type == BigDecimal.class) {
result = new BigDecimal(object.toString());
} else if (type == BigInteger.class) {
result = new BigInteger(object.toString());
} else if (type == Number.class) {
result = Double.parseDouble(object.toString());
} else if ((type == Character.class) || ((type == char.class))) {
String value = object.toString();
if (value.length() == 1) {
result = Character.valueOf(value.charAt(0));
} else {
throw new IllegalArgumentException(value);
}
} else if (type == Currency.class) {
result = Currency.getInstance(object.toString());
} else {
throw new IllegalArgumentException(object.toString());
}
return (T) result;
} catch (NumberFormatException | ClassNotFoundException e) {
throw new IllegalArgumentException(object.toString(), e);
}
}

}
Loading

0 comments on commit 4043422

Please sign in to comment.