Skip to content

Commit

Permalink
US-31: Clevcore-Engine migration to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarinelli committed May 10, 2015
1 parent 9a77f6f commit 3ef9348
Show file tree
Hide file tree
Showing 13 changed files with 1,152 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
/.classpath
/.project
/.settings/
98 changes: 98 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ar.com.clevcore</groupId>
<artifactId>clevcore-java</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>Clevcore Java</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<itextpdf.version>5.0.6</itextpdf.version>
<java.version>1.8</java.version>
<junit.version>4.11</junit.version>
<poi.version>3.11-beta2</poi.version>
</properties>

<dependencies>
<!-- POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>

<!-- ITextPdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itextpdf.version}</version>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>clevcore-java</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalBuildcommands>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>org.eclipse.m2e.core.maven2Nature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
</plugins>
</build>
</project>
76 changes: 76 additions & 0 deletions src/main/java/ar/com/clevcore/exceptions/ClevcoreException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ar.com.clevcore.exceptions;

public class ClevcoreException extends Exception {
private static final long serialVersionUID = 1L;

public static enum Severity {
ERROR, FATAL
}

private Severity severity;
private String message;

private int errorCode;
private Throwable cause;
private Object object;

public ClevcoreException() {
}

public ClevcoreException(Severity severity, String message) {
super();
this.severity = severity;
this.message = message;
}

public ClevcoreException(Severity severity, String message, int errorCode, Throwable cause, Object object) {
super();
this.severity = severity;
this.message = message;
this.errorCode = errorCode;
this.cause = cause;
this.object = object;
}

// GETTER & SETTER
public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public Severity getSeverity() {
return severity;
}

public void setSeverity(Severity severity) {
this.severity = severity;
}

public int getErrorCode() {
return errorCode;
}

public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}

public Throwable getCause() {
return cause;
}

public void setCause(Throwable cause) {
this.cause = cause;
}

public Object getObject() {
return object;
}

public void setObject(Object object) {
this.object = object;
}

}
132 changes: 132 additions & 0 deletions src/main/java/ar/com/clevcore/utils/DateUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package ar.com.clevcore.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public final class DateUtils {

private DateUtils() {
throw new AssertionError();
}

public static Date getDate(String value, String pattern) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.parse(value);
}

public static Date getDateNotTolerant(String value, String pattern) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.setLenient(false);
return sdf.parse(value);
}

public static Calendar getCalendar() {
return new GregorianCalendar();
}

public static Calendar getCalendarNotTolerant() {
Calendar calendar = new GregorianCalendar();
calendar.setLenient(false);
return calendar;
}

public static Date addYear(Date date, int year) {
Calendar calendar = getCalendar();
calendar.setTimeInMillis(date.getTime());
calendar.add(Calendar.YEAR, year);
return new Date(calendar.getTimeInMillis());
}

public static Date addMonth(Date date, int month) {
Calendar calendar = getCalendar();
calendar.setTimeInMillis(date.getTime());
calendar.add(Calendar.MONTH, month - 1);
return new Date(calendar.getTimeInMillis());
}

public static Date addDay(Date date, int day) {
Calendar calendar = getCalendar();
calendar.setTimeInMillis(date.getTime());
calendar.add(Calendar.DAY_OF_MONTH, day);
return new Date(calendar.getTimeInMillis());
}

public static Date getDate(int year, int month, int day) throws Exception {
Calendar calendar = getCalendarNotTolerant();
calendar.set(year, month - 1, day, 0, 0, 0);
return new Date(calendar.getTimeInMillis());
}

public static Calendar getCalendar(int year, int month, int day) throws Exception {
Calendar calendar = getCalendarNotTolerant();
calendar.set(year, month - 1, day, 0, 0, 0);
return calendar;
}

public static int getYear(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
return Integer.parseInt(sdf.format(date));
}

public static int getYear(Calendar calendar) {
return calendar.get(Calendar.YEAR);
}

public static Calendar setYear(Calendar calendar, int value) {
calendar.set(Calendar.YEAR, value);
return calendar;
}

public static int getMonth(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("MM");
return Integer.parseInt(sdf.format(date));
}

public static int getMonth(Calendar calendar) {
return calendar.get(Calendar.MONTH) + 1;
}

public static Calendar setMonth(Calendar calendar, int value) {
calendar.set(Calendar.MONTH, value - 1);
return calendar;
}

public static int getDay(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("dd");
return Integer.parseInt(sdf.format(date));
}

public static int getDay(Calendar calendar) {
return calendar.get(Calendar.DAY_OF_MONTH);
}

public static Calendar setDay(Calendar calendar, int value) {
calendar.set(Calendar.DAY_OF_MONTH, value);
return calendar;
}

public static int getActualMaximumDay(Calendar calendar) {
return calendar.getActualMaximum(Calendar.DATE);
}

public static Long getAge(Date date) {
Date sysdate = new Date();
return (long) Math.floor((sysdate.getTime() - date.getTime()) / 31557600000L);
}

public static String getDateFormat(Date date, String pattern) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}

public static String getDateFormat(Date date, String pattern, TimeZone timeZone) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.setTimeZone(timeZone);
return sdf.format(date);
}

}
23 changes: 23 additions & 0 deletions src/main/java/ar/com/clevcore/utils/ExceptionUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ar.com.clevcore.utils;

import ar.com.clevcore.exceptions.ClevcoreException;
import ar.com.clevcore.exceptions.ClevcoreException.Severity;

public final class ExceptionUtils {

private ExceptionUtils() {
throw new AssertionError();
}

// TODO: We must create a log, We can use log4j
public static void treateException(Exception e, Object object) throws ClevcoreException {
System.out.println("Message: " + e.getMessage());
System.out.println("Severity: " + Severity.FATAL);
System.out.println("errorCode: " + -1);
System.out.println("Cause: " + e.getCause());
System.out.println("Object: " + object.toString());

throw new ClevcoreException(Severity.FATAL, e.getMessage(), -1, e.getCause(), object);
}

}
29 changes: 29 additions & 0 deletions src/main/java/ar/com/clevcore/utils/FileUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ar.com.clevcore.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

public final class FileUtils {

private FileUtils() {
throw new AssertionError();
}

public static boolean makeDir(String path) throws Exception {
return new File(path).mkdirs();
}

public static void saveFile(String path, String name, byte[] file) throws Exception {
makeDir(path);

OutputStream outputStream = new FileOutputStream(new File(path + File.separator + name));
outputStream.write(file);
outputStream.close();
}

public static boolean deleteFile(String path, String name) throws Exception {
return new File(path + File.separator + name).delete();
}

}
30 changes: 30 additions & 0 deletions src/main/java/ar/com/clevcore/utils/IntegerUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ar.com.clevcore.utils;

public final class IntegerUtils {

private IntegerUtils() {
throw new AssertionError();
}

public static Integer[] createInteger(int begin, int end) {
Integer[] array = null;

if (begin < end) {
array = new Integer[end - begin + 1];
for (int i = 0; i < array.length; i++) {
array[i] = begin + i;
}
} else if (begin > end) {
array = new Integer[begin - end + 1];
for (int i = 0; i < array.length; i++) {
array[i] = begin - i;
}
} else {
array = new Integer[1];
array[0] = begin;
}

return array;
}

}
Loading

0 comments on commit 3ef9348

Please sign in to comment.