use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class SerializableMetadata method createSerialVersionField.
/**
* Generates a field to store the serialization ID
*
* @return a non-<code>null</code> field
*/
private FieldMetadataBuilder createSerialVersionField() {
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), PRIVATE | STATIC | FINAL, SERIAL_VERSION_FIELD, LONG_PRIMITIVE, DEFAULT_SERIAL_VERSION);
fieldBuilder.getCustomData().put(CustomDataKeys.SERIAL_VERSION_UUID_FIELD, true);
return fieldBuilder;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaOperationsImpl method getVersionField.
/**
* 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();
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaEntityMetadata method getIterableToRemoveCantBeNullConstant.
/**
* This method obtains the constant that contains the message
* "The given Iterable of items to remove can't be null!".
*
* @return name of the generated constant
*/
private FieldMetadata getIterableToRemoveCantBeNullConstant() {
// Check if iterableCantBeNullConstant already exists
if (iterableToRemoveCantBeNullConstant != null) {
return iterableToRemoveCantBeNullConstant;
}
// If not exists, generate a new one and include into builder
FieldMetadataBuilder constant = new FieldMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC + Modifier.FINAL, new JavaSymbolName("ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE"), JavaType.STRING, "\"The given Iterable of items to add can't be null!\"");
iterableToRemoveCantBeNullConstant = constant.build();
return iterableToRemoveCantBeNullConstant;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class NewUpdateCompilationUnitTest method testSimpleClassAddField.
@Test
public void testSimpleClassAddField() throws Exception {
// Set up
final File file = getResource(SIMPLE_CLASS_FILE_PATH);
final String fileContents = getResourceContents(file);
final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService.getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID, SIMPLE_CLASS_TYPE);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(SIMPLE_CLASS_DECLARED_BY_MID, Modifier.PRIVATE, new JavaSymbolName("newFieldAddedByCode"), new JavaType(String.class), "\"Create by code\"");
final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addField(simpleInterfaceDetails, fieldBuilder.build());
// Invoke
final String result = typeParsingService.updateAndGetCompilationUnitContents(file.getCanonicalPath(), newSimpleInterfaceDetails);
saveResult(file, result, "-addedField");
checkSimpleClass(result);
assertTrue(result.contains("private String newFieldAddedByCode = \"Create by code\";"));
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class SeleniumOperationsImpl method generateTest.
/**
* Creates a new Selenium testcase
*
* @param controller the JavaType of the controller under test (required)
* @param name the name of the test case (optional)
* @param serverURL the URL of the Selenium server (optional)
*/
@Override
public void generateTest(final JavaType controller, String name, String serverURL) {
Validate.notNull(controller, "Controller type required");
final ClassOrInterfaceTypeDetails controllerTypeDetails = typeLocationService.getTypeDetails(controller);
Validate.notNull(controllerTypeDetails, "Class or interface type details for type '%s' could not be resolved", controller);
final LogicalPath path = PhysicalTypeIdentifier.getPath(controllerTypeDetails.getDeclaredByMetadataId());
final String webScaffoldMetadataIdentifier = WebScaffoldMetadata.createIdentifier(controller, path);
final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) metadataService.get(webScaffoldMetadataIdentifier);
Validate.notNull(webScaffoldMetadata, "Web controller '%s' does not appear to be an automatic, scaffolded controller", controller.getFullyQualifiedTypeName());
// allow the creation of new instances for the form backing object
if (!webScaffoldMetadata.getAnnotationValues().isCreate()) {
LOGGER.warning("The controller you specified does not allow the creation of new instances of the form backing object. No Selenium tests created.");
return;
}
if (!serverURL.endsWith("/")) {
serverURL = serverURL + "/";
}
final JavaType formBackingType = webScaffoldMetadata.getAnnotationValues().getFormBackingObject();
final String relativeTestFilePath = "selenium/test-" + formBackingType.getSimpleTypeName().toLowerCase() + ".xhtml";
final String seleniumPath = pathResolver.getFocusedIdentifier(Path.SRC_MAIN_WEBAPP, relativeTestFilePath);
final InputStream templateInputStream = FileUtils.getInputStream(getClass(), "selenium-template.xhtml");
Validate.notNull(templateInputStream, "Could not acquire selenium.xhtml template");
final Document document = XmlUtils.readXml(templateInputStream);
final Element root = (Element) document.getLastChild();
if (root == null || !"html".equals(root.getNodeName())) {
throw new IllegalArgumentException("Could not parse selenium test case template file!");
}
name = name != null ? name : "Selenium test for " + controller.getSimpleTypeName();
XmlUtils.findRequiredElement("/html/head/title", root).setTextContent(name);
XmlUtils.findRequiredElement("/html/body/table/thead/tr/td", root).setTextContent(name);
final Element tbody = XmlUtils.findRequiredElement("/html/body/table/tbody", root);
tbody.appendChild(openCommand(document, serverURL + projectOperations.getProjectName(projectOperations.getFocusedModuleName()) + "/" + webScaffoldMetadata.getAnnotationValues().getPath() + "?form"));
final ClassOrInterfaceTypeDetails formBackingTypeDetails = typeLocationService.getTypeDetails(formBackingType);
Validate.notNull(formBackingType, "Class or interface type details for type '%s' could not be resolved", formBackingType);
final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(getClass().getName(), formBackingTypeDetails);
// Add composite PK identifier fields if needed
for (final FieldMetadata field : persistenceMemberLocator.getEmbeddedIdentifierFields(formBackingType)) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(field);
final String fieldName = field.getFieldName().getSymbolName();
fieldBuilder.setFieldName(new JavaSymbolName(fieldName + "." + fieldName));
tbody.appendChild(typeCommand(document, fieldBuilder.build()));
}
}
// Add all other fields
final List<FieldMetadata> fields = webMetadataService.getScaffoldEligibleFieldMetadata(formBackingType, memberDetails, null);
for (final FieldMetadata field : fields) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
tbody.appendChild(typeCommand(document, field));
}
}
tbody.appendChild(clickAndWaitCommand(document, "//input[@id = 'proceed']"));
// Add verifications for all other fields
for (final FieldMetadata field : fields) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
tbody.appendChild(verifyTextCommand(document, formBackingType, field));
}
}
fileManager.createOrUpdateTextFileIfRequired(seleniumPath, XmlUtils.nodeToString(document), false);
manageTestSuite(relativeTestFilePath, name, serverURL);
// Install selenium-maven-plugin
installMavenPlugin();
}
Aggregations