Example usage for org.springframework.web.bind.support SessionStatus setComplete

List of usage examples for org.springframework.web.bind.support SessionStatus setComplete

Introduction

In this page you can find the example usage for org.springframework.web.bind.support SessionStatus setComplete.

Prototype

void setComplete();

Source Link

Document

Mark the current handler's session processing as complete, allowing for cleanup of session attributes.

Usage

From source file:egovframework.example.sample.web.EgovSampleController.java

@RequestMapping(value = "/insertProduct.do")
public void insertProduct(HttpServletRequest request, HttpServletResponse response, SessionStatus status)
        throws Exception {
    System.out.println("? ?");
    PlatformData oData = new PlatformData();
    int nErrorCode = 0;
    String strErrorMsg = "START";

    HttpPlatformRequest pReq = new HttpPlatformRequest(request);
    pReq.receiveData();//????  ??  

    PlatformData iData = pReq.getData();

    VariableList in_vl = iData.getVariableList();
    int in_var2 = in_vl.getInt("sVal1");

    DataSet ds = iData.getDataSet("product");

    try {/*w w w. j  a va2 s. c  o  m*/
        //String uuid = java.util.UUID.randomUUID().toString();
        String uuid = request.getParameter("uuid");
        Product pro = new Product();

        pro.setP_name(ds.getString(0, "p_name"));
        System.out.println("?---" + ds.getString(0, "p_name"));
        pro.setP_price(ds.getInt(0, "p_price"));
        System.out.println("---" + ds.getInt(0, "p_price"));
        pro.setP_ea(ds.getInt(0, "p_ea"));
        System.out.println("---" + ds.getInt(0, "p_ea"));
        pro.setP_from(ds.getString(0, "p_from"));
        System.out.println(" --" + ds.getString(0, "p_from"));
        pro.setP_delivery(in_var2);
        System.out.println("--" + in_var2);
        pro.setP_content(ds.getString(0, "p_content"));
        System.out.println("--" + ds.getString(0, "p_content"));
        pro.setP_uuid(uuid);
        System.out.println("uuid--" + uuid);

        sampleService.insertProduct(pro);
        status.setComplete();

        //   List<SampleVO> ListSamVO= new l

    } catch (Exception e) {
        // VariableList? ? ? 
        nErrorCode = -1;
        strErrorMsg = e.getMessage();
        e.printStackTrace();
    }

    // VariableList 
    VariableList varList = oData.getVariableList();

    // VariableList? ? ? 
    varList.add("ErrorCode", nErrorCode);
    varList.add("ErrorMsg", strErrorMsg);
    varList.add("out_var", "1234"); // 

    //   return "forward:/egovSampleList.do";

    // HttpServletResponse ? HttpPlatformResponse ?
    HttpPlatformResponse pRes = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML, "UTF-8");
    pRes.setData(oData);

    // ?? 
    pRes.sendData();
}

From source file:egovframework.example.sample.web.EgovSampleController.java

/**
 * qna ? //from w  ww  .  j a  v a2 s  .  c om
 */
@RequestMapping("/QnaDelete.do")
public String QnaDelete(@ModelAttribute("searchVO") SampleDefaultVO searchVO, @RequestParam("num") int id,
        @RequestParam("seq") int seq, SessionStatus status, Model model) throws Exception {

    QnaVO qnaVO = new QnaVO();
    qnaVO.setQ_num(id);
    qnaVO.setQ_seq(seq);
    SampleVO sampleVO = new SampleVO();
    sampleVO.setbUuid(qnaVO.getQ_uuid());
    QnaVO qvo = sampleService.selectQna(qnaVO);
    int qseq = qvo.getQ_pseq();

    /////////////?(?  ? ? )///
    List<SampleVO> uuidList = (List<SampleVO>) sampleService.getUuid(sampleVO); //? ? uuid  
    for (int i = 0; i < uuidList.size(); i++) {

        System.out.println("uuid=====" + uuidList.get(i).getbUuid()); //
    }

    SampleVO iVo = new SampleVO();
    SampleVO iVo2 = new SampleVO();
    for (int i = 0; i < uuidList.size(); i++) {

        String bUuid = uuidList.get(i).getbUuid().toString();
        //   iVo.setiUuid(bUuid);
        iVo.setbUuid(bUuid);

        //? ? ? 
        //iVo2 = sampleService.selectImgUuid(iVo); //b
        List<SampleVO> ivoList = (List<SampleVO>) sampleService.selectImgUuid(iVo); //uuid?  ??  
        System.out.println(ivoList.get(0).getiUrl());
        for (int j = 0; j < ivoList.size(); j++) { // ??   for
            System.out.println(" +? ====" + ivoList.get(j).getiUrl());
            File f = new File(ivoList.get(j).getiUrl().toString()); //? 
            f.delete(); //? 

            sampleService.deleteImgUuid(iVo);
            status.setComplete();
        }

    }
    /////////////////////////

    sampleService.deleteQnaOri(qnaVO);
    status.setComplete();

    //System.out.println(" -"+qseq);
    return "forward:/selectProduct.do?searchKeyword2=not&pageIndex=1&selectedId=" + qseq;

}

