updated API description

This commit is contained in:
2019-09-14 17:54:26 +02:00
parent 13d16a1309
commit 6348f81bed
53 changed files with 487 additions and 670 deletions

View File

@ -20,7 +20,7 @@ import de.muehlencord.shared.configuration.converter.BooleanStringConverter;
/** /**
* A Boolean parameter * A Boolean parameter
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class BooleanParameter extends Parameter<Boolean> { public class BooleanParameter extends Parameter<Boolean> {

View File

@ -18,14 +18,16 @@ package de.muehlencord.shared.configuration;
import java.util.Map; import java.util.Map;
/** /**
* Specifies a configurable objects.
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public interface Configuration { public interface Configuration {
/** /**
* adds a new parameter to the configuration * adds a new parameter to the configuration
* *
* @param <T> the type of the parameter to add
* @param p the parameter to add * @param p the parameter to add
* @throws ConfigurationException if the parameter cannot be added * @throws ConfigurationException if the parameter cannot be added
*/ */
@ -34,25 +36,27 @@ public interface Configuration {
/** /**
* sets the value of the given parameter * sets the value of the given parameter
* *
* @param <T> * @param <T> the type of the parameter to add
* @param p * @param p the parameter to add
* @param value * @param value the value the parameter should have
* @throws ConfigurationException if the parameter is not defined * @throws ConfigurationException if the parameter is not defined
*/ */
public <T> void setParameterValue(Parameter<T> p, T value) throws ConfigurationException; public <T> void setParameterValue(Parameter<T> p, T value) throws ConfigurationException;
/** /**
* sets the value of parameter with given name * sets the value of parameter with given name
* *
* @param <T> the type of the parameter to add
* @param parameterName parameter to set * @param parameterName parameter to set
* @param value value to set * @param value value to set
* @throws ConfigurationException if the parameter is not defined * @throws ConfigurationException if the parameter is not defined
*/ */
public <T> void setParameterValue(String parameterName, T value) throws ConfigurationException; public <T> void setParameterValue(String parameterName, T value) throws ConfigurationException;
/** /**
* sets the value of the given parameter * sets the value of the given parameter
* *
* @param <T> the type of the parameter to add
* @param p parameter to set * @param p parameter to set
* @param value value to set * @param value value to set
* @throws ConfigurationException if the parameter is not defined * @throws ConfigurationException if the parameter is not defined
@ -71,22 +75,26 @@ public interface Configuration {
/** /**
* returns the value of the given parameter * returns the value of the given parameter
* *
* @param <T> the type of the parameter to add
* @param p the parameter to return the value for * @param p the parameter to return the value for
* @return the value of the given parameter; null if not set * @return the value of the given parameter; null if not set
* *
* @throws ConfigurationException if the parameter is not defined or if the value is not set * @throws ConfigurationException if the parameter is not defined or if the
* value is not set
*/ */
public <T> T getParameterValue(Parameter<T> p) throws ConfigurationException; public <T> T getParameterValue(Parameter<T> p) throws ConfigurationException;
/** /**
* returns the value of the given parameter * returns the value of the given parameter
* *
* @param <T> the type of the parameter to add
* @param parameterName the name of the parameter to return the value for * @param parameterName the name of the parameter to return the value for
* @return the value of the given parameter; null if not set * @return the value of the given parameter; null if not set
* *
* @throws ConfigurationException if the parameter is not defined or if the value is not set * @throws ConfigurationException if the parameter is not defined or if the
* value is not set
*/ */
public <T> T getParameterValue(String parameterName) throws ConfigurationException; public <T> T getParameterValue(String parameterName) throws ConfigurationException;
/** /**
* validates the configuration * validates the configuration
@ -94,11 +102,12 @@ public interface Configuration {
* @throws ConfigurationException if the configuration is invalid * @throws ConfigurationException if the configuration is invalid
*/ */
public void validateConfiguration() throws ConfigurationException; public void validateConfiguration() throws ConfigurationException;
/** /**
* returns the map of parameters and values * returns the map of parameters and values
* *
* @param <T> the type of the parameter to add
* @return the map of parameters and values * @return the map of parameters and values
*/ */
public <T> Map<Parameter<T>, T> getParameterMap(); public <T> Map<Parameter<T>, T> getParameterMap();
} }

View File

