Example usage for org.springframework.data.mapping PersistentProperty getName

List of usage examples for org.springframework.data.mapping PersistentProperty getName

Introduction

In this page you can find the example usage for org.springframework.data.mapping PersistentProperty getName.

Prototype

String getName();

Source Link

Document

The name of the property

Usage

From source file:org.lightadmin.core.util.NamingUtils.java

public static String entityId(DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration,
        Object entity) {// w w w. j a va  2 s. c om
    if (entity == null) {
        return null;
    }

    PersistentEntity persistentEntity = domainTypeAdministrationConfiguration.getPersistentEntity();
    PersistentProperty idProperty = persistentEntity.getIdProperty();

    BeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(entity);

    return String.valueOf(beanWrapper.getPropertyValue(idProperty.getName()));
}

From source file:org.springframework.data.rest.webmvc.json.JacksonMetadata.java

/**
 * Finds the {@link BeanPropertyDefinition} for the given {@link PersistentProperty} within the given definitions.
 * /*from   w w  w.jav a  2s  .co m*/
 * @param property must not be {@literal null}.
 * @param definitions must not be {@literal null}.
 * @return
 */
private static BeanPropertyDefinition getDefinitionFor(PersistentProperty<?> property,
        Iterable<BeanPropertyDefinition> definitions) {

    for (BeanPropertyDefinition definition : definitions) {
        if (definition.getInternalName().equals(property.getName())) {
            return definition;
        }
    }

    return null;
}

From source file:com.expedia.seiso.web.assembler.ItemPropertyHandler.java

@Override
public void doWithPersistentProperty(PersistentProperty<?> prop) {
    val propName = prop.getName();

    // Copy the ID over since the V1 schema exposes database IDs. (The V2 HAL schema doesn't, though.)
    val restResource = prop.findAnnotation(RestResource.class);
    if (restResource == null || restResource.exported()) {
        properties.put(propName, wrapper.getProperty(prop));
    }/* w  w w  . jav a 2  s  . com*/
}

From source file:com.expedia.seiso.web.assembler.ItemAssociationHandler.java

@Override
public void doWithAssociation(Association<? extends PersistentProperty<?>> assoc) {
    val item = wrapper.getBean();

    // val doesn't work here for some reason.
    PersistentProperty<?> prop = assoc.getInverse();
    val propName = prop.getName();
    val propType = prop.getType();
    val child = projection.getChild(propName);

    // Link/*from  ww  w .  jav  a  2 s  .com*/
    if (topLevel) {
        val restResource = prop.findAnnotation(RestResource.class);
        val path = (restResource == null ? propName : restResource.path());
        resource.addLink(itemLinks.itemPropertyLink(item, path));
    }

    // Property
    if (child != null) {
        if (Item.class.isAssignableFrom(propType)) {
            val propEntity = (Item) wrapper.getProperty(prop);
            val propResource = assembler.toResource(apiVersion, propEntity, child, false);
            resource.setAssociation(propName, propResource);
        } else if (List.class.isAssignableFrom(propType)) {
            val propEntityList = (List<?>) wrapper.getProperty(prop);
            val propResourceList = assembler.toResourceList(apiVersion, propEntityList, child);
            resource.setAssociation(propName, propResourceList);
        } else {
            log.warn("Don't know how to handle association type {}", propType);
        }
    }
}

From source file:org.lightadmin.core.storage.strategy.binary.BinaryFileManipulationStrategy.java

protected Object getPropertyValue(Object entity, PersistentProperty persistentProperty) {
    return beanWrapper(entity).getPropertyValue(persistentProperty.getName());
}

From source file:org.lightadmin.core.storage.strategy.binary.BinaryFileManipulationStrategy.java

protected void setPropertyValue(Object entity, PersistentProperty persistentProperty, Object value) {
    beanWrapper(entity).setPropertyValue(persistentProperty.getName(), value);
}

From source file:org.lightadmin.core.storage.strategy.file.command.ReferenceFileDeletionCommand.java

public void execute(Object entity, PersistentProperty persistentProperty) {
    logger.info("Performing delete operation on @FileReference property {}", persistentProperty.getName());

    if (hasNoReferencedFile(entity, persistentProperty)) {
        return;//from w  w w .  ja va2  s  .c o m
    }

    boolean fileDeleted = deleteFile(entity, persistentProperty);
    if (fileDeleted) {
        resetPropertyValue(entity, persistentProperty);

        deletePropertyFileDirectory(entity, persistentProperty);
    }
}

From source file:org.lightadmin.core.config.domain.unit.visitor.FieldSetConfigurationUnitVisitor.java

@Override
protected void visitInternal(DefaultFieldSetConfigurationUnit configurationUnit) {
    PersistentProperty idProperty = persistentEntity.getIdProperty();
    PersistentFieldMetadata primaryKeyField = getPersistentField(configurationUnit.getFields(),
            idProperty.getName());

    if (primaryKeyField != null) {
        primaryKeyField.setPrimaryKey(true);
    } else {/*from  w w  w. j  a v  a  2s.c om*/
        configurationUnit.addField(keyField(capitalize(idProperty.getName()), idProperty.getName()));
    }

    configurationUnit.doWithPersistentFields(new FieldHandler<PersistentFieldMetadata>() {
        @Override
        public void doWithField(PersistentFieldMetadata persistentField) {
            PersistentProperty persistentProperty = persistentEntity
                    .getPersistentProperty(persistentField.getField());
            persistentField.setPersistentProperty(persistentProperty);
        }
    });
}

From source file:org.lightadmin.core.storage.strategy.file.ReferenceFilePathResolver.java

private String persistentPropertyFileDirectoryRelativePath(Object entity,
        PersistentProperty persistentProperty) {
    return Joiner.on(separator).join(persistentEntityRootDirectoryRelativePath(entity),
            persistentProperty.getName());
}

From source file:org.lightadmin.core.storage.strategy.file.command.ReferenceFileSaveCommand.java

public void execute(Object entity, PersistentProperty persistentProperty, Object incomingValueObject)
        throws IOException {
    logger.info("Starting save command execution for {}", persistentProperty.getName());

    byte[] incomingVal = incomingValue(incomingValueObject);

    logger.info("Received data for persisting {}: {}", persistentProperty.getName(), incomingVal);

    String relativePath = pathResolver.persistentPropertyFileRelativePath(entity, persistentProperty);

    logger.info("Property {} relative file path {}", persistentProperty.getName(), relativePath);

    File file = pathResolver.persistentPropertyFileReference(entity, persistentProperty);

    if (ArrayUtils.isEmpty(incomingVal)) {
        logger.info("Incoming value is empty");

        resetPropertyValue(entity, persistentProperty);

        logger.info("Resetted property value to {}", getPropertyValue(entity, persistentProperty));

        boolean fileDeleted = deleteQuietly(file);
        if (fileDeleted) {
            logger.info("File {} has been deleted", file);
        }//from  w  w  w .jav  a 2 s  .com

        return;
    }

    logger.info("Writing binary data to file {}: {}", file, incomingVal);

    writeByteArrayToFile(file, incomingVal);

    logger.info("Settign property {} new value {}", persistentProperty.getName(), relativePath);

    setPropertyValue(entity, persistentProperty, relativePath);

    logger.info("Current property {} value is {}", persistentProperty.getName(),
            getPropertyValue(entity, persistentProperty));
}