From source file:egovframework.example.sample.web.EgovSampleController.java

@RequestMapping(value = "/cashPay.do", method = RequestMethod.POST)
public String cashPay( //? 
        HttpServletRequest request,// ww w  .ja va2 s .c o  m

        @RequestParam("dType") String o_type, //
        @RequestParam("pPricee") int o_price, // ?
        @RequestParam("o_name") String o_name, //??
        @RequestParam("o_phone") String o_phone, //? 
        @RequestParam("o_adress") String o_adress, //? 
        @RequestParam("o_orderMessage") String o_omessage, //
        @RequestParam("o_delivMessage") String o_dmessage, //
        @RequestParam("useCash") int useCash, // ?
        @RequestParam("cashSum") int cashSum, //? ?
        Model model, SessionStatus status) throws Exception {

    if (o_omessage.isEmpty()) {
        o_omessage = "";
    }
    if (o_dmessage.isEmpty()) {
        o_dmessage = "";
    }

    //System.out.println("1"+ o_type+"2"+ o_price+"3"+o_name +"4"+o_phone +"5"+ o_adress+"6"+ o_omessage+"7"+o_dmessage +"8"+useCash );
    ///// ?//
    Date orderDate = DateUtils.addDays(new Date(), 0);
    orderDate = DateUtils.addSeconds(orderDate, 0);
    Format sdf = FastDateFormat.getInstance("yyyyMMddhhmmss", Locale.getDefault());
    String orderDates = sdf.format(orderDate);

    String code = "";
    for (int i = 1; i <= 4; i++) {
        char ch = (char) ((Math.random() * 26) + 65);
        code = ch + code;
    }
    String orderCode = orderDates + code;
    //System.out.println("-"+orderCode);
    ////////////////////////////////////////////////////
    OrderResult or = new OrderResult(o_omessage, o_dmessage, o_name, o_phone, o_adress, orderCode, o_price,
            useCash);

    model.addAttribute("orderList", or);

    HttpSession hs = request.getSession();
    Account loginInfo = (Account) hs.getAttribute("userInfo");

    Account acc = new Account();
    model.addAttribute("myCash", loginInfo.getA_cash());
    //? ? (? -  ? +? ?)
    //       loginInfo.getA_cash() -   useCash +     cashSum        
    //int resultCash = (loginInfo.getA_cash() - useCash) +cashSum;
    int resultCash = (loginInfo.getA_cash() - useCash);
    acc.setA_cash(resultCash);
    acc.setA_id(loginInfo.getA_id());

    sampleService.useCash(acc);
    status.setComplete();
    System.out.println("? ");

    KartVO kart = new KartVO();
    kart.setK_id(loginInfo.getA_id());
    List<KartVO> kartList = sampleService.kartList(kart);

    String ol_name = kartList.get(0).getK_name();
    model.addAttribute("resultList", kartList);
    for (int i = 0; i < kartList.size(); i++) {
        int pSeq = kartList.get(i).getK_seq();
        int pEa = kartList.get(i).getK_ea();
        String pname = kartList.get(i).getK_name();
        //System.out.println(pname);

        // ?

        //TODO  ? ?(??   )
        Product product = new Product();
        product.setP_seq(pSeq);
        Product product2 = sampleService.selectProduct(product);
        int proEa = product2.getP_ea();
        int setEa = proEa - pEa;
        product.setP_ea(setEa);
        sampleService.updateEa(product);
        ///?

        OrderSeetVO orderVO = new OrderSeetVO(orderCode, loginInfo.getA_id(), o_type, o_name, o_phone, o_adress,
                o_omessage, o_dmessage, pname, pEa, o_price, pSeq);
        sampleService.orderSeet(orderVO);
        status.setComplete();
        System.out.println(i + " ? ?");
        if (i == kartList.size() - 1) {
            ol_name = ol_name + " " + i + "";
        }
    }

    //?
    OrderSeetListVO oslVO = new OrderSeetListVO(orderCode, loginInfo.getA_id(), " ", ol_name,
            o_omessage, o_dmessage, o_price);
    sampleService.orderSeetList(oslVO);
    System.out.println("? ?");
    //       

    sampleService.allDeleteKart(kart);
    status.setComplete();
    System.out.println(" ");

    ////? refresh  ?  /////////
    Account ac = new Account();
    ac.setA_id(loginInfo.getA_id());

    Account ac2 = sampleService.getAccount(ac);

    hs.setAttribute("userInfo", ac2);
    //      hs.setMaxInactiveInterval(1*60*60);

    //////////////////////////////////////////////   

    model.addAttribute("login", "loginOK.jsp");
    model.addAttribute("main", "orderResult.jsp");

    return "sample/home";

}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthorizationEndpoint.java

