Example usage for com.google.gson JsonDeserializer JsonDeserializer

List of usage examples for com.google.gson JsonDeserializer JsonDeserializer

Introduction

In this page you can find the example usage for com.google.gson JsonDeserializer JsonDeserializer.

Prototype

JsonDeserializer

Source Link

Usage

From source file:com.quchwe.cms.data.remote.RemoteSource.java

private RemoteSource(Context context) {
    this.mContext = context;
    mLocalSource = LocalSource.instance(context);
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
        public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            return new Date(json.getAsJsonPrimitive().getAsLong());
        }//from   w ww  .  j a va 2 s  . c  o m
    });

    gson = builder.create();

}

From source file:com.quix.aia.cn.imo.mapper.UserMaintenance.java

License:Open Source License

/**
 * <p>This method checks USer id and Password and  sets values to bean  and 
 * also set last time login Date & Time</p>
 * @param User user object// w ww.j a v a 2s .c  o m
 * @param requestParameters Servlet Request Parameter
 * @return User object
 */

//   public User authenticateUser(String userID, String password) {
//      log.log(Level.INFO,"UserMaintenance --> authenticateUser ");
//      
//       ArrayList<User> list = new ArrayList();
//       User user=null;  
//       Query query=null;
//       Session session = null;
//      Transaction tx;
//       try{ 
//         
//             session = HibernateFactory.openSession();
//            tx= session.beginTransaction();
//            String psw=PasswordHashing.EncryptBySHA2(password);
//            query = session.createQuery(" from User where status = 1 and staffLoginId=:LoginId and password=:psw    ");
//            query.setParameter("LoginId",userID.toUpperCase());
//            query.setParameter("psw",psw );
//            
//            list=(ArrayList<User>) query.list();
//            
//            if(list.size()==0){
//               query = session.createQuery(" from User where status = 1 and staffLoginId=:LoginId   ");
//               query.setParameter("LoginId",userID.toUpperCase());
//               list=(ArrayList<User>) query.list();
//               User tempUser=new User();
//               if(list.size()!=0){
//                  tempUser=list.get(0);
//                  query = session.createQuery("UPDATE User SET faildLogin=:failLogin where status = 1 and user_no=:userno  ");
//                  query.setParameter("failLogin", new Date());
//                  query.setParameter("userno", tempUser.getUser_no());
//                  query.executeUpdate();
//                  tx.commit();
//                  
//               }
//               
//               return user;
//            }else{
//               user = new User();
//               user = list.get(0);
//               
//               if(user.getSscCode() > 0)
//                  user.setSscLevel(true);
//               else if(user.getCityCode() > 0)
//                  user.setCityLevel(true);
//               else if(user.getBranchCode() > 0)
//                  user.setBranchLevel(true);
//               else if(user.getDistrict() > 0)
//                  user.setDistrictLevel(true);
//               else if(user.getBuCode() > 0)
//                  user.setBuLevel(true);
//            }
//            
//            query = session.createQuery("UPDATE User SET lastLogIn=:lastLogin where status = 1 and user_no=:userno  ");
//            query.setParameter("lastLogin", new Date());
//            query.setParameter("userno", user.getUser_no());
//            query.executeUpdate();
//            tx.commit();
//            
//            
//          log.log(Level.INFO,"authenticateUser Successfully ................. ");
//       }   
//         catch(Exception e)
//         {
//            log.log(Level.INFO,"authenticateUser Failed ................. ");
//            e.printStackTrace();
//            
//         }finally{
//            try{
//               HibernateFactory.close(session);
//            }catch(Exception e){
//               
//               e.printStackTrace();
//            }
//      
//         }
//      return user;
//   }

