Java Code Examples for org.apache.commons.beanutils.PropertyUtils.copyProperties()

The following are Jave code examples for showing how to use copyProperties() of the org.apache.commons.beanutils.PropertyUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: AnswerDTO.java   View Source Code Vote up 6 votes
public AnswerDTO(SurveyQuestion question) {
try {
    PropertyUtils.copyProperties(this, question);
} catch (Exception e) {
    logger.error("Error occurs during creating AnswerDTO");
}

// clone options
Set<SurveyOption> optList = question.getOptions();
if (optList != null) {
    SortedSet<SurveyOption> newOptions = new TreeSet<SurveyOption>(new SurveyOptionComparator());
    for (SurveyOption option : optList) {
	SurveyOption newOption = (SurveyOption) option.clone();
	// clone does not copy the UID, here copy it back
	newOption.setUid(option.getUid());
	newOptions.add(newOption);
    }
    this.setOptions(newOptions);
}

String desc = this.getDescription();
desc = desc.replaceAll("<(.|\n)*?>", "");
this.setShortTitle(StringUtils.abbreviate(desc, SHORT_TITLE_LENGTH));

   }
 
Example 2
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, AssessmentConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
AssessmentForm existForm = (AssessmentForm) sessionMap.get(AssessmentConstants.ATTR_ASSESSMENT_FORM);

AssessmentForm assessmentForm = (AssessmentForm) form;
try {
    PropertyUtils.copyProperties(assessmentForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(AssessmentConstants.SUCCESS);
   }
 
Example 3
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, PeerreviewConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
PeerreviewForm existForm = (PeerreviewForm) sessionMap.get(PeerreviewConstants.ATTR_PEERREVIEW_FORM);

PeerreviewForm peerreviewForm = (PeerreviewForm) 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 mapping.findForward(PeerreviewConstants.SUCCESS);
   }
 
Example 4
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
CommonCartridgeForm existForm = (CommonCartridgeForm) sessionMap
	.get(CommonCartridgeConstants.ATTR_RESOURCE_FORM);

CommonCartridgeForm commonCartridgeForm = (CommonCartridgeForm) form;
try {
    PropertyUtils.copyProperties(commonCartridgeForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(CommonCartridgeConstants.SUCCESS);
   }
 
Example 5
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) 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);

DokumaranForm dokumaranForm = (DokumaranForm) form;
try {
    PropertyUtils.copyProperties(dokumaranForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(DokumaranConstants.SUCCESS);
   }
 
Example 6
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    * 
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   protected ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) 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);

DacoForm dacoForm = (DacoForm) form;
try {
    PropertyUtils.copyProperties(dacoForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(DacoConstants.SUCCESS);
   }
 
Example 7
Project: weibo   File: UserServiceImpl.java   View Source Code Vote up 6 votes
public void register(UserToken userToken) throws Exception {

		// 检查用户名和邮箱
		this.chickUserNameExist(userToken.getUsername());
		this.chickEmailExist(userToken.getEmail());
		
		// 判定密码相同与否
		if(!(userToken.getPassword().equals(userToken.getRpassword()))){
			throw new WeiboException("两次密码不一致");
		}
		
		// 整理数据,插入数据库
		User user = new User();
		PropertyUtils.copyProperties(user, userToken);
		user.setWeibo(0);
		user.setFollow(0);
		user.setFollower(0);
		user.setDeleted((byte) 0);
		user.setStatus(DC.STATUS_NORMAL);
		user.setPassword(MD5.getMD5(user.getPassword()));
		userMapper.insertSelective(user);
	}
 
Example 8
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) 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);

ScratchieForm scratchieForm = (ScratchieForm) form;
try {
    PropertyUtils.copyProperties(scratchieForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(ScratchieConstants.SUCCESS);
   }
 
Example 9
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, SpreadsheetConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
SpreadsheetForm existForm = (SpreadsheetForm) sessionMap.get(SpreadsheetConstants.ATTR_RESOURCE_FORM);

SpreadsheetForm spreadsheetForm = (SpreadsheetForm) form;
try {
    PropertyUtils.copyProperties(spreadsheetForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(SpreadsheetConstants.SUCCESS);
   }
 
Example 10
Project: lams   File: AuthoringAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) 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);

