]> SALOME platform Git repositories - modules/gde.git/blob - projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/ApplicationEJB.java
Salome HOME
Merge with master
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / ejb / ApplicationEJB.java
1 package com.edf.gde.ejb;
2
3 import com.edf.gde.common.PermissionManager;
4 import java.util.HashMap;
5 import java.util.Map;
6 import javax.annotation.PostConstruct;
7 import javax.ejb.Singleton;
8 import javax.ejb.LocalBean;
9 import javax.persistence.EntityManager;
10 import javax.persistence.PersistenceContext;
11
12 /**
13  * @author Kavoos
14  */
15 @Singleton
16 @LocalBean
17 public class ApplicationEJB {
18     /*
19      Locked files map.
20      key = file id
21      value = user id
22      */
23     @PersistenceContext(unitName = "GDE-ejbPU")
24     private EntityManager em;
25
26     private Map<Long, Long> userFiles;
27     private PermissionManager permissionManager;
28
29     /**
30      *
31      */
32     @PostConstruct
33     private void init() {
34         userFiles = new HashMap<>();
35         permissionManager = new PermissionManager();
36     }
37
38     /**
39      * Try to lock a file
40      *
41      * @param userId
42      * @param fileId
43      * @return true if file is locked, false if file is already locked by
44      * someone else
45      */
46     public boolean lockFile(long userId, long fileId) {
47         if (userFiles.containsKey(fileId)) {
48             if (userFiles.get(fileId) == userId) {
49                 return true;
50             }
51             return false;
52         }
53         userFiles.put(fileId, userId);
54         return true;
55     }
56
57     /**
58      * Try to unlock a file
59      * @param userId
60      * @param fileId
61      * @return
62      */
63     public boolean unlockFile(long userId, long fileId) {
64         if (userFiles.containsKey(fileId)) {
65             if (userFiles.get(fileId) == userId) {
66                 userFiles.remove(fileId);
67                 return true;
68             }
69         }
70         return false;
71     }
72
73     public PermissionManager getPermissionManager() {
74         return permissionManager;
75     }    
76     
77     private void loadPermissions() {
78         
79     }
80 }