public User authenticateUser(String userID, String password, String branch, ServletContext context) {
    log.log(Level.INFO, "UserMaintenance --> authenticateUser ");

    ArrayList<User> list = new ArrayList();
    User user = null;
    Query query = null;
    Session session = null;
    Transaction tx;
    UserRest userRest = null;
    UserAuthResponds userAuth = new UserAuthResponds();
    if ("admin".equalsIgnoreCase(userID) && "P@ssword1".equals(password)) {
        user = new User();
        user.setBranchCode(0);
        user.setBranchLevel(false);
        user.setBuCode(0);
        user.setStaffName("Admin");
        user.setBuLevel(true);
        // user.setChannelCode("2|3|");
        user.setCityCode("0");
        user.setCityLevel(false);
        user.setContactNo("0000000000");
        user.setDepartment(0);
        user.setDistrict(0);
        user.setDistrictLevel(false);
        user.setEmail("admin@email.com");
        user.setPassword(password);
        user.setSscCode("0");
        user.setSscLevel(false);
        user.setOfficeCode("0");
        user.setOfficeLevel(false);
        user.setBranchCode(0);
        user.setBranchLevel(false);
        user.setStaffLoginId("Admin");
        user.setStatus(true);
        user.setStatusPsw(true);
        user.setUser_no(0);
        user.setUserType("AD");
        user.setCho(true);
        log.log(Level.INFO, "authenticateUser Successfully ................. ");
    } else {
        GsonBuilder builder = new GsonBuilder();
        HttpClient httpClient = new DefaultHttpClient();
        try {

            String co = "";
            //                  userID="NSNP306";
            //                  password="A111111A";
            AamData aamData = new AamData();
            co = branch;
            //                  co="0986";
            Map<String, String> map = (Map<String, String>) context
                    .getAttribute(ApplicationAttribute.CONFIGURATION_PROPERTIES_MAP);
            //                  String userAuthUrl  = ResourceBundle.getBundle("configurations").getString("userAuthUrl");
            //                  String userAuthUrl = map.get("userAuthUrl");
            String userAuthUrlFinal = "";
            //                  String userAuthEnvironment = map.get("userAuthEnvironment");
            //                  String userAuthEnvironment = context.getInitParameter("userAuthEnvironment");
            Context envEntryContext = (Context) new InitialContext().lookup("java:comp/env");
            String userAuthEnvironment = (String) envEntryContext.lookup("userAuthEnvironment");
            if ("internet".equalsIgnoreCase(userAuthEnvironment)) {
                userAuthUrlFinal = map.get("userAuthUrlInternet") + "&co=" + co + "&account=" + userID
                        + "&password=" + password;

            } else {
                userAuthUrlFinal = map.get("userAuthUrl") + "&co=" + co + "&account=" + userID + "&password="
                        + password;
            }
            log.log(Level.INFO,
                    "UserAuthUrl : " + userAuthUrlFinal + " :- userAuthEnvironment : " + userAuthEnvironment,
                    "");
            HttpGet getRequest = new HttpGet(userAuthUrlFinal);
            getRequest.addHeader("accept", "application/json");
            HttpResponse response = httpClient.execute(getRequest);

            if (response.getStatusLine().getStatusCode() != 200) {
                throw new RuntimeException(
                        "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

            String output;
            log.log(Level.INFO, "UserMaintenance --> Output from Server ....  ");
            // System.out.println("Output from Server .... \n");
            if ((output = br.readLine()) != null) {
                //System.out.println(output);
                Gson googleJson = new Gson();
                userAuth = googleJson.fromJson(output, UserAuthResponds.class);
                System.out.println("Success " + userAuth.getSuccess());
                if (userAuth.getSuccess().equals("1")) {

                    String content = userAuth.getContent();

                    content = AESPasswordManager.getInstance().decryptPassword(content);

                    builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
                        @Override
                        public Date deserialize(JsonElement json, Type typeOfT,
                                JsonDeserializationContext context) throws JsonParseException {
                            return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                        }
                    });

                    googleJson = builder.create();

                    //                       content="{\"BRANCH\":\"0986\",\"CITY\":NULL,\"SSC\":NULL,\"USERTYPE\":NULL,\"USERID\":\"000015710\",\"USERNAME\":\"                        \",\"USERSTATUS\":\"A\",\"TEAMCODE\":\"G00000060\",\"TEAMNAME\":\"                        \",\"OFFICECODE\":\"YA01\",\"OFFICENAME\":\"                      \",\"CERTIID\":\"310110198008080808  \",\"DATEOFBIRTH\":\"1980-08-08\",\"GENDER\":\"F \",\"CONTRACTEDDATE\":\"2002-10-01 12:00:00.0\",\"TITLE\":\"L3\",\"DTLEADER\":NULL}";

                    userRest = googleJson.fromJson(content, UserRest.class);

                    if ("STAFF".equalsIgnoreCase(userRest.getUSERTYPE())) {
                        //                     
                        //                     aamData = AamDataMaintenance.retrieveDataToModel(userID);
                        //                     
                        //                     
                        //                     user = new User();
                        //                     if(aamData.getBranchCode()==null){
                        //                        user.setBranchCode(0);
                        //                     }else{
                        //                        user.setBranchCode(aamData.getBranchCode());
                        //                     }
                        //                     
                        //                     if(aamData.getOfficeCode()==null){
                        //                        user.setOfficeCode(0);
                        //                     }else{
                        //                        user.setOfficeCode(Integer.parseInt(aamData.getOfficeCode()));
                        //                     }
                        //                     
                        //                     if(aamData.getDistrictCode()==null){
                        //                        user.setDistrict(0);
                        //                     }else{
                        //                        user.setDistrict(aamData.getDistrictCode());
                        //                     }
                        //                     
                        //                     if(aamData.getCityCode()==null){
                        //                        user.setCityCode(0);
                        //                     }else{
                        //                        user.setCityCode(aamData.getCityCode());
                        //                     }
                        //                     
                        //                     if(aamData.getBuCode()==null){
                        //                        user.setBuCode(0);
                        //                     }else{
                        //                        user.setBuCode(aamData.getBuCode());
                        //                     }
                        //                     if(aamData.getSscCode()==null){
                        //                        user.setSscCode(0);
                        //                     }else{
                        //                        user.setSscCode(aamData.getSscCode());
                        //                     }
                        //                     
                        //                     user.setStaffLoginId(aamData.getAgentCode());
                        //                  
                        //                     user.setUserType(userRest.getUSERTYPE());
                        //                     if(userRest.getUSERSTATUS()!=null){
                        //                        if(userRest.getUSERSTATUS().equalsIgnoreCase("A")){
                        //                           user.setStatus(true);
                        //                        }else{
                        //                           user.setStatus(false);
                        //                        }
                        //                     }else{
                        //                        user.setStatus(false);
                        //                     }
                        //                     
                        //                     if(aamData.getAgentName()==null){
                        //                        user.setStaffName("");
                        //                     }else{
                        //                        user.setStaffName(aamData.getAgentName());
                        //                     }
                        //                     
                        //                     if(user.getOfficeCode() > 0)
                        //                        user.setOfficeLevel(true);
                        //                     if(user.getSscCode() > 0)
                        //                        user.setSscLevel(true);
                        //                     
                        //                     else if(user.getCityCode() > 0)
                        //                        user.setCityLevel(true);
                        //                     else if(user.getBranchCode() > 0)
                        //                        user.setBranchLevel(true);
                        //                     else if(user.getDistrict() > 0)
                        //                        user.setDistrictLevel(true);
                        //                     else if(user.getBuCode() > 0)
                        //                        user.setBuLevel(true);

                        session = HibernateFactory.openSession();
                        tx = session.beginTransaction();
                        //String psw=PasswordHashing.EncryptBySHA2(password);
                        query = session.createQuery(" from User where status = 1 and staffLoginId=:LoginId ");
                        query.setParameter("LoginId", userID.toUpperCase());
                        //query.setParameter("psw",psw );

                        list = (ArrayList<User>) query.list();

                        if (list.size() == 0) {
                            //                           query = session.createQuery(" from User where status = 1 and staffLoginId=:LoginId   ");
                            //                           query.setParameter("LoginId",userID.toUpperCase());
                            //                           list=(ArrayList<User>) query.list();
                            //                           User tempUser=new User();
                            //                           if(list.size()!=0){
                            //                              tempUser=list.get(0);
                            //                              query = session.createQuery("UPDATE User SET faildLogin=:failLogin where status = 1 and user_no=:userno  ");
                            //                              query.setParameter("failLogin", new Date());
                            //                              query.setParameter("userno", tempUser.getUser_no());
                            //                              query.executeUpdate();
                            //                              tx.commit();
                            //                              
                            //                           }
                            //                           
                            return user;
                        } else {
                            user = new User();
                            user = list.get(0);

                            if (!user.getOfficeCode().trim().equals("0"))
                                user.setOfficeLevel(true);
                            else if (!user.getSscCode().trim().equals("0"))
                                user.setSscLevel(true);
                            else if (!user.getCityCode().trim().equals("0"))
                                user.setCityLevel(true);
                            else if (user.getBranchCode() > 0)
                                user.setBranchLevel(true);
                            else if (user.getDistrict() > 0)
                                user.setDistrictLevel(true);
                            else if (user.getBuCode() > 0)
                                user.setBuLevel(true);
                        }

                        query = session.createQuery(
                                "UPDATE User SET lastLogIn=:lastLogin where status = 1 and user_no=:userno  ");
                        query.setParameter("lastLogin", new Date());
                        query.setParameter("userno", user.getUser_no());
                        query.executeUpdate();
                        tx.commit();

                        log.log(Level.INFO, "authenticateUser Successfully ................. ");

                    } else {
                        log.log(Level.INFO, "Login Failed............");
                    }

                } else {
                    log.log(Level.INFO, "Login Failed............");

                }

            }

        } catch (Exception e) {
            log.log(Level.SEVERE, e.getMessage());
            e.printStackTrace();
            LogsMaintenance logsMain = new LogsMaintenance();
            StringWriter errors = new StringWriter();
            e.printStackTrace(new PrintWriter(errors));
            logsMain.insertLogs("UserMaintenance", Level.SEVERE + "", errors.toString());
        } finally {
            httpClient.getConnectionManager().shutdown();
            HibernateFactory.close(session);
        }
    }
    return user;
}