TaskListForm taskListForm = (TaskListForm) form;
try {
    PropertyUtils.copyProperties(taskListForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(TaskListConstants.SUCCESS);
   }
 
Example 11
Project: lams   File: AuthoringTaskListConditionAction.java   View Source Code Vote up 6 votes
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward showConditions(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) 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);

TaskListForm taskListForm = (TaskListForm) form;
try {
    PropertyUtils.copyProperties(taskListForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

return mapping.findForward(TaskListConstants.SUCCESS);
   }
 
Example 12
Project: linkbinder   File: DummyMenuPage.java   View Source Code Vote up 6 votes
public void execute() throws ServiceAbortException {
    ProjectUser pu = (ProjectUser) page.getUsers().getRowData();

    for (Project p : page.projects) {
        if (p.getProjectId().equals(pu.getProjectId())) {
            page.viewHelper.setSessionValue(Constants.KEY_PROJECT, p);
        }
    }
    page.viewHelper.setSessionValue(Constants.KEY_PROJECT_USER, pu);

    User login = page.getCurrentUser();
    try {
        PropertyUtils.copyProperties(login, pu.getUser());
    } catch (Exception e) {
        throw new ApplicationFatalRuntimeException(e);
    }
}
 
Example 13
Project: linkbinder   File: DummyMenuPage.java   View Source Code Vote up 6 votes
public void execute() throws ServiceAbortException {
    ProjectUser pu = (ProjectUser) page.getUsers().getRowData();

    for (Project p : page.projects) {
        if (p.getProjectId().equals(pu.getProjectId())) {
            page.viewHelper.setSessionValue(Constants.KEY_PROJECT, p);
        }
    }
    page.viewHelper.setSessionValue(Constants.KEY_PROJECT_USER, pu);

    User login = page.getCurrentUser();
    try {
        PropertyUtils.copyProperties(login, pu.getUser());
    } catch (Exception e) {
        throw new ApplicationFatalRuntimeException(e);
    }
}
 
Example 14
Project: linkbinder   File: AbstractCorresponSetupStrategyTestCase.java   View Source Code Vote up 6 votes
@Mock
public Correspon find(Long id) throws ServiceAbortException {
    if (EX_FIND_BY_ID != null) {
        throw EX_FIND_BY_ID;
    }
    Correspon result = new Correspon();
    Correspon ret;
    if (RET_FIND != null) {
        ret = RET_FIND;
    } else {
        ret = RET_CORRESPON_MAP.get(id);
    }
    try {
        PropertyUtils.copyProperties(result, ret);
    } catch (Exception e) {
        e.printStackTrace();
        throw new AssertionFailedError(e.getMessage());
    }
    return result;
}
 
Example 15
Project: linkbinder   File: CopiedAttachmentInfo.java   View Source Code Vote up 6 votes
@Override
public Attachment toAttachment() throws ServiceAbortException {
    Attachment a = new Attachment();
    try {
        PropertyUtils.copyProperties(a, this.attachment);
    } catch (Exception e) {
        throw new ApplicationFatalRuntimeException(e);
    }
    a.setMode(UpdateMode.NEW);
    if (a.getContent() == null) {
        a.setContent(getContent());
        a.setSourcePath(getSourcePath());
    }

    return a;
}
 
Example 16
Project: automat   File: InstanceUtil.java   View Source Code Vote up 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 17
Project: mumu   File: InstanceUtil.java   View Source Code Vote up 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 18
Project: JAVA-   File: InstanceUtil.java   View Source Code Vote up 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 19
Project: bird-java   File: InstanceHelper.java   View Source Code Vote up 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 20
Project: iBase4J   File: InstanceUtil.java   View Source Code Vote up 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 21
Project: weixin-boot   File: TestPropertyUtils.java   View Source Code Vote up 5 votes
/**
 * Method Name:	main<br/>
 * Description:			[description]
 * @author				guhanjie
 * @time					2016年9月4日 下午12:33:35
 * @param args 
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 */
public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    final User user1 = new User();
    System.out.println(JSON.toJSONString(user1));
    User user2 = new User();
    user2.setCity("jfds");
    user2.setId(12421);
    user2.setNickname("sdfsdf");
    PropertyUtils.copyProperties(user1, user2);
    //BeanUtils.copyProperties(user1, user2);
    System.out.println(JSON.toJSONString(user1));
}
 
