enhanced enddateable support
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.db;
|
package de.muehlencord.shared.db;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.util.DateUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -89,9 +90,8 @@ public abstract class AbstractController<T> {
|
|||||||
* @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
|
* @param include if set to true, the filter is used as include filter (equals, in). If set to false, the filter is
|
||||||
* (equals, in). If set to false, the filter is inverted and used as exclude
|
* inverted and used as exclude filter (not equals, not in etc)
|
||||||
* filter (not equals, not in etc)
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
|
protected Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
|
||||||
@ -103,7 +103,15 @@ public abstract class AbstractController<T> {
|
|||||||
|
|
||||||
// check for differnt types
|
// check for differnt types
|
||||||
// 1st String, either from Enum Status or from other free text string
|
// 1st String, either from Enum Status or from other free text string
|
||||||
if (String.class.equals(filter.getValue().getClass())) {
|
if (filter.getValue() == null) {
|
||||||
|
Predicate predicate;
|
||||||
|
if (include) {
|
||||||
|
predicate = cb.isNull(path);
|
||||||
|
} else {
|
||||||
|
predicate = cb.isNotNull(path);
|
||||||
|
}
|
||||||
|
filterCondition = addFilterCondition(cb, filterCondition, predicate);
|
||||||
|
} else if (String.class.equals(filter.getValue().getClass())) {
|
||||||
switch (filter.getKey()) {
|
switch (filter.getKey()) {
|
||||||
default:
|
default:
|
||||||
String filterValue = filter.getValue().toString();
|
String filterValue = filter.getValue().toString();
|
||||||
@ -204,6 +212,10 @@ public abstract class AbstractController<T> {
|
|||||||
Updateable updateable = (Updateable) entity;
|
Updateable updateable = (Updateable) entity;
|
||||||
applyUpdateableChanges(updateable, true, createdBy);
|
applyUpdateableChanges(updateable, true, createdBy);
|
||||||
}
|
}
|
||||||
|
if (EndDateable.class.isAssignableFrom(entity.getClass())) {
|
||||||
|
EndDateable endDateable = (EndDateable) entity;
|
||||||
|
endDateable.setValidFrom(DateUtil.getCurrentTimeInUTC());
|
||||||
|
}
|
||||||
em.persist(entity);
|
em.persist(entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@ -223,8 +235,15 @@ public abstract class AbstractController<T> {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
public void delete(T entity, String deletedBy) throws ControllerException {
|
public void delete(T entity, String deletedBy) throws ControllerException {
|
||||||
|
// if the entity is endDateable just set the validToDate to now intead of executing the deletion
|
||||||
|
if (EndDateable.class.isAssignableFrom(entity.getClass())) {
|
||||||
|
EndDateable endDateable = (EndDateable) entity;
|
||||||
|
endDateable.setValidTo(DateUtil.getCurrentTimeInUTC());
|
||||||
|
update(entity, deletedBy);
|
||||||
|
} else {
|
||||||
em.remove(attach(entity));
|
em.remove(attach(entity));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Lock(LockType.READ)
|
@Lock(LockType.READ)
|
||||||
public T find(Object id) {
|
public T find(Object id) {
|
||||||
@ -287,9 +306,8 @@ public abstract class AbstractController<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns null, if the list is empty or null itself. Returns the one
|
* returns null, if the list is empty or null itself. Returns the one element if there is exactly one element in the
|
||||||
* element if there is exactly one element in the list. Otherwise an
|
* list. Otherwise an exception is thrown
|
||||||
* exception is thrown
|
|
||||||
*
|
*
|
||||||
* @param resultList
|
* @param resultList
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
Reference in New Issue
Block a user