Search in sources :

Example 71 with LogicalPath

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

the class PluralMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = PluralMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = PluralMetadata.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 72 with LogicalPath

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

the class PluralServiceImpl method getPlural.

@Override
public String getPlural(ClassOrInterfaceTypeDetails cid, Locale locale) {
    Validate.notNull(cid, "ERROR: You must provide a valid ClassOrInterfaceTypeDetails");
    Validate.notNull(locale, "ERROR: You must provide a valid Locale");
    final JavaType javaType = cid.getType();
    final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(cid.getDeclaredByMetadataId());
    final String pluralMetadataKey = PluralMetadata.createIdentifier(javaType, logicalPath);
    final PluralMetadata pluralMetadata = (PluralMetadata) getMetadataService().get(pluralMetadataKey);
    if (pluralMetadata != null) {
        final String plural = pluralMetadata.getPlural();
        if (plural.equalsIgnoreCase(javaType.getSimpleTypeName())) {
            return plural + "Items";
        } else {
            return plural;
        }
    }
    return getPlural(javaType.getSimpleTypeName(), locale);
}
Also used : JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 73 with LogicalPath

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

the class ThymeleafMainControllerMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = ThymeleafMainControllerMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = ThymeleafMainControllerMetadata.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 74 with LogicalPath

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

the class ControllerOperationsImpl method createOrUpdateControllerForEntity.