From source file:com.quix.aia.cn.imo.rest.AddressBookRest.java

License:Open Source License

/**
 * <p>//from   ww  w  . j a  v a 2 s. c  o  m
 * Address Book Synchronization rest service post method which gets Json
 * string, which contains list of Address Book records. This method performs
 * save or update operations. It returns Json string with local address code
 * with IOS address code.
 * </p>
 * 
 * @param jsonAddressBookListString
 * 
 */
@POST
@Path("/sync")
@Consumes(MediaType.TEXT_PLAIN)
@Produces({ MediaType.APPLICATION_JSON })
public Response syncAddressBook(String jsonAddressBookListString) {
    log.log(Level.INFO, "Address Book --> Sync Record ");
    log.log(Level.INFO,
            "Address Book --> Sync Record --> Data for Sync...  ::::: " + jsonAddressBookListString);

    MsgBeans beans = new MsgBeans();
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    List<AddressBook> jsonObjList = new ArrayList();
    GsonBuilder builder = new GsonBuilder();
    AddressBookMaintenance addressBookMaintenance = new AddressBookMaintenance();
    Gson googleJson = null;
    Type listType = null;
    String returnJsonString = "";
    try {
        returnJsonString = "[";

        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        builder.registerTypeHierarchyAdapter(byte[].class, new JsonDeserializer<byte[]>() {
            public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                return Base64.decodeBase64(json.getAsString());
            }
        });

        googleJson = builder.create();
        listType = new TypeToken<List<AddressBook>>() {
        }.getType();
        jsonObjList = googleJson.fromJson(jsonAddressBookListString, listType);

        // maintain in single transaction
        returnJsonString += addressBookMaintenance.insertOrUpdateRestBatch(jsonObjList);
        returnJsonString += "]";

        log.log(Level.INFO, "Address Book --> saved successfully ");
        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_ADDRESS_BOOK, AuditTrail.FUNCTION_SUCCESS, "SUCCESS"));
        return Response.status(200).entity(returnJsonString).build();

    } catch (Exception e) {

        beans.setCode("500");
        beans.setMassage(
                "Something wrong happens, please contact administrator. Error Message : " + e.getMessage());
        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_ADDRESS_BOOK, AuditTrail.FUNCTION_FAIL, "FAILED"));

        log.log(Level.SEVERE, "Address Book --> Error in Save Record.");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("AddressBookRest", Level.SEVERE + "", errors.toString());

        return Response.status(200).entity(googleJson.toJson(beans)).build();
    } finally {
        jsonObjList.clear();
        auditTrailMaint = null;
        addressBookMaintenance = null;
        builder = null;
        googleJson = null;
        listType = null;
        returnJsonString = null;
        beans = null;
        System.gc();
    }
}

