/** * Checks if foreignable element is a new created object (not yet persistet - no id) */ private boolean isNewObject(Foreignable<?> foreignable) { return ((Identifiable) foreignable).getId() == null; }
public static Class<?> getGenericType(Field field) { return getGenericType(field, 0); }
public List<ResourceEntity> getResourcesByGroupNameWithRelations(String groupName) throws ValidationException { ValidationHelper.validateNotNullOrEmptyChecked(groupName); return resourceRepository.getResourcesByGroupNameWithRelations(groupName); }
/** * Removes an entity from the database. * * @param entity The entity to remove. */ public void remove(T entity) { preRemove(entity); // TODO check access entityManager.remove(entity); }
/** * Creates an entity on the database. The object is updated with the ID that it is created with. * * @param entity The entity to create */ public void persist(T entity) { prePersist(entity); // TODO check access entityManager.persist(entity); }
/** * Updates an entity on the database. ALL new reference to the updated entity is returned, the old one should be * discarded. * * @param entity The entity to update * @return ALL new reference to the updated object that should be used for further actions. */ public T merge(T entity) { preMerge(entity); // TODO check access return entityManager.merge(entity); }
static boolean hasEagerAnnotation(Field field) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { for (Annotation annotation : field.getAnnotations()) { if ((annotation instanceof OneToMany && isEagerFetch(annotation)) || annotation instanceof OneToOne) { return true; } } return false; }
/** * Validate all arguments. If at least one argument is either null or empty an exception is thrown */ public static void validateNotNullOrEmptyChecked(String... arguments) throws ValidationException { for (String argument : arguments) { if (argument == null || argument.isEmpty()) { throw new ValidationException("Argument must not be null or empty"); } } }
@PostConstruct public void init() { checkFilesystemPrerequisites(); }
public MikEntity(String name, AmwFunctionEntity amwFunction) { String validName = ValidationHelper.validateNotNullOrEmpty(name).trim(); if (!validName.isEmpty()) { this.name = validName; } this.amwFunction = amwFunction; }
public static <T> Class<T> getActualTypeArguments(Class<?> clazz, int indexOfArgument) { Class<T> resolvedType = getActualTypeArguments(clazz.getSuperclass().getGenericSuperclass(), indexOfArgument); if (resolvedType == null) { return getActualTypeArguments(clazz.getGenericSuperclass(), indexOfArgument); } return resolvedType; }
protected void setId(Identifiable resource, Integer id) { resource.setId(id); }
public List<ResourceEntity> getResourcesByGroupNameWithAllRelationsOrderedByRelease(String groupName) throws ValidationException { ValidationHelper.validateNotNullOrEmptyChecked(groupName); return resourceRepository.getResourcesByGroupNameWithAllRelationsOrderedByRelease(groupName); }
/** * Deletes an entity on the database without performing the normal user level access check. Should only be used by * sublcasses in special cases where you know exactly what you are doing. * * @param entity The entity to remove */ protected void removeWithoutAccessCheck(T entity) { preRemove(entity); entityManager.remove(entity); }
/** * Persists an entity without performing the normal user level access check. Should only be used by subclasses * in special cases where you know exactly what you are doing. * * @param entity The entity to update without access check */ protected void persistWithoutAccessCheck(T entity) { prePersist(entity); entityManager.persist(entity); }
/** * Updates an entity on the database without performing the normal user level access check. Should only be used by * subclasses in special cases where you know exactly what you are doing. * * @param entity The entity to update * @return ALL new reference to the updated object that should be used for further actions. */ protected T mergeWithoutAccessCheck(T entity) { preMerge(entity); return entityManager.merge(entity); }
@Test(expected = ValidationException.class) public void validateNotNullOrEmptyOnAtLeastOneInvalidArgumentShouldThrowException() throws ValidationException { // given String arg1 = "not empty argument1"; String arg2 = ""; String arg3 = "not empty argument3"; // when ValidationHelper.validateNotNullOrEmptyChecked(arg1, arg2, arg3); }
@Test(expected = ValidationException.class) public void validateNotNullOrEmptyOnOneEmptyArgumentShouldThrowException() throws ValidationException { // given String arg1 = ""; // when ValidationHelper.validateNotNullOrEmptyChecked(arg1); }
@Test(expected = ValidationException.class) public void validateNotNullOrEmptyOnOneNullArgumentShouldThrowException() throws ValidationException { // given String arg1 = null; // when ValidationHelper.validateNotNullOrEmptyChecked(arg1); }