Ignore:
Timestamp:
09/20/11 03:16:11 (8 months ago)
Author:
delmitz
Branch:
default
Convert:
svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2782
Message:

modified API interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kraken-dom/src/main/java/org/krakenapps/dom/api/impl/AdminApiImpl.java

    r340 r348  
    4949import org.krakenapps.dom.model.Organization; 
    5050import org.krakenapps.dom.model.Admin; 
    51 import org.krakenapps.dom.model.OrganizationParameter; 
    5251import org.krakenapps.dom.model.Role; 
    5352import org.krakenapps.jpa.ThreadLocalEntityManagerService; 
     
    9291 
    9392                if (hash.equals(Sha1.hash(password + session.getString("nonce")))) { 
    94                         OrganizationParameter param = orgParamApi.getOrganizationParameter(admin.getUser().getOrganization().getId(), 
     93                        String maxSession = orgParamApi.getOrganizationParameter(admin.getUser().getOrganization().getId(), 
    9594                                        "max_sessions"); 
    96                         if (param != null) { 
     95                        if (maxSession != null) { 
    9796                                try { 
    98                                         int maxSessions = Integer.parseInt(param.getValue()); 
     97                                        int maxSessions = Integer.parseInt(maxSession); 
    9998                                        if (maxSessions > 0) { 
    10099                                                if (force) { 
     
    116115                        for (LoginCallback callback : callbacks) 
    117116                                callback.onLoginSuccess(admin, session); 
    118                         loggedIn.add(new LoggedInAdmin(admin.getRole().getLevel(), new Date(), session, admin.getUser().getLoginName())); 
     117                        loggedIn.add(new LoggedInAdmin(admin.getRole().getLevel(), new Date(), session, admin.getUser() 
     118                                        .getLoginName())); 
    119119                        return admin; 
    120120                } else { 
     
    269269 
    270270        @Override 
    271         public void createAdmin(int organizationId, Integer requestAdminId, Admin admin) { 
    272                 createAdminInternal(organizationId, requestAdminId, admin); 
    273                 fireEntityAdded(admin); 
    274         } 
    275  
    276         @Transactional 
    277         private void createAdminInternal(int organizationId, Integer requestAdminId, Admin admin) { 
     271        public Admin createAdmin(int organizationId, Integer requestAdminId, Admin admin) { 
     272                Admin a = createAdminInternal(organizationId, requestAdminId, admin); 
     273                fireEntityAdded(a); 
     274                return a; 
     275        } 
     276 
     277        @Transactional 
     278        private Admin createAdminInternal(int organizationId, Integer requestAdminId, Admin admin) { 
    278279                EntityManager em = entityManagerService.getEntityManager(); 
    279280                Organization organization = em.find(Organization.class, organizationId); 
     
    300301                        em.persist(host); 
    301302                } 
     303 
     304                return admin; 
    302305        } 
    303306 
     
    323326                Admin admin = (Admin) em.createQuery("SELECT a FROM Admin a LEFT JOIN a.user u WHERE u.loginName = ?") 
    324327                                .setParameter(1, loginName).getSingleResult(); 
    325                  
     328 
    326329                admin.getRole().getPermissions().size(); 
    327330                admin.getTrustHosts().size(); 
    328                  
     331 
    329332                return admin; 
    330333        } 
     
    379382 
    380383        @Override 
    381         public void removeAdmin(int organizationId, Integer requestAdminId, int adminId) { 
    382                 Admin admin = removeAdminInternal(organizationId, requestAdminId, adminId); 
    383                 fireEntityRemoved(admin); 
    384         } 
    385  
    386         @Transactional 
    387         private Admin removeAdminInternal(int organizationId, Integer requestAdminId, int adminId) { 
    388                 EntityManager em = entityManagerService.getEntityManager(); 
    389  
    390                 Admin admin = (Admin) em.find(Admin.class, adminId); 
    391                 if (admin.getUser().getOrganization().getId() != organizationId) 
    392                         throw new AdminNotFoundException(adminId); 
    393  
    394                 if (requestAdminId != null) { 
    395                         Admin requestAdmin = em.find(Admin.class, requestAdminId); 
    396                         if (requestAdmin == null) 
    397                                 throw new AdminNotFoundException(requestAdminId); 
    398  
    399                         if (requestAdmin.getRole().getLevel() < admin.getRole().getLevel()) 
    400                                 throw new SecurityException("remove admin"); 
    401  
    402                         if (requestAdminId == adminId) { 
    403                                 throw new CannotRemoveRequestingAdminException(requestAdminId); 
    404                         } 
    405                 } 
    406  
    407                 em.remove(admin); 
    408  
    409                 return admin; 
    410         } 
    411  
    412         @Override 
    413         public void updateAdmin(int organizationId, Integer requestAdminId, Admin targetAdmin) { 
     384        public Admin updateAdmin(int organizationId, Integer requestAdminId, Admin targetAdmin) { 
    414385                Admin admin = updateAdminInternal(organizationId, requestAdminId, targetAdmin); 
    415386                fireEntityUpdated(admin); 
     387                return admin; 
    416388        } 
    417389 
     
    477449        } 
    478450 
     451        @Override 
     452        public Admin removeAdmin(int organizationId, Integer requestAdminId, int adminId) { 
     453                Admin admin = removeAdminInternal(organizationId, requestAdminId, adminId); 
     454                fireEntityRemoved(admin); 
     455                return admin; 
     456        } 
     457 
     458        @Transactional 
     459        private Admin removeAdminInternal(int organizationId, Integer requestAdminId, int adminId) { 
     460                EntityManager em = entityManagerService.getEntityManager(); 
     461 
     462                Admin admin = (Admin) em.find(Admin.class, adminId); 
     463                if (admin.getUser().getOrganization().getId() != organizationId) 
     464                        throw new AdminNotFoundException(adminId); 
     465 
     466                if (requestAdminId != null) { 
     467                        Admin requestAdmin = em.find(Admin.class, requestAdminId); 
     468                        if (requestAdmin == null) 
     469                                throw new AdminNotFoundException(requestAdminId); 
     470 
     471                        if (requestAdmin.getRole().getLevel() < admin.getRole().getLevel()) 
     472                                throw new SecurityException("remove admin"); 
     473 
     474                        if (requestAdminId == adminId) { 
     475                                throw new CannotRemoveRequestingAdminException(requestAdminId); 
     476                        } 
     477                } 
     478 
     479                em.remove(admin); 
     480 
     481                return admin; 
     482        } 
     483 
    479484        private static final char[] chars = new char[62]; 
    480485        static { 
Note: See TracChangeset for help on using the changeset viewer.