private AnnotationMetadataBuilder buildEntityFormatAnnotation( final String entityFormatExpression, final String entityFormatMessage, final String fieldName) { final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); // Check for each attribute individually if (StringUtils.isNotBlank(entityFormatExpression)) { entityFormatBuilder.addStringAttribute("value", entityFormatExpression); } if (StringUtils.isNotBlank(entityFormatMessage)) { entityFormatBuilder.addStringAttribute("message", entityFormatMessage); } return entityFormatBuilder; }
private AnnotationMetadataBuilder getRequestMappingAnnotation() { AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_MAPPING); // Adding path attribute annotationBuilder.addStringAttribute("value", controllerMetadata.getRequestMappingValue()); // Add name attribute annotationBuilder.addStringAttribute("name", this.getMvcControllerName()); // Add produces annotationBuilder.addEnumAttribute("produces", SpringEnumDetails.MEDIA_TYPE_TEXT_HTML_VALUE); return annotationBuilder; }
/** * Generates the Springlets `@EntityFormat` annotation to be applied to the projection * * @return AnnotationMetadata */ private AnnotationMetadata getEntityFormatAnnotation() { String expressionAttribute = this.annotationValues.getFormatExpression(); String messageAttribute = this.annotationValues.getFormatMessage(); final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); // Check for each attribute individually if (StringUtils.isNotBlank(expressionAttribute)) { entityFormatBuilder.addStringAttribute("value", expressionAttribute); } if (StringUtils.isNotBlank(messageAttribute)) { entityFormatBuilder.addStringAttribute("message", messageAttribute); } return entityFormatBuilder.build(); }
/** * Generates the Springlets `@EntityFormat` annotation to be applied to the dto * * @return AnnotationMetadata */ private AnnotationMetadata getEntityFormatAnnotation() { String expressionAttribute = this.annotationValues.getFormatExpression(); String messageAttribute = this.annotationValues.getFormatMessage(); final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); // Check for each attribute individually if (StringUtils.isNotBlank(expressionAttribute)) { entityFormatBuilder.addStringAttribute("value", expressionAttribute); } if (StringUtils.isNotBlank(messageAttribute)) { entityFormatBuilder.addStringAttribute("message", messageAttribute); } return entityFormatBuilder.build(); }
private AnnotationMetadataBuilder getRequestMappingAnnotation() { AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_MAPPING); // Adding path attribute annotationBuilder.addStringAttribute("value", controllerMetadata.getRequestMappingValue()); // Add name attribute annotationBuilder.addStringAttribute("name", getDestination().getSimpleTypeName()); // Add produces annotationBuilder.addEnumAttribute("produces", SpringEnumDetails.MEDIA_TYPE_APPLICATION_JSON_VALUE); return annotationBuilder; }
/** * Generates the JPA @Table annotation to be applied to the entity * * @param annotationValues * @return */ private AnnotationMetadata getTableAnnotation() { final AnnotationMetadata tableAnnotation = getTypeAnnotation(TABLE); if (tableAnnotation == null) { return null; } final String catalog = annotationValues.getCatalog(); final String schema = annotationValues.getSchema(); final String table = annotationValues.getTable(); if (StringUtils.isNotBlank(table) || StringUtils.isNotBlank(schema) || StringUtils.isNotBlank(catalog)) { final AnnotationMetadataBuilder tableBuilder = new AnnotationMetadataBuilder(tableAnnotation); if (StringUtils.isNotBlank(catalog)) { tableBuilder.addStringAttribute("catalog", catalog); } if (StringUtils.isNotBlank(schema)) { tableBuilder.addStringAttribute("schema", schema); } if (StringUtils.isNotBlank(table)) { tableBuilder.addStringAttribute("name", table); } return tableBuilder.build(); } return null; }
/** * Generates the Springlets `@EntityFormat` annotation to be applied to the entity * * @return AnnotationMetadata */ private AnnotationMetadata getEntityFormatAnnotation() { AnnotationMetadata entityFormatAnnotation = getTypeAnnotation(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); if (entityFormatAnnotation == null) { return null; } String expressionAttribute = this.annotationValues.getEntityFormatExpression(); String messageAttribute = this.annotationValues.getEntityFormatMessage(); final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(entityFormatAnnotation); // Check for each attribute individually if (StringUtils.isNotBlank(expressionAttribute)) { entityFormatBuilder.addStringAttribute("value", expressionAttribute); } if (StringUtils.isNotBlank(messageAttribute)) { entityFormatBuilder.addStringAttribute("message", messageAttribute); } entityFormatAnnotation = entityFormatBuilder.build(); return entityFormatAnnotation; }
/** * Method that returns @RooDetail annotation * * @param relationField * Field that set the relationship * @param viewsList * Separated comma list that defines the parent views where the * new detail will be displayed. * @return */ private AnnotationMetadataBuilder getRooDetailAnnotation(final String relationField, final String viewsList) { AnnotationMetadataBuilder annotationDetail = new AnnotationMetadataBuilder(RooJavaType.ROO_DETAIL); annotationDetail.addStringAttribute(RELATION_FIELD_KEY, relationField); // Including views attribute if needed if (StringUtils.isNotEmpty(viewsList)) { String[] views = viewsList.split(","); List<StringAttributeValue> viewsValues = new ArrayList<StringAttributeValue>(); for (String view : views) { viewsValues.add(new StringAttributeValue(VALUE_SYM, view)); } ArrayAttributeValue<StringAttributeValue> viewsAttr = new ArrayAttributeValue<StringAttributeValue>(VIEWS_SYM, viewsValues); annotationDetail.addAttribute(viewsAttr); } return annotationDetail; }
/** * Generates the JPA @Entity annotation to be applied to the entity * * @return */ private AnnotationMetadata getEntityAnnotation() { AnnotationMetadata entityAnnotation = getTypeAnnotation(ENTITY); if (entityAnnotation == null) { return null; } if (StringUtils.isNotBlank(annotationValues.getEntityName())) { final AnnotationMetadataBuilder entityBuilder = new AnnotationMetadataBuilder(entityAnnotation); entityBuilder.addStringAttribute("name", annotationValues.getEntityName()); entityAnnotation = entityBuilder.build(); } return entityAnnotation; }
private void setDateAnnotations(final String columnDefinition, final List<AnnotationMetadataBuilder> annotations) { // Add JSR 220 @Temporal annotation to date fields String temporalType = StringUtils.defaultIfEmpty(StringUtils.upperCase(columnDefinition), "DATE"); if ("DATETIME".equals(temporalType)) { temporalType = "TIMESTAMP"; // ROO-2606 } final AnnotationMetadataBuilder temporalBuilder = new AnnotationMetadataBuilder(TEMPORAL); temporalBuilder.addEnumAttribute("value", new EnumDetails(TEMPORAL_TYPE, new JavaSymbolName( temporalType))); annotations.add(temporalBuilder); final AnnotationMetadataBuilder dateTimeFormatBuilder = new AnnotationMetadataBuilder(DATE_TIME_FORMAT); dateTimeFormatBuilder.addStringAttribute("style", "M-"); annotations.add(dateTimeFormatBuilder); } }
preauthorizeAnnotation.addStringAttribute("value", entry.getValue()); DeclaredMethodAnnotationDetails preauthorizeAnnotationInGetterMethod = new DeclaredMethodAnnotationDetails(entry.getKey(), preauthorizeAnnotation.build());
/** * Builds modifiedBy field for storing user who last modifies entity registers * * @return FieldMetadataBuilder */ private FieldMetadataBuilder getModifiedByField(ClassOrInterfaceTypeDetails entityDetails, String columnName) { // Create field annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Only add @Column if required by annotation @RooJpaAudit if (StringUtils.isNotBlank(columnName)) { AnnotationMetadataBuilder columnAnnotation = new AnnotationMetadataBuilder(JpaJavaType.COLUMN); columnAnnotation.addStringAttribute("name", columnName); annotations.add(columnAnnotation); } AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.LAST_MODIFIED_BY); annotations.add(createdDateAnnotation); // Create field FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JavaType.STRING, new JavaSymbolName("modifiedBy")); fieldDetails.setModifiers(Modifier.PRIVATE); fieldDetails.setAnnotations(annotations); FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails); return fieldBuilder; }
/** * Builds createdBy field for storing user who creates entity registers * * @return FieldMetadataBuilder */ private FieldMetadataBuilder getCreatedByField(ClassOrInterfaceTypeDetails entityDetails, String columnName) { // Create field annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Only add @Column if required by annotation @RooJpaAudit if (StringUtils.isNotBlank(columnName)) { AnnotationMetadataBuilder columnAnnotation = new AnnotationMetadataBuilder(JpaJavaType.COLUMN); columnAnnotation.addStringAttribute("name", columnName); annotations.add(columnAnnotation); } AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.CREATED_BY); annotations.add(createdDateAnnotation); // Create field FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JavaType.STRING, new JavaSymbolName("createdBy")); fieldDetails.setModifiers(Modifier.PRIVATE); fieldDetails.setAnnotations(annotations); FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails); return fieldBuilder; }
/** * This method generates the version field using the provided values * * @param entity * @param versionField * @param versionType * @param versionColumn * @return */ private FieldMetadata getVersionField(final JavaType entity, String versionField, final JavaType versionType, final String versionColumn) { if (StringUtils.isEmpty(versionField)) { versionField = "version"; } final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(new AnnotationMetadataBuilder(VERSION)); if (StringUtils.isNotEmpty(versionColumn)) { final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(COLUMN); columnBuilder.addStringAttribute("name", versionColumn); annotations.add(columnBuilder); } FieldDetails versionFieldDetails = new FieldDetails(getTypeLocationService().getPhysicalTypeIdentifier(entity), versionType, new JavaSymbolName(versionField)); versionFieldDetails.setModifiers(Modifier.PRIVATE); versionFieldDetails.addAnnotations(annotations); return new FieldMetadataBuilder(versionFieldDetails).build(); }
/** * This method provides the related field for the provided endPoint * * @param endPoint to obtain the related field * * @return FieldMetadataBuilder that contains all information about the field */ public FieldMetadataBuilder getEndPointField(WsClientEndpoint endPoint) { // Checking if already exists the endPoint field to // prevent to generate it again if (endPointFields.get(endPoint.getName()) != null) { return endPointFields.get(endPoint.getName()); } // Calculate the field name JavaSymbolName fieldName = new JavaSymbolName(StringUtils.uncapitalize(endPoint.getName()).concat("Url")); // Create the field FieldMetadataBuilder endPointField = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, fieldName, JavaType.STRING, null); // Include @Value annotation AnnotationMetadataBuilder valueAnnotation = new AnnotationMetadataBuilder(SpringJavaType.VALUE); valueAnnotation.addStringAttribute("value", String.format("${url/%s}", endPoint.getName())); endPointField.addAnnotation(valueAnnotation); // Cache generated fields endPointFields.put(endPoint.getName(), endPointField); return endPointField; }
getMapping.addStringAttribute("value", "/accessibility"); annotations.add(getMapping);
getMappingAnnotation.addStringAttribute("name", methodName.getSymbolName()); annotations.add(getMappingAnnotation);
/** * This method obtains the servlet field that will be used in some different methods * * @return FieldMetadata that contains all the necessary information * about the servlet field */ private FieldMetadata getServletField() { // Check if already exists if (this.servletField != null) { return this.servletField; } // Create the field FieldMetadataBuilder servlet = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new JavaSymbolName("cxfServletPath"), JavaType.STRING, null); AnnotationMetadataBuilder valueAnnotation = new AnnotationMetadataBuilder(SpringJavaType.VALUE); valueAnnotation.addStringAttribute("value", "${cxf.path}"); servlet.addAnnotation(valueAnnotation); servletField = servlet.build(); return servletField; }
private AnnotationMetadataBuilder getColumnBuilder(final Identifier identifier) { final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(COLUMN); columnBuilder.addStringAttribute("name", identifier.getColumnName()); if (StringUtils.isNotBlank(identifier.getColumnDefinition())) { columnBuilder.addStringAttribute("columnDefinition", identifier.getColumnDefinition()); } columnBuilder.addBooleanAttribute("nullable", false); // Add length attribute for Strings if (identifier.getColumnSize() < 4000 && identifier.getFieldType().equals(JavaType.STRING)) { columnBuilder.addIntegerAttribute("length", identifier.getColumnSize()); } // Add precision and scale attributes for numeric fields if (identifier.getScale() > 0 && (identifier.getFieldType().equals(JavaType.DOUBLE_OBJECT) || identifier.getFieldType().equals(JavaType.DOUBLE_PRIMITIVE) || identifier .getFieldType().equals(BIG_DECIMAL))) { columnBuilder.addIntegerAttribute("precision", identifier.getColumnSize()); columnBuilder.addIntegerAttribute("scale", identifier.getScale()); } return columnBuilder; }
/** * This method returns the getXmlIdentityInfo() method. * * @return MethodMetadata that contains the getXmlIdentityInfoMethod */ public MethodMetadata getXmlIdentityInfoMethod() { // Check if already exists if (xmlIdentityInfoMethod != null) { return xmlIdentityInfoMethod; } // If not, generate a new one InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); // return getClass().getName() + ":" + getId(); bodyBuilder.appendFormalLine(String.format("return getClass().getName() + \":\" + %s();", identifierAccessor.getMethodName())); MethodMetadataBuilder method = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("getXmlIdentityInfo"), JavaType.STRING, bodyBuilder); method.addAnnotation(new AnnotationMetadataBuilder(JavaType.XML_ID)); AnnotationMetadataBuilder xmlAttributeAnnotation = new AnnotationMetadataBuilder(JavaType.XML_ATTRIBUTE); xmlAttributeAnnotation.addStringAttribute("name", "id"); method.addAnnotation(xmlAttributeAnnotation); CommentStructure comment = new CommentStructure(); comment.addComment(new JavadocComment("Must return an unique ID across all entities"), CommentLocation.BEGINNING); method.setCommentStructure(comment); xmlIdentityInfoMethod = method.build(); return xmlIdentityInfoMethod; }