@RequestMapping(value = "/oauth/authorize")
public ModelAndView authorize(Map<String, Object> model, @RequestParam Map<String, String> parameters,
        SessionStatus sessionStatus, Principal principal, HttpServletRequest request) {

    ClientDetails client;/*from   w ww . j a v  a  2s  .co m*/
    String clientId;
    try {
        clientId = parameters.get("client_id");
        client = getClientServiceExtention().loadClientByClientId(clientId, IdentityZoneHolder.get().getId());
    } catch (NoSuchClientException x) {
        throw new InvalidClientException(x.getMessage());
    }

    // Pull out the authorization request first, using the OAuth2RequestFactory. All further logic should
    // query off of the authorization request instead of referring back to the parameters map. The contents of the
    // parameters map will be stored without change in the AuthorizationRequest object once it is created.
    AuthorizationRequest authorizationRequest;
    try {
        authorizationRequest = getOAuth2RequestFactory().createAuthorizationRequest(parameters);
    } catch (DisallowedIdpException x) {
        return switchIdp(model, client, clientId, request);
    }

    Set<String> responseTypes = authorizationRequest.getResponseTypes();
    String grantType = deriveGrantTypeFromResponseType(responseTypes);

    if (!supported_response_types.containsAll(responseTypes)) {
        throw new UnsupportedResponseTypeException("Unsupported response types: " + responseTypes);
    }

    if (authorizationRequest.getClientId() == null) {
        throw new InvalidClientException("A client id must be provided");
    }

    String resolvedRedirect = "";
    try {
        String redirectUriParameter = authorizationRequest.getRequestParameters().get(OAuth2Utils.REDIRECT_URI);
        try {
            resolvedRedirect = redirectResolver.resolveRedirect(redirectUriParameter, client);
        } catch (RedirectMismatchException rme) {
            throw new RedirectMismatchException(
                    "Invalid redirect " + redirectUriParameter + " did not match one of the registered values");
        }
        if (!StringUtils.hasText(resolvedRedirect)) {
            throw new RedirectMismatchException(
                    "A redirectUri must be either supplied or preconfigured in the ClientDetails");
        }

        boolean isAuthenticated = (principal instanceof Authentication)
                && ((Authentication) principal).isAuthenticated();

        if (!isAuthenticated) {
            throw new InsufficientAuthenticationException(
                    "User must be authenticated with Spring Security before authorization can be completed.");
        }

        if (!(responseTypes.size() > 0)) {
            return new ModelAndView(new RedirectView(
                    addQueryParameter(addQueryParameter(resolvedRedirect, "error", "invalid_request"),
                            "error_description", "Missing response_type in authorization request")));
        }

        authorizationRequest.setRedirectUri(resolvedRedirect);
        // We intentionally only validate the parameters requested by the client (ignoring any data that may have
        // been added to the request by the manager).
        oauth2RequestValidator.validateScope(authorizationRequest, client);

        // Some systems may allow for approval decisions to be remembered or approved by default. Check for
        // such logic here, and set the approved flag on the authorization request accordingly.
        authorizationRequest = userApprovalHandler.checkForPreApproval(authorizationRequest,
                (Authentication) principal);
        boolean approved = userApprovalHandler.isApproved(authorizationRequest, (Authentication) principal);
        authorizationRequest.setApproved(approved);

        // Validation is all done, so we can check for auto approval...
        if (authorizationRequest.isApproved()) {
            if (responseTypes.contains("token") || responseTypes.contains("id_token")) {
                return getImplicitGrantOrHybridResponse(authorizationRequest, (Authentication) principal,
                        grantType);
            }
            if (responseTypes.contains("code")) {
                return new ModelAndView(
                        getAuthorizationCodeResponse(authorizationRequest, (Authentication) principal));
            }
        }

        if ("none".equals(authorizationRequest.getRequestParameters().get("prompt"))) {
            return new ModelAndView(
                    new RedirectView(addFragmentComponent(resolvedRedirect, "error=interaction_required")));
        } else {
            // Place auth request into the model so that it is stored in the session
            // for approveOrDeny to use. That way we make sure that auth request comes from the session,
            // so any auth request parameters passed to approveOrDeny will be ignored and retrieved from the session.
            model.put(AUTHORIZATION_REQUEST, authorizationRequest);
            model.put("original_uri", UrlUtils.buildFullRequestUrl(request));
            model.put(ORIGINAL_AUTHORIZATION_REQUEST, unmodifiableMap(authorizationRequest));

            return getUserApprovalPageResponse(model, authorizationRequest, (Authentication) principal);
        }
    } catch (RedirectMismatchException e) {
        sessionStatus.setComplete();
        throw e;
    } catch (Exception e) {
        sessionStatus.setComplete();
        logger.debug("Unable to handle /oauth/authorize, internal error", e);
        if ("none".equals(authorizationRequest.getRequestParameters().get("prompt"))) {
            return new ModelAndView(
                    new RedirectView(addFragmentComponent(resolvedRedirect, "error=internal_server_error")));
        }

        throw e;
    }

}

From source file:egovframework.example.sample.web.EgovSampleController.java

