Example usage for org.apache.shiro.session Session getAttribute

List of usage examples for org.apache.shiro.session Session getAttribute

Introduction

In this page you can find the example usage for org.apache.shiro.session Session getAttribute.

Prototype

Object getAttribute(Object key) throws InvalidSessionException;

Source Link

Document

Returns the object bound to this session identified by the specified key.

Usage

From source file:Homework4ShiroCommandLineClient.java

/**
 * @param args//from  www . ja v  a 2 s  .  com
 */
public static void main(String[] args) {
    log.info("My First Apache Shiro Application");

    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    Subject currentUser = SecurityUtils.getSubject();

    Session session = currentUser.getSession();
    session.setAttribute("someKey", "aValue");
    String value = (String) session.getAttribute("someKey");
    if (value.equals("aValue")) {
        log.info("Retrieved the correct value! [" + value + "]");
    }

    // let's login the current user so we can check against roles and permissions:
    if (!currentUser.isAuthenticated()) {
        UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");
        token.setRememberMe(true);
        try {
            currentUser.login(token);
        } catch (UnknownAccountException uae) {
            log.info("There is no user with username of " + token.getPrincipal());
        } catch (IncorrectCredentialsException ice) {
            log.info("Password for account " + token.getPrincipal() + " was incorrect!");
        } catch (LockedAccountException lae) {
            log.info("The account for username " + token.getPrincipal() + " is locked.  "
                    + "Please contact your administrator to unlock it.");
        }
        // ... catch more exceptions here (maybe custom ones specific to your application?
        catch (AuthenticationException ae) {
            //unexpected condition?  error?
        }
    }

    log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

    if (currentUser.hasRole("schwartz")) {
        log.info("May the Schwartz be with you!");
    } else {
        log.info("Hello, mere mortal.");
    }

    if (currentUser.isPermitted("lightsaber:weild")) {
        log.info("You may use a lightsaber ring.  Use it wisely.");
    } else {
        log.info("Sorry, lightsaber rings are for schwartz masters only.");
    }

    if (currentUser.isPermitted("winnebago:drive:eagle5")) {
        log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  "
                + "Here are the keys - have fun!");
    } else {
        log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");
    }

    currentUser.logout();

    System.exit(0);
}

From source file:Tutorial.java

public static void main(String[] args) {
    log.info(//from   w w  w. j  a va 2 s  .com
            "\n\n\n\t\t\t**************************************************\n\t\t\t\tMy First Apache Shiro Application\n\t\t\t**************************************************\n");

    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    //Factory<SecurityManager> factory = new IniSecurityManagerFactory("file:src/main/webapp/WEB-INF/shiro.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    // get the currently executing user:
    Subject currentUser = SecurityUtils.getSubject();

    // Do some stuff with a Session (no need for a web or EJB container!!!)
    Session session = currentUser.getSession();
    session.setAttribute("someKey", "aValue");
    String value = (String) session.getAttribute("someKey");
    if (value.equals("aValue")) {
        log.info("Retrieved the correct value! [" + value + "]");
    }

    // let's login the current user so we can check against roles and permissions:
    if (!currentUser.isAuthenticated()) {
        UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");
        token.setRememberMe(true);
        try {
            currentUser.login(token);
        } catch (UnknownAccountException uae) {
            log.info("There is no user with username of " + token.getPrincipal());
        } catch (IncorrectCredentialsException ice) {
            log.info("Password for account " + token.getPrincipal() + " was incorrect!");
        } catch (LockedAccountException lae) {
            log.info("The account for username " + token.getPrincipal() + " is locked.  "
                    + "Please contact your administrator to unlock it.");
        }
        // ... catch more exceptions here (maybe custom ones specific to your application?
        catch (AuthenticationException ae) {
            //unexpected condition?  error?
        }
    }

    //say who they are:
    //print their identifying principal (in this case, a username):
    log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

    //test a role:
    if (currentUser.hasRole("schwartz")) {
        log.info("May the Schwartz be with you!");
    } else {
        log.info("Hello, mere mortal.");
    }

    //test a typed permission (not instance-level)
    if (currentUser.isPermitted("lightsaber:weild")) {
        log.info("You may use a lightsaber ring.  Use it wisely.");
    } else {
        log.info("Sorry, lightsaber rings are for schwartz masters only.");
    }

    //a (very powerful) Instance Level permission:
    if (currentUser.isPermitted("winnebago:drive:eagle5")) {
        log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  "
                + "Here are the keys - have fun!");
    } else {
        log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");
    }

    //all done - log out!
    currentUser.logout();
    log.info("User Logged out successfully!!");

    System.exit(0);
}