From source file:com.quix.aia.cn.imo.rest.AddressBookRest.java

License:Open Source License

/**
 * <p>//from w  w w  . jav  a  2 s.  co m
 * This method inserts Candidate Note record.
 * </p>
 */
//[{"addressCode":172926,"iosAddressCode":"38","activityType":"Participation","activityDate":"2015-06-06 08:00:00","description":"description","activityStatus":true}]
@POST
@Path("/syncNotes")
@Consumes(MediaType.TEXT_PLAIN)
@Produces({ MediaType.APPLICATION_JSON })
public Response syncNotes(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {
    log.log(Level.INFO, "Address Book --> syncNotes ");
    log.log(Level.INFO, "Address Book --> syncNotes --> Data for Sync Notes...  ::::: " + jsonString);
    String responseString = "[{\"status\":";
    MsgBeans beans = new MsgBeans();
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    Gson googleJson = null;
    GsonBuilder builder = new GsonBuilder();
    //        CandidateNoteId candidateNoteId = new CandidateNoteId();
    CandidateNote candidateNote = null;

    CandidateNoteMaintenance candidateNoteMaint = new CandidateNoteMaintenance();
    try {
        log.log(Level.INFO, "Address Book --> Saving Candidate Notes ... ");

        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        googleJson = builder.create();
        Type listType = new TypeToken<List<CandidateNote>>() {
        }.getType();
        List<CandidateNote> jsonObjList = googleJson.fromJson(jsonString, listType);
        //           candidateNote = jsonObjList.get(0);  
        //           candidateNoteId.setAddressCode(candidateNote.getAddressCode());
        //           candidateNoteId.setIosNoteCode(candidateNote.getIosNoteCode());
        //           candidateNote.setNoteId(candidateNoteId);

        candidateNoteMaint.syncNotes(jsonObjList, request);

        //           String msg = candidateNoteMaint.createNewCandidateNote(candidateNote,request);

        log.log(Level.INFO, "Address Book --> Candidate Notes Saved successfully... ");
        responseString += true;
    } catch (Exception e) {
        e.printStackTrace();
        beans.setCode("500");
        beans.setMassage(
                "Something wrong happens, please contact administrator. Error Message : " + e.getMessage());
        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_ADDRESS_BOOK, AuditTrail.FUNCTION_FAIL, "FAILED"));

        log.log(Level.SEVERE, "Address Book --> Error in Saving Candidate Notes.");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("AddressBookRest", Level.SEVERE + "", errors.toString());

        responseString += false;
    } finally {
        builder = null;
        googleJson = null;
        //         candidateNoteId=null;
        auditTrailMaint = null;
        candidateNoteMaint = null;
        candidateNote = null;
        beans = null;
        System.gc();
    }

    responseString += "}]";
    return Response.status(200).entity(responseString).build();
}

