Example usage for org.springframework.beans BeanUtils copyProperties

List of usage examples for org.springframework.beans BeanUtils copyProperties

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils copyProperties.

Prototype

public static void copyProperties(Object source, Object target, String... ignoreProperties)
        throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the given target bean, ignoring the given "ignoreProperties".

Usage

From source file:org.nekorp.workflow.desktop.servicio.bridge.DatosCobranzaBridge.java

@Override
public void unload(DatosCobranzaVB origen, DatosCobranza destino) {
    BeanUtils.copyProperties(origen, destino, "pagos");
    List<PagoCobranza> pagos = new LinkedList<>();
    for (PagoCobranzaVB x : origen.getPagos()) {
        PagoCobranza pago = new PagoCobranza();
        pagoCobranzaBridge.unload(x, pago);
        pagos.add(pago);//from  ww w  .  j av a  2s  .co  m
    }
    destino.setPagos(pagos);
}

From source file:org.syncope.core.policy.PolicyEvaluator.java

public <T extends AbstractPolicySpec> T evaluate(final Policy policy, final AbstractAttributable attributable) {

    T result = null;//www  . j a  v  a 2 s  . c  om

    if (policy != null) {
        AbstractAttr attribute;
        List<String> values;

        switch (policy.getType()) {
        case PASSWORD:
        case GLOBAL_PASSWORD:
            final PasswordPolicySpec pspec = policy.getSpecification();
            final PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();

            BeanUtils.copyProperties(pspec, passwordPolicy, new String[] { "schemasNotPermitted" });

            for (String schema : pspec.getSchemasNotPermitted()) {
                attribute = attributable.getAttribute(schema);
                if (attribute != null) {
                    values = attribute.getValuesAsStrings();
                    if (values != null && !values.isEmpty()) {
                        passwordPolicy.getWordsNotPermitted().add(values.get(0));
                    }
                }
            }

            // Password history verification and update
            final String password = ((SyncopeUser) attributable).getPassword();

            final List<String> passwordHistory = ((SyncopeUser) attributable).getPasswordHistory();

            if (((SyncopeUser) attributable).verifyPasswordHistory(
                    ((SyncopeUser) attributable).getClearPassword(), pspec.getHistoryLength())) {

                passwordPolicy.getWordsNotPermitted().add(((SyncopeUser) attributable).getClearPassword());
            } else {

                if (pspec.getHistoryLength() > 0 && password != null) {
                    passwordHistory.add(password);
                }

                if (pspec.getHistoryLength() < passwordHistory.size()) {
                    for (int i = 0; i < passwordHistory.size() - pspec.getHistoryLength(); i++) {

                        passwordHistory.remove(i);
                    }
                }
            }

            result = (T) passwordPolicy;
            break;
        case ACCOUNT:
        case GLOBAL_ACCOUNT:
            final AccountPolicySpec spec = policy.getSpecification();
            final AccountPolicySpec accountPolicy = new AccountPolicySpec();

            BeanUtils.copyProperties(spec, accountPolicy, new String[] { "schemasNotPermitted" });

            for (String schema : spec.getSchemasNotPermitted()) {
                attribute = attributable.getAttribute(schema);
                if (attribute != null) {
                    values = attribute.getValuesAsStrings();
                    if (values != null && !values.isEmpty()) {
                        accountPolicy.getWordsNotPermitted().add(values.get(0));
                    }
                }
            }

            result = (T) accountPolicy;
            break;
        case SYNC:
        case GLOBAL_SYNC:
            result = null;
            break;
        default:
            result = null;
        }
    }

    return result;
}

From source file:org.syncope.core.rest.data.ReportDataBinder.java

public void getReport(final Report report, final ReportTO reportTO) {
    BeanUtils.copyProperties(reportTO, report, IGNORE_REPORT_PROPERTIES);
    report.setReportletConfs(null);//  w w  w.  j  av a2  s . c  om
    for (ReportletConf conf : reportTO.getReportletConfs()) {
        report.addReportletConf(conf);
    }
}

From source file:com.kazuki43zoo.jpetstore.ui.controller.MyAccountController.java

@GetMapping(path = "/update", params = "form")
public String updateForm(AccountForm form, @AuthenticationPrincipal(expression = "account") Account account) {
    BeanUtils.copyProperties(account, form, "password");
    return "account/updateForm";
}

From source file:org.syncope.core.rest.data.ReportDataBinder.java

