Search in sources :

Example 26 with StringAttributeValue

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;
}
Also used : ArrayAttributeValue(org.springframework.roo.classpath.details.annotations.ArrayAttributeValue) AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) ArrayList(java.util.ArrayList) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) List(java.util.List) ArrayList(java.util.ArrayList) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 27 with StringAttributeValue

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;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) EnumDetails(org.springframework.roo.model.EnumDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 28 with StringAttributeValue

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));
    }
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 29 with StringAttributeValue

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));
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)29 ArrayList (java.util.ArrayList)28 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)27 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)23 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)23 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)12 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)10 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)10 EnumDetails (org.springframework.roo.model.EnumDetails)9 List (java.util.List)8 JavaType (org.springframework.roo.model.JavaType)8 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)7 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)7 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)6 IntegerAttributeValue (org.springframework.roo.classpath.details.annotations.IntegerAttributeValue)5 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)4 CharAttributeValue (org.springframework.roo.classpath.details.annotations.CharAttributeValue)4 DoubleAttributeValue (org.springframework.roo.classpath.details.annotations.DoubleAttributeValue)4 LongAttributeValue (org.springframework.roo.classpath.details.annotations.LongAttributeValue)4