From source file:com.quix.aia.cn.imo.rest.AddressBookRest.java

License:Open Source License

/**
 * <p>//from   www  . j  av  a  2s .  com
 * This method Push Contract Details
 * </p>
 */
//[{"branchCode":"12345","candidateAgentCode":"1255210","candidateNric":"nric2","recruiterAgentCode":"125521","recruitmentType":"recruitmentType","contractDate":"2015-06-06 08:00:00"}]
@POST
@Path("/pushContractedDetails")
@Consumes({ MediaType.TEXT_PLAIN })
@Produces({ MediaType.APPLICATION_JSON })
public Response pushContractedAamData(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {

    log.log(Level.INFO, "Address Book --> pushContractedDetails ... ");
    log.log(Level.INFO, "Address Book --> pushContractedDetails --> Data...  ::::: " + jsonString);
    ContractDetail contractDetail;
    AddressBook addressBook;
    Gson googleJson = null;
    String responseString = "[{\"status\":";
    MsgBeans beans = new MsgBeans();
    AddressBookMaintenance addressBookMaintenance = new AddressBookMaintenance();
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    try {
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        googleJson = builder.create();
        Type listType = new TypeToken<List<ContractDetail>>() {
        }.getType();
        List<ContractDetail> jsonObjList = googleJson.fromJson(jsonString, listType);
        if (!jsonObjList.isEmpty()) {
            contractDetail = jsonObjList.get(0);
            addressBook = new AddressBook();

            addressBook = addressBookMaintenance.getAddressBookNric(contractDetail.getCandidateNric(),
                    contractDetail.getRecruiterAgentCode());

            addressBook.setCandidateAgentCode(contractDetail.getCandidateAgentCode());
            addressBook.setBranchCode(contractDetail.getBranchCode());
            addressBook.setContractDate(contractDetail.getContractDate());
            addressBook.setRecruitmentType(contractDetail.getRecruitmentType());
            addressBook.setNric(contractDetail.getCandidateNric());
            addressBook.setAgentId(contractDetail.getRecruiterAgentCode());
            addressBook.setRecruitmentProgressStatus("9/9");

            addressBookMaintenance.updateAddressBook(addressBook);
        }
        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_REST, "SUCCESS"));
        responseString += true;
    } catch (Exception e) {
        log.log(Level.INFO, "EventRest --> candidateRegister --> Exception..... ");
        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_FAIL, "FAILED"));
        beans.setCode("500");
        beans.setMassage("Database Error");
        responseString += false;

        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("AddressBookRest", Level.SEVERE + "", errors.toString());
    }

    responseString += "}]";
    return Response.status(200).entity(responseString).build();
}

From source file:com.quix.aia.cn.imo.rest.EventRest.java

License:Open Source License

@POST
@Path("/candidateAttend")
@Consumes(MediaType.TEXT_PLAIN)// w  w  w  .j  a v a2s .  c om
@Produces({ MediaType.APPLICATION_JSON })
public Response candidateAttend(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {
    log.log(Level.INFO, "EventRest --> candidateAttend");
    log.log(Level.INFO, "EventRest --> candidateAttend --> Data ...  ::::: " + jsonString);
    boolean status = false;
    MsgBeans beans = new MsgBeans();
    String agentId = request.getParameter("agentId");
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    EventCandidate candidate = null;
    try {

        EopAttendanceMaintenance objMaintenance = new EopAttendanceMaintenance();
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertoDateHHMMSSAMPM1(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        Gson googleJson = builder.create();
        Type listType = new TypeToken<List<EventCandidate>>() {
        }.getType();
        List<EventCandidate> jsonObjList = googleJson.fromJson(jsonString, listType);

        for (Iterator<EventCandidate> itr = jsonObjList.iterator(); itr.hasNext();) {
            candidate = (EventCandidate) itr.next();
            objMaintenance.candidateAttendanceRest(candidate);
        }

        status = true;
        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_REST, "SUCCESS"));
    } catch (Exception e) {
        log.log(Level.INFO, "EventRest --> candidateAttend --> Exception..... ");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("EventRest", Level.SEVERE + "", errors.toString());

        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_FAIL, "FAILED"));
        beans.setCode("500");
        beans.setMassage("Database Error");
    }

    return Response.status(200).entity("[{\"status\":" + status + "}]").build();
}