public ReportTO getReportTO(final Report report) {
    ReportTO reportTO = new ReportTO();
    reportTO.setId(report.getId());/*w  ww . j ava  2s .  co m*/
    BeanUtils.copyProperties(report, reportTO, IGNORE_REPORT_PROPERTIES);

    reportTO.setReportletConfs(report.getReportletConfs());

    ReportExec latestExec = reportExecDAO.findLatestStarted(report);
    reportTO.setLatestExecStatus(latestExec == null ? "" : latestExec.getStatus());

    for (ReportExec reportExec : report.getExecs()) {
        reportTO.addExecution(getReportExecTO(reportExec));
    }

    String triggerName = JobInstanceLoader.getTriggerName(JobInstanceLoader.getJobName(report));

    Trigger trigger;
    try {
        trigger = scheduler.getScheduler().getTrigger(triggerName, Scheduler.DEFAULT_GROUP);
    } catch (SchedulerException e) {
        LOG.warn("While trying to get to " + triggerName, e);
        trigger = null;
    }

    if (trigger != null) {
        reportTO.setLastExec(trigger.getPreviousFireTime());
        reportTO.setNextExec(trigger.getNextFireTime());
    }

    return reportTO;
}

From source file:org.syncope.core.rest.data.DerivedSchemaDataBinder.java

private <T extends AbstractSchema> AbstractDerSchema populate(final AbstractDerSchema derivedSchema,
        final DerivedSchemaTO derivedSchemaTO, final SyncopeClientCompositeErrorException scce)
        throws SyncopeClientCompositeErrorException {

    if (derivedSchemaTO.getExpression() == null) {
        SyncopeClientException requiredValuesMissing = new SyncopeClientException(
                SyncopeClientExceptionType.RequiredValuesMissing);
        requiredValuesMissing.addElement("expression");

        scce.addException(requiredValuesMissing);
    }//w ww .  jav  a  2  s .  c  o  m

    if (!jexlUtil.isExpressionValid(derivedSchemaTO.getExpression())) {
        SyncopeClientException invalidMandatoryCondition = new SyncopeClientException(
                SyncopeClientExceptionType.InvalidValues);
        invalidMandatoryCondition.addElement(derivedSchemaTO.getExpression());

        scce.addException(invalidMandatoryCondition);
    }

    if (scce.hasExceptions()) {
        throw scce;
    }

    BeanUtils.copyProperties(derivedSchemaTO, derivedSchema, ignoreDerivedSchemaProperties);

    return derivedSchema;
}

From source file:org.syncope.core.rest.data.SchemaDataBinder.java

private <T extends AbstractDerSchema> void populate(final AbstractSchema schema, final SchemaTO schemaTO)
        throws SyncopeClientCompositeErrorException {

    if (!jexlUtil.isExpressionValid(schemaTO.getMandatoryCondition())) {
        SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(
                HttpStatus.BAD_REQUEST);

        SyncopeClientException invalidMandatoryCondition = new SyncopeClientException(
                SyncopeClientExceptionType.InvalidValues);
        invalidMandatoryCondition.addElement(schemaTO.getMandatoryCondition());

        scce.addException(invalidMandatoryCondition);
        throw scce;
    }//from w ww  . j a  v a 2 s . c  o m

    BeanUtils.copyProperties(schemaTO, schema, IGNORE_SCHEMA_PROPERTIES);
}

From source file:org.syncope.core.rest.data.VirtualSchemaDataBinder.java

public <T extends AbstractVirSchema> VirtualSchemaTO getVirtualSchemaTO(final T virtualSchema) {

    VirtualSchemaTO virtualSchemaTO = new VirtualSchemaTO();
    BeanUtils.copyProperties(virtualSchema, virtualSchemaTO, ignoreVirtualSchemaProperties);

    return virtualSchemaTO;
}

From source file:technology.tikal.ventas.model.pedido.ofy.PartidaOfy.java

@Override
public void update(Partida source) {
    BeanUtils.copyProperties(source, this, "owner");
}

From source file:org.shept.persistence.provider.hibernate.HibernateUtils_old.java

public static Object copyTemplate(HibernateDaoSupport dao, Object entityModelTemplate) {
    if (entityModelTemplate != null) {
        // hier besser die Metadaten von Hibernate fragen
        if (null != getClassMetadata(dao, entityModelTemplate)) {
            //         if (null != AnnotationUtils.findAnnotation(entityModelTemplate.getClass(), Entity.class)) {
            String idName = HibernateUtils_old.getIdentifierPropertyName(dao, entityModelTemplate);
            Object newModel = BeanUtils.instantiateClass(entityModelTemplate.getClass());
            BeanUtils.copyProperties(entityModelTemplate, newModel, new String[] { idName });

            Serializable idx = getIdValue(dao, entityModelTemplate);

            ClassMetadata meta = getClassMetadata(dao, idx);
            Type type = meta.getIdentifierType();

            if (meta != null && type.isComponentType()) {
                // alternaitv               if (id != null && (null != AnnotationUtils.findAnnotation(id.getClass(), Embeddable.class))) {
                Serializable copyId = BeanUtils.instantiate(idx.getClass());
                BeanUtils.copyProperties(idx, copyId);
                Method idMth = ReflectionUtils.findMethod(entityModelTemplate.getClass(),
                        "set" + StringUtils.capitalize(idName), new Class[] {});
                if (idMth != null) {
                    ReflectionUtils.invokeMethod(idMth, newModel, copyId);
                }/* w  w w.  jav  a  2 s. c o  m*/
            }
            return newModel;
        }
    }
    return null;
}