Example usage for java.lang Short equals

List of usage examples for java.lang Short equals

Introduction

In this page you can find the example usage for java.lang Short equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object to the specified object.

Usage

From source file:com.jd.survey.web.survey.PublicSurveyController.java

/**
 * Updates a survey page/*from  w  ww.jav  a2s .  com*/
 * @param surveyPage
 * @param backAction
 * @param proceedAction
 * @param bindingResult
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String updateSurveyPage(@Valid SurveyPage surveyPage,
        @RequestParam(value = "_back", required = false) String backAction,
        @RequestParam(value = "_proceed", required = false) String proceedAction, BindingResult bindingResult,
        Model uiModel, HttpServletRequest httpServletRequest) {
    try {

        Short order = surveyPage.getOrder();
        Survey survey = surveyService.survey_findById(surveyPage.getSurvey().getId());
        SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(survey.getTypeId());
        if (!surveyDefinition.getIsPublic()) {//survey definition not open to the public
            //attempt to access a private survey definition from a public open url 
            log.warn(SURVEY_NOT_PUBLIC_WARNING_MESSAGE + httpServletRequest.getPathInfo()
                    + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        //Attempt to access a survey from different IP Address
        if (!survey.getIpAddress().equalsIgnoreCase(httpServletRequest.getLocalAddr())) {
            log.warn(UNAUTHORIZED_ATTEMPT_TO_ACCESS_SURVEY_WARNING_MESSAGE + httpServletRequest.getPathInfo()
                    + FROM_IP_WARNING_MESSAGE + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }

        if (proceedAction != null) { //next button
            List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(),
                    messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()));
            surveyPage.setOrder(surveyPages.get(surveyPage.getOrder() - 1).getOrder());
            surveyPage.setTitle(surveyPages.get(surveyPage.getOrder() - 1).getTitle());
            surveyPage.setInstructions(surveyPages.get(surveyPage.getOrder() - 1).getInstructions());
            surveyPage.setSurvey(survey);
            surveyPage = surveyService.surveyPage_updateSettings(surveyPage);

            //populate the uploaded files
            MultipartHttpServletRequest multiPartRequest = (MultipartHttpServletRequest) httpServletRequest;
            Iterator<String> fileNames = multiPartRequest.getFileNames();
            while (fileNames.hasNext()) {
                String fileName = fileNames.next();
                Long questionId = Long.parseLong(fileName.toUpperCase().replace("FILE", ""));
                for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) {
                    if (questionAnswer.getQuestion().getId().equals(questionId)
                            && multiPartRequest.getFile(fileName).getBytes().length > 0) {
                        questionAnswer.setSurveyDocument(new SurveyDocument(survey.getId(), questionId,
                                multiPartRequest.getFile(fileName).getName(),
                                multiPartRequest.getFile(fileName).getContentType(),
                                multiPartRequest.getFile(fileName).getBytes()));
                    }
                }
            }

            Policy policy = Policy.getInstance(this.getClass().getResource(POLICY_FILE_LOCATION));
            AntiSamy as = new AntiSamy();
            for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) {
                if (questionAnswer.getQuestion().getType().getIsTextInput()) {
                    CleanResults cr = as.scan(questionAnswer.getStringAnswerValue(), policy);
                    questionAnswer.setStringAnswerValue(cr.getCleanHTML());
                }
            }

            GlobalSettings globalSettings = applicationSettingsService.getSettings();

            SurveyPageValidator validator = new SurveyPageValidator(
                    messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()),
                    globalSettings.getValidContentTypes(), globalSettings.getValidImageTypes(),
                    globalSettings.getMaximunFileSize(), globalSettings.getInvalidContentMessage(),
                    globalSettings.getInvalidFileSizeMessage());
            validator.validate(surveyPage, bindingResult);
            if (bindingResult.hasErrors()) {
                /*
                for (ObjectError err :bindingResult.getAllErrors()) {
                   log.info("getObjectName:" + err.getObjectName() + " getCode:" + err.getCode() + " getDefaultMessage:" + err.getDefaultMessage());
                   log.info("toString:" + err.toString());
                } 
                */
                uiModel.addAttribute("survey_base_path", "open");
                uiModel.addAttribute("survey", survey);
                uiModel.addAttribute("surveyDefinition",
                        surveySettingsService.surveyDefinition_findById(survey.getTypeId()));
                uiModel.addAttribute("surveyPage", surveyPage);
                uiModel.addAttribute("surveyPages", surveyPages);
                return "surveys/page";
            }

            surveyService.surveyPage_update(surveyPage,
                    messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()));
            //get the survey pages from the database again, prvious call updates visibility when there is  branching logic 
            surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(),
                    messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()));
            order = getNextPageOrder(surveyPages, order);
            if (order.equals((short) 0)) {
                //Submit page
                uiModel.asMap().clear();
                return "redirect:/open/submit/"
                        + encodeUrlPathSegment(surveyPage.getSurvey().getId().toString(), httpServletRequest);
            } else {
                //go to the next page
                uiModel.asMap().clear();
                return "redirect:/open/"
                        + encodeUrlPathSegment(surveyPage.getSurvey().getId().toString(), httpServletRequest)
                        + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest);
            }

        } else {//back button
            List<SurveyPage> surveyPages = surveyService.surveyPage_getAll(surveyPage.getSurvey().getId(),
                    messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()));
            order = getPreviousPageOrder(surveyPages, order);
            if (order.equals((short) 0)) {
                //Go to the surveyEntries page
                uiModel.asMap().clear();
                return "redirect:/open/"
                        + encodeUrlPathSegment(survey.getTypeId().toString(), httpServletRequest) + "?list";
            } else {
                //go to previous page
                uiModel.asMap().clear();
                return "redirect:/open/" + encodeUrlPathSegment(survey.getId().toString(), httpServletRequest)
                        + "/" + encodeUrlPathSegment(order.toString(), httpServletRequest);

            }
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }

}

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

