Search in sources :

Example 11 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class EqualsMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = EqualsMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = EqualsMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 12 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class ToStringMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = ToStringMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = ToStringMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 13 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class JpaEntityMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = getType(metadataIdentificationString);
    final LogicalPath path = PhysicalTypeIdentifierNamingUtils.getPath(PROVIDES_TYPE_STRING, metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 14 with LogicalPath

use of org.springframework.roo.project.LogicalPath 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();
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) LogicalPath(org.springframework.roo.project.LogicalPath) Document(org.w3c.dom.Document) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder) SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) WebScaffoldMetadata(org.springframework.roo.addon.web.mvc.controller.addon.scaffold.WebScaffoldMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Example 15 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class WebFlowOperationsImpl method addLocalizedMessages.

/**
 * Add this add-on localized messages from its message bundles to the project's
 * message bundles, for each installed language, plus English. Existing messages
 * will be replaced.
 *
 * @param moduleName the module name where the message bundles are.
 * @param flowName the name/id of the flow to prefix the messages.
 */
private void addLocalizedMessages(String moduleName) {
    // Install localized messages for each installed language
    for (I18n i18n : i18nSupport.getSupportedLanguages()) {
        if (i18n.getLanguage().equals(new EnglishLanguage().getLanguage())) {
            continue;
        }
        // Get theme specific messages
        InputStream themeMessagesInputStream = null;
        try {
            themeMessagesInputStream = FileUtils.getInputStream(getClass(), String.format("messages_%s.properties", i18n.getLocale()));
        } catch (NullPointerException ex) {
            LOGGER.warning(String.format("There aren't translations for %1$s language. Adding english messages to messages_%1$s.properties instead.", i18n.getLocale()));
            themeMessagesInputStream = FileUtils.getInputStream(getClass(), String.format("messages.properties", i18n.getLocale()));
        }
        final Properties loadedProperties = propFilesManagerService.loadProperties(themeMessagesInputStream);
        // Add theme messages to localized message bundle
        final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName);
        final String targetDirectory = pathResolver.getIdentifier(resourcesPath, "");
        String bundlePath = String.format("%s%smessages_%s.properties", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, i18n.getLocale());
        if (fileManager.exists(bundlePath)) {
            Map<String, String> newProperties = new HashMap<String, String>();
            for (Entry<Object, Object> entry : loadedProperties.entrySet()) {
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();
                // Prefix with flow name
                key = String.format("%s_%s", this.flowName.toLowerCase(), key);
                newProperties.put(key, value);
                newProperties.put("label_".concat(this.flowName.toLowerCase()), StringUtils.capitalize(this.flowName));
            }
            propFilesManagerService.addProperties(resourcesPath, String.format("messages_%s.properties", i18n.getLocale()), newProperties, true, true);
        }
        // Close InputStream
        try {
            themeMessagesInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // Always install english messages
    InputStream themeMessagesInputStream = FileUtils.getInputStream(getClass(), "messages.properties");
    EnglishLanguage english = new EnglishLanguage();
    final Properties loadedProperties = propFilesManagerService.loadProperties(themeMessagesInputStream);
    // Add theme messages to localized message bundle
    final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName);
    final String targetDirectory = pathResolver.getIdentifier(resourcesPath, "");
    String bundlePath = String.format("%s%smessages.properties", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, english.getLocale());
    if (fileManager.exists(bundlePath)) {
        Map<String, String> newProperties = new HashMap<String, String>();
        for (Entry<Object, Object> entry : loadedProperties.entrySet()) {
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();
            // Prefix with flow name
            key = String.format("%s_%s", this.flowName.toLowerCase(), key);
            newProperties.put(key, value);
            newProperties.put("label_".concat(this.flowName.toLowerCase()), StringUtils.capitalize(this.flowName));
        }
        propFilesManagerService.addProperties(resourcesPath, "messages.properties", newProperties, true, true);
    }
    // Close InputStream
    try {
        themeMessagesInputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) EnglishLanguage(org.springframework.roo.addon.web.mvc.i18n.languages.EnglishLanguage) InputStream(java.io.InputStream) LogicalPath(org.springframework.roo.project.LogicalPath) IOException(java.io.IOException) Properties(java.util.Properties) I18n(org.springframework.roo.addon.web.mvc.i18n.components.I18n)

Aggregations

LogicalPath (org.springframework.roo.project.LogicalPath)85 JavaType (org.springframework.roo.model.JavaType)62 RooJavaType (org.springframework.roo.model.RooJavaType)55 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)13 JpaJavaType (org.springframework.roo.model.JpaJavaType)12 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 SpringJavaType (org.springframework.roo.model.SpringJavaType)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)5 BufferedInputStream (java.io.BufferedInputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 I18n (org.springframework.roo.addon.web.mvc.i18n.components.I18n)4 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3