From source file:QuickstartGuice.java

License:Apache License

public static void main(String[] args) {

    // We will utilize standard Guice bootstrapping to create a Shiro SecurityManager.
    Injector injector = Guice.createInjector(new QuickstartShiroModule());
    SecurityManager securityManager = injector.getInstance(SecurityManager.class);

    // for this simple example quickstart, make the SecurityManager
    // accessible as a JVM singleton.  Most applications wouldn't do this
    // and instead rely on their container configuration or web.xml for
    // webapps.  That is outside the scope of this simple quickstart, so
    // we'll just do the bare minimum so you can continue to get a feel
    // for things.
    SecurityUtils.setSecurityManager(securityManager);

    // Now that a simple Shiro environment is set up, let's see what you can do:

    // get the currently executing user:
    Subject currentUser = SecurityUtils.getSubject();

    // Do some stuff with a Session (no need for a web or EJB container!!!)
    Session session = currentUser.getSession();
    session.setAttribute("someKey", "aValue");
    String value = (String) session.getAttribute("someKey");
    if (value.equals("aValue")) {
        log.info("Retrieved the correct value! [" + value + "]");
    }//from   w  w w  . j  a  va 2 s  . c  o  m

    // let's login the current user so we can check against roles and permissions:
    if (!currentUser.isAuthenticated()) {
        UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");
        token.setRememberMe(true);
        try {
            currentUser.login(token);
        } catch (UnknownAccountException uae) {
            log.info("There is no user with username of " + token.getPrincipal());
        } catch (IncorrectCredentialsException ice) {
            log.info("Password for account " + token.getPrincipal() + " was incorrect!");
        } catch (LockedAccountException lae) {
            log.info("The account for username " + token.getPrincipal() + " is locked.  "
                    + "Please contact your administrator to unlock it.");
        }
        // ... catch more exceptions here (maybe custom ones specific to your application?
        catch (AuthenticationException ae) {
            //unexpected condition?  error?
        }
    }

    //say who they are:
    //print their identifying principal (in this case, a username):
    log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

    //test a role:
    if (currentUser.hasRole("schwartz")) {
        log.info("May the Schwartz be with you!");
    } else {
        log.info("Hello, mere mortal.");
    }

    //test a typed permission (not instance-level)
    if (currentUser.isPermitted("lightsaber:weild")) {
        log.info("You may use a lightsaber ring.  Use it wisely.");
    } else {
        log.info("Sorry, lightsaber rings are for schwartz masters only.");
    }

    //a (very powerful) Instance Level permission:
    if (currentUser.isPermitted("winnebago:drive:eagle5")) {
        log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  "
                + "Here are the keys - have fun!");
    } else {
        log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");
    }

    //all done - log out!
    currentUser.logout();

    System.exit(0);
}

From source file:apm.modules.sys.security.SystemAuthorizingRealm.java

License:Open Source License

/**
 * ?, /*from www. ja v  a 2 s  .com*/
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;

    if (LoginController.isValidateCodeLogin(token.getUsername(), false, false)) {
        // ??
        Session session = SecurityUtils.getSubject().getSession();
        String code = (String) session.getAttribute(ValidateCodeServlet.VALIDATE_CODE);
        if (token.getCaptcha() == null || !token.getCaptcha().toUpperCase().equals(code)) {
            throw new CaptchaException("??.");
        }
    }

    User user = getUserService().findByLoginName(token.getUsername());
    if (user != null) {
        byte[] salt = Encodes.decodeHex(user.getPassword().substring(0, 16));
        return new SimpleAuthenticationInfo(new Principal(user), user.getPassword().substring(16),
                ByteSource.Util.bytes(salt), getName());
    } else {
        return null;
    }
}

From source file:cn.adfi.radius.controller.LoginController.java