Example 22
Project: melon   File: InstanceUtil.java   View Source Code Vote up 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 23
Project: linkbinder   File: DummyMenuPage.java   View Source Code Vote up 5 votes
public void execute() throws ServiceAbortException {
    ProjectUser pu = (ProjectUser) page.getUsers().getRowData();
    User login = page.getCurrentUser();
    try {
        PropertyUtils.copyProperties(login, pu.getUser());
    } catch (Exception e) {
        throw new ApplicationFatalRuntimeException(e);
    }
}
 
Example 24
Project: linkbinder   File: CorresponSaveServiceImpl.java   View Source Code Vote up 5 votes
/**
 * プロパティコピーをしたコレポン文書オブジェクトを作成する.
 *
 * @param correspon
 *            コレポン文書情報
 * @return correspon
 *            コレポン文書情報
 */
private Correspon copyCorresponProperties(Correspon correspon) {
    Correspon clone = new Correspon();
    try {
        PropertyUtils.copyProperties(clone, correspon);
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new ApplicationFatalRuntimeException(e);
    }
    return clone;
}
 
Example 25
Project: linkbinder   File: CorresponTest.java   View Source Code Vote up 5 votes
@Test
public void testProperties() throws Exception {
    Correspon expected = new Correspon();
    initProperties(expected);
    PropertyUtils.copyProperties(correspon, expected);

    assertEquals(expected.toString(), correspon.toString());
}
 
Example 26
Project: linkbinder   File: CopyPropertiesTest.java   View Source Code Vote up 5 votes
@Test
public void testPropertyUtilsCopyProperties() throws Exception {

    Map<String, Object> values = new HashMap<String, Object>();
    values.put("id", Long.valueOf(10));
    values.put("name", "test");
    List<CorresponGroup> groups = new ArrayList<CorresponGroup>();
    CorresponGroup g = new CorresponGroup();
    g.setId(1L);
    g.setName("g1");
    groups.add(g);

    g = new CorresponGroup();
    g.setId(2L);
    g.setName("g2");
    groups.add(g);

    values.put("groups", groups);

    Dto dto = new Dto();

    PropertyUtils.copyProperties(dto, values);

    assertEquals(Long.valueOf(10L), dto.getId());
    assertEquals("test", dto.getName());

    List<CorresponGroup> actual = dto.getGroups();
    assertNotNull(actual);
    assertEquals(groups.size(), actual.size());
    assertEquals(groups.get(0).getId(), actual.get(0).getId());
    assertEquals(groups.get(0).getName(), actual.get(0).getName());

}
 
