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.gallatinsystems.survey.dao.SurveyUtils.java
public static QuestionGroup copyQuestionGroup(QuestionGroup source, Long newSurveyId, Map<Long, Long> qMap) { final QuestionGroupDao qgDao = new QuestionGroupDao(); final QuestionGroup tmp = new QuestionGroup(); BeanUtils.copyProperties(source, tmp, Constants.EXCLUDED_PROPERTIES); tmp.setSurveyId(null); // reset parent SurveyId, it will get set by the // save action log.log(Level.INFO, "Copying `QuestionGroup` " + source.getKey().getId()); final QuestionGroup newQuestionGroup = qgDao.save(tmp, newSurveyId); log.log(Level.INFO, "New `QuestionGroup` ID: " + newQuestionGroup.getKey().getId()); final Queue queue = QueueFactory.getDefaultQueue(); final TaskOptions options = TaskOptions.Builder.withUrl("/app_worker/dataprocessor") .param(DataProcessorRequest.ACTION_PARAM, DataProcessorRequest.COPY_QUESTION_GROUP) .param(DataProcessorRequest.QUESTION_GROUP_ID_PARAM, String.valueOf(newQuestionGroup.getKey().getId())) .param(DataProcessorRequest.SOURCE_PARAM, String.valueOf(source.getKey().getId())); queue.add(options);//from w ww . j a v a2s . co m return newQuestionGroup; }
From source file:org.syncope.core.rest.data.ConnInstanceDataBinder.java
public ConnInstance getConnInstance(final ConnInstanceTO connectorInstanceTO) throws SyncopeClientCompositeErrorException { SyncopeClientCompositeErrorException compositeErrorException = new SyncopeClientCompositeErrorException( HttpStatus.BAD_REQUEST);/*w w w .j a va 2s . c om*/ SyncopeClientException requiredValuesMissing = new SyncopeClientException( SyncopeClientExceptionType.RequiredValuesMissing); if (connectorInstanceTO.getBundleName() == null) { requiredValuesMissing.addElement("bundlename"); } if (connectorInstanceTO.getVersion() == null) { requiredValuesMissing.addElement("bundleversion"); } if (connectorInstanceTO.getConnectorName() == null) { requiredValuesMissing.addElement("connectorname"); } if (connectorInstanceTO.getConfiguration() == null || connectorInstanceTO.getConfiguration().isEmpty()) { requiredValuesMissing.addElement("configuration"); } ConnInstance connectorInstance = new ConnInstance(); BeanUtils.copyProperties(connectorInstanceTO, connectorInstance, IGNORE_PROPERTIES); // Throw composite exception if there is at least one element set // in the composing exceptions if (!requiredValuesMissing.isEmpty()) { compositeErrorException.addException(requiredValuesMissing); } if (compositeErrorException.hasExceptions()) { throw compositeErrorException; } return connectorInstance; }
From source file:org.syncope.core.rest.data.DerivedSchemaDataBinder.java
public <T extends AbstractDerSchema> DerivedSchemaTO getDerivedSchemaTO(final T derivedSchema) { DerivedSchemaTO derivedSchemaTO = new DerivedSchemaTO(); BeanUtils.copyProperties(derivedSchema, derivedSchemaTO, ignoreDerivedSchemaProperties); return derivedSchemaTO; }
From source file:technology.tikal.ventas.model.envio.ofy.EnvioOfy.java
@Override public void update(Envio source) { BeanUtils.copyProperties(source, this, "owner"); }
From source file:sample.web.account.AccountController.java
@RequestMapping(value = "/edit", method = RequestMethod.GET) public String edit(Model model, @AuthenticationPrincipal User user) { Account account = accountService.getAccount(user.getUsername()); EditAccountForm accountForm = new EditAccountForm(); BeanUtils.copyProperties(account, accountForm, "password"); return modelAndViewForEdit(model, accountForm, user); }
From source file:org.syncope.core.rest.data.ReportDataBinder.java
public ReportExecTO getReportExecTO(final ReportExec execution) { ReportExecTO executionTO = new ReportExecTO(); executionTO.setId(execution.getId()); BeanUtils.copyProperties(execution, executionTO, IGNORE_REPORT_EXECUTION_PROPERTIES); if (execution.getId() != null) { executionTO.setId(execution.getId()); }//from ww w . j av a 2 s . c o m executionTO.setReport(execution.getReport().getId()); return executionTO; }
From source file:jahspotify.web.api.HistoryController.java
private jahspotify.web.media.TrackHistory toWebTrack(final TrackHistory next) { jahspotify.web.media.TrackHistory trackHistory = new jahspotify.web.media.TrackHistory(); trackHistory.setTrackLink(toWebLink(next.getTrackLink())); trackHistory.setQueue(toWebLink(next.getQueue())); BeanUtils.copyProperties(next, trackHistory, new String[] { "trackLink", "queue" }); return trackHistory; }
From source file:org.syncope.core.rest.data.SchemaDataBinder.java
public <T extends AbstractSchema> SchemaTO getSchemaTO(final T schema, final AttributableUtil attributableUtil) { SchemaTO schemaTO = new SchemaTO(); BeanUtils.copyProperties(schema, schemaTO, IGNORE_SCHEMA_PROPERTIES); return schemaTO; }
From source file:org.shept.persistence.provider.DaoUtils.java
/** * This deepCopy will copy all properties of the template model but ignore * the id. In case the id is a compound id the the resulting copy will get a * deepCopy of the id if the composite id is only partially filled * // w ww.j a v a2 s . c om * NOTE that the method will only create shallow copies except for component * properties which will be deep copied This means that collections and * associations will NOT be deep copied * * @param dao * @param entityModelTemplate * @return a copy of the entityModelTemplate */ public static Object deepCopyModel(DaoSupport dao, Object entityModelTemplate) { ClassMetadata modelMeta = getClassMetadata(dao, entityModelTemplate); if (null == modelMeta) { return null; } Object modelCopy = shallowCopyModel(dao, entityModelTemplate, false); // Ids of new models are either null or composite ids and will be copied // if new boolean isCopyId = isNewModel(dao, entityModelTemplate); Object idValue = modelMeta.getIdentifier(entityModelTemplate, EntityMode.POJO); if (null != idValue && isCopyId) { String idName = modelMeta.getIdentifierPropertyName(); Object idCopy = BeanUtils.instantiateClass(idValue.getClass()); BeanUtils.copyProperties(idValue, idCopy, new String[] { idName }); modelMeta.setIdentifier(modelCopy, (Serializable) idCopy, EntityMode.POJO); } String[] names = modelMeta.getPropertyNames(); Type[] types = modelMeta.getPropertyTypes(); for (int i = 0; i < modelMeta.getPropertyNames().length; i++) { if (types[i].isComponentType()) { String propName = names[i]; Object propValue = modelMeta.getPropertyValue(entityModelTemplate, propName, EntityMode.POJO); Object propCopy = shallowCopyModel(dao, propValue, true); modelMeta.setPropertyValue(modelCopy, propName, propCopy, EntityMode.POJO); } } return modelCopy; }
From source file:com.gallatinsystems.survey.dao.SurveyUtils.java
public static Question copyQuestion(Question source, Long newQuestionGroupId, Integer order, Long newSurveyId) { final QuestionDao qDao = new QuestionDao(); final QuestionOptionDao qoDao = new QuestionOptionDao(); final Question tmp = new Question(); final String[] questionExcludedProps = { "questionOptionMap", "questionHelpMediaMap", "scoringRules", "translationMap", "order", "questionId" }; final String[] allExcludedProps = (String[]) ArrayUtils.addAll(questionExcludedProps, Constants.EXCLUDED_PROPERTIES); BeanUtils.copyProperties(source, tmp, allExcludedProps); tmp.setOrder(order);//from ww w.j ava 2s. c o m if (source.getQuestionId() != null) { tmp.setQuestionId(source.getQuestionId() + "_copy"); } log.log(Level.INFO, "Copying `Question` " + source.getKey().getId()); final Question newQuestion = qDao.save(tmp, newQuestionGroupId); log.log(Level.INFO, "New `Question` ID: " + newQuestion.getKey().getId()); log.log(Level.INFO, "Copying question translations"); SurveyUtils.copyTranslation(source.getKey().getId(), newQuestion.getKey().getId(), newSurveyId, newQuestionGroupId, ParentType.QUESTION_NAME, ParentType.QUESTION_DESC, ParentType.QUESTION_TEXT, ParentType.QUESTION_TIP); if (!Question.Type.OPTION.equals(newQuestion.getType())) { // Nothing more to do return newQuestion; } final TreeMap<Integer, QuestionOption> options = qoDao.listOptionByQuestion(source.getKey().getId()); if (options == null) { return newQuestion; } log.log(Level.INFO, "Copying " + options.values().size() + " `QuestionOption`"); // Copying Question Options for (QuestionOption qo : options.values()) { SurveyUtils.copyQuestionOption(qo, newQuestion.getKey().getId(), newSurveyId, newQuestionGroupId); } return newQuestion; }