Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.megatim.fdxconsultation.core.ifaces.abtracts;
 
import com.megatim.fdxconsultation.model.administration.User;
import java.io.Serializable;
 
/**
 *
 * @author ASUS
 */
public interface GenericCrudManagerIFaces<T, K, S, ID extends Serializable, U> extends GeneriConsultingManagerIFaces<T, K, S, ID, U> {
 
    public default T add(T entity, User connectedUser) {
 
        //Pre-traitements
        beforeAdd(entity, connectedUser);
 
        //On save
        T newEntity = save(entity);
 
        return newEntity;
    }
 
    @Override
    public default S getById(ID id) {
 
        T entity = find(getEntityIdName(), id);
 
        return mapToDetailDto(entity);
    }
 
    public default T modify(ID id, T entity, User connectedUser) {
 
        T actualEntity = find(getEntityIdName(), id);
 
        //On copie les nouvelles valeurs
        beforeModify(actualEntity, entity, connectedUser);
 
        update(id, actualEntity);
        
        return actualEntity;
    }
 
    public default T remove(ID id, User connectedUser) {
 
        T entity = find(getEntityIdName(), id);
 
        beforeRemove(entity, connectedUser);
 
        return update(id, entity);
    }
 
    public abstract void beforeAdd(T entity, User connectedUser);
 
    public abstract void beforeRemove(T entity, User connectedUser);
 
    public abstract void beforeModify(T actualEntity, T requestEntity, User connectedUser);
 
}