Search in sources :

Example 61 with FieldMetadata

use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.

the class DtoOperationsImpl method checkAndAddIdField.

/**
 * Check if provided fields contain the related entity id field and otherwise
 * adds it to the Map.
 *
 * @param entity JavaType the Projection related entity.
 * @param fieldsString the String with the fields received from operation
 * @return the String with the fields to add to Projection.
 */
private String checkAndAddIdField(JavaType entity, String fieldsString) {
    List<FieldMetadata> identifierFields = getPersistenceMemberLocator().getIdentifierFields(entity);
    String[] fieldsProvided = fieldsString.split(",");
    for (FieldMetadata idField : identifierFields) {
        boolean fieldIsInProjection = false;
        for (String field : fieldsProvided) {
            if (field.equals(idField.getFieldName().getSymbolName())) {
                fieldIsInProjection = true;
                break;
            }
        }
        if (!fieldIsInProjection) {
            // Add to fields String, which will be used to create the annotation
            fieldsString = idField.getFieldName().getSymbolName().concat(",").concat(fieldsString);
            LOGGER.info(String.format("INFO: You haven't included the identifier field/s of the entity '%s' in " + "your projection, which is necessary to be able to use this projection " + "in the view layer. But don't worry, Spring Roo has included it automatically.", entity.getSimpleTypeName()));
        }
    }
    return fieldsString;
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata)

Example 62 with FieldMetadata

use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.

the class DtoMetadata method getConstructor.

/**
 * Builds constructor for initializing <code>final</code> fields.
 *
 * @return ConstructorMetadataBuilder for adding constructor to ITD
 */
private ConstructorMetadataBuilder getConstructor() {
    ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    if (annotationValues.getImmutable() == true) {
        for (FieldMetadata field : fields) {
            // Add all fields excluding Serializable field
            if (!field.getFieldName().equals(serialField)) {
                String fieldName = field.getFieldName().getSymbolName();
                constructorBuilder.addParameter(fieldName, field.getFieldType());
                bodyBuilder.appendFormalLine(String.format("this.%s = %s;", fieldName, fieldName));
            }
        }
    }
    constructorBuilder.setModifier(Modifier.PUBLIC);
    constructorBuilder.setBodyBuilder(bodyBuilder);
    return constructorBuilder;
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ConstructorMetadataBuilder(org.springframework.roo.classpath.details.ConstructorMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 63 with FieldMetadata

use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.

the class MemberDetailsBuilder method tag.

public <T> void tag(final T toModify, final CustomDataKey<T> key, final Object value) {
    if (toModify instanceof FieldMetadata) {
        final CustomDataBuilder customDataBuilder = new CustomDataBuilder();
        customDataBuilder.put(key, value);
        doModification((FieldMetadata) toModify, customDataBuilder.build());
    } else if (toModify instanceof MethodMetadata) {
        final CustomDataBuilder customDataBuilder = new CustomDataBuilder();
        customDataBuilder.put(key, value);
        doModification((MethodMetadata) toModify, customDataBuilder.build());
    } else if (toModify instanceof ConstructorMetadata) {
        final CustomDataBuilder customDataBuilder = new CustomDataBuilder();
        customDataBuilder.put(key, value);
        doModification((ConstructorMetadata) toModify, customDataBuilder.build());
    } else if (toModify instanceof MemberHoldingTypeDetails) {
        final CustomDataBuilder customDataBuilder = new CustomDataBuilder();
        customDataBuilder.put(key, value);
        doModification((MemberHoldingTypeDetails) toModify, customDataBuilder.build());
    }
}
Also used : ConstructorMetadata(org.springframework.roo.classpath.details.ConstructorMetadata) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) CustomDataBuilder(org.springframework.roo.model.CustomDataBuilder) MemberHoldingTypeDetails(org.springframework.roo.classpath.details.MemberHoldingTypeDetails) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata)

Example 64 with FieldMetadata

use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.

the class MemberDetailsBuilder method doModification.

private void doModification(final FieldMetadata field, final CustomData customData) {
    final MemberHoldingTypeDetails memberHoldingTypeDetails = memberHoldingTypeDetailsMap.get(field.getDeclaredByMetadataId());
    if (memberHoldingTypeDetails != null) {
        final FieldMetadata matchedField = memberHoldingTypeDetails.getField(field.getFieldName());
        if (matchedField != null && !matchedField.getCustomData().keySet().containsAll(customData.keySet())) {
            final TypeDetailsBuilder typeDetailsBuilder = getTypeDetailsBuilder(memberHoldingTypeDetails);
            typeDetailsBuilder.addDataToField(field, customData);
            changed = true;
        }
    }
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) MemberHoldingTypeDetails(org.springframework.roo.classpath.details.MemberHoldingTypeDetails) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) AbstractMemberHoldingTypeDetailsBuilder(org.springframework.roo.classpath.details.AbstractMemberHoldingTypeDetailsBuilder) ItdTypeDetailsBuilder(org.springframework.roo.classpath.details.ItdTypeDetailsBuilder)

Example 65 with FieldMetadata

use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.

the class JpaAuditMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Obtain the fields that are annotated with Audit annotations
    List<FieldMetadata> auditFields = new ArrayList<FieldMetadata>();
    JavaType annotatedEntity = governorPhysicalTypeMetadata.getType();
    ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(annotatedEntity);
    auditFields.addAll(entityDetails.getFieldsWithAnnotation(SpringJavaType.CREATED_DATE));
    auditFields.addAll(entityDetails.getFieldsWithAnnotation(SpringJavaType.LAST_MODIFIED_DATE));
    auditFields.addAll(entityDetails.getFieldsWithAnnotation(SpringJavaType.CREATED_BY));
    auditFields.addAll(entityDetails.getFieldsWithAnnotation(SpringJavaType.LAST_MODIFIED_BY));
    return new JpaAuditMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, auditFields);
}
Also used : SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Aggregations

FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)141 JavaType (org.springframework.roo.model.JavaType)76 ArrayList (java.util.ArrayList)69 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)59 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)40 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)40 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)39 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)38 RooJavaType (org.springframework.roo.model.RooJavaType)38 JdkJavaType (org.springframework.roo.model.JdkJavaType)33 JpaJavaType (org.springframework.roo.model.JpaJavaType)32 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)30 SpringJavaType (org.springframework.roo.model.SpringJavaType)30 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)29 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)26 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)21 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)21 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)18 RelationInfo (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo)17 ServiceMetadata (org.springframework.roo.addon.layers.service.addon.ServiceMetadata)15