Search in sources :

Example 51 with ClassOrInterfaceTypeDetailsBuilder

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.

the class MailOperationsImpl method installReceiveEmailSupport.

@Override
public void installReceiveEmailSupport(String host, String port, String protocol, String username, String password, Boolean starttls, String jndiName, String profile, Pom module, JavaType service, boolean force) {
    // Include springlets-boot-starter-mail in module
    getProjectOperations().addDependency(module.getModuleName(), DEPENDENCY_SPRINGLETS_STARTER_MAIL);
    // Include property version
    getProjectOperations().addProperty("", PROPERTY_SPRINGLETS_VERSION);
    // check if exists any property
    if (getApplicationConfigService().existsSpringConfigFile(module.getModuleName(), profile) && areDefinedReceiveEmailProperties(module.getModuleName(), profile) && !force) {
        // Send error message to user. He needs to set --force parameter
        String profileStr = "profile " + profile;
        if (profile == null) {
            profileStr = "default profile";
        }
        String moduleStr = " and module " + module.getModuleName();
        if (StringUtils.isEmpty(module.getModuleName())) {
            moduleStr = "";
        }
        LOGGER.log(Level.INFO, String.format("There are defined the mail properties to %s" + "%s. Using this command with '--force' " + "will overwrite the current values.", profileStr, moduleStr));
    } else {
        Map<String, String> propertiesFormattedToInsert = getReceiveEmailPropertiesFormattedToInsert(host, port, protocol, username, password, starttls, jndiName);
        // Set properties in file
        getApplicationConfigService().addProperties(module.getModuleName(), propertiesFormattedToInsert, profile, force);
    }
    if (service != null) {
        // Add dependency springlets-mail to the module of the selected Service
        if (!service.getModule().equals(StringUtils.EMPTY)) {
            getProjectOperations().addDependency(service.getModule(), DEPENDENCY_SPRINGLETS_MAIL);
        }
        // Add MailReceiverService to service
        final ClassOrInterfaceTypeDetails serviceTypeDetails = getTypeLocationService().getTypeDetails(service);
        Validate.isTrue(serviceTypeDetails != null, "Cannot locate source for '%s'", service.getFullyQualifiedTypeName());
        final String declaredByMetadataId = serviceTypeDetails.getDeclaredByMetadataId();
        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(serviceTypeDetails);
        // Create the field
        cidBuilder.addField(new FieldMetadataBuilder(declaredByMetadataId, PRIVATE, Arrays.asList(new AnnotationMetadataBuilder(AUTOWIRED)), new JavaSymbolName("mailReceiver"), SpringletsJavaType.SPRINGLETS_MAIL_RECEIVER_SERVICE));
        getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
    }
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 52 with ClassOrInterfaceTypeDetailsBuilder

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.

the class MailOperationsImpl method installSendEmailSupport.

@Override
public void installSendEmailSupport(String host, String port, String protocol, String username, String password, Boolean starttls, String jndiName, String profile, Pom module, JavaType service, boolean force) {
    // Include spring-boot-starter-mail in module
    getProjectOperations().addDependency(module.getModuleName(), DEPENDENCY_SPRING_BOOT_STARTER_MAIL);
    // check if exists any property
    if (getApplicationConfigService().existsSpringConfigFile(module.getModuleName(), profile) && areDefinedSendEmailProperties(module.getModuleName(), profile) && !force) {
        // Send error message to user. He needs to set --force parameter
        String profileStr = "profile " + profile;
        if (profile == null) {
            profileStr = "default profile";
        }
        String moduleStr = " and module " + module.getModuleName();
        if (StringUtils.isEmpty(module.getModuleName())) {
            moduleStr = "";
        }
        LOGGER.log(Level.INFO, String.format("There are defined the mail properties to %s" + "%s. Using this command with '--force' " + "will overwrite the current values.", profileStr, moduleStr));
    } else {
        Map<String, String> propertiesFormattedToInsert = getSendEmailPropertiesFormattedToInsert(host, port, protocol, username, password, starttls, jndiName);
        // Set properties in file
        getApplicationConfigService().addProperties(module.getModuleName(), propertiesFormattedToInsert, profile, force);
    }
    if (service != null) {
        // Add dependency spring-context-support to the module of the selected Service
        getProjectOperations().addDependency(service.getModule(), DEPENDENCY_SPRING_CONTEXT_SUPPORT);
        // Add JavaMailSender to service
        final ClassOrInterfaceTypeDetails serviceTypeDetails = getTypeLocationService().getTypeDetails(service);
        Validate.isTrue(serviceTypeDetails != null, "Cannot locate source for '%s'", service.getFullyQualifiedTypeName());
        final String declaredByMetadataId = serviceTypeDetails.getDeclaredByMetadataId();
        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(serviceTypeDetails);
        // Create the field
        cidBuilder.addField(new FieldMetadataBuilder(declaredByMetadataId, PRIVATE, Arrays.asList(new AnnotationMetadataBuilder(AUTOWIRED)), new JavaSymbolName("mailSender"), SpringJavaType.JAVA_MAIL_SENDER));
        getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
    }
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 53 with ClassOrInterfaceTypeDetailsBuilder

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.

the class DbreDatabaseListenerImpl method createNewManagedEntityFromTable.

/**
 * Creates a new DBRE-managed entity from the given table
 *
 * @param javaType the name of the entity to be created (required)
 * @param table the table from which to create the entity (required)
 * @return the newly created entity
 */
private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(final JavaType javaType, final Table table) {
    // Create type annotations for new entity
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
    annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));
    // Find primary key from db metadata and add identifier attributes to
    // @RooJpaEntity
    final AnnotationMetadataBuilder jpaAnnotationBuilder = new AnnotationMetadataBuilder(ROO_JPA_ENTITY);
    manageIdentifier(javaType, jpaAnnotationBuilder, new HashSet<JavaSymbolName>(), table);
    if (!hasVersionField(table)) {
        jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
    }
    if (table.isDisableGeneratedIdentifiers()) {
        jpaAnnotationBuilder.addStringAttribute(SEQUENCE_NAME_FIELD, "");
    }
    jpaAnnotationBuilder.addStringAttribute("table", table.getName());
    if (!DbreModelService.NO_SCHEMA_REQUIRED.equals(table.getSchema().getName())) {
        jpaAnnotationBuilder.addStringAttribute("schema", table.getSchema().getName());
    }
    annotations.add(jpaAnnotationBuilder);
    // Add @RooDbManaged
    annotations.add(getRooDbManagedAnnotation());
    final JavaType superclass = OBJECT;
    final List<JavaType> extendsTypes = new ArrayList<JavaType>();
    extendsTypes.add(superclass);
    // Create entity class
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(javaType, getProjectOperations().getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, javaType, PhysicalTypeCategory.CLASS);
    cidBuilder.setExtendsTypes(extendsTypes);
    cidBuilder.setAnnotations(annotations);
    final ClassOrInterfaceTypeDetails entity = cidBuilder.build();
    getTypeManagementService().createOrUpdateTypeOnDisk(entity);
    getShell().flash(Level.FINE, "Created " + javaType.getFullyQualifiedTypeName(), DbreDatabaseListenerImpl.class.getName());
    getShell().flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
    return entity;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) JdkJavaType(org.springframework.roo.model.JdkJavaType) JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 54 with ClassOrInterfaceTypeDetailsBuilder

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.