@RequestMapping(value = "me", method = RequestMethod.GET)
public User getMe() {
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();

    return (User) session.getAttribute("user");
}

From source file:cn.cjam.test.TestShiro.java

public static void main(String[] args) {
    log.info("My First Apache Shiro Application");

    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    // ??://from  ww w.j a v  a 2  s .c o  m
    Subject currentUser = SecurityUtils.getSubject();

    // ? Session 
    Session session = currentUser.getSession();
    session.setAttribute("someKey", "aValue");
    String value = (String) session.getAttribute("someKey");
    if (value.equals("aValue")) {
        log.info("Retrieved the correct value! [" + value + "]");
    }

    // ???
    if (!currentUser.isAuthenticated()) {
        UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa");
        token.setRememberMe(true);
        try {
            currentUser.login(token);
        } catch (UnknownAccountException uae) {
            log.info("There is no user with username of " + token.getPrincipal());
        } catch (IncorrectCredentialsException ice) {
            log.info("Password for account " + token.getPrincipal() + " was incorrect!");
        } catch (LockedAccountException lae) {
            log.info("The account for username " + token.getPrincipal() + " is locked.  "
                    + "Please contact your administrator to unlock it.");
        }
        // ... ?
        catch (AuthenticationException ae) {
            //??
        }
    }

    //?:
    //??? ( username):
    log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");

    //:
    if (currentUser.hasRole("schwartz")) {
        log.info("May the Schwartz be with you!");
    } else {
        log.info("Hello, mere mortal.");
    }

    //?? (?instance-level)
    if (currentUser.isPermitted("lightsaber:weild")) {
        log.info("You may use a lightsaber ring.  Use it wisely.");
    } else {
        log.info("Sorry, lightsaber rings are for schwartz masters only.");
    }

    //(?)??:
    if (currentUser.isPermitted("winnebago:drive:eagle5")) {
        log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'.  "
                + "Here are the keys - have fun!");
    } else {
        log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!");
    }

    //? - t!
    currentUser.logout();

    System.exit(0);
}

From source file:cn.com.sinosoft.cimp.recordsummarize.blacklist.service.impl.BlacklistService.java

public List<Map<String, Object>> getCreditItem() {
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    Map<String, Object> unlicenseIndividual = new HashMap<String, Object>();
    unlicenseIndividual.put("CR_CODE", "0305010000");
    unlicenseIndividual.put("NAME_TABLE", "?");
    Map<String, Object> unlicenseOrg = new HashMap<String, Object>();
    unlicenseOrg.put("CR_CODE", "0306020000");
    unlicenseOrg.put("NAME_TABLE", "?");
    Map<String, Object> docCertificRevoke = new HashMap<String, Object>();
    docCertificRevoke.put("CR_CODE", "0301000000");
    docCertificRevoke.put("NAME_TABLE", "???");
    Map<String, Object> medicOrgCertificRevoke = new HashMap<String, Object>();
    medicOrgCertificRevoke.put("CR_CODE", "0302000000");
    medicOrgCertificRevoke.put("NAME_TABLE", "???");
    Map<String, Object> noitem = new HashMap<String, Object>();
    noitem.put("CR_CODE", "");
    noitem.put("NAME_TABLE", "----");
    Subject currentUser = SecurityUtils.getSubject();
    Session sessions = currentUser.getSession();
    UserVO user = (UserVO) sessions.getAttribute("loginuser");
    String orgCode = user.getOrgCode();
    if (orgCode != null && !orgCode.isEmpty()) {
        //0000000--  0000000001--??  0000000006--   0000000003--
        if (orgCode.equals("0000000001") || orgCode.equals("0000000") || orgCode.equals("0000000006")
                || orgCode.equals("0000000003") || orgCode.equals("0000000005")) {
            list.add(unlicenseIndividual);
            list.add(unlicenseOrg);/*from  w  w w.  j a  v a  2  s.c o m*/
            list.add(docCertificRevoke);
            list.add(medicOrgCertificRevoke);
        } else if (orgCode.equals("0000000000") || orgCode.equals("0000000004")) {
            list.add(docCertificRevoke);
            list.add(medicOrgCertificRevoke);
        } else if (orgCode.equals("0000000002")) {
            //0000000002--?? ??????   
            list.add(noitem);
        }
    }
    return list;
}

