Java Code Examples for org.apache.commons.beanutils.PropertyUtils#copyProperties()
The following examples show how to use
org.apache.commons.beanutils.PropertyUtils#copyProperties() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShortMessageServiceImp.java From jivejdon with Apache License 2.0 | 6 votes |
/** * 查找消息 根据PageIterator结果进行查找 */ public FromShortMessage getFromShortMessage(Long msgId) { logger.debug("ShortMessageServiceImp getFromShortMessage"); ShortMessage smsg = this.factory.findShortMessage(msgId); Account loginaccount = this.sessionContextUtil.getLoginAccount(sessionContext); // check auth if (!smsg.getMessageFrom().equals(loginaccount.getUsername())) { logger.error("msgId=" + msgId + " is not this user's =" + loginaccount.getUserId()); return null; } FromShortMessage fromsmsg = new FromShortMessage(); try { PropertyUtils.copyProperties(fromsmsg, smsg); } catch (Exception e) { e.printStackTrace(); } return fromsmsg; }
Example 2
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. */ @RequestMapping("/init") private String initPage(@ModelAttribute("authoringForm") ScratchieForm authoringForm, HttpServletRequest request) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession() .getAttribute(sessionMapID); ScratchieForm existForm = (ScratchieForm) sessionMap.get(ScratchieConstants.ATTR_RESOURCE_FORM); try { PropertyUtils.copyProperties(authoringForm, existForm); } catch (Exception e) { throw new ServletException(e); } ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); authoringForm.setMode(mode.toString()); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); return "pages/authoring/authoring"; }
Example 3
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. */ @RequestMapping(path = "/init", method = RequestMethod.POST) public String initPage(@ModelAttribute ImageGalleryForm startForm, HttpServletRequest request) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID); SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession() .getAttribute(sessionMapID); ImageGalleryForm existForm = (ImageGalleryForm) sessionMap.get(ImageGalleryConstants.ATTR_IMAGE_GALLERY_FORM); try { PropertyUtils.copyProperties(startForm, existForm); } catch (Exception e) { throw new ServletException(e); } ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); request.setAttribute("imageGalleryForm", startForm); return "pages/authoring/authoring"; }
Example 4
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. * * @param mapping * @param form * @param request * @param response * @return * @throws ServletException */ @RequestMapping("/init") protected String initPage(@ModelAttribute("authoringForm") DacoForm authoringForm, HttpServletRequest request) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, DacoConstants.ATTR_SESSION_MAP_ID); SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession() .getAttribute(sessionMapID); DacoForm existForm = (DacoForm) sessionMap.get(DacoConstants.ATTR_DACO_FORM); try { PropertyUtils.copyProperties(authoringForm, existForm); } catch (Exception e) { throw new ServletException(e); } ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); authoringForm.setMode(mode.toString()); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); return "pages/authoring/authoring"; }
Example 5
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. * * @param mapping * @param form * @param request * @param response * @return * @throws ServletException */ @RequestMapping("/init") private String initPage(@ModelAttribute("authoringForm") DokumaranForm authoringForm, HttpServletRequest request) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, DokumaranConstants.ATTR_SESSION_MAP_ID); SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession() .getAttribute(sessionMapID); DokumaranForm existForm = (DokumaranForm) sessionMap.get(DokumaranConstants.ATTR_RESOURCE_FORM); try { PropertyUtils.copyProperties(authoringForm, existForm); } catch (Exception e) { throw new ServletException(e); } ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); authoringForm.setMode(mode.toString()); return "pages/authoring/authoring"; }
Example 6
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. */ @RequestMapping("/init") private String initPage(@ModelAttribute("startForm") ResourceForm startForm, HttpServletRequest request) throws ServletException { SessionMap<String, Object> sessionMap = getSessionMap(request); ResourceForm existForm = (ResourceForm) sessionMap.get(ResourceConstants.ATTR_RESOURCE_FORM); try { PropertyUtils.copyProperties(startForm, existForm); } catch (Exception e) { throw new ServletException(e); } ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); startForm.setMode(mode.toString()); request.setAttribute("authoringForm", startForm); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); return "pages/authoring/authoring"; }
Example 7
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. * * @throws ServletException */ @RequestMapping("/init") @SuppressWarnings("unchecked") public String initPage(@ModelAttribute PeerreviewForm peerreviewForm, HttpServletRequest request, HttpSession session) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, PeerreviewConstants.ATTR_SESSION_MAP_ID); SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) session.getAttribute(sessionMapID); PeerreviewForm existForm = (PeerreviewForm) sessionMap.get(PeerreviewConstants.ATTR_PEERREVIEW_FORM); try { PropertyUtils.copyProperties(peerreviewForm, existForm); } catch (Exception e) { throw new ServletException(e); } ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); return AUTHORING_PATH; }
Example 8
Source File: AuthoringTaskListConditionController.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Display same entire authoring page content from HttpSession variable. */ @RequestMapping("/showConditions") public String showConditions(@ModelAttribute TaskListForm taskListForm, HttpServletRequest request) throws ServletException { String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID); SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession() .getAttribute(sessionMapID); TaskListForm existForm = (TaskListForm) sessionMap.get(TaskListConstants.ATTR_TASKLIST_FORM); try { PropertyUtils.copyProperties(taskListForm, existForm); } catch (Exception e) { throw new ServletException(e); } return "pages/authoring/conditions"; }
Example 9
Source File: BeanUtils.java From disconf with Apache License 2.0 | 6 votes |
/** * 获得输入对象列表的镜象实例列表,要求参数类必需包含一个无参的public构造函数 * * @param sourceList * * @return * * @author ying * @since 1.0.0 */ @SuppressWarnings({"rawtypes", "unchecked"}) public static List getCloneList(List sourceList) { if (null == sourceList) { return null; } List targetList = new ArrayList(); for (int i = 0; i < sourceList.size(); i++) { Object target = null; Object source = sourceList.get(i); try { Constructor con = source.getClass().getConstructor(); target = con.newInstance(); PropertyUtils.copyProperties(target, source); } catch (Exception e) { logger.error("clone object exception object class:" + source.getClass(), e); } targetList.add(target); } return targetList; }
Example 10
Source File: BeanUtils.java From disconf with Apache License 2.0 | 6 votes |
/** * 获得输入对象的简单一层镜象实例,要求参数类必需包含一个无参的public构造函数 * * @param source * * @return * * @author guojichun * @since 1.0.0 */ @SuppressWarnings("rawtypes") private static Object getOneLayerClone(Object source) { if (null == source) { return null; } Object target = null; try { Constructor con = source.getClass().getConstructor(); target = con.newInstance(); // 把一个集合类中的数据拷贝到另一集合类中 PropertyUtils.copyProperties(target, source); } catch (Exception e) { logger.error("clone object exception object class:" + source.getClass(), e); } return target; }
Example 11
Source File: BeanUtils.java From disconf with Apache License 2.0 | 6 votes |
/** * 获得输入对象的简单一层镜象实例,要求参数类必需包含一个无参的public构造函数 * * @param source * * @return * * @author guojichun * @since 1.0.0 */ @SuppressWarnings("rawtypes") private static Object getOneLayerClone(Object source) { if (null == source) { return null; } Object target = null; try { Constructor con = source.getClass().getConstructor(); target = con.newInstance(); // 把一个集合类中的数据拷贝到另一集合类中 PropertyUtils.copyProperties(target, source); } catch (Exception e) { logger.error("clone object exception object class:" + source.getClass(), e); } return target; }
Example 12
Source File: KimCommonUtils.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
public static void copyProperties(Object targetToCopyTo, Object sourceToCopyFrom){ if(targetToCopyTo!=null && sourceToCopyFrom!=null) { try{ PropertyUtils.copyProperties(targetToCopyTo, sourceToCopyFrom); } catch(Exception ex){ throw new RuntimeException("Failed to copy from source object: "+sourceToCopyFrom.getClass()+" to target object: "+targetToCopyTo,ex); } } }
Example 13
Source File: InstanceUtil.java From mumu with Apache License 2.0 | 5 votes |
/** 实例化并复制属性 */ public static final <T> T to(Object orig, Class<T> clazz) { T bean = null; try { bean = clazz.newInstance(); PropertyUtils.copyProperties(bean, orig); } catch (Exception e) { } return bean; }
Example 14
Source File: AssessmentServiceImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Stores given AssessmentQuestion's answer. */ private AssessmentQuestionResult storeUserAnswer(AssessmentResult assessmentResult, QuestionDTO questionDto) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Assessment assessment = assessmentResult.getAssessment(); // get questionResult from DB instance of AssessmentResult AssessmentQuestionResult questionResult = null; for (AssessmentQuestionResult questionResultIter : assessmentResult.getQuestionResults()) { if (questionDto.getUid().equals(questionResultIter.getAssessmentQuestion().getUid())) { questionResult = questionResultIter; } } //if teacher modified question in monitor - update questionDto now if (assessment.isContentModifiedInMonitor(assessmentResult.getStartDate())) { AssessmentQuestion modifiedQuestion = assessmentQuestionDao.getByUid(questionDto.getUid()); QuestionDTO updatedQuestionDto = modifiedQuestion.getQuestionDTO(); PropertyUtils.copyProperties(questionDto, updatedQuestionDto); } // store question answer values questionResult.setAnswerBoolean(questionDto.getAnswerBoolean()); questionResult.setAnswerFloat(questionDto.getAnswerFloat()); questionResult.setAnswerString(questionDto.getAnswerString()); int j = 0; for (OptionDTO optionDto : questionDto.getOptionDtos()) { // find according optionAnswer AssessmentOptionAnswer optionAnswer = null; for (AssessmentOptionAnswer optionAnswerIter : questionResult.getOptionAnswers()) { if (optionDto.getUid().equals(optionAnswerIter.getOptionUid())) { optionAnswer = optionAnswerIter; } } // store option answer values optionAnswer.setAnswerBoolean(optionDto.getAnswerBoolean()); optionAnswer.setAnswerInt(optionDto.getAnswerInt()); if (questionDto.getType() == AssessmentConstants.QUESTION_TYPE_ORDERING) { optionAnswer.setAnswerInt(j++); } } // store confidence levels entered by the learner if (assessment.isEnableConfidenceLevels()) { questionResult.setConfidenceLevel(questionDto.getConfidenceLevel()); } return questionResult; }
Example 15
Source File: WebRuleBaseValues.java From rice with Educational Community License v2.0 | 4 votes |
/** * Loads the given rule into this WebRuleBaseValues. */ public void load(RuleBaseValues rule) throws Exception { PropertyUtils.copyProperties(this, rule); injectWebMembers(); }
Example 16
Source File: ShallowCopyBenchmark.java From java-tool with Apache License 2.0 | 4 votes |
@Test public void commonsPropertyUtils() throws Exception { PropertyUtils.copyProperties(target, source); }
Example 17
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Update all content for submit tool except online/offline instruction files list. */ @SuppressWarnings("unchecked") @RequestMapping(path = "/updateContent", method = RequestMethod.POST) public String updateContent(@ModelAttribute AuthoringForm authoringForm, HttpServletRequest request) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession() .getAttribute(authoringForm.getSessionMapID()); ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.PARAM_MODE); MultiValueMap<String, String> errorMap = validate(authoringForm, request); if (!errorMap.isEmpty()) { request.setAttribute("errorMap", errorMap); return "authoring/authoring"; } SubmitFilesContent content = getContent(authoringForm); SubmitFilesContent persistContent = submitFilesService.getSubmitFilesContent(content.getContentID()); if (persistContent == null) { // new content persistContent = content; content.setCreated(new Date()); } else { Long uid = persistContent.getContentID(); PropertyUtils.copyProperties(persistContent, content); persistContent.setContentID(uid); // if it is Teacher (from monitor) - change define later status if (mode.isTeacher()) { persistContent.setDefineLater(false); } } // *******************************Handle user******************* // get session from shared session. HttpSession ss = SessionManager.getSession(); // get back login user DTO UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); Long contentId = authoringForm.getToolContentID(); SubmitUser user = submitFilesService.getContentUser(contentId, userDto.getUserID()); if (user == null) { user = submitFilesService.createContentUser(userDto, contentId); } persistContent.setCreatedBy(user); submitFilesService.saveOrUpdateContent(persistContent); // to jump to common success page in lams_central request.setAttribute(CommonConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); return "authoring/authoring"; }
Example 18
Source File: AuthoringController.java From lams with GNU General Public License v2.0 | 4 votes |
/** * This method will persist all information in this authoring page, include all spreadsheet item, information etc. */ @RequestMapping(path = "/updateContent", method = RequestMethod.POST) public String updateContent(@ModelAttribute SpreadsheetForm spreadsheetForm, HttpServletRequest request) throws Exception { ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); Spreadsheet spreadsheet = spreadsheetForm.getSpreadsheet(); // **********************************Get Spreadsheet PO********************* Spreadsheet spreadsheetPO = service.getSpreadsheetByContentId(spreadsheetForm.getSpreadsheet().getContentId()); if (spreadsheetPO == null) { // new Spreadsheet, create it. spreadsheetPO = spreadsheet; spreadsheetPO.setCreated(new Timestamp(new Date().getTime())); spreadsheetPO.setUpdated(new Timestamp(new Date().getTime())); } else { Long uid = spreadsheetPO.getUid(); PropertyUtils.copyProperties(spreadsheetPO, spreadsheet); // get back UID spreadsheetPO.setUid(uid); // if it's a teacher - change define later status if (mode.isTeacher()) { spreadsheetPO.setDefineLater(false); } spreadsheetPO.setUpdated(new Timestamp(new Date().getTime())); } // *******************************Handle user******************* // try to get form system session HttpSession ss = SessionManager.getSession(); // get back login user DTO UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); SpreadsheetUser spreadsheetUser = service.getUserByIDAndContent(new Long(user.getUserID().intValue()), spreadsheetForm.getSpreadsheet().getContentId()); if (spreadsheetUser == null) { spreadsheetUser = new SpreadsheetUser(user, spreadsheetPO); } spreadsheetPO.setCreatedBy(spreadsheetUser); // finally persist spreadsheetPO again service.saveOrUpdateSpreadsheet(spreadsheetPO); spreadsheetForm.setSpreadsheet(spreadsheetPO); request.setAttribute(CommonConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); return "pages/authoring/authoring"; }
Example 19
Source File: WebRuleUtils.java From rice with Educational Community License v2.0 | 4 votes |
/** * Copies the existing rule onto the current document. This is used within the web-based rule GUI to make a * copy of a rule on the existing document. Essentially, this method makes a copy of the rule and all * delegates but preserves the document ID of the original rule. */ public static WebRuleBaseValues copyRuleOntoExistingDocument(WebRuleBaseValues rule) throws Exception { WebRuleBaseValues ruleCopy = new WebRuleBaseValues(); PropertyUtils.copyProperties(ruleCopy, rule); ruleCopy.setPreviousRuleId(null); ruleCopy.setCurrentInd(null); ruleCopy.setVersionNbr(null); List responsibilities = new ArrayList(); for (Iterator iter = ruleCopy.getRuleResponsibilities().iterator(); iter.hasNext();) { WebRuleResponsibility responsibility = (WebRuleResponsibility) iter.next(); WebRuleResponsibility responsibilityCopy = new WebRuleResponsibility(); PropertyUtils.copyProperties(responsibilityCopy, responsibility); responsibilityCopy.setResponsibilityId(null); responsibilityCopy.setId(null); List delegations = new ArrayList(); for (Iterator iterator = responsibilityCopy.getDelegationRules().iterator(); iterator.hasNext();) { RuleDelegationBo delegation = (RuleDelegationBo) iterator.next(); RuleDelegationBo delegationCopy = new RuleDelegationBo(); PropertyUtils.copyProperties(delegationCopy, delegation); delegationCopy.setDelegateRuleId(null); delegationCopy.setVersionNumber(null); delegationCopy.setRuleDelegationId(null); delegationCopy.setResponsibilityId(null); WebRuleBaseValues delegationRule = ((WebRuleBaseValues) delegation.getDelegationRule()); WebRuleBaseValues ruleDelegateCopy = new WebRuleBaseValues(); PropertyUtils.copyProperties(ruleDelegateCopy, delegationRule); ruleDelegateCopy.setPreviousRuleId(null); ruleDelegateCopy.setCurrentInd(null); ruleDelegateCopy.setVersionNbr(null); List delegateResps = new ArrayList(); for (Iterator iterator1 = ruleDelegateCopy.getRuleResponsibilities().iterator(); iterator1.hasNext();) { WebRuleResponsibility delegateResp = (WebRuleResponsibility) iterator1.next(); WebRuleResponsibility delegateRespCopy = new WebRuleResponsibility(); PropertyUtils.copyProperties(delegateRespCopy, delegateResp); delegateRespCopy.setResponsibilityId(null); delegateRespCopy.setId(null); delegateResps.add(delegateRespCopy); } ruleDelegateCopy.setRuleResponsibilities(delegateResps); delegationCopy.setDelegationRule(ruleDelegateCopy); delegations.add(delegationCopy); } //responsibilityCopy.setDelegationRules(delegations); responsibilities.add(responsibilityCopy); } ruleCopy.setRuleResponsibilities(responsibilities); return ruleCopy; }
Example 20
Source File: BeanUtil.java From boubei-tss with Apache License 2.0 | 3 votes |
/** * 对象属性复制. * * @param to * 目标拷贝对象 * @param from * 拷贝源 */ public static void copy(Object to, Object from) { try { PropertyUtils.copyProperties(to, from); } catch (Exception e) { throw new RuntimeException("拷贝时出错!", e); } }