List of usage examples for org.apache.commons.lang3 StringUtils capitalize
public static String capitalize(final String str)
Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java
private void buildRenderUpdateFormsMethodBody(InvocableMemberBodyBuilder bodyBuilder) { // // Prepare result bodyBuilder.appendFormalLine("// Prepare result"); // List<Map<String, String>> result = new ArrayList<Map<String, // String>>(vets.size()); bodyBuilder.appendFormalLine(/*from w w w . j av a2 s. co m*/ String.format("%s result = new %s(%s.size());", helper.getFinalTypeName(LIST_MAP_STRING_STRING), helper.getFinalTypeName(ARRAYLIST_MAP_STRING_STRING), entityList)); // String controllerPath = "vets"; bodyBuilder.appendFormalLine( String.format("String controllerPath = \"%s\";", webScaffoldAnnotationValues.getPath())); // String pageToUse = "update"; bodyBuilder.appendFormalLine("String pageToUse = \"update\";"); // String renderUrl = String.format("/WEB-INF/views/%s/%s.jspx", // controllerPath, pageToUse); bodyBuilder.appendFormalLine( "String renderUrl = String.format(\"/WEB-INF/views/%s/%s.jspx\", controllerPath, pageToUse);"); // // For every element bodyBuilder.appendFormalLine("// For every element"); // for (Vet vet : vets) { bodyBuilder.appendFormalLine( String.format("for (%s %s : %s) {", helper.getFinalTypeName(entity), entityName, entityList)); bodyBuilder.indent(); // Map<String, String> item = new HashMap<String, String>(); bodyBuilder.appendFormalLine(String.format("%s item = new %s();", helper.getFinalTypeName(MAP_STRING_STRING), helper.getFinalTypeName(HASHMAP_STRING_STRING))); // final StringWriter buffer = new StringWriter(); bodyBuilder.appendFormalLine(String.format("final %s buffer = new %s();", helper.getFinalTypeName(STRING_WRITER), helper.getFinalTypeName(STRING_WRITER))); // // Call JSP to render update form bodyBuilder.appendFormalLine("// Call JSP to render update form"); // RequestDispatcher dispatcher = // request.getRequestDispatcher(renderUrl); bodyBuilder.appendFormalLine(String.format("%s dispatcher = %s.getRequestDispatcher(renderUrl);", helper.getFinalTypeName(REQUEST_DISPATCHER), REQUEST_PARAM_NAME.getSymbolName())); // populateItemForRender(request, vet, true); bodyBuilder.appendFormalLine(String.format("populateItemForRender(%s, %s, true);", REQUEST_PARAM_NAME.getSymbolName(), entityName)); // dispatcher.include(request, new HttpServletResponseWrapper(response) // { bodyBuilder.appendFormalLine(String.format("dispatcher.include(%s, new %s(response) {", REQUEST_PARAM_NAME.getSymbolName(), helper.getFinalTypeName(HTTP_SERVLET_RESPONSE_WRAPPER))); bodyBuilder.indent(); bodyBuilder.appendFormalLine(""); String printWriter = helper.getFinalTypeName(PRINT_WRITER); // private PrintWriter writer = new PrintWriter(buffer); bodyBuilder.appendFormalLine( String.format("private %s writer = new PrintWriter(buffer);", printWriter, printWriter)); bodyBuilder.appendFormalLine(""); // @Override bodyBuilder.appendFormalLine("@Override"); // public PrintWriter getWriter() throws IOException { bodyBuilder.appendFormalLine(String.format("public %s getWriter() throws %s {", printWriter, helper.getFinalTypeName(IO_EXCEPTION))); bodyBuilder.indent(); // return writer; bodyBuilder.appendFormalLine("return writer;"); // } bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // }); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("});"); // String render = buffer.toString(); bodyBuilder.appendFormalLine("String render = buffer.toString();"); // // Load item id bodyBuilder.appendFormalLine("// Load item id"); String idAccessor = "get".concat(StringUtils.capitalize(entityIdentifier.getFieldName().getSymbolName())); // item.put("DT_RowId", // conversionService_datatables.convert(vet.getId(), String.class)); bodyBuilder.appendFormalLine(String.format("item.put(\"DT_RowId\", %s.convert(%s.%s(), String.class));", getConversionServiceField().getFieldName().getSymbolName(), entityName, idAccessor)); // // Put rendered content into first column bodyBuilder.appendFormalLine("// Put rendered content into first column"); // item.put("form", render); bodyBuilder.appendFormalLine("item.put(\"form\", render);"); // result.add(item); bodyBuilder.appendFormalLine("result.add(item);"); // } bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // return result; bodyBuilder.appendFormalLine("return result;"); }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java
/** * Builds the method body of <code>renderXXX</code> method. <br> * This method renders the required jspx for item an store it in a List of * Map(String,String)//from ww w . ja va 2 s . com * * @param bodyBuilder */ private void buildRenderItemsMethodBody(InvocableMemberBodyBuilder bodyBuilder) { String entityTypeName = helper.getFinalTypeName(entity); bodyBuilder.appendFormalLine(""); bodyBuilder.appendFormalLine("// Prepare result"); /* * List<Pets> pets = searchResult.getResults(); */ bodyBuilder.appendFormalLine(String.format("%s %s = searchResult.getResults();", helper.getFinalTypeName(entityListType), entityList)); /* * List<Map<String, String>> result = new ArrayList<Map<String, * String>>(); */ bodyBuilder.appendFormalLine( String.format("%s result = new %s(%s.size());", helper.getFinalTypeName(LIST_MAP_STRING_STRING), helper.getFinalTypeName(ARRAYLIST_MAP_STRING_STRING), entityList)); bodyBuilder.appendFormalLine( String.format("String controllerPath = \"%s\";", webScaffoldAnnotationValues.getPath())); bodyBuilder.appendFormalLine(String.format("String pageToUse = \"%s\";", annotationValues.getMode())); bodyBuilder.appendFormalLine( "String renderUrl = String.format(\"/WEB-INF/views/%s/%s.jspx\", controllerPath, pageToUse);"); bodyBuilder.appendFormalLine(""); bodyBuilder.appendFormalLine("// For every element"); // for (Pet pet : owners) { bodyBuilder.appendFormalLine(String.format("for (%s %s: %s) {", entityTypeName, entityName, entityList)); bodyBuilder.indent(); // Map<String, String> row = new HashMap<String, String>(); bodyBuilder.appendFormalLine(String.format("%s item = new %s();", helper.getFinalTypeName(MAP_STRING_STRING), helper.getFinalTypeName(HASHMAP_STRING_STRING))); // final StringWriter buffer = new StringWriter(); bodyBuilder.appendFormalLine(String.format("final %s buffer = new %s();", helper.getFinalTypeName(STRING_WRITER), helper.getFinalTypeName(STRING_WRITER))); // TODO Check it can get dispatcher outside of for bodyBuilder.appendFormalLine("// Call JSP to render current entity"); // RequestDispatcher dispatcher = // request.getRequestDispatcher("/WEB-INF/views/owners/show.jspx"); bodyBuilder.appendFormalLine(String.format("%s dispatcher = %s.getRequestDispatcher(renderUrl);", helper.getFinalTypeName(REQUEST_DISPATCHER), REQUEST_PARAM_NAME.getSymbolName())); bodyBuilder.appendFormalLine(""); // populateItemForRender(request, pet, false); bodyBuilder.appendFormalLine(String.format("populateItemForRender(%s, %s, false);", REQUEST_PARAM_NAME.getSymbolName(), entityName)); // dispatcher.include(request, new HttpServletResponseWrapper(response) // { bodyBuilder.appendFormalLine(String.format("dispatcher.include(%s, new %s(%s) {", REQUEST_PARAM_NAME.getSymbolName(), helper.getFinalTypeName(HTTP_SERVLET_RESPONSE_WRAPPER), RESPONSE_PARAM_NAME.getSymbolName())); bodyBuilder.indent(); // private PrintWriter writer = new PrintWriter(buffer); bodyBuilder.appendFormalLine(String.format("private %s writer = new %s(buffer);", helper.getFinalTypeName(PRINT_WRITER), helper.getFinalTypeName(PRINT_WRITER))); // @Override bodyBuilder.appendFormalLine("@Override"); // public PrintWriter getWriter() throws IOException { bodyBuilder.appendFormalLine(String.format("public %s getWriter() throws %s {", helper.getFinalTypeName(PRINT_WRITER), helper.getFinalTypeName(IO_EXCEPTION))); bodyBuilder.indent(); // return writer; bodyBuilder.appendFormalLine("return writer;"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("});"); bodyBuilder.appendFormalLine(""); // String render = buffer.toString(); bodyBuilder.appendFormalLine("String render = buffer.toString();"); bodyBuilder.appendFormalLine("// Load item id)"); // row.put("DT_RowId", // conversionService_datatables.convert(owner.getId(), String.class)); bodyBuilder.appendFormalLine(String.format("item.put(\"DT_RowId\", %s.convert(%s.get%s(), String.class));", getConversionServiceField().getFieldName().getSymbolName(), entityName, StringUtils.capitalize(entityIdentifier.getFieldName().getSymbolName()))); bodyBuilder.appendFormalLine("// Put rendered content into first column (uses column index)"); // row.put(Integer.toString(rowIdx), showOwner); bodyBuilder.appendFormalLine("item.put(\"0\", render);"); bodyBuilder.appendFormalLine(""); bodyBuilder.appendFormalLine("result.add(item);"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(""); bodyBuilder.appendFormalLine("return result;"); }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java
/** * Builds body method for <code>getFindByParameters</code> method. <br> * This method generates a item List based on a parameters received in the * request. Used by DOM mode listDatatables. * /*from w ww . j ava 2 s . c o m*/ * @param bodyBuilder */ private void buildFindByParametersMapMethodBody(InvocableMemberBodyBuilder bodyBuilder) { // Gets propertyMap bodyBuilder.appendFormalLine("// Gets propertyMap"); // Map<String, Object> propertyMap = getPropertyMap(visit, // propertyNames); bodyBuilder.appendFormalLine(String.format("%s propertyMap = %s(%s, propertyNames);", helper.getFinalTypeName(MAP_STRING_OBJECT), GET_PROPERTY_MAP.getSymbolName(), entityName)); // bodyBuilder.appendFormalLine(""); // // // if there is a filter bodyBuilder.appendFormalLine("// if there is a filter"); // if (!propertyMap.isEmpty()) { bodyBuilder.appendFormalLine("if (!propertyMap.isEmpty()) {"); bodyBuilder.indent(); // // Prepare a predicate bodyBuilder.appendFormalLine("// Prepare a predicate"); // BooleanBuilder baseFilterPredicate = new BooleanBuilder(); bodyBuilder.appendFormalLine(String.format("%s baseFilterPredicate = new %s();", helper.getFinalTypeName(QDSL_BOOLEAN_BUILDER), helper.getFinalTypeName(QDSL_BOOLEAN_BUILDER))); bodyBuilder.appendFormalLine(""); // // Base filter. Using BooleanBuilder, a cascading builder for bodyBuilder.appendFormalLine("// Base filter. Using BooleanBuilder, a cascading builder for"); // // Predicate expressions bodyBuilder.appendFormalLine("// Predicate expressions"); // PathBuilder<Visit> entity = new PathBuilder<Visit>(Visit.class, // "entity"); bodyBuilder.appendFormalLine(String.format("%s<%s> entity = new %s<%s>(%s.class, \"entity\");", helper.getFinalTypeName(QDSL_PATH_BUILDER), helper.getFinalTypeName(entity), helper.getFinalTypeName(QDSL_PATH_BUILDER), helper.getFinalTypeName(entity), helper.getFinalTypeName(entity))); bodyBuilder.appendFormalLine(""); // // // Build base filter bodyBuilder.appendFormalLine("// Build base filter"); // for (String key : propertyMap.keySet()) { bodyBuilder.appendFormalLine("for (String key : propertyMap.keySet()) {"); bodyBuilder.indent(); // baseFilterPredicate.and(entity.get(key).eq(propertyMap.get(key))); bodyBuilder.appendFormalLine("baseFilterPredicate.and(entity.get(key).eq(propertyMap.get(key)));"); // } bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(""); // // // Create a query with filter bodyBuilder.appendFormalLine("// Create a query with filter"); // JPAQuery query = new JPAQuery(Visit.entityManager()); // JPAQuery query = new // JPAQuery(entityManagerProvider_dtt.getEntityManager(Vet.class)); bodyBuilder.appendFormalLine(String.format("%s query = new %s(%s.getEntityManager(%s.class));", helper.getFinalTypeName(QDSL_JPA_QUERY), helper.getFinalTypeName(QDSL_JPA_QUERY), DATATABLES_MANAGER_PROVIDER_NAME, helper.getFinalTypeName(entity))); // query = query.from(entity); bodyBuilder.appendFormalLine("query = query.from(entity);"); // bodyBuilder.appendFormalLine(""); // // execute query bodyBuilder.appendFormalLine("// execute query"); // return query.where(baseFilterPredicate).list(entity); bodyBuilder.appendFormalLine("return query.where(baseFilterPredicate).list(entity);"); // } bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(""); // // // no filter: return all elements bodyBuilder.appendFormalLine("// no filter: return all elements"); // return Visit.findAllVisits(); bodyBuilder.appendFormalLine(String.format("return %s.findAll%s();", helper.getFinalTypeName(entity), StringUtils.capitalize(entityPlural))); }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java
private void createBaseSearchExpressionWithNullCheck(InvocableMemberBodyBuilder bodyBuilder, FinderToDslHelper fHelper, FieldToken lastFieldToken, StringBuilder expBuilder, String operation) { // Getting fieldName and fieldType String fieldName = lastFieldToken.getField().getFieldName().getSymbolName(); JavaType fieldType = lastFieldToken.getField().getFieldType(); // Booleans doesn't need null validation if (JavaType.BOOLEAN_PRIMITIVE.equals(fieldType) || JavaType.BOOLEAN_OBJECT.equals(fieldType)) { bodyBuilder.appendFormalLine(fHelper.getDslAnd(expBuilder.toString())); } else {//from w w w. ja v a 2s. co m String nullExpression = ""; String dslOperation = ""; String dslOperationNull = ""; String nullValidation = ""; if ("and".equals(operation)) { nullExpression = String.format("entity%s.isNull()", fHelper.getDslGetterFor(fieldName, fieldType)); dslOperation = fHelper.getDslAnd(expBuilder.toString()); dslOperationNull = fHelper.getDslAnd(nullExpression); nullValidation = String.format("if(%s != null){", fieldName); } else if ("or".equals(operation)) { nullExpression = String.format("entity%s.isNull()", fHelper.getDslGetterFor(fieldName, fieldType)); dslOperation = fHelper.getDslOr(expBuilder.toString()); dslOperationNull = fHelper.getDslOr(nullExpression); nullValidation = String.format("if(%s != null){", fieldName); } else if ("between".equals(operation)) { // Getting min max variables String capitalized = StringUtils.capitalize(fieldName); String min = "min".concat(capitalized); String max = "max".concat(capitalized); // Generating expression expBuilder.append(fHelper.getBetweenExpression(fieldName)); nullExpression = String.format("entity%s.isNull()", fHelper.getDslGetterFor(fieldName, fieldType)); dslOperation = fHelper.getDslAnd(expBuilder.toString()); dslOperationNull = fHelper.getDslAnd(nullExpression); nullValidation = String.format("if(%s != null && %s != null){", min, max); } if (fieldType.isCommonCollectionType()) { String colType = fieldType.getSimpleTypeName().toString(); nullExpression = String.format("entity.getCollection(\"%s\", %s.class).isEmpty()", fieldName, colType); dslOperation = fHelper.getDslAnd(expBuilder.toString()); dslOperationNull = fHelper.getDslAnd(nullExpression); nullValidation = String.format("if(%s != null){", fieldName); } // There is an expression not included in predicate yet. // Include it using "and" join if (expBuilder != null && StringUtils.isNotBlank(nullExpression)) { bodyBuilder.appendFormalLine(nullValidation); // filterCondition.and( {exp}); bodyBuilder.indent(); bodyBuilder.appendFormalLine(dslOperation); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}else{"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(dslOperationNull); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); } } }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java
/** * Build standard body method for <code>populateItemForRender</code> method <br> * This methods prepares request attributes to render a entity item in * non-standard render mode. User can make push-in of this method to * customize the parameters received on target .jspx view. * // w w w . j ava 2s. c o m * @param bodyBuilder */ private void buildPopulateItemForRenderMethodBody(InvocableMemberBodyBuilder bodyBuilder) { // Model uiModel = new ExtendedModelMap(); bodyBuilder.appendFormalLine(String.format("%s uiModel = new %s();", MODEL, EXTENDED_MODEL_MAP)); bodyBuilder.appendFormalLine(""); // request.setAttribute("pet", pet); bodyBuilder .appendFormalLine(String.format("%s.setAttribute(\"%s\", %s);", REQUEST_PARAM_NAME.getSymbolName(), StringUtils.uncapitalize(entityName), StringUtils.uncapitalize(entityName) )); // request.setAttribute("itemId", // conversion_service.convert(pet.getId(), String.class); bodyBuilder.appendFormalLine(String.format( "%s.setAttribute(\"itemId\", %s.convert(%s.get%s(),String.class));", REQUEST_PARAM_NAME.getSymbolName(), getConversionServiceField().getFieldName().getSymbolName(), StringUtils.uncapitalize(entityName), StringUtils.capitalize(entityIdentifier.getFieldName().getSymbolName()))); bodyBuilder.appendFormalLine(""); // if (editing) { bodyBuilder.appendFormalLine("if (editing) {"); bodyBuilder.indent(); // // spring from:input tag uses BindingResult to locate property // editors for each bean // // property. So, we add a request attribute (required key id // BindingResult.MODEL_KEY_PREFIX + object name) // // with a correctly initialized bindingResult. bodyBuilder.appendFormalLine( "// spring from:input tag uses BindingResult to locate property editors for each bean"); bodyBuilder.appendFormalLine( "// property. So, we add a request attribute (required key id BindingResult.MODEL_KEY_PREFIX + object name)"); bodyBuilder.appendFormalLine("// with a correctly initialized bindingResult."); // BeanPropertyBindingResult bindindResult = new // BeanPropertyBindingResult(vet, "vet"); bodyBuilder.appendFormalLine(String.format("%s bindindResult = new %s(%s, \"%s\");", helper.getFinalTypeName(BEAN_PROPERTY_BINDING_RESULT), helper.getFinalTypeName(BEAN_PROPERTY_BINDING_RESULT), StringUtils.uncapitalize(entityName), StringUtils.uncapitalize(entityName))); // bindindResult.initConversion(conversionService_datatables); bodyBuilder.appendFormalLine(String.format("bindindResult.initConversion(%s);", getConversionServiceField().getFieldName().getSymbolName())); // request.setAttribute(BindingResult.MODEL_KEY_PREFIX + // "vet",bindindResult); bodyBuilder.appendFormalLine(String.format("%s.setAttribute(%s.MODEL_KEY_PREFIX + \"%s\",bindindResult);", REQUEST_PARAM_NAME.getSymbolName(), helper.getFinalTypeName(SpringJavaType.BINDING_RESULT), StringUtils.uncapitalize(entityName))); // // Add date time patterns and enums to populate inputs bodyBuilder.appendFormalLine("// Add date time patterns and enums to populate inputs"); // populateEditForm(uiModel, vet); bodyBuilder.appendFormalLine( String.format("populateEditForm(uiModel, %s);", StringUtils.uncapitalize(entityName))); if (!entityDatePatterns.isEmpty()) { // } else { bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine(ELSE); bodyBuilder.indent(); // // Add date time patterns bodyBuilder.appendFormalLine("// Add date time patterns"); // Add date patterns (if any) // Delegates on Roo standard populate date patterns method // addDateTimeFormatPatterns(uiModel); bodyBuilder.appendFormalLine("addDateTimeFormatPatterns(uiModel);"); } // } bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); bodyBuilder.appendFormalLine(""); // Load uiModel attributes into request bodyBuilder.appendFormalLine("// Load uiModel attributes into request"); // Map<String,Object> modelMap = uiModel.asMap(); bodyBuilder.appendFormalLine( String.format("%s modelMap = uiModel.asMap();", helper.getFinalTypeName(MAP_STRING_OBJECT))); // for (Entry<String,Object> entry : uiModel.asMap().entrySet()){ bodyBuilder.appendFormalLine( String.format("for (%s key : modelMap.keySet()){", helper.getFinalTypeName(JavaType.STRING))); bodyBuilder.indent(); // request.setAttribute(entry.getKey(), entry.getValue()); bodyBuilder.appendFormalLine("request.setAttribute(key, modelMap.get(key));"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java
/** * Returns export method for a specific format for a render-a-view * visualization mode./*from w w w . j ava2 s .c o m*/ * <p /> * This method handles datatables AJAX request for export data to a format * specified in the @{code exportType} parameter. * * @param exportType the export type: csv, xml, pdf, etc. * @param exportTypeJavaType the @{code JavaType} of the export type. * @return */ private MethodMetadata getExportFormatMethod(String exportType, JavaType exportTypeJavaType) { String exportTypeUpperCase = StringUtils.upperCase(exportType); String exportTypeCapitalized = StringUtils.capitalize(exportType); /* * @RequestMapping(value = "/exportcsv", produces = "text/csv") public * void PetController.exportCsv( * * @DatatablesParams DatatablesCriterias criterias, * * @ModelAttribute Pet pet, HttpServletRequest request, * HttpServletResponse response) throws ServletException, IOException, * ExportException { ... } */ // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); parameterTypes.add(new AnnotatedJavaType(DATATABLES_CRITERIA_TYPE, new AnnotationMetadataBuilder(DATATABLES_PARAMS).build())); parameterTypes.add(new AnnotatedJavaType(entity, new AnnotationMetadataBuilder(MODEL_ATTRIBUTE).build())); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST)); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE)); // Building method name JavaSymbolName methodName = new JavaSymbolName("export".concat(exportTypeCapitalized)); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder(); methodAnnotation.setAnnotationType(REQUEST_MAPPING); methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_VAL_NAME, "/export".concat(exportType)); methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_PROD_NAME, "text/".concat(exportType)); annotations.add(methodAnnotation); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); throwsTypes.add(SERVLET_EXCEPTION); throwsTypes.add(IO_EXCEPTION); throwsTypes.add(DATATABLES_EXPORT_EXCEPTION); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(CRITERIA_PARAM_NAME); parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entityName))); parameterNames.add(REQUEST_PARAM_NAME); parameterNames.add(RESPONSE_PARAM_NAME); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); /* * export(criterias, pet, ExportType.CSV, new CsvExport(), request, * response); */ String format = "export(%s, %s, %s.".concat(exportTypeUpperCase).concat(", new %s(), %s, %s);"); bodyBuilder.appendFormalLine(String.format(format, CRITERIA_PARAM_NAME.getSymbolName(), StringUtils.uncapitalize(entityName), helper.getFinalTypeName(DATATABLES_EXPORT_TYPE), helper.getFinalTypeName(exportTypeJavaType), REQUEST_PARAM_NAME.getSymbolName(), RESPONSE_PARAM_NAME.getSymbolName())); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadataProvider.java
/** * Locates All {@link FinderMetadataDetails} and its related * {@link QueryHolder} for every declared dynamic finder <br> * <br>/*from www.j ava 2s .co m*/ * <em>Note:</em> This method is similar to * {@link WebMetadataServiceImpl#getDynamicFinderMethodsAndFields(JavaType, MemberDetails, String)} * but without register dependency (this dependency produces NPE in * {@link #getMetadata(String, JavaType, PhysicalTypeMetadata, String)} when * it tries to get JPA information) * * @param entity * @param path * @param entityMemberDetails * @param plural * @param entityName * @return * @see WebMetadataServiceImpl#getDynamicFinderMethodsAndFields(JavaType, * MemberDetails, String) */ private Map<FinderMetadataDetails, QueryHolderTokens> getFindersRegisterd(JavaType entity, LogicalPath path, MemberDetails entityMemberDetails, String plural, String entityName) { // Get finder metadata final String finderMetadataKey = FinderMetadata.createIdentifier(entity, path); final FinderMetadata finderMetadata = (FinderMetadata) getMetadataService().get(finderMetadataKey); if (finderMetadata == null) { return null; } QueryHolderTokens queryHolder; FinderMetadataDetails details; Map<FinderMetadataDetails, QueryHolderTokens> findersRegistered = new HashMap<FinderMetadataDetails, QueryHolderTokens>(); // Iterate over for (final MethodMetadata method : finderMetadata.getAllDynamicFinders()) { final List<JavaSymbolName> parameterNames = method.getParameterNames(); final List<JavaType> parameterTypes = AnnotatedJavaType .convertFromAnnotatedJavaTypes(method.getParameterTypes()); final List<FieldMetadata> fields = new ArrayList<FieldMetadata>(); for (int i = 0; i < parameterTypes.size(); i++) { JavaSymbolName fieldName = null; if (parameterNames.get(i).getSymbolName().startsWith("max") || parameterNames.get(i).getSymbolName().startsWith("min")) { fieldName = new JavaSymbolName(Introspector.decapitalize( StringUtils.capitalize(parameterNames.get(i).getSymbolName().substring(3)))); } else { fieldName = parameterNames.get(i); } final FieldMetadata field = BeanInfoUtils.getFieldForPropertyName(entityMemberDetails, fieldName); if (field != null) { final FieldMetadataBuilder fieldMd = new FieldMetadataBuilder(field); fieldMd.setFieldName(parameterNames.get(i)); fields.add(fieldMd.build()); } } details = new FinderMetadataDetails(method.getMethodName().getSymbolName(), method, fields); // locate QueryHolder instances. This objects contain // information about a roo finder (parameters names and types // and a "token" list with of find definition queryHolder = getQueryHolder(entityMemberDetails, method.getMethodName(), plural, entityName); findersRegistered.put(details, queryHolder); } return findersRegistered; }
From source file:org.gvnix.addon.datatables.addon.FinderToDslHelper.java
public Object getBetweenExpression(String fieldName) { String capitalized = StringUtils.capitalize(fieldName); String min = "min".concat(capitalized); String max = "max".concat(capitalized); return String.format(".between(%s,%s)", min, max); }
From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java
/** * Initialize all entity name dependent methods-names and javaTypes */// w ww . j a v a 2 s.c o m private void initializeEntityDependenDefinitions() { this.findAllMethodName = new JavaSymbolName("findAll".concat(StringUtils.capitalize(this.entityPlural))); this.findMethodName = new JavaSymbolName("find".concat(StringUtils.capitalize(entityName))); this.getRevisionsMethodName = new JavaSymbolName( "get".concat(StringUtils.capitalize(entityName)).concat("Revisions")); this.findRevisionsByDatesMethodName = new JavaSymbolName( "find".concat(StringUtils.capitalize(entityName).concat("RevisionsByDates"))); this.findRevisionsMethodName = new JavaSymbolName( "find".concat(StringUtils.capitalize(entityName).concat("Revisions"))); this.revisonItemTypeName = StringUtils.capitalize(entityName).concat("Revision"); this.revisonItemType = new JavaType( entity.getFullyQualifiedTypeName().concat(".").concat(revisonItemTypeName)); this.revisonItemListType = new JavaType(LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(revisonItemType)); }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java
/** * {@inheritDoc}//from w w w .ja va 2 s.co m */ @Override public void buildBodyFindAllFromRevision(InvocableMemberBodyBuilder body, List<JavaSymbolName> parameterNames) { // return auditReader().createQuery().forEntitiesAtRevision(Visit.class, // revision).getResultList(); body.appendFormalLine( String.format("return %s().createQuery().forEntitiesAtRevision(%s.class, %s).getResultList();", AUDIT_READER_STATIC_METHOD, StringUtils.capitalize(context.getEntityName()), parameterNames.get(0))); }