From source file:com.quix.aia.cn.imo.rest.EventRest.java

License:Open Source License

@POST
@Path("/candidateRegister")
@Consumes(MediaType.TEXT_PLAIN)/*from  ww  w .  j  a v a  2  s.  co m*/
@Produces({ MediaType.APPLICATION_JSON })
public Response candidateRegister(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {
    log.log(Level.INFO, "EventRest --> candidateRegister");
    log.log(Level.INFO, "EventRest --> candidateRegister --> Data ...  ::::: " + jsonString);
    boolean status = false;
    boolean isDuplicate = false;
    Integer registeredCount = 0;
    MsgBeans beans = new MsgBeans();
    String agentId = request.getParameter("agentId");
    String coBranch = request.getParameter("co");
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    try {
        AamData aamData = AamDataMaintenance.retrieveDataToModel(agentId, coBranch);
        EopAttendanceMaintenance objMaintenance = new EopAttendanceMaintenance();
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        Gson googleJson = builder.create();
        Type listType = new TypeToken<List<EventCandidate>>() {
        }.getType();
        List<EventCandidate> jsonObjList = googleJson.fromJson(jsonString, listType);
        EventCandidate candidate = jsonObjList.get(0);
        candidate.setAgentName(aamData.getAgentName());
        candidate.setBuName(aamData.getBu());
        candidate.setDistName(aamData.getDistrict());
        candidate.setCityName(aamData.getCity());
        candidate.setSscName(aamData.getSsc());
        candidate.setBranchName(aamData.getBranch());
        candidate.setOfficeName(aamData.getOfficeName());
        candidate.setAgencyLeaderCode(aamData.getLeaderCode());
        candidate.setEventCandidateCode("" + candidate.getCandidateCode());

        if (candidate.getStatusStr() != null && candidate.getStatusStr().equalsIgnoreCase("true"))
            candidate.setStatus(true);
        else
            candidate.setStatus(false);

        //           candidate.setAgencyLeaderName(aamData.getTeamName());

        List<EventCandidate> list1 = objMaintenance.getAttendanceList(request, candidate.getEventCode());
        registeredCount = list1.size();

        if (!objMaintenance.checkDuplicateCandiadteReg("" + candidate.getEventCode(),
                candidate.getServicingAgent(), candidate.getEventCandidateCode())) {
            status = true;
            objMaintenance.createNewCandidateRest(candidate, request, aamData);
            registeredCount++;
            AddressBookMaintenance addrBookMain = new AddressBookMaintenance();
            String emailAddrs = addrBookMain
                    .getEmailAddress(Integer.parseInt(candidate.getEventCandidateCode()));

            if (emailAddrs != null && emailAddrs.length() > 0) {
                EmailNotification.sendEopRegEmailNotification(candidate, emailAddrs, aamData);
            }
            String conditionFieldName[] = { "addressCode" };
            String conditionFieldValue[] = { candidate.getEventCandidateCode() };
            new AddressBookMaintenance().updateAddressBookStatus("1/9", conditionFieldName,
                    conditionFieldValue);

            auditTrailMaint.insertAuditTrail(
                    new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_REST, "SUCCESS"));
        } else {
            auditTrailMaint.insertAuditTrail(
                    new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_REST, "FAIL"));
            isDuplicate = true;
        }

    } catch (Exception e) {
        log.log(Level.INFO, "EventRest --> candidateRegister --> Exception..... ");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("EventRest", Level.SEVERE + "", errors.toString());

        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_EOP, AuditTrail.FUNCTION_FAIL, "FAILED"));
        beans.setCode("500");
        beans.setMassage("Database Error");
    }

    return Response.status(200).entity("[{\"status\":" + status + ",\"isDuplicate\":" + isDuplicate
            + ",\"registeredCount\":" + registeredCount + "}]").build();
}

From source file:com.quix.aia.cn.imo.rest.FirstInterviewRest.java

License:Open Source License

/**
 * <p>//  w ww  .  j  a va2  s  .com
 * This method inserts Candidate First Interview Detail record.
 * </p>
 */