From source file:cn.com.sinosoft.cimp.recordsummarize.datadeduplication.service.impl.DataDeduplicationService.java

public String queryUserOrg() {
    Subject currentUser = SecurityUtils.getSubject();
    Session sessions = currentUser.getSession();
    UserVO user = (UserVO) sessions.getAttribute("loginuser");
    String queryFieldNameSql = "select ORG_CODE from t_auth_user where ID='" + user.getId() + "'";
    String userOrg = dao.executeSql(queryFieldNameSql);
    return userOrg;
}

From source file:cn.com.sinosoft.cimp.recordsummarize.datadeduplication.service.impl.DataDeduplicationService.java

@Transactional
public Map<String, Object> mergeRecord(Map<String, Object> params) throws Exception {
    Map<String, Object> msg = new HashMap<String, Object>();
    String tableCode = (String) params.get("tableCode");
    String id = UUID.randomUUID().toString().replace("-", "");
    org.hibernate.classic.Session hibsession = dao.getHibernateTemplate().getSessionFactory()
            .getCurrentSession();/* ww  w. j  a va2  s  .com*/
    boolean flag = false;
    Date tt = new Date();
    String preid = (String) params.get("idOne");
    if ("0101000000".equals(tableCode)) {//?
        CimpCoDoctor preobj = (CimpCoDoctor) hibsession.get(CimpCoDoctor.class, preid);
        CimpCoDoctor newobj = (CimpCoDoctor) bindData2Class(params, CimpCoDoctor.class, null);
        CimpCoDoctor finalobj = new CimpCoDoctor();
        //         BeanUtils.copyProperties(doctorNew , doctorOld , new String[]{});
        //               doctorOld .setUuid(id);
        //               doctorOld .setState_release("02");
        //         hibsession.save(doctorOld );
        //         CimpCoDoctor doctor=(CimpCoDoctor) hibsession.get(CimpCoDoctor.class, preid);
        //         doctor=(CimpCoDoctor) bindData2Class(params, CimpCoDoctor.class, null);
        //         doctor.setUuid(id);
        //         doctor.setState_release("02");
        //         hibsession.save(finalDoctor);
        //
        //         Field[] field = doctorOld.getClass().getDeclaredFields();
        //         for (Field f : field) {
        //            if (!f.getName().equals("uuid")) {
        //               Field tempField = finalDoctor.getClass().getDeclaredField(f.getName());
        //               tempField.setAccessible(true);
        //               Object val = tempField.get(doctorOld);// 
        //               if (val != null) {
        //                  tempField.set(finalDoctor, val);
        //               }
        //
        //            }
        //            
        //         }
        //         Field[] field2 = doctorNew.getClass().getDeclaredFields();
        //         for (Field f : field2) {
        //            if (!f.getName().equals("uuid")) {
        //               Field tempField = finalDoctor.getClass().getDeclaredField(f.getName());
        //               tempField.setAccessible(true);
        //               Object val = tempField.get(doctorNew);// 
        //               if (val != null) {
        //                  tempField.set(finalDoctor, val);
        //               }
        //
        //            }
        //         
        //         }
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        CimpCoDoctor preDoctorOne = dao.queryById((String) params.get("idTwo"), CimpCoDoctor.class);
        CimpCoDoctor preDoctorTwo = dao.queryById((String) params.get("idOne"), CimpCoDoctor.class);
        preDoctorOne.setState_valid("01");
        preDoctorTwo.setState_valid("01");
        hibsession.update(preDoctorTwo);
        hibsession.update(preDoctorOne);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0102000000".equals(tableCode)) {//?
        CimpCoNurse preNurseOne, preNurseTwo;
        CimpCoNurse preobj = (CimpCoNurse) hibsession.get(CimpCoNurse.class, preid);
        CimpCoNurse newobj = (CimpCoNurse) bindData2Class(params, CimpCoNurse.class, null);
        CimpCoNurse finalobj = new CimpCoNurse();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preNurseOne = dao.queryById((String) params.get("idTwo"), CimpCoNurse.class);
        preNurseTwo = dao.queryById((String) params.get("idOne"), CimpCoNurse.class);
        preNurseOne.setState_valid("01");
        preNurseTwo.setState_valid("01");
        hibsession.update(preNurseOne);
        hibsession.update(preNurseTwo);
        flag = true;
        msg.put("mark", "success");
    }
    //      if("0103000000".equals(tableCode)||"0104000000".equals(tableCode)||"0105000000".equals(tableCode)||"0106000000".equals(tableCode)){
    if ("0103000000".equals(tableCode)) {
        //????---???
        PerCoDisinfectant preDisinfectantOne, preDisinfectantTwo;
        PerCoDisinfectant preobj = (PerCoDisinfectant) hibsession.get(PerCoDisinfectant.class, preid);
        PerCoDisinfectant newobj = (PerCoDisinfectant) bindData2Class(params, PerCoDisinfectant.class, null);
        PerCoDisinfectant finalobj = new PerCoDisinfectant();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preDisinfectantOne = dao.queryById((String) params.get("idOne"), PerCoDisinfectant.class);
        preDisinfectantTwo = dao.queryById((String) params.get("idTwo"), PerCoDisinfectant.class);
        preDisinfectantOne.setState_valid("01");
        preDisinfectantTwo.setState_valid("01");
        hibsession.update(preDisinfectantOne);
        hibsession.update(preDisinfectantTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0104000000".equals(tableCode)) {
        //??????---???
        PerCoWater preWaterOne, preWaterTwo;
        PerCoWater preobj = (PerCoWater) hibsession.get(PerCoWater.class, preid);
        PerCoWater newobj = (PerCoWater) bindData2Class(params, PerCoWater.class, null);
        PerCoWater finalobj = new PerCoWater();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preWaterOne = dao.queryById((String) params.get("idOne"), PerCoWater.class);
        preWaterTwo = dao.queryById((String) params.get("idTwo"), PerCoWater.class);
        preWaterOne.setState_valid("01");
        preWaterTwo.setState_valid("01");
        hibsession.update(preWaterOne);
        hibsession.update(preWaterTwo);
        flag = true;
        msg.put("mark", "success");
    }
    //      if("0104000000".equals(tableCode)){//?????
    //         
    //      }
    //      if("0105000000".equals(tableCode)){//??????
    //         
    //      }
    //      if("0106000000".equals(tableCode)){//?????
    //         
    //      }
    if ("0107000000".equals(tableCode)) {//???
        CimpCoPublicplaces preOne, preTwo;
        CimpCoPublicplaces preobj = (CimpCoPublicplaces) hibsession.get(CimpCoPublicplaces.class, preid);
        CimpCoPublicplaces newobj = (CimpCoPublicplaces) bindData2Class(params, CimpCoPublicplaces.class, null);
        CimpCoPublicplaces finalobj = new CimpCoPublicplaces();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoPublicplaces.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoPublicplaces.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");

    }
    if ("0108000000".equals(tableCode)) {//?????
        CimpCoWater preOne, preTwo;
        CimpCoWater preobj = (CimpCoWater) hibsession.get(CimpCoWater.class, preid);
        CimpCoWater newobj = (CimpCoWater) bindData2Class(params, CimpCoWater.class, null);
        CimpCoWater finalobj = new CimpCoWater();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoWater.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoWater.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0109000000".equals(tableCode)) {//????
        CimpCoDisinfectant preOne, preTwo;
        CimpCoDisinfectant preobj = (CimpCoDisinfectant) hibsession.get(CimpCoDisinfectant.class, preid);
        CimpCoDisinfectant newobj = (CimpCoDisinfectant) bindData2Class(params, CimpCoDisinfectant.class, null);
        CimpCoDisinfectant finalobj = new CimpCoDisinfectant();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDisinfectant.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDisinfectant.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    //      if("0110000000".equals(tableCode)){//????
    //         msg.put("mark", "success");
    //         return msg;
    //      }
    if ("0111000000".equals(tableCode)) {//??????
        CimpCoWater preOne, preTwo;
        CimpCoWater preobj = (CimpCoWater) hibsession.get(CimpCoWater.class, preid);
        CimpCoWater newobj = (CimpCoWater) bindData2Class(params, CimpCoWater.class, null);
        CimpCoWater finalobj = new CimpCoWater();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoWater.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoWater.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0112000000".equals(tableCode)) {//????
        CimpCoRadiation preOne, preTwo;
        CimpCoRadiation preobj = (CimpCoRadiation) hibsession.get(CimpCoRadiation.class, preid);
        CimpCoRadiation newobj = (CimpCoRadiation) bindData2Class(params, CimpCoRadiation.class, null);
        CimpCoRadiation finalobj = new CimpCoRadiation();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoRadiation.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoRadiation.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0113000000".equals(tableCode)) {//??????
        CimpCoOccServices preOne, preTwo;
        CimpCoOccServices preobj = (CimpCoOccServices) hibsession.get(CimpCoOccServices.class, preid);
        CimpCoOccServices newobj = (CimpCoOccServices) bindData2Class(params, CimpCoOccServices.class, null);
        CimpCoOccServices finalobj = new CimpCoOccServices();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setStateValid("02");
        finalobj.setDateDataAccess(tt);
        finalobj.setStateRelease("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoOccServices.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoOccServices.class);
        preOne.setStateValid("01");
        preTwo.setStateValid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0201010000".equals(tableCode)) {//???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0202020000".equals(tableCode)) {//???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0203050000".equals(tableCode)) {//???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0204030000".equals(tableCode)) {//?)???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0205040000".equals(tableCode)) {//???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0206080000".equals(tableCode)) {//???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0207020000".equals(tableCode)) {//??????
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
        //          return msg;   
    }
    if ("0208070000".equals(tableCode)) {//???
        CimpCoDiscipline preOne, preTwo;
        CimpCoDiscipline preobj = (CimpCoDiscipline) hibsession.get(CimpCoDiscipline.class, preid);
        CimpCoDiscipline newobj = (CimpCoDiscipline) bindData2Class(params, CimpCoDiscipline.class, null);
        CimpCoDiscipline finalobj = new CimpCoDiscipline();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoDiscipline.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoDiscipline.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0401000000".equals(tableCode)) {//??
        CimpCoExDonateBlood preOne, preTwo;
        CimpCoExDonateBlood preobj = (CimpCoExDonateBlood) hibsession.get(CimpCoExDonateBlood.class, preid);
        CimpCoExDonateBlood newobj = (CimpCoExDonateBlood) bindData2Class(params, CimpCoExDonateBlood.class,
                null);
        CimpCoExDonateBlood finalobj = new CimpCoExDonateBlood();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setState_valid("02");
        finalobj.setDate_data_access(tt);
        finalobj.setState_release("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoExDonateBlood.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoExDonateBlood.class);
        preOne.setState_valid("01");
        preTwo.setState_valid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    //      if("0301000000".equals(tableCode)){//???
    //         msg.put("mark", "success");
    //         return msg;
    //      }
    //      if("0302000000".equals(tableCode)){//???
    //         msg.put("mark", "success");
    //      }
    if ("0303000000".equals(tableCode)) {//??
        CimpCoBlaObjectInvolved preOne, preTwo;
        CimpCoBlaObjectInvolved preobj = (CimpCoBlaObjectInvolved) hibsession.get(CimpCoBlaObjectInvolved.class,
                preid);
        CimpCoBlaObjectInvolved newobj = (CimpCoBlaObjectInvolved) bindData2Class(params,
                CimpCoBlaObjectInvolved.class, null);
        CimpCoBlaObjectInvolved finalobj = new CimpCoBlaObjectInvolved();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setStateValid("02");
        finalobj.setDateDataAccess(tt);
        finalobj.setStateRelease("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoBlaObjectInvolved.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoBlaObjectInvolved.class);
        preOne.setStateValid("01");
        preTwo.setStateValid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if ("0304000000".equals(tableCode)) {//??
        CimpCoBlaUnit preOne, preTwo;
        CimpCoBlaUnit preobj = (CimpCoBlaUnit) hibsession.get(CimpCoBlaUnit.class, preid);
        CimpCoBlaUnit newobj = (CimpCoBlaUnit) bindData2Class(params, CimpCoBlaUnit.class, null);
        CimpCoBlaUnit finalobj = new CimpCoBlaUnit();
        reflect(preobj, newobj, finalobj);
        finalobj.setUuid(id);
        finalobj.setStateValid("02");
        finalobj.setDateDataAccess(tt);
        finalobj.setStateRelease("01");
        hibsession.save(finalobj);
        preOne = dao.queryById((String) params.get("idTwo"), CimpCoBlaUnit.class);
        preTwo = dao.queryById((String) params.get("idOne"), CimpCoBlaUnit.class);
        preOne.setStateValid("01");
        preTwo.setStateValid("01");
        hibsession.update(preOne);
        hibsession.update(preTwo);
        flag = true;
        msg.put("mark", "success");
    }
    if (flag) {
        CimpDeduplicateLog deduplicateLog1 = new CimpDeduplicateLog(),
                deduplicateLog2 = new CimpDeduplicateLog();
        Subject currentUser = SecurityUtils.getSubject();
        Session sessions = currentUser.getSession();
        UserVO user = (UserVO) sessions.getAttribute("loginuser");
        String id1 = UUID.randomUUID().toString().replace("-", "");
        String id2 = UUID.randomUUID().toString().replace("-", "");
        deduplicateLog1.setId(id1);
        deduplicateLog2.setId(id2);
        deduplicateLog1.setPreRecordUUID(params.get("idOne").toString());
        deduplicateLog2.setPreRecordUUID(params.get("idTwo").toString());
        deduplicateLog1.setNewRecordUUID(id);
        deduplicateLog2.setNewRecordUUID(id);
        deduplicateLog1.setUserId(user.getId());
        deduplicateLog2.setUserId(user.getId());
        deduplicateLog1.setOperateDate(tt);
        deduplicateLog2.setOperateDate(tt);
        ;
        deduplicateLog1.setCreditTypeCode(tableCode.substring(0, 2));
        deduplicateLog2.setCreditTypeCode(tableCode.substring(0, 2));
        deduplicateLog1.setCreditItemCode(tableCode);
        deduplicateLog2.setCreditItemCode(tableCode);
        deduplicateLog1.setOperateType("01");
        deduplicateLog2.setOperateType("01");
        deduplicateLog1.setOrgCode(user.getOrgCode());
        deduplicateLog2.setOrgCode(user.getOrgCode());
        hibsession.save(deduplicateLog1);
        hibsession.save(deduplicateLog2);
        return msg;
    }
    msg.put("mark", "fail");
    return msg;
}

From source file:cn.com.sinosoft.cimp.recordsummarize.datadeduplication.service.impl.DataDeduplicationService.java

@Transactional
public boolean deleteRecordEntry(String[] id, String tableCode) {
    String tableName;/*www .  j a v  a  2s  .c  o m*/
    tableName = queryCreditItemTableFieldName(
            "select CODE_COLLECTION_TABLE from dic_credit_record_management where cr_code='" + tableCode + "'");
    String newID;
    Subject currentUser = SecurityUtils.getSubject();
    Session sessions = currentUser.getSession();
    UserVO user = (UserVO) sessions.getAttribute("loginuser");
    Date time = new Date();
    try {
        for (int i = 0; i < id.length; i++) {
            if (tableName != null && !tableName.isEmpty()) {
                newID = UUID.randomUUID().toString().replace("-", "");
                String sql = "update " + tableName + " set STATE_VALID='01' where uuid='" + id[i] + "'";
                org.hibernate.classic.Session hibsession = dao.getHibernateTemplate().getSessionFactory()
                        .getCurrentSession();
                dao.executeSql(sql);
                CimpDeduplicateLog deduplicateLog = new CimpDeduplicateLog();
                deduplicateLog.setId(newID);
                deduplicateLog.setPreRecordUUID(id[i]);
                deduplicateLog.setUserId(user.getId());
                deduplicateLog.setOperateDate(time);
                deduplicateLog.setCreditTypeCode(tableCode.substring(0, 2));
                deduplicateLog.setCreditItemCode(tableCode);
                deduplicateLog.setOperateType("02");
                deduplicateLog.setOrgCode(user.getOrgCode());
                hibsession.save(deduplicateLog);
            }
        }
        //         dao.executeDelOrUpdateSql("DELETE FROM CimpPiBasDoctor WHERE doctorId = ? ",
        //               new Object[]{id}, new Type[]{StringType.INSTANCE});
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}