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

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

Introduction

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

Prototype

@Nullable
<A extends Annotation> A findAnnotation(Class<A> annotationType);

Source Link

Document

Looks up the annotation of the given type on the PersistentProperty .

Usage

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

public static Annotation findAnnotationByName(PersistentProperty persistentProperty, String annotationTypeName)
        throws RuntimeException {
    try {/* ww w  .  j  a v a 2 s .c om*/
        return persistentProperty != null ? persistentProperty.findAnnotation(Class.forName(annotationTypeName))
                : null;
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }
}

From source file:org.lightadmin.core.persistence.metamodel.PersistentPropertyType.java

private static boolean hasTemporalType(PersistentProperty persistentProperty, TemporalType temporalType) {
    Temporal temporal = (Temporal) persistentProperty.findAnnotation(Temporal.class);
    return temporal != null && temporal.value() == temporalType;
}

From source file:org.springframework.data.mapping.model.JsonPropertyPreservingFieldNamingStrategy.java

@Override
public String getFieldName(PersistentProperty<?> property) {

    JsonProperty jsonPropertyAnnotation = property.findAnnotation(JsonProperty.class);

    if (jsonPropertyAnnotation != null) {
        return jsonPropertyAnnotation.value();
    } else {/*  ww w .  j  a v  a 2  s  .  c  o  m*/
        return backingStrategy.getFieldName(property);
    }
}

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

private FileReference fileReferenceAnnotation(PersistentProperty persistentProperty) {
    return (FileReference) persistentProperty.findAnnotation(FileReference.class);
}

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));
    }/*from www.  jav a  2  s. c  om*/
}

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   w  w w  . java2 s . co  m*/
    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.config.bootstrap.parsing.validation.PersistentFieldMetadataValidator.java

@Override
@SuppressWarnings("unchecked")
public Collection<? extends DomainConfigurationProblem> validateFieldMetadata(
        PersistentFieldMetadata fieldMetadata, Class<?> domainType,
        DomainConfigurationValidationContext validationContext) {
    MappingContext mappingContext = validationContext.getMappingContext();
    final LightAdminConfiguration lightAdminConfiguration = validationContext.getLightAdminConfiguration();

    final PersistentEntity persistentEntity = mappingContext.getPersistentEntity(domainType);

    PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(fieldMetadata.getField());

    if (persistentProperty == null) {
        return newArrayList(validationContext.notPersistableFieldProblem(fieldMetadata.getName()));
    }//from  w  w  w.  j a  v  a 2s  .  c  o  m

    if (!isSupportedAttributeType(PersistentPropertyType.forPersistentProperty(persistentProperty))) {
        return newArrayList(validationContext.notSupportedTypeFieldProblem(fieldMetadata.getName()));
    }

    if (!isOfFileReferenceType(persistentProperty)) {
        return emptyList();
    }

    Annotation annotation = persistentProperty.findAnnotation(FileReference.class);

    FileReference fileReference = (FileReference) annotation;

    if (isEmpty(fileReference.baseDirectory())) {
        if (lightAdminConfiguration.getFileStorageDirectory() != null) {
            return emptyList();
        }
        return newArrayList(
                validationContext.missingBaseDirectoryInFileReferenceProblem(fieldMetadata.getName()));
    }

    final File directory = getFile(fileReference.baseDirectory());
    if (directory.exists() && directory.isDirectory()) {
        return emptyList();
    }

    return newArrayList(validationContext.missingBaseDirectoryInFileReferenceProblem(fieldMetadata.getName()));
}