Package org.springframework.roo.addon.web.mvc.controller.scaffold

Examples of org.springframework.roo.addon.web.mvc.controller.scaffold.WebScaffoldMetadata


        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());

        // We abort the creation of a selenium test if the controller does not
        // 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(
View Full Code Here


                .createIdentifier(javaType, path);

        // We want to be notified if the getter info changes in any way
        metadataDependencyRegistry.registerDependency(webScaffoldMetadataKey,
                metadataIdentificationString);
        final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) metadataService
                .get(webScaffoldMetadataKey);

        // Abort if we don't have getter information available
        if (webScaffoldMetadata == null || !webScaffoldMetadata.isValid()) {
            return null;
        }

        final JavaType targetObject = webScaffoldMetadata.getAnnotationValues()
                .getFormBackingObject();
        Validate.notNull(
                targetObject,
                "Could not acquire form backing object for the '%s' controller",
                WebScaffoldMetadata.getJavaType(webScaffoldMetadata.getId())
                        .getFullyQualifiedTypeName());

        final String targetObjectMid = typeLocationService
                .getPhysicalTypeIdentifier(targetObject);
        final LogicalPath targetObjectPath = PhysicalTypeIdentifier
                .getPath(targetObjectMid);

        final SolrMetadata solrMetadata = (SolrMetadata) metadataService
                .get(SolrMetadata.createIdentifier(targetObject,
                        targetObjectPath));
        Validate.notNull(solrMetadata,
                "Could not determine SolrMetadata for type '%s'",
                targetObject.getFullyQualifiedTypeName());

        // Otherwise go off and create the to String metadata
        return new SolrWebSearchMetadata(metadataIdentificationString,
                aspectName, governorPhysicalTypeMetadata, annotationValues,
                webScaffoldMetadata.getAnnotationValues(),
                solrMetadata.getAnnotationValues());
    }