@RequestMapping(value = "/deleteReX.do", method = RequestMethod.GET)
public void deleteReX(HttpServletRequest request, HttpServletResponse response, SessionStatus status)
        throws Exception {
    System.out.println("-----------------------------------------");
    //PlatformData oData = new PlatformData();
    int nErrorCode = 0;
    String strErrorMsg = "START";

    HttpPlatformRequest pReq = new HttpPlatformRequest(request);
    pReq.receiveData();//????  ??  

    PlatformData iData = pReq.getData();

    VariableList in_vl = iData.getVariableList();
    //int in_var2 = in_vl.getInt("sVal1");
    int in_var2 = Integer.parseInt(request.getParameter("seq"));
    System.out.println(" ? seq???????>>>>>>>>>>>" + in_var2);
    if (in_var2 != 0) {

        try {//ww w  . ja  v a 2  s  .  c o m

            SampleVO sampleVO = new SampleVO();
            sampleVO.setbSeq(in_var2);

            //?///////////////////////////////////////////////////////////////////////////////////////////////      

            SampleVO sam2 = new SampleVO();
            sam2 = sampleService.selectSample(sampleVO);

            SampleVO iVo = new SampleVO();
            SampleVO iVo2 = new SampleVO();
            List<SampleVO> imgList = (List<SampleVO>) sampleService.selectImgList(sam2);

            for (int i = 0; i < imgList.size(); i++) {

                int imgSeq = imgList.get(i).getiSeq();
                //   System.out.println("imgseq======"+imgSeq);
                iVo.setiSeq(imgSeq);
                System.out.println(" ?? ===" + imgList.get(i).getiSeq());
                //? ? ?? 
                iVo2 = sampleService.selectImg(iVo); //? 
                System.out.println(" +? ====" + iVo2.getiUrl());
                File f = new File(iVo2.getiUrl().toString()); //? 
                f.delete(); //? 

                sampleService.deleteImg(iVo);
                status.setComplete();

            }

            //////////////////////////////////////////////////////////////////////////////////////////////////   
            sampleService.deleteSample(sampleVO);
            status.setComplete();

            nErrorCode = 0;
            strErrorMsg = "SUCC";
        } catch (Exception e) {
            // VariableList? ? ? 
            nErrorCode = -1;
            strErrorMsg = e.getMessage();
            e.printStackTrace();
        }
    }
    // VariableList 
    //VariableList varList = oData.getVariableList();

    // VariableList? ? ? 
    //   varList.add("ErrorCode", nErrorCode);
    //   varList.add("ErrorMsg", strErrorMsg);
    //   varList.add("out_var", "1234"); // 

    //   return "forward:/egovSampleList.do";

    // HttpServletResponse ? HttpPlatformResponse ?
    //   HttpPlatformResponse pRes = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML, "UTF-8");
    //pRes.setData(oData);

    // ?? 
    //   pRes.sendData();
}

From source file:org.motechproject.server.omod.web.controller.DemoPatientController.java