//[{"agentId":"172926","candidateCode":"38","interviewResult":"PASS","recruitmentPlan":"ABC","remarks":"description","passTime":"2015-06-06 08:00:00"}]
@POST
@Path("/pushFirstInterview")
@Consumes(MediaType.TEXT_PLAIN)
@Produces({ MediaType.APPLICATION_JSON })
public Response pushFirstInterviewDetails(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {
    log.log(Level.INFO, " First Interview --> push Details ");
    log.log(Level.INFO, " First Interview --> push Details  --> Data ...  ::::: " + jsonString);

    Gson googleJson = null;
    GsonBuilder builder = new GsonBuilder();
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    CandidateFirstInterviewMaintenance candidateFirstInterviewMaint = new CandidateFirstInterviewMaintenance();
    CandidateFirstInterview candidateFirstInterview = null;
    boolean status = false;

    try {
        log.log(Level.INFO, "First Interview --> Saving Candidate First Interview Details ... ");

        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        googleJson = builder.create();
        Type listType = new TypeToken<List<CandidateFirstInterview>>() {
        }.getType();
        List<CandidateFirstInterview> jsonObjList = googleJson.fromJson(jsonString, listType);
        candidateFirstInterview = jsonObjList.get(0);

        candidateFirstInterviewMaint.createNewCandidateFirstInterview(candidateFirstInterview, request);

        String conditionFieldName[] = { "addressCode" };
        String conditionFieldValue[] = { candidateFirstInterview.getCandidateCode() };
        new AddressBookMaintenance().updateAddressBookStatus("4/9", conditionFieldName, conditionFieldValue);

        log.log(Level.INFO, "First Interview --> Candidate First Interview Details Saved successfully... ");
        status = true;
    } catch (Exception e) {
        log.log(Level.SEVERE, "First Interview --> Error in Saving Candidate First Interview Details.");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("FirstInterviewRest", Level.SEVERE + "", errors.toString());

        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_TRAINING, AuditTrail.FUNCTION_FAIL, "FAILED"));

    } finally {
        builder = null;
        googleJson = null;
        auditTrailMaint = null;
        candidateFirstInterviewMaint = null;
        candidateFirstInterview = null;
        System.gc();
    }
    return Response.status(200).entity("[{\"status\":" + status + "}]").build();

}

From source file:com.quix.aia.cn.imo.rest.InterviewRest.java

License:Open Source License

@POST
@Path("/candidateRegister")
@Consumes(MediaType.TEXT_PLAIN)//from  w  ww. j  av a 2  s. c  o m
@Produces({ MediaType.APPLICATION_JSON })
public Response candidateRegister(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {
    log.log(Level.INFO, "InterviewRest --> candidateRegister");
    log.log(Level.INFO,
            "InterviewRest --> candidateRegister --> Data for Candidate Registration...  ::::: " + jsonString);
    boolean status = false;
    boolean isDuplicate = false;
    Integer registeredCount = 0;
    MsgBeans beans = new MsgBeans();
    String agentId = request.getParameter("agentId");
    String coBranch = request.getParameter("co");
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    try {
        AamData aamData = AamDataMaintenance.retrieveDataToModel(agentId, coBranch);
        InterviewAttendanceMaintenance objMaintenance = new InterviewAttendanceMaintenance();
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        Gson googleJson = builder.create();
        Type listType = new TypeToken<List<InterviewCandidate>>() {
        }.getType();
        List<InterviewCandidate> jsonObjList = googleJson.fromJson(jsonString, listType);
        InterviewCandidate candidate = jsonObjList.get(0);
        candidate.setAgentName(aamData.getAgentName());
        candidate.setBuName(aamData.getBu());
        candidate.setDistName(aamData.getDistrict());
        candidate.setCityName(aamData.getCity());
        candidate.setSscName(aamData.getSsc());
        candidate.setAgencyLeaderCode(aamData.getLeaderCode());
        candidate.setInterviewCandidateCode("" + candidate.getCandidateCode());
        candidate.setBuCode(aamData.getBuCode());
        candidate.setDistrictCode(aamData.getDistrictCode());
        candidate.setCityCode(aamData.getCity());
        candidate.setSscCode(aamData.getSsc());
        candidate.setOfficeCode(aamData.getOfficeCode());
        if (candidate.getStatusStr() != null && candidate.getStatusStr().equalsIgnoreCase("true"))
            candidate.setStatus(true);
        else
            candidate.setStatus(false);

        AddressBookMaintenance addrBookMain = new AddressBookMaintenance();
        String nric = addrBookMain.getNric(Integer.parseInt(candidate.getInterviewCandidateCode()));
        candidate.setNric(nric);

        //           candidate.setAgencyLeaderName(aamData.getTeamName());

        if (!objMaintenance.checkDuplicateCandiadteReg("" + candidate.getInterviewCode(),
                candidate.getServicingAgent(), candidate.getInterviewCandidateCode())) {
            objMaintenance.createNewCandidate(candidate, request);
            String emailAddrs = addrBookMain
                    .getEmailAddress(Integer.parseInt(candidate.getInterviewCandidateCode()));
            if (emailAddrs != null && emailAddrs.length() > 0) {
                EmailNotification.sendInterviewRegEmailNotification(candidate, emailAddrs, aamData);
            }

            String conditionFieldName[] = { "addressCode" };
            String conditionFieldValue[] = { candidate.getInterviewCandidateCode() };
            new AddressBookMaintenance().updateAddressBookStatus("2/9", conditionFieldName,
                    conditionFieldValue);

            List<InterviewCandidate> list1 = objMaintenance.getAttendanceList(request,
                    candidate.getInterviewCode());
            registeredCount = list1.size();
            auditTrailMaint.insertAuditTrail(new AuditTrail("Rest", AuditTrail.MODULE_INTERVIEW_REG,
                    AuditTrail.FUNCTION_REST, "SUCCESS"));
            status = true;
        } else {
            auditTrailMaint.insertAuditTrail(
                    new AuditTrail("Rest", AuditTrail.MODULE_INTERVIEW_REG, AuditTrail.FUNCTION_REST, "FAIL"));
            isDuplicate = true;
        }
    } catch (Exception e) {
        log.log(Level.INFO, "InterviewRest --> candidateRegister --> Exception..... ");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("InterviewRest", Level.SEVERE + "", errors.toString());

        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_INTERVIEW_REG, AuditTrail.FUNCTION_FAIL, "FAILED"));
        beans.setCode("500");
        beans.setMassage("Database Error");
    }

    return Response.status(200).entity("[{\"status\":" + status + ",\"isDuplicate\":" + isDuplicate
            + ",\"registeredCount\":" + registeredCount + "}]").build();
}