@ -20,7 +20,8 @@ import java.util.Date;
/** /**
* A Date parameter * A Date parameter
* @author joern@muehlencord.de *
* @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class DateParameter extends Parameter<Date> { public class DateParameter extends Parameter<Date> {
@ -47,7 +48,7 @@ public class DateParameter extends Parameter<Date> {
* creates a new parameter object using default string converter * creates a new parameter object using default string converter
* *
* @param name the name of the parameter * @param name the name of the parameter
* @param mandatory detremines if this is a mandatory parameter or not * @param mandatory determines if this is a mandatory parameter or not
*/ */
public DateParameter(String name, boolean mandatory) { public DateParameter(String name, boolean mandatory) {
super(name, new DateStringConverter(), mandatory); super(name, new DateStringConverter(), mandatory);
@ -58,7 +59,7 @@ public class DateParameter extends Parameter<Date> {
* *
* @param name the name of the parameter * @param name the name of the parameter
* @param converter the converter object to convert the value of the parameter to string and vice versa * @param converter the converter object to convert the value of the parameter to string and vice versa
* @param mandatory detremines if this is a mandatory parameter or not * @param mandatory determines if this is a mandatory parameter or not
*/ */
public DateParameter(String name, StringConverter<Date> converter, boolean mandatory) { public DateParameter(String name, StringConverter<Date> converter, boolean mandatory) {
super(name, converter, mandatory); super(name, converter, mandatory);

View File

@ -22,7 +22,7 @@ import java.util.Map;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class DefaultConfiguration implements Configuration { public class DefaultConfiguration implements Configuration {
@ -104,6 +104,7 @@ public class DefaultConfiguration implements Configuration {
/** /**
* overrides parameter map with given map * overrides parameter map with given map
* *
* @param <T> the type of the parameter to add
* @param map map to use * @param map map to use
* @throws ConfigurationException if the parameter is not defined * @throws ConfigurationException if the parameter is not defined
*/ */

View File

@ -20,7 +20,7 @@ import de.muehlencord.shared.configuration.converter.IntegerStringConverter;
/** /**
* A Integer parameter * A Integer parameter
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class IntegerParameter extends Parameter<Integer> { public class IntegerParameter extends Parameter<Integer> {

View File

@ -19,7 +19,8 @@ import de.muehlencord.shared.configuration.converter.StringStringConverter;
/** /**
* A String parameter * A String parameter
* @author joern@muehlencord.de *
* @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class StringParameter extends Parameter<String> { public class StringParameter extends Parameter<String> {
@ -31,22 +32,24 @@ public class StringParameter extends Parameter<String> {
public StringParameter(String name) { public StringParameter(String name) {
super(name, new StringStringConverter(), true); super(name, new StringStringConverter(), true);
} }
/** /**
* creates a new mandatory parameter object using default string converter * creates a new mandatory parameter object using default string converter
* *
* @param name the name of the parameter * @param name the name of the parameter
* @param defaultValue the default value of the parameter to set.
*/ */
public StringParameter(String name, String defaultValue) { public StringParameter(String name, String defaultValue) {
super(name, new StringStringConverter(), true); super(name, new StringStringConverter(), true);
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
} }
/** /**
* creates a new mandatory parameter object * creates a new mandatory parameter object
* *
* @param name the name of the parameter * @param name the name of the parameter
* @param converter the converter object to convert the value of the parameter to string and vice versa * @param converter the converter object to convert the value of the
* parameter to string and vice versa
*/ */
public StringParameter(String name, StringConverter<String> converter) { public StringParameter(String name, StringConverter<String> converter) {
super(name, converter, true); super(name, converter, true);
@ -66,7 +69,8 @@ public class StringParameter extends Parameter<String> {
* creates a new parameter object * creates a new parameter object
* *
* @param name the name of the parameter * @param name the name of the parameter
* @param converter the converter object to convert the value of the parameter to string and vice versa * @param converter the converter object to convert the value of the
* parameter to string and vice versa
* @param mandatory detremines if this is a mandatory parameter or not * @param mandatory detremines if this is a mandatory parameter or not
*/ */
public StringParameter(String name, StringConverter<String> converter, boolean mandatory) { public StringParameter(String name, StringConverter<String> converter, boolean mandatory) {

View File

@ -20,7 +20,7 @@ import java.net.URI;
/** /**
* A URI parameter * A URI parameter
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class URIParameter extends Parameter<URI> { public class URIParameter extends Parameter<URI> {

View File

@ -17,7 +17,7 @@ package de.muehlencord.shared.configuration;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class ValidationException extends Exception { public class ValidationException extends Exception {

View File

@ -18,7 +18,7 @@ package de.muehlencord.shared.configuration;
/** /**
* *
* @param <T> the type of the validator * @param <T> the type of the validator
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public interface Validator<T> { public interface Validator<T> {

View File

@ -21,7 +21,7 @@ import static java.lang.Boolean.parseBoolean;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class BooleanStringConverter implements StringConverter<Boolean> { public class BooleanStringConverter implements StringConverter<Boolean> {

View File

@ -20,7 +20,7 @@ import de.muehlencord.shared.configuration.Validator;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class IntgerRangeValidator implements Validator<Integer> { public class IntgerRangeValidator implements Validator<Integer> {

View File

@ -23,7 +23,7 @@ import java.util.List;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class StringValueListValidator implements Validator<String> { public class StringValueListValidator implements Validator<String> {

View File

@ -34,7 +34,8 @@ import javax.persistence.criteria.Root;
/** /**
* *
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
* @param <T> * @param <T> the entity this controller will serve. All objects returned are of
* this type.
*/ */
public abstract class AbstractController<T extends Serializable> extends CommonAbstractController { public abstract class AbstractController<T extends Serializable> extends CommonAbstractController {
@ -44,16 +45,26 @@ public abstract class AbstractController<T extends Serializable> extends CommonA
this.entityClass = clazz; this.entityClass = clazz;
} }
/** /**
* * general find methods *** * general find method
*
* @param id the primary key of the entity to search for.
* @return the found entity instance or null if the entity does not exist
*/ */
@Lock(LockType.READ) @Lock(LockType.READ)
public T find(Object id) { public T find(Object id) {
return em.find(entityClass, id); return em.find(entityClass, id);
} }
/**
* general find method with the option to initialize lists/sets of 1:n
* relations during the query.
*
* @param id the primary key of the entity to search for.
* @param subGraphItems the name of the subgraph items to initialize.
* Typically this is the name of the 1:n set or list.
* @return the found entity instance or null if the entity does not exist
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public T find(Object id, String... subGraphItems) { public T find(Object id, String... subGraphItems) {
EntityGraph graph = this.em.createEntityGraph(entityClass); EntityGraph graph = this.em.createEntityGraph(entityClass);
@ -68,16 +79,32 @@ public abstract class AbstractController<T extends Serializable> extends CommonA
return entity; return entity;
} }
/**
* returns a list of all entities.
*
* @return a list of all entities.
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public List<T> findAll() { public List<T> findAll() {
return findAll(new ArrayList<>()); return findAll(new ArrayList<>());
} }
/**
* returns a list of all entities.
*
* @param orderFields the list of field names to order the result by.
* @return a list of all entities.
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public List<T> findAll(String... orderFields) { public List<T> findAll(String... orderFields) {
return findAll(Arrays.asList(orderFields)); return findAll(Arrays.asList(orderFields));
} }
/**
*
* @param orderFields the list of field names to order the result by.
* @return a list of all entities.
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public List<T> findAll(List<String> orderFields) { public List<T> findAll(List<String> orderFields) {
final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaBuilder cb = em.getCriteriaBuilder();
@ -92,6 +119,14 @@ public abstract class AbstractController<T extends Serializable> extends CommonA
return query.getResultList(); return query.getResultList();
} }
/**
* searches for entities by specifying a filter map. The map contains a
* field name and field value.
*
* @param filters the filters to apply
* @param orderFields the fields to order the result by.
* @return a list of found entities.
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public List<T> find(Map<String, Object> filters, List<String> orderFields) { public List<T> find(Map<String, Object> filters, List<String> orderFields) {
final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaBuilder cb = em.getCriteriaBuilder();
@ -108,6 +143,5 @@ public abstract class AbstractController<T extends Serializable> extends CommonA
return query.getResultList(); return query.getResultList();
} }
} }

View File

@ -44,20 +44,43 @@ import org.apache.commons.lang3.StringUtils;
*/ */
public abstract class CommonAbstractController { public abstract class CommonAbstractController {
/**
* the entity manager to use
*/
@Inject @Inject
@ApplicationPU @ApplicationPU
protected EntityManager em; protected EntityManager em;
/**
*
* @param <T> the type of the entity to search for
* @param entityClass the entity class to return
* @return a list of all entities found
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public <T> List<T> findAll(Class<T> entityClass) { public <T> List<T> findAll(Class<T> entityClass) {
return findAll(entityClass, new ArrayList<>()); return findAll(entityClass, new ArrayList<>());
} }
/**
*
* @param <T> the type of the entity to search for
* @param entityClass the entity class to return
* @param orderFields the fields to order the result by.
* @return a list of all entities found
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public <T> List<T> findAll(Class<T> entityClass, String... orderFields) { public <T> List<T> findAll(Class<T> entityClass, String... orderFields) {
return findAll(entityClass, Arrays.asList(orderFields)); return findAll(entityClass, Arrays.asList(orderFields));
} }
/**
*
* @param <T> the type of the entity to search for
* @param entityClass the entity class to return
* @param orderFields the fields to order the result by.
* @return a list of all entities found
*/
@Lock(LockType.READ) @Lock(LockType.READ)
public <T> List<T> findAll(Class<T> entityClass, List<String> orderFields) { public <T> List<T> findAll(Class<T> entityClass, List<String> orderFields) {
final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaBuilder cb = em.getCriteriaBuilder();
@ -73,6 +96,17 @@ public abstract class CommonAbstractController {
} }
/* **** standard crud options *** */ /* **** standard crud options *** */
/**
* updates the audit field of the entity class.
*
* @param audit the audit to apply
* @param onCreate specifies, whether the the update should be applied for a
* new entity or not. If yes, then also the createdBy /createdOn fields are
* updated. Otherwise these fields are skipped.
* @param changedBy the username to apply
* @return an updated audit object to use for the updated entity.
* @throws ControllerException
*/
public Audit applyAuditChanges(Audit audit, boolean onCreate, String changedBy) throws ControllerException { public Audit applyAuditChanges(Audit audit, boolean onCreate, String changedBy) throws ControllerException {
if (audit == null) { if (audit == null) {
audit = new Audit(); audit = new Audit();
@ -87,6 +121,16 @@ public abstract class CommonAbstractController {
return audit; return audit;
} }
/**
* creates an new entity or if the entity already exists updates it
*
* @param <T> the type of the entity to search for
* @param entity the entity to create or update
* @param createdBy the username to apply write into the audit history
* @return the entity after it has been written to the database.
* @throws ControllerException if the the creation or update of the entity
* fails.
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED) @TransactionAttribute(TransactionAttributeType.REQUIRED)
@Transactional @Transactional
@Lock(LockType.WRITE) @Lock(LockType.WRITE)
@ -99,6 +143,15 @@ public abstract class CommonAbstractController {
} }
} }
/**
* creates an new entity.
*
* @param <T> the type of the entity to handle
* @param entity the entity to create or update
* @param createdBy the username to apply write into the audit history
* @return the entity after it has been written to the database.
* @throws ControllerException if the the creation fails
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED) @TransactionAttribute(TransactionAttributeType.REQUIRED)
@Transactional @Transactional
@Lock(LockType.WRITE) @Lock(LockType.WRITE)
@ -121,6 +174,15 @@ public abstract class CommonAbstractController {
return entity; return entity;
} }
/**
* updates an existing entity.
*
* @param <T> the type of the entity to handle
* @param entity the entity to update
* @param updatedBy the username to apply write into the audit history
* @return the entity after it has been written to the database.
* @throws ControllerException if the the updates fails
*/
private <T extends Serializable> T executeUpdate(T entity, String updatedBy) throws ControllerException { private <T extends Serializable> T executeUpdate(T entity, String updatedBy) throws ControllerException {
T currentEntity = attach(entity); T currentEntity = attach(entity);
if (Auditable.class.isAssignableFrom(currentEntity.getClass())) { if (Auditable.class.isAssignableFrom(currentEntity.getClass())) {
@ -145,6 +207,15 @@ public abstract class CommonAbstractController {
return currentEntity; return currentEntity;
} }
/**
* updates an existing entity.
*
* @param <T> the type of the entity to handle
* @param entity the entity to update
* @param updatedBy the username to apply write into the audit history
* @return the entity after it has been written to the database.
* @throws ControllerException if the the updates fails
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED) @TransactionAttribute(TransactionAttributeType.REQUIRED)
@Transactional @Transactional
@Lock(LockType.WRITE) @Lock(LockType.WRITE)
@ -161,6 +232,16 @@ public abstract class CommonAbstractController {
} }
} }
/**
* Deletes an entity from the database. If the entity implements the
* {@link EndDateable} interface, the entity is not deleted but marked as
* deleted (end date set).
*
* @param <T> the type of the entity to handle
* @param entity the entity to delete
* @param deletedBy the username to apply write into the audit history
* @throws ControllerException if the deletion fails.
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED) @TransactionAttribute(TransactionAttributeType.REQUIRED)
@Transactional @Transactional
@Lock(LockType.WRITE) @Lock(LockType.WRITE)
@ -174,20 +255,53 @@ public abstract class CommonAbstractController {
} }
} }
/**
* attaches the given entity
*
* @param <T> the type of the entity to handle
* @param entity the entity to attach
* @return the entity after it has been attached
*/
public <T extends Serializable> T attach(T entity) { public <T extends Serializable> T attach(T entity) {
return em.merge(entity); return em.merge(entity);
} }
public <T extends Serializable> void refresh (T entity) { /**
* Refreshes an entity.
*
* @param <T> the type of the entity to handle
* @param entity the entity after it has been refreshed.
*/
public <T extends Serializable> void refresh(T entity) {
em.refresh(entity); em.refresh(entity);
} }
/* *** filter methods *** */ /* *** filter methods *** */
/**
* Creates a filter condition.
*
* @param <T> the type of the entity to handle
* @param cb the CriteriaBuilder to use
* @param root the root to use
* @param filters the filters to use
* @return the created filter condition
*/
protected <T extends Serializable> Predicate getFilterCondition(CriteriaBuilder cb, Root<T> root, Map<String, Object> filters) { protected <T extends Serializable> Predicate getFilterCondition(CriteriaBuilder cb, Root<T> root, Map<String, Object> filters) {
return getFilterCondition(cb, root, filters, null); return getFilterCondition(cb, root, filters, null);
} }
/**
* Creates a filter condition.
*
* @param <T> the type of the entity to handle
* @param cb the CriteriaBuilder to use
* @param root the root to use
* @param filters the filters to use
* @param excludeFilters the exclude filters to apply. Entities which match
* these filters, are not taken into the result list.
* @return the created filter condition
*/
protected <T extends Serializable> Predicate getFilterCondition(CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, Map<String, Object> excludeFilters) { protected <T extends Serializable> Predicate getFilterCondition(CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, Map<String, Object> excludeFilters) {
// Predicate filterCondition = null; // Predicate filterCondition = null;
// filterCondition = getFilterCondition(filterCondition, cb, root, filters, true); // filterCondition = getFilterCondition(filterCondition, cb, root, filters, true);
@ -208,14 +322,17 @@ public abstract class CommonAbstractController {
} }
/** /**
* extends the given filterCondition by the addtional filters * extends the given filterCondition by the additional filters
* *
* @param <T> the type of the entity to handle
* @param filterCondition the current filter condition * @param filterCondition the current filter condition
* @param cb the criteria builder to use * @param cb the criteria builder to use
* @param root the root of the object to search for * @param root the root of the object to search for
* @param filters the filters to apply * @param filters the filters to apply
* @param include if set to true, the filter is used as include filter (equals, in). If set to false, the filter is inverted and used as exclude filter (not equals, not in etc) * @param include if set to true, the filter is used as include filter
* @return * (equals, in). If set to false, the filter is inverted and used as exclude
* filter (not equals, not in etc)
* @return the created filter condition
*/ */
protected <T extends Serializable> Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) { protected <T extends Serializable> Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
String wildCard = "%"; String wildCard = "%";
@ -301,6 +418,14 @@ public abstract class CommonAbstractController {
return filterCondition; return filterCondition;
} }
/**
* Adds a filter condition to an existing condition
*
* @param cb the builder to use
* @param filterCondition the existing filter condition
* @param addCondition the condition to add to the existing condition.
* @return an updated filter condition.
*/
protected Predicate addFilterCondition(CriteriaBuilder cb, Predicate filterCondition, Predicate addCondition) { protected Predicate addFilterCondition(CriteriaBuilder cb, Predicate filterCondition, Predicate addCondition) {
if (addCondition == null) { if (addCondition == null) {
return filterCondition; return filterCondition;
@ -327,20 +452,23 @@ public abstract class CommonAbstractController {
} }
/** /**
* returns null, if the list is empty or null itself. Returns the one element if there is exactly one element in the list. Otherwise an exception is thrown * returns null, if the list is empty or null itself.Returns the one element
* if there is exactly one element in the list. Otherwise an exception is
* thrown
* *
* @param resultList * @param <T> the type of the entity to handle
* @return * @param entityList the list to validate
* @throws ControllerException * @return the one and only element of the provided list
* @throws ControllerException if the list contains more than one element.
*/ */
public <T> T ensureSingleElement(List<T> resultList) throws ControllerException { public <T> T ensureSingleElement(List<T> entityList) throws ControllerException {
if ((resultList == null) || (resultList.isEmpty())) { if ((entityList == null) || (entityList.isEmpty())) {
return null; return null;
} }
if (resultList.size() > 1) { if (entityList.size() > 1) {
throw new ControllerException(ControllerException.CAUSE_TOO_MANY_ROWS, "More than one element found in list - expected exactly one"); throw new ControllerException(ControllerException.CAUSE_TOO_MANY_ROWS, "More than one element found in list - expected exactly one");
} }
return resultList.get(0); return entityList.get(0);
} }
} }

View File

@ -20,7 +20,7 @@ import javax.faces.application.FacesMessage.Severity;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class DefaultUIMessage implements UIMessage { public class DefaultUIMessage implements UIMessage {

View File

@ -29,7 +29,7 @@ import org.hibernate.usertype.UserType;
/** /**
* http://octagen.at/2014/10/postgresql-custom-data-types-enum-in-hibernate/ * http://octagen.at/2014/10/postgresql-custom-data-types-enum-in-hibernate/
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class GenericEnumType<T, E extends Enum<E>> implements UserType, Serializable { public abstract class GenericEnumType<T, E extends Enum<E>> implements UserType, Serializable {

View File

@ -44,11 +44,6 @@ limitations under the License.
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.enterprisedt</groupId>
<artifactId>edtFTPj</artifactId>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>

View File

@ -1,253 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.network.ftp;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPException;
import com.enterprisedt.net.ftp.FTPFile;
import de.muehlencord.shared.util.StringUtil;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author joern@muehlencord.de
*/
public class FTPConnection {
/** the default timeout in ms */
public static final int DEFAULTTIMEOUT = 30000;
/** the logger object */
private final static Logger LOGGER = LoggerFactory.getLogger(FTPConnection.class);
/** the username to connect with */
private String userName;
/** the password to connect with */
private String password;
/** the ftp client to use */
private FTPClient client;
/** the remote host to connect to */
private String remoteHost;
/** the locale of the client to use */
private Locale clientLocale;
/**
* creates a new ftp connection
*
* @param remoteHost the host to connect to
* @param userName the user to connect with
* @param password the password to connect with
*/
public FTPConnection(String remoteHost, String userName, String password) {
this(remoteHost, userName, password, Locale.getDefault());
}
/**
* creates a new ftp connection
*
* @param remoteHost the host to connect to
* @param userName the user to connect with
* @param password the password to connect with
* @param clientLocale the locale to use for the client
*/
public FTPConnection(String remoteHost, String userName, String password, Locale clientLocale) {
this.remoteHost = remoteHost;
this.userName = userName;
this.password = password;
this.clientLocale = clientLocale;
}
/**
* connects the ftp client to the remote host
*
* @throws FTPConnectionException if the command cannot be executed
*/
public void connect() throws FTPConnectionException {
try {
client = new FTPClient();
client.setConnectMode(FTPConnectMode.PASV);
client.setParserLocale(clientLocale);
client.setRemoteHost(remoteHost);
client.setTimeout(DEFAULTTIMEOUT);
client.connect();
client.login(userName, password);
} catch (Exception ex) {
throw new FTPConnectionException("Error while connecting to ftp client. Reason: " + ex.getMessage(), ex);
}
}
/** disconnects the ftp client from the remote host */
public void disconnect() {
try {
client.quit();
} catch (IOException | FTPException ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
}
}
/**
* returns a list of files (as string) found in the given directory
*
* @param dir the directory to return the list for
* @return a list of files (as string) found in the given directory
*
* @throws FTPConnectionException if the command cannot be executed
*/
public List<String> list(String dir) throws FTPConnectionException {
List<String> returnValue = new LinkedList<>();
try {
FTPFile[] files = client.dirDetails(dir);
for (FTPFile file : files) {
returnValue.add(file.getName());
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
}
return returnValue;
}
/**
* returns a list of directories contained in given directory
*
* @param dir the directory to return the subfolders for
* @return a list of subfolders of the given directory
*
* @throws FTPConnectionException if the command cannot be executed
*/
public List<String> listDirsOnly(String dir) throws FTPConnectionException {
List<String> returnValue = new LinkedList<>();
try {
FTPFile[] files = client.dirDetails(dir);
for (FTPFile file : files) {
if (file.isDir()) {
returnValue.add(file.getName());
}
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
}
return returnValue;
}
/**
* returns a list of files contained in the given folder
*
* @param dir the directory to list
* @return a list of files contained in the given folder
*
* @throws FTPConnectionException if the command cannot be executed
*/
public List<String> listFilesOnly(String dir) throws FTPConnectionException {
List<String> returnValue = new LinkedList<>();
try {
FTPFile[] files = client.dirDetails(dir);
for (FTPFile file : files) {
if (!file.isDir()) {
returnValue.add(file.getName());
}
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
}
return returnValue;
}
/**
* returns a list of links contained in the given folder
*
* @param dir the directory to list
* @return a list of links contained in the given folder
*
* @throws FTPConnectionException if the command cannot be executed
*/
public List<String> listLinksOnly(String dir) throws FTPConnectionException {
List<String> returnValue = new LinkedList<>();
try {
FTPFile[] files = client.dirDetails(dir);
for (FTPFile file : files) {
if (file.isLink()) {
returnValue.add(file.getName());
}
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
}
return returnValue;
}
/**
* uploads the given file and stores it under the given remote filename - including path
*
* @param localFilename the path and filename of the source file
* @param remoteFileName the path and filename of the destination file
* @throws FTPConnectionException if the command cannot be executed
*/
public void uploadFile(String localFilename, String remoteFileName) throws FTPConnectionException {
try {
client.setDetectTransferMode(true);
if ((remoteFileName != null) && !remoteFileName.equals("")) {
client.put(localFilename, remoteFileName, false);
} else {
File f = new File(localFilename);
String remoteName = f.getName();
client.put(localFilename, remoteName, false);
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
}
}
/**
* renames a file on the remote host
*
* @param remoteOldName the current file name
* @param remoteNewName the new file name
* @throws FTPConnectionException if the command cannot be executed
*/
public void rename(String remoteOldName, String remoteNewName) throws FTPConnectionException {
try {
client.rename(remoteOldName, remoteNewName);
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.debug(StringUtil.getStackTraceString(ex));
throw new FTPConnectionException("Error while renaming file. Reason: " + ex.getMessage(), ex);
}
}
}

View File

@ -1,47 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.network.ftp;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class FTPConnectionException extends Exception {
private static final long serialVersionUID = 1001347648193052240L;
/**
* Constructs an instance of
* <code>FTPConnectionException</code> with the specified detail message.
*
* @param msg the detail message.
*/
public FTPConnectionException(String msg) {
super(msg);
}
/**
* Constructs an instance of
* <code>FTPConnectionException</code> with the specified detail message.
*
* @param msg the detail message.
* @param th the causing exception
*/
public FTPConnectionException(String msg, Throwable th) {
super(msg, th);
}
}

View File

@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
/** /**
* Communication endpoint for posting a messages * Communication endpoint for posting a messages
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class HttpLayer { public class HttpLayer {

View File

@ -17,7 +17,7 @@ package de.muehlencord.shared.network.http;
/** /**
* This message is thrown if a message cannot be sent * This message is thrown if a message cannot be sent
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class MessageNotSendException extends Exception { public class MessageNotSendException extends Exception {

View File

@ -25,9 +25,10 @@ import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext; import javax.naming.ldap.LdapContext;
/** /**
* Inits and holds a connection to an ldap address directory * Initializes and holds a connection to an LDAP address directory
* @see javax.naming.ldap.LdapContext; * {@link javax.naming.ldap.LdapContext}
* @author dennis.nobel *
* @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class LDAPConnection { public class LDAPConnection {
@ -91,7 +92,7 @@ public class LDAPConnection {
} }
/** /**
* intializes connection to AD * initialize connection to AD
* @throws NamingException is thrown if connection to LDAP failed * @throws NamingException is thrown if connection to LDAP failed
*/ */
protected void init() throws NamingException { protected void init() throws NamingException {
@ -106,16 +107,23 @@ public class LDAPConnection {
env.put(Context.SECURITY_PROTOCOL, securityProtocol); env.put(Context.SECURITY_PROTOCOL, securityProtocol);
ldapContext = new InitialLdapContext(env, null); ldapContext = new InitialLdapContext(env, null);
} }
/** /**
* @see javax.naming.ldap.LdapContext; * {@link javax.naming.ldap.LdapContext}
*
* @param name the name to search for
* @param filter the filter to apply
* @param cons the search controls to use
* @return the result returned by the LDAP server
* @throws NamingException it the search fails
*/ */
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException { public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException {
return ldapContext.search(name, filter, cons); return ldapContext.search(name, filter, cons);
} }
/** /**
* @see javax.naming.ldap.LdapContext; * @throws javax.naming.NamingException if the close operation fails
* {@link javax.naming.ldap.LdapContext}
*/ */
public void close() throws NamingException { public void close() throws NamingException {
if (ldapContext != null) { if (ldapContext != null) {

View File

@ -16,9 +16,9 @@
package de.muehlencord.shared.network.ldap; package de.muehlencord.shared.network.ldap;
/** /**
* Represents a contact in ldap address directory * Represents a contact in LDAP address directory
* *
* @author Joern Muehlencord * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class LDAPContact { public class LDAPContact {
@ -45,6 +45,8 @@ public class LDAPContact {
private String countryCode = null; private String countryCode = null;
private boolean isEnabled = false; private boolean isEnabled = false;
private String distinguishedName = null; private String distinguishedName = null;
/* *** getter / setter *** */
public String getType() { public String getType() {
return type; return type;

View File

@ -29,38 +29,45 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Connection to ldap server to searh by different values * Connection to LDAP server to search by different values
* *
* @author Joern Muehlencord * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class LDAPSearch { public class LDAPSearch {
private static final Logger LOGGER = LoggerFactory.getLogger(LDAPSearch.class); private static final Logger LOGGER = LoggerFactory.getLogger(LDAPSearch.class);
/** /**
* the ldap connection to use * the LDAP connection to use
*/ */
private LDAPConnection ldapConnection; private LDAPConnection ldapConnection;
/** /**
* the search base for all queries * the search base for all queries
*/ */
private String searchBase; private final String searchBase;
/** /**
* Creates a new instance of a ldap search. * Creates a new instance of a LDAP search.
* *
* <p> * <div>
* Important: <br> If you want to use ldaps - usually port 636 make sure you provide a trustkeystore in case your ldap server does not use a certificate which can be trusted by the build in root * Important: <br> If you want to use LDAPs - usually port 636 make sure you
* certificates. (e.g. self signed certificates) </p> * provide a trustkeystore in case your LDAP server does not use a
* certificate which can be trusted by the build in root certificates. (e.g.
* self signed certificates)
* </div>
* *
* <p> * <div>
* To provide access to a trust center you can specify the following parameter to your application by providing the following parameter * To provide access to a trust center you can specify the following
* parameter to your application by providing the following parameter
* <pre> * <pre>
* -Djavax.net.ssl.trustStore=/path/to/truststore.keystore * -Djavax.net.ssl.trustStore=/path/to/truststore.keystore
* </pre> </p> * </pre>
* </div>
* *
* @param url the url of the ldap server to connect to like <code>ldap://ldapserver.your.domain:389</code> * @param url the url of the LDAP server to connect to like
* @param searchBase the search base to use - e.g. <code>DC=domain,DC=tld</code> * <code>ldap://ldapserver.your.domain:389</code>
* @param searchBase the search base to use - e.g.
* <code>DC=domain,DC=tld</code>
* @param username the username to connect with * @param username the username to connect with
* @param password the password to connect with * @param password the password to connect with
*/ */
@ -73,22 +80,29 @@ public class LDAPSearch {
} }
/** /**
* Creates a new instance of a ldap search. * Creates a new instance of a LDAP search.
* *
* <p> * <div>
* Important: <br> If you want to use ldaps - usually port 636 make sure you provide a trustkeystore in case your ldap server does not use a certificate which can be trusted by the build in root * Important: <br> If you want to use LDAPs - usually port 636 make sure you
* certificates. (e.g. self signed certificates) </p> * provide a trustkeystore in case your LDAP server does not use a
* certificate which can be trusted by the build in root certificates. (e.g.
* self signed certificates)
* </div>
* *
* <p> * <div>
* To provide access to a trust center you can specify the following parameter to your application by providing the following parameter * To provide access to a trust center you can specify the following
* parameter to your application by providing the following parameter
* <pre> * <pre>
* -Djavax.net.ssl.trustStore=/path/to/truststore.keystore * -Djavax.net.ssl.trustStore=/path/to/truststore.keystore
* </pre> </p> * </pre>
* </div>
* *
* @param authentication the authentification type to use -e.g. "SIMPLE" * @param authentication the authentification type to use -e.g. "SIMPLE"
* @param url the url of the ldap server to connect to like <code>ldap://ldapserver.your.domain:389</code> * @param url the url of the ldap server to connect to like
* <code>ldap://ldapserver.your.domain:389</code>
* @param securityProtocol the security protocol to use - e.g. SIMPLE * @param securityProtocol the security protocol to use - e.g. SIMPLE
* @param searchBase the search base to use - e.g. <code>DC=domain,DC=tld</code> * @param searchBase the search base to use - e.g.
* <code>DC=domain,DC=tld</code>
* @param username the username to connect with * @param username the username to connect with
* @param password the password to connect with * @param password the password to connect with
*/ */
@ -98,7 +112,10 @@ public class LDAPSearch {
} }
/** /**
* execute several init steps, connect to ldap * execute several init steps, connect to LDAP
*
* @throws de.muehlencord.shared.network.ldap.LDAPException if the
* connection cannot be established
*/ */
public void init() throws LDAPException { public void init() throws LDAPException {
try { try {
@ -109,7 +126,10 @@ public class LDAPSearch {
} }
/** /**
* close the ldap connection * close the LDAP connection
*
* @throws de.muehlencord.shared.network.ldap.LDAPException if an error
* during closing appears.
*/ */
public void close() throws LDAPException { public void close() throws LDAPException {
if (ldapConnection != null) { if (ldapConnection != null) {
@ -123,9 +143,9 @@ public class LDAPSearch {
} }
/** /**
* Returns the search base of the ldap connection * Returns the search base of the LDAP connection
* *
* @return the search base of the ldap connection * @return the search base of the LDAP connection
*/ */
public String getSearchBase() { public String getSearchBase() {
return searchBase; return searchBase;
@ -135,7 +155,7 @@ public class LDAPSearch {
* Searches a contact according to emailaddress in the address directory * Searches a contact according to emailaddress in the address directory
* *
* @param email emailaddress to search for * @param email emailaddress to search for
* @return ldap contact or null if nothing could be found * @return LDAP contact or null if nothing could be found
* @throws LDAPException when search fails * @throws LDAPException when search fails
*/ */
public LDAPContact searchContactWithEmail(String email) throws LDAPException { public LDAPContact searchContactWithEmail(String email) throws LDAPException {
@ -182,9 +202,10 @@ public class LDAPSearch {
} }
/** /**
* Returns true, if the given email address can be found in the configured ldap * Returns true, if the given email address can be found in the configured
* LDAP.
* *
* @param email the emailaddress to search for * @param email the email address to search for
* @return true, if the email address could be found; else false * @return true, if the email address could be found; else false
* @throws LDAPException if the search fails * @throws LDAPException if the search fails
*/ */
@ -193,11 +214,16 @@ public class LDAPSearch {
} }
/** /**
* Returns true, if the given email address is member of the given group, specified by the DN * Returns true, if the given email address is member of the given group,
* specified by the DN
* *
* @param email the email to validat * @param email the email to validate
* @param groupDn the group search base - all members must be found as "member" in this group * @param groupDn the group search base - all members must be found as
* @return * "member" in this group
* @return true, if the given contact, specified by the email address is
* member of the specified group. Otherwise false is returned.
*
* @throws de.muehlencord.shared.network.ldap.LDAPException
*/ */
public boolean isMemberOfGroup(String email, String groupDn) throws LDAPException { public boolean isMemberOfGroup(String email, String groupDn) throws LDAPException {
boolean returnValue = false; boolean returnValue = false;

View File

@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
/** /**
* MailReader to connect and work with IMAP mailboxes. Also works with exchange servers. * MailReader to connect and work with IMAP mailboxes. Also works with exchange servers.
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class DefaultMailReader implements MailReader { public abstract class DefaultMailReader implements MailReader {
@ -57,7 +57,7 @@ public abstract class DefaultMailReader implements MailReader {
} }
/** /**
* onnects to the mailbox * connects to the mailbox
* *
* @throws MailReaderConnectionException if the connection cannot be established * @throws MailReaderConnectionException if the connection cannot be established
*/ */
@ -486,8 +486,8 @@ public abstract class DefaultMailReader implements MailReader {
} }
/** /**
* asures the message can be read even if the underlaying IMAP server does not handle the message correctly. see * ensure the message can be read even if the underlaying IMAP server does not handle the message correctly. see
* http://www.oracle.com/technetwork/java/faq-135477.html for details * @see <a href="https://www.oracle.com/technetwork/java/faq-135477.html">https://www.oracle.com/technetwork/java/faq-135477.html</a>
* *
* @param msg the message to read * @param msg the message to read
* @return the message in a readable format * @return the message in a readable format

View File

@ -25,7 +25,7 @@ import javax.mail.internet.InternetAddress;
/** /**
* A mail message * A mail message
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class MailMessage { public class MailMessage {

View File

@ -17,7 +17,7 @@ package de.muehlencord.shared.network.mail;
/** /**
* Exception used during mail handling * Exception used during mail handling
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class MailMessageException extends Exception { public class MailMessageException extends Exception {

View File

@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
/** /**
* Util class to convert between javax.mail.Message and MailMessage objects * Util class to convert between javax.mail.Message and MailMessage objects
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class MailMessageUtils { public abstract class MailMessageUtils {

View File

@ -19,7 +19,7 @@ import java.util.List;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public interface MailReader { public interface MailReader {
@ -85,6 +85,8 @@ public interface MailReader {
* retrieves the list of messages stored in the given folder * retrieves the list of messages stored in the given folder
* *
* @param folder the folder to search return the emails for * @param folder the folder to search return the emails for
* @param start the number of the first message
* @param end the number of the last message
* @return list of messages stored in the given folder * @return list of messages stored in the given folder
* *
* @throws MailReaderException if the message list cannot be retrieved * @throws MailReaderException if the message list cannot be retrieved

View File

@ -22,11 +22,11 @@ package de.muehlencord.shared.network.mail;
public class MailReaderConfiguration { public class MailReaderConfiguration {
/** /**
* server for smtp sessions * server for SMTP sessions
*/ */
private String smtpHost = null; private String smtpHost = null;
/** /**
* server for incoming emails - e.g. the imap or pop3 server * server for incoming emails - e.g. the IMAP or pop3 server
*/ */
private String readerHost = null; private String readerHost = null;
/** /**
@ -47,11 +47,12 @@ public class MailReaderConfiguration {
private MailProtocol protocol = null; private MailProtocol protocol = null;
// TODO add checkConfig to asure the config is valid for the reader it is attached to // TODO add checkConfig to asure the config is valid for the reader it is attached to
/** /**
* creates a new config * creates a new config
* *
* @param mailHost the smtp host to connect to * @param mailHost the smtp host to connect to
* @param host the mailreader host (imap, exchange, pop, ...) to connect to * @param host the mailreader host (IMAP, exchange, pop, ...) to connect to
* @param user the username to connect with * @param user the username to connect with
* @param pw the password to connect with * @param pw the password to connect with
*/ */
@ -69,6 +70,7 @@ public class MailReaderConfiguration {
* @param host the mailreader host (imap, exchange, pop, ...) to connect to * @param host the mailreader host (imap, exchange, pop, ...) to connect to
* @param user the username to connect with * @param user the username to connect with
* @param pw the password to connect with * @param pw the password to connect with
* @param email the email address to use for sending emails
*/ */
public MailReaderConfiguration(String mailHost, String host, String user, String pw, String email) { public MailReaderConfiguration(String mailHost, String host, String user, String pw, String email) {
this.smtpHost = mailHost; this.smtpHost = mailHost;

View File

@ -17,7 +17,7 @@ package de.muehlencord.shared.network.mail;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class MailReaderConfigurationException extends Exception { public class MailReaderConfigurationException extends Exception {

View File

@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class MailReaderConfigurationFactory { public abstract class MailReaderConfigurationFactory {

View File

@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
/** /**
* Implementation of MailReader to connect to an IMAP server * Implementation of MailReader to connect to an IMAP server
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class ImapMailReader extends DefaultMailReader { public class ImapMailReader extends DefaultMailReader {

View File

@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser { public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser {

View File

@ -23,7 +23,7 @@ import org.apache.commons.net.whois.WhoisClient;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class Whois { public class Whois {

View File

@ -21,7 +21,7 @@ import java.util.List;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class WhoisInformation { public class WhoisInformation {

View File

@ -21,7 +21,7 @@ import java.io.InputStream;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class BaseTest { public abstract class BaseTest {

View File

@ -1,166 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.network.ftp;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class FTPConnectionTest {
private final static Logger LOGGER = LoggerFactory.getLogger(FTPConnectionTest.class.getName());
/** the properties loaded from the config file */
Properties props = null;
/** true, if init is complete to execute test */
boolean initDone = false;
@BeforeEach
public void setup() {
System.out.println("\n[FTPConnectionTest]");
URL testConfigURL = FTPConnectionTest.class.getResource("/test.properties");
FileInputStream fin = null;
try {
File file = new File(testConfigURL.toURI());
props = new Properties();
if ((file == null) || (!file.exists())) {
initDone = false;
} else {
fin = new FileInputStream(file);
props.load(fin);
}
if ((props.containsKey("ftp.host")) && (props.containsKey("ftp.user")) && (props.containsKey("ftp.password")) && (props.containsKey("ftp.locale"))) {
initDone = true;
} else {
initDone = false;
}
} catch (Exception ex) {
initDone = false;
} finally {
try {
if (fin != null) {
fin.close();
}
} catch (IOException ex) {
LOGGER.error (ex.toString(), ex);
}
}
}
/** tests connect / disconnect */
@Test
public void testConnectAndDisconnect() throws FTPConnectionException {
System.out.println("testConnectAndDisconnect");
if (initDone) {
String remoteHost = props.getProperty("ftp.host");
String user = props.getProperty("ftp.user");
String password = props.getProperty("ftp.password");
Locale locale = new Locale(props.getProperty("ftp.locale"));
FTPConnection con = new FTPConnection(remoteHost, user, password, locale);
con.connect();
con.disconnect();
System.out.println("executed successfully");
} else {
System.out.println("Skipped because config is not complete");
}
}
@Test
@Disabled
public void testList() throws FTPConnectionException {
System.out.println("list");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.list(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Disabled
public void testListDirsOnly() throws FTPConnectionException {
System.out.println("listDirsOnly");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.listDirsOnly(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Disabled
public void testListFilesOnly() throws FTPConnectionException {
System.out.println("listFilesOnly");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.listFilesOnly(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Disabled
public void testListLinksOnly() throws FTPConnectionException {
System.out.println("listLinksOnly");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.listLinksOnly(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Disabled
public void testUploadFile() throws FTPConnectionException {
System.out.println("uploadFile");
String localFilename = "";
String remoteFileName = "";
FTPConnection instance = null;
instance.uploadFile(localFilename, remoteFileName);
}
@Test
@Disabled
public void testRename() throws FTPConnectionException {
System.out.println("rename");
String remoteOldName = "";
String remoteNewName = "";
FTPConnection instance = null;
instance.rename(remoteOldName, remoteNewName);
fail("The test case is a prototype.");
}
}

View File

@ -38,8 +38,7 @@ public class HttpLayerTest extends BaseTest {
String[] value = {"Hello World!", "Hello World again"}; String[] value = {"Hello World!", "Hello World again"};
map.put("message", value); map.put("message", value);
HttpLayer httpLayer = new HttpLayer( HttpLayer httpLayer = new HttpLayer("http://localhost:8080/HttpPostListener/HttpPostListener");
"http://localhost:8080/HttpPostListener/HttpPostListener");
httpLayer.post(map); httpLayer.post(map);
} }

View File

@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class MailMessageUtilsTest extends BaseTest { public class MailMessageUtilsTest extends BaseTest {

193
pom.xml
View File

@ -22,6 +22,7 @@ limitations under the License.
<version>1.2-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>shared</name> <name>shared</name>
<modules> <modules>
<module>configuration</module> <module>configuration</module>
<module>network</module> <module>network</module>
@ -34,10 +35,43 @@ limitations under the License.
</modules> </modules>
<scm> <scm>
<connection>scm:git:https://jomu.timelord.de/git/jomu/shared/</connection>
<developerConnection>scm:git:https://jomu.timelord.de/git/jomu/shared/</developerConnection> <developerConnection>scm:git:https://jomu.timelord.de/git/jomu/shared/</developerConnection>
<url>https://jomu.timelord.de/git/jomu/shared/</url>
<tag>HEAD</tag> <tag>HEAD</tag>
</scm> </scm>
<issueManagement>
<system>Gitea</system>
<url>https://jomu.timelord.de/git/jomu/shared/issues</url>
</issueManagement>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>Joern Muehlencord</name>
<email>joern@muehlencord.de</email>
</developer>
</developers>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<properties> <properties>
<!-- project setup --> <!-- project setup -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -67,12 +101,7 @@ limitations under the License.
<groupId>de.muehlencord.shared</groupId> <groupId>de.muehlencord.shared</groupId>
<artifactId>shared-jeeutil</artifactId> <artifactId>shared-jeeutil</artifactId>
<version>1.2-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>de.muehlencord.sf</groupId>
<artifactId>filter</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
@ -157,13 +186,6 @@ limitations under the License.
<version>7.0</version> <version>7.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.enterprisedt</groupId>
<artifactId>edtFTPj</artifactId>
<version>1.5.3</version> <!--FIXME - requires update -->
</dependency>
<dependency> <dependency>
<groupId>com.lambdaworks</groupId> <groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId> <artifactId>scrypt</artifactId>
@ -207,18 +229,6 @@ limitations under the License.
<artifactId>omnifaces</artifactId> <artifactId>omnifaces</artifactId>
<version>3.3</version> <version>3.3</version>
</dependency> </dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
@ -228,7 +238,7 @@ limitations under the License.
<groupId>com.inversoft</groupId> <groupId>com.inversoft</groupId>
<artifactId>prime-jwt</artifactId> <artifactId>prime-jwt</artifactId>
<version>2.0.0</version> <version>2.0.0</version>
</dependency> </dependency>
<!-- Testing --> <!-- Testing -->
<dependency> <dependency>
@ -237,25 +247,106 @@ limitations under the License.
<version>5.5.1</version> <version>5.5.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> </dependencies>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement> </dependencyManagement>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- deploy artifacts to maven repository -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- ensure sources are build so they are also uploaded -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ensure java doc is built -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- create license file -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.14</version>
<executions>
<execution>
<id>download-licenses</id>
<phase>generate-resources</phase>
<goals>
<goal>download-licenses</goal>
<goal>add-third-party</goal>
</goals>
<configuration>
<licensesOutputDirectory>${licenses.dir}</licensesOutputDirectory>
<outputDirectory>${licenses.dir}</outputDirectory>
<licenseMerges>
<licenseMerge>The Apache Software License, Version 2.0|Apache 2|Apache License, Version 2.0|Apache Public License 2.0</licenseMerge>
</licenseMerges>
</configuration>
</execution>
</executions>
</plugin>
<!-- sign jar archives -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build> <build>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<!-- build archive -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
@ -266,27 +357,21 @@ limitations under the License.
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId> <!-- build maven ejb artifacts -->
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId> <artifactId>maven-ejb-plugin</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
</plugin> </plugin>
<plugin>
<!-- switched to com.helger.maven - need to revert back to org.codehaus.mojo when jaxws-maven-plugin with JDK11 support has been released --> <!-- create new releases -->
<groupId>com.helger.maven</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6.2</version>
</plugin>
<plugin> <plugin>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version> <version>2.5.3</version>
</plugin> </plugin>
<!-- control junit tests from maven build -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
@ -294,6 +379,8 @@ limitations under the License.
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -35,16 +35,6 @@ limitations under the License.
<artifactId>shiro-web</artifactId> <artifactId>shiro-web</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>javax</groupId> <groupId>javax</groupId>
<artifactId>javaee-api</artifactId> <artifactId>javaee-api</artifactId>

View File

@ -25,7 +25,7 @@ import java.util.Date;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class DateUtil { public class DateUtil {

View File

@ -20,7 +20,7 @@ import java.util.Locale;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class OSUtil { public abstract class OSUtil {

View File

@ -17,7 +17,7 @@ package de.muehlencord.shared.util;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class SecurityException extends Exception { public class SecurityException extends Exception {

View File

@ -17,7 +17,7 @@ package de.muehlencord.shared.util;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class StringEncodingException extends Exception { public class StringEncodingException extends Exception {

View File

@ -19,13 +19,12 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class StringUtil { public abstract class StringUtil {
@ -72,15 +71,11 @@ public abstract class StringUtil {
} }
/** /**
* fills s with blanks if s < length * fills s with blanks if s &lt; length
*
*
*
*
* *
* @param length the needed length for this field * @param length the needed length for this field
* @param s the field to extend with blanks * @param s the field to extend with blanks
* @return s extended by trainling blanks. s.length == length * @return s extended by trailing blanks. s.length == length
*/ */
public static String getBlankedString(int length, String s) { public static String getBlankedString(int length, String s) {
if (s == null) { if (s == null) {
@ -100,7 +95,7 @@ public abstract class StringUtil {
* *
* @param content the string to get the value from * @param content the string to get the value from
* @param keyWord1 the starting keyword * @param keyWord1 the starting keyword
* @param keyWord2 the end keywod * @param keyWord2 the end keyword
* @return the string between keyword1 and keyword2 * @return the string between keyword1 and keyword2
* @throws ParseException if the value cannot be determined - e.g. if one of the keywords is not found * @throws ParseException if the value cannot be determined - e.g. if one of the keywords is not found
*/ */

View File

@ -23,7 +23,7 @@ import java.util.Map;
/** /**
* Defines possbile file Byte Order Marks used in files. * Defines possbile file Byte Order Marks used in files.
* *
* @see http://en.wikipedia.org/wiki/Byte-order_mark * @see <a href="https://en.wikipedia.org/wiki/Byte-order_mark">https://en.wikipedia.org/wiki/Byte-order_mark</a>
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class BOM { public class BOM {

View File

@ -29,7 +29,7 @@ public class BOMStripperInputStream extends PushbackInputStream {
/** /**
* List of all possible BOMS * List of all possible BOMS
* *
* @see http://en.wikipedia.org/wiki/Byte-order_mark for details * @see <a href="https://en.wikipedia.org/wiki/Byte-order_mark">https://en.wikipedia.org/wiki/Byte-order_mark</a>
*/ */
protected static final int[][] BOMS = { protected static final int[][] BOMS = {
BOM.BOM_UTF32_BE, BOM.BOM_UTF32_BE,

View File

@ -19,7 +19,7 @@ import java.io.Serializable;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class FileHandlingException extends Exception implements Serializable { public class FileHandlingException extends Exception implements Serializable {

View File

@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class FileUtil { public abstract class FileUtil {

View File

@ -21,7 +21,7 @@ import java.io.InputStream;
/** /**
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class DefaultTest { public abstract class DefaultTest {

View File

@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
/** /**
* Basic StringUtilTests * Basic StringUtilTests
* *
* @author joern@muehlencord.de * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class StringUtilTest extends DefaultTest { public class StringUtilTest extends DefaultTest {