@RequestMapping(method = RequestMethod.POST)
public String submitForm(@ModelAttribute("patient") WebPatient patient, Errors errors, ModelMap model,
        SessionStatus status, HttpSession session) {

    log.debug("Register Demo Patient");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "registrationMode",
            "motechmodule.registrationMode.required");
    if (patient.getRegistrationMode() == RegistrationMode.USE_PREPRINTED_ID) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "motechId", "motechmodule.motechId.required");
    }//  ww  w. ja  va  2  s . c  om
    if (patient.getMotechId() != null) {
        String motechIdString = patient.getMotechId().toString();
        boolean validId = false;
        MotechIdVerhoeffValidator validator = new MotechIdVerhoeffValidator();
        try {
            validId = validator.isValid(motechIdString);
        } catch (Exception e) {
        }
        if (!validId) {
            errors.rejectValue("motechId", "motechmodule.motechId.invalid");
        } else if (openmrsBean.getPatientByMotechId(motechIdString) != null) {
            errors.rejectValue("motechId", "motechmodule.motechId.nonunique");
        }
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "motechmodule.firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "motechmodule.lastName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "birthDate", "motechmodule.birthDate.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "birthDateEst", "motechmodule.birthDateEst.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sex", "motechmodule.sex.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "insured", "motechmodule.insured.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "region", "motechmodule.region.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "district", "motechmodule.district.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "communityId", "motechmodule.communityId.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address", "motechmodule.address.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "enroll", "motechmodule.enroll.required");

    if (Boolean.TRUE.equals(patient.getEnroll())) {
        if (!Boolean.TRUE.equals(patient.getConsent())) {
            errors.rejectValue("consent", "motechmodule.consent.required");
        }
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phoneType", "motechmodule.phoneType.required");
        if (patient.getPhoneType() == ContactNumberType.PERSONAL
                || patient.getPhoneType() == ContactNumberType.HOUSEHOLD) {
            ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phoneNumber",
                    "motechmodule.phoneNumber.required");
        }
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mediaType", "motechmodule.mediaType.required");
        if (patient.getPhoneType() == ContactNumberType.PUBLIC && patient.getMediaType() != null
                && patient.getMediaType() != MediaType.VOICE) {
            errors.rejectValue("mediaType", "motechmodule.mediaType.voice");
        }
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "language", "motechmodule.language.required");
        if (patient.getMediaType() == MediaType.TEXT && patient.getLanguage() != null
                && !patient.getLanguage().equals("en")) {
            errors.rejectValue("language", "motechmodule.language.english");
        }
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "interestReason",
                "motechmodule.interestReason.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "howLearned", "motechmodule.howLearned.required");
    }

    Community community = null;
    if (patient.getCommunityId() != null) {
        community = registrarBean.getCommunityById(patient.getCommunityId());
        if (community == null) {
            errors.rejectValue("communityId", "motechmodule.communityId.notexist");
        }
    }

    if (patient.getPhoneNumber() != null
            && !patient.getPhoneNumber().matches(MotechConstants.PHONE_REGEX_PATTERN)) {
        errors.rejectValue("phoneNumber", "motechmodule.phoneNumber.invalid");
    }

    validateTextLength(errors, "firstName", patient.getFirstName(), MotechConstants.MAX_STRING_LENGTH_OPENMRS);
    validateTextLength(errors, "middleName", patient.getMiddleName(),
            MotechConstants.MAX_STRING_LENGTH_OPENMRS);
    validateTextLength(errors, "lastName", patient.getLastName(), MotechConstants.MAX_STRING_LENGTH_OPENMRS);
    validateTextLength(errors, "prefName", patient.getPrefName(), MotechConstants.MAX_STRING_LENGTH_OPENMRS);
    validateTextLength(errors, "nhis", patient.getNhis(), MotechConstants.MAX_STRING_LENGTH_OPENMRS);
    validateTextLength(errors, "address", patient.getAddress(), MotechConstants.MAX_STRING_LENGTH_OPENMRS);
    validateTextLength(errors, "phoneNumber", patient.getPhoneNumber(),
            MotechConstants.MAX_STRING_LENGTH_OPENMRS);

    if (!errors.hasErrors()) {
        registrarBean.demoRegisterPatient(patient.getRegistrationMode(), patient.getMotechId(),
                patient.getFirstName(), patient.getMiddleName(), patient.getLastName(), patient.getPrefName(),
                patient.getBirthDate(), patient.getBirthDateEst(), patient.getSex(), patient.getInsured(),
                patient.getNhis(), patient.getNhisExpDate(), community, patient.getAddress(),
                patient.getPhoneNumber(), patient.getEnroll(), patient.getConsent(), patient.getPhoneType(),
                patient.getMediaType(), patient.getLanguage(), patient.getDayOfWeek(), patient.getTimeOfDay(),
                patient.getInterestReason(), patient.getHowLearned());

        model.addAttribute("successMsg", "motechmodule.Demo.Patient.register.success");

        status.setComplete();

        // Save the registration number for next step of demo
        session.setAttribute("demoLastMotechId", patient.getMotechId());

        return "redirect:/module/motechmodule/demo-success.htm";
    }

    JSONLocationSerializer.populateJavascriptMaps(model, patient.getPreferredLocation());

    return "/module/motechmodule/demo-patient";
}

From source file:org.openmrs.module.sdmxhddataexport.web.controller.dataelement.DataElementController.java