From source file:com.quix.aia.cn.imo.rest.TrainingRest.java

License:Open Source License

/**
 * <p>//from ww  w.java 2s.co m
 * This method inserts Candidate Training Detail record.
 * </p>
 */
//[{"courseCode":"172926","courseName":"38","curriculamCode":"Participation","courseType":"description","startDate":"2015-06-06 08:00:00"}]
@POST
@Path("/pushDetails")
@Consumes(MediaType.TEXT_PLAIN)
@Produces({ MediaType.APPLICATION_JSON })
public Response pushTrainingDetails(@Context HttpServletRequest request, @Context ServletContext context,
        String jsonString) {
    log.log(Level.INFO, " Training --> push Details ");
    log.log(Level.INFO, " Training --> push Details  --> Data ...  ::::: " + jsonString);

    Gson googleJson = null;
    GsonBuilder builder = new GsonBuilder();
    AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance();
    CandidateTrainingDetailMaintenance candidateTrainingDetailMaint = new CandidateTrainingDetailMaintenance();
    CandidateTrainingDetail candidateTrainingDetail = null;
    int isSuccessful = 0;

    try {
        log.log(Level.INFO, "Training --> Saving Candidate Training Details ... ");

        builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException {
                Date date = LMSUtil.convertDateToyyyymmddhhmmssDashed(json.getAsString());
                if (null != date) {
                    return date;
                } else {
                    return LMSUtil.convertDateToyyyy_mm_dd(json.getAsString());
                }
            }
        });

        googleJson = builder.create();
        Type listType = new TypeToken<List<CandidateTrainingDetail>>() {
        }.getType();
        List<CandidateTrainingDetail> jsonObjList = googleJson.fromJson(jsonString, listType);
        candidateTrainingDetail = jsonObjList.get(0);
        candidateTrainingDetail.setCreationDate(new Date());

        candidateTrainingDetailMaint.createNewCandidateTrainingDetail(candidateTrainingDetail, request);

        log.log(Level.INFO, "Training --> Candidate Training Details Saved successfully... ");
        isSuccessful = 1;
    } catch (Exception e) {
        log.log(Level.SEVERE, "Training --> Error in Saving Candidate Training Details.");
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        LogsMaintenance logsMain = new LogsMaintenance();
        logsMain.insertLogs("TrainingRest", Level.SEVERE + "", errors.toString());

        auditTrailMaint.insertAuditTrail(
                new AuditTrail("Rest", AuditTrail.MODULE_TRAINING, AuditTrail.FUNCTION_FAIL, "FAILED"));

    } finally {
        builder = null;
        googleJson = null;
        auditTrailMaint = null;
        candidateTrainingDetailMaint = null;
        candidateTrainingDetail = null;
        System.gc();
    }
    return Response.status(200).entity("[{\"isSuccessful\":" + isSuccessful + "}]").build();

}