@Override
public void createOrUpdateControllerForEntity(JavaType entity, ControllerMVCResponseService responseType, JavaPackage controllerPackage, String pathPrefix) {
    // Getting entity details to obtain information about it
    ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
    AnnotationMetadata entityAnnotation = entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY);
    if (entityAnnotation == null) {
        LOGGER.log(Level.INFO, String.format("ERROR: The provided class %s is not a valid entity. It should be annotated with @RooEntity", entity.getSimpleTypeName()));
        return;
    }
    JpaEntityMetadata entityMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(entityDetails));
    if (entityMetadata.isCompositionChild()) {
        // Don't generate Controller for composition Child entities
        LOGGER.log(Level.INFO, String.format("INFO: The provided class %s is composition child part of a relationship. No controller is needed as it's managed form parent controller", entity.getSimpleTypeName()));
        return;
    }
    // Getting related service
    JavaType service = null;
    ClassOrInterfaceTypeDetails serviceDetails = getServiceLocator().getService(entity);
    if (serviceDetails == null) {
        // Is necessary at least one service to generate controller
        LOGGER.log(Level.INFO, String.format("ERROR: You must generate a service to '%s' entity before to generate a new controller.", entity.getFullyQualifiedTypeName()));
        return;
    }
    service = serviceDetails.getName();
    Collection<ClassOrInterfaceTypeDetails> controllers = getControllerLocator().getControllers(entity);
    // Check controllersPackage value
    if (controllerPackage == null) {
        controllerPackage = getDefaultControllerPackage();
        if (controllerPackage == null) {
            return;
        }
    }
    ControllerAnnotationValues values;
    for (ClassOrInterfaceTypeDetails existingController : controllers) {
        values = new ControllerAnnotationValues(existingController);
        if ((values.getType() == ControllerType.COLLECTION || values.getType() == ControllerType.ITEM)) {
            if (StringUtils.equals(values.getPathPrefix(), pathPrefix) && existingController.getAnnotation(responseType.getAnnotation()) != null) {
                LOGGER.log(Level.INFO, String.format("ERROR: Already exists a controller associated to entity '%s' with the " + "pathPrefix '%s' for this responseType. Specify different one " + "using --pathPrefix or --responseType parameter.", entity.getSimpleTypeName(), pathPrefix));
                return;
            }
        }
    }
    // Generate Collection controller JavaType
    String entityPluralCapitalized = StringUtils.capitalize(getPluralService().getPlural(entity));
    JavaType collectionController = new JavaType(String.format("%s.%sCollection%sController", controllerPackage.getFullyQualifiedPackageName(), entityPluralCapitalized, responseType.getControllerNameModifier()), controllerPackage.getModule());
    ClassOrInterfaceTypeDetails collectionControllerDetails = getTypeLocationService().getTypeDetails(collectionController);
    if (collectionControllerDetails == null) {
        List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(getRooControllerAnnotation(entity, pathPrefix, ControllerType.COLLECTION));
        // Add responseType annotation. Don't use responseTypeService
        // annotate to
        // prevent multiple
        // updates of the .java file. Annotate operation will be used during
        // controller update.
        annotations.add(new AnnotationMetadataBuilder(responseType.getAnnotation()));
        final LogicalPath controllerPath = getPathResolver().getPath(collectionController.getModule(), Path.SRC_MAIN_JAVA);
        final String resourceIdentifier = getTypeLocationService().getPhysicalTypeCanonicalPath(collectionController, controllerPath);
        final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(collectionController, getPathResolver().getPath(resourceIdentifier));
        ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, collectionController, PhysicalTypeCategory.CLASS);
        cidBuilder.setAnnotations(annotations);
        getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
        // Create LinkFactory class
        if (responseType.getName().equals("THYMELEAF")) {
            createLinkFactoryClass(cidBuilder.getName());
        }
    } else {
        LOGGER.log(Level.INFO, String.format("ERROR: The controller %s already exists.", collectionController.getFullyQualifiedTypeName()));
        return;
    }
    // Same operation to itemController
    // Generate Item Controller JavaType
    JavaType itemController = new JavaType(String.format("%s.%sItem%sController", controllerPackage.getFullyQualifiedPackageName(), entityPluralCapitalized, responseType.getControllerNameModifier()), controllerPackage.getModule());
    ClassOrInterfaceTypeDetails itemControllerDetails = getTypeLocationService().getTypeDetails(itemController);
    if (itemControllerDetails == null) {
        List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(getRooControllerAnnotation(entity, pathPrefix, ControllerType.ITEM));
        // Add responseType annotation. Don't use responseTypeService
        // annotate to
        // prevent multiple
        // updates of the .java file. Annotate operation will be used during
        // controller update.
        annotations.add(new AnnotationMetadataBuilder(responseType.getAnnotation()));
        final LogicalPath controllerPathItem = getPathResolver().getPath(itemController.getModule(), Path.SRC_MAIN_JAVA);
        final String resourceIdentifierItem = getTypeLocationService().getPhysicalTypeCanonicalPath(itemController, controllerPathItem);
        final String declaredByMetadataIdItem = PhysicalTypeIdentifier.createIdentifier(itemController, getPathResolver().getPath(resourceIdentifierItem));
        ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataIdItem, Modifier.PUBLIC, itemController, PhysicalTypeCategory.CLASS);
        cidBuilder.setAnnotations(annotations);
        getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
        // Create LinkFactory class
        if (responseType.getName().equals("THYMELEAF")) {
            createLinkFactoryClass(cidBuilder.getName());
        }
    } else {
        LOGGER.log(Level.INFO, String.format("ERROR: The controller %s already exists.", collectionController.getFullyQualifiedTypeName()));
        return;
    }
    // Check if requires Deserializer
    if (responseType.requiresJsonDeserializer()) {
        createJsonDeserializersIfDontExists(entity, itemController.getModule(), controllerPackage);
    }
    if (responseType.requiresJsonMixin()) {
        createJsonMixinIfDontExists(entity, entityMetadata, itemController.getModule(), controllerPackage);
    }
    // Check multimodule project
    if (getProjectOperations().isMultimoduleProject()) {
        getProjectOperations().addModuleDependency(collectionController.getModule(), service.getModule());
        getProjectOperations().addModuleDependency(itemController.getModule(), service.getModule());
    }
}
Also used : ArrayList(java.util.ArrayList) LogicalPath(org.springframework.roo.project.LogicalPath) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 75 with LogicalPath

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

the class JSONMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

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

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