public void updateCamera(String id, String standardNumber, String subType, String name, String organId,
        String manufacturerId, String location, String note, Short storeType, String localStorePlan,
        String centerStorePlan, String streamType, String parentId, String mssId, String crsId,
        Short channelNumber, String deviceModelId, String expand, String navigation, String stakeNumber,
        String owner, String civilCode, Double block, String certNum, Integer certifiable, Integer errCode,
        Long endTime, String rmsId, String storeStream) throws BusinessException {
    LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
    List<Camera> list = null;
    if (null != standardNumber) {
        // standardNumber??
        params.put("standardNumber", standardNumber);
        list = cameraDAO.findByPropertys(params);
        if (list.size() >= 1) {
            if (!list.get(0).getId().equals(id)) {
                throw new BusinessException(ErrorCode.UNIQUE_PROPERTY_DUPLICATE,
                        "standardNumber[" + standardNumber + "] is already exist !");
            }//  w  w w.jav  a  2 s .co  m
        }
    }
    // if (null != name) {
    // // name??
    // params.clear();
    // params.put("name", name);
    // list = cameraDAO.findByPropertys(params);
    // if (list.size() >= 1) {
    // if (!list.get(0).getId().equals(id)) {
    // throw new BusinessException(ErrorCode.NAME_EXIST, "name["
    // + name + "] is already exist !");
    // }
    // }
    // }
    // ?????
    params.clear();
    params.put("channelNumber", channelNumber);
    params.put("parent.id", parentId);
    list = cameraDAO.findByPropertys(params);
    if (list.size() >= 1) {
        if (!id.equals(list.get(0).getId())) {
            throw new BusinessException(ErrorCode.CHANNEL_NUMBER_EXIST,
                    "channelId[" + channelNumber + "] is already exist !");
        }
    }

    // ?
    boolean isUpdateCrs = false;

    Camera camera = cameraDAO.findById(id);
    if (null != channelNumber) {
        camera.setChannelNumber(channelNumber);
    }
    if (null != location) {
        camera.setLocation(location);
    }
    if (null != name) {
        camera.setName(name);
    }
    if (null != note) {
        camera.setNote(note);
    }
    if (StringUtils.isNotBlank(standardNumber)) {
        syncSN(camera.getStandardNumber(), standardNumber, TypeDefinition.RESOURCE_TYPE_CAMERA);
        camera.setStandardNumber(standardNumber);
    }
    if (null != subType) {
        camera.setSubType(subType);
    }
    if (null != crsId) {
        if (!crsId.equals(camera.getCrs() != null ? camera.getCrs().getId() : "")) {
            isUpdateCrs = true;
        }
        camera.setCrs(StringUtils.isNotBlank(crsId) ? crsDAO.findById(crsId) : null);
    }
    if (null != rmsId) {
        camera.setRms(StringUtils.isNotBlank(rmsId) ? rmsDAO.findById(rmsId) : null);
    }
    if (StringUtils.isNotBlank(manufacturerId)) {
        camera.setManufacturer(manufacturerDAO.findById(manufacturerId));
    }
    if (StringUtils.isNotBlank(deviceModelId)) {
        camera.setDeviceModel(deviceModelDAO.findById(deviceModelId));
    } else {
        camera.setDeviceModel(null);
    }
    if (null != mssId) {
        camera.setMss(StringUtils.isNotBlank(mssId) ? mssDAO.findById(mssId) : null);
    }
    if (null != organId) {
        camera.setOrgan(organDAO.findById(organId));
    }
    if (null != parentId) {
        camera.setParent(dvrDAO.findById(parentId));
    }
    if (null != navigation) {
        camera.setNavigation(navigation);
    }
    if (null != stakeNumber) {
        camera.setStakeNumber(stakeNumber);
    }
    cameraDAO.update(camera);

    // property
    VideoDeviceProperty property = camera.getProperty();

    if (null != storeType) {
        // ??isUpdateCrs
        if (!storeType.equals(camera.getProperty().getStoreType())) {
            isUpdateCrs = true;
        }
        //
        if (storeType == 0) {
            if (null != localStorePlan) {
                property.setLocalStorePlan(localStorePlan);
            }
            property.setCenterStorePlan(null);
        } else if (storeType == 1) {
            if (StringUtils.isNotBlank(crsId)) {
                if (null != centerStorePlan) {
                    property.setCenterStorePlan(centerStorePlan);
                }
            } else {
                property.setCenterStorePlan(null);
            }
            property.setLocalStorePlan(null);
        } else if (storeType == 2) {
            if (StringUtils.isNotBlank(crsId)) {
                if (null != centerStorePlan) {
                    property.setCenterStorePlan(centerStorePlan);
                }
            } else {
                property.setCenterStorePlan(null);
            }
            if (null != localStorePlan) {
                property.setLocalStorePlan(localStorePlan);
            }
        }
    } else {
        // ??isUpdateCrs
        if (null != centerStorePlan) {
            if (!centerStorePlan.equals(camera.getProperty().getCenterStorePlan() != null
                    ? camera.getProperty().getCenterStorePlan()
                    : "")) {
                isUpdateCrs = true;
            }
            property.setCenterStorePlan(centerStorePlan);
        }
        if (null != localStorePlan) {
            if (!localStorePlan.equals(
                    camera.getProperty().getLocalStorePlan() != null ? camera.getProperty().getLocalStorePlan()
                            : "")) {
                isUpdateCrs = true;
            }
            property.setLocalStorePlan(localStorePlan);
        }
    }

    if (null != streamType) {
        property.setStreamType(streamType);
    }
    if (null != storeType) {
        property.setStoreType(storeType);
    }
    if (null != expand) {
        property.setExpand(expand);
    }
    if (null != owner) {
        property.setOwner(owner);
    }
    if (null != civilCode) {
        property.setCivilCode(civilCode);
    }
    if (null != block) {
        property.setBlock(block);
    }
    if (null != certNum) {
        property.setCertNum(certNum);
    }
    if (null != certifiable) {
        property.setCertifiable(certifiable);
    }
    if (null != errCode) {
        property.setErrCode(errCode);
    }
    if (null != endTime) {
        property.setEndTime(endTime);
    }
    if (null != storeStream) {
        if (!storeStream.equals(
                camera.getProperty().getStoreStream() != null ? camera.getProperty().getStoreStream() : "")) {
            isUpdateCrs = true;
        }
        property.setStoreStream(storeStream);
    }
    // 
    deviceUpdateTime = System.currentTimeMillis();

    // 
    if (isUpdateCrs) {
        deviceCrsUpdeateTime = System.currentTimeMillis();
    }
}