Ejemplo n.º 1
0
 @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
 @Path("/list")
 @GET
 public String list() {
   List<Authority> list = authorityService.list();
   List<SubAuthority> listNew = new ArrayList<SubAuthority>();
   // List<AuthorityPower> authorityPowerList = authorityPowerService.getAuthorityPowerList();
   for (Authority a : list) {
     SubAuthority subAuthority = new SubAuthority();
     String authorityName = a.getName();
     subAuthority.setId(a.getId());
     subAuthority.setName(authorityName);
     subAuthority.setDescription(a.getDescription());
     subAuthority.setStatus(a.getStatus());
     List<String> resourceList = authorityPowerService.getResourcesByAuthorityName(authorityName);
     String resources = "";
     for (String s : resourceList) {
       String s2 = s + ";";
       resources += s2;
       System.out.println(">>>>>>>>" + s);
     }
     System.out.println("<<<<<<<<" + resources);
     String r1;
     if (resources.equals("")) {
       r1 = "";
     } else {
       r1 = resources.substring(0, resources.length() - 1);
     }
     System.out.println(">>>>>>>>" + r1);
     // String r2 = "\'"+r1+"\'";
     /*String resource="";
     int length = authorityPowerList.size();
     for(int i = 0;i<length;i++){
         String authorityName = authorityPowerList.get(i).getAuthorityName();
         if(authorityName.equals(a.getName())){
             String s = "\'"+authorityPowerList.get(i).getPowerResource()+"\'";
             resource +=s ;
         }
     } */
     subAuthority.setResource(r1);
     listNew.add(subAuthority);
   }
   return JsonResultUtils.getObjectResultByStringAsDefault(listNew, JsonResultUtils.Code.SUCCESS);
 }
Ejemplo n.º 2
0
 @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
 @Path("/delete")
 @POST
 public String delete(@FormParam("jsonString") String jsonString) {
   Authority authority = JsonMapper.buildNonDefaultMapper().fromJson(jsonString, Authority.class);
   String authorityName = authority.getName();
   int numDeleted = authorityPowerService.deleteByAuthorityName(authorityName);
   int result = authorityService.delete(authority);
   List<UserAuthority> userAuthorityList = userAuthorityService.findByAuthorityName(authorityName);
   if (userAuthorityList.size() > 0) {
     for (UserAuthority ua : userAuthorityList) {
       String userName = ua.getUserName();
       User user = userService.findByName(userName);
       String role = user.getRole();
       String[] roles = role.split(";");
       String[] newRoles = new String[roles.length - 1];
       int temp = 0;
       for (int i = 0; i < roles.length; i++) {
         if (!roles[i].equals(authorityName)) {
           newRoles[temp] = roles[i] + ";";
           temp++;
         }
       }
       String roles2 = "";
       String nr;
       for (int i = 0; i < newRoles.length; i++) {
         roles2 += newRoles[i];
       }
       if (roles2.equals("")) {
         nr = "";
       } else {
         nr = roles2.substring(0, roles2.length() - 1);
       }
       user.setRole(nr);
       userService.update(user);
       userAuthorityService.delete(ua);
     }
   }
   if ((result > 0) && (numDeleted >= 0)) {
     return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.SUCCESS);
   } else {
     return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.ERROR);
   }
 }