List of usage examples for org.springframework.beans BeanUtils copyProperties
public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException
From source file:com.hybris.integration.controller.AccessTokenController.java
/** * Go tmall exchange access_token, and the authorization information persistence, then the correspondence between * appkey and integrationId told datahub * * @param request//ww w .j a v a 2 s .c o m * @param response * @param session * @return view */ @RequestMapping(value = "doOauth") public ModelAndView doOauth(HttpServletRequest request, HttpServletResponse response, HttpSession session) { addCustomHeader(response); String code = request.getParameter("code"); String state = request.getParameter("state"); AccessToken accessToken = (AccessToken) session.getAttribute("accessToken"); String sessionState = (String) session.getAttribute("state"); Map<String, Object> model = new HashMap<String, Object>(); ModelAndView modelAndView = new ModelAndView("oauthResult"); if (accessToken == null) { model.put("error", "Authorized accident, loss of data, please try again."); return modelAndView.addAllObjects(model); } LOGGER.trace("Execution authorization information , marketplaceStoreId=[" + accessToken.getMarketplaceStoreId() + "]."); AccessToken newAccessToken = null; if (StringUtils.isNotEmpty(code) && StringUtils.isNotEmpty(state) && state.equals(sessionState)) { try { // Go tmall exchange access_token newAccessToken = accessTokenService.get(code, accessToken.getAppkey(), accessToken.getSecret()); String[] ignoreProperties = new String[] { "appkey", "secret", "integrationId", "authorized", "marketplaceStoreId" }; BeanUtils.copyProperties(newAccessToken, accessToken, ignoreProperties); accessToken.setIntegrationId(accessToken.getMarketplaceStoreId()); // The authorization information persistence accessTokenService.save(accessToken); // Correspondence between AppKey and integrationId tell datahub dhAuthService.saveAuthInfo(accessToken); model.put("integrationId", accessToken.getIntegrationId()); } catch (Exception e) { model.put("error", e.getMessage()); return modelAndView.addAllObjects(model); } } else { String errorMsg = request.getParameter("error_description"); if (StringUtils.isEmpty(errorMsg)) { errorMsg = "Authorized failed,Please try again later."; } model.put("error", errorMsg); } return modelAndView.addAllObjects(model); }
From source file:it.jugpadova.controllers.JuggerEditController.java
@RequestMapping(method = RequestMethod.GET) protected String form(@RequestParam("jugger.user.username") String username, Model model) { if (!servicesBo.checkAuthorization(username)) { throw new ParancoeAccessDeniedException("Forbidden access to user identified by " + username); }/*from ww w .j a v a2 s .co m*/ EditJugger ej = new EditJugger(); Jugger jugger = juggerBo.searchByUsername(username); Jugger newJugger = new Jugger(); BeanUtils.copyProperties(jugger, newJugger, new String[] { "jug", "user" }); User newUser = new User(); BeanUtils.copyProperties(jugger.getUser(), newUser); newJugger.setUser(newUser); JUG newJug = new JUG(); BeanUtils.copyProperties(jugger.getJug(), newJug, new String[] { "country" }); newJugger.setJug(newJug); Country newCountry = new Country(); if (jugger.getJug().getCountry() != null) { BeanUtils.copyProperties(jugger.getJug().getCountry(), newCountry); } newJug.setCountry(newCountry); ej.setJugger(newJugger); ej.setRequireReliability(new RequireReliability()); ej.setReliable(servicesBo.isJuggerReliable(jugger.getReliability())); model.addAttribute(JUGGER_ATTRIBUTE, ej); return FORM_VIEW; }
From source file:org.parancoe.plugin.configuration.bo.ConfigurationManager.java
/** * Initialize a configuration, creating the elements (categories and properties) that doesn't * already exists.//from w ww . j a v a 2 s .c o m * * @param value The configuration collection to initialize. */ @Transactional @Override public void initializeConfiguration(ConfigurationCollection configurationCollection) { for (Category category : configurationCollection.getCategories()) { Category dbCategory = categoryDao.findByName(category.getName()); if (dbCategory == null) { log.info("Creating new configuration category: " + category.getName()); dbCategory = new Category(); BeanUtils.copyProperties(category, dbCategory, new String[] { "properties" }); categoryDao.create(dbCategory); } else { log.info("This category already exists: " + category.getName()); } for (Property property : category.getProperties()) { Property dbProperty = propertyDao.findByNameAndCategoryId(property.getName(), dbCategory.getId()); if (dbProperty == null) { log.info(" Creating new configuration property: {name=" + property.getName() + ", type=" + property.getType() + ", value=" + property.getValue() + "}"); dbProperty = new Property(); BeanUtils.copyProperties(property, dbProperty, new String[] { "category", "typedValue" }); dbProperty.setCategory(dbCategory); propertyDao.create(dbProperty); } else { log.info(" This property already exists: " + property.getName()); } } } }
From source file:com.github.lothar.security.acl.elasticsearch.repository.AclElasticsearchRepository.java
@Override public Page<T> search(SearchQuery query) { Assert.isInstanceOf(NativeSearchQuery.class, query, "NativeSearchQuery only are supported :("); NativeSearchQuery searchQuery = new NativeSearchQuery(and(query.getQuery(), aclFilter())); BeanUtils.copyProperties(query, searchQuery, "query"); return elasticsearchOperations.queryForPage(searchQuery, getEntityClass()); }
From source file:org.syncope.core.rest.data.ConnInstanceDataBinder.java
public ConnInstanceTO getConnInstanceTO(final ConnInstance connInstance) throws NotFoundException { ConnInstanceTO connInstanceTO = new ConnInstanceTO(); connInstanceTO.setId(connInstance.getId() != null ? connInstance.getId().longValue() : 0L); // retrieve the ConfigurationProperties. ConfigurationProperties properties = connBundleManager.getConfigurationProperties( connInstance.getBundleName(), connInstance.getVersion(), connInstance.getConnectorName()); BeanUtils.copyProperties(connInstance, connInstanceTO, IGNORE_PROPERTIES); ConnConfPropSchema connConfPropSchema; ConfigurationProperty configurationProperty; Map<String, ConnConfProperty> connInstanceToConfMap = connInstanceTO.getConfigurationMap(); for (String propName : properties.getPropertyNames()) { configurationProperty = properties.getProperty(propName); if (!connInstanceToConfMap.containsKey(propName)) { connConfPropSchema = new ConnConfPropSchema(); connConfPropSchema.setName(configurationProperty.getName()); connConfPropSchema.setDisplayName(configurationProperty.getDisplayName(propName)); connConfPropSchema.setHelpMessage(configurationProperty.getHelpMessage(propName)); connConfPropSchema.setRequired(configurationProperty.isRequired()); connConfPropSchema.setType(configurationProperty.getType().getName()); ConnConfProperty property = new ConnConfProperty(); property.setSchema(connConfPropSchema); connInstanceTO.addConfiguration(property); } else {/*from w w w . ja va2 s . c o m*/ connInstanceToConfMap.get(propName).getSchema() .setDisplayName(configurationProperty.getDisplayName(propName)); } } return connInstanceTO; }
From source file:org.obiba.mica.micaConfig.service.TaxonomyService.java
private Taxonomy copy(Taxonomy source) { Taxonomy target = new Taxonomy(); BeanUtils.copyProperties(source, target, "vocabularies"); if (source.hasVocabularies()) { source.getVocabularies().forEach(sourceVoc -> { Vocabulary targetVoc = new Vocabulary(); BeanUtils.copyProperties(sourceVoc, targetVoc, "terms"); if (sourceVoc.hasTerms()) { sourceVoc.getTerms().forEach(sourceTerm -> { Term targetTerm = new Term(); BeanUtils.copyProperties(sourceTerm, targetTerm); targetVoc.addTerm(targetTerm); });//from w ww .ja v a 2 s.c o m } target.addVocabulary(targetVoc); }); } return target; }
From source file:org.shept.persistence.provider.DaoUtils.java
/** * This Hibernate specific code will create shallow copies of the model * object//w w w. ja v a2 s .c o m * * @param dao * @param entityModelTemplate * @param includeId * true if the id is to be included * @return */ public static Object shallowCopyModel(DaoSupport dao, Object entityModelTemplate, boolean includeId) { ClassMetadata modelMeta = getClassMetadata(dao, entityModelTemplate); if (null == modelMeta) { return null; } Object modelCopy = BeanUtils.instantiateClass(entityModelTemplate.getClass()); if (!includeId) { String idName = modelMeta.getIdentifierPropertyName(); BeanUtils.copyProperties(entityModelTemplate, modelCopy, new String[] { idName }); } else { BeanUtils.copyProperties(entityModelTemplate, modelCopy); } return modelCopy; }
From source file:com.gallatinsystems.survey.dao.SurveyUtils.java
public static QuestionOption copyQuestionOption(QuestionOption source, Long newQuestionId, Long newSurveyId, Long newQuestionGroupId) { final QuestionOptionDao qDao = new QuestionOptionDao(); final QuestionOption tmp = new QuestionOption(); BeanUtils.copyProperties(source, tmp, Constants.EXCLUDED_PROPERTIES); tmp.setQuestionId(newQuestionId);/*from ww w . ja v a2 s . co m*/ log.log(Level.INFO, "Copying `QuestionOption` " + source.getKey().getId()); final QuestionOption newQuestionOption = qDao.save(tmp); log.log(Level.INFO, "New `QuestionOption` ID: " + newQuestionOption.getKey().getId()); log.log(Level.INFO, "Copying question option translations"); SurveyUtils.copyTranslation(source.getKey().getId(), newQuestionOption.getKey().getId(), newSurveyId, newQuestionGroupId, ParentType.QUESTION_OPTION); return newQuestionOption; }
From source file:org.syncope.core.rest.data.TaskDataBinder.java
public TaskExecTO getTaskExecTO(final TaskExec execution) { TaskExecTO executionTO = new TaskExecTO(); BeanUtils.copyProperties(execution, executionTO, IGNORE_TASK_EXECUTION_PROPERTIES); if (execution.getId() != null) { executionTO.setId(execution.getId()); }/*from w w w.j ava 2 s . c om*/ executionTO.setTask(execution.getTask().getId()); return executionTO; }
From source file:com.hybris.integration.controller.AccessTokenController.java
/** * @param request// ww w .j a v a2 s .c o m * @return view */ @RequestMapping(value = "refresh") public ModelAndView refresh(HttpServletRequest request) { String integrationId = request.getParameter("integrationId"); AccessToken oldToken = null; AccessToken newAccessToken = null; Map<String, Object> model = new HashMap<String, Object>(); ModelAndView modelAndView = new ModelAndView("oauthResult"); if (StringUtils.isEmpty(integrationId)) { model.put("error", "404:Missing parameters,refresh failure."); return modelAndView.addAllObjects(model); } try { oldToken = accessTokenService.get(integrationId); newAccessToken = accessTokenService.refresh(oldToken.getAppkey(), oldToken.getSecret(), oldToken.getRefreshToken()); String[] ignoreProperties = new String[] { "appkey", "secret", "integrationId", "authorized", "marketplaceStoreId" }; BeanUtils.copyProperties(newAccessToken, oldToken, ignoreProperties); // The authorization information persistence accessTokenService.save(oldToken); } catch (Exception e) { model.put("error", e.getMessage()); return modelAndView.addAllObjects(model); } model.put("integrationId", newAccessToken.getIntegrationId()); return modelAndView.addAllObjects(model); }