@RequestMapping(value = "/module/sdmxhddataexport/listDataElement.form", method = RequestMethod.POST)
public String deleteDataElement(@RequestParam(value = "ids", required = false) String[] ids,
        @RequestParam(value = "files", required = false) MultipartFile uploadItem, HttpServletRequest request,
        @RequestParam(value = "upload", required = false) String upload,
        @RequestParam(value = "IncludeQueries", required = false) String IncludeQueries, Object command,
        SessionStatus status) {
    String temp = "";
    HttpSession httpSession = request.getSession();
    Integer dataElementId = null;
    System.out.println(" done " + upload);
    if (upload != null) {
        System.out.println("1st part truly done");
        //FileUpload file = uploadItem;
        String fileName = "";
        if (uploadItem != null) {
            fileName = uploadItem.getOriginalFilename();
            System.out.println("2nd part truly done " + fileName);

            byte[] byteArray = null;
            try {
                byteArray = uploadItem.getBytes();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println("Bad file name");

                e.printStackTrace();/*from   w  w w .j  av  a 2  s.  c o m*/
            }

            String data = new String(byteArray);
            System.out.println("3rd part truly done " + data);
            XPath xpath = XPathFactory.newInstance().newXPath();
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
            DocumentBuilder builder = null;
            try {
                builder = domFactory.newDocumentBuilder();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();

            }
            Document doc = null;
            try {
                doc = builder.parse(uploadItem.getInputStream());
            } catch (SAXException e1) {
                httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                        "Unsupported Document type is uploaded ");

                //or we can use httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "sdmxhddataexport.UploadedFile.Wrong" );

                return "redirect:/module/sdmxhddataexport/listDataElement.form";

            } catch (IOException e1) {
                // TODO Auto-generated catch block
                httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "error in reading Document type  ");

                //e1.printStackTrace();

            }
            XPathExpression expr = null;
            XPathExpression exprDesc = null;
            XPathExpression exprQuery = null;
            try {
                expr = xpath.compile(
                        "//*[local-name(.)='CodeList' and @id='CL_DATAELEMENT']/*[local-name(.)='Code']");
                exprDesc = xpath.compile("//[local-name(.)='Description']");

                exprQuery = xpath.compile("//[local-name(.)='Query']");
            } catch (XPathExpressionException e) {
                httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Error parsing document ");

            }
            Object result = null;
            try {
                result = expr.evaluate(doc, XPathConstants.NODESET);
            } catch (XPathExpressionException e) {
                httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Error parsing document ");

                // e.printStackTrace();
            }
            NodeList nodes = (NodeList) result;
            ArrayList<DataElement> dataElements = new ArrayList<DataElement>();
            for (int i = 0; i < nodes.getLength(); i++) {
                boolean putItIn = false;
                DataElement de = new DataElement();
                System.out.println(nodes.item(i).getLocalName());

                NamedNodeMap nmp = nodes.item(i).getAttributes();
                System.out.println(nmp.getNamedItem("value").getNodeValue() + "  hellooo..");
                de.setCode(nmp.getNamedItem("value").getNodeValue());
                //Node tempNode = (Node)nodes.item(i); 
                NodeList innerNodeList = nodes.item(i).getChildNodes();
                System.out.println("length: " + innerNodeList.getLength());
                for (int j = 0; j < innerNodeList.getLength(); j++) {
                    if (innerNodeList.item(j).getLocalName() != null) {
                        System.out.println("hehe " + innerNodeList.item(j).getLocalName());
                        if (innerNodeList.item(j).getLocalName().equals(new String("Description"))) {
                            System.out.println("Description: " + innerNodeList.item(j).getTextContent());
                            de.setName(innerNodeList.item(j).getTextContent());

                            putItIn = true;
                        }

                        if (innerNodeList.item(j).getLocalName().equals(new String("Query"))
                                && IncludeQueries != null) {
                            System.out.println("Query: " + innerNodeList.item(j).getTextContent());
                            de.setSqlQuery(innerNodeList.item(j).getTextContent());
                        }
                    }
                }
                if (putItIn) {

                    boolean bool;
                    DataElementValidator valid = new DataElementValidator();
                    bool = valid.fileValidate(de);
                    if (bool == true)
                        dataElements.add(de);

                }
            }
            ListIterator<DataElement> li = dataElements.listIterator();
            DataElement de;
            while (li.hasNext()) {
                de = (DataElement) li.next();
                System.out.println("Element 1 = " + de.getName());
                de.setCreatedOn(new java.util.Date());
                de.setCreatedBy(Context.getAuthenticatedUser().getGivenName());
                SDMXHDDataExportService sDMXHDDataExportService = Context
                        .getService(SDMXHDDataExportService.class);

                sDMXHDDataExportService.saveDataElement(de);

            }

            status.setComplete();
        }

        return "redirect:/module/sdmxhddataexport/listDataElement.form";
    }
    try {
        SDMXHDDataExportService sDMXHDDataExportService = Context.getService(SDMXHDDataExportService.class);
        if (ids != null && ids.length > 0) {
            for (String sId : ids) {
                dataElementId = Integer.parseInt(sId);
                if (dataElementId != null && dataElementId > 0 && CollectionUtils.isEmpty(
                        sDMXHDDataExportService.listReportDataElement(null, dataElementId, null, 0, 1))) {
                    sDMXHDDataExportService
                            .deleteDataElement(sDMXHDDataExportService.getDataElementById(dataElementId));
                } else {
                    //temp += "We can't delete store="+store.getName()+" because that store is using please check <br/>";
                    temp = "This dataElement cannot be deleted as it is in use";
                }
            }
        }
    } catch (Exception e) {
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Can not delete dataElement ");
        log.error(e);
    }
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
            StringUtils.isBlank(temp) ? "sdmxhddataexport.dataElement.deleted" : temp);

    return "redirect:/module/sdmxhddataexport/listDataElement.form";
}

From source file:egovframework.example.sample.web.EgovSampleController.java