Example 27
Project: lams   File: AuthoringAction.java   View Source Code Vote up 4 votes
/**
    * This method will persist all inforamtion in this authoring page, include
    * all peerreview item, information etc.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
PeerreviewForm peerreviewForm = (PeerreviewForm) form;

// get back sessionMAP
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(peerreviewForm.getSessionMapID());

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

Peerreview peerreview = peerreviewForm.getPeerreview();
IPeerreviewService service = getPeerreviewService();

// **********************************Get Peerreview PO*********************
Peerreview peerreviewPO = service.getPeerreviewByContentId(peerreviewForm.getPeerreview().getContentId());
if (peerreviewPO == null) {
    // new Peerreview, create it
    peerreviewPO = peerreview;
    peerreviewPO.setCreated(new Timestamp(new Date().getTime()));
    peerreviewPO.setUpdated(new Timestamp(new Date().getTime()));
    
} else {
    Long uid = peerreviewPO.getUid();
    PropertyUtils.copyProperties(peerreviewPO, peerreview);
    // get back UID
    peerreviewPO.setUid(uid);
	
    // if it's a teacher - change define later status
    if (mode.isTeacher()) {
	peerreviewPO.setDefineLater(false);
    }
    
    peerreviewPO.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);
PeerreviewUser peerreviewUser = service.getUserByIDAndContent(new Long(user.getUserID().intValue()),
	peerreviewForm.getPeerreview().getContentId());
if (peerreviewUser == null) {
    peerreviewUser = new PeerreviewUser(user, peerreviewPO);
}

peerreviewPO.setCreatedBy(peerreviewUser);

// finally persist peerreviewPO
service.saveOrUpdatePeerreview(peerreviewPO);

// ************************* Handle rating criterias *******************
Long contentId = peerreview.getContentId();
List<RatingCriteria> oldCriterias = (List<RatingCriteria>) sessionMap.get(AttributeNames.ATTR_RATING_CRITERIAS);
service.saveRatingCriterias(request, oldCriterias, contentId);

peerreviewForm.setPeerreview(peerreviewPO);

request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE);
return mapping.findForward(PeerreviewConstants.SUCCESS);
   }
 
Example 28
Project: lams   File: AuthoringAction.java   View Source Code Vote up 4 votes
/**
    * This method will persist all inforamtion in this authoring page, include
    * all dokumaran item, information etc.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
DokumaranForm dokumaranForm = (DokumaranForm) form;

// get back sessionMAP
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(dokumaranForm.getSessionMapID());
ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
Dokumaran dokumaran = dokumaranForm.getDokumaran();
IDokumaranService service = getDokumaranService();

// **********************************Get Dokumaran PO*********************
Dokumaran dokumaranPO = service.getDokumaranByContentId(dokumaran.getContentId());
if (dokumaranPO == null) {
    // new Dokumaran, create it
    dokumaranPO = dokumaran;
    dokumaranPO.setCreated(new Timestamp(new Date().getTime()));
    dokumaranPO.setUpdated(new Timestamp(new Date().getTime()));
    
} else {
    Long uid = dokumaranPO.getUid();
    PropertyUtils.copyProperties(dokumaranPO, dokumaran);

    // copyProperties() above may result in "collection assigned to two objects in a session" exception
    // Below we remove reference to one of Assessment objects,
    // so maybe there will be just one object in session when save is done
    // If this fails, we may have to evict the object from session using DAO
    dokumaranForm.setDokumaran(null);
    dokumaran = null;
    // get back UID
    dokumaranPO.setUid(uid);

    // if it's a teacher - change define later status
    if (mode.isTeacher()) {
	dokumaranPO.setDefineLater(false);
    }
    dokumaranPO.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);
DokumaranUser dokumaranUser = service.getUserByIDAndContent(new Long(user.getUserID().intValue()),
	dokumaranPO.getContentId());
if (dokumaranUser == null) {
    dokumaranUser = new DokumaranUser(user, dokumaranPO);
}

dokumaranPO.setCreatedBy(dokumaranUser);

// ***************************** finally persist dokumaranPO again
service.saveOrUpdateDokumaran(dokumaranPO);

dokumaranForm.setDokumaran(dokumaranPO);

request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(DokumaranConstants.SUCCESS);
   }
 
Example 29
Project: lams   File: AuthoringAction.java   View Source Code Vote up 4 votes
/**
    * Update all content for submit tool except online/offline instruction files list.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws NoSuchMethodException
    * @throws InvocationTargetException
    * @throws Exception
    */
   public ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

AuthoringForm authForm = (AuthoringForm) form;
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(authForm.getSessionMapID());
ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.PARAM_MODE);

ActionMessages errors = validate(authForm, mapping, request);
if (!errors.isEmpty()) {
    saveErrors(request, errors);
    return mapping.getInputForward();
}

SubmitFilesContent content = getContent(form);

submitFilesService = getService();
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 = authForm.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(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE);
return mapping.findForward("success");
   }
 
