Example usage for org.springframework.data.mapping PersistentEntity getType

List of usage examples for org.springframework.data.mapping PersistentEntity getType

Introduction

In this page you can find the example usage for org.springframework.data.mapping PersistentEntity getType.

Prototype

Class<T> getType();

Source Link

Document

Returns the resolved Java type of this entity.

Usage

From source file:org.lightadmin.core.web.support.DynamicRepositoryEntityLinks.java

public Link linkForFilePropertyLink(Object instance, PersistentProperty persistentProperty) {
    PersistentEntity persistentEntity = persistentProperty.getOwner();
    Serializable id = idValue(instance, persistentEntity);

    return delegate.linkForSingleResource(persistentEntity.getType(), id).slash(persistentProperty.getName())
            .slash("file").withSelfRel();
}

From source file:org.lightadmin.core.web.support.DomainEntityLinks.java

public Link linkFor(PersistentEntityResource persistentEntityResource) {
    PersistentEntity persistentEntity = persistentEntityResource.getPersistentEntity();
    Object instance = persistentEntityResource.getContent();

    return linkToSingleResource(persistentEntity.getType(), idAttributeValue(instance, persistentEntity));
}

From source file:org.lightadmin.core.storage.FileManipulationStrategyFactory.java

private FileManipulationStrategy createReferenceFileManipulationStrategy(PersistentEntity persistentEntity) {
    File fileStorageDirectory = lightAdminConfiguration.getFileStorageDirectory();
    DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration = configuration
            .forManagedDomainType(ClassUtils.getUserClass(persistentEntity.getType()));
    String domainTypeName = domainTypeAdministrationConfiguration.getDomainTypeName();

    FilePathResolver pathResolver = new ReferenceFilePathResolver(fileStorageDirectory, persistentEntity,
            domainTypeName);//from   w ww  .j av a2  s.  com

    return new ReferenceFileManipulationStrategy(pathResolver);
}

From source file:org.lightadmin.core.web.json.DomainTypeToJsonMetadataConverter.java

@Override
public JsonConfigurationMetadata convert(PersistentEntity persistentEntity) {
    final JsonConfigurationMetadata jsonConfigurationMetadata = new JsonConfigurationMetadata(
            persistentEntity.getName(),/*from w w  w . j  a  v a2 s  .c o m*/
            globalAdministrationConfiguration.isManagedDomainType(persistentEntity.getType()));

    persistentEntity.doWithProperties(new SimplePropertyHandler() {
        @Override
        public void doWithPersistentProperty(PersistentProperty<?> persistentProperty) {
            jsonConfigurationMetadata.addPersistentProperty(persistentProperty);
        }
    });

    persistentEntity.doWithAssociations(new SimpleAssociationHandler() {
        @Override
        public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
            jsonConfigurationMetadata.addAssociationProperty(association,
                    associationRestLinkTemplate(association.getInverse()));
        }
    });

    if (!globalAdministrationConfiguration.isManagedDomainType(persistentEntity.getType())) {
        return jsonConfigurationMetadata;
    }

    DomainTypeAdministrationConfiguration configuration = globalAdministrationConfiguration
            .forManagedDomainType(persistentEntity.getType());

    List<DomainConfigurationUnitType> unitTypes = newArrayList(LIST_VIEW, FORM_VIEW, SHOW_VIEW, QUICK_VIEW);

    for (DomainConfigurationUnitType unitType : unitTypes) {
        Set<FieldMetadata> fieldForUnit = configuration.fieldsForUnit(unitType);

        for (FieldMetadata field : fieldForUnit) {
            if (persistentFieldMetadataPredicate().apply(field)) {
                addPersistentProperty((PersistentFieldMetadata) field, unitType.toString(),
                        jsonConfigurationMetadata);
            }

            if (customFieldMetadataPredicate().apply(field)) {
                jsonConfigurationMetadata.addDynamicProperty((CustomFieldMetadata) field, unitType.toString());
            }

            if (transientFieldMetadataPredicate().apply(field)) {
                jsonConfigurationMetadata.addDynamicProperty((TransientFieldMetadata) field,
                        unitType.toString());
            }
        }
    }

    return jsonConfigurationMetadata;
}

From source file:org.lightadmin.core.web.support.DynamicPersistentEntityResourceProcessor.java