@RequestMapping(value = "/deleteQnaReX.do", method = RequestMethod.GET)
public void deleteQnaReX(HttpServletRequest request, HttpServletResponse response, SessionStatus status)
        throws Exception {
    System.out.println("-----------------------------------------");
    PlatformData oData = new PlatformData();
    int nErrorCode = 0;
    String strErrorMsg = "START";

    HttpPlatformRequest pReq = new HttpPlatformRequest(request);
    pReq.receiveData();//????  ??  

    PlatformData iData = pReq.getData();

    VariableList in_vl = iData.getVariableList();
    //int in_var2 = in_vl.getInt("sVal1");
    int in_var2 = Integer.parseInt(request.getParameter("seq"));
    System.out.println(" ? seq???????>>>>>>>>>>>" + in_var2);
    if (in_var2 != 0) {

        try {// ww w.j  a  v  a 2  s . com

            QnaVO qvo = new QnaVO();
            qvo.setQ_seq(in_var2);

            //SampleVO sampleVO = new SampleVO();
            //sampleVO.setbSeq(in_var2);

            //?///////////////////////////////////////////////////////////////////////////////////////////////      

            //sam2
            QnaVO qvo2 = sampleService.selectQna(qvo);

            qvo2.getQ_uuid();
            SampleVO sam2 = new SampleVO();
            sam2.setbUuid(qvo2.getQ_uuid());

            SampleVO iVo = new SampleVO();
            SampleVO iVo2 = new SampleVO();
            List<SampleVO> imgList = (List<SampleVO>) sampleService.selectImgList(sam2);

            for (int i = 0; i < imgList.size(); i++) {

                int imgSeq = imgList.get(i).getiSeq();
                //   System.out.println("imgseq======"+imgSeq);
                iVo.setiSeq(imgSeq);
                System.out.println(" ?? ===" + imgList.get(i).getiSeq());
                //? ? ?? 
                iVo2 = sampleService.selectImg(iVo); //? 
                System.out.println(" +? ====" + iVo2.getiUrl());
                File f = new File(iVo2.getiUrl().toString()); //? 
                f.delete(); //? 

                sampleService.deleteImg(iVo);
                status.setComplete();

            }

            //////////////////////////////////////////////////////////////////////////////////////////////////   
            sampleService.deleteQnaReply(qvo2);
            status.setComplete();

            nErrorCode = 0;
            strErrorMsg = "SUCC";
        } catch (Exception e) {
            // VariableList? ? ? 
            nErrorCode = -1;
            strErrorMsg = e.getMessage();
            e.printStackTrace();
        }
    }
    // VariableList 
    VariableList varList = oData.getVariableList();

    // VariableList? ? ? 
    varList.add("ErrorCode", nErrorCode);
    varList.add("ErrorMsg", strErrorMsg);
    //   varList.add("out_var", "1234"); // 

    //   return "forward:/egovSampleList.do";

    // HttpServletResponse ? HttpPlatformResponse ?
    HttpPlatformResponse pRes = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML, "UTF-8");
    pRes.setData(oData);

    // ?? 
    pRes.sendData();
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractUsersController.java

/**
 * @param form/*from  w  w w.java  2s. c o  m*/
 * @param result
 * @param map
 * @param status
 * @return
 */
@RequestMapping(value = { "/{userParam}/myprofile" }, method = RequestMethod.POST)
public String edit(@PathVariable String userParam, @Valid @ModelAttribute("user") UserForm form,
        BindingResult result, HttpServletRequest request, ModelMap map, SessionStatus status) {
    logger.debug("###Entering in edit(form,result,map,status) method @POST");
    com.citrix.cpbm.access.User user = form.getUser();

    MyProfileValidator validator = new MyProfileValidator();
    validator.validate(form, result);
    if (result.hasErrors()
            && !(result.getErrorCount() == 1 && result.getAllErrors().get(0).getCode().equals("Size")
                    && form.getUser().getUsername().equals("root"))) {
        displayErrors(result);
        // TODO to return the edit page with errors
        return "redirect:/portal/users/" + userParam + "/myprofile";
    }
    User logedInUser = this.getCurrentUser();
    if (isEmailBlacklisted(user.getEmail().toLowerCase())) {
        logger.info("Email Id : " + form.getUser().getEmail()
                + " rejected because it is not on the whitelist or part of the blacklist. Kindly contact support");
        result.rejectValue("user.email", "signup.emaildomain.blacklist.error");
        return edit(null, user.getObject().getUuid(), request, map);
    }
    if (form.getClearPassword() != null && !form.getClearPassword().isEmpty()) { // password reset
        if (form.getOldPassword() == null) {
            result.addError(new FieldError(result.getObjectName(), "oldPassword", null, false,
                    new String[] { "errors.password.required" }, null, null));
        } else if (!user.getObject().authenticate(form.getOldPassword())) {
            result.addError(new FieldError(result.getObjectName(), "oldPassword", null, false,
                    new String[] { "errors.password.invalid" }, null, null));
        } else {
            user.getObject().setClearPassword(form.getClearPassword());
        }
    }
    com.citrix.cpbm.access.User userClone = form.getUserClone();
    // TODO need to do Validation(Once fix this then remove @Ignore annotation against testUpdateUserFail from Test
    // Suit.
    form.setPhone(form.getPhone().replaceAll(PHONE_NUMBER_REGEX, "")); // removing all characters from phone number
    String oldPhone = userClone.getPhoneWithoutIsdCode() != null ? userClone.getPhoneWithoutIsdCode() : "";
    boolean phoneVerificationEnabled = false;
    if (!form.getPhone().equals(oldPhone.replaceAll(PHONE_NUMBER_REGEX, ""))
            || !form.getCountryCode().toString().equals(user.getCountryCode())) {

        if (connectorManagementService.getOssServiceInstancebycategory(ConnectorType.PHONE_VERIFICATION) != null
                && ((TelephoneVerificationService) connectorManagementService
                        .getOssServiceInstancebycategory(ConnectorType.PHONE_VERIFICATION)).isEnabled()) {
            phoneVerificationEnabled = true;
        }

        if (phoneVerificationEnabled && !userService.hasAuthority(logedInUser, "ROLE_ACCOUNT_CRUD")) {
            String generatedPhoneVerificationPin = (String) request.getSession()
                    .getAttribute("phoneVerificationPin");
            String actualPhoneNumber = (String) request.getSession().getAttribute("phoneNumber");
            if (form.getUserEnteredPhoneVerificationPin() == null
                    || !form.getUserEnteredPhoneVerificationPin().equals(generatedPhoneVerificationPin)
                    || !areDigitsInPhoneNosEqual(form.getPhone(), actualPhoneNumber)) {
                map.addAttribute("userEditError", "phoneVerfication.error");
                result.rejectValue("phone", "phoneVerfication.error");
                parseResult(result, map);
                return edit(null, user.getObject().getUuid(), request, map);
            }
        }
    }
    String phoneNo = form.getCountryCode().replaceAll(PHONE_NUMBER_REGEX, "")
            + COUNTRY_CODE_TO_PHONE_NUMBER_SEPERATOR + form.getPhone().replaceAll(PHONE_NUMBER_REGEX, "");
    // Set the phone number
    if (!phoneVerificationEnabled && StringUtils.isEmpty(form.getPhone())) {
        user.setPhone(null);
    } else {
        user.setPhone(phoneNo);
    }

    if ((user.getObject().getTenant().getState() == State.ACTIVE
            || user.getObject().getTenant().getState() == State.LOCKED
            || user.getObject().getTenant().getState() == State.SUSPENDED)
            && !user.getEmail().equals(userClone.getEmail())) {
        userAlertPreferencesService.createUserAlertPreference(user.getObject(), user.getEmail(),
                AlertType.USER_EMAIL);
        // set email so that it wont be updated in users table and other places
        user.setEmail(userClone.getEmail());
        user.setEmailVerified(true);
    }
    userService.update(user, result);
    form.setUser(user);
    map.addAttribute("user", form);
    setPage(map, Page.USER_PERSONAL_PROFILE);
    status.setComplete();
    logger.debug("###Exiting edit(form,result,map,status) method @POST");
    map.clear();
    return "redirect:/portal/users/" + user.getObject().getParam() + "/myprofile";
}