Example 30
Project: lams   File: AuthoringAction.java   View Source Code Vote up 4 votes
/**
    * This method will persist all inforamtion in this authoring page, include all spreadsheet item, information etc.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
SpreadsheetForm spreadsheetForm = (SpreadsheetForm) (form);

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

Spreadsheet spreadsheet = spreadsheetForm.getSpreadsheet();
ISpreadsheetService service = getSpreadsheetService();

// **********************************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(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE);
return mapping.findForward(SpreadsheetConstants.SUCCESS);
   }
 
Example 31
Project: linkbinder   File: SavedAttachmentInfoTest.java   View Source Code Vote up 4 votes
public MockCorresponService(Attachment attachment, String content) throws Exception {
    Attachment a = new Attachment();
    PropertyUtils.copyProperties(a, attachment);
    this.attachment = a;
    this.content = content;
}
 
Example 32
Project: linkbinder   File: CopiedAttachmentInfoTest.java   View Source Code Vote up 4 votes
public MockCorresponService(Attachment attachment, String content) throws Exception {
    Attachment a = new Attachment();
    PropertyUtils.copyProperties(a, attachment);
    this.attachment = a;
    this.content = content;
}
 
Example 33
Project: nbone   File: BeanTest.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
	try {
		
		UserDto dto = UserDto.getUser("001");
		
		User user = new User();
		user.setPassword("9999");
		
		//BeanUtils.copyProperties(dto, user);
		
		//org.apache.commons.beanutils.BeanUtils.copyProperties(user, dto);
		
		PropertyUtils.copyProperties(user, dto);
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 34
Project: easycode   File: ImageTools.java   View Source Code Vote up 4 votes
/**
 * 
 * @param imgName	如果resizeImg对象的imgName有值,则依据imgName否则图片名用该参数
 * @param scale		是够是等比例缩放,如果resizeImg中的宽、高有一个没值就强制等比例缩放
 * @param enlarge   是否能够放大图片
 * @param resizeImg	期望缩放的图片信息
 * @return	Image[] 
 */
@Deprecated
public static Image[] resizeImage(BufferedImage img, String imgName, String baseRealPath, boolean scale, boolean enlarge,
		List<Image> resizeImg) throws Exception {
	if(img == null ||  resizeImg.size() == 0) 
       	throw new IllegalArgumentException("img or resizeImg is balnk in the method resizeImage of ImageTools.Class .");
	
	int w = img.getWidth(),
		h = img.getHeight();
	Image[] returnImgs = new Image[resizeImg.size()];
	for(int i = 0; i < resizeImg.size(); i++) {
		Image t = resizeImg.get(i);
		//如果Image没有初始化imgName则用该函数的imgName参数
		if(Strings.isBlank(t.getName()))
			t.setName(imgName);
		Integer width = t.getWidth(),
				height = t.getHeight();
		
		if(!enlarge && !(BIG_IMG_WIDTH.equals(width)
				&& BIG_IMG_HEIGHT.equals(height)
				//|| MOBILE_BIG_IMG_WIDTH.equals(width) 
				//&& MOBILE_BIG_IMG_HEIGHT.equals(height)
				) ) {
			if(width != null
					&& width > w) {
				throw new NonEnlargedException("原图片宽度不能小于" + width);
			}
			if(height != null
					&& height > h) {
				throw new NonEnlargedException("原图片高度不能小于" + height);
			}
		}
		int[] tmp = scaleSize(w, h, width, height, scale, enlarge);
		width = tmp[0];
		height = tmp[1];
		// 生成处理后的图片存储空间
		BufferedImage newBufferedImg = new BufferedImage(width,
				height, BufferedImage.TYPE_3BYTE_BGR);
		/*AffineTransform tsf = AffineTransform.getScaleInstance(
					(double)width/w, (double)height/h);
		// 根据原始图片生成处理后的图片
		AffineTransformOp ato = new AffineTransformOp(tsf, null);
		newImg = ato.filter(img, null);*/
		java.awt.Image imgObj = img.getScaledInstance(width, height, java.awt.Image.SCALE_DEFAULT);
		Graphics2D g = newBufferedImg.createGraphics();
		g.drawImage(imgObj, 0, 0, Color.WHITE, null);
		g.dispose();
		File newFile = new File(baseRealPath + Symbol.SLASH + t.getPath() + Symbol.SLASH + t.getName());
		if(!newFile.getParentFile().exists())
			newFile.getParentFile().mkdirs();
		ImageIO.write(newBufferedImg, FilenameUtils.getExtension(t.getName()).toLowerCase(), newFile);
		
		//设置图片的宽高
		Image sImg = new Image();
		PropertyUtils.copyProperties(sImg,t);
		//BeanUtils.copyProperties(sImg, t);	此方法会自动把Integer=null值转换成0
		sImg.setWidth(width);
		sImg.setHeight(height);
		returnImgs[i] = sImg;
	}
	return returnImgs;
}