the class DbreDatabaseListenerImpl method createIdentifierClass.

private void createIdentifierClass(final JavaType identifierType) {
    final List<AnnotationMetadataBuilder> identifierAnnotations = new ArrayList<AnnotationMetadataBuilder>();
    final AnnotationMetadataBuilder identifierBuilder = new AnnotationMetadataBuilder(ROO_IDENTIFIER);
    identifierBuilder.addBooleanAttribute(DB_MANAGED.getSymbolName(), true);
    identifierAnnotations.add(identifierBuilder);
    // Produce identifier itself
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(identifierType, getProjectOperations().getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC | Modifier.FINAL, identifierType, PhysicalTypeCategory.CLASS);
    cidBuilder.setAnnotations(identifierAnnotations);
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
    getShell().flash(Level.FINE, "Created " + identifierType.getFullyQualifiedTypeName(), DbreDatabaseListenerImpl.class.getName());
    getShell().flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
}
Also used : ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 55 with ClassOrInterfaceTypeDetailsBuilder

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.

the class DbreMetadata method excludeFieldsInToStringAnnotation.

// XXX DiSiD: Invoke this method when add non other fields to builder
// http://projects.disid.com/issues/7455
private void excludeFieldsInToStringAnnotation(final String fieldName) {
    if (toStringAnnotation == null) {
        return;
    }
    final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
    final List<StringAttributeValue> ignoreFields = new ArrayList<StringAttributeValue>();
    // Copy the existing attributes, excluding the "ignoreFields" attribute
    boolean alreadyAdded = false;
    AnnotationAttributeValue<?> value = toStringAnnotation.getAttribute(new JavaSymbolName("excludeFields"));
    if (value == null) {
        value = new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("excludeFields"), new ArrayList<StringAttributeValue>());
    }
    // Ensure we have an array of strings
    final String errMsg = "@RooToString attribute 'excludeFields' must be an array of strings";
    Validate.isInstanceOf(ArrayAttributeValue.class, value, errMsg);
    final ArrayAttributeValue<?> arrayVal = (ArrayAttributeValue<?>) value;
    for (final Object obj : arrayVal.getValue()) {
        Validate.isInstanceOf(StringAttributeValue.class, obj, errMsg);
        final StringAttributeValue sv = (StringAttributeValue) obj;
        if (sv.getValue().equals(fieldName)) {
            alreadyAdded = true;
        }
        ignoreFields.add(sv);
    }
    // Add the desired field to ignore to the end
    if (!alreadyAdded) {
        ignoreFields.add(new StringAttributeValue(new JavaSymbolName("ignored"), fieldName));
    }
    attributes.add(new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("excludeFields"), ignoreFields));
    final AnnotationMetadataBuilder toStringAnnotationBuilder = new AnnotationMetadataBuilder(ROO_TO_STRING, attributes);
    updatedGovernorBuilder = new ClassOrInterfaceTypeDetailsBuilder(governorTypeDetails);
    toStringAnnotation = toStringAnnotationBuilder.build();
    updatedGovernorBuilder.updateTypeAnnotation(toStringAnnotation, new HashSet<JavaSymbolName>());
}
Also used : ArrayAttributeValue(org.springframework.roo.classpath.details.annotations.ArrayAttributeValue) AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) ArrayList(java.util.ArrayList) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)68 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)54 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)43 JavaType (org.springframework.roo.model.JavaType)30 ArrayList (java.util.ArrayList)29 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)29 RooJavaType (org.springframework.roo.model.RooJavaType)26 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)19 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)14 SpringJavaType (org.springframework.roo.model.SpringJavaType)12 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)10 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)10 JpaJavaType (org.springframework.roo.model.JpaJavaType)10 Dependency (org.springframework.roo.project.Dependency)10 LogicalPath (org.springframework.roo.project.LogicalPath)10 Pom (org.springframework.roo.project.maven.Pom)9 List (java.util.List)8 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)7 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)7 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)7