use of org.springframework.roo.classpath.details.annotations.StringAttributeValue in project spring-roo by spring-projects.
the class WebFinderOperationsImpl method updateExistingSearchController.
/**
* Update existing controller with new query methods
* @param queryMethods the finder names to add
* @param controllerToUpdateOrCreate the existing controller
* @param controllerBuilder the builder to apply the changes
* @return
*/
private boolean updateExistingSearchController(List<String> queryMethods, ClassOrInterfaceTypeDetails controllerToUpdateOrCreate, ClassOrInterfaceTypeDetailsBuilder controllerBuilder) {
// Get @RooSearch and build necessary variables
AnnotationMetadata searchAnnotation = controllerToUpdateOrCreate.getAnnotation(RooJavaType.ROO_SEARCH);
List<AnnotationAttributeValue<?>> findersToAdd = new ArrayList<AnnotationAttributeValue<?>>();
List<String> finderNames = new ArrayList<String>();
boolean findersAdded = false;
// Get existent finder values
if (searchAnnotation != null && searchAnnotation.getAttribute("finders") != null) {
List<?> existingFinders = (List<?>) searchAnnotation.getAttribute("finders").getValue();
Iterator<?> it = existingFinders.iterator();
// Add existent finders to new attributes array to merge with new ones
while (it.hasNext()) {
StringAttributeValue attributeValue = (StringAttributeValue) it.next();
findersToAdd.add(attributeValue);
finderNames.add(attributeValue.getValue());
}
// Add new finders to new attributes array
for (String finder : queryMethods) {
if (!finderNames.contains(finder)) {
findersToAdd.add(new StringAttributeValue(new JavaSymbolName("value"), finder));
findersAdded = true;
}
}
// Add attributes array to @RooSearch
AnnotationMetadataBuilder searchAnnotationBuilder = new AnnotationMetadataBuilder(searchAnnotation);
ArrayAttributeValue<AnnotationAttributeValue<?>> allFinders = new ArrayAttributeValue<AnnotationAttributeValue<?>>(new JavaSymbolName("finders"), findersToAdd);
searchAnnotationBuilder.addAttribute(allFinders);
controllerBuilder.updateTypeAnnotation(searchAnnotationBuilder);
}
return findersAdded;
}
use of org.springframework.roo.classpath.details.annotations.StringAttributeValue in project spring-roo by spring-projects.
the class WebFinderOperationsImpl method buildNewSearchController.
/**
* Build a new search controller for provided entity, with provided response type,
* package, path prefix and query methods.
*
* @param entity
* @param queryMethods
* @param responseType
* @param controllerPackage
* @param pathPrefix
* @return
*/
private ClassOrInterfaceTypeDetailsBuilder buildNewSearchController(JavaType entity, List<String> queryMethods, ControllerMVCResponseService responseType, JavaPackage controllerPackage, String pathPrefix) {
ClassOrInterfaceTypeDetailsBuilder controllerBuilder;
JavaType searchController = new JavaType(String.format("%s.%sSearch%sController", controllerPackage.getFullyQualifiedPackageName(), pluralService.getPlural(entity), responseType.getControllerNameModifier()), controllerPackage.getModule());
final String physicalPath = PhysicalTypeIdentifier.createIdentifier(searchController, LogicalPath.getInstance(Path.SRC_MAIN_JAVA, controllerPackage.getModule()));
controllerBuilder = new ClassOrInterfaceTypeDetailsBuilder(physicalPath, Modifier.PUBLIC, searchController, PhysicalTypeCategory.CLASS);
// Create @RooController
AnnotationMetadataBuilder controllerAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_CONTROLLER);
controllerAnnotation.addClassAttribute("entity", entity);
if (StringUtils.isNotBlank(pathPrefix)) {
controllerAnnotation.addStringAttribute("pathPrefix", pathPrefix);
}
controllerAnnotation.addEnumAttribute("type", new EnumDetails(RooJavaType.ROO_ENUM_CONTROLLER_TYPE, new JavaSymbolName("SEARCH")));
controllerBuilder.addAnnotation(controllerAnnotation.build());
// Create @RooSearch
AnnotationMetadataBuilder searchAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_SEARCH);
List<AnnotationAttributeValue<?>> findersToAdd = new ArrayList<AnnotationAttributeValue<?>>();
for (String finder : queryMethods) {
findersToAdd.add(new StringAttributeValue(new JavaSymbolName("value"), finder));
}
searchAnnotation.addAttribute(new ArrayAttributeValue<AnnotationAttributeValue<?>>(new JavaSymbolName("finders"), findersToAdd));
controllerBuilder.addAnnotation(searchAnnotation);
// Add response type annotation
AnnotationMetadataBuilder responseTypeAnnotation = new AnnotationMetadataBuilder(responseType.getAnnotation());
controllerBuilder.addAnnotation(responseTypeAnnotation);
return controllerBuilder;
}
use of org.springframework.roo.classpath.details.annotations.StringAttributeValue in project spring-roo by spring-projects.
the class StringOrNumericField method decorateAnnotationsList.
@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
super.decorateAnnotationsList(annotations);
if (decimalMin != null) {
final List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
attrs.add(new StringAttributeValue(new JavaSymbolName("value"), decimalMin));
annotations.add(new AnnotationMetadataBuilder(DECIMAL_MIN, attrs));
}
if (decimalMax != null) {
final List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
attrs.add(new StringAttributeValue(new JavaSymbolName("value"), decimalMax));
annotations.add(new AnnotationMetadataBuilder(DECIMAL_MAX, attrs));
}
}
use of org.springframework.roo.classpath.details.annotations.StringAttributeValue in project spring-roo by spring-projects.
the class DateField method decorateAnnotationsList.
@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
super.decorateAnnotationsList(annotations);
if (past) {
annotations.add(new AnnotationMetadataBuilder(PAST));
}
if (future) {
annotations.add(new AnnotationMetadataBuilder(FUTURE));
}
if (persistenceType != null) {
// Add JSR 220 @Temporal annotation
String value = null;
if (persistenceType == DateFieldPersistenceType.JPA_DATE) {
value = "DATE";
} else if (persistenceType == DateFieldPersistenceType.JPA_TIME) {
value = "TIME";
} else if (persistenceType == DateFieldPersistenceType.JPA_TIMESTAMP) {
value = "TIMESTAMP";
}
final List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
attrs.add(new EnumAttributeValue(new JavaSymbolName("value"), new EnumDetails(TEMPORAL_TYPE, new JavaSymbolName(value))));
annotations.add(new AnnotationMetadataBuilder(TEMPORAL, attrs));
}
// Only add a DateTimeFormat annotation if class is not a DTO
final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
if (pattern != null) {
attributes.add(new StringAttributeValue(new JavaSymbolName("pattern"), pattern));
} else {
final String dateStyle = null != dateFormat ? String.valueOf(dateFormat.getShortKey()) : "M";
final String timeStyle = null != timeFormat ? String.valueOf(timeFormat.getShortKey()) : "-";
attributes.add(new StringAttributeValue(new JavaSymbolName("style"), dateStyle + timeStyle));
}
annotations.add(new AnnotationMetadataBuilder(DATE_TIME_FORMAT, attributes));
}
Aggregations