appslandia-common-cp

AppsLandia Common - Java Utilities

License

License

GroupId

GroupId

com.appslandia
ArtifactId

ArtifactId

appslandia-common-cp
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

appslandia-common-cp
AppsLandia Common - Java Utilities
Project URL

Project URL

https://github.com/haducloc/appslandia-common
Source Code Management

Source Code Management

https://github.com/haducloc/appslandia-common.git

Download appslandia-common-cp

How to add to project

<!-- https://jarcasting.com/artifacts/com.appslandia/appslandia-common-cp/ -->
<dependency>
    <groupId>com.appslandia</groupId>
    <artifactId>appslandia-common-cp</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.appslandia/appslandia-common-cp/
implementation 'com.appslandia:appslandia-common-cp:1.0'
// https://jarcasting.com/artifacts/com.appslandia/appslandia-common-cp/
implementation ("com.appslandia:appslandia-common-cp:1.0")
'com.appslandia:appslandia-common-cp:jar:1.0'
<dependency org="com.appslandia" name="appslandia-common-cp" rev="1.0">
  <artifact name="appslandia-common-cp" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.appslandia', module='appslandia-common-cp', version='1.0')
)
libraryDependencies += "com.appslandia" % "appslandia-common-cp" % "1.0"
[com.appslandia/appslandia-common-cp "1.0"]

Dependencies

provided (1)

Group / Artifact Type Version
com.google.code.gson : gson jar 2.8.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Java Utilities

Features

  • Cryptography utilities
  • JDBC utilities (Named parameters, Array parameters, LIKE_ANY operator, etc.)
  • EasyRecord framework
  • DI framework
  • Type formatters/parsers with localization
  • Java bean validators
  • GSON adapters
  • JSON Web Token
  • Geography utilities
  • ToStringBuilder
  • 400+ Unit tests

Installation

Maven

<dependency>
    <groupId>com.appslandia</groupId>
    <artifactId>appslandia-common</artifactId>
    <version>{LATEST_VERSION}</version>
</dependency>

Gradle

dependencies {
   compile 'com.appslandia:appslandia-common:{LATEST_VERSION}'
}

Sample Usage

JDBC Array

Sql cmd = new Sql("SELECT * FROM User WHERE status=:status AND userType IN :types");

try (StatementImpl stat = new StatementImpl(connection, cmd)) {
  stat.setInt("status", 1); // Named parameter
  stat.setIntArray("types", new int[] {1,2,3}); // Named array parameter
  //
  stat.executeQuery();
}

JDBC LIKE_ANY

Sql cmd = new Sql("SELECT * FROM User WHERE name LIKE_ANY :names");

try (StatementImpl stat = new StatementImpl(connection, cmd)) {
  stat.setLikeAny("names", new String[] {"a, "b"}); // name LIKE '%a%' OR name LIKE '%b%'
  //
  stat.executeQuery();
}

System.getProperty & getenv

 String password = SYS.resolveExpr("${db.password, env.DB_PASSWORD:default_password}")
 // resolving order:  System.getProperty("db.password"),  System.getenv("DB_PASSWORD"), default_password

Geography

 GeoLocation loc = new GeoLocation(lat, long);
 GeoLocation loc_east = loc.move(Direction.EAST, 10, DistanceUnit.MILE);
 //
 double distanceInMiles = loc.distanceTo(loc_east, DistanceUnit.MILE); // ~10 miles

JWT

  // JwtProcessor
  JwtProcessor processor = new JwtProcessor().setIssuer("Issuer1");

  GsonBuilder gsonBuilder = GsonProcessor.newBuilder()
				.registerTypeAdapter(JwtHeader.class, new GsonMapDeserializer<>((m) -> new JwtHeader(m)))
				.registerTypeAdapter(JwtPayload.class, new GsonMapDeserializer<>((m) -> new JwtPayload(m)));

  // GsonProcessor or your JsonProcessor
  processor.setJsonProcessor(new GsonProcessor().setBuilder(gsonBuilder));
  
  processor.setJwtSigner(new JwtSigner().setAlg("HS256")
  				.setSigner(new MacDigester().setAlgorithm("HmacSHA256").setSecret("secret")));

  JwtHeader header = processor.newHeader();
  JwtPayload payload = processor.newPayload().setExpiresIn(1, TimeUnit.DAYS);

  // Serialize
  String jwt = processor.toJwt(new JwtToken(header, payload));
  
  // Deserialize
  JwtToken token = processor.parseJwt(jwt);
  token.getHeader(); token.getPayload();

Questions?

Please feel free to contact me if you have any questions or comments. Email: [email protected]

License

This code is distributed under the terms and conditions of the MIT license.

Versions

Version
1.0