View Full Code Here

        // controller class

        final String webScaffoldMetadataKey = WebScaffoldMetadata
                .createIdentifier(JspMetadata.getJavaType(jspMetadataId),
                        JspMetadata.getPath(jspMetadataId));
        final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) metadataService
                .get(webScaffoldMetadataKey);
        if (webScaffoldMetadata == null || !webScaffoldMetadata.isValid()) {
            // Can't get the corresponding scaffold, so we certainly don't need
            // to manage any JSPs at this time
            return null;
        }

        final JavaType formBackingType = webScaffoldMetadata
                .getAnnotationValues().getFormBackingObject();
        final MemberDetails memberDetails = webMetadataService
                .getMemberDetails(formBackingType);
        final JavaTypeMetadataDetails formBackingTypeMetadataDetails = webMetadataService
                .getJavaTypeMetadataDetails(formBackingType, memberDetails,
                        jspMetadataId);
        Validate.notNull(formBackingTypeMetadataDetails,
                "Unable to obtain metadata for type %s",
                formBackingType.getFullyQualifiedTypeName());

        formBackingObjectTypesToLocalMids.put(formBackingType, jspMetadataId);

        final SortedMap<JavaType, JavaTypeMetadataDetails> relatedTypeMd = webMetadataService
                .getRelatedApplicationTypeMetadata(formBackingType,
                        memberDetails, jspMetadataId);
        final JavaTypeMetadataDetails formbackingTypeMetadata = relatedTypeMd
                .get(formBackingType);
        Validate.notNull(formbackingTypeMetadata,
                "Form backing type metadata required");
        final JavaTypePersistenceMetadataDetails formBackingTypePersistenceMetadata = formbackingTypeMetadata
                .getPersistenceDetails();
        if (formBackingTypePersistenceMetadata == null) {
            return null;
        }
        final ClassOrInterfaceTypeDetails formBackingTypeDetails = typeLocationService
                .getTypeDetails(formBackingType);
        final LogicalPath formBackingTypePath = PhysicalTypeIdentifier
                .getPath(formBackingTypeDetails.getDeclaredByMetadataId());
        metadataDependencyRegistry.registerDependency(PhysicalTypeIdentifier
                .createIdentifier(formBackingType, formBackingTypePath),
                JspMetadata.createIdentifier(formBackingType,
                        formBackingTypePath));
        final LogicalPath path = JspMetadata.getPath(jspMetadataId);

        // Install web artifacts only if Spring MVC config is missing
        // TODO: Remove this call when 'controller' commands are gone
        final PathResolver pathResolver = projectOperations.getPathResolver();
        final LogicalPath webappPath = LogicalPath.getInstance(
                Path.SRC_MAIN_WEBAPP, path.getModule());

        if (!fileManager.exists(pathResolver.getIdentifier(webappPath,
                WEB_INF_VIEWS))) {
            jspOperations.installCommonViewArtefacts(path.getModule());
        }

        installImage(webappPath, "images/show.png");
        if (webScaffoldMetadata.getAnnotationValues().isUpdate()) {
            installImage(webappPath, "images/update.png");
        }
        if (webScaffoldMetadata.getAnnotationValues().isDelete()) {
            installImage(webappPath, "images/delete.png");
        }

        final List<FieldMetadata> eligibleFields = webMetadataService
                .getScaffoldEligibleFieldMetadata(formBackingType,
                        memberDetails, jspMetadataId);
        if (eligibleFields.isEmpty()
                && formBackingTypePersistenceMetadata.getRooIdentifierFields()
                        .isEmpty()) {
            return null;
        }
       
        final JspViewManager viewManager = new JspViewManager(eligibleFields,
                webScaffoldMetadata.getAnnotationValues(), relatedTypeMd, typeLocationService);

        String controllerPath = webScaffoldMetadata.getAnnotationValues()
                .getPath();
        if (controllerPath.startsWith("/")) {
            controllerPath = controllerPath.substring(1);
        }

        // Make the holding directory for this controller
        final String destinationDirectory = pathResolver.getIdentifier(
                webappPath, WEB_INF_VIEWS + controllerPath);
        if (!fileManager.exists(destinationDirectory)) {
            fileManager.createDirectory(destinationDirectory);
        }
        else {
            final File file = new File(destinationDirectory);
            Validate.isTrue(file.isDirectory(),
                    "%s is a file, when a directory was expected",
                    destinationDirectory);
        }

        // By now we have a directory to put the JSPs inside
        final String listPath1 = destinationDirectory + "/list.jspx";
        xmlRoundTripFileManager.writeToDiskIfNecessary(listPath1,
                viewManager.getListDocument());
        tilesOperations.addViewDefinition(controllerPath, webappPath,
                controllerPath + "/" + "list",
                TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS
                        + controllerPath + "/list.jspx");

        final String showPath = destinationDirectory + "/show.jspx";
        xmlRoundTripFileManager.writeToDiskIfNecessary(showPath,
                viewManager.getShowDocument());
        tilesOperations.addViewDefinition(controllerPath, webappPath,
                controllerPath + "/" + "show",
                TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS
                        + controllerPath + "/show.jspx");

        final Map<String, String> properties = new LinkedHashMap<String, String>();

        final JavaSymbolName categoryName = new JavaSymbolName(
                formBackingType.getSimpleTypeName());
        properties.put("menu_category_"
                + categoryName.getSymbolName().toLowerCase() + "_label",
                categoryName.getReadableSymbolName());

        final JavaSymbolName newMenuItemId = new JavaSymbolName("new");
        properties.put("menu_item_"
                + categoryName.getSymbolName().toLowerCase() + "_"
                + newMenuItemId.getSymbolName().toLowerCase() + "_label",
                new JavaSymbolName(formBackingType.getSimpleTypeName())
                        .getReadableSymbolName());

        if (webScaffoldMetadata.getAnnotationValues().isCreate()) {
            final String listPath = destinationDirectory + "/create.jspx";
            xmlRoundTripFileManager.writeToDiskIfNecessary(listPath,
                    viewManager.getCreateDocument());
            // Add 'create new' menu item
            menuOperations.addMenuItem(categoryName, newMenuItemId,
                    "global_menu_new", "/" + controllerPath + "?form",
                    MenuOperations.DEFAULT_MENU_ITEM_PREFIX, webappPath);
            tilesOperations.addViewDefinition(controllerPath, webappPath,
                    controllerPath + "/" + "create",
                    TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS
                            + controllerPath + "/create.jspx");
        }
        else {
            menuOperations
                    .cleanUpMenuItem(categoryName, new JavaSymbolName("new"),
                            MenuOperations.DEFAULT_MENU_ITEM_PREFIX, webappPath);
            tilesOperations.removeViewDefinition(controllerPath + "/"
                    + "create", controllerPath, webappPath);
        }
        if (webScaffoldMetadata.getAnnotationValues().isUpdate()) {
            final String listPath = destinationDirectory + "/update.jspx";
            xmlRoundTripFileManager.writeToDiskIfNecessary(listPath,
                    viewManager.getUpdateDocument());
            tilesOperations.addViewDefinition(controllerPath, webappPath,
                    controllerPath + "/" + "update",
View Full Code Here

                && !typeLocationService.hasTypeChanged(getClass().getName(),
                        type)) {
            return pathMap.get(type.getFullyQualifiedTypeName());
        }
        String webScaffoldMetadataKey = null;
        WebScaffoldMetadata webScaffoldMetadata = null;
        for (final ClassOrInterfaceTypeDetails cid : typeLocationService
                .findClassesOrInterfaceDetailsWithAnnotation(ROO_WEB_SCAFFOLD)) {
            for (final AnnotationMetadata annotation : cid.getAnnotations()) {
                if (annotation.getAnnotationType().equals(ROO_WEB_SCAFFOLD)) {
                    final AnnotationAttributeValue<?> formBackingObject = annotation
                            .getAttribute(new JavaSymbolName(
                                    "formBackingObject"));
                    if (formBackingObject instanceof ClassAttributeValue) {
                        final ClassAttributeValue formBackingObjectValue = (ClassAttributeValue) formBackingObject;
                        if (formBackingObjectValue.getValue().equals(type)) {
                            final AnnotationAttributeValue<String> path = annotation
                                    .getAttribute("path");
                            if (path != null) {
                                final String pathString = path.getValue();
                                pathMap.put(type.getFullyQualifiedTypeName(),
                                        pathString);
                                return pathString;
                            }
                            final LogicalPath cidPath = PhysicalTypeIdentifier
                                    .getPath(cid.getDeclaredByMetadataId());
                            webScaffoldMetadataKey = WebScaffoldMetadata
                                    .createIdentifier(cid.getName(), cidPath);
                            webScaffoldMetadata = (WebScaffoldMetadata) metadataService
                                    .get(webScaffoldMetadataKey);
                            break;
                        }
                    }
                }
            }
        }
        if (webScaffoldMetadata != null) {
            registerDependency(webScaffoldMetadataKey,
                    metadataIdentificationString);
            final String path = webScaffoldMetadata.getAnnotationValues()
                    .getPath();
            pathMap.put(type.getFullyQualifiedTypeName(), path);
            return path;
        }
        return getPlural(type, metadataIdentificationString).toLowerCase();
View Full Code Here

TOP

Related Classes of org.springframework.roo.addon.web.mvc.controller.scaffold.WebScaffoldMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.