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;
}
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;
}
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());
}
}
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;
}
}
}
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);
}
Aggregations