Initial import (partially)

This commit is contained in:
2013-11-23 15:49:50 +01:00
parent 50d9edfb75
commit f5ee928477
183 changed files with 69850 additions and 0 deletions

72
org.migor.core/pom.xml Normal file
View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.migor.server</groupId>
<artifactId>org.migor.server</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>org.migor.core</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.migor.server</groupId>
<artifactId>org.migor.shared</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,date,yyyyMMddHHmmss}</format>
<items>
<item>timestamp</item>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</items>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,26 @@
package org.migor.core;
import org.migor.shared.StatusCode;
/**
* @author Daniel Scheidle
* @since 11/4/13 11:03 PM
*/
public class MigorException extends Exception {
private StatusCode status = StatusCode.ERROR;
public MigorException(String message, Throwable cause, StatusCode status) {
super(message, cause);
this.status = status;
}
public MigorException(String message, StatusCode status) {
super(message);
this.status = status;
}
public StatusCode getStatus() {
return status;
}
}

View File

@@ -0,0 +1,30 @@
package org.migor.core.bootstrap;
import org.apache.log4j.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
/**
* @author Daniel Scheidle
* @since 11/4/13 11:22 PM
*/
@SuppressWarnings("UnusedDeclaration")
@Startup
@Singleton
public class StartUp {
private static final Logger logger = Logger.getLogger(StartUp.class);
@PostConstruct
public void postConstruct() {
logger.info("Started");
}
@PreDestroy
public void preDestroy() {
logger.info("Destroyed");
}
}

View File

@@ -0,0 +1,57 @@
package org.migor.core.utils;
import org.jetbrains.annotations.NotNull;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* 05.07.13 15:09
*
* @author Daniel Scheidle
* daniel.scheidle@ucs.at
* Unique Computing Solutions GmbH
*/
public class BeanUtils {
public static final String JNDI_BEAN_MANAGER = "java:comp/BeanManager";
/**
* This method does NOT work on interfaces.
*
* @param instanceClass the bean class.
* @param <T> generic type of the bean.
* @return injected bean.
* @throws javax.naming.NamingException if lookup for the BeanManager fails
*/
@SuppressWarnings( "unchecked" )
public static <T> T get(@NotNull final Class<T> instanceClass) throws NamingException {
BeanManager beanManager = getBeanManager();
AnnotatedType<Object> annotatedType = (AnnotatedType<Object>) beanManager.createAnnotatedType(instanceClass);
InjectionTarget<Object> injectionTarget = beanManager.createInjectionTarget(annotatedType);
CreationalContext<Object> context = beanManager.createCreationalContext(null);
Object instance = injectionTarget.produce(context);
injectionTarget.inject(instance, context);
injectionTarget.postConstruct( instance );
return (T) instance;
}
/**
*
* @return BeanManager
* @throws javax.naming.NamingException
*/
@NotNull
public static BeanManager getBeanManager() throws NamingException {
return InitialContext.doLookup(JNDI_BEAN_MANAGER);
}
}

View File

@@ -0,0 +1,122 @@
package org.migor.core.utils;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* The type Zip utils.
* @author Daniel Scheidle
* daniel.scheidle@ucs.at
* Unique Computing Solutions GmbH
*/
public class ZipUtils {
private ZipUtils() {
// utils class --> no constructor needed
}
/**
* Compress byte [ ].
*
* @param bytes the bytes
* @return the byte [ ]
* @throws Exception the exception
*/
public static byte[] compress(@NotNull final byte[] bytes) throws Exception {
ByteArrayInputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try {
inputStream = new ByteArrayInputStream(bytes);
outputStream = new ByteArrayOutputStream();
compress(inputStream, outputStream);
return outputStream.toByteArray();
}
catch(Exception e) {
throw new Exception(e.getMessage(), e);
} finally {
if (outputStream != null) outputStream.close();
if (inputStream != null) inputStream.close();
}
}
/**
* Decompress byte [ ].
*
* @param bytes the bytes
* @return the byte [ ]
* @throws Exception the exception
*/
public static byte[] decompress(@NotNull final byte[] bytes) throws Exception {
ByteArrayInputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try {
inputStream = new ByteArrayInputStream(bytes);
outputStream = new ByteArrayOutputStream();
decompress(inputStream, outputStream);
return outputStream.toByteArray();
}
catch(Exception e) {
throw new Exception(e.getMessage(), e);
} finally {
if (outputStream != null) outputStream.close();
if (inputStream != null) inputStream.close();
}
}
/**
* Compress void.
*
* @param inputStream the input stream
* @param outputStream the output stream
* @throws java.io.IOException the iO exception
*/
public static void compress(@NotNull final InputStream inputStream,
@NotNull final OutputStream outputStream) throws IOException {
GZIPOutputStream gzipOutputStream = null;
try {
gzipOutputStream = new GZIPOutputStream(outputStream);
int count;
byte[] buffer = new byte[1024];
while ((count = inputStream.read(buffer)) > 0) {
gzipOutputStream.write(buffer, 0, count);
}
} finally {
if (gzipOutputStream != null) gzipOutputStream.close();
}
}
/**
* Decompress void.
*
* @param inputStream the input stream
* @param outputStream the output stream
* @throws java.io.IOException the iO exception
*/
public static void decompress(@NotNull final InputStream inputStream,
@NotNull final OutputStream outputStream) throws IOException {
GZIPInputStream gzipInputStream = null;
try {
gzipInputStream = new GZIPInputStream(inputStream);
int count;
byte[] buffer = new byte[1024];
while ((count = gzipInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, count);
}
} finally {
if (gzipInputStream != null) gzipInputStream.close();
}
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file can be an empty text file (0 bytes) -->
<!-- We're declaring the schema to save you time if you do have to configure
this in the future -->
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
</interceptors>
</beans>