From source file:egovframework.example.sample.web.EgovSampleController.java

@RequestMapping(value = "/deleteOriX.do", method = RequestMethod.POST)
public void deleteOriX(HttpServletRequest request, HttpServletResponse response, SessionStatus status)
        throws Exception {
    System.out.println("-----------------------------------------");
    //PlatformData oData = new PlatformData();
    int nErrorCode = 0;
    String strErrorMsg = "START";

    HttpPlatformRequest pReq = new HttpPlatformRequest(request);
    pReq.receiveData();//????  ??  

    PlatformData iData = pReq.getData();

    VariableList in_vl = iData.getVariableList();
    int in_var2 = in_vl.getInt("sVal1");
    System.out.println("? --" + in_var2);

    if (in_var2 != 0) {

        try {/*ww  w  .j a v  a  2s .  c o m*/

            SampleVO sampleVO = new SampleVO();
            sampleVO.setbNum(in_var2);

            /////////////?(?  ? ? )///
            List<SampleVO> uuidList = (List<SampleVO>) sampleService.getUuid(sampleVO); //? ? uuid  
            //         for (int i = 0; i < uuidList.size(); i++) {
            //            
            //      //      System.out.println("uuid====="+uuidList.get(i).getbUuid());      //
            //         }

            SampleVO iVo = new SampleVO();
            SampleVO iVo2 = new SampleVO();
            for (int i = 0; i < uuidList.size(); i++) {

                String bUuid = uuidList.get(i).getbUuid().toString();
                //   iVo.setiUuid(bUuid);
                iVo.setbUuid(bUuid);

                //? ? ? 
                //iVo2 = sampleService.selectImgUuid(iVo); //b
                List<SampleVO> ivoList = (List<SampleVO>) sampleService.selectImgUuid(iVo); //uuid?  ??  
                //         System.out.println(ivoList.get(0).getiUrl());
                for (int j = 0; j < ivoList.size(); j++) { // ??   for
                    //      System.out.println(" +? ===="+ivoList.get(j).getiUrl());
                    File f = new File(ivoList.get(j).getiUrl().toString()); //? 
                    f.delete(); //? 

                    sampleService.deleteImgUuid(iVo);
                    status.setComplete();
                }

            }
            /////////////////////////

            sampleService.deleteSampleOri(sampleVO);
            status.setComplete();

            nErrorCode = 0;
            strErrorMsg = "SUCC";
        } catch (Exception e) {
            // VariableList? ? ? 
            nErrorCode = -1;
            strErrorMsg = e.getMessage();
            e.printStackTrace();
        }

    } //?

    nErrorCode = 0;
    strErrorMsg = "SUCC";

}