use of org.springframework.roo.classpath.operations.jsr303.CollectionField in project spring-roo by spring-projects.
the class DtoFieldCreatorProvider method insertField.
public void insertField(final FieldDetails fieldDetails, final boolean permitReservedWords, final boolean transientModifier) {
String module = null;
if (!permitReservedWords) {
ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getFieldName());
if (fieldDetails.getColumn() != null) {
ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getColumn());
}
}
final List<AnnotationMetadataBuilder> annotations = fieldDetails.getInitedAnnotations();
fieldDetails.decorateAnnotationsList(annotations);
fieldDetails.setAnnotations(annotations);
if (fieldDetails.getFieldType() != null) {
module = fieldDetails.getFieldType().getModule();
}
fieldDetails.setModifiers(Modifier.PRIVATE);
String initializer = null;
if (fieldDetails instanceof CollectionField) {
final CollectionField collectionField = (CollectionField) fieldDetails;
module = collectionField.getGenericParameterTypeName().getModule();
initializer = "new " + collectionField.getInitializer() + "()";
} else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
initializer = "new Date()";
}
// Format the passed-in comment (if given)
formatFieldComment(fieldDetails);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
fieldBuilder.setFieldInitializer(initializer);
typeManagementService.addField(fieldBuilder.build());
if (module != null) {
projectOperations.addModuleDependency(module);
}
}
use of org.springframework.roo.classpath.operations.jsr303.CollectionField in project spring-roo by spring-projects.
the class EmbeddableFieldCreatorProvider method insertField.
public void insertField(final FieldDetails fieldDetails, final boolean permitReservedWords, final boolean transientModifier) {
String module = null;
if (!permitReservedWords) {
ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getFieldName());
if (fieldDetails.getColumn() != null) {
ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getColumn());
}
}
final List<AnnotationMetadataBuilder> annotations = fieldDetails.getInitedAnnotations();
fieldDetails.decorateAnnotationsList(annotations);
fieldDetails.setAnnotations(annotations);
if (fieldDetails.getFieldType() != null) {
module = fieldDetails.getFieldType().getModule();
}
String initializer = null;
if (fieldDetails instanceof CollectionField) {
final CollectionField collectionField = (CollectionField) fieldDetails;
module = collectionField.getGenericParameterTypeName().getModule();
initializer = "new " + collectionField.getInitializer() + "()";
} else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
initializer = "new Date()";
}
int modifier = Modifier.PRIVATE;
if (transientModifier) {
modifier += Modifier.TRANSIENT;
}
fieldDetails.setModifiers(modifier);
// Format the passed-in comment (if given)
formatFieldComment(fieldDetails);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
fieldBuilder.setFieldInitializer(initializer);
typeManagementService.addField(fieldBuilder.build());
if (module != null) {
projectOperations.addModuleDependency(module);
}
}
use of org.springframework.roo.classpath.operations.jsr303.CollectionField in project spring-roo by spring-projects.
the class JpaFieldCreatorProvider method getFieldModule.
private String getFieldModule(final FieldDetails fieldDetails) {
String module = null;
if (fieldDetails.getFieldType() != null) {
module = fieldDetails.getFieldType().getModule();
}
if (fieldDetails instanceof CollectionField) {
final CollectionField collectionField = (CollectionField) fieldDetails;
module = collectionField.getGenericParameterTypeName().getModule();
}
return module;
}
use of org.springframework.roo.classpath.operations.jsr303.CollectionField in project spring-roo by spring-projects.
the class JpaFieldCreatorProvider method generateFieldBuilder.
/**
* Generates Field builder based on fieldDetails
*
* @param fieldDetails
* @param permitReservedWords
* @param transientModifier
* @return
*/
private FieldMetadataBuilder generateFieldBuilder(final FieldDetails fieldDetails, final boolean permitReservedWords, final boolean transientModifier) {
if (!permitReservedWords) {
ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getFieldName());
if (fieldDetails.getColumn() != null) {
ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getColumn());
}
}
final List<AnnotationMetadataBuilder> annotations = fieldDetails.getInitedAnnotations();
fieldDetails.decorateAnnotationsList(annotations);
fieldDetails.setAnnotations(annotations);
String initializer = null;
if (fieldDetails instanceof CollectionField) {
final CollectionField collectionField = (CollectionField) fieldDetails;
initializer = "new " + collectionField.getInitializer() + "()";
} else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
initializer = "new Date()";
}
int modifier = Modifier.PRIVATE;
if (transientModifier) {
modifier += Modifier.TRANSIENT;
}
fieldDetails.setModifiers(modifier);
// Format the passed-in comment (if given)
formatFieldComment(fieldDetails);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
fieldBuilder.setFieldInitializer(initializer);
return fieldBuilder;
}
use of org.springframework.roo.classpath.operations.jsr303.CollectionField in project spring-roo by spring-projects.
the class DtoOperationsImpl method addFieldsToProjection.
/**
* Removes persistence annotations of provided fields and adds them to a
* ClassOrInterfaceTypeDetailsBuilder representing a Projection in construction.
* Also adds final modifier to fields if required.
*
* @param projectionBuilder the ClassOrInterfaceTypeDetailsBuilder for building the
* Projection class.
* @param fieldsToAdd the List<FieldMetadata> to add.
*/
private void addFieldsToProjection(ClassOrInterfaceTypeDetailsBuilder projectionBuilder, Map<String, FieldMetadata> fieldsToAdd) {
Iterator<Entry<String, FieldMetadata>> iterator = fieldsToAdd.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, FieldMetadata> entry = iterator.next();
FieldMetadata field = entry.getValue();
// List and Set types require special management
FieldMetadataBuilder fieldBuilder = null;
FieldDetails fieldDetails = null;
if (field.getFieldType().getFullyQualifiedTypeName().equals("java.util.Set")) {
JavaType fieldType = field.getFieldType().getParameters().get(0);
fieldDetails = new SetField(projectionBuilder.getDeclaredByMetadataId(), new JavaType(JdkJavaType.SET.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(fieldType)), field.getFieldName(), fieldType, null, null, true);
fieldBuilder = new FieldMetadataBuilder(fieldDetails);
fieldBuilder.setModifier(field.getModifier());
fieldBuilder.setAnnotations(field.getAnnotations());
} else if (field.getFieldType().getFullyQualifiedTypeName().equals("java.util.List")) {
JavaType fieldType = field.getFieldType().getParameters().get(0);
fieldDetails = new ListField(projectionBuilder.getDeclaredByMetadataId(), new JavaType(JdkJavaType.LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(fieldType)), field.getFieldName(), fieldType, null, null, true);
fieldBuilder = new FieldMetadataBuilder(fieldDetails);
fieldBuilder.setModifier(field.getModifier());
fieldBuilder.setAnnotations(field.getAnnotations());
} else {
// Can't just copy FieldMetadata because field.declaredByMetadataId will be the same
fieldBuilder = new FieldMetadataBuilder(projectionBuilder.getDeclaredByMetadataId(), field);
}
// Add dependency between modules
typeLocationService.addModuleDependency(projectionBuilder.getName().getModule(), field.getFieldType());
// Set new fieldName
fieldBuilder.setFieldName(new JavaSymbolName(entry.getKey()));
// If it is a CollectionField it needs an initializer
String initializer = null;
if (fieldDetails instanceof CollectionField) {
final CollectionField collectionField = (CollectionField) fieldDetails;
initializer = "new " + collectionField.getInitializer() + "()";
} else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
initializer = "new Date()";
}
fieldBuilder.setFieldInitializer(initializer);
// Remove persistence annotations
List<AnnotationMetadata> annotations = field.getAnnotations();
for (AnnotationMetadata annotation : annotations) {
if (annotation.getAnnotationType().getFullyQualifiedTypeName().contains("javax.persistence")) {
fieldBuilder.removeAnnotation(annotation.getAnnotationType());
} else if (annotation.getAnnotationType().getFullyQualifiedTypeName().startsWith("javax.validation")) {
// Add validation dependency
projectOperations.addDependency(projectionBuilder.getName().getModule(), new Dependency("javax.validation", "validation-api", null));
} else if (annotation.getAnnotationType().equals(RooJavaType.ROO_JPA_RELATION)) {
fieldBuilder.removeAnnotation(annotation.getAnnotationType());
}
}
fieldBuilder.setModifier(Modifier.PRIVATE);
// Build field
FieldMetadata projectionField = fieldBuilder.build();
// Add field to DTO
projectionBuilder.addField(projectionField);
}
}
Aggregations