private Map<DomainConfigurationUnitType, Map<String, Object>> dynamicPropertiesPerUnit(Object value,
        PersistentEntity persistentEntity) {
    if (!adminConfiguration.isManagedDomainType(persistentEntity.getType())) {
        return Collections.emptyMap();
    }//from   w  ww  .  j a va  2  s  . c o m

    DomainTypeAdministrationConfiguration managedDomainTypeConfiguration = adminConfiguration
            .forManagedDomainType(persistentEntity.getType());

    List<DomainConfigurationUnitType> units = newArrayList(LIST_VIEW, FORM_VIEW, SHOW_VIEW, QUICK_VIEW);

    List<PersistentProperty> persistentProperties = findPersistentFileProperties(persistentEntity);
    List<Association> associations = findLinkableAssociations(persistentEntity);

    Map<DomainConfigurationUnitType, Map<String, Object>> dynamicPropertiesPerUnit = newHashMap();
    for (DomainConfigurationUnitType unit : units) {
        Map<String, Object> dynamicProperties = newLinkedHashMap();
        for (PersistentProperty persistentProperty : persistentProperties) {
            dynamicProperties.put(persistentProperty.getName(), filePropertyValue(persistentProperty, value));
        }
        for (Association association : associations) {
            dynamicProperties.put(association.getInverse().getName(),
                    associationPropertyValue(association, value));
        }
        for (FieldMetadata customField : customFields(managedDomainTypeConfiguration.fieldsForUnit(unit))) {
            dynamicProperties.put(customField.getUuid(), customField.getValue(value));
        }
        for (FieldMetadata transientField : transientFields(
                managedDomainTypeConfiguration.fieldsForUnit(unit))) {
            dynamicProperties.put(transientField.getUuid(), transientField.getValue(value));
        }
        dynamicPropertiesPerUnit.put(unit, dynamicProperties);
    }
    return dynamicPropertiesPerUnit;
}

From source file:org.lightadmin.core.web.support.DynamicPersistentEntityResourceProcessor.java

private Link domainLink(PersistentEntityResource persistentEntityResource) {
    PersistentEntity persistentEntity = persistentEntityResource.getPersistentEntity();
    if (domainEntityLinks.supports(persistentEntity.getType())) {
        return domainEntityLinks.linkFor(persistentEntityResource);
    }//ww  w .ja va  2s. c o m
    return null;
}

From source file:org.lightadmin.core.web.support.DynamicPersistentEntityResourceProcessor.java

private String stringRepresentation(Object value, PersistentEntity persistentEntity) {
    DomainTypeBasicConfiguration domainTypeBasicConfiguration = adminConfiguration
            .forDomainType(persistentEntity.getType());
    EntityNameExtractor nameExtractor = domainTypeBasicConfiguration.getEntityConfiguration()
            .getNameExtractor();/*from   www  .j av  a 2 s . co m*/

    return exceptionAwareNameExtractor(nameExtractor, domainTypeBasicConfiguration).apply(value);
}

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

/**
 * Returns the {@link MappedProperties} for the given {@link PersistentEntity}.
 * /*from  w  w  w  .j a  va 2s  .  co  m*/
 * @param entity must not be {@literal null}.
 * @param mapper must not be {@literal null}.
 * @return
 */
private MappedProperties getJacksonProperties(PersistentEntity<?, ?> entity, ObjectMapper mapper) {

    BeanDescription description = introspector.forDeserialization(mapper.getDeserializationConfig(),
            mapper.constructType(entity.getType()), mapper.getDeserializationConfig());

    return new MappedProperties(entity, description);
}

From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java

private Collection<Descriptor> buildSearchResourceDescriptors(PersistentEntity<?, ?> entity) {

    ResourceMetadata metadata = associations.getMetadataFor(entity.getType());
    List<Descriptor> descriptors = new ArrayList<Descriptor>();

    for (MethodResourceMapping methodMapping : metadata.getSearchResourceMappings()) {

        List<Descriptor> parameterDescriptors = new ArrayList<Descriptor>();

        for (ParameterMetadata parameterMetadata : methodMapping.getParametersMetadata()) {

            parameterDescriptors.add(//
                    descriptor().//
                            name(parameterMetadata.getName()).//
                            doc(getDocFor(parameterMetadata.getDescription())).//
                            type(Type.SEMANTIC)//
                            .build());/*from   w ww.  j a v  a2  s  .c om*/
        }

        descriptors.add(descriptor().//
                type(Type.SAFE).//
                name(methodMapping.getRel()).//
                descriptors(parameterDescriptors).//
                build());
    }

    return descriptors;
}

From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java

private Descriptor buildItemResourceDescriptor(RootResourceInformation resourceInformation,
        Descriptor representationDescriptor, HttpMethod method) {

    PersistentEntity<?, ?> entity = resourceInformation.getPersistentEntity();
    ResourceMetadata metadata = associations.getMetadataFor(entity.getType());

    return descriptor().//
            id(prefix(method).concat(metadata.getItemResourceRel())).//
            name(metadata.getItemResourceRel()).//
            type(getType(method)).//
            doc(getDocFor(metadata.getItemResourceDescription())).//
            rt("#".concat(representationDescriptor.getId())). //
            descriptors(getProjectionDescriptor(entity.getType(), method)).//
            build();/*from  w  ww.  jav a2 s  .  c om*/
}