use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class EqualsMetadata method getDefaultHashCodeMethodReturnStatment.
/**
* Returns the default `hasCode` method return statement
*
* @return a {@link StringBuilder}
*/
private static StringBuilder getDefaultHashCodeMethodReturnStatment(EqualsAnnotationValues annotationValues, List<FieldMetadata> locatedFields, ImportRegistrationResolver importRegistrationResolver) {
final StringBuilder builder = new StringBuilder(String.format("return new %s()", HASH_CODE_BUILDER.getNameIncludingTypeParameters(false, importRegistrationResolver)));
if (annotationValues.isAppendSuper()) {
builder.append(".appendSuper(super.hashCode())");
}
for (final FieldMetadata field : locatedFields) {
builder.append(".append(" + field.getFieldName() + ")");
}
builder.append(".toHashCode();");
return builder;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class EntityProjectionMetadataProviderImpl method buildFieldMetadataFromAnnotation.
/**
* Builds FieldMetadata to provide {@link EntityProjectionMetadata} with the necessary
* resources to create constructor.
*
* @param fields the String[] from 'fields' annotation parameter.
* @param cid the governor ClassOrInterfaceTypeDetails, that is, the Projection physical type.
* @return the List<FieldMetadata> with the fields to build the constructor.
*/
private List<FieldMetadata> buildFieldMetadataFromAnnotation(String[] fields, ClassOrInterfaceTypeDetails cid) {
List<FieldMetadata> allFields = getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), cid).getFields();
List<FieldMetadata> fieldsToAdd = new ArrayList<FieldMetadata>();
// Iterate over all specified fields
for (int i = 0; i < fields.length; i++) {
String fieldName = "";
boolean existsInGovernor = false;
// Build field name following Java convention
String[] splittedByDot = StringUtils.split(fields[i], ".");
for (int t = 0; t < splittedByDot.length; t++) {
if (t == 0) {
fieldName = fieldName.concat(splittedByDot[t]);
} else {
fieldName = fieldName.concat(StringUtils.capitalize(splittedByDot[t]));
}
}
// Check existence in governor
for (FieldMetadata field : allFields) {
if (field.getFieldName().getSymbolName().equals(fieldName)) {
existsInGovernor = true;
fieldsToAdd.add(field);
}
}
if (!existsInGovernor) {
throw new IllegalStateException(String.format("Field %s couldn't be located in %s. Please, be sure that it is well written in 'fields' param of @RooEntityProjection.", fieldName, cid.getType().getFullyQualifiedTypeName()));
}
}
return fieldsToAdd;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class EntityProjectionMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final EntityProjectionAnnotationValues annotationValues = new EntityProjectionAnnotationValues(governorPhysicalTypeMetadata);
// Get CID from governor
ClassOrInterfaceTypeDetails cid = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
// Get all projection fields from annotation
String[] fieldsString = annotationValues.getFields();
List<FieldMetadata> fields = buildFieldMetadataFromAnnotation(fieldsString, cid);
// Add dependency between modules
for (FieldMetadata field : fields) {
getTypeLocationService().addModuleDependency(cid.getName().getModule(), field.getFieldType());
}
return new EntityProjectionMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, fields);
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class EqualsMetadataProviderImpl method getIdentifier.
public FieldMetadata getIdentifier(final PhysicalTypeMetadata governorPhysicalTypeMetadata) {
List<FieldMetadata> identifierFields = getPersistenceMemberLocator().getIdentifierFields(governorPhysicalTypeMetadata.getType());
FieldMetadata identifierField = null;
if (!identifierFields.isEmpty()) {
identifierField = identifierFields.get(0);
}
return identifierField;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class FinderOperationsImpl method findDtoFieldRecursivelyAndAddToMappings.
private boolean findDtoFieldRecursivelyAndAddToMappings(JavaType entity, Map<String, String> fieldNamesMap, Map<String, FieldMetadata> fieldMetadataMap, boolean found, FieldMetadata field, JavaSymbolName finderFieldName, JavaType finderFieldType, List<FieldMetadata> allDtoFields, String dtoSimpleName) {
JavaType currentEntity;
if (getTypeLocationService().getTypeDetails(field.getFieldType()) != null && getTypeLocationService().getTypeDetails(field.getFieldType()).getAnnotation(RooJavaType.ROO_JPA_ENTITY) != null) {
// Change current entity
currentEntity = field.getFieldType();
// Modify pathName with one more level
String pathName = StringUtils.uncapitalize(entity.getSimpleTypeName()).concat(".").concat(field.getFieldName().getSymbolName());
List<FieldMetadata> relatedEntityFields = getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), getTypeLocationService().getTypeDetails(currentEntity)).getFields();
for (FieldMetadata relatedField : relatedEntityFields) {
if (relatedField.getFieldName().equals(finderFieldName) && relatedField.getFieldType().equals(finderFieldType)) {
// Add FieldMetadata from DTO to fieldMetadataMap
boolean fieldFoundInDto = false;
for (FieldMetadata dtoField : allDtoFields) {
if (dtoField.getFieldName().equals(finderFieldName) && dtoField.getFieldType().equals(finderFieldType)) {
fieldMetadataMap.put(finderFieldName.getSymbolName(), dtoField);
fieldFoundInDto = true;
}
}
Validate.isTrue(fieldFoundInDto, "Couldn't find a field with same name and type that %s on DTO %s", finderFieldName.getSymbolName(), dtoSimpleName);
fieldNamesMap.put(finderFieldName.getSymbolName(), pathName.concat(".").concat(relatedField.getFieldName().getSymbolName()));
found = true;
break;
} else {
findDtoFieldRecursivelyAndAddToMappings(currentEntity, fieldNamesMap, fieldMetadataMap, found, relatedField, finderFieldName, finderFieldType, allDtoFields, dtoSimpleName);
}
}
}
return found;
}
Aggregations